Basic Configuration¶
In this section we will cover how to configure the IEEE PHY and how to schedule basic TX/RX commands for a more detailed explanation on how to configure the PHY and the differences between command types go to:
Before running any radio operation command described in this section, the radio must be set up in IEEE 802.15.4 mode using the command CMD_RADIO_SETUP. Otherwise, the operation will end with error.
In IEEE 802.15.4 mode, the radio CPU shall accept two levels of radio operation commands. Operations can run in the background level or in the foreground level. Each operation can only run in one of these levels. Operations in the foreground level normally require a background level operation to be running at the same time.
The background level operations are the receive and energy detect scan operations. Only one of these can run at a time. The foreground level operations are the CSMA-CA operation, the receive ACK operation, the transmit operation, the abort background level operation, and the modify radio setup operation. These can be entered as a single command or a command chain even if a background level operation is running. The CSMA-CA and receive ACK operations will run simultaneously with the background level operation. The transmit operation will cause the background level operation to be suspended until the transmission is done. The allowed combinations of background and foreground level operations are shown in Table 6. Violation of this shall cause an error when the foreground level command is about to start, signaled by the ERROR_WRONG_BG status in the status field of the foreground level command structure.
‘Foreground level operation’ |
‘Background level operation’ |
||
None |
CMD_IEEE_RX |
CMD_IEEE_ED_SCAN |
|
None |
Allowed |
Allowed |
Allowed |
CMD_IEEE_TX |
Allowed |
Allowed |
Allowed |
CMD_IEEE_CSMA |
Forbidden |
Allowed |
Allowed |
CMD_IEEE_RX_ACK |
Forbidden |
Allowed |
Forbidden |
CMD_IEEE_ABORT_BG |
Allowed |
Allowed |
Allowed |
CMD_IEEE_SETUP |
Allowed |
Allowed |
Allowed |
CMD_FG_NOP |
Allowed |
Allowed |
Allowed |
CMD_FG_COUNT |
Allowed |
Allowed |
Allowed |
CMD_FG_SCH_IMM |
Allowed |
Allowed |
Allowed |
CMD_FG_COUNT_BRANCH |
Allowed |
Allowed |
Allowed |
CMD_FG_PATTERN_CHECK |
Allowed |
Allowed |
Allowed |
For more information, a more detailed description is given in the CC13x2 CC26x2 SimpleLink Wireless MCU Technical Reference Manual.
PHY configuration¶
After following
PHY Configuration
you should be ready to import one of the examples included in the PropRF/
folder
(we recommend starting with rfPacketTX/RX). All of the PHY configuration should be
done and applied using syscfg.
Once all PHY modifications are completed you should be able to preview the ti_radio_config.[c|h]
files generated by syscfg. These files will have all the commands necessary to operate the device in IEEE mode.
Setup Command¶
Setting up the radio is no different than previously explained in
PHY Configuration , make sure to follow the name of the new
radio config structures for IEEE mode in ti_radio_config.[c|h]
files.:
RF_Params rfParams;
RF_Params_init(&rfParams);
rfParams.nID = RF_STACK_ID_154;
/* Request access to the radio */
rfHandle = RF_open((RF_Object *)&rfObject, &RF_prop_ieee154, (RF_RadioSetup*) &RF_cmdRadioSetup, &rfParams);
/* Set the frequency */
RF_postCmd(rfHandle, (RF_Op*)&RF_cmdFs_ieee154, RF_PriorityNormal, NULL, 0);
RX Operation¶
The receive radio operation is a background level operation. It is started with the CMD_IEEE_RX command.
At the start of an Rx operation, the radio CPU shall wait for the start trigger. It shall then program the
frequency based on the channel
parameter. If channel
is 0xFF, the operation shall keep running on a
channel already configured. This requires that the operation follows another receive operation or a synthesizer
programming operation. If the frequency synthesizer is not running, the operation will end with error. After
programming the frequency, the radio CPU shall configure the receiver to receive IEEE 802.15.4 packets.
The number of bytes given by the received PHY header are received and stored in the receive queue given by pRxQ
.
If there is no available Rx buffer with enough available space to hold the received packet, the received data shall
be discarded. If frameFiltOpt.frameFiltStop
is 1, the reception shall be stopped, otherwise the packet shall be received
so that the CRC can be checked.
Setting up Rx Buffer¶
In order to prep the radio for RX, you must first define a Queue to receive messages. This is already included in the rfPacketRx example, but we will show it below:
Let’s first define important parameters about the packet format and length:
/* Packet RX Configuration */
#define MAX_LENGTH 256 /* Max length byte the radio will accept */
#define NUM_DATA_ENTRIES 2 /* NOTE: Only two data entries supported at the moment */
#define MAC_PHY_PHR_IEEE_LEN 1
#define MAC_RSSI_LEN 1
#define MAC_TS_LEN 4
#define MAC_FCS2_FIELD_LEN 2 /* 2-byte FCS field */
#define NUM_APPENDED_BYTES MAC_PHY_PHR_IEEE_LEN + MAC_RSSI_LEN + MAC_TS_LEN + MAC_FCS2_FIELD_LEN
Now let’s define the structures necessary to store these packets:
#pragma DATA_ALIGN (rxRadioBufferPtr, 4);
static uint8_t
rxRadioBufferPtr[RF_QUEUE_DATA_ENTRY_BUFFER_SIZE(NUM_DATA_ENTRIES,
MAX_LENGTH,
NUM_APPENDED_BYTES)];
static dataQueue_t macRxDataEntryQueue;
static rfc_ieeeRxOutput_t macRxOutputIeee;
We need to assign a Callback function to the RX operation command. This callback function will be used to handle the received data:
static void macRxCb(RF_Handle h, RF_CmdHandle ch, RF_EventMask e){
currentDataEntry = RFQueue_getDataEntry();
RFQueue_nextEntry();
if (e & RF_EventRxOk)
{
packetLength = (currentDataEntry->data - MAC_FCS2_FIELD_LEN);
PIN_setOutputValue(ledPinHandle, CONFIG_PIN_RLED,!PIN_getOutputValue(CONFIG_PIN_RLED));
}
}
Now that we have all of our structs and constant values defined, lets set up the Queue and the RX command:
void *mainThread(void *arg0)
{
RF_Params rfParams;
RF_Params_init(&rfParams);
rfParams.nID = RF_STACK_ID_154;
//Define Queue for RX operation
if( RFQueue_defineQueue(&macRxDataEntryQueue,
rxRadioBufferPtr,
sizeof(rxRadioBufferPtr),
NUM_DATA_ENTRIES,
MAX_LENGTH + NUM_APPENDED_BYTES))
{
while(1);
}
/* Request access to the radio */
rfHandle = RF_open((RF_Object *)&rfObject, &RF_prop_ieee154, (RF_RadioSetup*) &RF_cmdRadioSetup, &rfParams);
/* Set the frequency */
RF_postCmd(rfHandle, (RF_Op*)&RF_cmdFs_ieee154, RF_PriorityNormal, NULL, 0);
//Let's start defining the RX operation scheduling command
RF_ScheduleCmdParams rxParam;
RF_ScheduleCmdParams_init(&rxParam);
//Events that will trigger the Callback Function
RF_EventMask evtMask = RF_EventRxOk | RF_EventRxNOk | RF_EventRxBufFull | RF_EventTXAck | RF_EventCmdPreempted;
/* Set the RX cmd satus to IDLE*/
RF_cmdIEEERx.status = IDLE;
/* Set receive queue and output buffer */
RF_cmdIEEERx.pRxQ = (dataQueue_t*)&macRxDataEntryQueue;
RF_cmdIEEERx.pOutput = (rfc_ieeeRxOutput_t *)&macRxOutputIeee;
//Set the Rx command to trigger as soon as the command is scheduled
RF_cmdIEEERx.startTime = 0;
RF_cmdIEEERx.startTrigger.triggerType = TRIG_NOW;
RF_cmdIEEERx.startTrigger.pastTrig = 1;
//Set the operating Channel
RF_cmdIEEERx.channel = 11;
/* Post the RX cmd */
RF_scheduleCmd(rfHandle, (RF_Op*)&RF_cmdIEEERx,
&rxParam, macRxCb, evtMask);
while(1);
}
This simple code will setup the radio to operate in IEEE mode, and schedule a Rx
command to listen to channel 11 and trigger a callback for EvtMask
events. Since
the device has no other scheduled commands, it will run forever in RX mode and triggering
the callback everytime it receives a packet.
For more information, a more detailed description is given in the CC13x2 CC26x2 SimpleLink Wireless MCU Technical Reference Manual.