EVE 1.0
uart.h
Go to the documentation of this file.
1 #ifndef UART_H
2 #define UART_H
3 /**********************************************************************/
4 /*
5  * Copyright (c) 2013-2015, Jetro AS
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without modification,
9  * are permitted provided that the following conditions are met:
10  *
11  * 1. Redistributions of source code must retain the above copyright notice,
12  * this list of conditions and the following disclaimer.
13  * 2. Redistributions in binary form must reproduce the above copyright notice,
14  * this list of conditions and the following disclaimer in the documentation
15  * and/or other materials provided with the distribution.
16  * 3. The name of the author may not be used to endorse or promote products
17  * derived from this software without specific prior written permission.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONRIBUTORS ``AS IS'' AND ANY EXPRESS
20  * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
21  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
22  * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
23  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
24  * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
27  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
28  * OF SUCH DAMAGE.
29  *
30  * This file is part of the EVE platform.
31  */
32 
33 /**
34  * @file
35  * @brief Abstract UART driver header.
36  *
37  * @author: PE, SE, Jetro AS
38  */ /*******************************************************************/
39 
40 #include <core/clk.h>
41 #include <core/pm.h>
42 #include <core/uwork.h>
43 #include <dev/data-buffer.h>
44 #include <hal/nrf_uarte.h>
45 #include <lib/assert.h>
46 
47 /**
48  * \defgroup uart UART driver
49  * \ingroup abstract
50  * \{
51  *
52  * Abstract UART driver header.
53  *
54  * This UART driver provides common interface to various UART block(s).
55  * Functionality included:
56  * - Init and disable of Uart driver.
57  * - Handling RX interrupts with timeout after rx-data pause (ex. pause after an received message)
58  */
59 
60 /***********************************************************************
61  * Global defines
62 ***********************************************************************/
63 /** UART flow control settings */
65 {
66  UART_FLOW_CONTROL_DISABLED = NRF_UARTE_HWFC_DISABLED, //!< Flow control OFF
67  UART_FLOW_CONTROL_CTSRTS = NRF_UARTE_HWFC_ENABLED, //!< HW flow control
68  UART_FLOW_CONTROL_XONXOFF = 2, //!< SW flow control
69 };
70 
71 /** UART parity settings */
73 {
74  UART_PARITY_NONE = NRF_UARTE_PARITY_EXCLUDED, //!< No parity bit
75  UART_PARITY_EVEN = NRF_UARTE_PARITY_INCLUDED, //!< Parity bit is on. Calculate even parity.
76  UART_PARITY_ODD = 1, //!< Parity bit is on. Calculate odd parity.
77  UART_PARITY_FORCED1 = 2, //!< Parity bit is on and always 1.
78  UART_PARITY_FORCED0 = 3, //!< Parity bit is on and always 0.
79 };
82 CTASSERT(UART_PARITY_NONE < (1 << 4));
83 CTASSERT(UART_PARITY_EVEN < (1 << 4));
84 
85 /** UART stop bits settings */
87 {
88  UART_STOP_1 = 0, //!< One stop bit
89  UART_STOP_2 = 1, //!< Two stop bits
90 };
91 
92 /** Status of finished Rx operation */
94 {
95  UART_RX_OK, //!< Receiving completed successfully
96  UART_RX_TIMEOUT, //!< Timeout while receiving (long delay after the last char received, typically 4 chars pause)
97  UART_RX_ERROR_OVERRUN, //!< Buffer overrun while receiving
98  UART_RX_ERROR_PARITY, //!< Parity error while receiving
99  UART_RX_ERROR_FRAMING, //!< Frame error (no stop bit) while receiving
100  UART_RX_ERROR_BREAK, //!< Break received
101  UART_RX_CANCELLED, //!< Rx was aborted by UartCancelRx()
102 };
103 
104 enum
105 {
106  UART_RX_TIMEOUT_DEFAULT = 0, //!< No Rx timeout: check buffer and return immedialely
107  UART_RX_TIMEOUT_INFINITE = 0xFFFFFFFF, //!< No Rx timeout: wait forever
108 };
109 
110 /** Length of one UART word. */
112 {
113  UART_WORDLEN_DEFAULT = 0, //!< default word length (8 bit)
114  UART_WORDLEN_5 = 5, //!< 5 bit word length
115  UART_WORDLEN_6 = 6, //!< 6 bit word length
116  UART_WORDLEN_7 = 7, //!< 7 bit word length
117  UART_WORDLEN_8 = 8, //!< 8 bit word length
118 };
119 
120 struct uart_t;
121 
122 /**
123  * The callback is called at completion of an asynchronous receive.
124  *
125  * @param Uart UART to be used
126  * @param CallbackData User-defined data
127  * @param ...TODO
128  */
129 typedef void (*uart_rx_callback_t)(const struct uart_t *Uart, void *CallbackData, enum uart_rx_status_t RxStatus);
130 
131 /**
132  * The callback is called at completion of an asynchronous transmit.
133  *
134  * @param Uart UART to be used
135  * @param CallbackData User-defined data
136  */
137 typedef void (*uart_tx_callback_t)(const struct uart_t *Uart, void *CallbackData);
138 
139 /**
140  * The callback is called at completion of break sending.
141  *
142  * @param Uart UART to be used
143  * @param CallbackData User-defined data
144  */
145 typedef void (*uart_break_callback_t)(const struct uart_t *Uart, void *CallbackData);
146 
147 
148 /**
149  * UART driver virtual function types
150  */
151 typedef void (*uart_init_t)(const struct uart_t *Uart);
152 typedef void (*uart_disable_t)(const struct uart_t *Uart);
153 typedef void (*uart_start_basic_tx_t)(const struct uart_t *Uart, uint8_t *DataSrc, uint16_t DataSize, uart_tx_callback_t Callback, void *CallbackData);
154 typedef void (*uart_start_ping_pong_tx_t)(const struct uart_t *Uart, uint8_t *PrimDataSrc, uint16_t PrimDataSize, uint8_t *AltDataSrc, uint16_t AltDataSize, uart_tx_callback_t Callback, void *CallbackData);
155 typedef void (*uart_refresh_ping_pong_tx_t)(const struct uart_t *Uart, uint8_t *DataSrc, uint16_t DataSize, bool Stop);
156 typedef void (*uart_start_basic_rx_t)(const struct uart_t *Uart, uint8_t *DataDest, uint16_t DataSize, uart_rx_callback_t Callback, void *CallbackData);
157 typedef void (*uart_start_ping_pong_rx_t)(const struct uart_t *Uart, uint8_t *PrimDataDest, uint16_t PrimDataSize, uint8_t *AltDataDest, uint16_t AltDataSize, uart_rx_callback_t Callback, void *CallbackData);
158 typedef void (*uart_refresh_ping_pong_rx_t)(const struct uart_t *Uart, uint8_t *DataDest, uint16_t DataSize, bool Stop);
159 typedef void (*uart_reset_fifo_t)(const struct uart_t* Uart, bool Tx, bool Rx);
160 typedef void (*uart_cancel_rx_t)(const struct uart_t *Uart);
161 typedef bool (*uart_is_busy_rx_t)(const struct uart_t *Uart);
162 typedef void (*uart_cancel_tx_t)(const struct uart_t *Uart);
163 typedef bool (*uart_is_busy_tx_t)(const struct uart_t *Uart);
164 typedef void (*uart_set_baudrate_t)(const struct uart_t *Uart);
165 typedef void (*uart_set_rx_timeouts_t)(const struct uart_t *Uart, uint32_t RxStartTimeoutUs, uint32_t RxStopTimeoutUs);
166 typedef void (*uart_send_break)(const struct uart_t *Uart, uart_break_callback_t Callback, void *CallbackData);
167 typedef void (*uart_set_rts)(const struct uart_t *Uart, bool Active);
168 typedef void (*uart_interrupt_handler_t)(const struct uart_t *Uart);
169 
170 /**
171  * UART driver run-time state
172  */
174 {
175  const struct uart_t* Uart; //!< Backpointer to the static configuration
176  uint32_t Baudrate; //!< Current baudrate in bit/s.
177  uint32_t RxStartTimeoutUs; //!< Current value for the max time the driver waits for the first symbol in a message
178  uint32_t RxStopTimeoutUs; //!< Current value for the max time the driver waits for the next symbol in a message
179  struct data_buffer_t RxBuffer[2]; //!< Receive buffer for asynchronous transfers
180  uart_rx_callback_t RxCallback; //!< RX completion callback
181  void *RxCallbackData; //!< Data for the RX completion callback
182  uint8_t RxBufIndex; //!< Index of the active RX buffer
183  uint8_t RxStop; //!< Amount of RX buffers in the pipeline
184  uint8_t RxCancelled; //!< RX is cancelled
185  struct data_buffer_t TxBuffer[2]; //!< Transmit buffer for asynchronous transfers
186  uart_tx_callback_t TxCallback; //!< TX completion callback
187  void *TxCallbackData; //!< Data for the TX completion callback
188  uint8_t TxBufIndex; //!< Index of the active TX buffer
189  uint8_t TxStop; //!< Amount of TX buffers in the pipeline
190  uart_break_callback_t BreakCallback; //!< Send Break completion callback
191  void* BreakCallbackData; //!< Data for the Break send completion callback
192  struct uwork_t SendBreakWork; //!< timeout counter for Send Break
193 };
194 
195 /**
196  * UART driver virtual function table
197  */
199 {
201  uart_disable_t UartDisable;
202  uart_start_basic_tx_t UartStartBasicTx;
203  uart_start_ping_pong_tx_t UartStartPingPongTx;
204  uart_refresh_ping_pong_tx_t UartRefreshPingPongTx;
205  uart_start_basic_rx_t UartStartBasicRx;
206  uart_start_ping_pong_rx_t UartStartPingPongRx;
207  uart_refresh_ping_pong_rx_t UartRefreshPingPongRx;
208  uart_reset_fifo_t UartResetFifo;
209  uart_cancel_rx_t UartCancelRx;
210  uart_is_busy_rx_t UartIsBusyRx;
211  uart_cancel_tx_t UartCancelTx;
212  uart_is_busy_tx_t UartIsBusyTx;
213  uart_set_baudrate_t UartSetBaudrate;
214  uart_set_rx_timeouts_t UartSetRxTimeouts;
215  uart_send_break UartSendBreak;
216  uart_set_rts UartSetRts;
217 };
218 
219 /**
220  * UART driver configuration data
221  */
222 struct uart_t
223 {
224  const void* Impl; //!< Device specific configuration data
225  struct uart_state_t* State; //!< Address to struct with RAM variables used by the uart driver
226  uint32_t Baudrate : 20; //!< Default baudrate in bit/s.
227  uint32_t FlowControl : 2; //!< @ref uart_flow_control_t
228  uint32_t RtsInverse : 1; //!< Inverted RTS line (active 1)
229  uint32_t Parity : 4; //!< @ref uart_parity_t
230  uint32_t StopBits : 1; //!< @ref uart_stops_t
231  uint32_t WordLength : 4; //!< @ref uart_wordlen_t
232  uint32_t RxStartTimeoutUs; //!< Default value for the max time the driver waits for the first symbol in a message
233  uint32_t RxStopTimeoutUs; //!< Default value for the max time the driver waits for the next symbol in a message
234  const struct uart_api_t* Func; //!< Virtual function table
235 };
236 
237 #define UART_VCALL(Uart, Fn) (Uart)->Func->Fn
238 
239 /**********************************************************************/
240 /**
241  * @brief Name: UartInit\n
242  * Initializes Uart
243  *
244  * @param Uart UART parameters to be used.
245  * @return void
246  ***********************************************************************/
247 static inline void UartInit(const struct uart_t *Uart)
248 {
249  UART_VCALL(Uart, UartInit)(Uart);
250 }
251 
252 /**********************************************************************/
253 /**
254  * @brief Name: UartDisable\n
255  * Disables UART
256  *
257  * @param Uart UART parameters to be used.
258  * @return void
259  ***********************************************************************/
260 static inline void UartDisable(const struct uart_t *Uart)
261 {
262  UART_VCALL(Uart, UartDisable)(Uart);
263 }
264 
265 /**********************************************************************/
266 /**
267  * @brief Name: UartDmaBytesReceived\n
268  * Will return number of received bytes for current DMA transfer.
269  *
270  * @param Uart UART parameters to be used.
271  * @return Number of received bytes for current DMA transfer
272 ***********************************************************************/
273 static inline uint32_t UartDmaBytesReceived(const struct uart_t *Uart)
274 {
275  struct uart_state_t *State = Uart->State;
276  return State->RxBuffer[State->RxBufIndex].Pos;
277 }
278 
279 /**********************************************************************/
280 /**
281  * @brief Name: UartStartBasicTx\n
282  * Transmit data using DMA transfer in basic mode.
283  * Using primary DMA descriptor only.
284  *
285  * @param Uart UART parameters to be used.
286  * @param DataSrc Source address for DMA transfer
287  * @param DataSize Number of DMA transfer bytes. Range: 1 through 255
288  * @param Callback User-defined function to be called at completion
289  * @param CallbackData User-defined data for the completion callback
290  * @return void
291 ***********************************************************************/
292 static inline void UartStartBasicTx(const struct uart_t *Uart,
293  uint8_t *DataSrc, uint16_t DataSize,
294  uart_tx_callback_t Callback, void *CallbackData)
295 {
296  UART_VCALL(Uart, UartStartBasicTx)(Uart, DataSrc, DataSize, Callback, CallbackData);
297 }
298 
299 /**********************************************************************/
300 /**
301  * @brief Name: UartStartPingPongTx\n
302  * Transmit data using DMA transfer in PingPong mode.
303  * Will alternate between primary and alternate DMA descriptor
304  *
305  * @param Uart UART parameters to be used.
306  * @param PrimDataSrc Source address for DMA transfer using primary descriptor
307  * @param PrimDataSize Number of DMA transfer bytes using primary descriptor. Range: 1 through 1024
308  * @param AltDataSrc Source address for DMA transfer using alternate descriptor
309  * @param AltDataSize Number of DMA transfer bytes using alternate descriptor. Range: 1 through 1024
310  * @param Callback User-defined function to be called at completion
311  * @param CallbackData User-defined data for the completion callback
312  * @return void
313 ***********************************************************************/
314 static inline void UartStartPingPongTx(const struct uart_t *Uart,
315  uint8_t *PrimDataSrc, uint16_t PrimDataSize,
316  uint8_t *AltDataSrc, uint16_t AltDataSize,
317  uart_tx_callback_t Callback, void *CallbackData)
318 {
319  UART_VCALL(Uart, UartStartPingPongTx)(Uart, PrimDataSrc, PrimDataSize,
320  AltDataSrc, AltDataSize,
321  Callback, CallbackData);
322 }
323 
324 /**********************************************************************/
325 /**
326  * @brief Name: UartRefreshPingPongTx\n
327  * Refresh transmit of data using DMA transfer in PingPong mode.
328  *
329  * @param Uart UART parameters to be used.
330  * @param DataSrc Source address for DMA transfer. NULL to leave descriptor as is.
331  * @param DataSize Number of DMA transfer bytes. Range: 1 through 1024
332  * @param Stop Indicate that DMA transfer shall stop after using this descriptor.
333  * @return void
334 ***********************************************************************/
335 static inline void UartRefreshPingPongTx(const struct uart_t *Uart,
336  uint8_t *DataSrc, uint16_t DataSize,
337  bool Stop)
338 {
339  UART_VCALL(Uart, UartRefreshPingPongTx)(Uart, DataSrc, DataSize, Stop);
340 }
341 
342 /**********************************************************************/
343 /**
344  * @brief Name: UartGetTxBuffer\n
345  * Returns the current TX buffer.
346  *
347  * @param Uart UART parameters to be used.
348  * @return Pointer to the active TX buffer
349 ***********************************************************************/
350 static inline struct data_buffer_t *UartGetTxBuffer(const struct uart_t *Uart)
351 {
352  struct uart_state_t *State = Uart->State;
353  return &State->TxBuffer[State->TxBufIndex];
354 }
355 
356 /**********************************************************************/
357 /**
358  * @brief Name: UartStartBasicRx\n
359  * Receive data using DMA transfer in basic mode.
360  * Using primary DMA descriptor only.
361  *
362  * @param Uart UART parameters to be used.
363  * @param DataDest Destination address for DMA transfer
364  * @param DataSize Number of DMA transfer bytes. Range: 1 through 1024
365  * @param Callback User-defined function to be called at completion or timeout
366  * @param CallbackData User-defined data for the completion callback
367  * @return void
368 ***********************************************************************/
369 static inline void UartStartBasicRx(const struct uart_t *Uart,
370  uint8_t *DataDest, uint16_t DataSize,
371  uart_rx_callback_t Callback, void *CallbackData)
372 {
373  UART_VCALL(Uart, UartStartBasicRx)(Uart, DataDest, DataSize, Callback, CallbackData);
374 }
375 
376 /**********************************************************************/
377 /**
378  * @brief Name: UartStartPingPongRx\n
379  * Receive data using DMA transfer in PingPong mode.
380  * Will alternate between primary and alternate DMA descriptor
381  *
382  * @param Uart UART parameters to be used.
383  * @param PrimDataDest Destination address for DMA transfer using primary descriptor
384  * @param PrimDataSize Number of DMA transfer bytes using primary descriptor. Range: 1 through 1024
385  * @param AltDataDest Destination address for DMA transfer using alternate descriptor
386  * @param AltDataSize Number of DMA transfer bytes using alternate descriptor. Range: 1 through 1024
387  * @param Callback User-defined function to be called at completion or timeout
388  * @param CallbackData User-defined data for the completion callback
389  * @return void
390 ***********************************************************************/
391 static inline void UartStartPingPongRx(const struct uart_t *Uart,
392  uint8_t *PrimDataDest, uint16_t PrimDataSize,
393  uint8_t *AltDataDest, uint16_t AltDataSize,
394  uart_rx_callback_t Callback, void *CallbackData)
395 {
396  UART_VCALL(Uart, UartStartPingPongRx)(Uart, PrimDataDest, PrimDataSize,
397  AltDataDest, AltDataSize,
398  Callback, CallbackData);
399 }
400 
401 /**********************************************************************/
402 /**
403  * @brief Name: UartRefreshPingPongRx\n
404  * Refresh of receive data using DMA transfer in PingPong mode.
405  * Will alternate between primary and alternate DMA descriptor
406  *
407  * @param Uart UART parameters to be used.
408  * @param DataDest Destination address for DMA transfer. NULL to leave descriptor as is.
409  * @param DataSize Number of DMA transfer bytes using primary descriptor. Range: 1 through 1024
410  * @param Stop Indicate that DMA transfer shall stop after using this descriptor.
411  * @return void
412 ***********************************************************************/
413 static inline void UartRefreshPingPongRx(const struct uart_t *Uart,
414  uint8_t *DataDest, uint16_t DataSize,
415  bool Stop)
416 {
417  UART_VCALL(Uart, UartRefreshPingPongRx)(Uart, DataDest, DataSize, Stop);
418 }
419 
420 /**********************************************************************/
421 /**
422  * @brief Name: UartGetRxBuffer\n
423  * Returns the current RX buffer.
424  *
425  * @param Uart UART parameters to be used.
426  * @return Pointer to the active RX buffer
427 ***********************************************************************/
428 static inline const struct data_buffer_t *UartGetRxBuffer(const struct uart_t *Uart)
429 {
430  struct uart_state_t *State = Uart->State;
431  return &State->RxBuffer[State->RxBufIndex];
432 }
433 
434 /**********************************************************************/
435 /**
436  * @brief Name: UartResetFifo\n
437  * Resets FIFO buffer for Tx or Rx or both.\n
438  * NB: Resetting Rx FIFO stops receiving
439  *
440  * @param Uart UART parameters to be used.
441  * @param Tx Set to TRUE to reset Tx FIFO.
442  * @param Rx Set to TRUE to reset Rx FIFO.
443  * @return void
444 ***********************************************************************/
445 static inline void UartResetFifo(const struct uart_t* Uart, bool Tx, bool Rx)
446 {
447  UART_VCALL(Uart, UartResetFifo)(Uart, Tx, Rx);
448 }
449 
450 /**********************************************************************/
451 /**
452  * @brief Name: UartCancelRx\n
453  * Shuts down DMA, flushes FIFO and disables RX interrupts for the UART
454  *
455  * @param Uart UART parameters to be used.
456  * @return void
457 ***********************************************************************/
458 static inline void UartCancelRx(const struct uart_t *Uart)
459 {
460  UART_VCALL(Uart, UartCancelRx)(Uart);
461 }
462 
463 /**********************************************************************/
464 /**
465  * @brief Name: UartIsBusyRx\n
466  * Returns busy status of the UART RX path
467  *
468  * @param Uart UART parameters to be used.
469  * @return true if UART is receiving data
470 ***********************************************************************/
471 static inline bool UartIsBusyRx(const struct uart_t *Uart)
472 {
473  return UART_VCALL(Uart, UartIsBusyRx)(Uart);
474 }
475 
476 /**********************************************************************/
477 /**
478  * @brief Name: UartCancelTx\n
479  * Shuts down DMA, flushes FIFO and disables TX interrupts for the UART
480  *
481  * @param Uart UART parameters to be used.
482 ***********************************************************************/
483 static inline void UartCancelTx(const struct uart_t *Uart)
484 {
485  UART_VCALL(Uart, UartCancelTx)(Uart);
486 }
487 
488 /**********************************************************************/
489 /**
490  * @brief Name: UartIsBusyTx\n
491  * Returns busy status of the UART TX path
492  *
493  * @param Uart UART parameters to be used.
494  * @return true if UART is sending data
495 ***********************************************************************/
496 static inline bool UartIsBusyTx(const struct uart_t *Uart)
497 {
498  return UART_VCALL(Uart, UartIsBusyTx)(Uart);
499 }
500 
501 /**********************************************************************/
502 /**
503  * @brief Name: UartSetBaudrate\n
504  * Sets new baudrate to the UART
505  * Note that in many situation Rx timeout settings must be adjusted
506  * simultaneously (use UartSetRxTimeouts function)
507  *
508  * @param Uart UART parameters to be used.
509  * @param Baudrate New baudrate in bps.
510  * @return void
511  ***********************************************************************/
512 static inline void UartSetBaudrate(const struct uart_t *Uart, uint32_t Baudrate)
513 {
514  Uart->State->Baudrate = Baudrate;
515  UART_VCALL(Uart, UartSetBaudrate)(Uart);
516 }
517 
518 /**********************************************************************/
519 /**
520  * @brief Name: UartSetRxTimeouts\n
521  * Sets timeout values for the UART
522  * Calling code can use value UART_RX_TIMEOUT_DEFAULT as default value
523  *
524  * @param Uart UART parameters to be used.
525  * @param RxStartTimeoutUs Max time the driver will wait for the first symbol in the message.
526  * UART_RX_TIMEOUT_DEFAULT can be used to set the timeout to default.
527  * UART_RX_TIMEOUT_INFINITE can be used to disable the timeout.
528  * @param RxStopTimeoutUs Max time the driver will wait for the next symbol in the message
529  * UART_RX_TIMEOUT_DEFAULT can be used to set the timeout to default.
530  * UART_RX_TIMEOUT_INFINITE can be used to disable the timeout.
531  * @return void
532 ***********************************************************************/
533 static inline void UartSetRxTimeouts(const struct uart_t *Uart,
534  uint32_t RxStartTimeoutUs, uint32_t RxStopTimeoutUs)
535 {
537 }
538 
539 /**********************************************************************/
540 /**
541  * @brief Sends break (sets TX to logic 0 for a time of 1 byte transmission)
542  *
543  * @param Uart UART parameters to be used.
544  * @param Callback Function to be called after the break signal is sent.
545  * @param CallbackData Pointer to the user data to be supplied as callback parameter.
546  **********************************************************************/
547 static inline void UartSendBreak(const struct uart_t *Uart,
548  uart_break_callback_t Callback, void *CallbackData)
549 {
550  UART_VCALL(Uart, UartSendBreak)(Uart, Callback, CallbackData);
551 }
552 
553 /**********************************************************************/
554 /**
555  * @brief Manually drives RTS pin.
556  * HW flow control must be off to use this function.
557  *
558  * @param Uart UART parameters to be used.
559  * @param Active TRUE: set RTS active (logic 0)
560  * FALSE: set RTS passive (logical 1)
561  **********************************************************************/
562 static inline void UartSetRts(const struct uart_t *Uart, bool Active)
563 {
564  UART_VCALL(Uart, UartSetRts)(Uart, Active);
565 }
566 
567 /** @} uart */
568 
569 #endif // UART_H
Generic data buffer.
struct uart_state_t * State
Address to struct with RAM variables used by the uart driver.
Definition: uart.h:225
Two stop bits.
Definition: uart.h:89
No Rx timeout: check buffer and return immedialely.
Definition: uart.h:106
default word length (8 bit)
Definition: uart.h:113
Parity bit is on. Calculate odd parity.
Definition: uart.h:76
6 bit word length
Definition: uart.h:115
struct data_buffer_t TxBuffer[2]
Transmit buffer for asynchronous transfers.
Definition: uart.h:185
void * TxCallbackData
Data for the TX completion callback.
Definition: uart.h:187
static void UartStartPingPongTx(const struct uart_t *Uart, uint8_t *PrimDataSrc, uint16_t PrimDataSize, uint8_t *AltDataSrc, uint16_t AltDataSize, uart_tx_callback_t Callback, void *CallbackData)
Name: UartStartPingPongTx Transmit data using DMA transfer in PingPong mode. Will alternate between p...
Definition: uart.h:314
void(* uart_rx_callback_t)(const struct uart_t *Uart, void *CallbackData, enum uart_rx_status_t RxStatus)
Definition: uart.h:129
static void UartDisable(const struct uart_t *Uart)
Name: UartDisable Disables UART.
Definition: uart.h:260
static void UartSendBreak(const struct uart_t *Uart, uart_break_callback_t Callback, void *CallbackData)
Sends break (sets TX to logic 0 for a time of 1 byte transmission)
Definition: uart.h:547
uart_parity_t
Definition: uart.h:72
static void UartStartBasicRx(const struct uart_t *Uart, uint8_t *DataDest, uint16_t DataSize, uart_rx_callback_t Callback, void *CallbackData)
Name: UartStartBasicRx Receive data using DMA transfer in basic mode. Using primary DMA descriptor on...
Definition: uart.h:369
Definition: uart.h:222
Header file for the EVE power management framework.
No parity bit.
Definition: uart.h:74
Flow control OFF.
Definition: uart.h:66
static void UartStartBasicTx(const struct uart_t *Uart, uint8_t *DataSrc, uint16_t DataSize, uart_tx_callback_t Callback, void *CallbackData)
Name: UartStartBasicTx Transmit data using DMA transfer in basic mode. Using primary DMA descriptor o...
Definition: uart.h:292
const struct uart_api_t * Func
Virtual function table.
Definition: uart.h:234
SW flow control.
Definition: uart.h:68
HW flow control.
Definition: uart.h:67
Receiving completed successfully.
Definition: uart.h:95
Parity error while receiving.
Definition: uart.h:98
uint8_t RxBufIndex
Index of the active RX buffer.
Definition: uart.h:182
8 bit word length
Definition: uart.h:117
uart_stops_t
Definition: uart.h:86
uint8_t TxBufIndex
Index of the active TX buffer.
Definition: uart.h:188
static void UartSetRts(const struct uart_t *Uart, bool Active)
Manually drives RTS pin. HW flow control must be off to use this function.
Definition: uart.h:562
uart_rx_status_t
Definition: uart.h:93
Frame error (no stop bit) while receiving.
Definition: uart.h:99
uart_tx_callback_t TxCallback
TX completion callback.
Definition: uart.h:186
Parity bit is on. Calculate even parity.
Definition: uart.h:75
Buffer overrun while receiving.
Definition: uart.h:97
void(* uart_init_t)(const struct uart_t *Uart)
Definition: uart.h:151
static uint32_t UartDmaBytesReceived(const struct uart_t *Uart)
Name: UartDmaBytesReceived Will return number of received bytes for current DMA transfer.
Definition: uart.h:273
uint16_t Pos
Definition: data-buffer.h:53
static void UartInit(const struct uart_t *Uart)
Name: UartInit Initializes Uart.
Definition: uart.h:247
static void UartCancelRx(const struct uart_t *Uart)
Name: UartCancelRx Shuts down DMA, flushes FIFO and disables RX interrupts for the UART...
Definition: uart.h:458
Header file for the EVE clock management framework.
uint32_t RxStartTimeoutUs
Default value for the max time the driver waits for the first symbol in a message.
Definition: uart.h:232
void(* uart_tx_callback_t)(const struct uart_t *Uart, void *CallbackData)
Definition: uart.h:137
const struct uart_t * Uart
Backpointer to the static configuration.
Definition: uart.h:175
void * BreakCallbackData
Data for the Break send completion callback.
Definition: uart.h:191
static const struct data_buffer_t * UartGetRxBuffer(const struct uart_t *Uart)
Name: UartGetRxBuffer Returns the current RX buffer.
Definition: uart.h:428
static void UartSetBaudrate(const struct uart_t *Uart, uint32_t Baudrate)
Name: UartSetBaudrate Sets new baudrate to the UART Note that in many situation Rx timeout settings m...
Definition: uart.h:512
uart_wordlen_t
Definition: uart.h:111
No Rx timeout: wait forever.
Definition: uart.h:107
One stop bit.
Definition: uart.h:88
uint8_t TxStop
Amount of TX buffers in the pipeline.
Definition: uart.h:189
Header file for the EVE microsecond-scale work scheduling.
Break received.
Definition: uart.h:100
void * RxCallbackData
Data for the RX completion callback.
Definition: uart.h:181
5 bit word length
Definition: uart.h:114
uart_rx_callback_t RxCallback
RX completion callback.
Definition: uart.h:180
static void UartCancelTx(const struct uart_t *Uart)
Name: UartCancelTx Shuts down DMA, flushes FIFO and disables TX interrupts for the UART...
Definition: uart.h:483
uart_break_callback_t BreakCallback
Send Break completion callback.
Definition: uart.h:190
uint32_t RxStartTimeoutUs
Current value for the max time the driver waits for the first symbol in a message.
Definition: uart.h:177
uint32_t Baudrate
Current baudrate in bit/s.
Definition: uart.h:176
Timeout while receiving (long delay after the last char received, typically 4 chars pause) ...
Definition: uart.h:96
struct data_buffer_t RxBuffer[2]
Receive buffer for asynchronous transfers.
Definition: uart.h:179
static void UartRefreshPingPongTx(const struct uart_t *Uart, uint8_t *DataSrc, uint16_t DataSize, bool Stop)
Name: UartRefreshPingPongTx Refresh transmit of data using DMA transfer in PingPong mode...
Definition: uart.h:335
uint32_t RxStopTimeoutUs
Default value for the max time the driver waits for the next symbol in a message. ...
Definition: uart.h:233
static void UartRefreshPingPongRx(const struct uart_t *Uart, uint8_t *DataDest, uint16_t DataSize, bool Stop)
Name: UartRefreshPingPongRx Refresh of receive data using DMA transfer in PingPong mode...
Definition: uart.h:413
static struct data_buffer_t * UartGetTxBuffer(const struct uart_t *Uart)
Name: UartGetTxBuffer Returns the current TX buffer.
Definition: uart.h:350
uint8_t RxCancelled
RX is cancelled.
Definition: uart.h:184
Definition: uwork.h:142
uint8_t RxStop
Amount of RX buffers in the pipeline.
Definition: uart.h:183
static void UartSetRxTimeouts(const struct uart_t *Uart, uint32_t RxStartTimeoutUs, uint32_t RxStopTimeoutUs)
Name: UartSetRxTimeouts Sets timeout values for the UART Calling code can use value UART_RX_TIMEOUT_D...
Definition: uart.h:533
7 bit word length
Definition: uart.h:116
Rx was aborted by UartCancelRx()
Definition: uart.h:101
static void UartStartPingPongRx(const struct uart_t *Uart, uint8_t *PrimDataDest, uint16_t PrimDataSize, uint8_t *AltDataDest, uint16_t AltDataSize, uart_rx_callback_t Callback, void *CallbackData)
Name: UartStartPingPongRx Receive data using DMA transfer in PingPong mode. Will alternate between pr...
Definition: uart.h:391
static bool UartIsBusyTx(const struct uart_t *Uart)
Name: UartIsBusyTx Returns busy status of the UART TX path.
Definition: uart.h:496
static void UartResetFifo(const struct uart_t *Uart, bool Tx, bool Rx)
Name: UartResetFifo Resets FIFO buffer for Tx or Rx or both. NB: Resetting Rx FIFO stops receiving...
Definition: uart.h:445
uart_flow_control_t
Definition: uart.h:64
Parity bit is on and always 1.
Definition: uart.h:77
static bool UartIsBusyRx(const struct uart_t *Uart)
Name: UartIsBusyRx Returns busy status of the UART RX path.
Definition: uart.h:471
uint32_t RxStopTimeoutUs
Current value for the max time the driver waits for the next symbol in a message. ...
Definition: uart.h:178
void(* uart_break_callback_t)(const struct uart_t *Uart, void *CallbackData)
Definition: uart.h:145
struct uwork_t SendBreakWork
timeout counter for Send Break
Definition: uart.h:192
Parity bit is on and always 0.
Definition: uart.h:78
const void * Impl
Device specific configuration data.
Definition: uart.h:224