ADuCM302x Device Drivers API Reference Manual  Release 3.1.2.0
adi_uart_def.h
1 
45 #ifndef DEF_UART_DEF_H
46 #define DEF_UART_DEF_H
47 
48 /* Macro mapping from ADuCM4x50 to ADuCM302x */
49 #if defined(__ADUCM302x__)
50 
51 #define INTR_UART0_EVT INTR_UART_EVT
52 #define UART0_Int_Handler(void) UART_Int_Handler(void)
53 #define DMA_UART0_TX_Int_Handler(void) DMA_UART_TX_Int_Handler(void)
54 #define DMA_UART0_RX_Int_Handler(void) DMA_UART_RX_Int_Handler(void)
55 
56 #endif /* __ADUCM302x__ */
57 
64 typedef struct UART_BUFF_INFO
65 {
66  void *pStartAddress;
67  uint32_t nCount;
68  uint32_t nIndex;
69  bool bInUse;
70  bool bDMA;
71  struct UART_BUFF_INFO *pNextBuffer;
74 }ADI_UART_BUFF_INFO;
75 
76 
78 typedef void (*UART_BUFFER_SUBMIT) (ADI_UART_CONST_HANDLE const hDevice,
79  ADI_UART_BUFF_INFO *const pBuffer
80  );
81 
82 
91 typedef struct _ADI_UART_DATA_CHANNEL
92 {
93  ADI_UART_BUFF_INFO PingPong[2];
94  ADI_UART_BUFF_INFO *pFreeBuffer;
95  ADI_UART_BUFF_INFO *pFillBuffer;
98  ADI_UART_BUFF_INFO *pActiveBuffer;
99  ADI_UART_TRANSFER_MODE eDataTranferMode;
100  UART_BUFFER_SUBMIT pfSubmitBuffer;
101  SEM_VAR_DECLR
102 
103 }ADI_UART_DATA_CHANNEL;
104 
105 
112 typedef struct _ADI_UART_DEVICE_INFO
113 {
114  DMA_CHANn_TypeDef dmaTxChannelNum;
115  DMA_CHANn_TypeDef dmaRxChannelNum;
116  IRQn_Type eDMATx;
117  IRQn_Type eDMARx;
118  IRQn_Type eIRQn;
119  ADI_UART_TypeDef *pUartRegs;
120  ADI_UART_HANDLE hDevice;
122 }ADI_UART_DEVICE_INFO;
123 
124 
131 typedef struct _ADI_UART_DEVICE
132 {
133  ADI_UART_DIRECTION eDirection;
134  ADI_UART_DEVICE_INFO *pUartInfo;
135  volatile ADI_UART_TypeDef *pUARTRegs;
136  ADI_CALLBACK pfCallback;
137  void *pCBParam;
138  bool bAutobaudInProgress;
139  volatile uint32_t nHwError;
140  volatile uint32_t nAutobaudError;
141  ADI_UART_DATA_CHANNEL *pChannelTx;
142  ADI_UART_DATA_CHANNEL *pChannelRx;
143  volatile uint32_t nBaudRate;
144  bool bAutobaudCallbackMode;
145  bool bRxFifoEn;
146  uint8_t nRxFifoTrig;
147 } ADI_UART_DEVICE;
148 
149 
156 typedef struct _ADI_UART_CONFIG
157 {
158  uint16_t LCR;
160  uint16_t DIV;
162  uint16_t FBR;
164  uint16_t LCR2;
166  uint16_t FCR;
168  uint16_t RSC;
170  uint16_t IEN;
172 } ADI_UART_CONFIG;
173 
174 
175 /******************************************************************************
176  * UART Device internal API function prototypes
177  *****************************************************************************/
178 
179 /*
180  * UART device initialization helper function.
181 */
182 static void uart_init(ADI_UART_CONST_HANDLE const hDevice, uint32_t const nDeviceNum);
183 
184 
185 /*
186  * Data transfer helper functions.
187 */
188 static void uart_submittxbuffer(ADI_UART_CONST_HANDLE const hDevice, ADI_UART_BUFF_INFO *const pBuffer);
189 
190 static void uart_submitrxbuffer(ADI_UART_CONST_HANDLE const hDevice, ADI_UART_BUFF_INFO *const pBuffer);
191 
192 
193 /*
194  * Data management helper functions.
195 */
196 static ADI_UART_RESULT uart_getbuffer(ADI_UART_HANDLE hDevice, ADI_UART_DATA_CHANNEL *pChannel, void **ppBuffer, uint32_t *pHwError);
197 
198 static ADI_UART_RESULT uart_PendForBuffer(ADI_UART_HANDLE const hDevice , ADI_UART_DATA_CHANNEL *pChannel, uint32_t *pHwError);
199 
200 static void uart_ManageProcessedBuffer(ADI_UART_HANDLE hDevice, ADI_UART_DATA_CHANNEL *pChannel, ADI_UART_EVENT eEvent);
201 
202 static void uart_TxDataHandler(ADI_UART_HANDLE hDevice);
203 
204 static void uart_RxDataHandler(ADI_UART_HANDLE hDevice, uint8_t nBytes);
205 
206 
207 /*
208  * Interrupt Handler.
209 */
210 static void Common_Uart_Interrupt_Handler(ADI_UART_HANDLE hDevice);
211 
212 
213 /*
214  * Handle Validation function
215 */
216 #ifdef ADI_DEBUG
217 static ADI_UART_RESULT ValidateHandle(ADI_UART_CONST_HANDLE hDevice);
218 #endif /* ADI_DEBUG */
219 
220 #endif /* end of ifndef DEF_UART_DEF_H */
221 
ADI_UART_RESULT
Definition: adi_uart.h:138
ADI_UART_DIRECTION
Definition: adi_uart.h:98
ADI_UART_EVENT
Definition: adi_uart.h:114
struct _ADI_UART_DEVICE * ADI_UART_HANDLE
Definition: adi_uart.h:86
ADI_UART_TRANSFER_MODE
Definition: adi_uart.h:305
const struct _ADI_UART_DEVICE * ADI_UART_CONST_HANDLE
Definition: adi_uart.h:91