Skip to content

Commit 6ef2123

Browse files
committed
If watchdog is on and automatic, ensure that reset() keeps the automatic kicking going
Ensure that a console stays locked even after Ensure interpreter flags (eg echo) are cleared after a `reset()` nRF5x: When watchdog is on and automatic, automatically wake up often enough to service it
1 parent b051476 commit 6ef2123

File tree

5 files changed

+21
-5
lines changed

5 files changed

+21
-5
lines changed

ChangeLog

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@
55
Smartibot devices now advertise on BLE as 'Smartibot abcd'
66
nRF5x: Leave digital input disconnected for analog read (saves power)
77
nRF5x: Return 'analog' as pin mode for any pin where input is disconnected
8+
If watchdog is on and automatic, ensure that `reset()` keeps the automatic kicking going
9+
Ensure that a console stays locked even after
10+
Ensure interpreter flags (eg echo) are cleared after a `reset()`
11+
nRF5x: When watchdog is on and automatic, automatically wake up often enough to service it
812

913
2v03 : nRF5x: Fix issue when calling NRF.setAdvertising while connected via BLE (fix #1659)
1014
nRF5x: 'dump()' not outputs `NRF.setSecurity` line if it has been called.

src/jsinteractive.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -777,7 +777,7 @@ void jsiSemiInit(bool autoLoad) {
777777
// Set state
778778
interruptedDuringEvent = false;
779779
// Set defaults
780-
jsiStatus &= ~JSIS_SOFTINIT_MASK;
780+
jsiStatus &= JSIS_SOFTINIT_MASK;
781781
#ifndef SAVE_ON_FLASH
782782
pinBusyIndicator = DEFAULT_BUSY_PIN_INDICATOR;
783783
#endif

src/jsinteractive.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,8 @@ typedef enum {
149149
JSIS_COMPLETELY_RESET = 1<<11, ///< Has the board powered on, having not loaded anything from flash
150150

151151
JSIS_ECHO_OFF_MASK = JSIS_ECHO_OFF|JSIS_ECHO_OFF_FOR_LINE,
152-
JSIS_SOFTINIT_MASK = JSIS_PASSWORD_PROTECTED // stuff that DOESN'T get reset on softinit
152+
JSIS_SOFTINIT_MASK = JSIS_PASSWORD_PROTECTED|JSIS_WATCHDOG_AUTO // stuff that DOESN'T get reset on softinit
153+
// watchdog can't be reset without a reboot so if it's set to auto we must keep it as auto
153154
} PACKED_FLAGS JsiStatus;
154155

155156
extern JsiStatus jsiStatus;

src/jswrap_espruino.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -623,10 +623,9 @@ setInterval(function() {
623623
624624
**NOTE:** This is only implemented on STM32 and nRF5x devices (all official Espruino boards).
625625
626-
**NOTE:** On STM32 (Pico, WiFi, Original) with `setDeepSleep(1)`, or nRF52 (Puck, Pixl, MDBT42) you need to
626+
**NOTE:** On STM32 (Pico, WiFi, Original) with `setDeepSleep(1)` you need to
627627
explicitly wake Espruino up with an interval of less than the watchdog timeout or the watchdog will fire and
628-
the board will reboot.
629-
628+
the board will reboot. You can do this with `setInterval("", time_in_milliseconds)`.
630629
*/
631630
void jswrap_espruino_enableWatchdog(JsVarFloat time, JsVar *isAuto) {
632631
if (time<0 || isnan(time)) time=1;

targets/nrf5x/jshardware.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1580,6 +1580,18 @@ bool jshSleep(JsSysTime timeUntilWake) {
15801580
*/
15811581
if (timeUntilWake > jshGetTimeFromMilliseconds(240*1000))
15821582
timeUntilWake = jshGetTimeFromMilliseconds(240*1000);
1583+
1584+
/* Are we set to ping the watchdog automatically? If so ensure
1585+
* that we always wake up often enough to ping it by ensuring
1586+
* we don't sleep for more than half the WDT time. */
1587+
if (jsiStatus&JSIS_WATCHDOG_AUTO) {
1588+
// actual time is CRV / 32768 seconds
1589+
// we just kicked watchdog (in jsinteractive.c) so aim to wake up just a little before it fires
1590+
JsSysTime max = jshGetTimeFromMilliseconds(NRF_WDT->CRV/34.000);
1591+
if (timeUntilWake > max) timeUntilWake = max;
1592+
}
1593+
1594+
15831595
if (timeUntilWake < JSSYSTIME_MAX) {
15841596
#ifdef BLUETOOTH
15851597
#if NRF_SD_BLE_API_VERSION<5

0 commit comments

Comments
 (0)