1 /******************** (C) COPYRIGHT 2003 STMicroelectronics ********************
\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
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
23 #include "71x_map.h"
\r
34 UART_EVEN_PARITY = 0x0000,
\r
35 UART_ODD_PARITY = 0x0020,
\r
37 } UARTParity_TypeDef;
\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
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
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
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
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
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
98 *******************************************************************************/
\r
99 void UART_Init(UART_TypeDef *UARTx);
\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
108 *******************************************************************************/
\r
109 inline void UART_ModeConfig(UART_TypeDef *UARTx, UARTMode_TypeDef UART_Mode)
\r
111 UARTx->CR = (UARTx->CR&0xFFF8)|(u16)UART_Mode;
\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
121 *******************************************************************************/
\r
122 void UART_BaudRateConfig(UART_TypeDef *UARTx, u32 BaudRate);
\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
131 *******************************************************************************/
\r
132 inline void UART_ParityConfig(UART_TypeDef *UARTx, UARTParity_TypeDef Parity)
\r
134 UARTx->CR = (UARTx->CR&0xFFDF)|(u16)Parity;
\r
137 /*******************************************************************************
\r
138 * Function Name : UART_StopBitsConfig
\r
139 * Description : This function configures the number of stop bits of the
\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
145 *******************************************************************************/
\r
146 inline void UART_StopBitsConfig(UART_TypeDef *UARTx, UARTStopBits_TypeDef StopBits)
\r
148 UARTx->CR = (UARTx->CR&0xFFE7)|(u16)StopBits;
\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
162 *******************************************************************************/
\r
163 void UART_Config(UART_TypeDef *UARTx, u32 BaudRate, UARTParity_TypeDef Parity,
\r
164 UARTStopBits_TypeDef StopBits, UARTMode_TypeDef Mode);
\r
166 /*******************************************************************************
\r
167 * Function Name : UART_ItConfig
\r
168 * Description : This function enables or disables the interrupts of the
\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
175 *******************************************************************************/
\r
176 void UART_ItConfig(UART_TypeDef *UARTx, u16 UART_Flag, FunctionalState NewState);
\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
186 *******************************************************************************/
\r
187 void UART_FifoConfig(UART_TypeDef *UARTx, FunctionalState NewState);
\r
189 /*******************************************************************************
\r
190 * Function Name : UART_FifoReset
\r
191 * Description : This function resets the Rx and the Tx FIFOs of the
\r
193 * Input 1 : UARTx (x can be 0,1, 2 or 3) the desired UART
\r
194 * Input 2 : RxFIFO or TxFIFO
\r
197 *******************************************************************************/
\r
198 void UART_FifoReset(UART_TypeDef *UARTx, UARTFIFO_TypeDef FIFO);
\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
208 *******************************************************************************/
\r
209 void UART_LoopBackConfig(UART_TypeDef *UARTx, FunctionalState NewState);
\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
218 *******************************************************************************/
\r
219 inline void UART_TimeOutPeriodConfig(UART_TypeDef *UARTx, u16 TimeOutPeriod)
\r
221 UARTx->TOR = TimeOutPeriod;
\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
231 *******************************************************************************/
\r
232 inline void UART_GuardTimeConfig(UART_TypeDef *UARTx, u16 GuardTime)
\r
234 UARTx->GTR = GuardTime;
\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
244 *******************************************************************************/
\r
245 void UART_RxConfig(UART_TypeDef *UARTx, FunctionalState NewState);
\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
254 *******************************************************************************/
\r
255 void UART_OnOffConfig(UART_TypeDef *UARTx, FunctionalState NewState);
\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
264 *******************************************************************************/
\r
265 void UART_ByteSend(UART_TypeDef *UARTx, u8 *Data);
\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
274 *******************************************************************************/
\r
275 void UART_9BitByteSend(UART_TypeDef *UARTx, u16 *Data);
\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
285 *******************************************************************************/
\r
286 void UART_DataSend(UART_TypeDef *UARTx, u8 *Data, u8 DataLength);
\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
296 *******************************************************************************/
\r
297 void UART_9BitDataSend(UART_TypeDef *UARTx, u16 *Data, u8 DataLength);
\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
306 *******************************************************************************/
\r
307 void UART_StringSend(UART_TypeDef *UARTx, u8 *String);
\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
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
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
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
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
362 *******************************************************************************/
\r
363 u16 UART_StringReceive(UART_TypeDef *UARTx, u8 *Data);
\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
371 *******************************************************************************/
\r
372 inline u16 UART_FlagStatus(UART_TypeDef *UARTx)
\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
384 *******************************************************************************/
\r
385 void sendchar( char *ch );
\r
386 #endif /* USE_SERIAL_PORT */
\r
388 #endif /* _UART_H */
\r
390 /******************* (C) COPYRIGHT 2003 STMicroelectronics *****END OF FILE****/
\r