]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/ARM7_STR71x_IAR/Library/include/uart.h
Add FreeRTOS-Plus directory.
[freertos] / FreeRTOS / Demo / ARM7_STR71x_IAR / Library / include / uart.h
1 /******************** (C) COPYRIGHT 2003 STMicroelectronics ********************\r
2 * File Name          : uart.h\r
3 * Author             : MCD Application Team\r
4 * Date First Issued  : 16/05/2003\r
5 * Description        : This file contains all the functions prototypes for the\r
6 *                      UART software library.\r
7 ********************************************************************************\r
8 * History:\r
9 *  30/11/2004 : V2.0\r
10 *  14/07/2004 : V1.3\r
11 *  01/01/2004 : V1.2\r
12 *******************************************************************************\r
13  THE PRESENT SOFTWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS WITH\r
14  CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME.\r
15  AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT, INDIRECT\r
16  OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE CONTENT\r
17  OF SUCH SOFTWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING INFORMATION\r
18  CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.\r
19 *******************************************************************************/\r
20 #ifndef _UART_H\r
21 #define _UART_H\r
22 \r
23 #include "71x_map.h"\r
24 #include "rccu.h"\r
25 \r
26 typedef enum\r
27 {\r
28   UART_RxFIFO,\r
29   UART_TxFIFO\r
30 } UARTFIFO_TypeDef;\r
31 \r
32 typedef enum\r
33 {\r
34   UART_EVEN_PARITY = 0x0000,\r
35   UART_ODD_PARITY  = 0x0020,\r
36   UART_NO_PARITY\r
37 } UARTParity_TypeDef;\r
38 \r
39 typedef enum\r
40 {\r
41   UART_0_5_StopBits  = 0x00,\r
42   UART_1_StopBits    = 0x08,\r
43   UART_1_5_StopBits  = 0x10,\r
44   UART_2_StopBits    = 0x18\r
45 } UARTStopBits_TypeDef;\r
46 \r
47 typedef enum\r
48 {\r
49   UARTM_8D   = 0x01,\r
50   UARTM_7D_P = 0x03,\r
51   UARTM_9D   = 0x04,\r
52   UARTM_8D_W = 0x05,\r
53   UARTM_8D_P = 0x07\r
54 } UARTMode_TypeDef;\r
55 \r
56 \r
57 #define DUMMY 0\r
58 \r
59 // UART flags definition\r
60 #define UART_TxFull          0x0200\r
61 #define UART_RxHalfFull      0x0100\r
62 #define UART_TimeOutIdle     0x0080\r
63 #define UART_TimeOutNotEmpty 0x0040\r
64 #define UART_OverrunError    0x0020\r
65 #define UART_FrameError      0x0010\r
66 #define UART_ParityError     0x0008\r
67 #define UART_TxHalfEmpty     0x0004\r
68 #define UART_TxEmpty         0x0002\r
69 #define UART_RxBufFull       0x0001\r
70 \r
71 // CR regiter bit definition\r
72 #define UART_FIFOEnableBit 10\r
73 #define UART_RxEnableBit   8\r
74 #define UART_RunBit        7\r
75 #define UART_LoopBackBit   6\r
76 #define UART_ParityOddBit  5\r
77 #define UART_StopBits      3\r
78 \r
79 // Stop bits definition\r
80 #define UART_05StopBits     0x00\r
81 #define UART_1StopBit       (0x01<<3)\r
82 #define UART_15StopBits     (0x02<<3)\r
83 #define UART_2StopBits      (0x03<<3)\r
84 \r
85 // Modes definition\r
86 #define UART_8BitsData       0x01\r
87 #define UART_7BitsData       0x03\r
88 #define UART_9BitsData       0x04\r
89 #define UART_8BitsDataWakeUp 0x05\r
90 #define UART_8BitsDataParity 0x07\r
91 \r
92 /*******************************************************************************\r
93 * Function Name  : UART_Init\r
94 * Description    : This function initializes the selected UART.\r
95 * Input 1        : UARTx (x can be 0,1, 2 or 3) the desired UART\r
96 * Output         : None\r
97 * Return         : None\r
98 *******************************************************************************/\r
99 void UART_Init(UART_TypeDef *UARTx);\r
100 \r
101 /*******************************************************************************\r
102 * Function Name  : UART_ModeConfig\r
103 * Description    : This function configures the mode of the selected UART.\r
104 * Input 1        : UARTx (x can be 0,1, 2 or 3) the desired UART\r
105 * Input 2        : The UART mode\r
106 * Output         : None\r
107 * Return         : None\r
108 *******************************************************************************/\r
109 inline void UART_ModeConfig(UART_TypeDef *UARTx, UARTMode_TypeDef UART_Mode)\r
110 {\r
111   UARTx->CR = (UARTx->CR&0xFFF8)|(u16)UART_Mode;\r
112 }\r
113 \r
114 /*******************************************************************************\r
115 * Function Name  : UART_BaudRateConfig\r
116 * Description    : This function configures the baud rate of the selected UART.\r
117 * Input 1        : UARTx (x can be 0,1, 2 or 3) the desired UART\r
118 * Input 2        : The baudrate value\r
119 * Output         : None\r
120 * Return         : None\r
121 *******************************************************************************/\r
122 void UART_BaudRateConfig(UART_TypeDef *UARTx, u32 BaudRate);\r
123 \r
124 /*******************************************************************************\r
125 * Function Name  : UART_ParityConfig\r
126 * Description    : This function configures the data parity of the selected UART.\r
127 * Input 1        : UARTx (x can be 0,1, 2 or 3) the desired UART\r
128 * Input 2        : The parity type\r
129 * Output         : None\r
130 * Return         : None\r
131 *******************************************************************************/\r
132 inline void UART_ParityConfig(UART_TypeDef *UARTx, UARTParity_TypeDef Parity)\r
133 {\r
134   UARTx->CR = (UARTx->CR&0xFFDF)|(u16)Parity;\r
135 }\r
136 \r
137 /*******************************************************************************\r
138 * Function Name  : UART_StopBitsConfig\r
139 * Description    : This function configures the number of stop bits of the\r
140 *                  selected UART.\r
141 * Input 1        : UARTx (x can be 0,1, 2 or 3) the desired UART\r
142 * Input 2        : The number of stop bits\r
143 * Output         : None\r
144 * Return         : None\r
145 *******************************************************************************/\r
146 inline void UART_StopBitsConfig(UART_TypeDef *UARTx, UARTStopBits_TypeDef StopBits)\r
147 {\r
148   UARTx->CR = (UARTx->CR&0xFFE7)|(u16)StopBits;\r
149 }\r
150 \r
151 /*******************************************************************************\r
152 * Function Name  : UART_Config\r
153 * Description    : This function configures the baudrate, the mode, the data\r
154 *                  parity and the number of stop bits of the selected UART.\r
155 * Input 1        : UARTx (x can be 0,1, 2 or 3) the desired UART\r
156 * Input 2        : The baudrate value\r
157 * Input 3        : The parity type\r
158 * Input 4        : The number of stop bits\r
159 * Input 5        : The UART mode\r
160 * Output         : None\r
161 * Return         : None\r
162 *******************************************************************************/\r
163 void UART_Config(UART_TypeDef *UARTx, u32 BaudRate, UARTParity_TypeDef Parity,\r
164                  UARTStopBits_TypeDef StopBits, UARTMode_TypeDef Mode);\r
165 \r
166 /*******************************************************************************\r
167 * Function Name  : UART_ItConfig\r
168 * Description    : This function enables or disables the interrupts of the\r
169 *                  selected UART.\r
170 * Input 1        : UARTx (x can be 0,1, 2 or 3) the desired UART\r
171 * Input 2        : The new interrupt flag\r
172 * Input 3        : ENABLE or DISABLE\r
173 * Output         : None\r
174 * Return         : None\r
175 *******************************************************************************/\r
176 void UART_ItConfig(UART_TypeDef *UARTx, u16 UART_Flag, FunctionalState NewState);\r
177 \r
178 /*******************************************************************************\r
179 * Function Name  : UART_FifoConfig\r
180 * Description    : This function enables or disables the Rx and Tx FIFOs of\r
181 *                  the selected UART.\r
182 * Input 1        : UARTx (x can be 0,1, 2 or 3) the desired UART\r
183 * Input 2        : ENABLE or DISABLE\r
184 * Output         : None\r
185 * Return         : None\r
186 *******************************************************************************/\r
187 void UART_FifoConfig(UART_TypeDef *UARTx, FunctionalState NewState);\r
188 \r
189 /*******************************************************************************\r
190 * Function Name  : UART_FifoReset\r
191 * Description    : This function resets the Rx and the Tx FIFOs of the\r
192 *                  selected UART.\r
193 * Input 1        : UARTx (x can be 0,1, 2 or 3) the desired UART\r
194 * Input 2        : RxFIFO or TxFIFO\r
195 * Output         : None\r
196 * Return         : None\r
197 *******************************************************************************/\r
198 void UART_FifoReset(UART_TypeDef *UARTx, UARTFIFO_TypeDef FIFO);\r
199 \r
200 /*******************************************************************************\r
201 * Function Name  : UART_LoopBackConfig\r
202 * Description    : This function enables or disables the loop back mode of\r
203 *                  the selected UART.\r
204 * Input 1        : UARTx (x can be 0,1, 2 or 3) the desired UART\r
205 * Input 2        : ENABLE or DISABLE\r
206 * Output         : None\r
207 * Return         : None\r
208 *******************************************************************************/\r
209 void UART_LoopBackConfig(UART_TypeDef *UARTx, FunctionalState NewState);\r
210 \r
211 /*******************************************************************************\r
212 * Function Name  : UART_TimeOutPeriodConfig\r
213 * Description    : This function configure the Time Out Period.\r
214 * Input 1        : UARTx (x can be 0,1, 2 or 3) the desired UART\r
215 * Input 2        : The time-out period value\r
216 * Output         : None\r
217 * Return         : None\r
218 *******************************************************************************/\r
219 inline void UART_TimeOutPeriodConfig(UART_TypeDef *UARTx, u16 TimeOutPeriod)\r
220 {\r
221   UARTx->TOR = TimeOutPeriod;\r
222 }\r
223 \r
224 /*******************************************************************************\r
225 * Function Name  : UART_GuardTimeConfig\r
226 * Description    : This function configure the Guard Time.\r
227 * Input 1        : UARTx (x can be 0,1, 2 or 3) the desired UART\r
228 * Input 2        : The guard time value\r
229 * Output         : None\r
230 * Return         : None\r
231 *******************************************************************************/\r
232 inline void UART_GuardTimeConfig(UART_TypeDef *UARTx, u16 GuardTime)\r
233 {\r
234   UARTx->GTR = GuardTime;\r
235 }\r
236 \r
237 /*******************************************************************************\r
238 * Function Name  : UART_RxConfig\r
239 * Description    : This function enable and disable the UART data reception.\r
240 * Input 1        : UARTx (x can be 0,1, 2 or 3) the desired UART\r
241 * Input 2        : ENABLE or DISABLE\r
242 * Output         : None\r
243 * Return         : None\r
244 *******************************************************************************/\r
245 void UART_RxConfig(UART_TypeDef *UARTx, FunctionalState NewState);\r
246 \r
247 /*******************************************************************************\r
248 * Function Name  : UART_OnOffConfig\r
249 * Description    : This function sets On/Off the selected UART.\r
250 * Input 1        : UARTx (x can be 0,1, 2 or 3) the desired UART\r
251 * Input 2        : ENABLE or DISABLE\r
252 * Output         : None\r
253 * Return         : None\r
254 *******************************************************************************/\r
255 void UART_OnOffConfig(UART_TypeDef *UARTx, FunctionalState NewState);\r
256 \r
257 /*******************************************************************************\r
258 * Function Name  : UART_ByteSend\r
259 * Description    : This function sends a data byte to the selected UART.\r
260 * Input 1        : UARTx (x can be 0,1, 2 or 3) the desired UART\r
261 * Input 2        : A pointer to the data byte to send\r
262 * Output         : None\r
263 * Return         : None\r
264 *******************************************************************************/\r
265 void UART_ByteSend(UART_TypeDef *UARTx, u8 *Data);\r
266 \r
267 /*******************************************************************************\r
268 * Function Name  : UART_9BitByteSend\r
269 * Description    : This function sends a 9 bits data byte to the selected UART.\r
270 * Input 1        : UARTx (x can be 0,1, 2 or 3) the desired UART\r
271 * Input 2        : A pointer to the data to send\r
272 * Output         : None\r
273 * Return         : None\r
274 *******************************************************************************/\r
275 void UART_9BitByteSend(UART_TypeDef *UARTx, u16 *Data);\r
276 \r
277 /*******************************************************************************\r
278 * Function Name  : UART_DataSend\r
279 * Description    : This function sends several data bytes to the selected UART.\r
280 * Input 1        : UARTx (x can be 0,1, 2 or 3) the desired UART\r
281 * Input 2        : A pointer to the data to send\r
282 * Input 3        : The data length in bytes\r
283 * Output         : None\r
284 * Return         : None\r
285 *******************************************************************************/\r
286 void UART_DataSend(UART_TypeDef *UARTx, u8 *Data, u8 DataLength);\r
287 \r
288 /*******************************************************************************\r
289 * Function Name  : UART_9BitDataSend\r
290 * Description    : This function sends several 9 bits data bytes to the selected UART.\r
291 * Input 1        : UARTx (x can be 0,1, 2 or 3) the desired UART\r
292 * Input 2        : A pointer to the data to send\r
293 * Input 3        : The data length\r
294 * Output         : None\r
295 * Return         : None\r
296 *******************************************************************************/\r
297 void UART_9BitDataSend(UART_TypeDef *UARTx, u16 *Data, u8 DataLength);\r
298 \r
299 /*******************************************************************************\r
300 * Function Name  : UART_StringSend\r
301 * Description    : This function sends a string to the selected UART.\r
302 * Input 1        : UARTx (x can be 0,1, 2 or 3) the desired UART\r
303 * Input 2        : A pointer to the string to send\r
304 * Output         : None\r
305 * Return         : None\r
306 *******************************************************************************/\r
307 void UART_StringSend(UART_TypeDef *UARTx, u8 *String);\r
308 \r
309 /*******************************************************************************\r
310 * Function Name  : UART_ByteReceive\r
311 * Description    : This function gets a data byte from the selected UART.\r
312 * Input 1        : UARTx (x can be 0,1, 2 or 3) the desired UART\r
313 * Input 2        : A pointer to the buffer where the data will be stored\r
314 * Input 3        : The time-out period\r
315 * Output         : The received data\r
316 * Return         : The UARTx.SR register contents\r
317 *******************************************************************************/\r
318 u16 UART_ByteReceive(UART_TypeDef *UARTx, u8 *Data, u8 TimeOut);\r
319 \r
320 /*******************************************************************************\r
321 * Function Name  : UART_9BitByteReceive\r
322 * Description    : This function gets a 9 bits data byte from the selected UART.\r
323 * Input 1        : UARTx (x can be 0,1, 2 or 3) the desired UART\r
324 * Input 2        : A pointer to the buffer where the data will be stored\r
325 * Input 3        : The time-out period value\r
326 * Output         : The received data\r
327 * Return         : The UARTx.SR register contents\r
328 *******************************************************************************/\r
329 u16 UART_9BitByteReceive(UART_TypeDef *UARTx, u16 *Data, u8 TimeOut);\r
330 \r
331 /*******************************************************************************\r
332 * Function Name  : UART_DataReceive\r
333 * Description    : This function gets 8 bits data bytes from the selected UART.\r
334 * Input 1        : UARTx (x can be 0,1, 2 or 3) the desired UART\r
335 * Input 2        : A pointer to the buffer where the data will be stored\r
336 * Input 3        : The data length\r
337 * Input 4        : The time-out period value\r
338 * Output         : The received data\r
339 * Return         : The UARTx.SR register contents\r
340 *******************************************************************************/\r
341 u16 UART_DataReceive(UART_TypeDef *UARTx, u8 *Data, u8 DataLength, u8 TimeOut);\r
342 \r
343 /*******************************************************************************\r
344 * Function Name  : UART_9BitDataReceive\r
345 * Description    : This function gets 9 bits data bytes from the selected UART.\r
346 * Input 1        : UARTx (x can be 0,1, 2 or 3) the desired UART\r
347 * Input 2        : A pointer to the buffer where the data will be stored\r
348 * Input 3        : The data length\r
349 * Input 4        : The time-out value\r
350 * Output         : The received data\r
351 * Return         : The UARTx.SR register contents\r
352 *******************************************************************************/\r
353 u16 UART_9BitDataReceive(UART_TypeDef *UARTx, u16 *Data, u8 DataLength, u8 TimeOut);\r
354 \r
355 /*******************************************************************************\r
356 * Function Name  : UART_StringReceive\r
357 * Description    : This function gets 8 bits data bytes from the selected UART.\r
358 * Input 1        : UARTx (x can be 0,1, 2 or 3) the desired UART\r
359 * Input 2        : A pointer to the buffer where the string will be stored\r
360 * Output         : None\r
361 * Return         : None\r
362 *******************************************************************************/\r
363 u16 UART_StringReceive(UART_TypeDef *UARTx, u8 *Data);\r
364 \r
365 /*******************************************************************************\r
366 * Function Name  : UART_FlagStatus\r
367 * Description    : This function gets the flags status of the selected UART.\r
368 * Input 1        : UARTx (x can be 0,1, 2 or 3) the desired UART\r
369 * Output         : None\r
370 * Return         : None\r
371 *******************************************************************************/\r
372 inline u16 UART_FlagStatus(UART_TypeDef *UARTx)\r
373 {\r
374   return UARTx->SR;\r
375 }\r
376 \r
377 #ifdef USE_SERIAL_PORT\r
378 /*******************************************************************************\r
379 * Function Name  : sendchar\r
380 * Description    : This function sends a character to the selected UART.\r
381 * Input 1        : A pointer to the character to send.\r
382 * Output         : None\r
383 * Return         : None\r
384 *******************************************************************************/\r
385 void sendchar( char *ch );\r
386 #endif /* USE_SERIAL_PORT */\r
387 \r
388 #endif /* _UART_H */\r
389 \r
390 /******************* (C) COPYRIGHT 2003 STMicroelectronics *****END OF FILE****/\r