57 #define LDC_FREQ_CLK S2LPTimerGetRcoFrequency() 70 #define IS_RX_TIMEOUT_STOP_CONDITION(COND) ( COND == NO_TIMEOUT_STOP || \ 71 COND == TIMEOUT_ALWAYS_STOPPED || \ 72 COND == RSSI_ABOVE_THRESHOLD || \ 73 COND == SQI_ABOVE_THRESHOLD || \ 74 COND == PQI_ABOVE_THRESHOLD || \ 75 COND == RSSI_AND_SQI_ABOVE_THRESHOLD || \ 76 COND == RSSI_AND_PQI_ABOVE_THRESHOLD || \ 77 COND == SQI_AND_PQI_ABOVE_THRESHOLD || \ 78 COND == ALL_ABOVE_THRESHOLD || \ 79 COND == RSSI_OR_SQI_ABOVE_THRESHOLD || \ 80 COND == RSSI_OR_PQI_ABOVE_THRESHOLD || \ 81 COND == SQI_OR_PQI_ABOVE_THRESHOLD || \ 82 COND == ANY_ABOVE_THRESHOLD ) 130 (*plWakeUpUsec) = (uint32_t)((uint64_t)1000000*(cCounter+1)*(cPrescaler+1)/LDC_FREQ_CLK*cMulti);
153 if(lDesiredUsec<(((uint32_t)((uint64_t)1000000*65536/LDC_FREQ_CLK))<<i))
163 n = (uint32_t)((uint64_t)lDesiredUsec*(LDC_FREQ_CLK>>i)/1000000);
169 (*pcPrescaler) = 0xFF;
174 (*pcPrescaler) = (n/0xFF)+2;
175 (*pcCounter) = n / (*pcPrescaler);
210 uint64_t tgt,tgt1,tgt2;
221 tgt=(uint64_t)lDesiredUsec*f_dig;
222 n=(uint32_t)(tgt/1210000000);
223 tgt1=(uint64_t)1210000000*n;
224 tgt2=(uint64_t)1210000000*(n+1);
226 n=((tgt2-tgt)<(tgt-tgt1))?(n+1):(n);
232 (*pcPrescaler) = 0xFF;
237 (*pcPrescaler)=(n/0xFF)+2;
238 (*pcCounter) = n / (*pcPrescaler);
268 (*pulDesiredUsec) = (uint32_t)((uint64_t)1000000*(cPrescaler+1)*cCounter*1210/f_dig);
292 s_assert_param(IS_SFUNCTIONAL_STATE(xNewState));
295 if(xNewState==S_ENABLE) {
296 tmp |= LDC_MODE_REGMASK;
299 tmp &= ~LDC_MODE_REGMASK;
314 s_assert_param(IS_SFUNCTIONAL_STATE(xNewState));
317 if(xNewState==S_ENABLE) {
318 tmp |= LDC_RELOAD_ON_SYNC_REGMASK;
321 tmp &= ~LDC_RELOAD_ON_SYNC_REGMASK;
350 uint8_t tmpBuffer[2] = {cCounter, cPrescaler};
364 uint8_t tmpBuffer[2];
407 uint8_t tmpBuffer[2];
411 (*pcCounter) = tmpBuffer[0];
412 (*pcPrescaler) = tmpBuffer[1];
430 uint8_t tmpBuffer[2] = {cPrescaler, cCounter};
446 uint8_t tmpBuffer[2], multi, tmp;
452 tmp &= ~LDC_TIMER_MULT_REGMASK;
499 uint8_t tmpBuffer[2], tmp;
502 tmp &= LDC_TIMER_MULT_REGMASK;
506 *pcCounter = tmpBuffer[1];
507 *pcPrescaler = tmpBuffer[0];
527 uint8_t tmpBuffer[2] = {cPrescaler, cCounter}, tmp;
530 tmp &= (~LDC_TIMER_MULT_REGMASK);
548 uint8_t tmpBuffer[2], multi, tmp;
554 tmp &= ~LDC_TIMER_MULT_REGMASK;
600 uint8_t tmpBuffer[2], tmp;
603 tmp &= LDC_TIMER_MULT_REGMASK;
607 *pcCounter = tmpBuffer[1];
608 *pcPrescaler = tmpBuffer[0];
623 s_assert_param(IS_RX_TIMEOUT_STOP_CONDITION(xStopCondition));
626 tmp &= ~(CS_TIMEOUT_MASK_REGMASK | SQI_TIMEOUT_MASK_REGMASK | PQI_TIMEOUT_MASK_REGMASK);
627 tmp |= (((uint8_t)xStopCondition) << 5);
631 tmp &= ~RX_TIMEOUT_AND_OR_SEL_REGMASK;
632 tmp |= (((uint8_t)xStopCondition) >> 1);
667 s_assert_param(IS_SFUNCTIONAL_STATE(xNewState));
670 if(xNewState == S_ENABLE) {
671 tmp |= FAST_CS_TERM_EN_REGMASK;
674 tmp &= ~FAST_CS_TERM_EN_REGMASK;
702 uint8_t tmp,fast_rx_word;
711 s_assert_param(fast_rx_us<(1000000*0xff)/(f_dig/24/(1<<(tmp&0x0F))));
714 fast_rx_word=((f_dig/24/(1<<(tmp&0x0F)))*fast_rx_us)/1000000;
730 s_assert_param(IS_SFUNCTIONAL_STATE(xCalibration));
734 if(xCalibration == S_ENABLE) {
735 tmp |= RCO_CALIBRATION_REGMASK;
737 tmp &= ~RCO_CALIBRATION_REGMASK;
753 s_assert_param(IS_SFUNCTIONAL_STATE(en));
758 tmp |= SLEEP_MODE_SEL_REGMASK;
760 tmp &= ~SLEEP_MODE_SEL_REGMASK;
767 uint8_t tmp[2]={0x00,0x60};
771 tmp[0]=0x01; tmp[1]=0x64;
780 g_xStatus = S2LPSpiWriteRegisters(0x7B, 1, &tmp[1]);
781 g_xStatus = S2LPSpiWriteRegisters(0x7A, 1, &tmp[0]);
uint16_t S2LPTimerGetRcoFrequency(void)
Computes and Return the RCO frequency. This frequency depends on the xtal frequency and the XTAL bit ...
void S2LPTimerSetRxTimer(uint8_t cCounter, uint8_t cPrescaler)
Set the RX timeout timer initialization registers with the values of COUNTER and PRESCALER according ...
void S2LPTimerSetWakeUpTimerReload(uint8_t cCounter, uint8_t cPrescaler, uint8_t cMulti)
Set the LDCR wake up timer reloading registers with the values of COUNTER and PRESCALER according to ...
void S2LPTimerComputeRxTimerRegValues(uint32_t plDesiredUsec, uint8_t *pcCounter, uint8_t *pcPrescaler)
Computes the values of the rx_timeout timer counter and prescaler from the user time expressed in mil...
SFunctionalState S2LPTimerLdcrGetAutoReload(void)
Return the LDCR timer reload bit.
#define PROTOCOL2_ADDR
PROTOCOL2 register.
void S2LpSetTimerFastRxTermTimerUs(uint32_t fast_rx_us)
Set the Fast RX termination timer word starting from a us value. The timer counter is clocked at freq...
void S2LpTimerFastRxTermTimer(SFunctionalState xNewState)
Enables the Fast RX termination timer.
SFunctionalState
S2LP Functional state. Used to enable or disable a specific option.
uint32_t S2LPRadioGetXtalFrequency(void)
Return the XTAL frequency.
void S2LPTimerSetRxTimerStopCondition(RxTimeoutStopCondition xStopCondition)
Set the RX timeout stop conditions.
#define PROTOCOL1_ADDR
PROTOCOL1 register.
void S2LPTimerSleepB(SFunctionalState en)
Enable the SLEEP_B mode. SLEEP_A and SLEEP_B are mutually exclusive.
void S2LPTimerGetRxTimerUs(uint32_t *plTimeoutUsec, uint8_t *pcCounter, uint8_t *pcPrescaler)
Return the RX timeout timer.
void S2LPTimerLdcrMode(SFunctionalState xNewState)
Enables or Disables the LDCR mode.
void S2LPTimerSetRxTimerUs(uint32_t lDesiredUsec)
Set the RX timeout timer counter and prescaler from the desired value in ms. it is possible to fix th...
void S2LPTimerSetWakeUpTimerUs(uint32_t lDesiredUsec)
Set the LDCR wake up timer counter and prescaler from the desired value in ms, according to the formu...
void S2LPTimerLdcrAutoReload(SFunctionalState xNewState)
Enables or Disables the LDCR timer reloading with the value stored in the LDCR_RELOAD registers.
#define TIMERS4_ADDR
TIMERS4 register.
void S2LPTimerSetRxTimerPrescaler(uint8_t cPrescaler)
Set the RX timeout timer prescaler. If it is equal to 0 the timeout is infinite.
#define DIG_DOMAIN_XTAL_THRESH
void S2LPTimerSetWakeUpTimerPrescaler(uint8_t cPrescaler)
Set the LDCR wake up timer prescaler. Remember that this value is incresead by one in the Twu calcula...
#define TIMERS3_ADDR
TIMERS3 register.
#define TIMERS5_ADDR
TIMERS5 register.
#define FAST_RX_TIMER_ADDR
FAST_RX_TIMER register.
void S2LPTimerComputeRxTimerValues(uint32_t *plDesiredUsec, uint8_t pcCounter, uint8_t pcPrescaler)
Computes the values of the rx_timeout given the timer counter and prescaler.
#define TIMERS1_ADDR
TIMERS1 register.
void S2LPRefreshStatus(void)
Updates the gState (the global variable used to maintain memory of S2LP Status) reading the MC_STATE ...
void S2LPTimerSetWakeUpTimerCounter(uint8_t cCounter)
Set the LDCR wake up timer counter. Remember that this value is incresead by one in the Twu calculati...
void S2LPTimerGetWakeUpTimerUs(uint32_t *plWakeUpUsec, uint8_t *pcCounter, uint8_t *pcPrescaler, uint8_t *pcMulti)
Return the LDCR wake up timer, according to the formula: Twu=(PRESCALER +1)*(COUNTER+1)*Tck,...
void S2LPTimerComputeWakeupTimerValues(uint32_t *plWakeUpUsec, uint8_t cCounter, uint8_t cPrescaler, uint8_t cMulti)
Computes the wake up timer.
void S2LPTimerGetWakeUpTimerReloadUs(uint32_t *plWakeUpReloadUsec, uint8_t *pcCounter, uint8_t *pcPrescaler, uint8_t *pcMulti)
Return the LDCR wake up reload timer, according to the formula: Twu=(PRESCALER +1)*(COUNTER+1)*Tck,...
RxTimeoutStopCondition
All the possible RX timeout stop conditions enumeration.
#define PM_CONF0_ADDR
PM_CONF0 register.
S2LP Configuration and useful defines .
void S2LPTimerSetWakeUpTimer(uint8_t cCounter, uint8_t cPrescaler)
Set the LDCR wake up timer initialization registers with the values of COUNTER and PRESCALER accordin...
void S2LPTimerSetWakeUpTimerReloadCounter(uint8_t cCounter)
Set the LDCR wake up timer reload counter. Remember that this value is incresead by one in the Twu ca...
#define CHFLT_ADDR
CHFLT register.
void S2LPTimerSetRxTimerCounter(uint8_t cCounter)
Set the RX timeout timer counter. If it is equal to 0 the timeout is infinite.
volatile S2LPStatus g_xStatus
S2LP Status global variable. This global variable of S2LPStatus type is updated on every SPI transact...
#define TIMERS2_ADDR
TIMERS2 register.
void S2LPTimerComputeWakeupTimerRegValues(uint32_t plDesiredUsec, uint8_t *pcCounter, uint8_t *pcPrescaler, uint8_t *pcMulti)
Computes the values of the wakeup timer counter and prescaler from the user time expressed in millise...
#define PCKT_FLT_OPTIONS_ADDR
PCKT_FLT_OPTIONS register.
void S2LpSetTimerFastRxTermTimer(uint8_t fast_rx_word)
Set the Fast RX termination timer word. When the timer counter will reach this word,...
#define XO_RCO_CONF0_ADDR
XO_RCO_CONF0 register.
Header file for low level S2LP SPI driver.
#define TIMERS0_ADDR
TIMERS0 register.
void S2LPTimerSetWakeUpTimerReloadUs(uint32_t lDesiredUsec)
Set the LDCR wake up reload timer counter and prescaler from the desired value in ms,...
void S2LPTimerCalibrationRco(SFunctionalState xCalibration)
Enables the RCO autocalibration when the device make the transition READY -> SLEEP.
void S2LPTimerSetWakeUpTimerReloadPrescaler(uint8_t cPrescaler)
Set the LDCR wake up timer reload prescaler. Remember that this value is incresead by one in the Twu ...