ADuCM4x50 Device Drivers API Reference Manual  Release 4.0.0.0
adi_uart_def.h
1 
14 #ifndef DEF_UART_DEF_H
15 #define DEF_UART_DEF_H
16 
17 /* Macro mapping from ADuCM4x50 to ADuCM302x */
18 #if defined(__ADUCM302x__)
19 
20 #define INTR_UART0_EVT INTR_UART_EVT
21 #define UART0_Int_Handler(void) UART_Int_Handler(void)
22 #define DMA_UART0_TX_Int_Handler(void) DMA_UART_TX_Int_Handler(void)
23 #define DMA_UART0_RX_Int_Handler(void) DMA_UART_RX_Int_Handler(void)
24 
25 #endif /* __ADUCM302x__ */
26 
33 typedef struct UART_BUFF_INFO
34 {
35  void *pStartAddress;
36  uint32_t nCount;
37  uint32_t nIndex;
38  uint32_t nRemDoneTransfers;
39  uint8_t nDmaMode;
40  bool bInUse;
41  bool bDMA;
42  struct UART_BUFF_INFO *pNextBuffer;
44 }ADI_UART_BUFF_INFO;
45 
46 
48 typedef void (*UART_BUFFER_SUBMIT) (ADI_UART_CONST_HANDLE const hDevice,
49  ADI_UART_BUFF_INFO *const pBuffer
50  );
51 
52 
61 typedef struct _ADI_UART_DATA_CHANNEL
62 {
63  ADI_UART_BUFF_INFO PingPong[2];
64  ADI_UART_BUFF_INFO *pFreeBuffer;
65  ADI_UART_BUFF_INFO *pFillBuffer;
68  ADI_UART_BUFF_INFO *pActiveBuffer;
69  ADI_UART_TRANSFER_MODE eDataTranferMode;
70  UART_BUFFER_SUBMIT pfSubmitBuffer;
71  uint8_t nFreeDescriptor;
72  bool bIsPrimNext;
73  SEM_VAR_DECLR
74 
75 }ADI_UART_DATA_CHANNEL;
76 
77 
84 typedef struct _ADI_UART_DEVICE_INFO
85 {
86  DMA_CHANn_TypeDef dmaTxChannelNum;
87  DMA_CHANn_TypeDef dmaRxChannelNum;
88  IRQn_Type eDMATx;
89  IRQn_Type eDMARx;
90  IRQn_Type eIRQn;
91  ADI_UART_TypeDef *pUartRegs;
92  ADI_UART_HANDLE hDevice;
94 }ADI_UART_DEVICE_INFO;
95 
96 
103 typedef struct _ADI_UART_DEVICE
104 {
105  ADI_UART_DIRECTION eDirection;
106  ADI_UART_DEVICE_INFO *pUartInfo;
107  volatile ADI_UART_TypeDef *pUARTRegs;
108  ADI_CALLBACK pfCallback;
109  void *pCBParam;
110  bool bAutobaudInProgress;
111  volatile uint32_t nHwError;
112  volatile uint32_t nAutobaudError;
113  ADI_UART_DATA_CHANNEL *pChannelTx;
114  ADI_UART_DATA_CHANNEL *pChannelRx;
115  volatile uint32_t nBaudRate;
116  bool bAutobaudCallbackMode;
117  bool bRxFifoEn;
118  uint8_t nRxFifoTrig;
119 } ADI_UART_DEVICE;
120 
121 
128 typedef struct _ADI_UART_CONFIG
129 {
130  uint16_t LCR;
132  uint16_t DIV;
134  uint16_t FBR;
136  uint16_t LCR2;
138  uint16_t FCR;
140  uint16_t RSC;
142  uint16_t IEN;
144 } ADI_UART_CONFIG;
145 
146 
147 /******************************************************************************
148  * UART Device internal API function prototypes
149  *****************************************************************************/
150 
151 /*
152  * UART device initialization helper function.
153 */
154 static void uart_init(ADI_UART_CONST_HANDLE const hDevice, uint32_t const nDeviceNum);
155 
156 
157 /*
158  * Data transfer helper functions.
159 */
160 static void uart_submittxbuffer(ADI_UART_CONST_HANDLE const hDevice, ADI_UART_BUFF_INFO *const pBuffer);
161 
162 static void uart_submitrxbuffer(ADI_UART_CONST_HANDLE const hDevice, ADI_UART_BUFF_INFO *const pBuffer);
163 
164 
165 /*
166  * Data management helper functions.
167 */
168 static ADI_UART_RESULT uart_getbuffer(ADI_UART_HANDLE hDevice, ADI_UART_DATA_CHANNEL *pChannel, void **ppBuffer, uint32_t *pHwError);
169 
170 static ADI_UART_RESULT uart_PendForBuffer(ADI_UART_HANDLE const hDevice , ADI_UART_DATA_CHANNEL *pChannel, uint32_t *pHwError);
171 
172 static void uart_ManageProcessedBuffer(ADI_UART_HANDLE hDevice, ADI_UART_DATA_CHANNEL *pChannel, ADI_UART_EVENT eEvent);
173 
174 static void uart_TxDataHandler(ADI_UART_HANDLE hDevice);
175 
176 static void uart_RxDataHandler(ADI_UART_HANDLE hDevice, uint8_t nBytes);
177 
178 
179 /*
180  * Interrupt Handler.
181 */
182 static void Common_Uart_Interrupt_Handler(ADI_UART_HANDLE hDevice);
183 
184 #if defined(ADI_UART_DMA_EXTENSION_ENABLE) && (ADI_UART_DMA_EXTENSION_ENABLE == 1)
185 static void Common_DMA_Uart_Interrupt_Handler(ADI_UART_HANDLE hDevice, ADI_UART_DATA_CHANNEL *pChannel, ADI_UART_EVENT eEvent);
186 #endif
187 
188 
189 /*
190  * Handle Validation function
191 */
192 #ifdef ADI_DEBUG
193 static ADI_UART_RESULT ValidateHandle(ADI_UART_CONST_HANDLE hDevice);
194 
195 #if defined(ADI_UART_DMA_EXTENSION_ENABLE) && (ADI_UART_DMA_EXTENSION_ENABLE == 1)
196 static ADI_UART_RESULT ValidateDmaMode(ADI_UART_CONST_HANDLE hDevice, uint8_t eMode);
197 #endif
198 
199 #endif /* ADI_DEBUG */
200 
201 #endif /* end of ifndef DEF_UART_DEF_H */
202 
ADI_UART_RESULT
Definition: adi_uart.h:107
ADI_UART_DIRECTION
Definition: adi_uart.h:67
ADI_UART_EVENT
Definition: adi_uart.h:83
struct _ADI_UART_DEVICE * ADI_UART_HANDLE
Definition: adi_uart.h:55
ADI_UART_TRANSFER_MODE
Definition: adi_uart.h:274
const struct _ADI_UART_DEVICE * ADI_UART_CONST_HANDLE
Definition: adi_uart.h:60