1 /**
2  * @file    uart.h
3  * @brief   Serial Peripheral Interface (UART) communications driver.
4  */
5 
6 /******************************************************************************
7  *
8  * Copyright (C) 2022-2023 Maxim Integrated Products, Inc. (now owned by
9  * Analog Devices, Inc.),
10  * Copyright (C) 2023-2024 Analog Devices, Inc.
11  *
12  * Licensed under the Apache License, Version 2.0 (the "License");
13  * you may not use this file except in compliance with the License.
14  * You may obtain a copy of the License at
15  *
16  *     http://www.apache.org/licenses/LICENSE-2.0
17  *
18  * Unless required by applicable law or agreed to in writing, software
19  * distributed under the License is distributed on an "AS IS" BASIS,
20  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21  * See the License for the specific language governing permissions and
22  * limitations under the License.
23  *
24  ******************************************************************************/
25 
26 /* Define to prevent redundant inclusion */
27 #ifndef LIBRARIES_PERIPHDRIVERS_INCLUDE_MAX78000_UART_H_
28 #define LIBRARIES_PERIPHDRIVERS_INCLUDE_MAX78000_UART_H_
29 
30 /***** Definitions *****/
31 #include <stdbool.h>
32 #include "uart_regs.h"
33 #include "mxc_sys.h"
34 
35 #define UART_EXTCLK_FREQ EXTCLK_FREQ
36 
37 #ifdef __cplusplus
38 extern "C" {
39 #endif
40 
41 /**
42  * @defgroup uart UART
43  * @ingroup periphlibs
44  * @{
45  */
46 
47 typedef struct _mxc_uart_req_t mxc_uart_req_t;
48 /**
49  * @brief   The list of UART stop bit lengths supported
50  *
51  */
52 typedef enum {
53     MXC_UART_STOP_1, ///< UART Stop 1 clock cycle
54     MXC_UART_STOP_2, ///< UART Stop 2 clock cycle (1.5 clocks for 5 bit characters)
55 } mxc_uart_stop_t;
56 
57 /**
58  * @brief   The list of UART Parity options supported
59  *
60  */
61 typedef enum {
62     MXC_UART_PARITY_DISABLE, ///< UART Parity Disabled
63     MXC_UART_PARITY_EVEN_0, ///< UART Parity Even, 0 based
64     MXC_UART_PARITY_EVEN_1, ///< UART Parity Even, 1 based
65     MXC_UART_PARITY_ODD_0, ///< UART Parity Odd, 0 based
66     MXC_UART_PARITY_ODD_1, ///< UART Parity Odd, 1 based
67 } mxc_uart_parity_t;
68 
69 /**
70  * @brief   The list of UART flow control options supported
71  *
72  */
73 typedef enum {
74     MXC_UART_FLOW_DIS, ///< UART Flow Control Disabled
75     MXC_UART_FLOW_EN, ///< UART Flow Control Enabled
76 } mxc_uart_flow_t;
77 
78 /**
79  * @brief      Clock settings */
80 typedef enum {
81     /*For UART3 APB clock source is the 8MHz clock*/
82     MXC_UART_APB_CLK = 0,
83     /*IBRO clock can only be used for UART 0, 1 & 2*/
84     MXC_UART_IBRO_CLK = 2,
85     /*ERTCO clock can only be used for UART3*/
86     MXC_UART_ERTCO_CLK = 4,
87 } mxc_uart_clock_t;
88 
89 /**
90  * @brief   The callback routine used to indicate the transaction has terminated.
91  *
92  * @param   req          The details of the transaction.
93  * @param   result       See \ref MXC_Error_Codes for the list of error codes.
94  */
95 typedef void (*mxc_uart_complete_cb_t)(mxc_uart_req_t *req, int result);
96 
97 /**
98  * @brief   The callback routine used to indicate the transaction has terminated.
99  *
100  * @param   req          The details of the transaction.
101  * @param   num          The number of characters actually copied
102  * @param   result       See \ref MXC_Error_Codes for the list of error codes.
103  */
104 typedef void (*mxc_uart_dma_complete_cb_t)(mxc_uart_req_t *req, int num, int result);
105 
106 /**
107  * @brief   The information required to perform a complete UART transaction
108  *
109  * @note    This structure is used by blocking, async, and DMA based transactions.
110  * @note    "callback" only needs to be initialized for interrupt driven (Async) or DMA transactions.
111  */
112 struct _mxc_uart_req_t {
113     mxc_uart_regs_t *uart; ///<Point to UART registers
114     const uint8_t *txData; ///< Buffer containing transmit data. For character sizes
115         ///< < 8 bits, pad the MSB of each byte with zeros. For
116         ///< character sizes > 8 bits, use two bytes per character
117         ///< and pad the MSB of the upper byte with zeros
118     uint8_t *rxData; ///< Buffer to store received data For character sizes
119         ///< < 8 bits, pad the MSB of each byte with zeros. For
120         ///< character sizes > 8 bits, use two bytes per character
121         ///< and pad the MSB of the upper byte with zeros
122     uint32_t txLen; ///< Number of bytes to be sent from txData
123     uint32_t rxLen; ///< Number of bytes to be stored in rxData
124     volatile uint32_t txCnt; ///< Number of bytes actually transmitted from txData
125     volatile uint32_t rxCnt; ///< Number of bytes stored in rxData
126 
127     mxc_uart_complete_cb_t callback; ///< Pointer to function called when transaction is complete
128 };
129 
130 /***** Function Prototypes *****/
131 
132 /* ************************************************************************* */
133 /* Control/Configuration functions                                           */
134 /* ************************************************************************* */
135 
136 /**
137  * @brief   Initialize and enable UART peripheral.
138  *
139  * This function initializes everything necessary to call a UART transaction function.
140  * Some parameters are set to defaults as follows:
141  * UART Data Size    - 8 bits
142  * UART Stop Bits    - 1 bit
143  * UART Parity       - None
144  * UART Flow Control - None
145  *
146  * These parameters can be modified after initialization using low level functions
147  *
148  * @param   uart         Pointer to UART registers (selects the UART block used.)
149  * @param   baud         The requested clock frequency. The actual clock frequency
150  *                       will be returned by the function if successful.
151  * @param   clock        Clock source
152  *
153  * @return  Success/Fail, see \ref MXC_Error_Codes for a list of return codes.
154  */
155 int MXC_UART_Init(mxc_uart_regs_t *uart, unsigned int baud, mxc_uart_clock_t clock);
156 
157 /**
158  * @brief   Disable and shutdown UART peripheral.
159  *
160  * @param   uart         Pointer to UART registers (selects the UART block used.)
161  *
162  * @return  Success/Fail, see \ref MXC_Error_Codes for a list of return codes.
163  */
164 int MXC_UART_Shutdown(mxc_uart_regs_t *uart);
165 
166 /**
167  * @brief   Checks if the given UART bus can be placed in sleep more.
168  *
169  * @note    This functions checks to see if there are any on-going UART transactions in
170  *          progress. If there are transactions in progress, the application should
171  *          wait until the UART bus is free before entering a low-power state.
172  *
173  * @param   uart         Pointer to UART registers (selects the UART block used.)
174  *
175  * @return  #E_NO_ERROR if ready, and non-zero if busy or error. See \ref
176  *          MXC_Error_Codes for the list of error return codes.
177  */
178 int MXC_UART_ReadyForSleep(mxc_uart_regs_t *uart);
179 
180 /**
181  * @brief   Set the frequency of the UART interface.
182  *
183  * @param   uart         Pointer to UART registers (selects the UART block used.)
184  * @param   baud         The desired baud rate
185  * @param   clock        Clock source
186  *
187  * @return  Negative if error, otherwise actual speed set. See \ref
188  *          MXC_Error_Codes for the list of error return codes.
189  */
190 int MXC_UART_SetFrequency(mxc_uart_regs_t *uart, unsigned int baud, mxc_uart_clock_t clock);
191 
192 /**
193  * @brief   Get the frequency of the UART interface.
194  *
195  * @note    This function is applicable in Master mode only
196  *
197  * @param   uart         Pointer to UART registers (selects the UART block used.)
198  *
199  * @return  The UART baud rate
200  */
201 int MXC_UART_GetFrequency(mxc_uart_regs_t *uart);
202 
203 /**
204  * @brief   Sets the number of bits per character
205  *
206  * @param   uart         Pointer to UART registers (selects the UART block used.)
207  * @param   dataSize     The number of bits per character (5-8 bits/character are valid)
208  *
209  * @return  Success/Fail, see \ref MXC_Error_Codes for a list of return codes.
210  */
211 int MXC_UART_SetDataSize(mxc_uart_regs_t *uart, int dataSize);
212 
213 /**
214  * @brief   Sets the number of stop bits sent at the end of a character
215  *
216  * @param   uart         Pointer to UART registers (selects the UART block used.)
217  * @param   stopBits     The number of stop bits used
218  *
219  * @return  Success/Fail, see \ref MXC_Error_Codes for a list of return codes.
220  */
221 int MXC_UART_SetStopBits(mxc_uart_regs_t *uart, mxc_uart_stop_t stopBits);
222 
223 /**
224  * @brief   Sets the type of parity generation used
225  *
226  * @param   uart         Pointer to UART registers (selects the UART block used.)
227  * @param   parity       see \ref UART Parity Types for details
228  *
229  * @return  Success/Fail, see \ref MXC_Error_Codes for a list of return codes.
230  */
231 int MXC_UART_SetParity(mxc_uart_regs_t *uart, mxc_uart_parity_t parity);
232 
233 /**
234  * @brief   Sets the flow control used
235  *
236  * @param   uart            Pointer to UART registers (selects the UART block used.)
237  * @param   flowCtrl        see \ref UART Flow Control Types for details
238  * @param   rtsThreshold    Number of bytes remaining in the RX FIFO when RTS is asserted
239  *
240  * @return  Success/Fail, see \ref MXC_Error_Codes for a list of return codes.
241  */
242 int MXC_UART_SetFlowCtrl(mxc_uart_regs_t *uart, mxc_uart_flow_t flowCtrl, int rtsThreshold);
243 
244 /**
245  * @brief   Sets the clock source for the baud rate generator
246  *
247  * @param   uart         Pointer to UART registers (selects the UART block used.)
248  * @param   clock        Clock source
249  *
250  * @return  Actual baud rate if successful, otherwise see \ref MXC_Error_Codes
251  *          for a list of return codes.
252  */
253 int MXC_UART_SetClockSource(mxc_uart_regs_t *uart, mxc_uart_clock_t clock);
254 
255 /* ************************************************************************* */
256 /* Low-level functions                                                       */
257 /* ************************************************************************* */
258 
259 /**
260  * @brief   Checks the UART Peripheral for an ongoing transmission
261  *
262  * @note    This function is applicable in Master mode only
263  *
264  * @param   uart         Pointer to UART registers (selects the UART block used.)
265  *
266  * @return  Active/Inactive, see \ref MXC_Error_Codes for a list of return codes.
267  */
268 int MXC_UART_GetActive(mxc_uart_regs_t *uart);
269 
270 /**
271  * @brief   Aborts an ongoing UART Transmission
272  *
273  * @param   uart         Pointer to UART registers (selects the UART block used.)
274  *
275  * @return  Success/Fail, see \ref MXC_Error_Codes for a list of return codes.
276  */
277 int MXC_UART_AbortTransmission(mxc_uart_regs_t *uart);
278 
279 /**
280  * @brief   Reads the next available character. If no character is available, this function
281  *          will return an error.
282  *
283  * @param   uart         Pointer to UART registers (selects the UART block used.)
284  *
285  * @return  The character read, otherwise see \ref MXC_Error_Codes for a list of return codes.
286  */
287 int MXC_UART_ReadCharacterRaw(mxc_uart_regs_t *uart);
288 
289 /**
290  * @brief   Writes a character on the UART. If the character cannot be written because the
291  *          transmit FIFO is currently full, this function returns an error.
292  *
293  * @param   uart         Pointer to UART registers (selects the UART block used.)
294  * @param   character         The character to write
295  *
296  * @return  Success/Fail, see \ref MXC_Error_Codes for a list of return codes.
297  */
298 int MXC_UART_WriteCharacterRaw(mxc_uart_regs_t *uart, uint8_t character);
299 
300 /**
301  * @brief   Reads the next available character
302  *
303  * @param   uart         Pointer to UART registers (selects the UART block used.)
304  *
305  * @return  The character read, otherwise see \ref MXC_Error_Codes for a list of return codes.
306  */
307 int MXC_UART_ReadCharacter(mxc_uart_regs_t *uart);
308 
309 /**
310  * @brief   Writes a character on the UART
311  *
312  * @param   uart         Pointer to UART registers (selects the UART block used.)
313  * @param   character    The character to write
314  *
315  * @return  Success/Fail, see \ref MXC_Error_Codes for a list of return codes.
316  */
317 int MXC_UART_WriteCharacter(mxc_uart_regs_t *uart, uint8_t character);
318 
319 /**
320  * @brief   Reads the next available character
321  * @note    This function blocks until len characters are received
322  *          See MXC_UART_TransactionAsync() for a non-blocking version
323  *
324  * @param   uart         Pointer to UART registers (selects the UART block used.)
325  * @param   buffer       Buffer to store data in
326  * @param   len          Number of characters
327  *
328  * @return  The character read, otherwise see \ref MXC_Error_Codes for a list of return codes.
329  */
330 int MXC_UART_Read(mxc_uart_regs_t *uart, uint8_t *buffer, int *len);
331 
332 /**
333  * @brief   Writes a byte on the UART
334  *
335  * @param   uart         Pointer to UART registers (selects the UART block used.)
336  * @param   byte         The buffer of characters to write
337  * @param   len          The number of characters to write
338  *
339  * @return  Success/Fail, see \ref MXC_Error_Codes for a list of return codes.
340  */
341 int MXC_UART_Write(mxc_uart_regs_t *uart, const uint8_t *byte, int *len);
342 
343 /**
344  * @brief   Unloads bytes from the receive FIFO.
345  *
346  * @param   uart         Pointer to UART registers (selects the UART block used.)
347  * @param   bytes        The buffer to read the data into.
348  * @param   len          The number of bytes to read.
349  *
350  * @return  The number of bytes actually read.
351  */
352 unsigned int MXC_UART_ReadRXFIFO(mxc_uart_regs_t *uart, unsigned char *bytes, unsigned int len);
353 
354 /**
355  * @brief   Unloads bytes from the receive FIFO user DMA for longer reads.
356  *
357  * @param   uart         Pointer to UART registers (selects the UART block used.)
358  * @param   bytes        The buffer to read the data into.
359  * @param   len          The number of bytes to read.
360  * @param   callback     The function to call when the read is complete
361  *
362  * @return  See \ref MXC_ERROR_CODES for a list of return values
363  */
364 int MXC_UART_ReadRXFIFODMA(mxc_uart_regs_t *uart, unsigned char *bytes, unsigned int len,
365                            mxc_uart_dma_complete_cb_t callback);
366 
367 /**
368  * @brief   Get the number of bytes currently available in the receive FIFO.
369  *
370  * @param   uart         Pointer to UART registers (selects the UART block used.)
371  *
372  * @return  The number of bytes available.
373  */
374 unsigned int MXC_UART_GetRXFIFOAvailable(mxc_uart_regs_t *uart);
375 
376 /**
377  * @brief   Loads bytes into the transmit FIFO.
378  *
379  * @param   uart         Pointer to UART registers (selects the UART block used.)
380  * @param   bytes        The buffer containing the bytes to write
381  * @param   len          The number of bytes to write.
382  *
383  * @return  The number of bytes actually written.
384  */
385 unsigned int MXC_UART_WriteTXFIFO(mxc_uart_regs_t *uart, const unsigned char *bytes,
386                                   unsigned int len);
387 
388 /**
389  * @brief   Loads bytes into the transmit FIFO using DMA for longer writes
390  *
391  * @param   uart         Pointer to UART registers (selects the UART block used.)
392  * @param   bytes        The buffer containing the bytes to write
393  * @param   len          The number of bytes to write.
394  * @param   callback     The function to call when the write is complete
395  *
396  * @return  See \ref MXC_ERROR_CODES for a list of return values
397  */
398 int MXC_UART_WriteTXFIFODMA(mxc_uart_regs_t *uart, const unsigned char *bytes, unsigned int len,
399                             mxc_uart_dma_complete_cb_t callback);
400 
401 /**
402  * @brief   Get the amount of free space available in the transmit FIFO.
403  *
404  * @param   uart         Pointer to UART registers (selects the UART block used.)
405  *
406  * @return  The number of bytes available.
407  */
408 unsigned int MXC_UART_GetTXFIFOAvailable(mxc_uart_regs_t *uart);
409 
410 /**
411  * @brief   Removes and discards all bytes currently in the receive FIFO.
412  *
413  * @param   uart         Pointer to UART registers (selects the UART block used.)
414  *
415  * @return  See \ref MXC_Error_Codes for the list of error return codes.
416  */
417 int MXC_UART_ClearRXFIFO(mxc_uart_regs_t *uart);
418 
419 /**
420  * @brief   Removes and discards all bytes currently in the transmit FIFO.
421  *
422  * @param   uart         Pointer to UART registers (selects the UART block used.)
423  *
424  * @return  See \ref MXC_Error_Codes for the list of error return codes.
425  */
426 int MXC_UART_ClearTXFIFO(mxc_uart_regs_t *uart);
427 
428 /**
429  * @brief   Set the receive threshold level.
430  *
431  * @note    RX FIFO Receive threshold. Smaller values will cause
432  *          interrupts to occur more often, but reduce the possibility
433  *          of losing data because of a FIFO overflow. Larger values
434  *          will reduce the time required by the ISR, but increase the
435  *          possibility of data loss. Passing an invalid value will
436  *          cause the driver to use the value already set in the
437  *          appropriate register.
438  *
439  * @param   uart         Pointer to UART registers (selects the UART block used.)
440  * @param   numBytes     The threshold level to set. This value must be
441  *                       between 0 and 8 inclusive.
442  *
443  * @return  Success/Fail, see \ref MXC_Error_Codes for a list of return codes.
444  */
445 int MXC_UART_SetRXThreshold(mxc_uart_regs_t *uart, unsigned int numBytes);
446 
447 /**
448  * @brief   Get the current receive threshold level.
449  *
450  * @param   uart         Pointer to UART registers (selects the UART block used.)
451  *
452  * @return  The receive threshold value (in bytes).
453  */
454 unsigned int MXC_UART_GetRXThreshold(mxc_uart_regs_t *uart);
455 
456 /**
457  * @brief   Set the transmit threshold level.
458  *
459  * @note    TX FIFO threshold. Smaller values will cause interrupts
460  *          to occur more often, but reduce the possibility of terminating
461  *          a transaction early in master mode, or transmitting invalid data
462  *          in slave mode. Larger values will reduce the time required by
463  *          the ISR, but increase the possibility errors occurring. Passing
464  *          an invalid value will cause the driver to use the value already
465  *          set in the appropriate register.
466  *
467  * @param   uart         Pointer to UART registers (selects the UART block used.)
468  * @param   numBytes     The threshold level to set.  This value must be
469  *                       between 0 and 8 inclusive.
470  *
471  * @return  Success/Fail, see \ref MXC_Error_Codes for a list of return codes.
472  */
473 int MXC_UART_SetTXThreshold(mxc_uart_regs_t *uart, unsigned int numBytes);
474 
475 /**
476  * @brief   Get the current transmit threshold level.
477  *
478  * @param   uart         Pointer to UART registers (selects the UART block used.)
479  *
480  * @return  The transmit threshold value (in bytes).
481  */
482 unsigned int MXC_UART_GetTXThreshold(mxc_uart_regs_t *uart);
483 
484 /**
485  * @brief   Gets the interrupt flags that are currently set
486  *
487  * @note    These functions should not be used while using non-blocking Transaction Level
488  *          functions (Async or DMA)
489  *
490  * @param   uart         Pointer to UART registers (selects the UART block used.)
491  *
492  * @return The interrupt flags
493  */
494 unsigned int MXC_UART_GetFlags(mxc_uart_regs_t *uart);
495 
496 /**
497  * @brief   Clears the interrupt flags that are currently set
498  *
499  * @note    These functions should not be used while using non-blocking Transaction Level
500  *          functions (Async or DMA)
501  *
502  * @param   uart         Pointer to UART registers (selects the UART block used.)
503  * @param   flags        mask of flags to clear
504  *
505  * @return  See \ref MXC_Error_Codes for the list of error return codes.
506  */
507 int MXC_UART_ClearFlags(mxc_uart_regs_t *uart, unsigned int flags);
508 
509 /**
510  * @brief   Enables specific interrupts
511  *
512  * @note    These functions should not be used while using non-blocking Transaction Level
513  *          functions (Async or DMA)
514  *
515  * @param   uart         Pointer to UART registers (selects the UART block used.)
516  * @param   mask         The interrupts to be enabled
517  *
518  * @return  See \ref MXC_Error_Codes for the list of error return codes.
519  */
520 int MXC_UART_EnableInt(mxc_uart_regs_t *uart, unsigned int mask);
521 
522 /**
523  * @brief   Disables specific interrupts
524  *
525  * @note    These functions should not be used while using non-blocking Transaction Level
526  *          functions (Async or DMA)
527  *
528  * @param   uart         Pointer to UART registers (selects the UART block used.)
529  * @param   mask         The interrupts to be disabled
530  *
531  * @return  See \ref MXC_Error_Codes for the list of error return codes.
532  */
533 int MXC_UART_DisableInt(mxc_uart_regs_t *uart, unsigned int mask);
534 
535 /**
536  * @brief   Gets the status flags that are currently set
537  *
538  * @param   uart         Pointer to UART registers (selects the UART block used.)
539  *
540  * @return  The status flags
541  */
542 unsigned int MXC_UART_GetStatus(mxc_uart_regs_t *uart);
543 
544 /* ************************************************************************* */
545 /* Transaction level functions                                               */
546 /* ************************************************************************* */
547 
548 /**
549  * @brief   Performs a blocking UART transaction.
550  *
551  * @note    Performs a blocking UART transaction as follows.
552  *          If tx_len is non-zero, transmit TX data
553  *          Once tx_len has been sent, if rx_len is non-zero, receive data
554  *
555  * @param   req          Pointer to details of the transaction
556  *
557  * @return  See \ref MXC_Error_Codes for the list of error return codes.
558  */
559 int MXC_UART_Transaction(mxc_uart_req_t *req);
560 
561 /**
562  * @brief   Setup an interrupt-driven UART transaction
563  *
564  * @note    The TX FIFO will be filled with txData if necessary
565  *          Relevant interrupts will be enabled
566  *
567  * @param   req          Pointer to details of the transaction
568  *
569  * @return  See \ref MXC_Error_Codes for the list of error return codes.
570  */
571 int MXC_UART_TransactionAsync(mxc_uart_req_t *req);
572 
573 /**
574  * @brief   Setup a DMA driven UART transaction
575  *
576  * @note    The TX FIFO will be filled with txData if necessary
577  *          Relevant interrupts will be enabled
578  *          The DMA channel indicated by the request will be set up to load/unload the FIFOs
579  *          with as few interrupt-based events as possible. The channel will be reset and
580  *          returned to the system at the end of the transaction.
581  *
582  * @param   req          Pointer to details of the transaction
583  *
584  * @return  See \ref MXC_Error_Codes for the list of error return codes.
585  */
586 int MXC_UART_TransactionDMA(mxc_uart_req_t *req);
587 
588 /**
589  * @brief   The processing function for DMA transactions.
590  *
591  * When using the DMA functions, the application must call this
592  * function periodically. This can be done from within the DMA Interrupt Handler.
593  *
594  * @param   ch          DMA channel
595  * @param   error       Error status
596  */
597 void MXC_UART_DMACallback(int ch, int error);
598 
599 /**
600  * @brief   Async callback
601  *
602  * @param   uart      The uart
603  * @param   retVal    The ret value
604  *
605  * @return  See \ref MXC_Error_Codes for the list of error return codes.
606  */
607 int MXC_UART_AsyncCallback(mxc_uart_regs_t *uart, int retVal);
608 
609 /**
610  * @brief   stop any async callbacks
611  *
612  * @param   uart      The uart
613  *
614  * @return  See \ref MXC_Error_Codes for the list of error return codes.
615  */
616 int MXC_UART_AsyncStop(mxc_uart_regs_t *uart);
617 
618 /**
619  * @brief   Abort any asynchronous requests in progress.
620  *
621  * @note    Abort any asynchronous requests in progress. Any callbacks associated with
622  *          the active transaction will be executed to indicate when the transaction
623  *          has been terminated.
624  *
625  * @param   uart         Pointer to UART registers (selects the UART block used.)
626  *
627  * @return  See \ref MXC_Error_Codes for the list of error return codes.
628  */
629 int MXC_UART_AbortAsync(mxc_uart_regs_t *uart);
630 
631 /**
632  * @brief   The processing function for asynchronous transactions.
633  *
634  * @note    When using the asynchronous functions, the application must call this
635  *          function periodically. This can be done from within the UART interrupt
636  *          handler or periodically by the application if UART interrupts are disabled.
637  *
638  * @param   uart         Pointer to UART registers (selects the UART block used.)
639  *
640  * @return  See \ref MXC_Error_Codes for the list of error return codes.
641  */
642 int MXC_UART_AsyncHandler(mxc_uart_regs_t *uart);
643 
644 /**
645  * @brief   Provide TXCount for asynchronous transactions..
646  *
647  * @param   uart         Pointer to UART registers (selects the UART block used.)
648  *
649  * @return  Returns transmit bytes (in FIFO).
650  */
651 uint32_t MXC_UART_GetAsyncTXCount(mxc_uart_req_t *req);
652 
653 /**
654  * @brief   Provide RXCount for asynchronous transactions..
655  *
656  * @param   uart         Pointer to UART registers (selects the UART block used.)
657  *
658  * @return  Returns receive bytes (in FIFO).
659  */
660 uint32_t MXC_UART_GetAsyncRXCount(mxc_uart_req_t *req);
661 
662 /**
663  * @brief Enable or disable automatic DMA interrupt handlers for the UART module.
664  *
665  * The @ref MXC_UART_TransactionDMA functions require special interrupt handlers to work.
666  *
667  * When "Auto" DMA handlers are enabled, the UART drivers will acquire DMA channels
668  * and assign the appropriate handlers automatically.  The acquired channels are
669  * released after each transaction.
670  *
671  * If "Auto" DMA handlers are disabled, the user must acquire DMA channels manually
672  * and assign them to the drivers with the @ref MXC_UART_SetTXDMAChannel and
673  * @ref MXC_UART_SetRXDMAChannel functions.
674  *
675  * @param uart Pointer to the UART module's registers.
676  * @param enable true to enable Auto DMA handlers, false to disable.
677  * @return 0 on success, or a non-zero error code on failure.
678  */
679 int MXC_UART_SetAutoDMAHandlers(mxc_uart_regs_t *uart, bool enable);
680 
681 /**
682  * @brief Set the TX (Transmit) DMA channel for a UART module.
683  *
684  * This function assigns the DMA channel for transmitting data
685  * when @ref is MXC_UART_SetAutoDMAHandlers disabled.
686  *
687  * @param uart Pointer to the UART module's registers.
688  * @param channel The DMA channel number to be used for @ref MXC_UART_TransactionDMA.
689  */
690 int MXC_UART_SetTXDMAChannel(mxc_uart_regs_t *uart, unsigned int channel);
691 
692 /**
693  * @brief Get the TX (Transmit) DMA channel for a UART module.
694  *
695  * This function retrieves the currently assigned DMA channel for transmitting data
696  * when @ref is MXC_UART_SetAutoDMAHandlers disabled.
697  *
698  * @param uart Pointer to the UART module's registers.
699  * @return The currently assigned TX DMA channel.
700  */
701 int MXC_UART_GetTXDMAChannel(mxc_uart_regs_t *uart);
702 
703 /**
704  * @brief Set the RX (Receive) DMA channel for a UART module.
705  *
706  * This function assigns the DMA channel for receiving data
707  * when @ref is MXC_UART_SetAutoDMAHandlers disabled.
708  *
709  * @param uart Pointer to the UART module's registers.
710  * @param channel The DMA channel number to be used for @ref MXC_UART_TransactionDMA.
711  */
712 int MXC_UART_SetRXDMAChannel(mxc_uart_regs_t *uart, unsigned int channel);
713 
714 /**
715  * @brief Get the RX (Receive) DMA channel for a UART module.
716  *
717  * This function retrieves the currently configured DMA channel for receiving data
718  * when @ref is MXC_UART_SetAutoDMAHandlers disabled.
719  *
720  * @param uart Pointer to the UART module's registers.
721  * @return The currently configured RX DMA channel.
722  */
723 int MXC_UART_GetRXDMAChannel(mxc_uart_regs_t *uart);
724 
725 /**@} end of group uart */
726 
727 #ifdef __cplusplus
728 }
729 #endif
730 
731 #endif // LIBRARIES_PERIPHDRIVERS_INCLUDE_MAX78000_UART_H_
732