Hello there,
it would be great if you could help me with a problem related to hibernation and waking-up. :-)
So we're building an application based on pxp-reporter example because we need the implemented SUOTA-functionality. That works so far.
Now, I'd like to add a timer that will shut down the device after a few seconds without BLE activity. A button (active high on P3_0) should wake the device up again and sw-reset it. Then it starts over again.
The code snippets so far are this:
main.c, system_init():...
pm_set_wakeup_mode(true);
pm_set_sleep_mode( pm_mode_hibernation );
// I don't want the device to automatically go to sleep, as this has interefered with BLE in the past, so keep it awake:
pm_stay_alive();
...
pxp_reporter_task.c, button_interrupt_cb():{
hw_wkup_reset_interrupt();
OS_TASK_NOTIFY_FROM_ISR(pxp_reporter_task_handle, BUTTON_WKUP, OS_NOTIFY_SET_BITS);
}
pxp_reporter_task.c, pxp_reporter_task():...
/* Initialize the Wake-up Timer */
hw_wkup_init(NULL);
/* Configure the Wake-up Timer to interrupt on the falling edge of P3_0 */
hw_wkup_configure_pin(HW_GPIO_PORT_3, HW_GPIO_PIN_0, 1, HW_WKUP_PIN_STATE_HIGH);
// (I'm wondering if this is the correct implementation for my use case?)
/ *注册回调处理的事件GPIO */
hw_wkup_register_interrupt(button_interrupt_cb, 1);
...
for(;;) {
// We need a system runtime in seconds to compare with (a real RTOS-timer would be probably better, but this works also)
runtime_sec = OS_GET_TICK_COUNT() / configTICK_RATE_HZ;
// the runtime_old is updated when there's BLE activity - without it, after ten seconds the device goes to sleep:
if(runtime_sec - runtime_old > 10) {
pm_resume_sleep();
}
// this is the normal RTOS-event queue, with the event for wake-up added:
ret = OS_TASK_NOTIFY_WAIT(0, OS_TASK_NOTIFY_ALL_BITS, ¬if, OS_TASK_NOTIFY_FOREVER);
...
/* Notified from button wake-up? */
if (notif & BUTTON_WKUP) {
// Reset platform:__disable_irq();
REG_SETF(CRG_TOP, SYS_CTRL_REG, SW_RESET, 1);
}
Sorry for the messy code...
So the thing is - it works only sometimes... could you have a look and see if you see something fishy in my code? I copied the hw_wkup-code from some example, but I'm not sure if it's fitting here, since the hw_wkup-module is about a timer as I understand it?
Thanks a lot in advance,
Philipp

Hi dsandbue,
My apologies for the delay. I checked your code snippet and you could find below my recommendations:
My recommendation and a possible solution might be to set your device in extended sleep mode into the system_init(), use a timer and after its expiration use the pm_set_sleep_mode() API in order to set the hibernation. The wake up procedure via a push button connected into the P3_0 seems correct. Also, could you please clarify if you configure the P3_0 somewhere else in your application?
Thanks, PM_Dialog