From 7bd10e8a1770da4d97f586f6a77aca75ebd52cce Mon Sep 17 00:00:00 2001 From: Johny Mattsson Date: Sat, 27 Jun 2015 12:34:03 +1000 Subject: [PATCH] Added node.bootreason() to inspect boot cause. --- app/include/rom.h | 3 +++ app/modules/node.c | 8 ++++++++ 2 files changed, 11 insertions(+) diff --git a/app/include/rom.h b/app/include/rom.h index 51d3fbe1..de031179 100644 --- a/app/include/rom.h +++ b/app/include/rom.h @@ -39,6 +39,9 @@ extern unsigned char * base64_decode(const unsigned char *src, size_t len, size_ extern void mem_init(void * start_addr); +// 2, 3 = reset (module dependent?), 4 = wdt +int rtc_get_reset_reason (void); + // Hardware exception handling struct exception_frame { diff --git a/app/modules/node.c b/app/modules/node.c index 5f6ae9bd..ce8d29cd 100644 --- a/app/modules/node.c +++ b/app/modules/node.c @@ -414,6 +414,13 @@ static int node_setcpufreq(lua_State* L) return 1; } +// Lua: code = bootreason() +static int node_bootreason (lua_State *L) +{ + lua_pushnumber (L, rtc_get_reset_reason ()); + return 1; +} + // Module function map #define MIN_OPT_LEVEL 2 #include "lrodefs.h" @@ -438,6 +445,7 @@ const LUA_REG_TYPE node_map[] = { LSTRKEY( "CPU80MHZ" ), LNUMVAL( CPU80MHZ ) }, { LSTRKEY( "CPU160MHZ" ), LNUMVAL( CPU160MHZ ) }, { LSTRKEY( "setcpufreq" ), LFUNCVAL( node_setcpufreq) }, + { LSTRKEY( "bootreason" ), LFUNCVAL( node_bootreason) }, // Combined to dsleep(us, option) // { LSTRKEY( "dsleepsetoption" ), LFUNCVAL( node_deepsleep_setoption) }, #if LUA_OPTIMIZE_MEMORY > 0