ADuCM4x50 Device Drivers API Reference Manual  Release 4.0.0.0
adi_uart.h
1 
15 #ifndef ADI_UART_H
16 #define ADI_UART_H
17 
24 /*============= I N C L U D E S =============*/
25 
26 #include <stdint.h>
27 #include <stddef.h>
28 #include <string.h>
29 #include <assert.h>
30 #include <adi_processor.h>
31 #include <adi_uart_config.h>
32 #include <rtos_map/adi_rtos_map.h>
33 #include <drivers/dma/adi_dma.h>
34 #include <drivers/pwr/adi_pwr.h>
35 
36 #ifdef __cplusplus
37 extern "C" {
38 #endif /* __cplusplus */
39 
45 #define ADI_UART_UNIDIR_MEMORY_SIZE (48u + (72u + ADI_SEM_SIZE))
46 
50 #define ADI_UART_BIDIR_MEMORY_SIZE (48u + (72u + ADI_SEM_SIZE)*2u)
51 
55 typedef struct _ADI_UART_DEVICE* ADI_UART_HANDLE;
56 
60 typedef const struct _ADI_UART_DEVICE* ADI_UART_CONST_HANDLE;
61 
67 typedef enum
68 {
76 
77 
83  typedef enum
84 {
98 
99 
107  typedef enum
108 {
109 
148 
156 typedef enum
157 {
181 
188 typedef enum
189 {
199 
205 typedef enum
206 {
207 
208  ADI_UART_RX_FIFO_TRIG_LEVEL_1BYTE = 0 << BITP_UART_FCR_RFTRIG,
210  ADI_UART_RX_FIFO_TRIG_LEVEL_4BYTE = 1 << BITP_UART_FCR_RFTRIG,
212  ADI_UART_RX_FIFO_TRIG_LEVEL_8BYTE = 2 << BITP_UART_FCR_RFTRIG,
214  ADI_UART_RX_FIFO_TRIG_LEVEL_14BYTE = 3 << BITP_UART_FCR_RFTRIG
217 
223 typedef enum
224 {
234 
240 typedef enum
241 {
253 
259 typedef enum
260 {
261 
268 
274 typedef enum
275 {
276 
286 
287 
295 {
297  uint32_t nBufferSize;
298  uint32_t nBytesNumber;
301 /******************************************************************************
302  * UART Device external API function prototypes
303  *****************************************************************************/
304 
305 /*
306  * Device initialization and uninitialization interfaces.
307 */
309  uint32_t const nDeviceNum,
310  ADI_UART_DIRECTION const eDirection,
311  void *pMemory,
312  uint32_t const nMemSize,
313  ADI_UART_HANDLE *const phDevice
314 );
315 
317  ADI_UART_HANDLE const hDevice
318 );
319 
320 
321 /******************************************************************************
322  * Eliminatable functions that may be optimized out by the linker
323  *****************************************************************************/
324 
325 /*
326  * Non-blocking mode functions.
327 */
328 
330  ADI_UART_HANDLE const hDevice,
331  void *const pBuffer,
332  uint32_t const nBufSize,
333  bool const bDMA
334 );
335 
337  ADI_UART_HANDLE const hDevice,
338  void *const pBuffer,
339  uint32_t const nBufSize,
340  bool const bDMA
341 );
342 
344  ADI_UART_HANDLE const hDevice,
345  void **const ppBuffer,
346  uint32_t *pHwError
347 );
348 
350  ADI_UART_HANDLE const hDevice,
351  void **const ppBuffer,
352  uint32_t *pHwError
353 );
355  ADI_UART_HANDLE const hDevice,
356  bool *const pbAvailable
357 );
358 
360  ADI_UART_HANDLE const hDevice,
361  bool *const pbAvailable
362 );
363 
364 /*
365  * Blocking mode functions.
366 */
367 
369  ADI_UART_HANDLE const hDevice,
370  void *const pBuffer,
371  uint32_t const nBufSize,
372  bool const bDMA,
373  uint32_t *pHwError
374 );
375 
377  ADI_UART_HANDLE const hDevice,
378  void *const pBuffer,
379  uint32_t const nBufSize,
380  bool const bDMA,
381  uint32_t *pHwError
382 );
383 
385  ADI_UART_HANDLE const hDevice,
386  uint8_t *const pRX
387 );
388 
389 
390 /*
391  * Configuration interface functions.
392 */
393 
395  ADI_UART_HANDLE const hDevice,
396  bool const bEnable
397 );
398 
400  ADI_UART_HANDLE const hDevice,
401  bool const bEnable,
402  bool const bAutobaudCallbackMode
403 );
404 
406  ADI_UART_HANDLE const hDevice,
407  ADI_UART_TRIG_LEVEL const eTriglevel
408 );
409 
411  ADI_UART_HANDLE const hDevice,
412  bool const bEnable
413 );
414 
416  ADI_UART_HANDLE const hDevice,
417  uint32_t *pnBaudRate,
418  uint32_t *pAutobaudError
419 );
420 
422  ADI_UART_HANDLE const hDevice,
423  bool const bEnable
424 );
425 
427  ADI_UART_HANDLE const hDevice,
428  ADI_UART_PARITY const eParity,
429  ADI_UART_STOPBITS const eStopBits,
430  ADI_UART_WORDLEN const eWordLength
431 );
432 
434  ADI_UART_HANDLE const hDevice,
435  uint16_t const nDivC,
436  uint8_t const nDivM,
437  uint16_t const nDivN,
438  uint8_t const nOSR
439 );
440 #if defined(ADI_UART_DMA_EXTENSION_ENABLE) && (ADI_UART_DMA_EXTENSION_ENABLE == 1)
442  ADI_UART_HANDLE const hDevice,
443  ADI_DMA_MODE const eMode
444 );
445 
447  ADI_UART_HANDLE const hDevice,
448  ADI_DMA_MODE const eMode
449 );
450 #endif
451 
452 /*
453  * Channel data control functions.
454 */
455 
457  ADI_UART_CONST_HANDLE const hDevice
458 );
459 
461  ADI_UART_CONST_HANDLE const hDevice
462 );
463 
465  ADI_UART_CONST_HANDLE const hDevice
466 );
467 
468 
470  ADI_UART_CONST_HANDLE const hDevice
471 );
472 
474  ADI_UART_HANDLE const hDevice,
475  bool *const pbComplete
476 );
477 
478 /*
479  * Callback functions.
480 */
481 
483  ADI_UART_HANDLE const hDevice,
484  const ADI_CALLBACK pfCallback,
485  void *const pCBParam
486 );
487 
488 #ifdef __cplusplus
489 }
490 #endif /* __cplusplus */
491 
494 #endif /* ADI_UART_H */
ADI_UART_RESULT
Definition: adi_uart.h:107
ADI_UART_RESULT adi_uart_SetTxDmaMode(ADI_UART_HANDLE const hDevice, ADI_DMA_MODE const eMode)
Set the DMA Mode of the UART Tx Channel.
Definition: adi_uart.c:2337
ADI_UART_RESULT adi_uart_Close(ADI_UART_HANDLE const hDevice)
Uninitialize the memory for the specified UART instance.
Definition: adi_uart.c:475
ADI_UART_RESULT adi_uart_SetConfiguration(ADI_UART_HANDLE const hDevice, ADI_UART_PARITY const eParity, ADI_UART_STOPBITS const eStopBits, ADI_UART_WORDLEN const eWordLength)
Configuration of UART data.
Definition: adi_uart.c:2208
ADI_UART_TRIG_LEVEL
Definition: adi_uart.h:205
struct ADI_UART_RX_BUFFER_INFO ADI_UART_RX_BUFFER_INFO
ADI_UART_RESULT adi_uart_IsRxBufferAvailable(ADI_UART_HANDLE const hDevice, bool *const pbAvailable)
Peek function to know if a filled buffer is available.
Definition: adi_uart.c:2056
ADI_UART_RESULT adi_uart_SetRxFifoTriggerLevel(ADI_UART_HANDLE const hDevice, ADI_UART_TRIG_LEVEL const eTriglevel)
Sets the RX FIFO trigger level. This will be the amount of data in the FIFO that will trigger an inte...
Definition: adi_uart.c:2697
ADI_UART_RESULT adi_uart_GetRxBuffer(ADI_UART_HANDLE const hDevice, void **const ppBuffer, uint32_t *pHwError)
Transfer buffer ownership from the device back to the API if the data receive has completed....
Definition: adi_uart.c:1352
ADI_UART_RESULT adi_uart_FlushTxFifo(ADI_UART_CONST_HANDLE const hDevice)
To flush the TX FIFO.
Definition: adi_uart.c:2783
ADI_UART_RESULT adi_uart_SubmitTxBuffer(ADI_UART_HANDLE const hDevice, void *const pBuffer, uint32_t const nBufSize, bool const bDMA)
Submit a "filled" buffer for transmitting data in ADI_UART_DATA_TRANSFER_MODE_NONBLOCKING....
Definition: adi_uart.c:562
ADI_UART_RESULT adi_uart_RegisterCallback(ADI_UART_HANDLE const hDevice, const ADI_CALLBACK pfCallback, void *const pCBParam)
Registering a callback function.
Definition: adi_uart.c:2157
ADI_UART_RESULT adi_uart_FlushRxChannel(ADI_UART_CONST_HANDLE const hDevice)
Flush the Rx channel and disable interrupts. This will stop any buffers in flight and clear out any d...
Definition: adi_uart.c:2845
ADI_UART_RESULT adi_uart_FlushTxChannel(ADI_UART_CONST_HANDLE const hDevice)
Flush the Tx channel and disable interrupts.This will stop any buffers in flight and clear out any da...
Definition: adi_uart.c:2901
ADI_UART_DIRECTION
Definition: adi_uart.h:67
ADI_UART_RESULT adi_uart_SetRxDmaMode(ADI_UART_HANDLE const hDevice, ADI_DMA_MODE const eMode)
Set the DMA Mode of the UART Rx Channel.
Definition: adi_uart.c:2411
ADI_UART_RESULT adi_uart_EnableFifo(ADI_UART_HANDLE const hDevice, bool const bEnable)
Enables internal FIFO as to work in 16550 mode. This helps to minimize system overhead and maximize s...
Definition: adi_uart.c:2732
ADI_UART_RESULT adi_uart_GetTxBuffer(ADI_UART_HANDLE const hDevice, void **const ppBuffer, uint32_t *pHwError)
Transfer buffer ownership from the device back to the API if the data transmit has completed....
Definition: adi_uart.c:1294
ADI_UART_WORDLEN
Definition: adi_uart.h:223
ADI_UART_RESULT adi_uart_SubmitRxBuffer(ADI_UART_HANDLE const hDevice, void *const pBuffer, uint32_t const nBufSize, bool const bDMA)
Submit an empty buffer for receiving the data in ADI_UART_DATA_TRANSFER_MODE_NONBLOCKING....
Definition: adi_uart.c:923
ADI_UART_RESULT adi_uart_Write(ADI_UART_HANDLE const hDevice, void *const pBuffer, uint32_t const nBufSize, bool const bDMA, uint32_t *pHwError)
Submit the buffer for transmitting the data in ADI_UART_DATA_TRANSFER_MODE_BLOCKING....
Definition: adi_uart.c:1490
ADI_DMA_MODE
Definition: adi_dma.h:100
ADI_UART_HW_ERRORS
Definition: adi_uart.h:156
ADI_UART_AUTOBAUD_ERRORS
Definition: adi_uart.h:188
ADI_UART_RESULT adi_uart_FlushRxFifo(ADI_UART_CONST_HANDLE const hDevice)
Flush the RX FIFO.
Definition: adi_uart.c:2813
ADI_UART_RESULT adi_uart_ForceTxBreak(ADI_UART_HANDLE const hDevice, bool const bEnable)
Forces the UART to send out a break signal.
Definition: adi_uart.c:2619
ADI_UART_RESULT adi_uart_Read(ADI_UART_HANDLE const hDevice, void *const pBuffer, uint32_t const nBufSize, bool const bDMA, uint32_t *pHwError)
Submit the buffer for reading the data in ADI_UART_DATA_TRANSFER_MODE_BLOCKING. Call to this function...
Definition: adi_uart.c:1690
ADI_UART_PARITY
Definition: adi_uart.h:240
ADI_UART_RESULT adi_uart_EnableLoopBack(ADI_UART_HANDLE const hDevice, bool const bEnable)
Enable/Disable the loopback for the specified UART device.
Definition: adi_uart.c:2658
ADI_UART_RESULT adi_uart_IsTxBufferAvailable(ADI_UART_HANDLE const hDevice, bool *const pbAvailable)
Peek function to know if an empty buffer is avilable.
Definition: adi_uart.c:2000
ADI_UART_EVENT
Definition: adi_uart.h:83
struct _ADI_UART_DEVICE * ADI_UART_HANDLE
Definition: adi_uart.h:55
ADI_UART_STOPBITS
Definition: adi_uart.h:259
ADI_UART_RESULT adi_uart_Open(uint32_t const nDeviceNum, ADI_UART_DIRECTION const eDirection, void *pMemory, uint32_t const nMemSize, ADI_UART_HANDLE *const phDevice)
Initialization function for the UART device.
Definition: adi_uart.c:284
ADI_UART_TRANSFER_MODE
Definition: adi_uart.h:274
ADI_UART_RESULT adi_uart_GetRX(ADI_UART_HANDLE const hDevice, uint8_t *const pRX)
Read the UART receive buffer register regardless of an error. This mode of reading a byte is done wit...
Definition: adi_uart.c:1878
const struct _ADI_UART_DEVICE * ADI_UART_CONST_HANDLE
Definition: adi_uart.h:60
ADI_UART_RESULT adi_uart_IsTxComplete(ADI_UART_HANDLE const hDevice, bool *const pbComplete)
Function to let the API know if all the data had been drained from the Tx shift registers.
Definition: adi_uart.c:2115
ADI_UART_RESULT adi_uart_ConfigBaudRate(ADI_UART_HANDLE const hDevice, uint16_t const nDivC, uint8_t const nDivM, uint16_t const nDivN, uint8_t const nOSR)
Set baudrate by configuring the fractional dividors.
Definition: adi_uart.c:2270
ADI_UART_RESULT adi_uart_EnableAutobaud(ADI_UART_HANDLE const hDevice, bool const bEnable, bool const bAutobaudCallbackMode)
Enable/Disable UART autobaud detection as well as configures the device for autobaud detection.
Definition: adi_uart.c:2545
ADI_UART_RESULT adi_uart_GetBaudRate(ADI_UART_HANDLE const hDevice, uint32_t *pnBaudRate, uint32_t *pAutobaudError)
Get the baudrate of the UART device instance. This is used in the scenario when a callback has not be...
Definition: adi_uart.c:2476