]> begriffs open source - cmsis/blob - CMSIS/DoxyGen/Driver/src/Driver_USART.c
CMSIS-Core(A): Core Register documentation.
[cmsis] / CMSIS / DoxyGen / Driver / src / Driver_USART.c
1 /* -----------------------------------------------------------------------------
2  * Copyright (c) 2013-2014 ARM Limited. All rights reserved.
3  *  
4  * $Date:        2. January 2014
5  * $Revision:    V2.00
6  *  
7  * Project:      USART Driver API
8  * -------------------------------------------------------------------------- */
9
10
11 /**
12 \defgroup usart_interface_gr USART Interface
13 \brief   Driver API for Universal Synchronous Asynchronous Receiver/Transmitter (%Driver_USART.h)
14 \details 
15 The <b>Universal Synchronous Asynchronous Receiver/Transmitter</b> (USART) implements a synchronous and asynchronous serial bus for exchanging data. 
16 When only asynchronous mode is supported it is called Universal Asynchronous Receiver/Transmitter (UART).  
17 Almost all microcontrollers have a serial interface (UART/USART peripheral). A UART is a simple device to send data to a PC
18 via a terminal emulation program (Hyperterm, TeraTerm) or to another microcontroller.
19 A UART takes bytes of data and transmits the individual bits in a sequential mode. At the destination, 
20 a second UART reassembles the bits into complete bytes. Each UART contains a shift register for converting between serial and parallel transmission forms. 
21 Wikipedia offers more information about  
22 the <a href="http://en.wikipedia.org/wiki/Universal_asynchronous_receiver/transmitter" target="_blank"><b>Universal asynchronous receiver/transmitter</b></a>.
23
24
25 <b>USART API</b>
26
27 The following header files define the Application Programming Interface (API) for the USART interface:
28   - \b %Driver_USART.h : Driver API for Universal Synchronous Asynchronous Receiver/Transmitter
29
30 The driver implementation is a typical part of the Device Family Pack (DFP) that supports the 
31 peripherals of the microcontroller family.
32
33
34 <b>Driver Functions</b>
35
36 The driver functions are published in the access struct as explained in \ref DriverFunctions
37   - \ref ARM_DRIVER_USART : access struct for USART driver functions
38
39   
40 <b>Example Code</b>
41
42 The following example code shows the usage of the USART interface for asynchronous communication.
43
44 \include USART_Demo.c
45
46 @{
47 */
48
49 /** 
50 \struct     ARM_DRIVER_USART
51 \details
52 The functions of the USART driver are accessed by function pointers exposed by this structure.
53 Refer to \ref DriverFunctions for overview information.
54
55 Each instance of an USART interface provides such an access structure. 
56 The instance is identified by a postfix number in the symbol name of the access structure, for example:
57  - \b Driver_USART0 is the name of the access struct of the first instance (no. 0).
58  - \b Driver_USART1 is the name of the access struct of the second instance (no. 1).
59
60 A middleware configuration setting allows connecting the middleware to a specific driver instance \b %Driver_USART<i>n</i>.
61 The default is \token{0}, which connects a middleware to the first instance of a driver.
62 *****************************************************************************************************************/
63
64 /**
65 \struct     ARM_USART_CAPABILITIES 
66 \details
67 An USART driver can be implemented with different capabilities.
68 The data fields of this structure encode the capabilities implemented by this driver.
69
70 <b>Returned by:</b>
71   - \ref ARM_USART_GetCapabilities
72 *****************************************************************************************************************/
73
74 /**
75 \struct     ARM_USART_STATUS
76 \details
77 Structure with information about the status of the USART. The data fields encode busy flags and error flags.
78
79 <b>Returned by:</b>
80   - \ref ARM_USART_GetStatus
81 *****************************************************************************************************************/
82
83 /**
84 \enum     ARM_USART_MODEM_CONTROL
85 \details
86 Specifies values for controlling the modem control lines.
87
88 <b>Parameter for:</b>
89   - \ref ARM_USART_SetModemControl
90 *****************************************************************************************************************/
91
92 /**
93 \struct     ARM_USART_MODEM_STATUS 
94 \details
95 Structure with information about the status of modem lines. The data fields encode states of modem status lines.
96
97 <b>Returned by:</b>
98   - \ref ARM_USART_GetModemStatus
99 *****************************************************************************************************************/
100
101
102 /**
103 \typedef    ARM_USART_SignalEvent_t
104 \details
105 Provides the typedef for the callback function \ref ARM_USART_SignalEvent.
106
107 <b>Parameter for:</b>
108   - \ref ARM_USART_Initialize
109 *******************************************************************************************************************/
110
111
112 /**
113 \defgroup usart_execution_status Status Error Codes
114 \ingroup common_drv_gr
115 \brief Negative values indicate errors (USART has specific codes in addition to common \ref execution_status). 
116 \details 
117 The USART driver has additional status error codes that are listed below.
118 Note that the USART driver also returns the common \ref execution_status. 
119   
120 @{
121 \def ARM_USART_ERROR_MODE
122 The \b mode requested with the function \ref ARM_USART_Control is not supported by this driver.
123
124 \def ARM_USART_ERROR_BAUDRATE
125 The <b>baude rate</b> requested with the function \ref ARM_USART_Control is not supported by this driver.
126
127 \def ARM_USART_ERROR_DATA_BITS
128 The number of <b>data bits</b> requested with the function \ref ARM_USART_Control is not supported by this driver.
129
130 \def ARM_USART_ERROR_PARITY
131 The <b>parity bit</b> requested with the function \ref ARM_USART_Control is not supported by this driver.
132
133 \def ARM_USART_ERROR_STOP_BITS
134 The <b>stop bit</b> requested with the function \ref ARM_USART_Control is not supported by this driver.
135
136 \def ARM_USART_ERROR_FLOW_CONTROL
137 The <b>flow control</b> requested with the function \ref ARM_USART_Control is not supported by this driver.
138
139 \def ARM_USART_ERROR_CPOL
140 The <b>clock polarity</b> requested with the function \ref ARM_USART_Control is not supported by this driver.
141
142 \def ARM_USART_ERROR_CPHA
143 The <b>clock phase</b> requested with the function \ref ARM_USART_Control is not supported by this driver.
144 @}
145 */
146
147
148 /**
149 \defgroup USART_events USART Events
150 \ingroup usart_interface_gr
151 \brief The USART driver generates call back events that are notified via the function \ref ARM_USART_SignalEvent.
152 \details 
153 This section provides the event values for the \ref ARM_USART_SignalEvent callback function.
154
155 The following call back notification events are generated:
156 @{
157 \def ARM_USART_EVENT_SEND_COMPLETE
158 \def ARM_USART_EVENT_RECEIVE_COMPLETE
159 \def ARM_USART_EVENT_TRANSFER_COMPLETE
160 \def ARM_USART_EVENT_TX_COMPLETE
161 \def ARM_USART_EVENT_TX_UNDERFLOW
162 \def ARM_USART_EVENT_RX_OVERFLOW
163 \def ARM_USART_EVENT_RX_TIMEOUT
164 \def ARM_USART_EVENT_RX_BREAK
165 \def ARM_USART_EVENT_RX_FRAMING_ERROR
166 \def ARM_USART_EVENT_RX_PARITY_ERROR
167 \def ARM_USART_EVENT_CTS
168 \def ARM_USART_EVENT_DSR
169 \def ARM_USART_EVENT_DCD
170 \def ARM_USART_EVENT_RI
171 @}
172 */
173
174
175 /**
176 \defgroup USART_control USART Control Codes
177 \ingroup usart_interface_gr
178 \brief Many parameters of the USART driver are configured using the \ref ARM_USART_Control function.
179 \details
180 @{
181 The various USART control codes define:
182   - \ref usart_mode_control specifies USART mode
183   - \ref usart_data_bits defines the number of data bits
184   - \ref usart_parity_bit defines the parity bit
185   - \ref usart_stop_bits defines the number of stop bits
186   - \ref usart_flow_control specifies RTS/CTS flow control
187   - \ref usart_clock_polarity defines the clock polarity for the synchronous mode
188   - \ref usart_clock_phase defines the clock phase for the synchronous mode
189   - \ref usart_misc_control specifies additional miscellaneous controls
190
191 Refer to the \ref ARM_USART_Control function for further details.
192
193 */
194
195
196 /**
197 \defgroup usart_mode_control USART Mode Control
198 \ingroup USART_control
199 \brief Specify USART mode.
200 \details
201 @{
202 \def ARM_USART_MODE_ASYNCHRONOUS
203 \sa ARM_USART_Control
204 \def ARM_USART_MODE_SYNCHRONOUS_MASTER
205 \sa ARM_USART_Control
206 \def ARM_USART_MODE_SYNCHRONOUS_SLAVE
207 \sa ARM_USART_Control
208 \def ARM_USART_MODE_SINGLE_WIRE
209 \sa ARM_USART_Control
210 \def ARM_USART_MODE_IRDA
211 \sa ARM_USART_Control
212 \def ARM_USART_MODE_SMART_CARD
213 \sa ARM_USART_Control
214 @}
215 */
216
217
218 /**
219 \defgroup usart_misc_control USART Miscellaneous Control
220 \ingroup USART_control
221 \brief Specifies additional miscellaneous controls.
222 \details
223 @{
224 \def ARM_USART_SET_DEFAULT_TX_VALUE
225 \sa ARM_USART_Control;  ARM_USART_Receive;
226 \def ARM_USART_SET_IRDA_PULSE
227 \sa ARM_USART_Control
228 \def ARM_USART_SET_SMART_CARD_GUARD_TIME
229 \sa ARM_USART_Control
230 \def ARM_USART_SET_SMART_CARD_CLOCK
231 \sa ARM_USART_Control
232 \def ARM_USART_CONTROL_SMART_CARD_NACK
233 \sa ARM_USART_Control
234 \def ARM_USART_CONTROL_TX
235 \sa ARM_USART_Control;  ARM_USART_Send;  ARM_USART_Transfer
236 \def ARM_USART_CONTROL_RX
237 \sa ARM_USART_Control;  ARM_USART_Receive; ARM_USART_Transfer; 
238 \def ARM_USART_CONTROL_BREAK
239 \sa ARM_USART_Control
240 \def ARM_USART_ABORT_SEND
241 \sa ARM_USART_Control;
242 \def ARM_USART_ABORT_RECEIVE
243 \sa ARM_USART_Control;
244 \def ARM_USART_ABORT_TRANSFER
245 \sa ARM_USART_Control;
246 @}
247 */
248
249 /**
250 \defgroup usart_data_bits  USART Data Bits
251 \ingroup USART_control
252 \brief Defines the number of data bits.
253 \details
254 @{
255 \def ARM_USART_DATA_BITS_5
256 \sa ARM_USART_Control
257 \def ARM_USART_DATA_BITS_6
258 \sa ARM_USART_Control
259 \def ARM_USART_DATA_BITS_7
260 \sa ARM_USART_Control
261 \def ARM_USART_DATA_BITS_8
262 \sa ARM_USART_Control
263 \def ARM_USART_DATA_BITS_9
264 \sa ARM_USART_Control
265 @}
266 */
267
268 /**
269 \defgroup usart_parity_bit  USART Parity Bit
270 \ingroup USART_control
271 \brief Defines the parity bit.
272 \details
273 @{
274 \def ARM_USART_PARITY_NONE
275 \sa ARM_USART_Control
276 \def ARM_USART_PARITY_EVEN
277 \sa ARM_USART_Control
278 \def ARM_USART_PARITY_ODD
279 \sa ARM_USART_Control
280 @}
281 */
282
283 /**
284 \defgroup usart_stop_bits  USART Stop Bits
285 \ingroup USART_control
286 \brief Defines the number of stop bits.
287 \details
288 @{
289 \sa ARM_USART_Control
290 \def ARM_USART_STOP_BITS_1
291 \sa ARM_USART_Control
292 \def ARM_USART_STOP_BITS_2
293 \sa ARM_USART_Control
294 \def ARM_USART_STOP_BITS_1_5
295 \sa ARM_USART_Control
296 \def ARM_USART_STOP_BITS_0_5
297 \sa ARM_USART_Control
298 @}
299 */
300
301 /**
302 \defgroup usart_flow_control USART Flow Control
303 \ingroup USART_control
304 \brief Specifies RTS/CTS flow control.
305 \details
306 @{
307 \def ARM_USART_FLOW_CONTROL_NONE
308 \sa ARM_USART_Control
309 \def ARM_USART_FLOW_CONTROL_RTS
310 \sa ARM_USART_Control
311 \def ARM_USART_FLOW_CONTROL_CTS
312 \sa ARM_USART_Control
313 \def ARM_USART_FLOW_CONTROL_RTS_CTS
314 \sa ARM_USART_Control
315 @}
316 */
317
318 /**
319 \defgroup usart_clock_polarity USART Clock Polarity
320 \ingroup USART_control
321 \brief Defines the clock polarity for the synchronous mode.
322 \details
323 @{
324 \def ARM_USART_CPOL0
325 \sa ARM_USART_Control; ARM_USART_Receive; ARM_USART_Send;  ARM_USART_Transfer
326 \def ARM_USART_CPOL1
327 \sa ARM_USART_Control; ARM_USART_Receive; ARM_USART_Send;  ARM_USART_Transfer
328 @}
329 */
330
331 /**
332 \defgroup usart_clock_phase USART Clock Phase 
333 \ingroup USART_control
334 \brief Defines the clock phase for the synchronous mode.
335 \details
336 @{
337 \def ARM_USART_CPHA0
338 \sa ARM_USART_Control; ARM_USART_Receive; ARM_USART_Send;  ARM_USART_Transfer
339 \def ARM_USART_CPHA1
340 \sa ARM_USART_Control; ARM_USART_Receive; ARM_USART_Send;  ARM_USART_Transfer
341 @}
342 */
343
344 /**
345 @}
346 */
347 // end group USART_control
348
349
350 //
351 //   Functions
352 //
353
354 ARM_DRIVER_VERSION ARM_USART_GetVersion (void)  {
355   return { 0, 0 };
356 }
357 /**
358 \fn     ARM_DRIVER_VERSION ARM_USART_GetVersion (void)
359 \details
360 The function \b ARM_USART_GetVersion returns version information of the driver implementation in \ref ARM_DRIVER_VERSION
361  - API version is the version of the CMSIS-Driver specification used to implement this driver.
362  - Driver version is source code version of the actual driver implementation.
363
364 Example:
365 \code
366 extern ARM_DRIVER_USART Driver_USART0;
367 ARM_DRIVER_USART *drv_info;
368  
369 void setup_usart (void)  {
370   ARM_DRIVER_VERSION  version;
371  
372   drv_info = &Driver_USART0;  
373   version = drv_info->GetVersion ();
374   if (version.api < 0x10A)  {      // requires at minimum API version 1.10 or higher
375     // error handling
376     return;
377   }
378 }
379 \endcode
380 *****************************************************************************************************************/
381
382 ARM_USART_CAPABILITIES ARM_USART_GetCapabilities (void)  {
383   return  { 0 } ;
384 }
385 /**
386 \fn       ARM_USART_CAPABILITIES ARM_USART_GetCapabilities (void)
387 \details
388 The function \b ARM_USART_GetCapabilities returns information about capabilities in this driver implementation.
389 The data fields of the structure \ref ARM_USART_CAPABILITIES encode various capabilities, for example
390 supported modes, if a hardware is capable to create signal events using the \ref ARM_USART_SignalEvent 
391 callback function ...
392  
393 Example:
394 \code
395 extern ARM_DRIVER_USART Driver_USART0;
396 ARM_DRIVER_USART *drv_info;
397   
398 void read_capabilities (void)  {
399   ARM_USART_CAPABILITIES drv_capabilities;
400  
401   drv_info = &Driver_USART0;  
402   drv_capabilities = drv_info->GetCapabilities ();
403   // interrogate capabilities
404  
405 }
406 \endcode
407 *****************************************************************************************************************/
408
409 int32_t ARM_USART_Initialize (ARM_USART_SignalEvent_t cb_event)  {
410   return ARM_DRIVER_OK;
411 }
412 /**
413 \fn       int32_t ARM_USART_Initialize (ARM_USART_SignalEvent_t cb_event)
414 \details
415 The function \b ARM_USART_Initialize initializes the USART interface. 
416 It is called when the middleware component starts operation.
417
418 The function performs the following operations:
419   - Initializes the resources needed for the USART interface.
420   - Registers the \ref ARM_USART_SignalEvent callback function.
421
422 The parameter \em cb_event is a pointer to the \ref ARM_USART_SignalEvent callback function; use a NULL pointer 
423 when no callback signals are required.
424
425 \b Example:
426  - see \ref usart_interface_gr - Driver Functions
427
428 *****************************************************************************************************************/
429
430 int32_t ARM_USART_Uninitialize (void)  {
431   return ARM_DRIVER_OK;
432 }
433 /**
434 \fn       int32_t ARM_USART_Uninitialize (void)
435 \details
436 The function \b ARM_USART_Uninitialize de-initializes the resources of USART interface.
437
438 It is called when the middleware component stops operation and releases the software resources used by the interface.
439 *****************************************************************************************************************/
440
441 int32_t ARM_USART_PowerControl (ARM_POWER_STATE state)  {
442   return ARM_DRIVER_OK;
443 }
444 /**
445 \fn int32_t ARM_USART_PowerControl (ARM_POWER_STATE state)
446 \details
447 The function \b ARM_USART_PowerControl operates the power modes of the USART interface.  
448
449 The parameter \em state sets the operation and can have the following values:
450   - \ref ARM_POWER_FULL : set-up peripheral for data transfers, enable interrupts (NVIC) and optionally DMA. 
451                           Can be called multiple times. If the peripheral is already in this mode the function performs 
452                                                   no operation and returns with \ref ARM_DRIVER_OK.
453   - \ref ARM_POWER_LOW : may use power saving. Returns \ref ARM_DRIVER_ERROR_UNSUPPORTED when not implemented.
454   - \ref ARM_POWER_OFF : terminates any pending data transfers, disables peripheral, disables related interrupts and DMA.
455       
456 Refer to \ref CallSequence for more information.
457
458 *****************************************************************************************************************/
459
460 int32_t ARM_USART_Send (const void *data, uint32_t num)  {
461   return ARM_DRIVER_OK;
462 }
463 /**
464 \fn int32_t ARM_USART_Send (const void *data, uint32_t num) 
465 \details
466 This functions \b ARM_USART_Send is used in asynchronous mode to send data to the USART transmitter.
467 It can also be used in synchronous mode when sending data only (received data is ignored). 
468
469 Transmitter needs to be enabled by calling \ref ARM_USART_Control with \ref ARM_USART_CONTROL_TX as the control parameter and \token{1} as argument. 
470
471 The function parameters specify the buffer with data and the number of items to send.
472 The item size is defined by the data type which depends on the configured number of data bits.
473
474 Data type is:
475  - \em uint8_t when configured for 5..8 data bits
476  - \em uint16_t when configured for 9 data bits
477  
478 Calling the function <b>ARM_USART_Send</b> only starts the send operation.
479 The function is non-blocking and returns as soon as the driver has started the operation (driver typically configures DMA or the interrupt system for continuous transfer).
480 When in synchronous slave mode the operation is only registered and started when the master starts the transfer.
481 During the operation it is not allowed to call this function again or any other data transfer function when in synchronous mode. Also the data buffer must stay allocated and the contents of unsent data must not be modified.
482 When send operation is completed (requested number of items sent) the \ref ARM_USART_EVENT_SEND_COMPLETE event is generated.
483 Progress of send operation can also be monitored by reading the number of items already sent by calling \ref ARM_USART_GetTxCount. 
484
485 After send operation has completed there might still be some data left in the driver's hardware buffer which is still being transmitted.
486 When all data has been physically transmitted the \ref ARM_USART_EVENT_TX_COMPLETE event is generated (if supported and reported by \em event_tx_complete in \ref ARM_USART_CAPABILITIES).
487 At that point also the \em tx_busy data field in \ref ARM_USART_STATUS is cleared.
488
489 Status of the transmitter can be monitored by calling the \ref ARM_USART_GetStatus and checking the \em tx_busy flag
490 which indicates if transmission is still in progress. 
491
492 When in synchronous slave mode and transmitter is enabled but send/receive/transfer operation is not started and data is requested by the master then the \ref ARM_USART_EVENT_TX_UNDERFLOW event is generated. 
493
494 Send operation can be aborted by calling \ref ARM_USART_Control with \ref ARM_USART_ABORT_SEND as the control parameter.
495 *****************************************************************************************************************/
496
497 int32_t ARM_USART_Receive (void *data, uint32_t num)  {
498   return ARM_DRIVER_OK;
499 }
500 /**
501 \fn int32_t ARM_USART_Receive (void *data, uint32_t num)
502 \details
503 This functions \b ARM_USART_Receive is used in asynchronous mode to receive data from the USART receiver.
504 It can also be used in synchronous mode when receiving data only (transmits the default value as specified by \ref ARM_USART_Control with \ref ARM_USART_SET_DEFAULT_TX_VALUE as control parameter). 
505
506 Receiver needs to be enabled by calling \ref ARM_USART_Control with \ref ARM_USART_CONTROL_RX as the control parameter and \token{1} as argument. 
507
508 The function parameters specify the buffer for data and the number of items to receive.
509 The item size is defined by the data type which depends on the configured number of data bits.
510
511 Data type is:
512  - \em uint8_t when configured for 5..8 data bits
513  - \em uint16_t when configured for 9 data bits
514  
515 Calling the function <b>ARM_USART_Receive</b> only starts the receive operation.
516 The function is non-blocking and returns as soon as the driver has started the operation (driver typically configures DMA or the interrupt system for continuous transfer).
517 When in synchronous slave mode the operation is only registered and started when the master starts the transfer.
518 During the operation it is not allowed to call this function again or any other data transfer function when in synchronous mode. Also the data buffer must stay allocated.
519 When receive operation is completed (requested number of items received) the \ref ARM_USART_EVENT_RECEIVE_COMPLETE event is generated.
520 Progress of receive operation can also be monitored by reading the number of items already received by calling \ref ARM_USART_GetRxCount. 
521
522 Status of the receiver can be monitored by calling the \ref ARM_USART_GetStatus and checking the \em rx_busy flag
523 which indicates if reception is still in progress. 
524
525 During reception the following events can be generated (in asynchronous mode):
526  - \ref ARM_USART_EVENT_RX_TIMEOUT : Receive timeout between consecutive characters detected (optional)
527  - \ref ARM_USART_EVENT_RX_BREAK : Break detected (Framing error is not generated for Break condition)
528  - \ref ARM_USART_EVENT_RX_FRAMING_ERROR : Framing error detected
529  - \ref ARM_USART_EVENT_RX_PARITY_ERROR : Parity error detected
530  - \ref ARM_USART_EVENT_RX_OVERFLOW : Data overflow detected (also in synchronous slave mode)
531
532 \ref ARM_USART_EVENT_RX_OVERFLOW event is also generated when receiver is enabled but data is lost because 
533 receive operation in asynchronous mode or receive/send/transfer operation in synchronous slave mode has not been started.
534
535 Receive operation can be aborted by calling \ref ARM_USART_Control with \ref ARM_USART_ABORT_RECEIVE as the control parameter.
536 *****************************************************************************************************************/
537
538 int32_t ARM_USART_Transfer (const void *data_out, void *data_in, uint32_t num) {
539   return ARM_DRIVER_OK;
540 }
541 /**
542 \fn int32_t ARM_USART_Transfer (const void *data_out, void *data_in, uint32_t num) 
543 \details
544 This functions \b ARM_USART_Transfer is used in synchronous mode to transfer data via USART. It synchronously sends data to the USART transmitter and receives data from the USART receiver. 
545
546 Transmitter needs to be enabled by calling \ref ARM_USART_Control with \ref ARM_USART_CONTROL_TX as the control parameter and \token{1} as argument. 
547 Receiver needs to be enabled by calling \ref ARM_USART_Control with \ref ARM_USART_CONTROL_RX as the control parameter and \token{1} as argument. 
548
549 The function parameters specify the buffer with data to send, the buffer for data to receive and the number of items to transfer.
550 The item size is defined by the data type which depends on the configured number of data bits.
551
552 Data type is:
553  - \em uint8_t when configured for 5..8 data bits
554  - \em uint16_t when configured for 9 data bits
555  
556 Calling the function <b>ARM_USART_Transfer</b> only starts the transfer operation.
557 The function is non-blocking and returns as soon as the driver has started the operation (driver typically configures DMA or the interrupt system for continuous transfer).
558 When in synchronous slave mode the operation is only registered and started when the master starts the transfer.
559 During the operation it is not allowed to call this function or any other data transfer function again. Also the data buffers must stay allocated and the contents of unsent data must not be modified.
560 When transfer operation is completed (requested number of items transferred) the \ref ARM_USART_EVENT_TRANSFER_COMPLETE event is generated.
561 Progress of transfer operation can also be monitored by reading the number of items already transferred by calling \ref ARM_USART_GetTxCount or \ref ARM_USART_GetRxCount. 
562
563 Status of the transmitter or receiver can be monitored by calling the \ref ARM_USART_GetStatus and checking the \em tx_busy or \em rx_busy flag. 
564
565 When in synchronous slave mode also the following events can be generated:
566  - \ref ARM_USART_EVENT_TX_UNDERFLOW : transmitter is enabled but transfer operation is not started and data is requested by the master
567  - \ref ARM_USART_EVENT_RX_OVERFLOW : data lost during transfer or because receiver is enabled but transfer operation has not been started
568
569 Transfer operation can also be aborted by calling \ref ARM_USART_Control with \ref ARM_USART_ABORT_TRANSFER as the control parameter.
570 *****************************************************************************************************************/
571
572 uint32_t ARM_USART_GetTxCount (void)  {
573   return 0;
574 }
575 /**
576 \fn uint32_t ARM_USART_GetTxCount (void)
577 \details
578 The function \b ARM_USART_GetTxCount returns the number of the currently transmitted data items during \ref ARM_USART_Send and \ref ARM_USART_Transfer operation.
579 *****************************************************************************************************************/
580
581 uint32_t ARM_USART_GetRxCount (void)  {
582   return 0;
583 }
584 /**
585 \fn uint32_t ARM_USART_GetRxCount (void)
586 \details
587 The function \b  ARM_USART_GetRxCount returns the number of the currently received data items during \ref ARM_USART_Receive and \ref ARM_USART_Transfer operation.
588 *****************************************************************************************************************/
589
590 int32_t ARM_USART_Control (uint32_t control, uint32_t arg)  {
591   return ARM_DRIVER_OK;
592 }
593 /**
594 \fn int32_t ARM_USART_Control (uint32_t control, uint32_t arg)
595 \details
596 The function \b ARM_USART_Control control the USART interface settings and execute various operations.
597
598 The parameter \em control sets the operation and is explained in the table below.
599 Values from different categories can be ORed with the exception of \ref usart_misc_tab "Miscellaneous Operations".
600
601 The parameter \em arg provides, depending on the operation, additional information, for example the baudrate.
602
603 The table lists the available \em control operations.
604
605 <TABLE class="cmtable" summary="">
606 <TR><TH>Parameter \em control           </TH>  <TH style="text-align:right"> Bit                 </TH>     <TH> Category </TH> <TH>Description </TH></TR>
607 <TR><TD>\ref ARM_USART_MODE_ASYNCHRONOUS</TD>         <td rowspan="6" style="text-align:right"> 0..7    </td>     <td rowspan="6"> Operation Mode  </td><TD>Set to asynchronous UART mode. \em arg specifies baudrate.</TD></TR>
608 <TR><TD>\ref ARM_USART_MODE_SYNCHRONOUS_MASTER</TD>   <TD>Set to synchronous master mode with clock signal generation. \em arg specifies baudrate.</TD></TR>
609 <TR><TD>\ref ARM_USART_MODE_SYNCHRONOUS_SLAVE</TD>    <TD>Set to synchronous slave mode with external clock signal.</TD></TR>
610 <TR><TD>\ref ARM_USART_MODE_SINGLE_WIRE</TD>          <TD>Set to single-wire (half-duplex) mode. \em arg specifies baudrate.</TD></TR>
611 <TR><TD>\ref ARM_USART_MODE_IRDA</TD>                 <TD>Set to Infra-red data mode. \em arg specifies baudrate.</TD></TR>
612 <TR><TD>\ref ARM_USART_MODE_SMART_CARD</TD>           <TD>Set to Smart Card mode. \em arg specifies baudrate.</TD></TR>
613 <TR><TD>\ref ARM_USART_DATA_BITS_5</TD>        <td rowspan="5" style="text-align:right"> 8..11    </td>     <td rowspan="5"> Data Bits  </td><TD>Set to \token{5} data bits</TD></TR>
614 <TR><TD>\ref ARM_USART_DATA_BITS_6</TD>           <TD>Set to \token{6} data bits</TD></TR>
615 <TR><TD>\ref ARM_USART_DATA_BITS_7</TD>           <TD>Set to \token{7} data bits</TD></TR>
616 <TR><TD>\ref ARM_USART_DATA_BITS_8</TD>           <TD>Set to \token{8} data bits (default)</TD></TR>
617 <TR><TD>\ref ARM_USART_DATA_BITS_9</TD>           <TD>Set to \token{9} data bits</TD></TR>
618 <TR><TD>\ref ARM_USART_PARITY_EVEN</TD>        <td rowspan="3" style="text-align:right"> 12..13 </td>  <td rowspan="3"> Parity Bit  </td><TD>Set to Even Parity</TD></TR>
619 <TR><TD>\ref ARM_USART_PARITY_NONE</TD>           <TD>Set to No Parity (default)</TD></TR>
620 <TR><TD>\ref ARM_USART_PARITY_ODD</TD>            <TD>Set to Odd Parity</TD></TR>
621 <TR><TD>\ref ARM_USART_STOP_BITS_1</TD>        <td rowspan="4" style="text-align:right"> 14..15 </td>  <td rowspan="4"> Stop Bit  </td><TD>Set to \token{1} Stop bit (default)</TD></TR>
622 <TR><TD>\ref ARM_USART_STOP_BITS_2</TD>           <TD>Set to \token{2} Stop bits</TD></TR>
623 <TR><TD>\ref ARM_USART_STOP_BITS_1_5</TD>         <TD>Set to \token{1.5} Stop bits</TD></TR>
624 <TR><TD>\ref ARM_USART_STOP_BITS_0_5</TD>         <TD>Set to \token{0.5} Stop bits</TD></TR>
625 <TR><TD>\ref ARM_USART_FLOW_CONTROL_NONE</TD>  <td rowspan="4" style="text-align:right"> 16..17 </td>  <td rowspan="4"> Flow Control  </td><TD>No flow control signal (default)</TD></TR>
626 <TR><TD>\ref ARM_USART_FLOW_CONTROL_CTS</TD>      <TD>Set to use the CTS flow control signal</TD></TR> 
627 <TR><TD>\ref ARM_USART_FLOW_CONTROL_RTS</TD>      <TD>Set to use the RTS flow control signal</TD></TR>
628 <TR><TD>\ref ARM_USART_FLOW_CONTROL_RTS_CTS</TD>  <TD>Set to use the RTS and CTS flow control signal</TD></TR> 
629 <TR><TD>\ref ARM_USART_CPOL0</TD>              <td rowspan="2" style="text-align:right"> 18     </td>  <td rowspan="2"> Clock Polarity  </td><TD>CPOL=\token{0} (default) : data are captured on rising edge (low->high transition)</TD></TR> 
630 <TR><TD>\ref ARM_USART_CPOL1</TD>                 <TD>CPOL=\token{1} : data are captured on falling edge (high->lowh transition)</TD></TR> 
631 <TR><TD>\ref ARM_USART_CPHA0</TD>              <td rowspan="2" style="text-align:right"> 19     </td>  <td rowspan="2"> Clock Phase  </td><TD>CPHA=\token{0} (default) : sample on first (leading) edge</TD></TR>
632 <TR><TD>\ref ARM_USART_CPHA1</TD>                 <TD>CPHA=\token{1} : sample on second (trailing) edge</TD></TR>
633 <TR><TD>\ref ARM_USART_ABORT_RECEIVE</TD>      <td rowspan="11" style="text-align:right"> 0..19  </td>  <td rowspan="11"> \anchor usart_misc_tab Miscellaneous Operations <br>(cannot be ORed)  </td><TD>Abort receive operation (see also: \ref ARM_USART_Receive)</TD></TR>
634 <TR> <TD>\ref ARM_USART_ABORT_SEND</TD>                 <TD>Abort  send operation   (see also: \ref ARM_USART_Send)</TD></TR>
635 <TR> <TD>\ref ARM_USART_ABORT_TRANSFER</TD>             <TD>Abort transfer operation  (see also: \ref ARM_USART_Transfer)</TD></TR>
636 <TR> <TD>\ref ARM_USART_CONTROL_BREAK</TD>              <TD>Enable or disable continuous Break transmission; \em arg : \token{0=disabled; 1=enabled}</TD></TR> 
637 <TR> <TD>\ref ARM_USART_CONTROL_RX</TD>                 <TD>Enable or disable receiver; \em arg : \token{0=disabled; 1=enabled} (see also: \ref ARM_USART_Receive; \ref ARM_USART_Transfer)</TD></TR>
638 <TR> <TD>\ref ARM_USART_CONTROL_SMART_CARD_NACK</TD>    <TD>Enable or disable Smart Card NACK generation; \em arg : \token{0=disabled; 1=enabled}</TD></TR> 
639 <TR> <TD>\ref ARM_USART_CONTROL_TX</TD>                 <TD>Enable or disable transmitter; \em arg : \token{0=disabled; 1=enabled} (see also: \ref ARM_USART_Send; \ref ARM_USART_Transfer)</TD></TR>
640 <TR> <TD>\ref ARM_USART_SET_DEFAULT_TX_VALUE</TD>       <TD>Set the default transmit value (synchronous receive only); \em arg specifies the value. (see also: \ref ARM_USART_Receive)</TD></TR>
641 <TR> <TD>\ref ARM_USART_SET_IRDA_PULSE</TD>             <TD>Set the IrDA pulse value in \token{ns}; \em arg : \token{0=3/16 of bit period}</TD></TR>
642 <TR> <TD>\ref ARM_USART_SET_SMART_CARD_CLOCK</TD>       <TD>Set the Smart Card Clock in \token{Hz}; \em arg : \token{0=Clock not set}</TD></TR>
643 <TR> <TD>\ref ARM_USART_SET_SMART_CARD_GUARD_TIME</TD>  <TD>Set the Smart Card guard time; \em arg = number of bit periods</TD></TR>
644 </TABLE>
645
646 \b Example
647
648 \code
649   extern ARM_DRIVER_USART Driver_USART0;
650   
651   // configure to UART mode: 8 bits, no parity, 1 stop bit, no flow control, 9600 bps
652   status = Driver_USART0.Control(ARM_USART_MODE_ASYNCHRONOUS | 
653                                  ARM_USART_DATA_BITS_8 | 
654                                  ARM_USART_PARITY_NONE | 
655                                  ARM_USART_STOP_BITS_1 | 
656                                  ARM_USART_FLOW_CONTROL_NONE, 9600);
657  
658   // identical with above settings (default settings removed)
659   // configure to UART mode: 8 bits, no parity, 1 stop bit, flow control, 9600 bps
660   status = Driver_USART0.Control(ARM_USART_MODE_ASYNCHRONOUS, 9600);
661  
662   // enable TX output
663   status = Driver_USART0.Control(ARM_USART_CONTROL_TX, 1);
664  
665   // disable RX output
666   status = Driver_USART0.Control(ARM_USART_CONTROL_RX, 0);
667 \endcode
668 *****************************************************************************************************************/
669
670 ARM_USART_STATUS ARM_USART_GetStatus (void)  {
671   return { 0 };
672 }
673 /**
674 \fn ARM_USART_STATUS ARM_USART_GetStatus (void)
675 \details
676 The function \b ARM_USART_GetStatus retrieves the current USART interface status.
677
678 *****************************************************************************************************************/
679
680 int32_t ARM_USART_SetModemControl (ARM_USART_MODEM_CONTROL control)  {
681   return ARM_DRIVER_OK;
682 }
683 /**
684 \fn int32_t ARM_USART_SetModemControl (ARM_USART_MODEM_CONTROL control)
685 \details
686 The function \b ARM_USART_SetModemControl activates or deactivates the selected USART modem control line. 
687
688 The function \ref ARM_USART_GetModemStatus returns information about status of the modem lines.
689
690 *****************************************************************************************************************/
691
692 ARM_USART_MODEM_STATUS ARM_USART_GetModemStatus (void)  {
693   return { 0 };
694 }
695 /**
696 \fn ARM_USART_MODEM_STATUS ARM_USART_GetModemStatus (void)
697 \details
698 The function \b ARM_USART_GetModemStatus returns the current USART Modem Status lines state.
699
700 The function \ref ARM_USART_SetModemControl sets the modem control lines of the USART.
701
702 *****************************************************************************************************************/
703
704 void ARM_USART_SignalEvent (uint32_t event)  {
705   // function body
706 }
707 /**
708 \fn void ARM_USART_SignalEvent (uint32_t event)
709 \details
710 The function \b ARM_USART_SignalEvent is a callback function registered by the function \ref ARM_USART_Initialize. 
711
712 The parameter \em event indicates one or more events that occurred during driver operation.
713 Each event is encoded in a separate bit and therefore it is possible to signal multiple events within the same call. 
714
715 Not every event is necessarily generated by the driver. This depends on the implemented capabilities stored in the 
716 data fields of the structure \ref ARM_USART_CAPABILITIES, which can be retrieved with the function \ref ARM_USART_GetCapabilities.
717
718 The following events can be generated:
719
720 <table class="cmtable" summary="">
721 <tr>
722   <th> Parameter \em event                      </th><th> Bit </th><th> Description </th>                                              
723   <th> supported when ARM_USART_CAPABILITIES    </th>
724 </tr>
725 <tr>
726   <td> \ref ARM_USART_EVENT_SEND_COMPLETE       </td><td>  0  </td><td> Occurs after call to \ref ARM_USART_Send to indicate that all the data to be sent 
727                                                                         was processed by the driver. All the data might have been already transmitted 
728                                                                                                                                                 or parts of it are still queued in transmit buffers. The driver is ready for the next 
729                                                                                                                                                 call to \ref ARM_USART_Send; however USART may still transmit data. </td>     
730   <td> <i>allways supported</i> </td>
731 </tr>
732 <tr>
733   <td> \ref ARM_USART_EVENT_RECEIVE_COMPLETE    </td><td>  1  </td><td> Occurs after call to \ref ARM_USART_Receive to indicate that all the data has been 
734                                                                         received. The driver is ready for the next call to \ref ARM_USART_Receive. </td>     
735   <td> <i>allways supported</i> </td>
736 </tr>
737 <tr>
738   <td> \ref ARM_USART_EVENT_TRANSFER_COMPLETE   </td><td>  2  </td><td> Occurs after call to \ref ARM_USART_Transfer to indicate that all the data has been 
739                                                                         transferred. The driver is ready for the next call to \ref ARM_USART_Transfer. </td>     
740   <td> <i>allways supported</i> </td>
741 </tr>
742 <tr>
743   <td> \ref ARM_USART_EVENT_TX_COMPLETE         </td><td>  3  </td><td> Occurs after call to \ref ARM_USART_Transfer to indicate that all the data has been 
744                                                                         transferred. The driver is ready for the next call to \ref ARM_USART_Transfer. </td>     
745   <td> data field \em event_tx_complete = \token{1} </td>
746 </tr>
747 <tr>
748   <td> \ref ARM_USART_EVENT_TX_UNDERFLOW        </td><td>  4  </td><td> Occurs in synchronous slave mode when data is requested by the master but 
749                                                                         send/receive/transfer operation has not been started. 
750                                                                         Data field \em  rx_underflow = \token{1} of \ref ARM_USART_STATUS. </td>                                                                                                                                                
751   <td> <i>allways supported</i> </td>
752 </tr>
753 <tr>
754   <td> \ref ARM_USART_EVENT_RX_OVERFLOW         </td><td>  5  </td><td> Occurs when data is lost during receive/transfer operation or when data is lost 
755                                                                         because receive operation in asynchronous mode or receive/send/transfer operation in 
756                                                                                                                                                 synchronous slave mode has not been started.
757                                                                         Data field \em  rx_overflow = \token{1} of \ref ARM_USART_STATUS. </td>
758   <td> <i>allways supported</i> </td>
759 </tr>
760 <tr>
761   <td> ARM_USART_EVENT_RX_TIMEOUT               </td><td>  6  </td><td> Occurs during receive when idle time is detected between consecutive characters 
762                                                                         (idle time is hardware dependent).</td>     
763   <td> data field \em event_rx_timeout = \token{1}  </td>
764 </tr>
765 <tr>
766   <td> \ref ARM_USART_EVENT_RX_BREAK            </td><td>  7  </td><td> Occurs when break is detected during receive. 
767                                                                         Data field \em  rx_break = \token{1} of \ref ARM_USART_STATUS. </td>     
768   <td> <i>allways supported</i> </td>
769 </tr>
770 <tr>
771   <td> \ref ARM_USART_EVENT_RX_FRAMING_ERROR    </td><td>  8  </td><td> Occurs when framing error is detected during receive. 
772                                                                         Data field \em  rx_framing_error = \token{1} of \ref ARM_USART_STATUS. </td>     
773   <td> <i>allways supported</i> </td>
774 </tr>
775 <tr>
776   <td> \ref ARM_USART_EVENT_RX_PARITY_ERROR     </td><td>  9  </td><td> Occurs when parity error is detected during receive.
777                                                                         Data field \em  rx_parity_error = \token{1} of \ref ARM_USART_STATUS. </td>     
778   <td> <i>allways supported</i> </td>
779 </tr>
780 <tr>
781   <td> ARM_USART_EVENT_CTS                      </td><td>  10 </td><td> Indicates that CTS modem line state has changed.
782                                                                         Data field \em  cts = \token{1} of \ref ARM_USART_MODEM_STATUS. </td>     
783   <td> data field \em event_cts = \token{1} and <br>
784        data field \em cts = \token{1}           </td>
785 </tr>
786 <tr>
787   <td> ARM_USART_EVENT_CTS                      </td><td>  11 </td><td> Indicates that DSR modem line state has changed.
788                                                                         Data field \em  dsr = \token{1} of \ref ARM_USART_MODEM_STATUS. </td>     
789   <td> data field \em event_dsr = \token{1} and <br>
790        data field \em dsr = \token{1}           </td>
791 </tr>
792 <tr>
793   <td> ARM_USART_EVENT_DCD                      </td><td>  12 </td><td> Indicates that DCD modem line state has changed.
794                                                                         Data field \em  dcd = \token{1} of \ref ARM_USART_MODEM_STATUS. </td>     
795   <td> data field \em event_dcd = \token{1} and <br>
796        data field \em dcd = \token{1}           </td>
797 </tr>
798 <tr>
799   <td> ARM_USART_EVENT_RI                       </td><td>  13 </td><td> Indicates that RI modem line state has changed.
800                                                                         Data field \em  ri = \token{1} of \ref ARM_USART_MODEM_STATUS. </td>     
801   <td> data field \em event_ri = \token{1} and  <br>
802        data field \em ri = \token{1}            </td>
803 </tr>
804 </table>
805 *****************************************************************************************************************/
806
807 /**
808 @}
809 */ 
810 // End USART Interface