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>© COPYRIGHT 2013 Capital-micro </center></h2> 24 ***************************************************************************** 25 */ 26 27 #ifndef __CMEM7_UART_H 28 #define __CMEM7_UART_H 29 30 #ifdef __cplusplus 31 extern "C" { 32 #endif 33 34 #include "cmem7.h" 35 #include "cmem7_conf.h" 36 37 #define IS_UART_ALL_PERIPH(PERIPH) (((PERIPH) == UART0) || \ 38 ((PERIPH) == UART1) || \ 39 ((PERIPH) == UART2)) 40 41 /** @defgroup UART_StopBits 42 * @{ 43 */ 44 #define UART_StopBits_0_5 0 45 #define UART_StopBits_1 1 46 #define UART_StopBits_1_5 2 47 #define UART_StopBits_2 3 48 #define IS_UART_STOPBITS(STOPBITS) (((STOPBITS) == UART_StopBits_1) || \ 49 ((STOPBITS) == UART_StopBits_0_5) || \ 50 ((STOPBITS) == UART_StopBits_2) || \ 51 ((STOPBITS) == UART_StopBits_1_5)) 52 /** 53 * @} 54 */ 55 56 /** @defgroup UART_Parity 57 * @{ 58 */ 59 #define UART_Parity_Even 0 60 #define UART_Parity_Odd 1 61 #define UART_Parity_None 2 62 #define IS_UART_PARITY(PARITY) (((PARITY) == UART_Parity_Even) || \ 63 ((PARITY) == UART_Parity_Odd) || \ 64 ((PARITY) == UART_Parity_None)) 65 /** 66 * @} 67 */ 68 69 /** @defgroup UART_Int 70 * @{ 71 */ 72 #define UART_Int_RxNotEmpty 0x00000001 73 #define UART_Int_TxEmpty 0x00000002 74 #define UART_Int_TxHalfEmpty 0x00000004 75 #define UART_Int_TxTimeoutNotEmpty 0x00000008 76 #define UART_Int_TxTimeoutEmpty 0x00000010 77 #define UART_Int_RxHalfFull 0x00000020 78 #define UART_Int_TxFull 0x00000040 79 #define UART_Int_ParityError 0x00000080 80 #define UART_Int_FrameError 0x00000100 81 #define UART_Int_OverrunError 0x00000200 82 #define UART_Int_RxThresholdReach 0x00000400 83 #define UART_Int_All 0x000007FF 84 85 #define IS_UART_INT(INT) (((INT) != 0) && (((INT) & ~UART_Int_All) == 0)) 86 87 /** 88 * @} 89 */ 90 91 /** 92 * @brief UART initialization structure 93 */ 94 typedef struct 95 { 96 uint32_t UART_BaudRate; /*!< Baudrate */ 97 uint8_t UART_StopBits; /*!< Specifies the number of stop bits transmitted, 98 It's a value of @ref UART_StopBits */ 99 uint8_t UART_Parity; /*!< Specifies the parity mode. 100 It's a value of @ref UART_Parity */ 101 BOOL UART_LoopBack; /*!< loop back mode */ 102 BOOL UART_RxEn; /*!< Receive enable bit */ 103 BOOL UART_CtsEn; /*!< Clear to set */ 104 } UART_InitTypeDef; 105 106 /** 107 * @brief UART initialization 108 * @note This function should be called at first before any other interfaces. 109 * @param[in] UARTx UART peripheral, which is UART0, UART1 or UART2 110 * @param[in] init A pointer to structure UART_InitTypeDef 111 * @retval None 112 */ 113 void UART_Init(UART0_Type* UARTx, UART_InitTypeDef *init); 114 115 /** 116 * @brief Enable or disable UART interrupt. 117 * @param[in] UARTx UART peripheral, which is UART0, UART1 or UART2 118 * @param[in] Int interrupt mask bits, which can be the combination of @ref UART_Int 119 * @param[in] Enable The bit indicates if specific interrupts are enable or not 120 * @retval None 121 */ 122 void UART_EnableInt(UART0_Type* UARTx, uint32_t Int, BOOL Enable); 123 124 /** 125 * @brief Enable or disable UART. 126 * @param[in] UARTx UART peripheral, which is UART0, UART1 or UART2 127 * @param[in] Enable The bit indicates if the specific UART is enable or not 128 * @retval None 129 */ 130 void UART_Enable(UART0_Type* UARTx, BOOL enable); 131 132 /** 133 * @brief Check specific interrupts are set or not 134 * @param[in] UARTx UART peripheral, which is UART0, UART1 or UART2 135 * @param[in] Int interrupt mask bits, which can be the combination of @ref UART_Int 136 * @retval BOOL The bit indicates if specific interrupts are set or not 137 */ 138 BOOL UART_GetIntStatus(UART0_Type* UARTx, uint32_t Int); 139 140 /** 141 * @brief Clear specific interrupts 142 * @param[in] UARTx UART peripheral, which is UART0, UART1 or UART2 143 * @param[in] Int interrupt mask bits, which can be the combination of @ref UART_Int 144 * @retval None 145 */ 146 void UART_ClearInt(UART0_Type* UARTx, uint32_t Int); 147 148 /** 149 * @brief Write data to UART 150 * @param[in] UARTx UART peripheral, which is UART0, UART1 or UART2 151 * @param[in] Size Expected data size to be written 152 * @param[in] Data A pointer to the data to be written 153 * @retval uint8_t Actual written data size 154 */ 155 uint8_t UART_Write(UART0_Type* UARTx, uint8_t Size, uint8_t* Data); 156 157 /** 158 * @brief Read data from UART 159 * @param[in] UARTx UART peripheral, which is UART0, UART1 or UART2 160 * @param[in] Size Expected data size to be read 161 * @param[out] Data A user-allocated buffer to fetch data to be read 162 * @retval uint8_t Actual read data size 163 */ 164 uint8_t UART_Read(UART0_Type* UARTx, uint8_t Size, uint8_t* Data); 165 166 167 #ifdef __cplusplus 168 } 169 #endif 170 171 #endif /* __CMEM7_UART_H */ 172 173