I'm using Bitcloud SDK 3.3.0 with the Atmel SAM R21 Xplained Pro Evaluation board. I'm trying to go to sleep and wake up after CS_END_DEVICE_SLEEP_PERIOD time period (20 seconds for me).
Note that I've sucessfully gotten automatic sleep working, using SYS_EnableSleepWhenIdle() - the device sleeps and wakes properly. However I'm attempting to manage sleeping manually, which I can't get working. I call SYS_DisableSleepWhenIdle() in my initialization function so that Bitcloud sleep-when-idle feature is disabled.
The device goes to sleep OK, but on wakeup it executes briefly but eventually hangs. My code snippets are below. Notice in ZDO_WakeUpInd() I call SYS_PostTask(APL_TASK_ID) to get running again after waking up.
My problem is, I call SYS_PostTask(APL_TASK_ID) in ZDO_WakeUpInd(), but my task handler APL_TaskHandler() never gets called after waking up.
After waking up, I traced through processManagerTask() (in sysTaskManager.c) in the debugger, and I noticed that the task handlers for tasks 3, 2, and 0 get called, in that order. These handlers are NWK_TaskHandler, MAC_HWI_TaskHandler, and MAC_PHY_HWD_TaskHandler, respectively. After calling MAC_PHY_HWD_TaskHandler, the software hangs forever.
When the software hangs, I pressed the Pause button in the debugger, and here is the call stack:
AS7_ATSAMR21G18A.elf! halDelayUs Line: 38762656
AS7_ATSAMR21G18A.elf! HAL_Delay Line: 38762656
AS7_ATSAMR21G18A.elf! PHY_SetTrxStateReq Line: 38762656
AS7_ATSAMR21G18A.elf! executeDataReq Line: 38762656
AS7_ATSAMR21G18A.elf! machwdTxFrameReqHandler Line: 38762656
AS7_ATSAMR21G18A.elf! MAC_PHY_HWD_TaskHandler Line: 38762656
> AS7_ATSAMR21G18A.elf! processManagerTask Line: 261
AS7_ATSAMR21G18A.elf! SYS_RunTask Line: 200
AS7_ATSAMR21G18A.elf! main Line: 1125
Anyone else have similar trouble? Why is it hanging? Is it hanging in halDelayUs, as the call stack indicates? halDelayUs is a simple function that delays for a few microseconds. Perhaps there is some other function I should call in ZDO_WakeUpInd() to wake up the device, although I'm doing what the Bitcloud documentation and samples say to do.
Here are my code snippets. They match the Bitcloud documentation and the few samples I've found.
// This is called from APL_TaskHandler() to attempt to go to sleep.
void goToSleep(void)
{
zdoSleepReq.ZDO_SleepConf = ZDO_SleepConf;
ZDO_SleepReq(&zdoSleepReq);
}
void ZDO_SleepConf(ZDO_SleepConf_t *conf)
{
if (ZDO_SUCCESS_STATUS == conf->status)
{
// Note that we get actually get here, so I know that the device goes to sleep.
// The device is going to sleep.
// ZDO_WakeUpInd() will be called by the stack when the device wakes up.
}
else
{
// The device is busy. Call SYS_PostTask(APL_TASK_ID) which will cause APL_TaskHandler() to call goToSleep() to try sleeping again.
appState = APP_SLEEPING_STATE; // In this state we attempt to sleep.
SYS_PostTask(APL_TASK_ID);
}
}
void ZDO_WakeUpInd(void)
{
// This function is called when the device wakes up.
// On an end device CS_END_DEVICE_SLEEP_PERIOD determines the duration of the sleep period.
if (appState == APP_SLEEPING_STATE)
{
// As recommended in the Bitcloud guide, post a task to get us running again.
// Note that we get actually get here, so I know that the device is waking up.
appState = APP_RUNNING_STATE; // go to the RUNNING state
SYS_PostTask(APL_TASK_ID);
// Even though I post a task above, APL_TaskHandler() never gets called.
}
}
Can anyone offer advice, or point me to a working example of manual sleeping using Bitcloud?
Thanks in advance for your help,
Tim M