65 #define IS_CCA_PERIOD(PERIOD) (PERIOD == CSMA_PERIOD_64TBIT || \ 66 PERIOD == CSMA_PERIOD_128TBIT || \ 67 PERIOD == CSMA_PERIOD_256TBIT || \ 68 PERIOD == CSMA_PERIOD_512TBIT) 70 #define IS_CSMA_LENGTH(LENGTH) (LENGTH < 16) 72 #define IS_BU_COUNTER_SEED(SEED) (SEED!=0) 73 #define IS_BU_PRESCALER(PRESCALER) (PRESCALER<64) 74 #define IS_CMAX_NB(NB) (NB<8) 116 uint8_t tmpBuffer[4];
121 s_assert_param(IS_CSMA_LENGTH(pxCsmaInit->
xCcaLength));
123 s_assert_param(IS_BU_PRESCALER(pxCsmaInit->
cBuPrescaler));
124 s_assert_param(IS_CMAX_NB(pxCsmaInit->
cMaxNb));
145 tmpBuffer[0] |= CSMA_PERS_ON_REGMASK;
148 tmpBuffer[0] &= ~CSMA_PERS_ON_REGMASK;
166 uint8_t tmpBuffer[4];
178 pxSCsmaInit->
nBuCounterSeed = (((uint16_t)tmpBuffer[0]) << 8) | (uint16_t)tmpBuffer[1];
187 pxSCsmaInit->
xCcaLength = (tmpBuffer[3]&CCA_LEN_REGMASK)>>4;
190 pxSCsmaInit->
cMaxNb = tmpBuffer[3] & NBACKOFF_MAX_REGMASK;
204 s_assert_param(IS_SFUNCTIONAL_STATE(xNewState));
209 if(xNewState==S_ENABLE)
211 tmp |= CSMA_ON_REGMASK;
214 tmp2 |= SLEEP_MODE_SEL_REGMASK;
219 tmp &= ~CSMA_ON_REGMASK;
239 if(tmp & CSMA_ON_REGMASK) {
257 s_assert_param(IS_SFUNCTIONAL_STATE(xNewState));
262 if(xNewState==S_ENABLE) {
263 tmp |= CSMA_PERS_ON_REGMASK;
266 tmp &= ~CSMA_PERS_ON_REGMASK;
285 if(tmp & CSMA_PERS_ON_REGMASK) {
304 s_assert_param(IS_SFUNCTIONAL_STATE(xNewState));
309 if(xNewState==S_ENABLE) {
310 tmp |= SEED_RELOAD_REGMASK;
313 tmp &= ~SEED_RELOAD_REGMASK;
333 if(tmp & SEED_RELOAD_REGMASK) {
350 uint8_t tmpBuffer[2];
351 s_assert_param(IS_BU_COUNTER_SEED(nBuCounterSeed));
353 tmpBuffer[0] = (uint8_t)(nBuCounterSeed>>8);
354 tmpBuffer[1] = (uint8_t)nBuCounterSeed;
367 uint8_t tmpBuffer[2];
371 return ((((uint16_t)tmpBuffer[0])<<8) + (uint16_t)tmpBuffer[1]);
384 s_assert_param(IS_BU_PRESCALER(cBuPrescaler));
388 tmp &= ~BU_PRSC_REGMASK;
389 tmp |= (cBuPrescaler<<2);
419 s_assert_param(IS_CCA_PERIOD(xMultiplierTbit));
423 tmp &= ~CCA_PERIOD_REGMASK;
424 tmp |= xMultiplierTbit;
455 s_assert_param(IS_CSMA_LENGTH(xCcaLength));
459 tmp &= ~CCA_LEN_REGMASK;
491 s_assert_param(IS_CMAX_NB(cMaxNb));
495 tmp &= ~NBACKOFF_MAX_REGMASK;
512 return (tmp & NBACKOFF_MAX_REGMASK);
#define CSMA_CONF0_ADDR
CSMA_CONF0 register.
void S2LPCsmaSetBuPrescaler(uint8_t cBuPrescaler)
Set the BU prescaler. The CSMA back off time is given by the formula: BO = rand(2^NB)*BU.
Configuration and management of S2-LP CSMA.
uint8_t S2LPCsmaGetCcaPeriod(void)
Return the CCA period.
SFunctionalState xCsmaPersistentMode
uint8_t S2LPCsmaGetMaxNumberBackoff(void)
Return the max number of back-off.
#define CSMA_CONF1_ADDR
CSMA_CONF1 register.
SFunctionalState
S2LP Functional state. Used to enable or disable a specific option.
uint16_t S2LPCsmaGetBuCounterSeed(void)
Return the BU counter seed (BU_COUNTER_SEED register).
#define PROTOCOL1_ADDR
PROTOCOL1 register.
void S2LPCsmaSetMaxNumberBackoff(uint8_t cMaxNb)
Set the max number of back-off. If reached S2LP stops the transmission.
SCsmaPeriod xMultiplierTbit
void S2LPCsmaSeedReloadMode(SFunctionalState xNewState)
Enables or Disables the seed reload mode (if enabled it reloads the back-off generator seed using the...
void S2LPCsmaGetInfo(SCsmaInit *pxSCsmaInit)
Return the fitted structure SCsmaInit starting from the registers values.
void S2LPCsma(SFunctionalState xNewState)
Enable or Disables the CSMA.
void S2LPCsmaPersistentMode(SFunctionalState xNewState)
Enables or Disables the persistent CSMA mode.
SCsmaPeriod
Multiplier for Tcca time enumeration (Tcca = Multiplier*Tbit).
void S2LPCsmaInit(SCsmaInit *pxCsmaInit)
Initialize the S2LP CSMA according to the specified parameters in the SCsmaInit.
SFunctionalState S2LPCsmaGetSeedReloadMode(void)
Gets the seed reload mode.
#define CSMA_CONF3_ADDR
CSMA_CONF3 register.
#define PM_CONF0_ADDR
PM_CONF0 register.
SFunctionalState S2LPCsmaGetCsma(void)
Gets the CSMA mode. Says if it is enabled or disabled.
uint8_t S2LPCsmaGetBuPrescaler(void)
Return the BU prescaler.
volatile S2LPStatus g_xStatus
S2LP Status global variable. This global variable of S2LPStatus type is updated on every SPI transact...
SFunctionalState S2LPCsmaGetPersistentMode(void)
Gets the persistent CSMA mode.
void S2LPCsmaSetCcaLength(uint8_t xCcaLength)
Set the CCA length.
uint8_t S2LPCsmaGetCcaLength(void)
Return the CCA length.
Header file for low level S2LP SPI driver.
void S2LPCsmaSetCcaPeriod(SCsmaPeriod xMultiplierTbit)
Set the CCA period.
void S2LPCsmaSetBuCounterSeed(uint16_t nBuCounterSeed)
Set the BU counter seed (BU_COUNTER_SEED register). The CSMA back off time is given by the formula: B...
S2LP CSMA Init structure definition.