EFR32 Mighty Gecko 1 Software Documentation  efr32mg1-doc-5.1.2
UARTDRV

Detailed Description

UARTDRV Universal Asynchronous Receiver/Transmitter Driver.

The source files for the UART driver library resides in the emdrv/uartdrv folder, and are named uartdrv.c and uartdrv.h.


Introduction

The UART driver support the UART capabilities of the USART, UART and LEUART peripherals. The driver is fully reentrant and multiple driver instances can coexist. The driver does not buffer or queue data, but it queues UART transmit and receive operations. Both blocking and non-blocking transfer functions are available. Non-blocking transfer functions report transfer completion with callback functions. Transfers are done using DMA. Simple direct/forced transmit and receive functions are also available. Note that these functions are blocking and not suitable for low energy applications as they use CPU polling.

UART hardware flow control (CTS/RTS) is fully supported by the driver. UART software flow control (XON/XOFF) is partially supported by the driver. Read more about flow control support in Flow Control Support.

Note
Transfer completion callback functions are called from within the DMA interrupt handler with interrupts disabled.


Configuration Options

Some properties of the UARTDRV driver are compile-time configurable. These properties are set in a file named uartdrv_config.h. A template for this file, containing default values, resides in the emdrv/config folder. To configure UARTDRV for your application, provide your own configuration file, or override the defines on the compiler command line. These are the available configuration parameters with default values defined.

// Size of the receive operation queue
#define EMDRV_UARTDRV_MAX_CONCURRENT_RX_BUFS 6
// Size of the transmit operation queue
#define EMDRV_UARTDRV_MAX_CONCURRENT_TX_BUFS 6
// Set to 1 to enable hardware flow control
#define EMDRV_UARTDRV_FLOW_CONTROL_ENABLE 1
// Maximum number of driver instances.
// This maximum applies only when EMDRV_UARTDRV_FLOW_CONTROL_ENABLE = 1
#define EMDRV_UARTDRV_MAX_DRIVER_INSTANCES 4
// UART software flow control code: request peer to start TX
#define UARTDRV_FC_SW_XON 0x11
// UART software flow control code: request peer to stop TX
#define UARTDRV_FC_SW_XOFF 0x13

The properties of each UART driver instance are set at run-time via the UARTDRV_InitUart_t data structure input parameter to the UARTDRV_InitUart() function for UART and USART peripherals, and the UARTDRV_InitLeuart_t data structure input parameter to the UARTDRV_InitLeuart() function for LEUART peripherals.


The API

This section contain brief descriptions of the functions in the API. You will find detailed information on input and output parameters and return values by clicking on the hyperlinked function names. Most functions return an error code, ECODE_EMDRV_UARTDRV_OK is returned on success, see ecode.h and uartdrv.h for other error codes.

Your application code must include one header file: uartdrv.h.

UARTDRV_InitUart(), UARTDRV_InitLeuart() and UARTDRV_DeInit()
These functions initialize and deinitialize the UARTDRV driver. Typically UARTDRV_InitUart() (for UART/USART) or UARTDRV_InitLeuart() (for LEUART) are called once in your startup code.

UARTDRV_GetReceiveStatus() and UARTDRV_GetTransmitStatus()
Query the status of a current transmit or receive operations. Reports number of items (frames) transmitted and remaining.

UARTDRV_GetReceiveDepth() and UARTDRV_GetTransmitDepth()
Get the number of queued receive or transmit operations.

UARTDRV_Transmit(), UARTDRV_Receive()
UARTDRV_TransmitB(), UARTDRV_ReceiveB()
UARTDRV_ForceTransmit() and UARTDRV_ForceReceive()
Transfer functions come in both blocking and non-blocking versions, the blocking versions have an uppercase B (for Blocking) at the end of their function name. Blocking functions will not return before the transfer has completed. The non-blocking functions signal transfer completion with a callback function. UARTDRV_ForceTransmit() and UARTDRV_ForceReceive() are also blocking. These two functions access the UART peripheral directly without using DMA or interrupts. UARTDRV_ForceTransmit() does not respect flow control. UARTDRV_ForceReceive() forces RTS low.

UARTDRV_Abort()
Abort current transmit or receive operations, and remove all queued operations.

UARTDRV_FlowControlSet(), UARTDRV_FlowControlGetSelfStatus(), UARTDRV_FlowControlSetPeerStatus() and UARTDRV_FlowControlGetPeerStatus()
Set and get flow control status of self or peer device. Note that the return value from these two functions depends on the flow control mode set by UARTDRV_FlowControlSet(), UARTDRV_InitUart() or UARTDRV_InitLeuart().

UARTDRV_FlowControlIgnoreRestrain()
Enables transmission when restrained by flow control.

UARTDRV_PauseTransmit() and UARTDRV_ResumeTransmit()
Pause a currently active transmit operation by preventing the DMA from loading the UART fifo. Will not override HW flow control state (if applicable), but can be used in conjunction.


Flow Control Support

If UART flow control is not required, make sure EMDRV_UARTDRV_FLOW_CONTROL_ENABLE is set to 0. This reduces the code size and complexity of the driver.

There are two types of flow control supported, hardware and software. To enable any of these, set EMDRV_UARTDRV_FLOW_CONTROL_ENABLE to 1 in uartdrv_config.h.


Hardware Flow Control

UART hardware flow control uses two additional pins for flow control handshaking, the clear-to-send (CTS) and ready-to-send (RTS) pins. RTS is an output and CTS is an input. These are active low signals. When CTS is high, the UART transmitter should stop sending frames. A receiver should set RTS high when it is no longer capable of receiving data.

Peripheral Hardware Flow Control

Newer devices, such as EFR32MG1 and EFM32PG1, natively support CTS/RTS in the USART peripheral hardware. To enable hardware flow control, perform the following steps:

GPIO Hardware Flow Control

To support hardware flow control on devices that don't have UART CTS/RTS hardware support, the driver includes the GPIOINT driver to emulate a hardware implementation of UART CTS/RTS flow control on these devices.

To enable hardware flow control, perform the following steps:

Note
Because of the limitations in GPIO interrupt hardware, you cannot select CTS pins in multiple driver instances with the same pin number. Ie. pin A0 and B0 cannot serve as CTS pins in two concurrent driver instances.

RTS is set high whenever there are no RX operations queued. The UART transmitter is halted when the CTS pin goes high. The transmitter completes the current frame before halting. DMA transfers are also halted.


Software Flow Control

UART software flow control uses in-band signaling, meaning the receiver sends special flow control characters to the transmitter and thereby removes the need for dedicated wires for flow control. The two symbols UARTDRV_FC_SW_XON and UARTDRV_FC_SW_XOFF are defined in uartdrv_config.h.

To enable support for software flow control, perform the following steps:

Note
Software flow control is partial only.

The application must monitor buffers and make decisions on when to send XON/ XOFF. XON/XOFF can be sent to the peer using UARTDRV_FlowControlSet(). Though UARTDRV_FlowControlSet() will pause the active transmit operation to send a flow control character, there is no way to guarantee the order. If the application implements a specific packet format where the flow control codes may appear only in fixed positions, then the application should not use UARTDRV_FlowControlSet(), but implement read and write of XON/XOFF into packet buffers. If the application code fully implements all the flow control logic, then EMDRV_UARTDRV_FLOW_CONTROL_ENABLE should be set to 0 to reduce code space.


Example

#include "uartdrv.h"
// Define receive/transmit operation queues
DEFINE_BUF_QUEUE(EMDRV_UARTDRV_MAX_CONCURRENT_RX_BUFS, rxBufferQueue);
DEFINE_BUF_QUEUE(EMDRV_UARTDRV_MAX_CONCURRENT_TX_BUFS, txBufferQueue);
// Configuration for USART0, location 11
#define MY_UART \
{ \
USART0, \
115200, \
_USART_ROUTELOC0_TXLOC_LOC11, \
_USART_ROUTELOC0_RXLOC_LOC11, \
usartStopbits1, \
usartNoParity, \
usartOVS16, \
false, \
uartdrvFlowControlHwUart, \
gpioPortA, \
4, \
gpioPortA, \
5, \
(UARTDRV_Buffer_FifoQueue_t *)&rxBufferQueue, \
(UARTDRV_Buffer_FifoQueue_t *)&txBufferQueue, \
_USART_ROUTELOC1_CTSLOC_LOC11, \
_USART_ROUTELOC1_RTSLOC_LOC11 \
}
UARTDRV_Handle_t handle = &handleData;
uint8_t buffer[64];
void callback(UARTDRV_Handle_t handle,
Ecode_t transferStatus,
uint8_t *data,
UARTDRV_Count_t transferCount)
{
(void)handle;
(void)transferStatus;
(void)data;
(void)transferCount;
}
void uartdrv_example(void)
{
// Initialize driver handle
UARTDRV_InitUart_t initData = MY_UART;
UARTDRV_InitUart(handle, &initData);
// Transmit data using a non-blocking transmit function
UARTDRV_Transmit(handle, buffer, 64, callback);
}

Data Structures

struct  UARTDRV_Buffer_FifoQueue_t
 Transfer operation FIFO queue typedef. More...
 
struct  UARTDRV_Buffer_t
 UART transfer buffer. More...
 
struct  UARTDRV_HandleData
 
struct  UARTDRV_InitLeuart_t
 
struct  UARTDRV_InitUart_t
 

Macros

#define DEFINE_BUF_QUEUE(qSize, qName)
 
#define ECODE_EMDRV_UARTDRV_ABORTED   (ECODE_EMDRV_UARTDRV_BASE | 0x00000009)
 UART transfer has been aborted.
 
#define ECODE_EMDRV_UARTDRV_BUSY   (ECODE_EMDRV_UARTDRV_BASE | 0x00000004)
 The UART port is busy.
 
#define ECODE_EMDRV_UARTDRV_CLOCK_ERROR   (ECODE_EMDRV_UARTDRV_BASE | 0x0000000F)
 Unable to set desired baudrate.
 
#define ECODE_EMDRV_UARTDRV_DMA_ALLOC_ERROR   (ECODE_EMDRV_UARTDRV_BASE | 0x0000000E)
 Unable to allocated DMA channels.
 
#define ECODE_EMDRV_UARTDRV_FRAME_ERROR   (ECODE_EMDRV_UARTDRV_BASE | 0x0000000D)
 UART frame error. Data is ignored.
 
#define ECODE_EMDRV_UARTDRV_IDLE   (ECODE_EMDRV_UARTDRV_BASE | 0x00000008)
 No UART transfer in progress.
 
#define ECODE_EMDRV_UARTDRV_ILLEGAL_HANDLE   (ECODE_EMDRV_UARTDRV_BASE | 0x00000002)
 Illegal UART handle.
 
#define ECODE_EMDRV_UARTDRV_ILLEGAL_OPERATION   (ECODE_EMDRV_UARTDRV_BASE | 0x00000005)
 Illegal operation on UART port.
 
#define ECODE_EMDRV_UARTDRV_OK   (ECODE_OK)
 Success return value.
 
#define ECODE_EMDRV_UARTDRV_PARAM_ERROR   (ECODE_EMDRV_UARTDRV_BASE | 0x00000003)
 Illegal input parameter.
 
#define ECODE_EMDRV_UARTDRV_PARITY_ERROR   (ECODE_EMDRV_UARTDRV_BASE | 0x0000000C)
 UART parity error frame. Data is ignored.
 
#define ECODE_EMDRV_UARTDRV_QUEUE_EMPTY   (ECODE_EMDRV_UARTDRV_BASE | 0x0000000B)
 UART operation queue is empty.
 
#define ECODE_EMDRV_UARTDRV_QUEUE_FULL   (ECODE_EMDRV_UARTDRV_BASE | 0x0000000A)
 UART operation queue is full.
 
#define ECODE_EMDRV_UARTDRV_WAITING   (ECODE_EMDRV_UARTDRV_BASE | 0x00000001)
 Operation is waiting in queue.
 
#define UARTDRV_STATUS_RXBLOCK   (1 << 3)
 Receiver is blocked; incoming frames will be discarded.
 
#define UARTDRV_STATUS_RXDATAV   (1 << 7)
 Data is available in receive buffer.
 
#define UARTDRV_STATUS_RXEN   (1 << 0)
 Receiver is enabled.
 
#define UARTDRV_STATUS_RXFULL   (1 << 8)
 Receive buffer is full.
 
#define UARTDRV_STATUS_TXBL   (1 << 6)
 Transmit buffer is empty.
 
#define UARTDRV_STATUS_TXC   (1 << 5)
 Transmit operation is complete, no more data is available in the transmit buffer and shift register.
 
#define UARTDRV_STATUS_TXEN   (1 << 1)
 Transmitter is enabled.
 
#define UARTDRV_STATUS_TXIDLE   (1 << 13)
 Transmitter is idle.
 
#define UARTDRV_STATUS_TXTRI   (1 << 4)
 Transmitter is tristated.
 

Typedefs

typedef enum UARTDRV_AbortType UARTDRV_AbortType_t
 Transfer abort type.
 
typedef void(* UARTDRV_Callback_t) (struct UARTDRV_HandleData *handle, Ecode_t transferStatus, uint8_t *data, UARTDRV_Count_t transferCount)
 UARTDRV transfer completion callback function. More...
 
typedef uint32_t UARTDRV_Count_t
 UART transfer count.
 
typedef enum UARTDRV_FlowControlState UARTDRV_FlowControlState_t
 Flow Control state.
 
typedef enum UARTDRV_FlowControlType UARTDRV_FlowControlType_t
 Flow Control method.
 
typedef UARTDRV_HandleData_tUARTDRV_Handle_t
 Handle pointer.
 
typedef struct UARTDRV_HandleData UARTDRV_HandleData_t
 
typedef uint32_t UARTDRV_Status_t
 UART status return type. Bitfield of UARTDRV_STATUS_* values.
 

Enumerations

enum  UARTDRV_AbortType {
  uartdrvAbortTransmit = 1,
  uartdrvAbortReceive = 2,
  uartdrvAbortAll = 3
}
 Transfer abort type. More...
 
enum  UARTDRV_FlowControlState {
  uartdrvFlowControlOn = 0,
  uartdrvFlowControlOff = 1,
  uartdrvFlowControlAuto = 2
}
 Flow Control state. More...
 
enum  UARTDRV_FlowControlType {
  uartdrvFlowControlNone = 0,
  uartdrvFlowControlSw = 1,
  uartdrvFlowControlHw = 2,
  uartdrvFlowControlHwUart = 3
}
 Flow Control method. More...
 

Functions

Ecode_t UARTDRV_Abort (UARTDRV_Handle_t handle, UARTDRV_AbortType_t type)
 Abort ongoing UART transfers. More...
 
Ecode_t UARTDRV_DeInit (UARTDRV_Handle_t handle)
 Deinitialize a UART driver instance. More...
 
UARTDRV_FlowControlState_t UARTDRV_FlowControlGetPeerStatus (UARTDRV_Handle_t handle)
 Checks the peer's flow control status. More...
 
UARTDRV_FlowControlState_t UARTDRV_FlowControlGetSelfStatus (UARTDRV_Handle_t handle)
 Checks the self's flow control status. More...
 
Ecode_t UARTDRV_FlowControlIgnoreRestrain (UARTDRV_Handle_t handle)
 Enables transmission when restrained by flow control. More...
 
Ecode_t UARTDRV_FlowControlSet (UARTDRV_Handle_t handle, UARTDRV_FlowControlState_t state)
 Set UART flow control state. Set nRTS pin if hardware flow control is enabled. Send XON/XOFF if software flow control is enabled. More...
 
Ecode_t UARTDRV_FlowControlSetPeerStatus (UARTDRV_Handle_t handle, UARTDRV_FlowControlState_t state)
 Set peer UART flow control state. Pause/resume transmit accordingly. Only for manual software flow control. More...
 
UARTDRV_Count_t UARTDRV_ForceReceive (UARTDRV_Handle_t handle, uint8_t *data, UARTDRV_Count_t maxLength)
 Direct receive without interrupts or callback. Blocking function. More...
 
Ecode_t UARTDRV_ForceTransmit (UARTDRV_Handle_t handle, uint8_t *data, UARTDRV_Count_t count)
 Direct transmit without interrupts or callback. Blocking function that ignores flow control if enabled. More...
 
UARTDRV_Status_t UARTDRV_GetPeripheralStatus (UARTDRV_Handle_t handle)
 Returns the status of the UART peripheral associated with a given handle. More...
 
uint8_t UARTDRV_GetReceiveDepth (UARTDRV_Handle_t handle)
 Returns the number of queued receive operations. More...
 
UARTDRV_Status_t UARTDRV_GetReceiveStatus (UARTDRV_Handle_t handle, uint8_t **buffer, UARTDRV_Count_t *bytesReceived, UARTDRV_Count_t *bytesRemaining)
 Check the status of the UART and gather information about any ongoing receive operations. More...
 
uint8_t UARTDRV_GetTransmitDepth (UARTDRV_Handle_t handle)
 Returns the number of queued transmit operations. More...
 
UARTDRV_Status_t UARTDRV_GetTransmitStatus (UARTDRV_Handle_t handle, uint8_t **buffer, UARTDRV_Count_t *bytesSent, UARTDRV_Count_t *bytesRemaining)
 Check the status of the UART and gather information about any ongoing transmit operations. More...
 
__STATIC_INLINE Ecode_t UARTDRV_Init (UARTDRV_Handle_t handle, UARTDRV_InitUart_t *initData)
 Initialize a U(S)ART driver instance. More...
 
Ecode_t UARTDRV_InitLeuart (UARTDRV_Handle_t handle, const UARTDRV_InitLeuart_t *initData)
 Initialize a LEUART driver instance. More...
 
Ecode_t UARTDRV_InitUart (UARTDRV_Handle_t handle, const UARTDRV_InitUart_t *initData)
 Initialize a U(S)ART driver instance. More...
 
Ecode_t UARTDRV_PauseTransmit (UARTDRV_Handle_t handle)
 Pause an ongoing transmit operation. More...
 
Ecode_t UARTDRV_Receive (UARTDRV_Handle_t handle, uint8_t *data, UARTDRV_Count_t count, UARTDRV_Callback_t callback)
 Start a non-blocking receive. More...
 
Ecode_t UARTDRV_ReceiveB (UARTDRV_Handle_t handle, uint8_t *data, UARTDRV_Count_t count)
 Start a blocking receive. More...
 
Ecode_t UARTDRV_ResumeTransmit (UARTDRV_Handle_t handle)
 Resume a paused transmit operation. More...
 
Ecode_t UARTDRV_Transmit (UARTDRV_Handle_t handle, uint8_t *data, UARTDRV_Count_t count, UARTDRV_Callback_t callback)
 Start a non-blocking transmit. More...
 
Ecode_t UARTDRV_TransmitB (UARTDRV_Handle_t handle, uint8_t *data, UARTDRV_Count_t count)
 Start a blocking transmit. More...
 

Macro Definition Documentation

#define DEFINE_BUF_QUEUE (   qSize,
  qName 
)
Value:
typedef struct { \
uint16_t head; \
uint16_t tail; \
volatile uint16_t used; \
const uint16_t size; \
UARTDRV_Buffer_t fifo[qSize]; \
} _##qName; \
static volatile _##qName qName = \
{ \
.head = 0, \
.tail = 0, \
.used = 0, \
.size = qSize, \
}

Macros to define fifo and buffer queues, can't use a typedef becuase the size of the fifo array in the queues can change.

Definition at line 154 of file uartdrv.h.

Typedef Documentation

typedef void(* UARTDRV_Callback_t) (struct UARTDRV_HandleData *handle, Ecode_t transferStatus, uint8_t *data, UARTDRV_Count_t transferCount)

UARTDRV transfer completion callback function.

The callback function is called when a transfer has completed. An application should check the transferStatus and itemsTransferred values.

Parameters
[in]handleThe UARTDRV device handle used to start the transfer.
[in]transferStatusCompletion status of the transfer operation.
[in]dataPointer to transfer data buffer.
[in]transferCountNumber of bytes transferred.

Definition at line 127 of file uartdrv.h.

UART driver instance handle data structure. The handle is allocated by the application using UARTDRV. There may be several concurrent driver instances in an application. The application must not modify the contents of this handle, and should not depend on its values.

Enumeration Type Documentation

Transfer abort type.

Enumerator
uartdrvAbortTransmit 

Abort current and queued transmit operations.

uartdrvAbortReceive 

Abort current and queued receive operations.

uartdrvAbortAll 

Abort all current and queued operations.

Definition at line 89 of file uartdrv.h.

Flow Control state.

Enumerator
uartdrvFlowControlOn 

XON or nRTS/nCTS low.

uartdrvFlowControlOff 

XOFF or nRTS/nCTS high.

uartdrvFlowControlAuto 

This driver controls the state.

Definition at line 81 of file uartdrv.h.

Flow Control method.

Enumerator
uartdrvFlowControlNone 

None.

uartdrvFlowControlSw 

Software XON/XOFF.

uartdrvFlowControlHw 

nRTS/nCTS hardware handshake

uartdrvFlowControlHwUart 

The UART peripheral controls nRTS/nCTS.

Definition at line 72 of file uartdrv.h.

Function Documentation

Ecode_t UARTDRV_Abort ( UARTDRV_Handle_t  handle,
UARTDRV_AbortType_t  type 
)

Abort ongoing UART transfers.

All ongoing or queued operations of the given abort type will be aborted.

Parameters
[in]handlePointer to a UART driver handle.
[in]typeAbort type – whether to abort only TX, only RX or both.
Returns
ECODE_EMDRV_UARTDRV_OK on success, ECODE_EMDRV_UARTDRV_IDLE if the UART is idle. On failure an appropriate UARTDRV Ecode_t is returned.

Definition at line 1511 of file uartdrv.c.

References UARTDRV_Buffer_t::callback, CORE_DECLARE_IRQ_STATE, CORE_ENTER_ATOMIC, CORE_EXIT_ATOMIC, DMADRV_StopTransfer(), DMADRV_TransferRemainingCount(), ECODE_EMDRV_UARTDRV_ABORTED, ECODE_EMDRV_UARTDRV_IDLE, ECODE_EMDRV_UARTDRV_ILLEGAL_HANDLE, ECODE_EMDRV_UARTDRV_OK, UARTDRV_Buffer_t::itemsRemaining, rxBuffer, UARTDRV_Buffer_t::transferStatus, UARTDRV_GetPeripheralStatus(), UARTDRV_STATUS_TXIDLE, uartdrvAbortAll, uartdrvAbortReceive, uartdrvAbortTransmit, and uartdrvFlowControlHwUart.

Referenced by UARTDRV_DeInit().

Ecode_t UARTDRV_DeInit ( UARTDRV_Handle_t  handle)
UARTDRV_FlowControlState_t UARTDRV_FlowControlGetPeerStatus ( UARTDRV_Handle_t  handle)

Checks the peer's flow control status.

Parameters
[in]handlePointer to a UART driver handle.
Returns
Returns uartdrvFlowControlOn if clear to send.

Definition at line 1879 of file uartdrv.c.

UARTDRV_FlowControlState_t UARTDRV_FlowControlGetSelfStatus ( UARTDRV_Handle_t  handle)

Checks the self's flow control status.

Parameters
[in]handlePointer to a UART driver handle.
Returns
Returns uartdrvFlowControlOn if requesting to send.

Definition at line 1894 of file uartdrv.c.

Ecode_t UARTDRV_FlowControlIgnoreRestrain ( UARTDRV_Handle_t  handle)

Enables transmission when restrained by flow control.

Parameters
[in]handlePointer to a UART driver handle.
Returns
ECODE_EMDRV_UARTDRV_OK on success.

Definition at line 1909 of file uartdrv.c.

References ECODE_EMDRV_UARTDRV_OK.

Ecode_t UARTDRV_FlowControlSet ( UARTDRV_Handle_t  handle,
UARTDRV_FlowControlState_t  state 
)

Set UART flow control state. Set nRTS pin if hardware flow control is enabled. Send XON/XOFF if software flow control is enabled.

Parameters
[in]handlePointer to a UART driver handle.
[in]stateFlow control state.
Returns
ECODE_EMDRV_UARTDRV_OK on success.

Definition at line 1816 of file uartdrv.c.

References ECODE_EMDRV_UARTDRV_ILLEGAL_OPERATION, ECODE_EMDRV_UARTDRV_OK, uartdrvFlowControlAuto, and uartdrvFlowControlHwUart.

Referenced by UARTDRV_DeInit().

Ecode_t UARTDRV_FlowControlSetPeerStatus ( UARTDRV_Handle_t  handle,
UARTDRV_FlowControlState_t  state 
)

Set peer UART flow control state. Pause/resume transmit accordingly. Only for manual software flow control.

Parameters
[in]handlePointer to a UART driver handle.
[in]stateFlow control state.
Returns
ECODE_EMDRV_UARTDRV_OK on success.

Definition at line 1846 of file uartdrv.c.

References ECODE_EMDRV_UARTDRV_ILLEGAL_OPERATION, ECODE_EMDRV_UARTDRV_OK, UARTDRV_PauseTransmit(), UARTDRV_ResumeTransmit(), uartdrvFlowControlAuto, uartdrvFlowControlOff, uartdrvFlowControlOn, and uartdrvFlowControlSw.

UARTDRV_Count_t UARTDRV_ForceReceive ( UARTDRV_Handle_t  handle,
uint8_t *  data,
UARTDRV_Count_t  maxCount 
)

Direct receive without interrupts or callback. Blocking function.

Parameters
[in]handlePointer to a UART driver handle.
[in]datapointer to buffer.
[in]maxCountMaximum number of bytes to receive.
Returns
Number of bytes received.

Definition at line 1930 of file uartdrv.c.

References ECODE_EMDRV_UARTDRV_OK, LEUART_STATUS_RXDATAV, LEUART_STATUS_RXENS, USART_STATUS_RXDATAV, and USART_STATUS_RXENS.

Ecode_t UARTDRV_ForceTransmit ( UARTDRV_Handle_t  handle,
uint8_t *  data,
UARTDRV_Count_t  count 
)

Direct transmit without interrupts or callback. Blocking function that ignores flow control if enabled.

Parameters
[in]handlePointer to a UART driver handle.
[in]dataPointer to buffer.
[in]countNumber of bytes to transmit.
Returns
ECODE_EMDRV_UARTDRV_OK on success.

Definition at line 2015 of file uartdrv.c.

References CORE_IrqIsBlocked(), ECODE_EMDRV_UARTDRV_OK, LEUART_STATUS_TXC, LEUART_STATUS_TXENS, LEUART_Tx(), USART_STATUS_TXC, USART_STATUS_TXENS, and USART_Tx().

UARTDRV_Status_t UARTDRV_GetPeripheralStatus ( UARTDRV_Handle_t  handle)

Returns the status of the UART peripheral associated with a given handle.

Parameters
[in]handlePointer to a UART driver handle.
Returns
UART status value

Definition at line 1624 of file uartdrv.c.

References LEUART_STATUS_RXBLOCK, LEUART_STATUS_RXDATAV, LEUART_STATUS_RXENS, LEUART_STATUS_TXBL, LEUART_STATUS_TXC, LEUART_STATUS_TXENS, LEUART_STATUS_TXIDLE, UARTDRV_STATUS_RXBLOCK, UARTDRV_STATUS_RXDATAV, UARTDRV_STATUS_RXEN, UARTDRV_STATUS_TXBL, UARTDRV_STATUS_TXC, UARTDRV_STATUS_TXEN, and UARTDRV_STATUS_TXIDLE.

Referenced by UARTDRV_Abort(), UARTDRV_GetReceiveStatus(), and UARTDRV_GetTransmitStatus().

uint8_t UARTDRV_GetReceiveDepth ( UARTDRV_Handle_t  handle)

Returns the number of queued receive operations.

Parameters
[in]handlePointer to a UART driver handle.
Returns
The number of queued operations.

Definition at line 1687 of file uartdrv.c.

UARTDRV_Status_t UARTDRV_GetReceiveStatus ( UARTDRV_Handle_t  handle,
uint8_t **  buffer,
UARTDRV_Count_t itemsReceived,
UARTDRV_Count_t itemsRemaining 
)

Check the status of the UART and gather information about any ongoing receive operations.

Parameters
[in]handlePointer to a UART driver handle.
[in]bufferPointer to the current data buffer.
[in]itemsReceivedCurrent bytes received count.
[in]itemsRemainingCurrent bytes remaining count.
Returns
UART status.

Definition at line 1709 of file uartdrv.c.

References UARTDRV_Buffer_t::data, DMADRV_TransferRemainingCount(), ECODE_EMDRV_UARTDRV_OK, rxBuffer, UARTDRV_Buffer_t::transferCount, and UARTDRV_GetPeripheralStatus().

uint8_t UARTDRV_GetTransmitDepth ( UARTDRV_Handle_t  handle)

Returns the number of queued transmit operations.

Parameters
[in]handlePointer to a UART driver handle.
Returns
The number of queued operations.

Definition at line 1751 of file uartdrv.c.

UARTDRV_Status_t UARTDRV_GetTransmitStatus ( UARTDRV_Handle_t  handle,
uint8_t **  buffer,
UARTDRV_Count_t itemsSent,
UARTDRV_Count_t itemsRemaining 
)

Check the status of the UART and gather information about any ongoing transmit operations.

Parameters
[in]handlePointer to a UART driver handle.
[in]bufferPointer to the current data buffer.
[in]itemsSentCurrent bytes sent count.
[in]itemsRemainingCurrent bytes remaining count.
Returns
UART status.

Definition at line 1772 of file uartdrv.c.

References UARTDRV_Buffer_t::data, DMADRV_TransferRemainingCount(), ECODE_EMDRV_UARTDRV_OK, UARTDRV_Buffer_t::transferCount, and UARTDRV_GetPeripheralStatus().

__STATIC_INLINE Ecode_t UARTDRV_Init ( UARTDRV_Handle_t  handle,
UARTDRV_InitUart_t initData 
)

Initialize a U(S)ART driver instance.

Deprecated:
This function is deprecated. Use UARTDRV_InitUart() instead.
Parameters
[out]handlePointer to a UARTDRV handle, refer to UARTDRV_Handle_t.
[in]initDataPointer to an initialization data structure, refer to UARTDRV_InitUart_t.
Returns
ECODE_EMDRV_UARTDRV_OK on success. On failure an appropriate UARTDRV Ecode_t is returned.

Definition at line 366 of file uartdrv.h.

References UARTDRV_InitUart().

Ecode_t UARTDRV_InitLeuart ( UARTDRV_Handle_t  handle,
const UARTDRV_InitLeuart_t initData 
)

Initialize a LEUART driver instance.

Parameters
[out]handlePointer to a UARTDRV handle, refer to UARTDRV_Handle_t.
[in]initDataPointer to an initialization data structure, refer to UARTDRV_InitLeuart_t.
Returns
ECODE_EMDRV_UARTDRV_OK on success. On failure an appropriate UARTDRV Ecode_t is returned.

Definition at line 1249 of file uartdrv.c.

References _CMU_LFBPRESC0_LEUART0_MASK, _CMU_LFBPRESC0_LEUART0_SHIFT, _LEUART_ROUTELOC0_RXLOC_MASK, _LEUART_ROUTELOC0_RXLOC_SHIFT, _LEUART_ROUTELOC0_TXLOC_MASK, _LEUART_ROUTELOC0_TXLOC_SHIFT, LEUART_Init_TypeDef::baudrate, UARTDRV_InitLeuart_t::baudRate, LEUART_TypeDef::CMD, CMU, CMU_ClockDivSet(), CMU_ClockEnable(), CMU_ClockFreqGet(), CMU_ClockSelectSet(), CMU_STATUS_LFXOENS, cmuClock_GPIO, cmuClock_HFLE, cmuClock_HFPER, cmuClock_LEUART0, cmuClock_LFB, cmuSelect_HFCLKLE, cmuSelect_LFXO, CORE_DECLARE_IRQ_STATE, CORE_ENTER_ATOMIC, CORE_EXIT_ATOMIC, LEUART_Init_TypeDef::databits, DMADRV_Init(), dmadrvPeripheralSignal_LEUART0_RXDATAV, dmadrvPeripheralSignal_LEUART0_TXBL, ECODE_EMDRV_UARTDRV_CLOCK_ERROR, ECODE_EMDRV_UARTDRV_ILLEGAL_HANDLE, ECODE_EMDRV_UARTDRV_OK, ECODE_EMDRV_UARTDRV_PARAM_ERROR, LEUART_Init_TypeDef::enable, UARTDRV_InitLeuart_t::fcType, LEUART0, LEUART_CMD_CLEARRX, LEUART_CMD_CLEARTX, LEUART_CTRL_DATABITS_EIGHT, LEUART_Enable(), LEUART_Init(), LEUART_INIT_DEFAULT, LEUART_IntClear(), LEUART_ROUTEPEN_RXPEN, LEUART_ROUTEPEN_TXPEN, LEUART_SYNCBUSY_CMD, leuartDisable, leuartEnableTx, LEUART_Init_TypeDef::parity, UARTDRV_InitLeuart_t::parity, UARTDRV_InitLeuart_t::port, UARTDRV_InitLeuart_t::portLocationRx, UARTDRV_InitLeuart_t::portLocationTx, LEUART_TypeDef::ROUTELOC0, LEUART_TypeDef::ROUTEPEN, UARTDRV_InitLeuart_t::rxQueue, LEUART_Init_TypeDef::stopbits, UARTDRV_InitLeuart_t::stopBits, LEUART_TypeDef::SYNCBUSY, SystemLFXOClockGet(), UARTDRV_InitLeuart_t::txQueue, uartdrvFlowControlHw, uartdrvFlowControlHwUart, and uartdrvFlowControlNone.

Ecode_t UARTDRV_InitUart ( UARTDRV_Handle_t  handle,
const UARTDRV_InitUart_t initData 
)

Initialize a U(S)ART driver instance.

Parameters
[out]handlePointer to a UARTDRV handle, refer to UARTDRV_Handle_t.
[in]initDataPointer to an initialization data structure, refer to UARTDRV_InitUart_t.
Returns
ECODE_EMDRV_UARTDRV_OK on success. On failure an appropriate UARTDRV Ecode_t is returned.

Definition at line 1015 of file uartdrv.c.

References _USART_ROUTELOC0_RXLOC_MASK, _USART_ROUTELOC0_RXLOC_SHIFT, _USART_ROUTELOC0_TXLOC_MASK, _USART_ROUTELOC0_TXLOC_SHIFT, _USART_ROUTELOC1_CTSLOC_SHIFT, _USART_ROUTELOC1_RTSLOC_SHIFT, UARTDRV_InitUart_t::baudRate, USART_InitAsync_TypeDef::baudrate, USART_TypeDef::CMD, CMU_ClockEnable(), cmuClock_GPIO, cmuClock_HFPER, cmuClock_USART0, cmuClock_USART1, CORE_DECLARE_IRQ_STATE, CORE_ENTER_ATOMIC, CORE_EXIT_ATOMIC, USART_TypeDef::CTRLX, USART_InitAsync_TypeDef::databits, DMADRV_Init(), dmadrvPeripheralSignal_USART0_RXDATAV, dmadrvPeripheralSignal_USART0_TXBL, dmadrvPeripheralSignal_USART1_RXDATAV, dmadrvPeripheralSignal_USART1_TXBL, ECODE_EMDRV_UARTDRV_ILLEGAL_HANDLE, ECODE_EMDRV_UARTDRV_OK, ECODE_EMDRV_UARTDRV_PARAM_ERROR, USART_InitAsync_TypeDef::enable, UARTDRV_InitUart_t::fcType, UARTDRV_InitUart_t::mvdis, USART_InitAsync_TypeDef::mvdis, UARTDRV_InitUart_t::oversampling, USART_InitAsync_TypeDef::oversampling, UARTDRV_InitUart_t::parity, USART_InitAsync_TypeDef::parity, UARTDRV_InitUart_t::port, UARTDRV_InitUart_t::portLocationCts, UARTDRV_InitUart_t::portLocationRts, UARTDRV_InitUart_t::portLocationRx, UARTDRV_InitUart_t::portLocationTx, USART_TypeDef::ROUTELOC0, USART_TypeDef::ROUTELOC1, USART_TypeDef::ROUTEPEN, UARTDRV_InitUart_t::rxQueue, UARTDRV_InitUart_t::stopBits, USART_InitAsync_TypeDef::stopbits, UARTDRV_InitUart_t::txQueue, uartdrvFlowControlHw, uartdrvFlowControlHwUart, uartdrvFlowControlNone, USART0, USART1, USART_CMD_CLEARRX, USART_CMD_CLEARTX, USART_CTRLX_CTSEN, USART_Enable(), USART_FRAME_DATABITS_EIGHT, USART_InitAsync(), USART_INITASYNC_DEFAULT, USART_IntClear(), USART_ROUTEPEN_CTSPEN, USART_ROUTEPEN_RTSPEN, USART_ROUTEPEN_RXPEN, USART_ROUTEPEN_TXPEN, usartDisable, usartEnable, and usartEnableTx.

Referenced by UARTDRV_Init().

Ecode_t UARTDRV_PauseTransmit ( UARTDRV_Handle_t  handle)

Pause an ongoing transmit operation.

Parameters
[in]handlePointer to a UART driver handle.
Returns
ECODE_EMDRV_UARTDRV_OK on success. On failure an appropriate UARTDRV Ecode_t is returned.

Definition at line 2098 of file uartdrv.c.

References DMADRV_PauseTransfer(), DMADRV_TransferActive(), ECODE_EMDRV_DMADRV_OK, ECODE_EMDRV_UARTDRV_ILLEGAL_HANDLE, ECODE_EMDRV_UARTDRV_ILLEGAL_OPERATION, ECODE_EMDRV_UARTDRV_OK, and uartdrvFlowControlOn.

Referenced by UARTDRV_FlowControlSetPeerStatus().

Ecode_t UARTDRV_Receive ( UARTDRV_Handle_t  handle,
uint8_t *  data,
UARTDRV_Count_t  count,
UARTDRV_Callback_t  callback 
)

Start a non-blocking receive.

Parameters
[in]handlePointer to a UART driver handle.
[in]dataReceive data buffer.
[in]countNumber of bytes received.
[in]callbackTransfer completion callback.
Returns
ECODE_EMDRV_UARTDRV_OK on success.

Definition at line 2141 of file uartdrv.c.

References UARTDRV_Buffer_t::callback, UARTDRV_Buffer_t::data, ECODE_EMDRV_UARTDRV_OK, ECODE_EMDRV_UARTDRV_WAITING, UARTDRV_Buffer_t::itemsRemaining, UARTDRV_Buffer_t::transferCount, UARTDRV_Buffer_t::transferStatus, uartdrvFlowControlHwUart, and uartdrvFlowControlOn.

Ecode_t UARTDRV_ReceiveB ( UARTDRV_Handle_t  handle,
uint8_t *  data,
UARTDRV_Count_t  count 
)

Start a blocking receive.

Parameters
[in]handlePointer to a UART driver handle.
[in]dataReceive data buffer.
[in]countNumber of bytes received.
Returns
ECODE_EMDRV_UARTDRV_OK on success.

Definition at line 2196 of file uartdrv.c.

References UARTDRV_Buffer_t::callback, UARTDRV_Buffer_t::data, ECODE_EMDRV_UARTDRV_OK, ECODE_EMDRV_UARTDRV_WAITING, EMU_EnterEM1(), UARTDRV_Buffer_t::itemsRemaining, UARTDRV_Buffer_t::transferCount, UARTDRV_Buffer_t::transferStatus, uartdrvFlowControlHwUart, and uartdrvFlowControlOn.

Ecode_t UARTDRV_ResumeTransmit ( UARTDRV_Handle_t  handle)

Resume a paused transmit operation.

Parameters
[in]handlePointer to a UART driver handle.
Returns
ECODE_EMDRV_UARTDRV_OK on success. On failure an appropriate UARTDRV Ecode_t is returned.

Definition at line 2250 of file uartdrv.c.

References DMADRV_ResumeTransfer(), DMADRV_TransferActive(), ECODE_EMDRV_DMADRV_OK, ECODE_EMDRV_UARTDRV_ILLEGAL_HANDLE, ECODE_EMDRV_UARTDRV_ILLEGAL_OPERATION, ECODE_EMDRV_UARTDRV_OK, and uartdrvFlowControlOn.

Referenced by UARTDRV_FlowControlSetPeerStatus().

Ecode_t UARTDRV_Transmit ( UARTDRV_Handle_t  handle,
uint8_t *  data,
UARTDRV_Count_t  count,
UARTDRV_Callback_t  callback 
)

Start a non-blocking transmit.

Parameters
[in]handlePointer to a UART driver handle.
[in]dataTransmit data buffer.
[in]countNumber of bytes to transmit.
[in]callbackTransfer completion callback.
Returns
ECODE_EMDRV_UARTDRV_OK on success.

Definition at line 2290 of file uartdrv.c.

References UARTDRV_Buffer_t::callback, CORE_ATOMIC_SECTION, UARTDRV_Buffer_t::data, ECODE_EMDRV_UARTDRV_OK, ECODE_EMDRV_UARTDRV_WAITING, UARTDRV_Buffer_t::itemsRemaining, UARTDRV_Buffer_t::transferCount, and UARTDRV_Buffer_t::transferStatus.

Ecode_t UARTDRV_TransmitB ( UARTDRV_Handle_t  handle,
uint8_t *  data,
UARTDRV_Count_t  count 
)

Start a blocking transmit.

Parameters
[in]handlePointer to a UART driver handle.
[in]dataTransmit data buffer.
[in]countNumber of bytes to transmit.
Returns
ECODE_EMDRV_UARTDRV_OK on success.

Definition at line 2343 of file uartdrv.c.

References UARTDRV_Buffer_t::callback, UARTDRV_Buffer_t::data, ECODE_EMDRV_UARTDRV_OK, ECODE_EMDRV_UARTDRV_WAITING, EMU_EnterEM1(), UARTDRV_Buffer_t::itemsRemaining, UARTDRV_Buffer_t::transferCount, and UARTDRV_Buffer_t::transferStatus.