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_MAX32655_UART_H_ 28 #define LIBRARIES_PERIPHDRIVERS_INCLUDE_MAX32655_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 #define UART_EXTCLK_FREQ E_BAD_PARAM 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 /*Only available for UARTS 0-2*/ 82 MXC_UART_APB_CLK = 0, 83 /*Available for all UARTs*/ 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) and 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 * @note On default this function enables UART peripheral clock. 149 * if you wish to manage clock and gpio related things in upper level instead of here. 150 * Define MSDK_NO_GPIO_CLK_INIT flag in project.mk file. 151 * By this flag this function will remove clock and gpio related codes from file. 152 * 153 * @param uart Pointer to UART registers (selects the UART block used.) 154 * @param baud The requested clock frequency. The actual clock frequency 155 * will be returned by the function if successful. 156 * @param clock Clock source 157 * 158 * @return Success/Fail, see \ref MXC_Error_Codes for a list of return codes. 159 */ 160 int MXC_UART_Init(mxc_uart_regs_t *uart, unsigned int baud, mxc_uart_clock_t clock); 161 162 /** 163 * @brief Disable and shutdown UART peripheral. 164 * 165 * @param uart Pointer to UART registers (selects the UART block used.) 166 * 167 * @return Success/Fail, see \ref MXC_Error_Codes for a list of return codes. 168 */ 169 int MXC_UART_Shutdown(mxc_uart_regs_t *uart); 170 171 /** 172 * @brief Checks if the given UART bus can be placed in sleep more. 173 * 174 * @note This functions checks to see if there are any on-going UART transactions in 175 * progress. If there are transactions in progress, the application should 176 * wait until the UART bus is free before entering a low-power state. 177 * 178 * @param uart Pointer to UART registers (selects the UART block used.) 179 * 180 * @return #E_NO_ERROR if ready, and non-zero if busy or error. See \ref 181 * MXC_Error_Codes for the list of error return codes. 182 */ 183 int MXC_UART_ReadyForSleep(mxc_uart_regs_t *uart); 184 185 /** 186 * @brief Set the frequency of the UART interface. 187 * 188 * @param uart Pointer to UART registers (selects the UART block used.) 189 * @param baud The desired baud rate 190 * @param clock Clock source 191 * 192 * @return Negative if error, otherwise actual speed set. See \ref 193 * MXC_Error_Codes for the list of error return codes. 194 */ 195 int MXC_UART_SetFrequency(mxc_uart_regs_t *uart, unsigned int baud, mxc_uart_clock_t clock); 196 197 /** 198 * @brief Get the frequency of the UART interface. 199 * 200 * @note This function is applicable in Master mode only 201 * 202 * @param uart Pointer to UART registers (selects the UART block used.) 203 * 204 * @return The UART baud rate 205 */ 206 int MXC_UART_GetFrequency(mxc_uart_regs_t *uart); 207 208 /** 209 * @brief Sets the number of bits per character 210 * 211 * @param uart Pointer to UART registers (selects the UART block used.) 212 * @param dataSize The number of bits per character (5-8 bits/character are valid) 213 * 214 * @return Success/Fail, see \ref MXC_Error_Codes for a list of return codes. 215 */ 216 int MXC_UART_SetDataSize(mxc_uart_regs_t *uart, int dataSize); 217 218 /** 219 * @brief Sets the number of stop bits sent at the end of a character 220 * 221 * @param uart Pointer to UART registers (selects the UART block used.) 222 * @param stopBits The number of stop bits used 223 * 224 * @return Success/Fail, see \ref MXC_Error_Codes for a list of return codes. 225 */ 226 int MXC_UART_SetStopBits(mxc_uart_regs_t *uart, mxc_uart_stop_t stopBits); 227 228 /** 229 * @brief Sets the type of parity generation used 230 * 231 * @param uart Pointer to UART registers (selects the UART block used.) 232 * @param parity see \ref UART Parity Types for details 233 * 234 * @return Success/Fail, see \ref MXC_Error_Codes for a list of return codes. 235 */ 236 int MXC_UART_SetParity(mxc_uart_regs_t *uart, mxc_uart_parity_t parity); 237 238 /** 239 * @brief Sets the flow control used 240 * 241 * @param uart Pointer to UART registers (selects the UART block used.) 242 * @param flowCtrl see \ref UART Flow Control Types for details 243 * @param rtsThreshold Number of bytes remaining in the RX FIFO when RTS is asserted 244 * 245 * @return Success/Fail, see \ref MXC_Error_Codes for a list of return codes. 246 */ 247 int MXC_UART_SetFlowCtrl(mxc_uart_regs_t *uart, mxc_uart_flow_t flowCtrl, int rtsThreshold); 248 249 /** 250 * @brief Sets the clock source for the baud rate generator 251 * 252 * @param uart Pointer to UART registers (selects the UART block used.) 253 * @param clock Clock source 254 * 255 * @return Actual baud rate if successful, otherwise see \ref MXC_Error_Codes 256 * for a list of return codes. 257 */ 258 int MXC_UART_SetClockSource(mxc_uart_regs_t *uart, mxc_uart_clock_t clock); 259 260 /* ************************************************************************* */ 261 /* Low-level functions */ 262 /* ************************************************************************* */ 263 264 /** 265 * @brief Checks the UART Peripheral for an ongoing transmission 266 * 267 * @note This function is applicable in Master mode only 268 * 269 * @param uart Pointer to UART registers (selects the UART block used.) 270 * 271 * @return Active/Inactive, see \ref MXC_Error_Codes for a list of return codes. 272 */ 273 int MXC_UART_GetActive(mxc_uart_regs_t *uart); 274 275 /** 276 * @brief Aborts an ongoing UART Transmission 277 * 278 * @param uart Pointer to UART registers (selects the UART block used.) 279 * 280 * @return Success/Fail, see \ref MXC_Error_Codes for a list of return codes. 281 */ 282 int MXC_UART_AbortTransmission(mxc_uart_regs_t *uart); 283 284 /** 285 * @brief Reads the next available character. If no character is available, this function 286 * will return an error. 287 * 288 * @param uart Pointer to UART registers (selects the UART block used.) 289 * 290 * @return The character read, otherwise see \ref MXC_Error_Codes for a list of return codes. 291 */ 292 int MXC_UART_ReadCharacterRaw(mxc_uart_regs_t *uart); 293 294 /** 295 * @brief Writes a character on the UART. If the character cannot be written because the 296 * transmit FIFO is currently full, this function returns an error. 297 * 298 * @param uart Pointer to UART registers (selects the UART block used.) 299 * @param character The character to write 300 * 301 * @return Success/Fail, see \ref MXC_Error_Codes for a list of return codes. 302 */ 303 int MXC_UART_WriteCharacterRaw(mxc_uart_regs_t *uart, uint8_t character); 304 305 /** 306 * @brief Reads the next available character 307 * 308 * @param uart Pointer to UART registers (selects the UART block used.) 309 * 310 * @return The character read, otherwise see \ref MXC_Error_Codes for a list of return codes. 311 */ 312 int MXC_UART_ReadCharacter(mxc_uart_regs_t *uart); 313 314 /** 315 * @brief Writes a character on the UART 316 * 317 * @param uart Pointer to UART registers (selects the UART block used.) 318 * @param character The character to write 319 * 320 * @return Success/Fail, see \ref MXC_Error_Codes for a list of return codes. 321 */ 322 int MXC_UART_WriteCharacter(mxc_uart_regs_t *uart, uint8_t character); 323 324 /** 325 * @brief Reads the next available character 326 * @note This function blocks until len characters are received 327 * See MXC_UART_TransactionAsync() for a non-blocking version 328 * 329 * @param uart Pointer to UART registers (selects the UART block used.) 330 * @param buffer Buffer to store data in 331 * @param len Number of characters 332 * 333 * @return The character read, otherwise see \ref MXC_Error_Codes for a list of return codes. 334 */ 335 int MXC_UART_Read(mxc_uart_regs_t *uart, uint8_t *buffer, int *len); 336 337 /** 338 * @brief Writes a byte on the UART 339 * 340 * @param uart Pointer to UART registers (selects the UART block used.) 341 * @param byte The buffer of characters to write 342 * @param len The number of characters to write 343 * 344 * @return Success/Fail, see \ref MXC_Error_Codes for a list of return codes. 345 */ 346 int MXC_UART_Write(mxc_uart_regs_t *uart, const uint8_t *byte, int *len); 347 348 /** 349 * @brief Unloads bytes from the receive FIFO. 350 * 351 * @param uart Pointer to UART registers (selects the UART block used.) 352 * @param bytes The buffer to read the data into. 353 * @param len The number of bytes to read. 354 * 355 * @return The number of bytes actually read. 356 */ 357 unsigned int MXC_UART_ReadRXFIFO(mxc_uart_regs_t *uart, unsigned char *bytes, unsigned int len); 358 359 /** 360 * @brief Unloads bytes from the receive FIFO user DMA for longer reads. 361 * 362 * @param uart Pointer to UART registers (selects the UART block used.) 363 * @param bytes The buffer to read the data into. 364 * @param len The number of bytes to read. 365 * @param callback The function to call when the read is complete 366 * 367 * @return See \ref MXC_ERROR_CODES for a list of return values 368 */ 369 int MXC_UART_ReadRXFIFODMA(mxc_uart_regs_t *uart, unsigned char *bytes, unsigned int len, 370 mxc_uart_dma_complete_cb_t callback); 371 372 /** 373 * @brief Get the number of bytes currently available in the receive FIFO. 374 * 375 * @param uart Pointer to UART registers (selects the UART block used.) 376 * 377 * @return The number of bytes available. 378 */ 379 unsigned int MXC_UART_GetRXFIFOAvailable(mxc_uart_regs_t *uart); 380 381 /** 382 * @brief Loads bytes into the transmit FIFO. 383 * 384 * @param uart Pointer to UART registers (selects the UART block used.) 385 * @param bytes The buffer containing the bytes to write 386 * @param len The number of bytes to write. 387 * 388 * @return The number of bytes actually written. 389 */ 390 unsigned int MXC_UART_WriteTXFIFO(mxc_uart_regs_t *uart, const unsigned char *bytes, 391 unsigned int len); 392 393 /** 394 * @brief Loads bytes into the transmit FIFO using DMA for longer writes 395 * 396 * @param uart Pointer to UART registers (selects the UART block used.) 397 * @param bytes The buffer containing the bytes to write 398 * @param len The number of bytes to write. 399 * @param callback The function to call when the write is complete 400 * 401 * @return See \ref MXC_ERROR_CODES for a list of return values 402 */ 403 int MXC_UART_WriteTXFIFODMA(mxc_uart_regs_t *uart, const unsigned char *bytes, unsigned int len, 404 mxc_uart_dma_complete_cb_t callback); 405 406 /** 407 * @brief Get the amount of free space available in the transmit FIFO. 408 * 409 * @param uart Pointer to UART registers (selects the UART block used.) 410 * 411 * @return The number of bytes available. 412 */ 413 unsigned int MXC_UART_GetTXFIFOAvailable(mxc_uart_regs_t *uart); 414 415 /** 416 * @brief Removes and discards all bytes currently in the receive FIFO. 417 * 418 * @param uart Pointer to UART registers (selects the UART block used.) 419 * 420 * @return See \ref MXC_Error_Codes for the list of error return codes. 421 */ 422 int MXC_UART_ClearRXFIFO(mxc_uart_regs_t *uart); 423 424 /** 425 * @brief Removes and discards all bytes currently in the transmit FIFO. 426 * 427 * @param uart Pointer to UART registers (selects the UART block used.) 428 * 429 * @return See \ref MXC_Error_Codes for the list of error return codes. 430 */ 431 int MXC_UART_ClearTXFIFO(mxc_uart_regs_t *uart); 432 433 /** 434 * @brief Set the receive threshold level. 435 * 436 * @note RX FIFO Receive threshold. Smaller values will cause 437 * interrupts to occur more often, but reduce the possibility 438 * of losing data because of a FIFO overflow. Larger values 439 * will reduce the time required by the ISR, but increase the 440 * possibility of data loss. Passing an invalid value will 441 * cause the driver to use the value already set in the 442 * appropriate register. 443 * 444 * @param uart Pointer to UART registers (selects the UART block used.) 445 * @param numBytes The threshold level to set. This value must be 446 * between 0 and 8 inclusive. 447 * 448 * @return Success/Fail, see \ref MXC_Error_Codes for a list of return codes. 449 */ 450 int MXC_UART_SetRXThreshold(mxc_uart_regs_t *uart, unsigned int numBytes); 451 452 /** 453 * @brief Get the current receive threshold level. 454 * 455 * @param uart Pointer to UART registers (selects the UART block used.) 456 * 457 * @return The receive threshold value (in bytes). 458 */ 459 unsigned int MXC_UART_GetRXThreshold(mxc_uart_regs_t *uart); 460 461 /** 462 * @brief Set the transmit threshold level. 463 * 464 * @note TX FIFO threshold. Smaller values will cause interrupts 465 * to occur more often, but reduce the possibility of terminating 466 * a transaction early in master mode, or transmitting invalid data 467 * in slave mode. Larger values will reduce the time required by 468 * the ISR, but increase the possibility errors occurring. Passing 469 * an invalid value will cause the driver to use the value already 470 * set in the appropriate register. 471 * 472 * @param uart Pointer to UART registers (selects the UART block used.) 473 * @param numBytes The threshold level to set. This value must be 474 * between 0 and 8 inclusive. 475 * 476 * @return Success/Fail, see \ref MXC_Error_Codes for a list of return codes. 477 */ 478 int MXC_UART_SetTXThreshold(mxc_uart_regs_t *uart, unsigned int numBytes); 479 480 /** 481 * @brief Get the current transmit threshold level. 482 * 483 * @param uart Pointer to UART registers (selects the UART block used.) 484 * 485 * @return The transmit threshold value (in bytes). 486 */ 487 unsigned int MXC_UART_GetTXThreshold(mxc_uart_regs_t *uart); 488 489 /** 490 * @brief Gets the interrupt flags that are currently set 491 * 492 * @note These functions should not be used while using non-blocking Transaction Level 493 * functions (Async or DMA) 494 * 495 * @param uart Pointer to UART registers (selects the UART block used.) 496 * 497 * @return The interrupt flags 498 */ 499 unsigned int MXC_UART_GetFlags(mxc_uart_regs_t *uart); 500 501 /** 502 * @brief Clears the interrupt flags that are currently set 503 * 504 * @note These functions should not be used while using non-blocking Transaction Level 505 * functions (Async or DMA) 506 * 507 * @param uart Pointer to UART registers (selects the UART block used.) 508 * @param flags mask of flags to clear 509 * 510 * @return See \ref MXC_Error_Codes for the list of error return codes. 511 */ 512 int MXC_UART_ClearFlags(mxc_uart_regs_t *uart, unsigned int flags); 513 514 /** 515 * @brief Enables specific interrupts 516 * 517 * @note These functions should not be used while using non-blocking Transaction Level 518 * functions (Async or DMA) 519 * 520 * @param uart Pointer to UART registers (selects the UART block used.) 521 * @param mask The interrupts to be enabled 522 * 523 * @return See \ref MXC_Error_Codes for the list of error return codes. 524 */ 525 int MXC_UART_EnableInt(mxc_uart_regs_t *uart, unsigned int mask); 526 527 /** 528 * @brief Disables specific interrupts 529 * 530 * @note These functions should not be used while using non-blocking Transaction Level 531 * functions (Async or DMA) 532 * 533 * @param uart Pointer to UART registers (selects the UART block used.) 534 * @param mask The interrupts to be disabled 535 * 536 * @return See \ref MXC_Error_Codes for the list of error return codes. 537 */ 538 int MXC_UART_DisableInt(mxc_uart_regs_t *uart, unsigned int mask); 539 540 /** 541 * @brief Gets the status flags that are currently set 542 * 543 * @param uart Pointer to UART registers (selects the UART block used.) 544 * 545 * @return The status flags 546 */ 547 unsigned int MXC_UART_GetStatus(mxc_uart_regs_t *uart); 548 549 /* ************************************************************************* */ 550 /* Transaction level functions */ 551 /* ************************************************************************* */ 552 553 /** 554 * @brief Performs a blocking UART transaction. 555 * 556 * @note Performs a blocking UART transaction as follows. 557 * If tx_len is non-zero, transmit TX data 558 * Once tx_len has been sent, if rx_len is non-zero, receive data 559 * 560 * @param req Pointer to details of the transaction 561 * 562 * @return See \ref MXC_Error_Codes for the list of error return codes. 563 */ 564 int MXC_UART_Transaction(mxc_uart_req_t *req); 565 566 /** 567 * @brief Setup an interrupt-driven UART transaction 568 * 569 * @note The TX FIFO will be filled with txData if necessary 570 * Relevant interrupts will be enabled 571 * 572 * @param req Pointer to details of the transaction 573 * 574 * @return See \ref MXC_Error_Codes for the list of error return codes. 575 */ 576 int MXC_UART_TransactionAsync(mxc_uart_req_t *req); 577 578 /** 579 * @brief Setup a DMA driven UART transaction 580 * 581 * @note The TX FIFO will be filled with txData if necessary 582 * Relevant interrupts will be enabled 583 * The DMA channel indicated by the request will be set up to load/unload the FIFOs 584 * with as few interrupt-based events as possible. The channel will be reset and 585 * returned to the system at the end of the transaction. 586 * 587 * @param req Pointer to details of the transaction 588 * 589 * @return See \ref MXC_Error_Codes for the list of error return codes. 590 */ 591 int MXC_UART_TransactionDMA(mxc_uart_req_t *req); 592 593 /** 594 * @brief The processing function for DMA transactions. 595 * 596 * When using the DMA functions, the application must call this 597 * function periodically. This can be done from within the DMA Interrupt Handler. 598 * 599 * @param ch DMA channel 600 * @param error Error status 601 */ 602 void MXC_UART_DMACallback(int ch, int error); 603 604 /** 605 * @brief Async callback 606 * 607 * @param uart The uart 608 * @param retVal The ret value 609 * 610 * @return See \ref MXC_Error_Codes for the list of error return codes. 611 */ 612 int MXC_UART_AsyncCallback(mxc_uart_regs_t *uart, int retVal); 613 614 /** 615 * @brief stop any async callbacks 616 * 617 * @param uart The uart 618 * 619 * @return See \ref MXC_Error_Codes for the list of error return codes. 620 */ 621 int MXC_UART_AsyncStop(mxc_uart_regs_t *uart); 622 623 /** 624 * @brief Abort any asynchronous requests in progress. 625 * 626 * @note Abort any asynchronous requests in progress. Any callbacks associated with 627 * the active transaction will be executed to indicate when the transaction 628 * has been terminated. 629 * 630 * @param uart Pointer to UART registers (selects the UART block used.) 631 * 632 * @return See \ref MXC_Error_Codes for the list of error return codes. 633 */ 634 int MXC_UART_AbortAsync(mxc_uart_regs_t *uart); 635 636 /** 637 * @brief The processing function for asynchronous transactions. 638 * 639 * @note When using the asynchronous functions, the application must call this 640 * function periodically. This can be done from within the UART interrupt 641 * handler or periodically by the application if UART interrupts are disabled. 642 * 643 * @param uart Pointer to UART registers (selects the UART block used.) 644 * 645 * @return See \ref MXC_Error_Codes for the list of error return codes. 646 */ 647 int MXC_UART_AsyncHandler(mxc_uart_regs_t *uart); 648 649 /** 650 * @brief Provide TXCount for asynchronous transactions.. 651 * 652 * @param uart Pointer to UART registers (selects the UART block used.) 653 * 654 * @return Returns transmit bytes (in FIFO). 655 */ 656 uint32_t MXC_UART_GetAsyncTXCount(mxc_uart_req_t *req); 657 658 /** 659 * @brief Provide RXCount for asynchronous transactions.. 660 * 661 * @param uart Pointer to UART registers (selects the UART block used.) 662 * 663 * @return Returns receive bytes (in FIFO). 664 */ 665 uint32_t MXC_UART_GetAsyncRXCount(mxc_uart_req_t *req); 666 667 /** 668 * @brief Enable or disable automatic DMA interrupt handlers for the UART module. 669 * 670 * The @ref MXC_UART_TransactionDMA functions require special interrupt handlers to work. 671 * 672 * When "Auto" DMA handlers are enabled, the UART drivers will acquire DMA channels 673 * and assign the appropriate handlers automatically. The acquired channels are 674 * released after each transaction. 675 * 676 * If "Auto" DMA handlers are disabled, the user must acquire DMA channels manually 677 * and assign them to the drivers with the @ref MXC_UART_SetTXDMAChannel and 678 * @ref MXC_UART_SetRXDMAChannel functions. 679 * 680 * @param uart Pointer to the UART module's registers. 681 * @param enable true to enable Auto DMA handlers, false to disable. 682 * @return 0 on success, or a non-zero error code on failure. 683 */ 684 int MXC_UART_SetAutoDMAHandlers(mxc_uart_regs_t *uart, bool enable); 685 686 /** 687 * @brief Set the TX (Transmit) DMA channel for a UART module. 688 * 689 * This function assigns the DMA channel for transmitting data 690 * when @ref is MXC_UART_SetAutoDMAHandlers disabled. 691 * 692 * @param uart Pointer to the UART module's registers. 693 * @param channel The DMA channel number to be used for @ref MXC_UART_TransactionDMA. 694 */ 695 int MXC_UART_SetTXDMAChannel(mxc_uart_regs_t *uart, unsigned int channel); 696 697 /** 698 * @brief Get the TX (Transmit) DMA channel for a UART module. 699 * 700 * This function retrieves the currently assigned DMA channel for transmitting data 701 * when @ref is MXC_UART_SetAutoDMAHandlers disabled. 702 * 703 * @param uart Pointer to the UART module's registers. 704 * @return The currently assigned TX DMA channel. 705 */ 706 int MXC_UART_GetTXDMAChannel(mxc_uart_regs_t *uart); 707 708 /** 709 * @brief Set the RX (Receive) DMA channel for a UART module. 710 * 711 * This function assigns the DMA channel for receiving data 712 * when @ref is MXC_UART_SetAutoDMAHandlers disabled. 713 * 714 * @param uart Pointer to the UART module's registers. 715 * @param channel The DMA channel number to be used for @ref MXC_UART_TransactionDMA. 716 */ 717 int MXC_UART_SetRXDMAChannel(mxc_uart_regs_t *uart, unsigned int channel); 718 719 /** 720 * @brief Get the RX (Receive) DMA channel for a UART module. 721 * 722 * This function retrieves the currently configured DMA channel for receiving data 723 * when @ref is MXC_UART_SetAutoDMAHandlers disabled. 724 * 725 * @param uart Pointer to the UART module's registers. 726 * @return The currently configured RX DMA channel. 727 */ 728 int MXC_UART_GetRXDMAChannel(mxc_uart_regs_t *uart); 729 730 /**@} end of group uart */ 731 732 #ifdef __cplusplus 733 } 734 #endif 735 736 #endif // LIBRARIES_PERIPHDRIVERS_INCLUDE_MAX32655_UART_H_ 737