rom_uart_8xx.h 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. /*
  2. * @brief LPC8xx UART ROM API declarations and functions
  3. *
  4. * @note
  5. * Copyright(C) NXP Semiconductors, 2012
  6. * All rights reserved.
  7. *
  8. * @par
  9. * Software that is described herein is for illustrative purposes only
  10. * which provides customers with programming information regarding the
  11. * LPC products. This software is supplied "AS IS" without any warranties of
  12. * any kind, and NXP Semiconductors and its licensor disclaim any and
  13. * all warranties, express or implied, including all implied warranties of
  14. * merchantability, fitness for a particular purpose and non-infringement of
  15. * intellectual property rights. NXP Semiconductors assumes no responsibility
  16. * or liability for the use of the software, conveys no license or rights under any
  17. * patent, copyright, mask work right, or any other intellectual property rights in
  18. * or to any products. NXP Semiconductors reserves the right to make changes
  19. * in the software without notification. NXP Semiconductors also makes no
  20. * representation or warranty that such application will be suitable for the
  21. * specified use without further testing or modification.
  22. *
  23. * @par
  24. * Permission to use, copy, modify, and distribute this software and its
  25. * documentation is hereby granted, under NXP Semiconductors' and its
  26. * licensor's relevant copyrights in the software, without fee, provided that it
  27. * is used in conjunction with NXP Semiconductors microcontrollers. This
  28. * copyright, permission, and disclaimer notice must appear in all copies of
  29. * this code.
  30. */
  31. #ifndef __ROM_UART_8XX_H_
  32. #define __ROM_UART_8XX_H_
  33. #ifdef __cplusplus
  34. extern "C" {
  35. #endif
  36. /** @defgroup UARTROM_8XX CHIP: LPC8xx UART ROM API declarations and functions
  37. * @ingroup CHIP_8XX_Drivers
  38. * @{
  39. */
  40. /**
  41. * @brief UART ROM driver - UART errors in UART configuration used in uart_init function
  42. */
  43. #define OVERRUN_ERR_EN (1 << 0) /*!< Bit 0: Enable overrun error */
  44. #define UNDERRUN_ERR_EN (1 << 1) /*!< Bit 1: Enable underrun error */
  45. #define FRAME_ERR_EN (1 << 2) /*!< Bit 2: enable frame error */
  46. #define PARITY_ERR_EN (1 << 3) /*!< Bit 3: enable parity error */
  47. #define RXNOISE_ERR_EN (1 << 4) /*!< Bit 4: enable receive noise error */
  48. /**
  49. * Macros for UART errors
  50. */
  51. /*!< Enable all the UART errors */
  52. #define ALL_ERR_EN (OVERRUN_ERR_EN | UNDERRUN_ERR_EN | FRAME_ERR_EN | PARITY_ERR_EN | \
  53. RXNOISE_ERR_EN)
  54. /*!< Disable all the errors */
  55. #define NO_ERR_EN (0)
  56. /**
  57. * Transfer mode values in UART parameter structure.
  58. * Used in uart_get_line & uart_put_line function
  59. */
  60. /*!< 0x00: uart_get_line: stop transfer when the buffer is full */
  61. /*!< 0x00: uart_put_line: stop transfer when the buffer is empty */
  62. #define TX_MODE_BUF_EMPTY (0x00)
  63. #define RX_MODE_BUF_FULL (0x00)
  64. /*!< 0x01: uart_get_line: stop transfer when CRLF are received */
  65. /*!< 0x01: uart_put_line: transfer stopped after reaching \0 and CRLF is sent out after that */
  66. #define TX_MODE_SZERO_SEND_CRLF (0x01)
  67. #define RX_MODE_CRLF_RECVD (0x01)
  68. /*!< 0x02: uart_get_line: stop transfer when LF are received */
  69. /*!< 0x02: uart_put_line: transfer stopped after reaching \0. And LF is sent out after that */
  70. #define TX_MODE_SZERO_SEND_LF (0x02)
  71. #define RX_MODE_LF_RECVD (0x02)
  72. /*!< 0x03: uart_get_line: RESERVED */
  73. /*!< 0x03: uart_put_line: transfer stopped after reaching \0 */
  74. #define TX_MODE_SZERO (0x03)
  75. /**
  76. * @brief UART ROM driver modes
  77. */
  78. #define DRIVER_MODE_POLLING (0x00) /*!< Polling mode */
  79. #define DRIVER_MODE_INTERRUPT (0x01) /*!< Interrupt mode */
  80. #define DRIVER_MODE_DMA (0x02) /*!< DMA mode */
  81. /**
  82. * @brief UART ROM driver UART handle
  83. */
  84. typedef void UART_HANDLE_T;
  85. /**
  86. * @brief UART ROM driver UART callback function
  87. */
  88. typedef void (*UART_CALLBK_T)(uint32_t err_code, uint32_t n);
  89. /**
  90. * @brief UART ROM driver UART DMA callback function
  91. */
  92. typedef void (*UART_DMA_REQ_T)(uint32_t src_adr, uint32_t dst_adr, uint32_t size);
  93. /**
  94. * @brief UART ROM driver configutaion structure
  95. */
  96. typedef struct {
  97. uint32_t sys_clk_in_hz; /*!< main clock in Hz */
  98. uint32_t baudrate_in_hz; /*!< Baud rate in Hz */
  99. uint8_t config; /*!< Configuration value */
  100. /*!< bit1:0 Data Length: 00: 7 bits length, 01: 8 bits length, others: reserved */
  101. /*!< bit3:2 Parity: 00: No Parity, 01: reserved, 10: Even, 11: Odd */
  102. /*!< bit4: Stop Bit(s): 0: 1 Stop bit, 1: 2 Stop bits */
  103. uint8_t sync_mod; /*!< Sync mode settings */
  104. /*!< bit0: Mode: 0: Asynchronous mode, 1: Synchronous mode */
  105. /*!< bit1: 0: Un_RXD is sampled on the falling edge of SCLK */
  106. /*!< 1: Un_RXD is sampled on the rising edge of SCLK */
  107. /*!< bit2: 0: Start and stop bits are transmitted as in asynchronous mode) */
  108. /*!< 1: Start and stop bits are not transmitted) */
  109. /*!< bit3: 0: The UART is a slave in Synchronous mode */
  110. /*!< 1: The UART is a master in Synchronous mode */
  111. uint16_t error_en; /*!< Errors to be enabled */
  112. /*!< bit0: Overrun Errors Enabled */
  113. /*!< bit1: Underrun Errors Enabled */
  114. /*!< bit2: FrameErr Errors Enabled */
  115. /*!< bit3: ParityErr Errors Enabled */
  116. /*!< bit4: RxNoise Errors Enabled */
  117. } UART_CONFIG_T;
  118. /**
  119. * @brief UART ROM driver parameter structure
  120. */
  121. typedef struct {
  122. uint8_t *buffer; /*!< Pointer to data buffer */
  123. uint32_t size; /*!< Size of the buffer */
  124. uint16_t transfer_mode; /*!< Transfer mode settings */
  125. /*!< 0x00: uart_get_line: stop transfer when the buffer is full */
  126. /*!< 0x00: uart_put_line: stop transfer when the buffer is empty */
  127. /*!< 0x01: uart_get_line: stop transfer when CRLF are received */
  128. /*!< 0x01: uart_put_line: transfer stopped after reaching \0 and CRLF is sent out after that */
  129. /*!< 0x02: uart_get_line: stop transfer when LF are received */
  130. /*!< 0x02: uart_put_line: transfer stopped after reaching \0 and LF is sent out after that */
  131. /*!< 0x03: uart_get_line: RESERVED */
  132. /*!< 0x03: uart_put_line: transfer stopped after reaching \0 */
  133. uint16_t driver_mode; /*!< Driver mode */
  134. /*!< 0x00: Polling mode, function blocked until transfer completes */
  135. /*!< 0x01: Interrupt mode, function immediately returns, callback invoked when transfer completes */
  136. /*!< 0x02: DMA mode, in case DMA block is available, DMA req function is called for UART DMA channel setup, then callback function indicate that transfer completes */
  137. UART_CALLBK_T callback_func_pt; /*!< callback function pointer */
  138. UART_DMA_REQ_T dma_req_func_pt; /*!< UART DMA channel setup function pointer, not applicable on LPC8xx */
  139. } UART_PARAM_T;
  140. /**
  141. * @brief UART ROM driver APIs structure
  142. */
  143. typedef struct UARTD_API {
  144. /*!< UART Configuration functions */
  145. uint32_t (*uart_get_mem_size)(void); /*!< Get the memory size needed by one Min UART instance */
  146. UART_HANDLE_T * (*uart_setup)(uint32_t base_addr, uint8_t * ram); /*!< Setup Min UART instance with provided memory and return the handle to this instance */
  147. uint32_t (*uart_init)(UART_HANDLE_T *handle, UART_CONFIG_T *set); /*!< Setup baud rate and operation mode for uart, then enable uart */
  148. /*!< UART polling functions block until completed */
  149. uint8_t (*uart_get_char)(UART_HANDLE_T *handle); /*!< Receive one Char from uart. This functions is only returned after Char is received. In case Echo is enabled, the received data is sent out immediately */
  150. void (*uart_put_char)(UART_HANDLE_T *handle, uint8_t data); /*!< Send one Char through uart. This function is only returned after data is sent */
  151. uint32_t (*uart_get_line)(UART_HANDLE_T *handle, UART_PARAM_T *param); /*!< Receive multiple bytes from UART */
  152. uint32_t (*uart_put_line)(UART_HANDLE_T *handle, UART_PARAM_T *param); /*!< Send string (end with \0) or raw data through UART */
  153. /*!< UART interrupt functions return immediately and callback when completed */
  154. void (*uart_isr)(UART_HANDLE_T *handle); /*!< UART interrupt service routine. To use this routine, the corresponding USART interrupt must be enabled. This function is invoked by the user ISR */
  155. } UARTD_API_T;
  156. /**
  157. * @}
  158. */
  159. #ifdef __cplusplus
  160. }
  161. #endif
  162. #endif /* __ROM_UART_8XX_H_ */