nRF51 SDK - S120 SoftDevice
 All Data Structures Functions Variables Typedefs Enumerations Enumerator Groups Pages
Serialization PHY

This file contains declarations of functions and definitions of data structures and identifiers (typedef enum) used as API of the serialization PHY layer.

Rationale
Each specific PHY layer (SPI, I2C, UART, low power UART etc.) should provide the same API. This allows the layer above (the HAL Transport layer) which is responsible for controlling the PHY layer, memory management, crc, retransmission etc. to be hardware independent.
Interlayer communication and control
The PHY layer is controlled by the HAL Transport layer by calling functions declared in this file. The PHY layer communicates events to the HAL Transport layer by calling a callback function. A handler to this function is passed in the ser_phy_open function. This callback function should be called with parameter of type ser_phy_evt_t filled accordingly to an event to be passed. Types of supported events are defined in ser_phy_evt_type_t. For example to pass an event indicating that RX packet has been successfully received first a struct of type ser_phy_evt_t has to be filled: ser_phy_evt_t phy_evt; phy_evt.evt_type = SER_PHY_EVT_RX_PKT_RECEIVED; phy_evt.evt_params.rx_pkt_received.p_buffer = (pointer to the RX buffer); phy_evt.evt_params.rx_pkt_received.num_of_bytes = (number of received bytes); and then the callback function has to be called: events_handler(phy_evt); All functions declared in this file are obligatory to implement. Some events specified in the ser_phy_evt_type_t are optional to implement.
Transmitting a packet
Each PHY layer is responsible for adding the PHY header to a packet to be sent. This header shall consists of 16-bit field carrying the packet length (the uint16_encode function defined in app_util.h should be used to ensure endianness independence). A pointer to a packet to be sent and a length of the packet are parameters of the ser_phy_tx_pkt_send function. When a packet has been transmitted an event of type SER_PHY_EVT_TX_PKT_SENT should be emitted.
ser_phy_transport_tx.png
TX - interlayer communication
Receiving a packet
The PHY layer should be able to store only the PHY header (16-bit field carrying the packet length). After the PHY header has been received the transmission shall be halted and the PHY layer has to sent a request to the HAL Transport layer for a memory to store a packet - an event of type SER_PHY_EVT_RX_BUF_REQUEST with event parameters defined in ser_phy_evt_rx_buf_request_params_t (the uint16_decode function defined in app_util.h should be used for header decoding to ensure endianness independence). The transmission should be resumed when ser_phy_rx_buf_set function has been called.

When ser_phy_rx_buf_set function parameter is equal to NULL it means that there is not enough memory to store the packet, however the packet shall be received to dummy location to ensure continuous communication. After receiving has finished an event of type SER_PHY_EVT_RX_PKT_DROPPED shall be generated.

ser_phy_transport_rx_dropped.png
RX dropping - interlayer communication

When ser_phy_rx_buf_set function parameter is different from NULL the packet should be received to a buffer pointed by it. After receiving has finished an event of type SER_PHY_EVT_RX_PKT_RECEIVED shall be generated with event parameters defined in ser_phy_evt_rx_pkt_received_params_t.

ser_phy_transport_rx_received.png
RX - interlayer communication
PHY layer errors
PHY layer errors can be signaled by an event of type SER_PHY_EVT_RX_OVERFLOW_ERROR or SER_PHY_EVT_TX_OVERREAD_ERROR or SER_PHY_EVT_HW_ERROR with event parameters defined in ser_phy_evt_hw_error_params_t.