1 /* 2 * Copyright (c) 2023 Intel Corporation 3 * 4 * SPDX-License-Identifier: BSD-3-Clause 5 */ 6 7 #ifndef _SEDI_DRIVER_UART_H_ 8 #define _SEDI_DRIVER_UART_H_ 9 10 #include "sedi_driver_common.h" 11 #include "sedi_driver_dma.h" 12 13 /** 14 * @defgroup sedi_driver_uart UART 15 * @ingroup sedi_driver 16 * @{ 17 */ 18 19 /** 20 * @defgroup uart_structure_type UART Structure Type 21 * @ingroup sedi_driver_uart 22 * @{ 23 */ 24 25 /** 26 * @struct sedi_uart_status_t 27 * @brief UART Status type 28 * @ingroup uart_structure_type 29 */ 30 typedef enum { 31 SEDI_UART_IDLE = 0, /**< IDLE. */ 32 SEDI_UART_RX_OE = BIT(1), /**< Receiver overrun. */ 33 SEDI_UART_RX_PE = BIT(2), /**< Parity error. */ 34 SEDI_UART_RX_FE = BIT(3), /**< Framing error. */ 35 SEDI_UART_RX_BI = BIT(4), /**< Break interrupt. */ 36 SEDI_UART_TX_BUSY = BIT(5), /**< TX Busy flag. */ 37 SEDI_UART_RX_BUSY = BIT(6), /**< RX Busy flag. */ 38 SEDI_UART_TX_NFULL = BIT(7), /**< TX FIFO not full. */ 39 SEDI_UART_RX_NEMPTY = BIT(8), /**< RX FIFO not empty. */ 40 SEDI_UART_UNHANDLED_INT = BIT(9) /**< Unhandled Interrupt. */ 41 } sedi_uart_status_t; 42 43 /** 44 * @struct sedi_uart_lc_t 45 * @brief UART Line control 46 * @ingroup uart_structure_type 47 */ 48 typedef enum { 49 /**< 5 data bits, no parity, 1 stop bit. */ 50 SEDI_UART_LC_5N1 = 0x00, 51 /**< 5 data bits, no parity, 1.5 stop bits. */ 52 SEDI_UART_LC_5N1_5 = 0x04, 53 /**< 5 data bits, even parity, 1 stop bit. */ 54 SEDI_UART_LC_5E1 = 0x18, 55 /**< 5 data bits, even parity, 1.5 stop bits. */ 56 SEDI_UART_LC_5E1_5 = 0x1c, 57 /**< 5 data bits, odd parity, 1 stop bit. */ 58 SEDI_UART_LC_5O1 = 0x08, 59 /**< 5 data bits, odd parity, 1.5 stop bits.*/ 60 SEDI_UART_LC_5O1_5 = 0x0c, 61 /**< 6 data bits, no parity, 1 stop bit. */ 62 SEDI_UART_LC_6N1 = 0x01, 63 /**< 6 data bits, no parity, 2 stop bits. */ 64 SEDI_UART_LC_6N2 = 0x05, 65 /**< 6 data bits, even parity, 1 stop bit. */ 66 SEDI_UART_LC_6E1 = 0x19, 67 /**< 6 data bits, even parity, 2 stop bits. */ 68 SEDI_UART_LC_6E2 = 0x1d, 69 /**< 6 data bits, odd parity, 1 stop bit. */ 70 SEDI_UART_LC_6O1 = 0x09, 71 /**< 6 data bits, odd parity, 2 stop bits. */ 72 SEDI_UART_LC_6O2 = 0x0d, 73 /**< 7 data bits, no parity, 1 stop bit. */ 74 SEDI_UART_LC_7N1 = 0x02, 75 /**< 7 data bits, no parity, 2 stop bits. */ 76 SEDI_UART_LC_7N2 = 0x06, 77 /**< 7 data bits, even parity, 1 stop bit. */ 78 SEDI_UART_LC_7E1 = 0x1a, 79 /**< 7 data bits, even parity, 2 stop bits. */ 80 SEDI_UART_LC_7E2 = 0x1e, 81 /**< 7 data bits, odd parity, 1 stop bit. */ 82 SEDI_UART_LC_7O1 = 0x0a, 83 /**< 7 data bits, odd parity, 2 stop bits. */ 84 SEDI_UART_LC_7O2 = 0x0e, 85 /**< 8 data bits, no parity, 1 stop bit. */ 86 SEDI_UART_LC_8N1 = 0x03, 87 /**< 8 data bits, no parity, 2 stop bits. */ 88 SEDI_UART_LC_8N2 = 0x07, 89 /**< 8 data bits, even parity, 1 stop bit. */ 90 SEDI_UART_LC_8E1 = 0x1b, 91 /**< 8 data bits, even parity, 2 stop bits. */ 92 SEDI_UART_LC_8E2 = 0x1f, 93 /**< 8 data bits, odd parity, 1 stop bit. */ 94 SEDI_UART_LC_8O1 = 0x0b, 95 /**< 8 data bits, odd parity, 2 stop bits. */ 96 SEDI_UART_LC_8O2 = 0x0f 97 } sedi_uart_lc_t; 98 99 /** 100 * @struct sedi_uart_rs485_transfer_mode_t 101 * @brief UART RS-485 transfer mode 102 * @ingroup uart_structure_type 103 */ 104 typedef enum { 105 /** Full Duplex mode. */ 106 SEDI_UART_RS485_XFER_MODE_FULL_DUPLEX, 107 108 /** Software Controlled Half Duplex mode. */ 109 SEDI_UART_RS485_XFER_MODE_HALF_DUPLEX 110 111 } sedi_uart_rs485_transfer_mode_t; 112 113 /** 114 * @struct sedi_uart_rs485_polarity 115 * @brief UART RS-485 polarity for de and re signals 116 * @ingroup uart_structure_type 117 */ 118 typedef enum { 119 SEDI_UART_RS485_POL_ACTIVE_LOW = 0, 120 SEDI_UART_RS485_POL_ACTIVE_HIGH 121 122 } sedi_uart_rs485_polarity; 123 124 /** 125 * @struct sedi_uart_rs485_config_t 126 * @brief UART RS-485 configuration structure type 127 * @ingroup uart_structure_type 128 */ 129 typedef struct { 130 /** de to re turnaround time in nanoseconds. */ 131 uint32_t de_re_tat; 132 133 /** re to de turnaround time in nanoseconds. */ 134 uint32_t re_de_tat; 135 136 /** Assertion time for DE in nanoseconds. */ 137 uint32_t de_assertion_time; 138 139 /** De-assertion time for DE in nanoseconds */ 140 uint32_t de_deassertion_time; 141 142 /** Transfer mode.*/ 143 sedi_uart_rs485_transfer_mode_t transfer_mode : 1; 144 145 /** de polarity 0:active low , 1:active high. */ 146 sedi_uart_rs485_polarity de_polarity : 1; 147 148 /** re polarity 0:active low , 1:active high. */ 149 sedi_uart_rs485_polarity re_polarity : 1; 150 151 /** Driver enable. */ 152 uint32_t de_en : 1; 153 154 /** Receiver enable. */ 155 uint32_t re_en : 1; 156 } sedi_uart_rs485_config_t; 157 158 /** 159 * @struct sedi_uart_9bit_addr_mode_t 160 * @brief Hardware / Software based address transmit 161 * and address match control. 162 * @ingroup uart_structure_type 163 */ 164 typedef enum { 165 SEDI_UART_9BIT_HW_ADDR_CTRL = 0, 166 SEDI_UART_9BIT_SW_ADDR_CTRL 167 168 } sedi_uart_9bit_addr_mode_t; 169 170 /** 171 * @struct sedi_uart_9bit_config_t 172 * @brief UART 9bit configuration structure type 173 * @ingroup uart_structure_type 174 */ 175 typedef struct { 176 177 /** Address of this node when hardware address match enabled. */ 178 uint8_t receive_address; 179 180 /** Addr Ctrl s/w or h/w enabled receive address match. */ 181 sedi_uart_9bit_addr_mode_t addr_ctrl; 182 183 } sedi_uart_9bit_config_t; 184 185 /** 186 * @struct sedi_uart_config_t 187 * @brief UART configuration structure type 188 * @ingroup uart_structure_type 189 */ 190 typedef struct { 191 sedi_uart_lc_t line_control; /**< Line control (enum). */ 192 uint32_t baud_rate; /**< Baud Rate. */ 193 bool hw_fc; /**< Hardware Automatic Flow Control. */ 194 uint32_t clk_speed_hz; /**< Clock speed for uart in Hz. */ 195 } sedi_uart_config_t; 196 197 /** 198 * @struct sedi_uart_transfer_t 199 * @brief UART asynchronous transfer structure 200 * @ingroup uart_structure_type 201 */ 202 typedef struct { 203 uint8_t *data; /**< Pre-allocated write or read buffer. */ 204 uint32_t data_len; /**< Number of bytes to transfer. */ 205 206 /** Transfer callback 207 * 208 * @param[in] data Callback user data. 209 * @param[in] SEDI_DRIVER_OK on success,negative value for possible 210 * errors. 211 * @param[in] status UART module status.To be interpreted with 212 * sedi_uart_status_t for different error bits. 213 * @param[in] len Length of the UART transfer if successful, 0 214 * otherwise. 215 */ 216 void (*callback)(void *data, int error, uint32_t status, uint32_t len); 217 void *callback_data; /**< Callback identifier. */ 218 } sedi_uart_transfer_t; 219 220 /** 221 * @struct sedi_uart_io_vec_t 222 * @brief UART IO vector 223 * @ingroup uart_structure_type 224 */ 225 typedef struct { 226 uint8_t *base; /* Start address. */ 227 uint32_t len; /* Length of transfer */ 228 } sedi_uart_io_vec_t; 229 230 /** 231 * @struct sedi_uart_io_vec_xfer_t 232 * @brief UART IO vector transfers 233 * @ingroup uart_structure_type 234 */ 235 typedef struct { 236 sedi_uart_io_vec_t *vec; /* Pointer to vector of transfers */ 237 uint32_t count; /* Number of transfers requested. */ 238 void *cb_data; /* Callback data */ 239 void (*callback)(void *data, int error, uint32_t status, 240 uint32_t completed_count); 241 } sedi_uart_io_vec_xfer_t; 242 243 /** 244 * @struct sedi_uart_unsol_rx_t 245 * @brief UART unsolicited receive structure 246 * @ingroup uart_structure_type 247 */ 248 typedef struct { 249 uint8_t *buffer; /* Buffer for unsolicited receive */ 250 int32_t size; /* Size of the buffer */ 251 void *cb_data; /* Callback data or context */ 252 void (*unsol_rx_callback)(void *usr_data, int err, uint32_t status, 253 int len); 254 } sedi_uart_unsol_rx_t; 255 256 /** 257 * @struct sedi_uart_dma_xfer_t 258 * @brief UART DMA transfer structure 259 * @ingroup uart_structure_type 260 */ 261 typedef struct { 262 sedi_dma_t dma_dev; /**< Dma device to be used. */ 263 int32_t channel; /**< Dma channel number to be used. */ 264 uint8_t *data; /**< Data ptr. */ 265 void (*callback)(void *cb_param, int error, uint32_t status, 266 uint32_t len); 267 void *cb_param; /** Callback param. */ 268 uint32_t len; /**< Length of transfer. */ 269 } sedi_uart_dma_xfer_t; 270 271 /** @} */ 272 273 /** 274 * @brief UART Driver Function Calls 275 * @defgroup uart_function_calls UART Driver Function Calls 276 * @ingroup sedi_driver_uart 277 * @{ 278 */ 279 280 /** 281 * @brief Set UART configuration. 282 * 283 * Change the configuration of a UART module. This includes line control, 284 * baud rate and hardware flow control. 285 * 286 * @param[in] uart Which UART module to configure. 287 * @param[in] cfg New configuration for UART. This must not be NULL. 288 * 289 * @return Standard return code for SEDI. 290 * @retval SEDI_DRIVER_OK on success, negative value for possible errors. 291 */ 292 int sedi_uart_set_config(IN sedi_uart_t uart, IN sedi_uart_config_t *const cfg); 293 294 /** 295 * @brief Get UART status. 296 * 297 * Retrieve UART interface status. Return SEDI_UART_BUSY if transmitting 298 * data; SEDI_UART_IDLE if available for transfer; SEDI_UART_TX_ERROR if an 299 * error has occurred in transmission. 300 * 301 * The user may call this function before performing an UART transfer in order 302 * to guarantee that the UART interface is available. 303 304 * @param[in] uart Which UART to read the status of. 305 * @param[out] status Current UART status. This must not be NULL. 306 * The returned status is to be interpreted using the sedi_uart_status_t for 307 * different error conditions. 308 * 309 * @return Standard return code for SEDI. 310 * @retval SEDI_DRIVER_OK on success, negative value for possible errors. 311 */ 312 int sedi_uart_get_status(IN sedi_uart_t uart, OUT uint32_t *const status); 313 314 /** 315 * @brief UART character data write. 316 * 317 * Perform a single character write on the UART interface. 318 * This is a blocking synchronous call. 319 * 320 * @param[in] uart UART identifier. 321 * @param[in] data Data to write to UART. 322 * 323 * @return Standard driver return type for SEDI. 324 * @retval SEDI_DRIVER_OK on success. 325 * @retval Negative @ref errno for possible error codes. 326 */ 327 int sedi_uart_write(IN sedi_uart_t uart, IN uint8_t data); 328 329 /** 330 * @brief UART character data read. 331 * 332 * Perform a single character read from the UART interface. 333 * This is a blocking synchronous call. 334 * 335 * @param[in] uart UART identifier. 336 * @param[out] data Data to read from UART. This must not be NULL. 337 * @param[out] status UART specific status. The returned status to be 338 * interpreted using sedi_uart_status_t for different error conditions. 339 * 340 * @return Standard return code for SEDI. 341 * @retval SEDI_DRIVER_OK on success, negative value for possible errors. 342 */ 343 int sedi_uart_read(IN sedi_uart_t uart, OUT uint8_t *const data, 344 OUT uint32_t *const status); 345 346 /** 347 * @brief Uart read multi bytes. 348 * 349 * Perform a read on the UART interface. This is a blocking 350 * synchronous call. The function will block until all data has 351 * been read to the buffer or an error has occurred. 352 * 353 * @param[in] uart UART controller identifier 354 * @param[OUT] data buffer where data is to be read.This must not be NULL. 355 * @param[in] req_len Requested length of data to be read. 356 * @param[OUT] comp_len Length of data read completed by this call. 357 * @param[OUT] status Line status in case of an error. 358 * 359 * @return Standard return code for SEDI. 360 * @retval SEDI_DRIVER_OK on success, negative value for possible errors. 361 */ 362 int sedi_uart_read_buffer(IN sedi_uart_t uart, OUT uint8_t *const data, 363 IN uint32_t req_len, OUT uint32_t *comp_len, 364 OUT uint32_t *status); 365 366 /** 367 * @brief UART character data write. 368 * 369 * Perform a single character write on the UART interface. 370 * This is a non-blocking synchronous call. 371 * 372 * @param[in] uart UART identifier. 373 * @param[in] data Data to write to UART. 374 * 375 * @return Standard return code for SEDI. 376 * @retval SEDI_DRIVER_OK on success, negative value for possible errors. 377 */ 378 int sedi_uart_write_non_block(IN sedi_uart_t uart, IN uint8_t data); 379 380 /** 381 * @brief UART character data read. 382 * 383 * Perform a single character read from the UART interface. 384 * This is a non-blocking synchronous call. 385 * 386 * @param[in] uart UART identifier. 387 * @param[out] data Character read. This must not be NULL. 388 * 389 * @return Standard return code for SEDI. 390 * @retval SEDI_DRIVER_OK on success, negative value for possible errors. 391 */ 392 int sedi_uart_read_non_block(IN sedi_uart_t uart, OUT uint8_t *const data); 393 394 /** 395 * @brief UART multi-byte data write. 396 * 397 * Perform a write on the UART interface. This is a blocking 398 * synchronous call. The function will block until all data has 399 * been transferred. 400 * 401 * @param[in] uart UART controller identifier 402 * @param[in] data Data to write to UART. This must not be NULL. 403 * @param[in] len Length of data to write to UART. 404 * 405 * @return Standard return code for SEDI. 406 * @retval SEDI_DRIVER_OK on success, negative value for possible errors. 407 */ 408 int sedi_uart_write_buffer(IN sedi_uart_t uart, IN uint8_t *const data, 409 IN uint32_t len); 410 411 /** 412 * @brief Interrupt based TX on UART. 413 * 414 * Perform an asynchronous interrupt based TX transfer on the UART bus. 415 * The function will replenish the TX FIFOs on UART empty interrupts. 416 * This function should not be called when an asynchronous write operation 417 * is already in progress.API user should terminate any ongoing async writes 418 * before issuing a new asynchronous write. 419 * 420 * @param[in] uart UART identifier. 421 * @param[in] xfer Structure containing pre-allocated 422 * write buffer and callback functions. 423 * The structure must not be NULL and must be kept valid until 424 * the transfer is complete. 425 * 426 * @return Standard return code for SEDI. 427 * @retval SEDI_DRIVER_OK on success, negative value for possible errors. 428 */ 429 int sedi_uart_write_async(IN sedi_uart_t uart, 430 IN sedi_uart_transfer_t *const xfer); 431 432 /** 433 * @brief Interrupt based RX on UART. 434 * 435 * Perform an asynchronous interrupt based RX transfer on the UART bus. 436 * The function will read back the RX FIFOs on UART empty interrupts. 437 * This function should not be called when an asynchronous receive operation 438 * is already in progress. API user should terminate any ongoing async 439 * read transfers before issuing a new asynchronous read. 440 * 441 * @param[in] uart UART identifier. 442 * @param[in] xfer Structure containing pre-allocated read 443 * buffer and callback functions. 444 * The structure must not be NULL and must be kept valid until 445 * the transfer is complete. 446 * 447 * @return Standard return code for SEDI. 448 * @retval SEDI_DRIVER_OK on success, negative value for possible errors. 449 */ 450 int sedi_uart_read_async(IN sedi_uart_t uart, 451 IN sedi_uart_transfer_t *const xfer); 452 453 /** 454 * @brief Terminate UART asynchronous(IRQ)TX transfer. 455 * 456 * Terminate the current IRQ TX transfer on the UART bus. 457 * This will cause the relevant callbacks to be called. 458 * 459 * @param[in] uart UART identifier. 460 * 461 * @return Standard return code for SEDI. 462 * @retval SEDI_DRIVER_OK on success, negative value for possible errors. 463 */ 464 int sedi_uart_async_write_terminate(IN sedi_uart_t uart); 465 466 /** 467 * @brief Terminate UART asynchronous(IRQ) RX transfer. 468 * 469 * Terminate the current IRQ RX transfer on the UART bus. 470 * This will cause the relevant callbacks to be called. 471 * 472 * @param[in] uart UART identifier. 473 * 474 * @return Standard return code for SEDI. 475 * @retval SEDI_DRIVER_OK on success, negative value for possible errors. 476 */ 477 int sedi_uart_async_read_terminate(IN sedi_uart_t uart); 478 479 /* Additional functions defined for UART Zephyr only. */ 480 481 /** 482 * @brief Is there a pending IRQ for uart. 483 * 484 * This function returns a boolean value indicating 485 * whether an IRQ is pending for the given UART instance. 486 * 487 * @param[in] uart UART port index. 488 * 489 * @return Boolean value indicating whether IQR is pending. 490 * @retval false if no irq is pending. 491 * true if irq is pending. 492 */ 493 bool sedi_uart_is_irq_pending(IN sedi_uart_t uart); 494 495 /** 496 * @brief Is transmit operation complete. 497 * 498 * This function returns a boolean value indicating 499 * whether a transmit operation is complete or not. 500 * 501 * 502 * @param[in] uart UART port index. 503 * 504 * @return Boolean value indication whether transmit operation is 505 * complete. 506 * @retval true if both transmit holding register and transmitter are empty. 507 * false otherwise. 508 */ 509 bool sedi_uart_is_tx_complete(IN sedi_uart_t uart); 510 511 /** 512 * @brief Is receive data available in the interrupt context. 513 * 514 * This function returns a boolean value indicating 515 * whether the interrupt is asserted due to data availability 516 * in the rx path.This API should be called in interrupt context 517 * after calling the IRQ update function. 518 * 519 * @param[in] uart UART port index. 520 * 521 * @return Boolean value indicating whether IRQ is asserted due to rx 522 * data. 523 * @retval false if IRQ is not due to rx data. 524 * true if IRQ is due to rx data.. 525 */ 526 bool sedi_uart_is_irq_rx_ready(IN sedi_uart_t uart); 527 528 /** 529 * @brief Is transmit ready. 530 * 531 * This function returns a boolean value indicating 532 * whether transmit path is ready to accept data for transmit operation. 533 * 534 * @param[in] uart UART port index. 535 * 536 * @return boolean value indicating whether tx . 537 * @retval false if transmit holding register is not empty. 538 * true if transmit holding register is empty 539 */ 540 bool sedi_uart_irq_tx_ready(IN sedi_uart_t uart); 541 542 /** 543 * @brief Fill uart fifo. 544 * 545 * This function fills the uart fifo with data provided in the 546 * data pointer based on specified length , based on the space available 547 * in the transmit fifo. 548 * 549 * @param[in] uart UART port index. 550 * @param[in] data pointer to data to be written. 551 * @param[in] size length of data to be filled. 552 * 553 * @return length of data written to the transmit fifo. 554 */ 555 int sedi_uart_fifo_fill(IN sedi_uart_t uart, IN uint8_t *data, 556 IN uint32_t size); 557 558 /** 559 * @brief Read uart fifo. 560 * 561 * Reads the uart fifo into provided data buffer for specified length. If 562 * data for specified read length is not available in the rx fifo,the 563 * function returns. 564 * 565 * @param[in] uart UART port index. 566 * @param[out] data pointer where data is to be read. 567 * @param[in] size length of data to be read. 568 * 569 * @return length of data read from the rx fifo. 570 */ 571 int sedi_uart_fifo_read(IN sedi_uart_t uart, OUT uint8_t *data, 572 IN uint32_t size); 573 574 /** 575 * @brief Enable interrupt generation for transmit event. 576 * 577 * Enable interrupt generation when transmit fifo/transmit holding 578 * register is empty. 579 * 580 * @param[in] uart UART port index. 581 * 582 * @return Standard return code for SEDI. 583 * @retval SEDI_DRIVER_OK on success, negative value for possible errors. 584 */ 585 int sedi_uart_irq_tx_enable(IN sedi_uart_t uart); 586 587 /** 588 * @brief Disable interrupt generation for transmit event. 589 * 590 * Disable interrupt generation when transmit fifo/transmit holding 591 * register is empty. 592 * 593 * @param[in] uart UART port index. 594 * 595 * @return Standard return code for SEDI. 596 * @retval SEDI_DRIVER_OK on success, negative value for possible errors. 597 */ 598 int sedi_uart_irq_tx_disable(IN sedi_uart_t uart); 599 600 /** 601 * @brief Enable interrupt generation for receive event. 602 * 603 * Enable interrupt generation when data available is receive buffer. 604 * 605 * @param[in] uart UART port index. 606 * 607 * @return Standard return code for SEDI. 608 * @retval SEDI_DRIVER_OK on success, negative value for possible errors. 609 */ 610 int sedi_uart_irq_rx_enable(IN sedi_uart_t uart); 611 612 /** 613 * @brief Disable interrupt generation for receive event. 614 * 615 * Disable interrupt generation when data available is receive buffer. 616 * 617 * @param[in] uart UART port index. 618 * 619 * @return Standard return code for SEDI. 620 * @retval SEDI_DRIVER_OK on success, negative value for possible errors. 621 */ 622 int sedi_uart_irq_rx_disable(IN sedi_uart_t uart); 623 624 /** 625 * @brief Enable interrupt generation for error conditions. 626 * 627 * Enable interrupt for error conditions - fifo overrun, 628 * parity,framing error,break condition. 629 * 630 * @param[in] uart UART port index. 631 * 632 * @return Standard return code for SEDI. 633 * @retval SEDI_DRIVER_OK on success, negative value for possible errors. 634 */ 635 int sedi_uart_irq_err_enable(IN sedi_uart_t uart); 636 637 /** 638 * @brief Disable interrupt generation for error conditions. 639 * 640 * Disable interrupt for error conditions - fifo overrun, 641 * parity,framing error,break condition. 642 * 643 * @param[in] uart UART port index. 644 * 645 * @return Standard return code for SEDI. 646 * @retval SEDI_DRIVER_OK on success, negative value for possible errors. 647 */ 648 int sedi_uart_irq_err_disable(IN sedi_uart_t uart); 649 650 /** 651 * @brief Update the cached values of the IRQ status. 652 * 653 * Updates the cached values of uart iid status register. 654 * Caching is required as many interrupt status bits get cleared on 655 * reading. 656 * 657 * @param[in] uart UART port index. 658 * 659 * @return Standard return code for SEDI. 660 * @retval SEDI_DRIVER_OK on success, negative value for possible errors. 661 */ 662 int sedi_uart_update_irq_cache(IN sedi_uart_t uart); 663 664 /** 665 * @brief Sets the baud rate for uart specified uart port. 666 * 667 * @param[in] uart UART port index. 668 * @param[in] baud_rate to set. 669 * @param[in] clock speed supplied to UART IP ,in Hz. 670 * 671 * @return Standard return code for SEDI. 672 * @retval SEDI_DRIVER_OK on success, negative value for possible errors. 673 */ 674 int sedi_uart_set_baud_rate(IN sedi_uart_t uart, IN uint32_t baud_rate, 675 IN uint32_t clock_speed_hz); 676 677 /** 678 * @brief Gets the current configuration for the specified UART port. 679 * 680 * @param[in] uart UART port index. 681 * @param[out] cfg pointer to configuration structure populated by this 682 * call. 683 * 684 * @return Standard return code for SEDI. 685 * @retval SEDI_DRIVER_OK on success, negative value for possible errors. 686 */ 687 int sedi_uart_get_config(IN sedi_uart_t uart, OUT sedi_uart_config_t *cfg); 688 689 /** 690 * @brief Set uart loopback mode. 691 * 692 * @param[in] uart UART port index. 693 * 694 * @return Standard return code for SEDI. 695 * @retval SEDI_DRIVER_OK on success, negative value for possible errors. 696 */ 697 int sedi_uart_set_loopback_mode(IN sedi_uart_t uart); 698 699 /** 700 * @brief Clear uart loopback mode. 701 * 702 * @param[in] uart UART port index. 703 * 704 * @return Standard return code for SEDI. 705 * @retval SEDI_DRIVER_OK on success, negative value for possible errors. 706 */ 707 int sedi_uart_clr_loopback_mode(IN sedi_uart_t uart); 708 709 /** 710 * @brief Set uart break condition. 711 * 712 * @param[in] uart UART port index. 713 * 714 * @return Standard return code for SEDI. 715 * @retval SEDI_DRIVER_OK on success, negative value for possible errors. 716 */ 717 int sedi_uart_set_break_con(IN sedi_uart_t uart); 718 719 /** 720 * @brief Clear uart break condition. 721 * 722 * @param[in] uart UART port index. 723 * 724 * @return Standard return code for SEDI. 725 * @retval SEDI_DRIVER_OK on success, negative value for possible errors. 726 */ 727 int sedi_uart_clr_break_con(IN sedi_uart_t uart); 728 729 /** 730 * @brief Enable uart auto flow control. 731 * 732 * @param[in] uart UART port index. 733 * 734 * @return Standard return code for SEDI. 735 * @retval SEDI_DRIVER_OK on success, negative value for possible errors. 736 */ 737 int sedi_uart_auto_fc_enable(IN sedi_uart_t uart); 738 739 /** 740 * @brief Disable uart auto flow control. 741 * 742 * @param[in] uart UART port index. 743 * 744 * @return Standard return code for SEDI. 745 * @retval SEDI_DRIVER_OK on success, negative value for possible errors. 746 */ 747 int sedi_uart_auto_fc_disable(IN sedi_uart_t uart); 748 749 /** 750 * @brief Set line status report mask. 751 * 752 * This function sets the line status errors that can be reported during 753 * receive operations. The errors include break condition , framing 754 * errors,parity error and fifo overrun error. 755 * The mask can be generated by OR ing the parameters of sedi_uart_lc_t. 756 * 757 * @param[in] uart UART port index. 758 * @param[in] mask : bit mask specifying the line status errors to be reported. 759 * 760 * @return Standard return code for SEDI. 761 * @retval SEDI_DRIVER_OK on success, negative value for possible errors. 762 */ 763 int sedi_set_ln_status_report_mask(IN sedi_uart_t uart, IN uint32_t mask); 764 765 /** 766 * @brief UART interrupt handler function. 767 * 768 * @param[in] uart UART port index. 769 * 770 * @return void :No return value. 771 */ 772 773 void sedi_uart_isr_handler(IN sedi_uart_t uart); 774 775 /** 776 * @brief Enable unsolicited receive. 777 * 778 * This function enables unsolicited receive using the buffer provided. 779 * The buffered data is maintained as a circular buffer and oldest unread data 780 * is overwritten in the event of received data exceeding the buffer length. 781 * On receiving any data on the uart device , user callback is triggered 782 * indicating the status and length of the accumulated data. User may call the 783 * sedi_uart_get_unsol_data API to read the accumulated data. Caller must set 784 * the unsol_rx_callback field in the sedi_uart_unsol_rx_t otherwise error 785 * would be returned. 786 * 787 * @param[in] uart UART port index. 788 * @param[in] unsol_rx pointer to unsolicited receive structure of type 789 * sedi_unsol_rx_t. 790 * 791 * @return Standard return code for SEDI. 792 * @retval SEDI_DRIVER_OK on success, negative value for possible errors. 793 */ 794 int sedi_uart_enable_unsol_rx(IN sedi_uart_t uart, 795 IN sedi_uart_unsol_rx_t *const unsol_rx); 796 797 /** 798 * @brief Disable unsolicited read. 799 * 800 * @param[in] uart UART port index. 801 * 802 * @return Standard return code for SEDI. 803 * @retval SEDI_DRIVER_OK on success, negative value for possible errors. 804 */ 805 int sedi_uart_disable_unsol_rx(IN sedi_uart_t uart); 806 807 /** 808 * @brief UART Get unsolicited data 809 * Get unsolicited data received. This may be called for the unsolicited 810 * receive callback to read the data accumulated. 811 * 812 * @param[in] uart UART port index. 813 * @param[in] buffer where data is to be transferred. 814 * @param[in] len length of data to be copied. 815 * 816 * @return Standard return code for SEDI. 817 * @retval SEDI_DRIVER_OK on success, negative value for possible errors. 818 */ 819 int sedi_uart_get_unsol_data(IN sedi_uart_t uart, OUT uint8_t *buffer, 820 IN int len); 821 822 /** 823 * @brief Get length of unsolicited data received. 824 * 825 * @param[in] uart UART port index. 826 * @param[OUT] p_len pointer to int which would be populated by length. 827 * 828 * @return Standard return code for SEDI. 829 * @retval SEDI_DRIVER_OK on success, negative value for possible errors. 830 */ 831 int sedi_uart_get_unsol_data_len(IN sedi_uart_t uart, OUT int *p_len); 832 833 /** 834 * @brief UART assert RTS line to logical high 835 * Set RTS line to logical high when Auto Flow Control is disabled. 836 * If auto flow contorl is enabled, error is returned. 837 * 838 * @param[in] uart UART port index. 839 * 840 * @return Standard return code for SEDI. 841 * @retval SEDI_DRIVER_OK on success, negative value for possible errors. 842 */ 843 int sedi_uart_assert_rts(IN sedi_uart_t uart); 844 845 /** 846 * @brief UART assert RTS line to logical low 847 * Set RTS line to logical low when Auto Flow Control is disabled. 848 * If auto flow contorl is enabled, error is returned. 849 * 850 * @param[in] uart UART port index. 851 * 852 * @return Standard return code for SEDI. 853 * @retval SEDI_DRIVER_OK on success, negative value for possible errors. 854 */ 855 int sedi_uart_de_assert_rts(IN sedi_uart_t uart); 856 857 /** 858 * @brief Read the current state of CTS line. 859 * @param[out] p_rts pointer to uint32_t to hold current CTS value. 860 * 861 * @param[in] uart UART port index. 862 * 863 * @return Standard return code for SEDI. 864 * @retval SEDI_DRIVER_OK on success, negative value for possible errors. 865 */ 866 int sedi_uart_read_cts(IN sedi_uart_t uart, OUT uint32_t *p_cts); 867 868 /** 869 * @brief Read the current state of RTS line. 870 * 871 * @param[in] uart UART port index. 872 * @param[out] p_rts pointer to uint32_t to hold current RTS value. 873 * 874 * @return Standard return code for SEDI. 875 * @retval SEDI_DRIVER_OK on success, negative value for possible errors. 876 */ 877 int sedi_uart_read_rts(IN sedi_uart_t uart, OUT uint32_t *p_rts); 878 879 /** 880 * @brief Read the current state of loopback mode. 881 * 882 * @param[in] uart UART port index. 883 * @param[out] p_mode pointer to uint32_t to hold current state of loopback 884 * mode. 885 * 886 * @return Standard return code for SEDI. 887 * @retval SEDI_DRIVER_OK on success, negative value for possible errors. 888 */ 889 int sedi_uart_get_loopback_mode(IN sedi_uart_t uart, OUT uint32_t *p_mode); 890 891 /** 892 * @brief Get the current line stauts report mask. 893 * 894 * @param[in] uart UART port index. 895 * @param[out] p_mask pointer to uint32_t to hold current line status mask 896 * mode. 897 * 898 * @return Standard return code for SEDI. 899 * @retval SEDI_DRIVER_OK on success, negative value for possible errors. 900 */ 901 int sedi_get_ln_status_report_mask(IN sedi_uart_t uart, OUT uint32_t *p_mask); 902 903 /** 904 * @brief Perform non-contiguous buffer asynchronous writes. 905 * 906 * @param[in] uart UART port index. 907 * @param[in] vec_xfer pointer to vector transfer of type 908 * sedi_uart_io_vec_xfer_t specifying the number of transfers in the count 909 * field and the io_vector in the vec field. User callback is called after all 910 * the writes specified in the vec field are completed or an error is detected. 911 * Callback field may be null. This call is non-blocking. 912 * 913 * @return Standard return code for SEDI. 914 * @retval SEDI_DRIVER_OK on success, negative value for possible errors. 915 */ 916 int sedi_uart_write_vec_async(IN sedi_uart_t uart, 917 IN sedi_uart_io_vec_xfer_t *const vec_xfer); 918 919 /** 920 * @brief Perform non-contiguous buffer asynchronous reads. 921 * 922 * @param[in] uart UART port index. 923 * @param[in] vec_xfer pointer to vector transfer of type 924 * sedi_uart_io_vec_xfer_t specifying the number of transfers in the count 925 * field and the io_vector in the vec field. User callback is called after all 926 * the reads specified in the vec field are completed or an error is detected. 927 * Callback field may be null. This call is non-blocking. 928 * 929 * @return Standard return code for SEDI. 930 * @retval SEDI_DRIVER_OK on success, negative value for possible errors. 931 */ 932 int sedi_uart_read_vec_async(IN sedi_uart_t uart, 933 IN sedi_uart_io_vec_xfer_t *const vec_xfer); 934 935 /** 936 * @brief Asynchronous DMA write on the specified UART port. 937 * 938 * @param[in] uart UART port index. 939 * * @param[out] dma transfer structure. 940 * call. 941 * 942 * @return Standard return code for SEDI. 943 * @retval SEDI_DRIVER_OK on success, negative value for possible errors 944 */ 945 int sedi_uart_dma_write_async(IN sedi_uart_t uart, 946 IN sedi_uart_dma_xfer_t *const xfer); 947 948 /** 949 * @brief Terminate UART asynchronous DMA write operation. 950 * 951 * Terminate an ongoing DMA write transfer. 952 * This will cause the relevant callbacks to be called. 953 * 954 * @param[in] uart UART identifier. 955 * 956 * @return Standard return code for SEDI. 957 * @retval SEDI_DRIVER_OK on success, negative value for possible errors. 958 */ 959 int sedi_uart_dma_write_terminate(IN sedi_uart_t uart); 960 961 /** 962 * @brief Asynchronous DMA read on the specified UART port. 963 * 964 * @param[in] uart UART port index. 965 * @param[out] dma transfer structure. 966 * call. 967 * 968 * @return Standard return code for SEDI. 969 * @retval SEDI_DRIVER_OK on success, negative value for possible errors 970 */ 971 int sedi_uart_dma_read_async(IN sedi_uart_t uart, 972 IN sedi_uart_dma_xfer_t *const xfer); 973 974 /** 975 * @brief Terminate UART asynchronous DMA read operation. 976 * 977 * Terminate an ongoing DMA read transfer. 978 * This will cause the relevant callbacks to be called. 979 * 980 * @param[in] uart UART identifier. 981 * 982 * @return Standard return code for SEDI. 983 * @retval SEDI_DRIVER_OK on success, negative value for possible errors. 984 */ 985 int sedi_uart_dma_read_terminate(IN sedi_uart_t uart); 986 987 /** 988 * @brief Polled DMA write on the specified UART port. 989 * 990 * @param[in] uart UART port index. 991 * @param[in] dma_dev Dma controller to use for transaction. 992 * @param[in] channel Dma channel to be used for transaction. 993 * @param[in] buff Pointer to uint8_t, from which data would be written. 994 * @param[in] length of data to be read, 995 * 996 * @return Standard return code for SEDI. 997 * @retval SEDI_DRIVER_OK on success, negative value for possible errors 998 */ 999 int sedi_uart_dma_write_polled(IN sedi_uart_t uart, IN sedi_dma_t dma_dev, 1000 IN uint32_t channel, IN uint8_t *buff, 1001 IN uint32_t length); 1002 1003 /** 1004 * @brief Polled DMA read on the specified UART port. 1005 * 1006 * @param[in] uart UART port index. 1007 * @param[in] dma_dev Dma controller to use for transaction. 1008 * @param[in] channel Dma channel to be used for transaction. 1009 * @param[out] buff Pointer to uint8_t, where data would be read. 1010 * @param[in] length of data to be read, 1011 * @param[out] status Pointer to uint32_t to report line status. 1012 * 1013 * @return Standard return code for SEDI. 1014 * @retval SEDI_DRIVER_OK on success, negative value for possible errors 1015 */ 1016 int sedi_uart_dma_read_polled(IN sedi_uart_t uart, IN sedi_dma_t dma_dev, 1017 IN uint32_t channel, OUT uint8_t *buff, 1018 IN uint32_t length, OUT uint32_t *status); 1019 1020 /** 1021 * @brief Set RS-485 config. 1022 * 1023 * @param[in] uart UART port index. 1024 * @param[in] cfg Pointer to sedi_uart_rs485_config_t. 1025 * 1026 * @return Standard return code for SEDI. 1027 * @retval SEDI_DRIVER_OK on success, negative value for possible errors 1028 */ 1029 int sedi_uart_rs485_set_config(IN sedi_uart_t uart, 1030 IN sedi_uart_rs485_config_t *cfg); 1031 1032 /** 1033 * @brief Set or clear uart rx-only mode. 1034 * 1035 * This APIs sets uart port to rx-only mode when rx_only parameter is true. 1036 * When rx_only parameter is false, it clears rx-only mode and enables both 1037 * tx and rx operation for the given port, irrespective of current mode. 1038 * 1039 * On enabling rx-only mode all transmit APIs return error. 1040 * If RS-485 mode is enabled, the driver enable signal(de) is disabled and 1041 * only receiver enable (re) signal can be activated. 1042 * 1043 * @param[in] uart UART port index. 1044 * @param[in] rx_only when rx_only flag set to true rx-only mode is enabled and 1045 * disabled when set to false. 1046 * 1047 * @return Standard return code for SEDI. 1048 * @retval SEDI_DRIVER_OK on success, negative value for possible errors 1049 */ 1050 int sedi_uart_set_rx_only_mode(IN sedi_uart_t uart, bool rx_only); 1051 1052 /** 1053 * @brief Set or clear uart tx-only mode. 1054 * 1055 * This APIs sets uart port to tx-only mode when tx_only parameter is true. 1056 * When tx_only parameter is false, it clears tx-only mode and enables both tx 1057 * and rx operation for the given port, irrespective of the current mode. 1058 * 1059 * On enabling tx-only mode all receive functions return error. 1060 * If RS-485 mode is enabled, the receiver enable signal(re) is disabled and 1061 * only driver enable (de) signal can be activated. 1062 * 1063 * @param[in] uart UART port index. 1064 * @param[in] tx_only when flag set to true tx-only mode is enabled and disabled 1065 * when set to false. 1066 * 1067 * @return Standard return code for SEDI. 1068 * @retval SEDI_DRIVER_OK on success, negative value for possible errors 1069 */ 1070 int sedi_uart_set_tx_only_mode(IN sedi_uart_t uart, bool tx_only); 1071 1072 /** 1073 * @brief Enable rs-485 signals for selected uart. 1074 * Should be enabled after configuring using sedi_uart_set_config. 1075 * 1076 * @param[in] uart UART port index. 1077 * 1078 * @return Standard return code for SEDI. 1079 * @retval SEDI_DRIVER_OK on success, negative value for possible errors 1080 */ 1081 int sedi_uart_rs485_enable(IN sedi_uart_t uart); 1082 1083 /** 1084 * @brief Disable rs-485 signals for selected uart. 1085 * 1086 * @param[in] uart UART port index. 1087 * 1088 * @return Standard return code for SEDI. 1089 * @retval SEDI_DRIVER_OK on success, negative value for possible errors 1090 */ 1091 int sedi_uart_rs485_disable(IN sedi_uart_t uart); 1092 1093 /** 1094 * @brief Get rs485 configuration for selected uart. 1095 * 1096 * @param[in] uart UART port index. 1097 * @param[out] cfg pointer to iseis_uart_rs485_config_t populated by the call. 1098 * 1099 * @return Standard return code for SEDI. 1100 * @retval SEDI_DRIVER_OK on success, negative value for possible errors 1101 */ 1102 int sedi_uart_rs485_get_config(IN sedi_uart_t uart, 1103 OUT sedi_uart_rs485_config_t *cfg); 1104 1105 /** 1106 * @brief Set the configuration for 9-bit operation. 1107 * 1108 * @param[in] uart UART port index. 1109 * @param[in] cfg pointer to configuration for 9-bit operation 1110 * 1111 * @return Standard return code for SEDI. 1112 * @retval SEDI_DRIVER_OK on success, negative value for possible errors 1113 */ 1114 int sedi_uart_9bit_set_config(IN sedi_uart_t uart, 1115 IN sedi_uart_9bit_config_t *cfg); 1116 1117 /** 1118 * @brief Disable 9-bit operation. 1119 * 1120 * @param[in] uart UART port index. 1121 * 1122 * @return Standard return code for SEDI. 1123 * @retval SEDI_DRIVER_OK on success, negative value for possible errors 1124 */ 1125 int sedi_uart_9bit_disable(IN sedi_uart_t uart); 1126 1127 /** 1128 * @brief Enable 9-bit operation. 1129 * 1130 * @param[in] uart UART port index. 1131 * 1132 * @return Standard return code for SEDI. 1133 * @retval SEDI_DRIVER_OK on success, negative value for possible errors 1134 */ 1135 int sedi_uart_9bit_enable(IN sedi_uart_t uart); 1136 1137 /** 1138 * @brief Transmit 9-bit destination address. 1139 * 1140 * @param[in] uart UART port index. 1141 * @param[in] address address to send. 1142 * 1143 * @return Standard return code for SEDI. 1144 * @retval SEDI_DRIVER_OK on success, negative value for possible errors 1145 */ 1146 int sedi_uart_9bit_send_address(IN sedi_uart_t uart, uint8_t address); 1147 1148 /** 1149 * @brief Get current configuration for 9-bit mode. 1150 * 1151 * @param[in] uart UART port index. 1152 * @param[out] cfg pointer to sedi_uart_9bit_config_t populated by this call. 1153 * 1154 * @return Standard return code for SEDI. 1155 * @retval SEDI_DRIVER_OK on success, negative value for possible errors 1156 */ 1157 int sedi_uart_9bit_get_config(IN sedi_uart_t uart, 1158 sedi_uart_9bit_config_t *cfg); 1159 1160 /** 1161 * @brief UART set power state. 1162 * 1163 * Set UART instance to specified power state 1164 * 1165 * @param[in] power state to be entered. 1166 * 1167 * @retval SEDI_DRIVER_OK if operation was successful. 1168 * @retval non zero error code otherwise. 1169 */ 1170 int32_t sedi_uart_set_power(IN sedi_uart_t uart, IN sedi_power_state_t state); 1171 1172 /** 1173 * @brief Init a UART instance. 1174 * 1175 * Set its register base address. A UART instance can be used only after 1176 * initialized 1177 * 1178 * @param[in] uart UART port index. 1179 * @param[in] register base address of the instance. 1180 * 1181 * @retval SEDI_DRIVER_OK if operation was successful. 1182 * @retval non zero error code otherwise. 1183 */ 1184 int32_t sedi_uart_init(IN sedi_uart_t uart, void *base); 1185 1186 #endif /* _SEDI_DRIVER_UART_H_ */ 1187