spectraphilic / wasp_sketches

Waspmote sketches develoded by our group
1 stars 0 forks source link

setWatchdog safety checks #63

Open jdavid opened 5 years ago

jdavid commented 5 years ago

Just like in WaspPWR::deepSleep, after setting the alarm, get it and verify the values are as expected, if they're not then return an error.

Also, in WaspPWR::deepSleep I think sleep_disable() should be called in case of an error.

jdavid commented 5 years ago

Also, the RTC DS1337C specification and API source code don't match Libelium's documentation. It looks they did something hardware in v15 to implement a different behaviour.

From the specification and source code setWatchdog(5) adds 5 minutes to the current time and sets alarm 2 to trigger when the date, hour and minute match. So it's an "absolute" alarm actually (except it doesn't include month and year information).

From the Libelium's documentation setWatchdog(5) is supposed to trigger the alarm when the minute changes 5 times. See the technical guide, but it's better explained in http://www.libelium.com/development/waspmote/examples/rtc-10-set-watchdog/

Test we can do:

jdavid commented 5 years ago

Pushed sketches/test_scripts/test_watchdog/test_watchdog.pde

Output is:

H#
Watchdog: test whether it's absolute or relative.
- Some Libelium docs say it's relative.
- The RTC DS1337C specification says it's absolute.

RTC time: Tue, 19/04/02, 12:06:20
Watchdog Alarm matches [Date, hh:mm] --> [02, 12:07]

RTC time: Mon, 19/04/01, 00:00:55
Watchdog Alarm matches [Date, hh:mm] --> [02, 12:07]

Will reboot at next 00s or wait for the absolute date?

Inside infinite loop. Time: Mon, 19/04/01, 00:00:55
Inside infinite loop. Time: Mon, 19/04/01, 00:00:56
Inside infinite loop. Time: Mon, 19/04/01, 00:00:57
Inside infinite loop. Time: Mon, 19/04/01, 00:00:58
Inside infinite loop. Time: Mon, 19/04/01, 00:00:59
Inside infinite loop. Time: Mon, 19/04/01, 00:01:00
Inside infinite loop. Time: Mon, 19/04/01, 00:01:01
Inside infinite loop. Time: Mon, 19/04/01, 00:01:02
Inside infinite loop. Time: Mon, 19/04/01, 00:01:03
Inside infinite loop. Time: Mon, 19/04/01, 00:01:04
Inside infinite loop. Time: Mon, 19/04/01, 00:01:05
[...]

This is bad (but expected) news. What we're testing here is what happens if for some reason the RTC goes back in time.

For instance in the case the RTC time is reset to 00/01/01 the watchdog won't trigger until a far distant future. Though if the time is reset probably the alarms will reset as well (that's asnother test).

This has been tested with firmware H, maybe it's different with firmware J.

johnhulth commented 5 years ago

This is what i get.

J# Watchdog: test whether it's absolute or relative.

RTC time: Tue, 19/04/02, 12:06:20 Watchdog Alarm matches [Date, hh:mm] --> [02, 12:07]

RTC time: Mon, 19/04/01, 00:00:55 Watchdog Alarm matches [Date, hh:mm] --> [02, 12:07]

Will reboot at next 00s or wait for the absolute date?

Inside infinite loop. Time: Mon, 19/04/01, 00:00:55 Inside infinite loop. Time: Mon, 19/04/01, 00:00:56 Inside infinite loop. Time: Mon, 19/04/01, 00:00:57 Inside infinite loop. Time: Mon, 19/04/01, 00:00:58 Inside infinite loop. Time: Mon, 19/04/01, 00:00:59 Inside infinite loop. Time: Mon, 19/04/01, 00:01:00 Inside infinite loop. Time: Mon, 19/04/01, 00:01:01 Inside infinite loop. Time: Mon, 19/04/01, 00:01:02 Inside infinite loop. Time: Mon, 19/04/01, 00:01:03 Inside infinite loop. Time: Mon, 19/04/01, 00:01:04

jdavid commented 5 years ago

Thanks! It's the same behaviour.

jdavid commented 5 years ago

A new test, with the same sketch. This one tests what happens when both alarms are triggered at the same time.

H#
What happens when both alarm 1 and 2 are triggered at the same time?

RTC time: Tue, 19/04/02, 13:05:40
Alarm 1  Alarm matches [Date, hh:mm:ss] --> [02, 13:06:00]
Watchdog Alarm matches [Date, hh:mm] --> [02, 13:06]

Sleep..

H#
What happens when both alarm 1 and 2 are triggered at the same time?

RTC time: Tue, 19/04/02, 13:05:40
Alarm 1  Alarm matches [Date, hh:mm:ss] --> [02, 13:06:00]
Watchdog Alarm matches [Date, hh:mm] --> [02, 13:06]

Sleep..

H#

The watchdog wins.

EDIT: Tests by John with J firmware show that most often Alarm 1 wins, but sometimes the watchdog wins.

jdavid commented 5 years ago

TODO:

jdavid commented 5 years ago

Many changes have been done already, mostly details. Here a couple of highlights:

Updated and extended TODO list: