Other Parts Discussed in Thread: CC2533, , Z-STACK, REMOTI
Tool/software:
The user guide for the CC2530 and CC2533 has the following text.
The Sleep Timer is running when operating in all power modes except PM3. The value of the Sleep Timer
is not preserved in PM3. When returning from PM1 or PM2 (where the system clock is shut down), the
Sleep Timer value in ST2:ST1:ST0 is not up-to-date until a positive edge on the 32-kHz clock has been
detected after the system clock restarted. To ensure an updated value is read, wait for a positive transition
on the 32-kHz clock by polling the SLEEPSTA.CLK32K bit, before reading the Sleep Timer value.
This implies that I should write code to ensure that SLEEPSTA.CLK32K !=0 before reading ST0 (or wait for the next rising edge which would wait for SLEEPSTA.CLK32K to be 1 and then 0, and then 1 again to get the next rising edge).
The code in Z-Stack 3.02 for the CC2530EB does not have this wait. Is the wait required?
void halSleepSetTimer(uint32 timeout)
{
uint32 ticks;
/* read the sleep timer; ST0 must be read first */
((uint8 *) &ticks)[UINT32_NDX0] = ST0;
((uint8 *) &ticks)[UINT32_NDX1] = ST1;
((uint8 *) &ticks)[UINT32_NDX2] = ST2;
((uint8 *) &ticks)[UINT32_NDX3] = 0;
/* Compute sleep timer compare value. The ratio of 32 kHz ticks to 320 usec ticks
* is 32768/3125 = 10.48576. This is nearly 671/64 = 10.484375.
*/
ticks += (timeout * 671) / 64;
/* subtract the processing time spent in function halSleep() */
ticks -= HAL_SLEEP_ADJ_TICKS;
/* set sleep timer compare; ST0 must be written last */
ST2 = ((uint8 *) &ticks)[UINT32_NDX2];
ST1 = ((uint8 *) &ticks)[UINT32_NDX1];
ST0 = ((uint8 *) &ticks)[UINT32_NDX0];
}
Similarly, the user guide states to wait until STLOAD.LDRDY is 1 before wring to ST2. The code above does not do that. However, the macro used for the CC2533EB in RemoTI 1.4.0, waits after setting the sleep timer registers.
#define HAL_SLEEP_ST_SET(STCNT) st ( \
/* Set the sleep timer compare; ST0 must be written last. */\
ST2 = ((uint8 *) &(STCNT))[2]; \
ST1 = ((uint8 *) &(STCNT))[1]; \
ST0 = ((uint8 *) &(STCNT))[0]; \
while (!(STLOAD & LDRDY)); /* Wait for the sleep timer to load. */\
)
Which version (the user guide, Z-Stack, or RemoTI) is correct or does it matter?