Data Management

Data management functions.

Data Structures

struct  RAIL_DataConfig_t
 RAIL data configuration structure.

Enumerations

enum  RAIL_TxDataSource_t { TX_PACKET_DATA }
 Transmit data sources supported by RAIL.
 
enum  RAIL_RxDataSource_t {
  RX_PACKET_DATA,
  RX_DEMOD_DATA,
  RX_IQDATA_FILTLSB,
  RX_IQDATA_FILTMSB
}
 Receive data sources supported by RAIL.
 
enum  RAIL_DataMethod_t {
  PACKET_MODE,
  FIFO_MODE
}
 Methods for the application to provide and retrieve data from RAIL.

Functions

RAIL_Status_t RAIL_ConfigData (RAIL_Handle_t railHandle, const RAIL_DataConfig_t *dataConfig)
 RAIL data management configuration.
 
uint16_t RAIL_WriteTxFifo (RAIL_Handle_t railHandle, const uint8_t *dataPtr, uint16_t writeLength, bool reset)
 Writes data to the transmit FIFO.
 
uint16_t RAIL_SetTxFifo (RAIL_Handle_t railHandle, uint8_t *addr, uint16_t initLength, uint16_t size)
 Sets the address of the TX FIFO, a circular buffer used for TX data.
 
RAIL_Status_t RAIL_SetRxFifo (RAIL_Handle_t railHandle, uint8_t *addr, uint16_t *size)
 Sets the address of the RX FIFO, a circular buffer used for RX data.
 
RAIL_Status_t RAILCb_SetupRxFifo (RAIL_Handle_t railHandle)
 Sets up the receive FIFO to use.
 
uint16_t RAIL_ReadRxFifo (RAIL_Handle_t railHandle, uint8_t *dataPtr, uint16_t readLength)
 Reads packet data from RAIL's internal receive FIFO buffer.
 
uint16_t RAIL_SetTxFifoThreshold (RAIL_Handle_t railHandle, uint16_t txThreshold)
 Configures the RAIL transmit FIFO almost empty threshold.
 
uint16_t RAIL_SetRxFifoThreshold (RAIL_Handle_t railHandle, uint16_t rxThreshold)
 Configures the RAIL receive FIFO almost full threshold.
 
uint16_t RAIL_GetTxFifoThreshold (RAIL_Handle_t railHandle)
 Gets the RAIL transmit FIFO almost empty threshold value.
 
uint16_t RAIL_GetRxFifoThreshold (RAIL_Handle_t railHandle)
 Gets the RAIL receive FIFO almost full threshold value.
 
void RAIL_ResetFifo (RAIL_Handle_t railHandle, bool txFifo, bool rxFifo)
 Resets the RAIL FIFOs.
 
uint16_t RAIL_GetRxFifoBytesAvailable (RAIL_Handle_t railHandle)
 Gets the number of bytes available in the receive FIFO.
 
uint16_t RAIL_GetTxFifoSpaceAvailable (RAIL_Handle_t railHandle)
 Gets the number of bytes open in the transmit FIFO.

Detailed Description

Data management functions.

These functions allow the application to choose how data is presented to the application. RAIL provides data in a packet-based method or in a FIFO-based method which gives the application more granularity and responsibility in managing transmit and receive data and allows packet sizes larger than the RX or TX FIFO buffers.

The application can configure RAIL data management through RAIL_ConfigData(). This function allows the application to specify the type of radio data (RAIL_TxDataSource_t and RAIL_RxDataSource_t) and the method of interacting with data (RAIL_DataMethod_t). By default, RAIL configures TX and RX both with packet data source and packet mode.

In packet-based data management:

In FIFO-based data management:

When trying to determine an appropriate threshold, the application needs to know the size of each FIFO. The receive FIFO is internal to RAIL and its default size is 512 bytes. The receive FIFO is level-based in that the RAIL_EVENT_RX_FIFO_ALMOST_FULL event will constantly pend if the threshold is exceeded. This normally means that inside this event's callback, the application should empty enough of the FIFO to go under the threshold. To defer reading the FIFO to main context, the application can disable or re-enable the receive FIFO threshold event using RAIL_ConfigEvents() with the mask RAIL_EVENT_RX_FIFO_ALMOST_FULL.

The transmit FIFO is specified by the application and its size is the value returned from the most recent call to RAIL_SetTxFifo(). The transmit FIFO is edge-based in that it only provides the RAIL_EVENT_TX_FIFO_ALMOST_EMPTY event once when the threshold is crossed in the emptying direction.

In FIFO mode, FIFOs can store multiple packets. Depending on the traffic, RAIL can receive multiple packets into the receive FIFO before the application gets around to reading out the received data from the FIFO. RAIL_ReadRxFifo() won't allow reading beyond a packet boundary so process packet completion events promptly. Keep in mind that in FIFO mode, packet data already read from packets that are subsequently aborted, frameerror, or filtered should be flushed.

While RAIL defaults to packet mode, the application can explicitly initialize RAIL for packet mode in the following manner:

static const RAIL_DataConfig_t railDataConfig = {
.rxSource = RX_PACKET_DATA,
.txMethod = PACKET_MODE,
.rxMethod = PACKET_MODE,
};
status = RAIL_ConfigData(&railDataConfig);
// Events that can occur in Packet Mode:
and optionally (packet data automatically dropped):

Initializing RAIL for FIFO Mode requires a few more function calls:

static const RAIL_DataConfig_t railDataConfig = {
.rxSource = RX_PACKET_DATA,
.txMethod = FIFO_MODE,
.rxMethod = FIFO_MODE,
};
status = RAIL_ConfigData(&railDataConfig);
// Gets the size of the FIFOs.
// The transmit and receive FIFOs are the same size
uint16_t fifoSize = RAIL_GetTxFifoSpaceAvailable();
// Sets the transmit and receive FIFO thresholds.
// For this example, set the threshold in the middle of each FIFO.
// Events that can occur in FIFO mode:

On receive, an application can use multiple data sources that are only compatible with the FIFO method of data delivery. All that differs from the FIFO mode example above is the RAIL_DataConfig_t::rxSource setting. IQ data samples are taken at the hardware's oversample rate and the amount of data can easily overwhelm the CPU processing time. The sample rate depends on the chosen PHY, as determined by the data rate and the decimation chain. It is not recommended to use the IQ data source with sample rates above 300 k samples/second as the CPU might not be able to keep up with the data. Depending on the application and needed CPU bandwidth, slower data rates may be required.

// IQ data is provided into the receive FIFO.
static const RAIL_DataConfig_t railDataConfig = {
.rxSource = RX_IQDATA_FILTLSB,
.txMethod = FIFO_MODE,
.rxMethod = FIFO_MODE,
};
// IQ data comes in the following format when reading out of the FIFO:
//------------------------------------
// I[LSB] | I[MSB] | Q[LSB] | Q[MSB] |
//------------------------------------
Note
RAIL_DataConfig_t::txMethod and RAIL_DataConfig_t::rxMethod must have the same RAIL_DataMethod_t configuration.
Warning
Do not call RAIL_ReadRxFifo() function while in RAIL_DataMethod_t::PACKET_MODE.

Enumeration Type Documentation

Methods for the application to provide and retrieve data from RAIL.

Enumerator
PACKET_MODE 

Packet-based data method.

FIFO_MODE 

FIFO-based data method.

Definition at line 1260 of file rail_types.h.

Receive data sources supported by RAIL.

Enumerator
RX_PACKET_DATA 

Uses the frame hardware to packetize data.

RX_DEMOD_DATA 

Gets 8-bit data output from the demodulator.

RX_IQDATA_FILTLSB 

Gets lower 16 bits of I/Q data provided to the demodulator.

RX_IQDATA_FILTMSB 

Gets highest 16 bits of I/Q data provided to the demodulator.

Definition at line 1247 of file rail_types.h.

Transmit data sources supported by RAIL.

Enumerator
TX_PACKET_DATA 

Uses the frame hardware to packetize data.

Definition at line 1239 of file rail_types.h.

Function Documentation

RAIL_Status_t RAIL_ConfigData ( RAIL_Handle_t  railHandle,
const RAIL_DataConfig_t dataConfig 
)

RAIL data management configuration.

Parameters
[in]railHandleA RAIL instance handle.
[in]dataConfigRAIL data configuration structure.
Returns
Status code indicating success of the function call.

This function configures how RAIL manages data. The application can configure RAIL to receive data in a packet-based or FIFO-based format. FIFO mode is necessary to support packets larger than the radio's FIFO buffers.

With FIFO mode, the application sets appropriate FIFO thresholds via RAIL_SetTxFifoThreshold() and RAIL_SetRxFifoThreshold() and then enables and handles the RAIL_EVENT_TX_FIFO_ALMOST_EMPTY event callback (to feed more packet data via RAIL_WriteTxFifo() before the FIFO underflows) and the RAIL_EVENT_RX_FIFO_ALMOST_FULL event callback (to consume packet data via RAIL_ReadRxFifo() before the RX FIFO overflows).

When configuring TX or RX for FIFO mode, this function resets the configured FIFOs. When configuring TX or RX for Packet mode, this function will reset the corresponding FIFO thresholds such that they won't trigger the RAIL_EVENT_RX_FIFO_ALMOST_FULL or RAIL_EVENT_TX_FIFO_ALMOST_EMPTY events.

When RAIL_DataConfig_t::rxMethod is set to RAIL_DataMethod_t::FIFO_MODE, the radio won't drop packet data of aborted or CRC error packets, but will present it to the application to deal with accordingly. On completion of erroneous packets, the RAIL_Config_t::eventsCallback with RAIL_EVENT_RX_PACKET_ABORTED, RAIL_EVENT_RX_FRAME_ERROR, or RAIL_EVENT_RX_ADDRESS_FILTERED will tell the application it can drop any data it read via RAIL_ReadRxFifo() during reception. For CRC error packets when the RAIL_RX_OPTION_IGNORE_CRC_ERRORS RX option is in effect, the application should check for that from the RAIL_RxPacketStatus_t obtained by calling RAIL_GetRxPacketInfo(). RAIL will automatically flush any remaining packet data after reporting one of these packet completion events or the application can explicitly flush it by calling RAIL_ReleaseRxPacket().

When RAIL_DataConfig_t::rxMethod is set to RAIL_DataMethod_t::PACKET_MODE, the radio will drop all packet data associated with aborted packets including those with CRC errors (unless configured to ignore CRC errors via the RAIL_RX_OPTION_IGNORE_CRC_ERRORS RX option). The application will never have to deal with packet data from these packets.

In either mode, the application can set RX options as needed. Packet details are not available for aborted packets.

uint16_t RAIL_GetRxFifoBytesAvailable ( RAIL_Handle_t  railHandle)

Gets the number of bytes available in the receive FIFO.

This function should only be used in RX FIFO mode. Apps should use RAIL_GetRxPacketInfo() instead.

Parameters
[in]railHandleA RAIL instance handle.
Returns
Number of raw bytes in the receive FIFO.
Note
The number of bytes returned may not just reflect the current packet's data but could also include raw appended info bytes added after successful packet reception and bytes from subsequently received packets. It is up to the app to never try to consume more than the packet's actual data when using the value returned here in a subsequent call to RAIL_ReadRxFifo(), otherwise the Rx buffer will be corrupted.
uint16_t RAIL_GetRxFifoThreshold ( RAIL_Handle_t  railHandle)

Gets the RAIL receive FIFO almost full threshold value.

Parameters
[in]railHandleA RAIL instance handle.
Returns
Configured RX Threshold value.

Retrieves the configured RX threshold value.

uint16_t RAIL_GetTxFifoSpaceAvailable ( RAIL_Handle_t  railHandle)

Gets the number of bytes open in the transmit FIFO.

Parameters
[in]railHandleA RAIL instance handle.
Returns
Number of bytes open in the transmit FIFO.

Gets the number of bytes open in the transmit FIFO.

uint16_t RAIL_GetTxFifoThreshold ( RAIL_Handle_t  railHandle)

Gets the RAIL transmit FIFO almost empty threshold value.

Parameters
[in]railHandleA RAIL instance handle.
Returns
Configured TX Threshold value.

Retrieves the configured TX threshold value.

uint16_t RAIL_ReadRxFifo ( RAIL_Handle_t  railHandle,
uint8_t *  dataPtr,
uint16_t  readLength 
)

Reads packet data from RAIL's internal receive FIFO buffer.

This function can be used in any RX mode, though in Packet mode it can only be used on the oldest unreleased packet whose RAIL_RxPacketStatus_t is among the RAIL_RX_PACKET_READY_ set.

Parameters
[in]railHandleA RAIL instance handle.
[out]dataPtrAn application-provided pointer to store data. If NULL, the data is thrown away rather than copied out.
[in]readLengthA number of packet bytes to read from the FIFO.
Returns
The number of packet bytes read from the receive FIFO.

This function reads packet data from the head of receive FIFO and writes it to the provided dataPtr. It does not permit reading more data than is available in the FIFO, nor does it permit reading more data than remains in the oldest unreleased packet.

Because this function does not have a critical section, use it only in one context or make sure function calls are protected to prevent buffer corruption.

Note
When reading data from an arriving packet that is not yet complete, keep in mind its data is highly suspect because it has not yet passed any CRC integrity checking. Also note that the packet could be aborted, cancelled, or fail momentarily, invalidating its data in Packet mode. Furthermore, there is a small chance towards the end of packet reception that the RX FIFO could include not only packet data received so far, but also some raw radio-appended info detail bytes that RAIL's packet-completion processing will subsequently deal with. It's up to the application to know its packet format well enough to avoid reading this info as it will corrupt the packet's details and possibly corrupt the RX FIFO buffer.
void RAIL_ResetFifo ( RAIL_Handle_t  railHandle,
bool  txFifo,
bool  rxFifo 
)

Resets the RAIL FIFOs.

Parameters
[in]railHandleA RAIL instance handle.
[in]txFifoIf true, reset the transmit FIFO.
[in]rxFifoIf true, reset the receive FIFO.
Returns
void.

This function can reset each FIFO. The application should not reset the RX FIFO while receiving a frame.

RAIL_Status_t RAIL_SetRxFifo ( RAIL_Handle_t  railHandle,
uint8_t *  addr,
uint16_t *  size 
)

Sets the address of the RX FIFO, a circular buffer used for RX data.

Parameters
[in]railHandleA RAIL instance handle.
[in,out]addrA pointer to a read-write memory location in RAM used as the RX FIFO. This memory must persist until the next call to this function.
[in,out]sizeA desired size of the RX FIFO in bytes. This will be populated with the actual size during the function call.
Returns
Status code indicating success of the function call.

This function sets the memory location for the RX FIFO. It must be called at least once before any receive operations occur.

The FIFO size can be determined by the value of size after this function. The chosen size is determined based on the available FIFO sizes supported by the hardware. For more on supported FIFO sizes and required alignments, see chip-specific documentation, such as EFR32. The returned FIFO size will be the closest allowed size less than or equal to the passed in size parameter, unless the size parameter is smaller than the minimum FIFO size.

This function reserves the block of RAM starting at addr with a length of size, which is used internally as a circular buffer for the receive FIFO. It must be able to hold the entire FIFO size. The caller must guarantee that the custom FIFO remains intact and unchanged (except via incoming packet data being written) until the next call to this function.

In multiprotocol, RAIL currently shares one receive FIFO across all protocols. This function will return RAIL_STATUS_INVALID_STATE if the requested RAIL_Handle_t is not active.

uint16_t RAIL_SetRxFifoThreshold ( RAIL_Handle_t  railHandle,
uint16_t  rxThreshold 
)

Configures the RAIL receive FIFO almost full threshold.

Parameters
[in]railHandleA RAIL instance handle.
[in]rxThresholdThe threshold once exceeded will fire RAIL_Config_t::eventsCallback with RAIL_EVENT_RX_FIFO_ALMOST_FULL set.
Returns
Configured receive FIFO threshold value.

This function configures the threshold for the receive FIFO. When the count of the receive FIFO is greater than the configured threshold, RAIL_Config_t::eventsCallback will fire with RAIL_EVENT_RX_FIFO_ALMOST_FULL set. A value of 0xFFFF is invalid and will not change the current configuration. Depending on the size of the receive FIFO hardware, the maximum value can vary. If the rxThreshold value exceeds the capability of the hardware, the RX threshold will be configured so that it fires only when the FIFO is one byte away from being full.

uint16_t RAIL_SetTxFifo ( RAIL_Handle_t  railHandle,
uint8_t *  addr,
uint16_t  initLength,
uint16_t  size 
)

Sets the address of the TX FIFO, a circular buffer used for TX data.

Parameters
[in]railHandleA RAIL instance handle.
[in,out]addrA pointer to a read-write memory location in RAM used as the TX FIFO. This memory must persist until the next call to this function.
[in]initLengthA number of initial bytes already in the TX FIFO.
[in]sizeA desired size of the TX FIFO in bytes.
Returns
Returns the FIFO size in bytes.

This function sets the memory location for the TX FIFO. It must be called at least once before any transmit operations occur.

The FIFO size can be determined by the return value of this function. The chosen size is determined based on the available FIFO sizes supported by the hardware. For more on supported FIFO sizes and alignments, see chip-specific documentation, such as EFR32. The returned FIFO size will be the closest allowed size less than or equal to the passed in size parameter, unless the size parameter is smaller than the minimum FIFO size. If the initLength parameter is larger than the returned size, the FIFO will be filled up to its size.

A user may write to the custom memory location directly before calling this function, or use RAIL_WriteTxFifo to write to the memory location after calling this function. Users must specify the initLength for previously-written memory to be set in the TX FIFO.

This function reserves the block of RAM starting at addr with a length of the returned FIFO size, which is used internally as a circular buffer for the transmit FIFO. It must be able to hold the entire FIFO size. The caller must guarantee that the custom FIFO remains intact and unchanged (except via calls to RAIL_WriteTxFifo) until the next call to this function.

Note
The protocol's packet configuration, as set up by the radio configurator or via RAIL_SetFixedLength(), determines how many bytes of data are consumed from the TX FIFO for a successful transmit operation, not the initLength value passed in. If not enough data has been put into the TX FIFO, a RAIL_EVENT_TX_UNDERFLOW event will occur. If too much data is put into the TX FIFO, the extra data will either become the first bytes sent in a subsequent packet, or will be thrown away if the FIFO gets reset prior to the next transmit. In general, the proper number of packet bytes to put into the TX FIFO are all payload bytes except for any CRC bytes which the packet configuration causes to be sent automatically.
uint16_t RAIL_SetTxFifoThreshold ( RAIL_Handle_t  railHandle,
uint16_t  txThreshold 
)

Configures the RAIL transmit FIFO almost empty threshold.

Parameters
[in]railHandleA RAIL instance handle.
[in]txThresholdThe threshold once fallen under will fire RAIL_Config_t::eventsCallback with RAIL_EVENT_TX_FIFO_ALMOST_EMPTY set.
Returns
Configured transmit FIFO threshold value.

This function configures the threshold for the transmit FIFO. When the count of the transmit FIFO is less than the configured threshold, RAIL_Config_t::eventsCallback will fire with RAIL_EVENT_TX_FIFO_ALMOST_EMPTY set. A value of 0 is invalid and will not change the current configuration.

uint16_t RAIL_WriteTxFifo ( RAIL_Handle_t  railHandle,
const uint8_t *  dataPtr,
uint16_t  writeLength,
bool  reset 
)

Writes data to the transmit FIFO.

Parameters
[in]railHandleA RAIL instance handle.
[in]dataPtrAn application-provided pointer to transmit data.
[in]writeLengthA number of bytes to write to the transmit FIFO.
[in]resetIf true, resets TX FIFO before writing the data.
Returns
The number of bytes written to the transmit FIFO.

This function reads data from the provided dataPtr and writes it to the TX FIFO. If the requested writeLength exceeds the current number of bytes open in the transmit FIFO, the function only writes until the transmit FIFO is full. The function returns the number of bytes written to the transmit FIFO or returns zero if railHandle is NULL or if the TX FIFO is full.

Note
The protocol's packet configuration, as set up by the radio configurator or via RAIL_SetFixedLength(), determines how many bytes of data are consumed from the TX FIFO for a successful transmit operation, not the writeLength value passed in. If not enough data has been put into the TX FIFO, a RAIL_EVENT_TX_UNDERFLOW event will occur. If too much data is put into the TX FIFO, the extra data will either become the first bytes sent in a subsequent packet, or will be thrown away if the FIFO gets reset prior to the next transmit. In general, the proper number of packet bytes to put into the TX FIFO are all payload bytes except for any CRC bytes, which the packet configuration causes to be sent automatically.
This function does not create a critical section but, depending on the application, a critical section could be appropriate.
RAIL_Status_t RAILCb_SetupRxFifo ( RAIL_Handle_t  railHandle)

Sets up the receive FIFO to use.

This function is optional to implement.

Parameters
[in]railHandleA RAIL instance handle.
Returns
Status code indicating success of the function call.

This function is called during the RAIL_Init process to set up the FIFO to use for received packets. If not implemented by the application, a default implementation from within the RAIL library will be used to initialize a 512 byte FIFO.

If this function returns an error, then the RAIL_Init process will fail.

During this function, the application should generally call RAIL_SetRxFifo. If that does not happen, then the application needs to set up the receive FIFO via a call to RAIL_SetRxFifo before attempting to receive any packets. An example implementation may look like the following:

#define RX_FIFO_SIZE 1024
static uint8_t rxFifo[RX_FIFO_SIZE];
{
uint16_t rxFifoSize = RX_FIFO_SIZE;
RAIL_Status_t status = RAIL_SetRxFifo(railHandle, &rxFifo[0], &rxFifoSize);
if (rxFifoSize != RX_FIFO_SIZE) {
// We set up an incorrect FIFO size
}
if (status == RAIL_STATUS_INVALID_STATE) {
// Allow failures due to multiprotocol
}
return status;
}