PHY layer for serialization. More...
Data Structures |
|
| struct | ser_phy_evt_rx_buf_request_params_t |
|
A struct containing parameters of event of type
SER_PHY_EVT_RX_BUF_REQUEST
.
More...
|
|
| struct | ser_phy_evt_rx_pkt_received_params_t |
|
A struct containing parameters of event of type
SER_PHY_EVT_RX_PKT_RECEIVED
.
More...
|
|
| struct | ser_phy_evt_hw_error_params_t |
|
A struct containing parameters of event of type
SER_PHY_EVT_HW_ERROR
.
More...
|
|
| struct | ser_phy_evt_t |
|
A struct containing events from a Serialization PHY module.
More...
|
|
Typedefs |
|
| typedef void(* | ser_phy_events_handler_t )( ser_phy_evt_t event) |
|
A type of generic callback function handler to be used by all PHY module events.
More...
|
|
Enumerations |
|
| enum |
ser_phy_evt_type_t
{
SER_PHY_EVT_TX_PKT_SENT = 0, SER_PHY_EVT_RX_BUF_REQUEST , SER_PHY_EVT_RX_PKT_RECEIVED , SER_PHY_EVT_RX_PKT_DROPPED , SER_PHY_EVT_RX_OVERFLOW_ERROR , SER_PHY_EVT_TX_OVERREAD_ERROR , SER_PHY_EVT_HW_ERROR , SER_PHY_EVT_TYPE_MAX } |
|
Serialization PHY module event types.
More...
|
|
Functions |
|
| uint32_t | ser_phy_open ( ser_phy_events_handler_t events_handler) |
|
Function for opening and initializing the PHY module.
More...
|
|
| uint32_t | ser_phy_tx_pkt_send (const uint8_t *p_buffer, uint16_t num_of_bytes) |
|
Function for transmitting a packet.
More...
|
|
| uint32_t | ser_phy_rx_buf_set (uint8_t *p_buffer) |
|
Function for setting an RX buffer and enabling reception of data (the PHY flow).
More...
|
|
| void | ser_phy_close (void) |
|
Function for closing the PHY module.
More...
|
|
| void | ser_phy_interrupts_enable (void) |
|
Function for enabling the PHY module interrupts.
More...
|
|
| void | ser_phy_interrupts_disable (void) |
|
Function for disabling the PHY module interrupts.
More...
|
|
Detailed Description
PHY layer for serialization.
Here you can find 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:
, and then the callback function has to be called: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);All functions declared in this file are obligatory to implement. Some events specified in ser_phy_evt_type_t are optional to implement.events_handler(phy_evt);
- Transmitting a packet
- Each PHY layer is responsible for adding the PHY header to a packet to be sent. This header consists of a 16-bit field that carries 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 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.
- 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 is stopped and the PHY layer has to send a request to the HAL Transport layer for memory to store the 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 the ser_phy_rx_buf_set function has been called.
When the ser_phy_rx_buf_set function parameter equals NULL, it means that there is not enough memory to store the packet, however the packet will be received to dummy location to ensure continuous communication. After receiving has finished, an event of type SER_PHY_EVT_RX_PKT_DROPPED is generated.
When the ser_phy_rx_buf_set function parameter is different than NULL, the packet is received to a buffer pointed by it. After receiving has finished, an event of type SER_PHY_EVT_RX_PKT_RECEIVED is generated with event parameters defined in ser_phy_evt_rx_pkt_received_params_t .
- 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 .
Typedef Documentation
| typedef void(* ser_phy_events_handler_t)( ser_phy_evt_t event) |
A type of generic callback function handler to be used by all PHY module events.
- Parameters
-
[in] event Serialization PHY module event.
Enumeration Type Documentation
| enum ser_phy_evt_type_t |
Serialization PHY module event types.
| Enumerator | |
|---|---|
| SER_PHY_EVT_TX_PKT_SENT |
Obligatory to implement. An event indicating that a TX packet has been transmitted. |
| SER_PHY_EVT_RX_BUF_REQUEST |
Obligatory to implement. An event indicating that the PHY layer needs a buffer for an RX packet. The PHY flow should be blocked until the ser_phy_rx_buf_set function is called. |
| SER_PHY_EVT_RX_PKT_RECEIVED |
Obligatory to implement. An event indicating that an RX packet has been successfully received. |
| SER_PHY_EVT_RX_PKT_DROPPED |
Obligatory to implement. An event indicating that the RX packet receiving has been finished but the packet was discarded because it was longer than available the buffer. |
| SER_PHY_EVT_RX_OVERFLOW_ERROR |
Optional to implement. An event indicating that more information has been transmitted than the PHY module could handle. |
| SER_PHY_EVT_TX_OVERREAD_ERROR |
Optional to implement. An event indicating that the PHY module was forced to transmit more information than possessed. |
| SER_PHY_EVT_HW_ERROR |
Optional to implement. An event indicating a hardware error in the PHY module. |
| SER_PHY_EVT_TYPE_MAX |
Enumeration upper bound. |
Function Documentation
| void ser_phy_close | ( | void | ) |
Function for closing the PHY module.
- Note
- The function disables hardware, resets internal module states, and unregisters the events callback function.
| void ser_phy_interrupts_disable | ( | void | ) |
Function for disabling the PHY module interrupts.
- Note
- The function disables all interrupts that are used by the PHY module (and only those).
| void ser_phy_interrupts_enable | ( | void | ) |
Function for enabling the PHY module interrupts.
- Note
- The function enables all interrupts that are used by the PHY module (and only those).
| uint32_t ser_phy_open | ( | ser_phy_events_handler_t | events_handler | ) |
Function for opening and initializing the PHY module.
- Note
- The function initializes hardware and internal module states, and registers callback function to be used by all PHY module events.
- Warning
- If the function has been already called, the function ser_phy_close has to be called before ser_phy_open can be called again.
- Parameters
-
[in] events_handler Generic callback function handler to be used by all PHY module events.
- Return values
-
NRF_SUCCESS Operation success. NRF_ERROR_INVALID_STATE Operation failure. The function has been already called. To call it again, the function ser_phy_close has to be called first. NRF_ERROR_NULL Operation failure. NULL pointer supplied. NRF_ERROR_INVALID_PARAM Operation failure. Hardware initialization parameters are not supported.
| uint32_t ser_phy_rx_buf_set | ( | uint8_t * | p_buffer | ) |
Function for setting an RX buffer and enabling reception of data (the PHY flow).
- Note
- The function has to be called as a response to an event of type SER_PHY_EVT_RX_BUF_REQUEST . The function sets an RX buffer and enables reception of data (enables the PHY flow). Size of a buffer pointed by the p_buffer parameter should be at least equal to the num_of_bytes parameter passed within the event ( ser_phy_evt_rx_buf_request_params_t ), or p_buffer should be equal to NULL if there is not enough memory. When p_buffer is different from NULL and num_of_bytes octets have been received, an event of type SER_PHY_EVT_RX_PKT_RECEIVED is generated ( ser_phy_evt_rx_pkt_received_params_t ). When p_buffer is equal to NULL, data is received to dummy location to ensure continuous communication. Then, if num_of_bytes octets have been received, an event of type SER_PHY_EVT_RX_PKT_DROPPED is generated.
- Parameters
-
[in] p_buffer Pointer to an RX buffer in which to receive.
- Return values
-
NRF_SUCCESS Operation success. NRF_ERROR_INVALID_STATE Operation failure. A buffer was set without request.
| uint32_t ser_phy_tx_pkt_send | ( | const uint8_t * | p_buffer , |
| uint16_t | num_of_bytes | ||
| ) |
Function for transmitting a packet.
- Note
- The function adds a packet pointed by p_buffer parameter to a transmission queue and schedules generation of an event of type SER_PHY_EVT_TX_PKT_SENT upon transmission completion.
- Parameters
-
[in] p_buffer Pointer to a buffer to transmit. [in] num_of_bytes Number of octets to transmit. Must be more than 0.
- Return values
-
NRF_SUCCESS Operation success. Packet was added to the transmission queue and event will be send upon transmission completion. NRF_ERROR_NULL Operation failure. NULL pointer supplied. NRF_ERROR_INVALID_PARAM Operation failure. The num_of_bytes parameter equal to 0. NRF_ERROR_BUSY Operation failure. Transmitting of a packet in progress.