1 /* 2 * @brief LPC15XX UART ROM API declarations and functions 3 * 4 * @note 5 * Copyright(C) NXP Semiconductors, 2013 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 32 #ifndef __ROM_UART_15XX_H_ 33 #define __ROM_UART_15XX_H_ 34 35 #ifdef __cplusplus 36 extern "C" { 37 #endif 38 39 /** @defgroup UARTROM_15XX CHIP: LPC15xx UART ROM API declarations and functions 40 * @ingroup ROMAPI_15XX 41 * @{ 42 */ 43 44 /** 45 * @brief UART ROM driver - UART errors in UART configuration used in uart_init function 46 */ 47 #define OVERRUN_ERR_EN (1 << 0) /*!< Bit 0: Enable overrun error */ 48 #define UNDERRUN_ERR_EN (1 << 1) /*!< Bit 1: Enable underrun error */ 49 #define FRAME_ERR_EN (1 << 2) /*!< Bit 2: enable frame error */ 50 #define PARITY_ERR_EN (1 << 3) /*!< Bit 3: enable parity error */ 51 #define RXNOISE_ERR_EN (1 << 4) /*!< Bit 4: enable receive noise error */ 52 53 /** 54 * Macros for UART errors 55 */ 56 /*!< Enable all the UART errors */ 57 #define ALL_ERR_EN (OVERRUN_ERR_EN | UNDERRUN_ERR_EN | FRAME_ERR_EN | PARITY_ERR_EN | \ 58 RXNOISE_ERR_EN) 59 /*!< Disable all the errors */ 60 #define NO_ERR_EN (0) 61 62 /** 63 * Transfer mode values in UART parameter structure. 64 * Used in uart_get_line & uart_put_line function 65 */ 66 /*!< 0x00: uart_get_line: stop transfer when the buffer is full */ 67 /*!< 0x00: uart_put_line: stop transfer when the buffer is empty */ 68 #define TX_MODE_BUF_EMPTY (0x00) 69 #define RX_MODE_BUF_FULL (0x00) 70 /*!< 0x01: uart_get_line: stop transfer when CRLF are received */ 71 /*!< 0x01: uart_put_line: transfer stopped after reaching \0 and CRLF is sent out after that */ 72 #define TX_MODE_SZERO_SEND_CRLF (0x01) 73 #define RX_MODE_CRLF_RECVD (0x01) 74 /*!< 0x02: uart_get_line: stop transfer when LF are received */ 75 /*!< 0x02: uart_put_line: transfer stopped after reaching \0. And LF is sent out after that */ 76 #define TX_MODE_SZERO_SEND_LF (0x02) 77 #define RX_MODE_LF_RECVD (0x02) 78 /*!< 0x03: uart_get_line: RESERVED */ 79 /*!< 0x03: uart_put_line: transfer stopped after reaching \0 */ 80 #define TX_MODE_SZERO (0x03) 81 82 /** 83 * @brief UART ROM driver modes 84 */ 85 #define DRIVER_MODE_POLLING (0x00) /*!< Polling mode */ 86 #define DRIVER_MODE_INTERRUPT (0x01) /*!< Interrupt mode */ 87 #define DRIVER_MODE_DMA (0x02) /*!< DMA mode */ 88 89 /** 90 * @brief UART ROM driver UART handle 91 */ 92 typedef void *UART_HANDLE_T; 93 94 /** 95 * @brief UART ROM driver UART callback function 96 */ 97 typedef void (*UART_CALLBK_T)(uint32_t err_code, uint32_t n); 98 99 /** 100 * @brief UART ROM driver UART DMA callback function 101 */ 102 typedef void (*UART_DMA_REQ_T)(uint32_t src_adr, uint32_t dst_adr, uint32_t size); 103 104 /** 105 * @brief UART ROM driver configutaion structure 106 */ 107 typedef struct { 108 uint32_t sys_clk_in_hz; /*!< System clock in Hz */ 109 uint32_t baudrate_in_hz; /*!< Baud rate in Hz */ 110 uint8_t config; /*!< Configuration value */ 111 /*!< bit1:0 Data Length: 00: 7 bits length, 01: 8 bits length, others: reserved */ 112 /*!< bit3:2 Parity: 00: No Parity, 01: reserved, 10: Even, 11: Odd */ 113 /*!< bit4: Stop Bit(s): 0: 1 Stop bit, 1: 2 Stop bits */ 114 uint8_t sync_mod; /*!< Sync mode settings */ 115 /*!< bit0: Mode: 0: Asynchronous mode, 1: Synchronous mode */ 116 /*!< bit1: 0: Un_RXD is sampled on the falling edge of SCLK */ 117 /*!< 1: Un_RXD is sampled on the rising edge of SCLK */ 118 /*!< bit2: 0: Start and stop bits are transmitted as in asynchronous mode) */ 119 /*!< 1: Start and stop bits are not transmitted) */ 120 /*!< bit3: 0: The UART is a slave in Synchronous mode */ 121 /*!< 1: The UART is a master in Synchronous mode */ 122 uint16_t error_en; /*!< Errors to be enabled */ 123 /*!< bit0: Overrun Errors Enabled */ 124 /*!< bit1: Underrun Errors Enabled */ 125 /*!< bit2: FrameErr Errors Enabled */ 126 /*!< bit3: ParityErr Errors Enabled */ 127 /*!< bit4: RxNoise Errors Enabled */ 128 } UART_CONFIG_T; 129 130 /** 131 * @brief UART ROM driver parameter structure 132 */ 133 typedef struct { 134 uint8_t *buffer; /*!< Pointer to data buffer */ 135 uint32_t size; /*!< Size of the buffer */ 136 uint16_t transfer_mode; /*!< Transfer mode settings */ 137 /*!< 0x00: uart_get_line: stop transfer when the buffer is full */ 138 /*!< 0x00: uart_put_line: stop transfer when the buffer is empty */ 139 /*!< 0x01: uart_get_line: stop transfer when CRLF are received */ 140 /*!< 0x01: uart_put_line: transfer stopped after reaching \0 and CRLF is sent out after that */ 141 /*!< 0x02: uart_get_line: stop transfer when LF are received */ 142 /*!< 0x02: uart_put_line: transfer stopped after reaching \0 and LF is sent out after that */ 143 /*!< 0x03: uart_get_line: RESERVED */ 144 /*!< 0x03: uart_put_line: transfer stopped after reaching \0 */ 145 uint8_t driver_mode; /*!< Driver mode */ 146 /*!< 0x00: Polling mode, function blocked until transfer completes */ 147 /*!< 0x01: Interrupt mode, function immediately returns, callback invoked when transfer completes */ 148 /*!< 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 */ 149 uint8_t dma_num; /*!< DMA channel number in case DMA mode is enabled */ 150 UART_CALLBK_T callback_func_pt; 151 uint32_t dma; /* DMA handler */ 152 } UART_PARAM_T; 153 154 /** 155 * @brief UART ROM driver APIs structure 156 */ 157 typedef struct UART_API { 158 /* UART Configuration functions */ 159 uint32_t (*uart_get_mem_size)(void); /*!< Get the memory size needed by one Min UART instance */ 160 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 */ 161 uint32_t (*uart_init)(UART_HANDLE_T handle, UART_CONFIG_T *set); /*!< Setup baud rate and operation mode for uart, then enable uart */ 162 163 /* UART polling functions block until completed */ 164 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 */ 165 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 */ 166 uint32_t (*uart_get_line)(UART_HANDLE_T handle, UART_PARAM_T *param); /*!< Receive multiple bytes from UART */ 167 uint32_t (*uart_put_line)(UART_HANDLE_T handle, UART_PARAM_T *param); /*!< Send string (end with \0) or raw data through UART */ 168 169 /* UART interrupt functions return immediately and callback when completed */ 170 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 */ 171 } UARTD_API_T; 172 173 /** 174 * @} 175 */ 176 177 #ifdef __cplusplus 178 } 179 #endif 180 181 #endif /* __ROM_UART_15XX_H_ */ 182