I am having some issues with the latest SDK hal_sleep.c halSleep( uint32 osal_timeout ) function:
With the RF disabled, theOSAL is passing in a wakeup time of 30,000 (30s), but it is waking up every 2.00s (verified by scope).
I debugged halSleep() and found that the code which calculates the number of 32.768kHz cycles to sleep for is returning the wrong number - 0x0000FFFF which is causing the exact 2s wakeup.
The following code is where the problem happens (In the previous step osal_timeout is 30,000 as expected):
// get next OSAL timer expiration and convert to 32kHz units
// Note: Could be early by one 32kHz timer tick due to rounding.
timeout = llDivide31By16To16( (uint32)osal_timeout*4096, 125 );
After this line, timeout = 4294901885 (0xFFFF007D). Then:
// only need the quotient
timeout >>= 16;
After this line, timeout = 65535 (0x0000FFFF) (as expected from above), but the result should be 983040 (0x000F0000).
Has anyone seen this before? I have tried with compiler optimization on and off but this makes no difference.
Help please