Navigation Menu

Skip to content

Commit

Permalink
Add WDT.feed()
Browse files Browse the repository at this point in the history
    PUBLISHED_FROM=f96adc6eb0b8f34e48ed2d0a8b6a1cb2b39c9dff
  • Loading branch information
alashkin authored and Marko Mikulicic committed Jul 2, 2015
1 parent d5d9ea8 commit 5cf9f21
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 4 deletions.
5 changes: 5 additions & 0 deletions platforms/esp8266/README.md
Expand Up @@ -73,6 +73,11 @@ See [temperature sensor driver](https://github.com/cesanta/smart.js/blob/master/

## HTTP

## Watchdog timer

ESP8266 includes a watchdog timer, a mechanism designed to deal with software lockups. This timer is periodically reset by the OS, or can be explicitly "fed" by user code. Failure to do so will cause the device to be reset.
The current default watchdog timer period is about 1 minute.
- `OS.wdt_feed()` - delay restart of the device for 1 minute. This function has to be called inside long loops, or other long operations to prevent device reset.

## Wifi

Expand Down
9 changes: 5 additions & 4 deletions platforms/esp8266/user/user_main.c
Expand Up @@ -49,6 +49,11 @@ ICACHE_FLASH_ATTR void init_done_cb() {
os_timer_disarm(&startcmd_timer);
os_timer_setfn(&startcmd_timer, start_cmd, NULL);
os_timer_arm(&startcmd_timer, 500, 0);

#ifndef ESP_ENABLE_HW_WATCHDOG
ets_wdt_disable();
#endif
pp_soft_wdt_stop();
}

// Init function
Expand All @@ -58,10 +63,6 @@ ICACHE_FLASH_ATTR void user_init() {
uart_div_modify(0, UART_CLK_FREQ / 115200);
system_set_os_print(0);

#ifndef ESP_ENABLE_WATCHDOG
ets_wdt_disable();
#endif

#ifdef V7_ESP_GDB_SERVER
/* registers exception handlers so that you can hook in gdb on crashes */
gdb_init();
Expand Down
11 changes: 11 additions & 0 deletions platforms/esp8266/user/v7_esp.c
Expand Up @@ -86,6 +86,16 @@ ICACHE_FLASH_ATTR static v7_val_t set_timeout(struct v7 *v7, v7_val_t this_obj,
return v7_create_undefined();
}

ICACHE_FLASH_ATTR static v7_val_t OS_wdt_feed(struct v7 *v7, v7_val_t this_obj,
v7_val_t args) {
(void)v7;
(void)this_obj;
(void)args;
pp_soft_wdt_restart();

return v7_create_boolean(1);
}

ICACHE_FLASH_ATTR static v7_val_t Wifi_connect(struct v7 *v7, v7_val_t this_obj,
v7_val_t args) {
(void) v7;
Expand Down Expand Up @@ -552,6 +562,7 @@ ICACHE_FLASH_ATTR void init_v7(void *stack_base) {
os = v7_create_object(v7);
v7_set(v7, v7_get_global_object(v7), "OS", 2, 0, os);
v7_set_method(v7, os, "prof", OS_prof);
v7_set_method(v7, os, "wdt_feed", OS_wdt_feed);

init_i2cjs(v7);
init_gpiojs(v7);
Expand Down
1 change: 1 addition & 0 deletions platforms/esp8266/user/v7_esp.h
Expand Up @@ -9,5 +9,6 @@ extern struct v7 *v7;

void init_v7();
void wifi_changed_cb(System_Event_t *evt);
void pp_soft_wdt_restart();

#endif /* V7_ESP_INCLUDED */

0 comments on commit 5cf9f21

Please sign in to comment.