cmem7_uart.h 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. /**
  2. *****************************************************************************
  3. * @file cmem7_uart.h
  4. *
  5. * @brief CMEM7 uart header file
  6. *
  7. *
  8. * @version V1.0
  9. * @date 3. September 2013
  10. *
  11. * @note
  12. *
  13. *****************************************************************************
  14. * @attention
  15. *
  16. * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
  17. * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
  18. * TIME. AS A RESULT, CAPITAL-MICRO SHALL NOT BE HELD LIABLE FOR ANY DIRECT,
  19. * INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
  20. * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
  21. * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
  22. *
  23. * <h2><center>&copy; COPYRIGHT 2013 Capital-micro </center></h2>
  24. *****************************************************************************
  25. */
  26. #ifndef __CMEM7_UART_H
  27. #define __CMEM7_UART_H
  28. #ifdef __cplusplus
  29. extern "C" {
  30. #endif
  31. #include "cmem7.h"
  32. #include "cmem7_conf.h"
  33. #define IS_UART_ALL_PERIPH(PERIPH) (((PERIPH) == UART0) || \
  34. ((PERIPH) == UART1) || \
  35. ((PERIPH) == UART2))
  36. /** @defgroup UART_StopBits
  37. * @{
  38. */
  39. #define UART_StopBits_0_5 0
  40. #define UART_StopBits_1 1
  41. #define UART_StopBits_1_5 2
  42. #define UART_StopBits_2 3
  43. #define IS_UART_STOPBITS(STOPBITS) (((STOPBITS) == UART_StopBits_1) || \
  44. ((STOPBITS) == UART_StopBits_0_5) || \
  45. ((STOPBITS) == UART_StopBits_2) || \
  46. ((STOPBITS) == UART_StopBits_1_5))
  47. /**
  48. * @}
  49. */
  50. /** @defgroup UART_Parity
  51. * @{
  52. */
  53. #define UART_Parity_Even 0
  54. #define UART_Parity_Odd 1
  55. #define UART_Parity_None 2
  56. #define IS_UART_PARITY(PARITY) (((PARITY) == UART_Parity_Even) || \
  57. ((PARITY) == UART_Parity_Odd) || \
  58. ((PARITY) == UART_Parity_None))
  59. /**
  60. * @}
  61. */
  62. /** @defgroup UART_Int
  63. * @{
  64. */
  65. #define UART_Int_RxNotEmpty 0x00000001
  66. #define UART_Int_TxEmpty 0x00000002
  67. #define UART_Int_TxHalfEmpty 0x00000004
  68. #define UART_Int_TxTimeoutNotEmpty 0x00000008
  69. #define UART_Int_TxTimeoutEmpty 0x00000010
  70. #define UART_Int_RxHalfFull 0x00000020
  71. #define UART_Int_TxFull 0x00000040
  72. #define UART_Int_ParityError 0x00000080
  73. #define UART_Int_FrameError 0x00000100
  74. #define UART_Int_OverrunError 0x00000200
  75. #define UART_Int_RxThresholdReach 0x00000400
  76. #define UART_Int_All 0x000007FF
  77. #define IS_UART_INT(INT) (((INT) != 0) && (((INT) & ~UART_Int_All) == 0))
  78. /**
  79. * @}
  80. */
  81. /**
  82. * @brief UART initialization structure
  83. */
  84. typedef struct
  85. {
  86. uint32_t UART_BaudRate; /*!< Baudrate */
  87. uint8_t UART_StopBits; /*!< Specifies the number of stop bits transmitted,
  88. It's a value of @ref UART_StopBits */
  89. uint8_t UART_Parity; /*!< Specifies the parity mode.
  90. It's a value of @ref UART_Parity */
  91. BOOL UART_LoopBack; /*!< loop back mode */
  92. BOOL UART_RxEn; /*!< Receive enable bit */
  93. BOOL UART_CtsEn; /*!< Clear to set */
  94. } UART_InitTypeDef;
  95. /**
  96. * @brief UART initialization
  97. * @note This function should be called at first before any other interfaces.
  98. * @param[in] UARTx UART peripheral, which is UART0, UART1 or UART2
  99. * @param[in] init A pointer to structure UART_InitTypeDef
  100. * @retval None
  101. */
  102. void UART_Init(UART0_Type* UARTx, UART_InitTypeDef *init);
  103. /**
  104. * @brief Enable or disable UART interrupt.
  105. * @param[in] UARTx UART peripheral, which is UART0, UART1 or UART2
  106. * @param[in] Int interrupt mask bits, which can be the combination of @ref UART_Int
  107. * @param[in] Enable The bit indicates if specific interrupts are enable or not
  108. * @retval None
  109. */
  110. void UART_EnableInt(UART0_Type* UARTx, uint32_t Int, BOOL Enable);
  111. /**
  112. * @brief Enable or disable UART.
  113. * @param[in] UARTx UART peripheral, which is UART0, UART1 or UART2
  114. * @param[in] Enable The bit indicates if the specific UART is enable or not
  115. * @retval None
  116. */
  117. void UART_Enable(UART0_Type* UARTx, BOOL enable);
  118. /**
  119. * @brief Check specific interrupts are set or not
  120. * @param[in] UARTx UART peripheral, which is UART0, UART1 or UART2
  121. * @param[in] Int interrupt mask bits, which can be the combination of @ref UART_Int
  122. * @retval BOOL The bit indicates if specific interrupts are set or not
  123. */
  124. BOOL UART_GetIntStatus(UART0_Type* UARTx, uint32_t Int);
  125. /**
  126. * @brief Clear specific interrupts
  127. * @param[in] UARTx UART peripheral, which is UART0, UART1 or UART2
  128. * @param[in] Int interrupt mask bits, which can be the combination of @ref UART_Int
  129. * @retval None
  130. */
  131. void UART_ClearInt(UART0_Type* UARTx, uint32_t Int);
  132. /**
  133. * @brief Write data to UART
  134. * @param[in] UARTx UART peripheral, which is UART0, UART1 or UART2
  135. * @param[in] Size Expected data size to be written
  136. * @param[in] Data A pointer to the data to be written
  137. * @retval uint8_t Actual written data size
  138. */
  139. uint8_t UART_Write(UART0_Type* UARTx, uint8_t Size, uint8_t* Data);
  140. /**
  141. * @brief Read data from UART
  142. * @param[in] UARTx UART peripheral, which is UART0, UART1 or UART2
  143. * @param[in] Size Expected data size to be read
  144. * @param[out] Data A user-allocated buffer to fetch data to be read
  145. * @retval uint8_t Actual read data size
  146. */
  147. uint8_t UART_Read(UART0_Type* UARTx, uint8_t Size, uint8_t* Data);
  148. #ifdef __cplusplus
  149. }
  150. #endif
  151. #endif /* __CMEM7_UART_H */