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