![]() |
nRF5 SDK
v12.3.0
|
Choose documentation: | nRF5 SDK | S130 SoftDevice API | S132 SoftDevice API | S212 SoftDevice API | S332 SoftDevice API |
The UART RAW protocol implements the Serialization PHY API using the UART interface.
UART RAW for serialization uses four standard UART lines: RX, TX, /CTS, and /RTS. Hardware flow control is enabled. The protocol supports full duplex communication. Every packet consists of a two-byte header followed by payload. Packet header contains the number of bytes of the payload. Header is transmitted with the least significant byte first.
Packets are transmitted in the following format:
[RX_HEADER]=[0x0004]
.[RX_PAYLOAD]=[0x00 0x78 0x41 0x03]
.[TX_HEADER]=[0x0006]
, [TX_PAYLOAD]=[0x01 0x78 0x00 0x00 0x00 0x00]
.The UART RAW protocol for serialization is implemented in the ser_phy_nrf51_uart.c
file. It uses app_uart.c
as a the low-level UART driver.
The implementation is event-driven. Events from the low-level driver are handled in a static ser_phy_uart_evt_callback()
function. Three types of app_uart_evt_t events are processed: APP_UART_COMMUNICATION_ERROR, APP_UART_TX_EMPTY, and APP_UART_DATA.
ser_phy_uart_tx()
. ser_phy_uart_tx()
function is called for the first time in the ser_phy_tx_pkt_send()
function. Later, it is only called in the app_uart_evt_t event callback.ser_phy_uart_rx()
is called, with the received byte as a parameter. The received byte is taken from the app_uart_evt_t structure.The following ser_phy_evt_t events are sent to the upper layer:
ser_phy_rx_buf_set()
function is called by the upper layer, indicating whether a receive buffer has been allocated or not. Subsequently the packet payload is received or dropped.Function ser_phy_open() initializes UART using the APP_UART_INIT macro with configuration structure of type app_uart_comm_params_t as input. It also registers the SER_PHY event callback.
Function ser_phy_close() closes UART using the app_uart_close() function. It also deregisters the SER_PHY event callback.