ADuCM302x Device Drivers API Reference Manual  Release 3.1.2.0
adi_uart.h
1 
46 #ifndef ADI_UART_H
47 #define ADI_UART_H
48 
55 /*============= I N C L U D E S =============*/
56 
57 #include <stdint.h>
58 #include <stddef.h>
59 #include <string.h>
60 #include <assert.h>
61 #include <adi_processor.h>
62 #include <adi_uart_config.h>
63 #include <rtos_map/adi_rtos_map.h>
64 #include <drivers/dma/adi_dma.h>
65 #include <drivers/pwr/adi_pwr.h>
66 
67 #ifdef __cplusplus
68 extern "C" {
69 #endif /* __cplusplus */
70 
76 #define ADI_UART_UNIDIR_MEMORY_SIZE (48u + (60u + ADI_SEM_SIZE))
77 
81 #define ADI_UART_BIDIR_MEMORY_SIZE (48u + (60u + ADI_SEM_SIZE)*2u)
82 
86 typedef struct _ADI_UART_DEVICE* ADI_UART_HANDLE;
87 
91 typedef const struct _ADI_UART_DEVICE* ADI_UART_CONST_HANDLE;
92 
98 typedef enum
99 {
107 
108 
114  typedef enum
115 {
129 
130 
138  typedef enum
139 {
140 
179 
187 typedef enum
188 {
212 
219 typedef enum
220 {
230 
236 typedef enum
237 {
238 
239  ADI_UART_RX_FIFO_TRIG_LEVEL_1BYTE = 0 << BITP_UART_FCR_RFTRIG,
241  ADI_UART_RX_FIFO_TRIG_LEVEL_4BYTE = 1 << BITP_UART_FCR_RFTRIG,
243  ADI_UART_RX_FIFO_TRIG_LEVEL_8BYTE = 2 << BITP_UART_FCR_RFTRIG,
245  ADI_UART_RX_FIFO_TRIG_LEVEL_14BYTE = 3 << BITP_UART_FCR_RFTRIG
248 
254 typedef enum
255 {
265 
271 typedef enum
272 {
284 
290 typedef enum
291 {
292 
293  ADI_UART_ONE_STOPBIT = 0x00,
299 
305 typedef enum
306 {
307 
308  ADI_UART_DATA_TRANSFER_MODE_NONE,
317 
318 
319 /******************************************************************************
320  * UART Device external API function prototypes
321  *****************************************************************************/
322 
323 /*
324  * Device initialization and uninitialization interfaces.
325 */
326 ADI_UART_RESULT adi_uart_Open(
327  uint32_t const nDeviceNum,
328  ADI_UART_DIRECTION const eDirection,
329  void *pMemory,
330  uint32_t const nMemSize,
331  ADI_UART_HANDLE *const phDevice
332 );
333 
334 ADI_UART_RESULT adi_uart_Close(
335  ADI_UART_HANDLE const hDevice
336 );
337 
338 
339 /******************************************************************************
340  * Eliminatable functions that may be optimized out by the linker
341  *****************************************************************************/
342 
343 /*
344  * Non-blocking mode functions.
345 */
346 
347 ADI_UART_RESULT adi_uart_SubmitTxBuffer(
348  ADI_UART_HANDLE const hDevice,
349  void *const pBuffer,
350  uint32_t const nBufSize,
351  bool const bDMA
352 );
353 
354 ADI_UART_RESULT adi_uart_SubmitRxBuffer(
355  ADI_UART_HANDLE const hDevice,
356  void *const pBuffer,
357  uint32_t const nBufSize,
358  bool const bDMA
359 );
360 
361 ADI_UART_RESULT adi_uart_GetTxBuffer(
362  ADI_UART_HANDLE const hDevice,
363  void **const ppBuffer,
364  uint32_t *pHwError
365 );
366 
367 ADI_UART_RESULT adi_uart_GetRxBuffer(
368  ADI_UART_HANDLE const hDevice,
369  void **const ppBuffer,
370  uint32_t *pHwError
371 );
372 ADI_UART_RESULT adi_uart_IsTxBufferAvailable(
373  ADI_UART_HANDLE const hDevice,
374  bool *const pbAvailable
375 );
376 
377 ADI_UART_RESULT adi_uart_IsRxBufferAvailable(
378  ADI_UART_HANDLE const hDevice,
379  bool *const pbAvailable
380 );
381 
382 /*
383  * Blocking mode functions.
384 */
385 
386 ADI_UART_RESULT adi_uart_Write(
387  ADI_UART_HANDLE const hDevice,
388  void *const pBuffer,
389  uint32_t const nBufSize,
390  bool const bDMA,
391  uint32_t *pHwError
392 );
393 
394 ADI_UART_RESULT adi_uart_Read(
395  ADI_UART_HANDLE const hDevice,
396  void *const pBuffer,
397  uint32_t const nBufSize,
398  bool const bDMA,
399  uint32_t *pHwError
400 );
401 
402 
403 /*
404  * Configuration interface functions.
405 */
406 
407 ADI_UART_RESULT adi_uart_EnableLoopBack(
408  ADI_UART_HANDLE const hDevice,
409  bool const bEnable
410 );
411 
412 ADI_UART_RESULT adi_uart_EnableAutobaud(
413  ADI_UART_HANDLE const hDevice,
414  bool const bEnable,
415  bool const bAutobaudCallbackMode
416 );
417 
418 ADI_UART_RESULT adi_uart_SetRxFifoTriggerLevel(
419  ADI_UART_HANDLE const hDevice,
420  ADI_UART_TRIG_LEVEL const eTriglevel
421 );
422 
423 ADI_UART_RESULT adi_uart_EnableFifo(
424  ADI_UART_HANDLE const hDevice,
425  bool const bEnable
426 );
427 
428 ADI_UART_RESULT adi_uart_GetBaudRate(
429  ADI_UART_HANDLE const hDevice,
430  uint32_t *pnBaudRate,
431  uint32_t *pAutobaudError
432 );
433 
434 ADI_UART_RESULT adi_uart_ForceTxBreak(
435  ADI_UART_HANDLE const hDevice,
436  bool const bEnable
437 );
438 
439 ADI_UART_RESULT adi_uart_SetConfiguration(
440  ADI_UART_HANDLE const hDevice,
441  ADI_UART_PARITY const eParity,
442  ADI_UART_STOPBITS const eStopBits,
443  ADI_UART_WORDLEN const eWordLength
444 );
445 
446 ADI_UART_RESULT adi_uart_ConfigBaudRate(
447  ADI_UART_HANDLE const hDevice,
448  uint16_t const nDivC,
449  uint8_t const nDivM,
450  uint16_t const nDivN,
451  uint8_t const nOSR
452 );
453 
454 /*
455  * Channel data control functions.
456 */
457 
458 ADI_UART_RESULT adi_uart_FlushTxFifo(
459  ADI_UART_CONST_HANDLE const hDevice
460 );
461 
462 ADI_UART_RESULT adi_uart_FlushRxFifo(
463  ADI_UART_CONST_HANDLE const hDevice
464 );
465 
466 ADI_UART_RESULT adi_uart_FlushRxChannel(
467  ADI_UART_CONST_HANDLE const hDevice
468 );
469 
470 
471 ADI_UART_RESULT adi_uart_FlushTxChannel(
472  ADI_UART_CONST_HANDLE const hDevice
473 );
474 
475 ADI_UART_RESULT adi_uart_IsTxComplete(
476  ADI_UART_HANDLE const hDevice,
477  bool *const pbComplete
478 );
479 
480 /*
481  * Callback functions.
482 */
483 
484 ADI_UART_RESULT adi_uart_RegisterCallback(
485  ADI_UART_HANDLE const hDevice,
486  const ADI_CALLBACK pfCallback,
487  void *const pCBParam
488 );
489 
490 #ifdef __cplusplus
491 }
492 #endif /* __cplusplus */
493 
496 #endif /* ADI_UART_H */
497 
498 
ADI_UART_RESULT
Definition: adi_uart.h:138
ADI_UART_RESULT adi_uart_Close(ADI_UART_HANDLE const hDevice)
Uninitialize the memory for the specified UART instance.
Definition: adi_uart.c:507
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:1689
ADI_UART_TRIG_LEVEL
Definition: adi_uart.h:236
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:1537
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:2028
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:1028
ADI_UART_RESULT adi_uart_FlushTxFifo(ADI_UART_CONST_HANDLE const hDevice)
To flush the TX FIFO.
Definition: adi_uart.c:2108
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. This function sets up the apropriate interrupts associated with the transaction and marks the buffer as submitted.
Definition: adi_uart.c:594
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:1638
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:2170
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:2221
ADI_UART_DIRECTION
Definition: adi_uart.h:98
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:2063
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:970
ADI_UART_WORDLEN
Definition: adi_uart.h:254
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. This will set up the Rx channel for notification on incoming data using either the DMA or UART interrupts, as well as mark the buffer as submitted.
Definition: adi_uart.c:784
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. Call to this function will not return until the entire buffer is transmitted. Returns error if this function is called when device is operating in ADI_UART_DATA_TRANSFER_MODE_NONBLOCKING. i.e Function "adi_uart_SubmitTxBuffer()" is called and the transfer is not yet complete.
Definition: adi_uart.c:1166
ADI_UART_HW_ERRORS
Definition: adi_uart.h:187
ADI_UART_AUTOBAUD_ERRORS
Definition: adi_uart.h:219
ADI_UART_RESULT adi_uart_FlushRxFifo(ADI_UART_CONST_HANDLE const hDevice)
Flush the RX FIFO.
Definition: adi_uart.c:2138
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:1950
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:1298
ADI_UART_PARITY
Definition: adi_uart.h:271
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:1989
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:1481
ADI_UART_EVENT
Definition: adi_uart.h:114
struct _ADI_UART_DEVICE * ADI_UART_HANDLE
Definition: adi_uart.h:86
ADI_UART_STOPBITS
Definition: adi_uart.h:290
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:315
ADI_UART_TRANSFER_MODE
Definition: adi_uart.h:305
const struct _ADI_UART_DEVICE * ADI_UART_CONST_HANDLE
Definition: adi_uart.h:91
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:1596
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:1751
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:1878
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:1809