Wake-up from hibernation and sw-resetting the device

⚠️
Hi there.. thanks for coming to the forums. Exciting news! we’re now in the process of moving to our new forum platform that will offer better functionality and is contained within the main Dialog website. All posts and accounts have been migrated. We’re now accepting traffic on the new forum only - please POST any new threads at//www.wsdof.com/support. We’ll be fixing bugs / optimising the searching and tagging over the coming days.
2 posts / 0 new
Last post
dsandbue
Offline
Last seen:1 year 8 months ago
Joined:2017-02-15 14:09
Wake-up from hibernation and sw-resetting the device

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

Device:
PM_Dialog
Offline
Last seen:10 hours 23 min ago
Staff
Joined:2018-02-08 11:03
Hi dsandbue,

Hi dsandbue,

My apologies for the delay. I checked your code snippet and you could find below my recommendations:

  • I would suggest you to se the sleep mode as extended sleep into the system_init() and the reason is that when the system wakes up from the hibernation, the system resets and runs from the start. This is not a software reset, it’s like a hardware reset, so the system will run the code from the start and the system_init() will be executed again (every time that the 680 wakes up from the hibernation)
  • The pm_stay_alive() is not needed into the system_init() because sets the system always active and it is not an efficient way. Also, the pm_resume_sleep() is not needed.
  • The pins configuration is completely correct because the 680 can wake up from the hibernation via the wake-up controller, so you should configure the P3_0 as a wake-up interrupt. Your implementation is correct.
  • 我能看到从你的代码片段,你disable the interrupts and a software reset is occurred. It is not recommended to occur a software reset manually, because as I have already mentioned in my first comment, when the device wakes up from the hibernation, the code will run from the start as a hardware reset is happened.

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