PDK API Guide for J721E
UART.h File Reference

Introduction

UART driver interface.

============================================================================

The UART header file should be included in an application as follows:

Operation

The UART driver simplifies reading and writing to any of the UART peripherals on the board with multiple modes of operation and performance. These include blocking, non-blocking, and polling as well as text/binary mode, echo and return characters. The boards UART peripheral and pins must be configured before initializing the UART driver. The application initializes the UART driver by calling UART_init() and is then ready to open a UART by calling UART_open() and passing in a UART parameters data structure.

The APIs in this driver serve as an interface to a typical TI-RTOS application. The specific peripheral implementations are responsible to create all the OS specific primitives to allow for thread-safe operation.

Opening the driver

UART_Handle handle;
UART_Params params;
params.baudRate = someNewBaudRate;
handle = UART_open(someUART_configIndexValue, &params);
if (!handle) {
System_printf("UART did not open");
}

Writing data

const unsigned char hello[] = "Hello World\n";
ret = UART_write(handle, hello, sizeof(hello));
System_printf("The UART wrote %d bytes\n", ret);

Reading data

unsigned char rxBuffer[20];
ret = UART_read(handle, rxBuffer, sizeof(rxBuffer));
System_printf("The UART read %d bytes\n", ret);

Implementation

This module serves as the main interface for TI-RTOS applications. Its purpose is to redirect the module's APIs to specific peripheral implementations which are specified using a pointer to a UART_FxnTable.

The UART driver interface module is joined (at link time) to a NULL-terminated array of UART_Config data structures named UART_config. UART_config is implemented in the application with each entry being an instance of a UART peripheral. Each entry in UART_config contains a:

  • (UART_FxnTable *) to a set of functions that implement a UART peripheral
  • (void *) data object that is associated with the UART_FxnTable
  • (void *) hardware attributes that are associated to the UART_FxnTable

Go to the source code of this file.

Data Structures

struct  UART_Transaction
 A UART_Transaction data structure is used with UART_read2(), UART_write2() and UART_Callback2() More...
 
struct  UART_Params
 Basic UART Parameters. More...
 
struct  UART_FxnTable
 The definition of a UART function table that contains the required set of functions to control a specific UART driver implementation. More...
 
struct  UART_Config
 UART Global configuration. More...
 

Macros

#define UART_SUCCESS   ((int32_t)(0))
 
#define UART_ERROR   (-((int32_t)1))
 
#define UART_ERRNO_BASE   (0)
 UART driver error base. More...
 
#define UART_EINVAL   (UART_ERRNO_BASE-1)
 Error Code: Invalid argument. More...
 
#define UART_EINUSE   (UART_ERRNO_BASE-2)
 Error Code: Operation cannot be implemented because a previous operation is still not complete. More...
 
#define UART_ENOTIMPL   (UART_ERRNO_BASE-3)
 Error Code: Operation is not implemented. More...
 
#define UART_NO_WAIT   ((uint32_t)0U)
 UART transaction timeout define. More...
 
#define UART_WAIT_FOREVER   (~((uint32_t)0U))
 
#define UART_MAX_CONFIG_CNT   (14U)
 

Typedefs

typedef struct UART_Config_s * UART_Handle
 A handle that is returned from a UART_open() call. More...
 
typedef void(* UART_Callback) (UART_Handle handle, void *buf, size_t count)
 The definition of a callback function used by the UART driver when used in UART_MODE_CALLBACK. More...
 
typedef void(* UART_Callback2) (UART_Handle handle, UART_Transaction *transaction)
 The definition of a callback2 function used by the UART driver when used in UART_MODE_CALLBACK. More...
 
typedef void(* UART_CloseFxn) (UART_Handle handle)
 A function pointer to a driver specific implementation of UART_CloseFxn(). More...
 
typedef int32_t(* UART_ControlFxn) (UART_Handle handle, uint32_t cmd, void *arg)
 A function pointer to a driver specific implementation of UART_ControlFxn(). More...
 
typedef void(* UART_InitFxn) (UART_Handle handle)
 A function pointer to a driver specific implementation of UART_InitFxn(). More...
 
typedef UART_Handle(* UART_OpenFxn) (UART_Handle handle, const UART_Params *params)
 A function pointer to a driver specific implementation of UART_OpenFxn(). More...
 
typedef int32_t(* UART_ReadFxn) (UART_Handle handle, void *buffer, size_t size)
 A function pointer to a driver specific implementation of UART_ReadFxn(). More...
 
typedef int32_t(* UART_ReadPollingFxn) (UART_Handle handle, void *buffer, size_t size)
 A function pointer to a driver specific implementation of UART_ReadPollingFxn(). More...
 
typedef void(* UART_ReadCancelFxn) (UART_Handle handle)
 A function pointer to a driver specific implementation of UART_ReadCancelFxn(). More...
 
typedef int32_t(* UART_WriteFxn) (UART_Handle handle, const void *buffer, size_t size)
 A function pointer to a driver specific implementation of UART_CloseFxn(). More...
 
typedef int32_t(* UART_WritePollingFxn) (UART_Handle handle, const void *buffer, size_t size)
 A function pointer to a driver specific implementation of UART_WritePollingFxn(). More...
 
typedef void(* UART_WriteCancelFxn) (UART_Handle handle)
 A function pointer to a driver specific implementation of UART_WriteCancelFxn(). More...
 
typedef int32_t(* UART_ReadFxn2) (UART_Handle handle, UART_Transaction *transaction)
 A function pointer to a driver specific implementation of UART_ReadFxn2(). More...
 
typedef int32_t(* UART_WriteFxn2) (UART_Handle handle, UART_Transaction *transaction)
 A function pointer to a driver specific implementation of UART_WriteFxn2(). More...
 
typedef UART_Config UART_config_list[UART_MAX_CONFIG_CNT]
 

Enumerations

enum  UART_TransferApiVer { UART_TRANSFER_API_VER_1 = 1, UART_TRANSFER_API_VER_2 = 2 }
 Transfer API version. More...
 
enum  UART_TransferStatus {
  UART_TRANSFER_STATUS_SUCCESS = 0, UART_TRANSFER_STATUS_TIMEOUT, UART_TRANSFER_STATUS_ERROR_BI, UART_TRANSFER_STATUS_ERROR_FE,
  UART_TRANSFER_STATUS_ERROR_PE, UART_TRANSFER_STATUS_ERROR_OE, UART_TRANSFER_STATUS_ERROR_OTH
}
 Transfer status codes that are set by the UART driver. More...
 
enum  UART_Mode { UART_MODE_BLOCKING, UART_MODE_CALLBACK }
 UART mode settings. More...
 
enum  UART_ReturnMode { UART_RETURN_FULL, UART_RETURN_NEWLINE }
 UART return mode settings. More...
 
enum  UART_DataMode { UART_DATA_BINARY, UART_DATA_TEXT }
 UART data mode settings. More...
 
enum  UART_Echo { UART_ECHO_OFF = 0, UART_ECHO_ON = 1 }
 UART echo settings. More...
 
enum  UART_LEN { UART_LEN_5 = 0, UART_LEN_6 = 1, UART_LEN_7 = 2, UART_LEN_8 = 3 }
 UART data length settings. More...
 
enum  UART_STOP { UART_STOP_ONE = 0, UART_STOP_TWO = 1 }
 UART stop bit settings. More...
 
enum  UART_PAR {
  UART_PAR_NONE = 0, UART_PAR_EVEN = 1, UART_PAR_ODD = 2, UART_PAR_ZERO = 3,
  UART_PAR_ONE = 4
}
 UART parity type settings. More...
 
enum  UART_FC_TYPE { UART_FC_NONE = 0, UART_FC_HW = 1 }
 UART flow control settings. More...
 

Functions

void UART_close (UART_Handle uartHnd)
 Function to closes a given UART peripheral specified by the UART handle. More...
 
int32_t UART_control (UART_Handle uartHnd, uint32_t cmd, void *arg)
 Function performs implementation specific features on a given UART_Handle. More...
 
void UART_init (void)
 Function to initializes the UART module. More...
 
UART_Handle UART_open (uint32_t idx, UART_Params *uartParams)
 Function to initialize a given UART peripheral specified by the particular index value. The parameter specifies which mode the UART will operate. More...
 
void UART_Params_init (UART_Params *uartParams)
 Function to initialize the UART_Params struct to its defaults. More...
 
int32_t UART_write (UART_Handle uartHnd, const void *buffer, size_t size)
 Function that writes data to a UART. More...
 
int32_t UART_writePolling (UART_Handle uartHnd, const void *buffer, size_t size)
 Function that writes data to a UART. More...
 
void UART_writeCancel (UART_Handle handle)
 Function that cancels a UART_write function call. More...
 
int32_t UART_read (UART_Handle handle, void *buffer, size_t size)
 Function that read data from a UART. More...
 
int32_t UART_readPolling (UART_Handle handle, void *buffer, size_t size)
 Function that reads data from a UART. More...
 
void UART_readCancel (UART_Handle handle)
 Function that cancels a UART_read function call. More...
 
int32_t UART_read2 (UART_Handle handle, UART_Transaction *uartTrans)
 Extended function that read data from a UART. More...
 
int32_t UART_write2 (UART_Handle handle, UART_Transaction *uartTrans)
 Extended function that writes data to a UART. More...
 
void UART_transactionInit (UART_Transaction *uartTrans)
 Function to initialize the UART_Transaction struct to its defaults. More...