EFR32 Mighty Gecko 13 Software Documentation  efr32mg13-doc-5.1.2
ezradio_transmit_plugin.c
Go to the documentation of this file.
1 /***************************************************************************/
33 #include <stddef.h>
34 #include <stdbool.h>
35 
36 #include "em_device.h"
37 
38 #include "ezradio_cmd.h"
39 #include "ezradio_prop.h"
40 #include "ezradio_api_lib.h"
41 #include "ezradio_api_lib_add.h"
42 #include "ezradio_plugin_manager.h"
44 
45 #if defined( EZRADIO_PLUGIN_TRANSMIT )
46 
48 
49 static Ecode_t ezradioStartTx(EZRADIODRV_Handle_t radioHandle, bool updateFields, EZRADIODRV_PacketLengthConfig_t pktLengthConf, uint8_t *pioRadioPacket);
50 
51 #if defined(EZRADIO_PLUGIN_AUTO_ACK) && defined(EZRADIO_PLUGIN_RECEIVE)
52 Ecode_t ezradioHandleAutoAckPlugin( EZRADIODRV_Handle_t radioHandle, EZRADIODRV_ReplyHandle_t radioReplyHandle );
53 #endif
54 
56 
57 /**************************************************************************/
70 Ecode_t ezradioStartTransmitBasic(EZRADIODRV_Handle_t radioHandle, uint16_t packetLength, uint8_t *pioRadioPacket)
71 {
72  /* Set default field configuration from the generated header file */
73  EZRADIODRV_PacketLengthConfig_t pktLengthConf =
74  { ezradiodrvTransmitLenghtCustomPacketLen, packetLength, { 0 } };
75 
76  bool updateFields = false;
77 
78  if ( radioHandle == NULL )
79  {
81  }
82 
83 
84  /* Radio field condfig has to be updated if the configuration is different from the previous */
86  (radioHandle->packetTx.lenConfig.pktLen != packetLength ) ||
87  (radioHandle->packetTx.lenConfig.fieldLen.f1 != (uint8_t)packetLength ) )
88  {
89  updateFields = true;
90  pktLengthConf.fieldLen.f1 = (uint8_t)packetLength;
91  pktLengthConf.fieldLen.f2 = 0u;
92  pktLengthConf.fieldLen.f3 = 0u;
93  pktLengthConf.fieldLen.f4 = 0u;
94  pktLengthConf.fieldLen.f5 = 0u;
95  }
96 
97  ezradioStartTx(radioHandle, updateFields, pktLengthConf, pioRadioPacket);
98 
100 }
101 
102 /**************************************************************************/
114 Ecode_t ezradioStartTransmitConfigured(EZRADIODRV_Handle_t radioHandle, uint8_t *pioRadioPacket)
115 {
116  /* Set default field configuration from the generated header file */
117  EZRADIODRV_PacketLengthConfig_t pktLengthConf =
118  { ezradiodrvTransmitLenghtDefault, RADIO_CONFIG_DATA_MAX_PACKET_LENGTH, RADIO_CONFIG_DATA_FIELD_LENGTH };
119 
120  bool updateFields = false;
121 
122  if ( radioHandle == NULL )
123  {
125  }
126 
127  /* Radio field config has to be updated if the configuration is different from the previous */
129  (radioHandle->packetTx.lenConfig.pktLen != pktLengthConf.pktLen ) ||
130  (radioHandle->packetTx.lenConfig.fieldLen.f1 != pktLengthConf.fieldLen.f1 ) ||
131  (radioHandle->packetTx.lenConfig.fieldLen.f2 != pktLengthConf.fieldLen.f2 ) ||
132  (radioHandle->packetTx.lenConfig.fieldLen.f3 != pktLengthConf.fieldLen.f3 ) ||
133  (radioHandle->packetTx.lenConfig.fieldLen.f4 != pktLengthConf.fieldLen.f4 ) ||
134  (radioHandle->packetTx.lenConfig.fieldLen.f5 != pktLengthConf.fieldLen.f5 ) )
135  {
136  updateFields = true;
137  }
138 
139  ezradioStartTx(radioHandle, updateFields, pktLengthConf, pioRadioPacket);
140 
142 }
143 
144 /**************************************************************************/
157 Ecode_t ezradioStartTransmitCustom(EZRADIODRV_Handle_t radioHandle, EZRADIODRV_PacketLengthConfig_t pktLengthConf, uint8_t *pioRadioPacket)
158 {
159  bool updateFields = false;
160 
161  if ( radioHandle == NULL )
162  {
164  }
165 
166  /* Radio field config has to be updated if the configuration is different from the previous */
168  (radioHandle->packetTx.lenConfig.pktLen != pktLengthConf.pktLen ) ||
169  (radioHandle->packetTx.lenConfig.fieldLen.f1 != pktLengthConf.fieldLen.f1 ) ||
170  (radioHandle->packetTx.lenConfig.fieldLen.f2 != pktLengthConf.fieldLen.f2 ) ||
171  (radioHandle->packetTx.lenConfig.fieldLen.f3 != pktLengthConf.fieldLen.f3 ) ||
172  (radioHandle->packetTx.lenConfig.fieldLen.f4 != pktLengthConf.fieldLen.f4 ) ||
173  (radioHandle->packetTx.lenConfig.fieldLen.f5 != pktLengthConf.fieldLen.f5 ) )
174  {
175  updateFields = true;
176  }
177 
178  ezradioStartTx(radioHandle, updateFields, pktLengthConf, pioRadioPacket);
179 
181 }
182 
183 /**************************************************************************/
198 Ecode_t ezradioStartTransmitSmart(EZRADIODRV_Handle_t radioHandle, EZRADIODRV_PacketLengthConfig_t pktLengthConf, uint8_t *pioRadioPacket)
199 {
200  if ( radioHandle == NULL )
201  {
203  }
204 
206  {
207  ezradioStartTransmitBasic(radioHandle, pktLengthConf.pktLen, pioRadioPacket);
208  }
209  else if (pktLengthConf.lenMode == ezradiodrvTransmitLenghtDefault)
210  {
211  ezradioStartTransmitConfigured(radioHandle, pioRadioPacket);
212  }
213  else if (pktLengthConf.lenMode == ezradiodrvTransmitLenghtCustomFieldLen)
214  {
215  ezradioStartTransmitCustom(radioHandle, pktLengthConf, pioRadioPacket);
216  }
217 
219 }
220 
221 /**************************************************************************/
234 Ecode_t ezradioStartTransmitDefault(EZRADIODRV_Handle_t radioHandle, uint8_t *pioRadioPacket)
235 {
236  if ( radioHandle == NULL )
237  {
239  }
240 
241  ezradioStartTransmitSmart(radioHandle, radioHandle->packetTx.lenConfig, pioRadioPacket);
242 
244 }
245 
247 // Note: These are internal routines used by ezradio plugin manager.
248 
249 /**************************************************************************/
259 Ecode_t ezradioHandleTransmitPlugin( EZRADIODRV_Handle_t radioHandle, EZRADIODRV_ReplyHandle_t radioReplyHandle )
260 {
261  if ( radioHandle == NULL )
262  {
264  }
265 
266  if ( radioReplyHandle->GET_INT_STATUS.PH_PEND & EZRADIO_CMD_GET_INT_STATUS_REP_PH_PEND_PACKET_SENT_PEND_BIT )
267  {
268 #if defined(EZRADIO_PLUGIN_AUTO_ACK) && defined(EZRADIO_PLUGIN_RECEIVE)
269  /* Handle auto acknowledge packet if enabled */
270  if ( (radioHandle->packetTx.pktType == ezradiodrvPacketTypeAutoAck) &&
271  (radioHandle->autoAck.ackMode == ezradiodrvAutoAckImmediate) )
272  {
273  ezradioHandleAutoAckPlugin(radioHandle, radioReplyHandle);
274  }
275  else
276 #endif //#if defined(EZRADIO_PLUGIN_AUTO_ACK) && defined(EZRADIO_PLUGIN_RECEIVE)
277  if ( radioHandle->packetTx.userCallback != NULL )
278  {
279  radioHandle->packetTx.userCallback( radioHandle, ECODE_EMDRV_EZRADIODRV_OK );
280  }
281 
282  }
283 
285 }
286 
287 /**************************************************************************/
303 static Ecode_t ezradioStartTx(EZRADIODRV_Handle_t radioHandle, bool updateFields, EZRADIODRV_PacketLengthConfig_t pktLengthConf, uint8_t *pioRadioPacket)
304 {
305  ezradio_cmd_reply_t ezradioReply;
306 
307  if ( radioHandle == NULL )
308  {
310  }
311 
312  /* Request and check radio device state */
313  ezradio_request_device_state(&ezradioReply);
314 
315  if (ezradioReply.REQUEST_DEVICE_STATE.CURR_STATE == EZRADIO_CMD_REQUEST_DEVICE_STATE_REP_CURR_STATE_MAIN_STATE_ENUM_TX) {
317  }
318 
319  /* Update radio packet filed configurations if requested */
320  if (updateFields)
321  {
322  radioHandle->packetTx.lenConfig.lenMode = pktLengthConf.lenMode;
323  radioHandle->packetTx.lenConfig.pktLen = 0;
324  radioHandle->packetTx.lenConfig.pktLen += radioHandle->packetTx.lenConfig.fieldLen.f1 = pktLengthConf.fieldLen.f1;
325  radioHandle->packetTx.lenConfig.pktLen += radioHandle->packetTx.lenConfig.fieldLen.f2 = pktLengthConf.fieldLen.f2;
326  radioHandle->packetTx.lenConfig.pktLen += radioHandle->packetTx.lenConfig.fieldLen.f3 = pktLengthConf.fieldLen.f3;
327  radioHandle->packetTx.lenConfig.pktLen += radioHandle->packetTx.lenConfig.fieldLen.f4 = pktLengthConf.fieldLen.f4;
328  radioHandle->packetTx.lenConfig.pktLen += radioHandle->packetTx.lenConfig.fieldLen.f5 = pktLengthConf.fieldLen.f5;
329 
330 #if (RADIO_CONFIGURATION_DATA_RADIO_CHIP_FAMILY == RADIO_CHIP_FAMILY_EZRADIOPRO)
331 
333  EZRADIO_PROP_GRP_ID_PKT, 2u,
334  EZRADIO_PROP_GRP_INDEX_PKT_FIELD_1_LENGTH,
335  0, pktLengthConf.fieldLen.f1
336  );
337 
339  EZRADIO_PROP_GRP_ID_PKT, 2u,
340  EZRADIO_PROP_GRP_INDEX_PKT_FIELD_2_LENGTH,
341  0, pktLengthConf.fieldLen.f2
342  );
343 
345  EZRADIO_PROP_GRP_ID_PKT, 2u,
346  EZRADIO_PROP_GRP_INDEX_PKT_FIELD_3_LENGTH,
347  0, pktLengthConf.fieldLen.f3
348  );
349 
351  EZRADIO_PROP_GRP_ID_PKT, 2u,
352  EZRADIO_PROP_GRP_INDEX_PKT_FIELD_4_LENGTH,
353  0, pktLengthConf.fieldLen.f4
354  );
355 
357  EZRADIO_PROP_GRP_ID_PKT, 2u,
358  EZRADIO_PROP_GRP_INDEX_PKT_FIELD_5_LENGTH,
359  0, pktLengthConf.fieldLen.f5
360  );
361 #endif //#if !(RADIO_CONFIG_DATA_RADIO_TYPE == 4455)
362  }
363 
364  /* Fill the TX fifo with datas */
365  ezradio_write_tx_fifo(radioHandle->packetTx.lenConfig.pktLen, pioRadioPacket);
366 
367  /* Start sending packet, channel 0, START immediately, Packet n bytes long, go READY when done */
368  ezradio_start_tx(radioHandle->packetTx.channel, 0x30, 0u);
369 
371 }
372 
374 
375 #endif //#if defined( EZRADIO_PLUGIN_TRANSMIT )
#define ECODE_EMDRV_EZRADIODRV_TRANSMIT_FAILED
Unable to start transmission.
EZRADIODRV_PacketTxHandle_t packetTx
Packet transmission plug-in handler.
Ecode_t ezradioStartTransmitDefault(EZRADIODRV_Handle_t radioHandle, uint8_t *pioRadioPacket)
Start a default transmission using the packet information previously set to radioHandle. Depending on the information in the radioHandle parameter the function decides which transmission function has to be called.
void ezradio_write_tx_fifo(uint8_t numbytes, uint8_t *pdata)
#define ECODE_EMDRV_EZRADIODRV_OK
Success return value.
uint8_t f1
Field 1 length.
uint8_t f5
Field 5 length.
uint8_t channel
Transmission channel.
Auto acknowledge packet type.
EZRADIODRV_TransmitLengthMode_t lenMode
Length mode.
This file contains the common API library of the EZRadio and EZRadioPRO families. ...
void ezradio_start_tx(uint8_t channel, uint8_t condition, uint16_t tx_len)
This file contains the plug-in manager for the EZRadio and EZRadioPRO chip families.
CMSIS Cortex-M Peripheral Access Layer for Silicon Laboratories microcontroller devices.
EzRadio transmit plug-in managed by the plug-in manager if enabled.
EzRadio transmit packet length configuration structure.
EZRADIODRV_FieldLength_t fieldLen
Field lengths.
Ecode_t ezradioStartTransmitSmart(EZRADIODRV_Handle_t radioHandle, EZRADIODRV_PacketLengthConfig_t pktLengthConf, uint8_t *pioRadioPacket)
Start a smart transmission. Depending on the information in the pktLengthConf parameter the function ...
Ecode_t ezradioStartTransmitBasic(EZRADIODRV_Handle_t radioHandle, uint16_t packetLength, uint8_t *pioRadioPacket)
Start basic transmission. Radio transmits with data only in the first field in this case...
EZRADIODRV_AutoAckHandle_t autoAck
Auto-acknowledge plug-in handler.
Transmit packet length is defined by the application for field1 only.
EZRADIODRV_Callback_t userCallback
User callback.
uint32_t Ecode_t
Typedef for API function error code return values.
Definition: ecode.h:51
void ezradio_set_property(uint8_t group, uint8_t num_props, uint8_t start_prop,...)
Transmit packet length is defined in the generated configuration.
uint8_t f4
Field 4 length.
Transmit packet length is defined by the application for multiple fields.
#define ECODE_EMDRV_EZRADIODRV_ILLEGAL_HANDLE
Illegal SPI handle.
Immediate acknowledge transmission.
Ecode_t ezradioStartTransmitConfigured(EZRADIODRV_Handle_t radioHandle, uint8_t *pioRadioPacket)
Start transmission using the packet parameters from the generated configuration header file...
Ecode_t ezradioStartTransmitCustom(EZRADIODRV_Handle_t radioHandle, EZRADIODRV_PacketLengthConfig_t pktLengthConf, uint8_t *pioRadioPacket)
Start transmission using the packet parameters from pktLengthConf.
EZRADIODRV_TransmitPacketType_t pktType
Packet type.
uint8_t f2
Field 2 length.
EZRADIODRV_AutoAckMode_t ackMode
Auto ack mode.
ezradio_cmd_reply_t * EZRADIODRV_ReplyHandle_t
EZradio reply union handle.
EZRADIODRV_PacketLengthConfig_t lenConfig
Packet length configuration.
void ezradio_request_device_state(ezradio_cmd_reply_t *ezradioReply)
uint8_t f3
Field 3 length.