5555
5656#define LINEAR_FIFO_ADDRESS 0xFF /* !< Linear FIFO address*/
5757
58- #define XTAL_FREQUENCY 50000000U
59-
60- #define PREAMBLE_LENGTH (64 *4 )
61- #define DATARATE 38400
62- #define MIN_PERIOD_WAKEUP ((8000 *((PREAMBLE_LENGTH/4 )-2 ))/DATARATE)
63-
6458/* Class Implementation ------------------------------------------------------*/
6559
6660/* * Constructor
@@ -89,7 +83,6 @@ S2LP::S2LP(SPIClass *spi, int csn, int sdn, int irqn, uint32_t frequency, uint32
8983 memset ((void *)vectcTxBuff, 0 , FIFO_SIZE*sizeof (uint8_t ));
9084 cRxData = 0 ;
9185 is_waiting_for_read = false ;
92- is_tx_done_before_read = false ;
9386 is_bypass_enabled = false ;
9487}
9588
@@ -125,7 +118,7 @@ void S2LP::begin(void)
125118 SRadioInit xRadioInit = {
126119 lFrequencyBase, /* base carrier frequency */
127120 MOD_2FSK, /* modulation type */
128- DATARATE, /* data rate */
121+ 38400 , /* data rate */
129122 20000 , /* frequency deviation */
130123 100000 /* bandwidth */
131124 };
@@ -161,7 +154,7 @@ void S2LP::begin(void)
161154 S2LPRadioSetPALevelMaxIndex (7 );
162155
163156 PktBasicInit xBasicInit={
164- PREAMBLE_LENGTH, /* Preamble length */
157+ 16 , /* Preamble length */
165158 32 , /* Sync length */
166159 0x88888888 , /* Sync word */
167160 S_ENABLE, /* Variable length */
@@ -186,7 +179,7 @@ void S2LP::begin(void)
186179 S2LPPktBasicAddressesInit (&xAddressInit);
187180
188181 SCsmaInit xCsmaInit={
189- S_DISABLE, /* Persistent mode enable/disable */
182+ S_ENABLE, /* Persistent mode enable/disable */
190183 CSMA_PERIOD_64TBIT, /* CS Period */
191184 3 , /* CS Timeout */
192185 5 , /* Max number of backoffs */
@@ -215,26 +208,15 @@ void S2LP::begin(void)
215208 S2LPGpioIrqConfig (RX_DATA_READY,S_ENABLE);
216209 S2LPGpioIrqConfig (TX_DATA_SENT , S_ENABLE);
217210
218- /* IRQ registers blanking */
219- S2LPGpioIrqClearStatus ();
220-
221211 /* clear FIFO if needed */
222212 S2LPCmdStrobeFlushRxFifo ();
223213
224- /* set the LDC mode wkup */
225- S2LPTimerSetWakeUpTimerUs (1000 *MIN_PERIOD_WAKEUP);
214+ /* Set infinite Timeout */
215+ S2LPTimerSetRxTimerCounter (0 );
216+ S2LPTimerSetRxTimerStopCondition (ANY_ABOVE_THRESHOLD);
226217
227- /* set the rx timeout */
228- S2LPTimerSetRxTimerUs (30000 );
229-
230- /* use SLEEP_A mode (default) */
231- S2LPTimerSleepB (S_DISABLE);
232-
233- /* enable LDC mode, FAST RX TERM and start Rx */
234- S2LPTimerLdcrMode (S_ENABLE);
235-
236- /* enable the fast rx timer */
237- S2LpTimerFastRxTermTimer (S_ENABLE);
218+ /* IRQ registers blanking */
219+ S2LPGpioIrqClearStatus ();
238220
239221 uint8_t tmp = 0x90 ;
240222 S2LPSpiWriteRegisters (0x76 , 1 , &tmp);
@@ -293,7 +275,6 @@ void S2LP::end(void)
293275 memset ((void *)vectcTxBuff, 0 , FIFO_SIZE*sizeof (uint8_t ));
294276 cRxData = 0 ;
295277 is_waiting_for_read = false ;
296- is_tx_done_before_read = false ;
297278 is_bypass_enabled = false ;
298279}
299280
@@ -335,10 +316,6 @@ uint8_t S2LP::send(uint8_t *payload, uint8_t payload_len, uint8_t dest_addr, boo
335316 return 1 ;
336317 }
337318
338- /* Disable LDC */
339- S2LPTimerLdcrMode (S_DISABLE);
340- S2LpTimerFastRxTermTimer (S_DISABLE);
341-
342319 S2LPPktBasicSetPayloadLength (payload_len);
343320
344321 S2LPSetRxSourceReferenceAddress (dest_addr);
@@ -383,14 +360,7 @@ uint8_t S2LP::send(uint8_t *payload, uint8_t payload_len, uint8_t dest_addr, boo
383360 S2LPCsma (S_DISABLE);
384361 }
385362
386- /* Enable LDC */
387- S2LPTimerLdcrMode (S_ENABLE);
388- S2LpTimerFastRxTermTimer (S_ENABLE);
389-
390- if (is_waiting_for_read)
391- {
392- is_tx_done_before_read = true ;
393- } else
363+ if (!is_waiting_for_read)
394364 {
395365 uint8_t tmp = 0x90 ;
396366 S2LPSpiWriteRegisters (0x76 , 1 , &tmp);
@@ -454,37 +424,64 @@ uint8_t S2LP::read(uint8_t *payload, uint8_t payload_len)
454424
455425 is_waiting_for_read = false ;
456426
457- if (is_tx_done_before_read)
458- {
459- is_tx_done_before_read = false ;
460- uint8_t tmp = 0x90 ;
461- S2LPSpiWriteRegisters (0x76 , 1 , &tmp);
462-
463- if (s_paInfo.paRfRangeExtender == RANGE_EXT_SKYWORKS_SKY66420)
464- {
465- FEM_Operation_SKY66420 (FEM_RX);
466- }
427+ uint8_t tmp = 0x90 ;
428+ S2LPSpiWriteRegisters (0x76 , 1 , &tmp);
467429
468- /* Return to RX state */
469- S2LPCmdStrobeCommand (CMD_RX);
470- } else
430+ if (s_paInfo.paRfRangeExtender == RANGE_EXT_SKYWORKS_SKY66420)
471431 {
472- /* Return to Sleep state */
473- S2LPCmdStrobeCommand (CMD_SLEEP);
474-
475- if (S2LPManagementGetCut ()==S2LP_CUT_2_0)
476- {
477- /* apply the workaround to exit from SLEEP (2nd part) */
478- delay (6 );
479- S2LPTimerLdcIrqWa (S_DISABLE);
480- }
432+ FEM_Operation_SKY66420 (FEM_RX);
481433 }
482434
435+ /* Return to RX state */
436+ S2LPCmdStrobeCommand (CMD_RX);
437+
483438 enableS2LPIrq ();
484439
485440 return ret_val;
486441}
487442
443+ /* *
444+ * @brief Sets the channel number.
445+ * @param cChannel the channel number.
446+ * @retval None.
447+ */
448+ void S2LP::setRadioChannel (uint8_t cChannel)
449+ {
450+ return S2LPRadioSetChannel (cChannel);
451+ }
452+
453+ /* *
454+ * @brief Returns the actual channel number.
455+ * @param None.
456+ * @retval uint8_t Actual channel number.
457+ */
458+ uint8_t S2LP::getRadioChannel (void )
459+ {
460+ return S2LPRadioGetChannel ();
461+ }
462+
463+ /* *
464+ * @brief Set the channel space factor in channel space register.
465+ * The channel spacing step is computed as F_Xo/32768.
466+ * @param fChannelSpace the channel space expressed in Hz.
467+ * @retval None.
468+ */
469+ void S2LP::setRadioChannelSpace (uint32_t lChannelSpace)
470+ {
471+ return S2LPRadioSetChannelSpace (lChannelSpace);
472+ }
473+
474+ /* *
475+ * @brief Return the channel space register.
476+ * @param None.
477+ * @retval uint32_t Channel space. The channel space is: CS = channel_space_factor x XtalFrequency/2^15
478+ * where channel_space_factor is the CHSPACE register value.
479+ */
480+ uint32_t S2LP::getRadioChannelSpace (void )
481+ {
482+ return S2LPRadioGetChannelSpace ();
483+ }
484+
488485/* *
489486* @brief Set the Ready state.
490487* @param None.
@@ -496,22 +493,14 @@ uint8_t S2LP::S2LPSetReadyState(void)
496493 uint32_t start_time;
497494 uint32_t current_time;
498495
496+ S2LPCmdStrobeCommand (CMD_SABORT);
497+
499498 start_time = millis ();
500499
501500 do
502501 {
503502 S2LPRefreshStatus ();
504503
505- if (g_xStatus.MC_STATE == MC_STATE_RX || g_xStatus.MC_STATE == MC_STATE_TX)
506- {
507- S2LPCmdStrobeCommand (CMD_SABORT);
508- } else
509- {
510- S2LPCmdStrobeCommand (CMD_READY);
511- }
512-
513- S2LPRefreshStatus ();
514-
515504 current_time = millis ();
516505 } while (g_xStatus.MC_STATE != MC_STATE_READY && (current_time - start_time) <= 1000 );
517506
@@ -554,11 +543,6 @@ void S2LP::S2LPIrqHandler(void)
554543 /* Check the S2LP RX_DATA_READY IRQ flag */
555544 if (xIrqStatus.IRQ_RX_DATA_READY )
556545 {
557- if (S2LPManagementGetCut ()==S2LP_CUT_2_0)
558- {/* apply the workaround to exit from SLEEP (1st part) */
559- S2LPTimerLdcIrqWa (S_ENABLE);
560- }
561-
562546 /* Get the RX FIFO size */
563547 cRxData = S2LPFifoReadNumberBytesRxFifo ();
564548
0 commit comments