Serial UART Communication#

This API contains the HAL interfaces that applications must implement for the high-level serial code.

This header describes the interface between the high-level serial APIs in serial/serial.h and the low level UART implementation.

Some functions in this file return an EmberStatus value and others return ::sl_status_t. See error-def.h for definitions of all EmberStatus return values, and sl_status.h for all ::sl_status_t return values.

See hal/micro/serial.h for source code.

Serial HAL APIs#

These functions must be implemented by the HAL in order for the serial code to operate. Only the higher-level serial code uses these functions, so they should not be called directly. The HAL should also implement the appropriate interrupt handlers to drain the TX queues and fill the RX FIFO queue.

sl_status_t
halInternalUartInit(uint8_t port, SerialBaudRate rate, SerialParity parity, uint8_t stopBits)

Initializes the UART to the given settings (same parameters as ::sli_legacy_serial_init() ).

void

This function is typically called by halPowerDown() and it is responsible for performing all the work internal to the UART needed to stop the UART before a sleep cycle.

void

This function is typically called by halPowerUp() and it is responsible for performing all the work internal to the UART needed to restart the UART after a sleep cycle.

void

Called by serial code whenever anything is queued for transmission to start any interrupt-driven transmission. May be called when transmission is already in progess.

void
halInternalStopUartTx(uint8_t port)

Called by serial code to stop any interrupt-driven serial transmission currently in progress.

sl_status_t
halInternalForceWriteUartData(uint8_t port, uint8_t *data, uint8_t length)

Directly writes a byte to the UART for transmission, regardless of anything currently queued for transmission. Should wait for anything currently in the UART hardware registers to finish transmission first, and block until data is finished being sent.

halInternalForceReadUartByte(uint8_t port, uint8_t *dataByte)

Directly reads a byte from the UART for reception, regardless of anything currently queued for reception. Does not block if a data byte has not been received.

void

Blocks until the UART has finished transmitting any data in its hardware registers.

void

This function is typically called by ::halInternalPowerUpBoard() and it is responsible for performing all the work internal to the UART needed to restart the UART after a sleep cycle. (For example, resyncing the DMA hardware and the serial FIFO.)

bool

Checks to see if the host is allowed to send serial data to the ncp - i.e., it is not being held off by nCTS or an XOFF. Returns true is the host is able to send.

bool

When Xon/Xoff flow control is used, returns true if the host is not being held off and XON refreshing is complete.

bool

Returns true if the uart transmitter is idle, including the transmit shift register.

bool

Testing function implemented by the upper layer. Determines whether the next packet should be dropped. Returns true if the next packet should be dropped, false otherwise.

#define

This function is used in FIFO mode when flow control is enabled. It is called from sli_legacy_serial_read_byte(), and based on the number of bytes used in the uart receive queue, decides when to tell the host it may resume transmission.

#define

This function exists only in software UART (SOFTUART) mode on the EM3xx. This function is called by ::sli_legacy_serial_read_byte(). It is responsible for maintaining synchronization between the emSerialRxQueue and the UART DMA.

#define

This function is used in FIFO mode when flow control is enabled. It is called from sli_legacy_serial_read_byte(), and based on the number of bytes used in the uart receive queue, decides when to tell the host it may resume transmission.

#define

This function is used in FIFO mode when flow control is enabled. It is called from sli_legacy_serial_read_byte(), and based on the number of bytes used in the uart receive queue, decides when to tell the host it may resume transmission.

#define

This function is used in FIFO mode when flow control is enabled. It is called from sli_legacy_serial_read_byte(), and based on the number of bytes used in the uart receive queue, decides when to tell the host it may resume transmission.

Virtual UART API#

API used by the stack in debug builds to receive data arriving over the virtual UART.

void
halStackReceiveVuartMessage(uint8_t *data, uint8_t length)

When using a debug build with virtual UART support, this API is called by the stack when virtual UART data has been received over the debug channel.

Serial Mode Definitions#

These are numerical definitions for the possible serial modes so that code can test for the one being used. There may be additional modes defined in the micro-specific micro.h.

#define

A numerical definition for a possible serial mode the code can test for.

#define

A numerical definition for a possible serial mode the code can test for.

#define

A numerical definition for a possible serial mode the code can test for.

FIFO Utility Macros#

These macros manipulate the FIFO queue data structures to add and remove data.

#define
FIFO_ENQUEUE (queue, data, size)

Macro that enqueues a byte of data in a FIFO queue.

#define
FIFO_DEQUEUE (queue, size)

Macro that de-queues a byte of data from a FIFO queue.

Enumerations#

enum
DEFINE_BAUD =(300) = 0
DEFINE_BAUD =(300) = 0
DEFINE_BAUD =(300) = 0
DEFINE_BAUD =(300) = 0
DEFINE_BAUD =(300) = 0
DEFINE_BAUD =(300) = 0
DEFINE_BAUD =(300) = 0
DEFINE_BAUD =(300) = 0
DEFINE_BAUD =(300) = 0
DEFINE_BAUD =(300) = 0
DEFINE_BAUD =(300) = 0
DEFINE_BAUD =(300) = 0
DEFINE_BAUD =(300) = 0
DEFINE_BAUD =(300) = 0
DEFINE_BAUD =(300) = 0
DEFINE_BAUD =(300) = 0
DEFINE_BAUD =(300) = 0
DEFINE_BAUD =(300) = 0
DEFINE_BAUD =(300) = 0
}

Assign numerical values for variables that hold Baud Rate parameters.

enum
DEFINE_PARITY =(NONE) = 0U
DEFINE_PARITY =(NONE) = 0U
DEFINE_PARITY =(NONE) = 0U
}

CORTEXM3_EFM32_MICRO.

Functions#

uint16_t
halHostEnqueueTx(const uint8_t *data, uint16_t length)
void
uint16_t
serialCopyFromRx(const uint8_t *data, uint16_t length)
void

Serial HAL APIs Documentation#

halInternalUartInit#

sl_status_t halInternalUartInit (uint8_t port, SerialBaudRate rate, SerialParity parity, uint8_t stopBits)

Initializes the UART to the given settings (same parameters as ::sli_legacy_serial_init() ).

Parameters
N/Aport

Serial port number (0 or 1).

N/Arate

Baud rate (see SerialBaudRate).

N/Aparity

Parity value (see SerialParity).

N/AstopBits

Number of stop bits.

Returns

  • An error code if initialization failed (such as invalid baud rate), otherise SL_STATUS_OK.


Definition at line 411 of file /mnt/raid/workspaces/ws.OJKVohJa4/overlay/gsdk/platform/base/hal/micro/serial.h

halInternalPowerDownUart#

void halInternalPowerDownUart (void )

This function is typically called by halPowerDown() and it is responsible for performing all the work internal to the UART needed to stop the UART before a sleep cycle.

Parameters
N/A

Definition at line 420 of file /mnt/raid/workspaces/ws.OJKVohJa4/overlay/gsdk/platform/base/hal/micro/serial.h

halInternalPowerUpUart#

void halInternalPowerUpUart (void )

This function is typically called by halPowerUp() and it is responsible for performing all the work internal to the UART needed to restart the UART after a sleep cycle.

Parameters
N/A

Definition at line 426 of file /mnt/raid/workspaces/ws.OJKVohJa4/overlay/gsdk/platform/base/hal/micro/serial.h

halInternalStartUartTx#

void halInternalStartUartTx (uint8_t port)

Called by serial code whenever anything is queued for transmission to start any interrupt-driven transmission. May be called when transmission is already in progess.

Parameters
N/Aport

Serial port number (0 or 1).


Definition at line 434 of file /mnt/raid/workspaces/ws.OJKVohJa4/overlay/gsdk/platform/base/hal/micro/serial.h

halInternalStopUartTx#

void halInternalStopUartTx (uint8_t port)

Called by serial code to stop any interrupt-driven serial transmission currently in progress.

Parameters
N/Aport

Serial port number (0 or 1).


Definition at line 441 of file /mnt/raid/workspaces/ws.OJKVohJa4/overlay/gsdk/platform/base/hal/micro/serial.h

halInternalForceWriteUartData#

sl_status_t halInternalForceWriteUartData (uint8_t port, uint8_t * data, uint8_t length)

Directly writes a byte to the UART for transmission, regardless of anything currently queued for transmission. Should wait for anything currently in the UART hardware registers to finish transmission first, and block until data is finished being sent.

Parameters
N/Aport

Serial port number (0 or 1).

N/Adata

Pointer to the data to be transmitted.

N/Alength

The length of data to be transmitted


Definition at line 454 of file /mnt/raid/workspaces/ws.OJKVohJa4/overlay/gsdk/platform/base/hal/micro/serial.h

halInternalForceReadUartByte#

EmberStatus halInternalForceReadUartByte (uint8_t port, uint8_t * dataByte)

Directly reads a byte from the UART for reception, regardless of anything currently queued for reception. Does not block if a data byte has not been received.

Parameters
N/Aport

Serial port number (0 or 1).

N/AdataByte

The byte to receive data into.


Definition at line 464 of file /mnt/raid/workspaces/ws.OJKVohJa4/overlay/gsdk/platform/base/hal/micro/serial.h

halInternalWaitUartTxComplete#

void halInternalWaitUartTxComplete (uint8_t port)

Blocks until the UART has finished transmitting any data in its hardware registers.

Parameters
N/Aport

Serial port number (0 or 1).


Definition at line 471 of file /mnt/raid/workspaces/ws.OJKVohJa4/overlay/gsdk/platform/base/hal/micro/serial.h

halInternalRestartUart#

void halInternalRestartUart (void )

This function is typically called by ::halInternalPowerUpBoard() and it is responsible for performing all the work internal to the UART needed to restart the UART after a sleep cycle. (For example, resyncing the DMA hardware and the serial FIFO.)

Parameters
N/A

Definition at line 507 of file /mnt/raid/workspaces/ws.OJKVohJa4/overlay/gsdk/platform/base/hal/micro/serial.h

halInternalUartFlowControlRxIsEnabled#

bool halInternalUartFlowControlRxIsEnabled (uint8_t port)

Checks to see if the host is allowed to send serial data to the ncp - i.e., it is not being held off by nCTS or an XOFF. Returns true is the host is able to send.

Parameters
N/Aport

Definition at line 514 of file /mnt/raid/workspaces/ws.OJKVohJa4/overlay/gsdk/platform/base/hal/micro/serial.h

halInternalUartXonRefreshDone#

bool halInternalUartXonRefreshDone (uint8_t port)

When Xon/Xoff flow control is used, returns true if the host is not being held off and XON refreshing is complete.

Parameters
N/Aport

Definition at line 526 of file /mnt/raid/workspaces/ws.OJKVohJa4/overlay/gsdk/platform/base/hal/micro/serial.h

halInternalUartTxIsIdle#

bool halInternalUartTxIsIdle (uint8_t port)

Returns true if the uart transmitter is idle, including the transmit shift register.

Parameters
N/Aport

Definition at line 538 of file /mnt/raid/workspaces/ws.OJKVohJa4/overlay/gsdk/platform/base/hal/micro/serial.h

serialDropPacket#

bool serialDropPacket (void )

Testing function implemented by the upper layer. Determines whether the next packet should be dropped. Returns true if the next packet should be dropped, false otherwise.

Parameters
N/A

Definition at line 548 of file /mnt/raid/workspaces/ws.OJKVohJa4/overlay/gsdk/platform/base/hal/micro/serial.h

halInternalUartFlowControl#

#define halInternalUartFlowControl
Value:
(port)

This function is used in FIFO mode when flow control is enabled. It is called from sli_legacy_serial_read_byte(), and based on the number of bytes used in the uart receive queue, decides when to tell the host it may resume transmission.


Definition at line 485 of file /mnt/raid/workspaces/ws.OJKVohJa4/overlay/gsdk/platform/base/hal/micro/serial.h

halInternalUartRxPump#

#define halInternalUartRxPump
Value:
(port)

This function exists only in software UART (SOFTUART) mode on the EM3xx. This function is called by ::sli_legacy_serial_read_byte(). It is responsible for maintaining synchronization between the emSerialRxQueue and the UART DMA.


Definition at line 499 of file /mnt/raid/workspaces/ws.OJKVohJa4/overlay/gsdk/platform/base/hal/micro/serial.h

halInternalUart1FlowControlRxIsEnabled#

#define halInternalUart1FlowControlRxIsEnabled
Value:
()

This function is used in FIFO mode when flow control is enabled. It is called from sli_legacy_serial_read_byte(), and based on the number of bytes used in the uart receive queue, decides when to tell the host it may resume transmission.


Definition at line 517 of file /mnt/raid/workspaces/ws.OJKVohJa4/overlay/gsdk/platform/base/hal/micro/serial.h

halInternalUart1XonRefreshDone#

#define halInternalUart1XonRefreshDone
Value:
()

This function is used in FIFO mode when flow control is enabled. It is called from sli_legacy_serial_read_byte(), and based on the number of bytes used in the uart receive queue, decides when to tell the host it may resume transmission.


Definition at line 529 of file /mnt/raid/workspaces/ws.OJKVohJa4/overlay/gsdk/platform/base/hal/micro/serial.h

halInternalUart1TxIsIdle#

#define halInternalUart1TxIsIdle
Value:
()

This function is used in FIFO mode when flow control is enabled. It is called from sli_legacy_serial_read_byte(), and based on the number of bytes used in the uart receive queue, decides when to tell the host it may resume transmission.


Definition at line 542 of file /mnt/raid/workspaces/ws.OJKVohJa4/overlay/gsdk/platform/base/hal/micro/serial.h

Virtual UART API Documentation#

halStackReceiveVuartMessage#

void halStackReceiveVuartMessage (uint8_t * data, uint8_t length)

When using a debug build with virtual UART support, this API is called by the stack when virtual UART data has been received over the debug channel.

Parameters
N/Adata

Pointer to the the data received

N/Alength

Length of the data received


Definition at line 575 of file /mnt/raid/workspaces/ws.OJKVohJa4/overlay/gsdk/platform/base/hal/micro/serial.h

Serial Mode Definitions Documentation#

SL_LEGACY_SERIAL_UNUSED#

#define SL_LEGACY_SERIAL_UNUSED
Value:
0

A numerical definition for a possible serial mode the code can test for.


Definition at line 92 of file /mnt/raid/workspaces/ws.OJKVohJa4/overlay/gsdk/platform/base/hal/micro/serial.h

SL_LEGACY_SERIAL_FIFO#

#define SL_LEGACY_SERIAL_FIFO
Value:
1

A numerical definition for a possible serial mode the code can test for.


Definition at line 93 of file /mnt/raid/workspaces/ws.OJKVohJa4/overlay/gsdk/platform/base/hal/micro/serial.h

SL_LEGACY_SERIAL_LOWLEVEL#

#define SL_LEGACY_SERIAL_LOWLEVEL
Value:
2

A numerical definition for a possible serial mode the code can test for.


Definition at line 94 of file /mnt/raid/workspaces/ws.OJKVohJa4/overlay/gsdk/platform/base/hal/micro/serial.h

FIFO Utility Macros Documentation#

FIFO_ENQUEUE#

#define FIFO_ENQUEUE
Value:
do { \
(queue)->fifo[(queue)->head] = (data); \
(queue)->head = (((queue)->head + 1) % (size)); \
(queue)->used++; \
} while (0)

Macro that enqueues a byte of data in a FIFO queue.


Definition at line 273 of file /mnt/raid/workspaces/ws.OJKVohJa4/overlay/gsdk/platform/base/hal/micro/serial.h

FIFO_DEQUEUE#

#define FIFO_DEQUEUE
Value:
(queue)->fifo[(queue)->tail]; \
(queue)->tail = (((queue)->tail + 1) % (size)); \
(queue)->used--

Macro that de-queues a byte of data from a FIFO queue.


Definition at line 288 of file /mnt/raid/workspaces/ws.OJKVohJa4/overlay/gsdk/platform/base/hal/micro/serial.h

Enumeration Documentation#

SerialBaudRate#

SerialBaudRate

Assign numerical values for variables that hold Baud Rate parameters.

Enumerator
DEFINE_BAUD
DEFINE_BAUD
DEFINE_BAUD
DEFINE_BAUD
DEFINE_BAUD
DEFINE_BAUD
DEFINE_BAUD
DEFINE_BAUD
DEFINE_BAUD
DEFINE_BAUD
DEFINE_BAUD
DEFINE_BAUD
DEFINE_BAUD
DEFINE_BAUD
DEFINE_BAUD
DEFINE_BAUD
DEFINE_BAUD
DEFINE_BAUD
DEFINE_BAUD

Definition at line 301 of file /mnt/raid/workspaces/ws.OJKVohJa4/overlay/gsdk/platform/base/hal/micro/serial.h

SerialParity#

SerialParity

CORTEXM3_EFM32_MICRO.

Assign numerical values for the types of parity. Use for variables that hold Parity parameters.

Enumerator
DEFINE_PARITY
DEFINE_PARITY
DEFINE_PARITY

Definition at line 371 of file /mnt/raid/workspaces/ws.OJKVohJa4/overlay/gsdk/platform/base/hal/micro/serial.h

Function Documentation#

halHostFlushBuffers#

void halHostFlushBuffers (void )
Parameters
N/A

Definition at line 586 of file /mnt/raid/workspaces/ws.OJKVohJa4/overlay/gsdk/platform/base/hal/micro/serial.h

halHostEnqueueTx#

uint16_t halHostEnqueueTx (const uint8_t * data, uint16_t length)
Parameters
N/Adata
N/Alength

Definition at line 587 of file /mnt/raid/workspaces/ws.OJKVohJa4/overlay/gsdk/platform/base/hal/micro/serial.h

halHostFlushTx#

void halHostFlushTx (void )
Parameters
N/A

Definition at line 588 of file /mnt/raid/workspaces/ws.OJKVohJa4/overlay/gsdk/platform/base/hal/micro/serial.h

serialCopyFromRx#

uint16_t serialCopyFromRx (const uint8_t * data, uint16_t length)
Parameters
N/Adata
N/Alength

Definition at line 591 of file /mnt/raid/workspaces/ws.OJKVohJa4/overlay/gsdk/platform/base/hal/micro/serial.h

emLoadSerialTx#

void emLoadSerialTx (void )
Parameters
N/A

Definition at line 594 of file /mnt/raid/workspaces/ws.OJKVohJa4/overlay/gsdk/platform/base/hal/micro/serial.h