From 5894df1da68460c9bf136023262c7da662a5a4fe Mon Sep 17 00:00:00 2001 From: HuangRui Date: Thu, 29 Jan 2015 14:21:38 +0800 Subject: [PATCH] =?UTF-8?q?Combined=20dsleep=5Fset=5Foptions(option)=20to?= =?UTF-8?q?=20dsleep(=20us,=20option=20)=20*=20dsleep(=20us,=20option=20)?= =?UTF-8?q?=20Hardware=20has=20to=20support=20deep-sleep=20wake=20up=20(XP?= =?UTF-8?q?D=5FDCDC=20connects=20to=20EXT=5FRSTB=20with=200R).=20system=5F?= =?UTF-8?q?deep=5Fsleep(0)=20=EF=BC=8Cset=20no=20wake=20up=20timer?= =?UTF-8?q?=EF=BC=8Cconnect=20a=20GPIO=20to=20pin=20RST,=20the=20chip=20wi?= =?UTF-8?q?ll=20wake=20up=20by=20a=20falling-edge=20on=20pin=20RST.=20**?= =?UTF-8?q?=20us:=20Integer=20time=20to=20sleep.=20if=20us=20=3D=200,=20it?= =?UTF-8?q?=20will=20sleep=20forever.=20**=20option:=20Integer=20option=3D?= =?UTF-8?q?0,=20init=20data=20byte=20108=20is=20valuable;=20option>0,=20in?= =?UTF-8?q?it=20data=20byte=20108=20is=20valueless.=20More=20details=20as?= =?UTF-8?q?=20follows:=200,=20RF=5FCAL=20or=20not=20after=20deep-sleep=20w?= =?UTF-8?q?ake=20up,=20depends=20on=20init=20data=20byte=20108.=201,=20RF?= =?UTF-8?q?=5FCAL=20after=20deep-sleep=20wake=20up,=20there=20will=20belar?= =?UTF-8?q?ge=20current.=202,=20no=20RF=5FCAL=20after=20deep-sleep=20wake?= =?UTF-8?q?=20up,=20there=20will=20only=20be=20small=20current.=204,=20dis?= =?UTF-8?q?able=20RF=20after=20deep-sleep=20wake=20up,=20just=20like=20mod?= =?UTF-8?q?em=20sleep,=20there=20will=20be=20the=20smallest=20current.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/modules/node.c | 57 ++++++++++++++++++++++++++++++---------------- 1 file changed, 38 insertions(+), 19 deletions(-) diff --git a/app/modules/node.c b/app/modules/node.c index 909acd02..11b7b6b6 100644 --- a/app/modules/node.c +++ b/app/modules/node.c @@ -11,7 +11,8 @@ #include "romfs.h" #include "c_string.h" #include "driver/uart.h" -#include "spi_flash.h" +//#include "spi_flash.h" +#include "user_interface.h" #include "flash_api.h" // Lua: restart() @@ -21,30 +22,47 @@ static int node_restart( lua_State* L ) return 0; } -// Lua: dsleep( us ) +// Lua: dsleep( us, option ) static int node_deepsleep( lua_State* L ) { - s32 us; - us = luaL_checkinteger( L, 1 ); - // if ( us <= 0 ) - if ( us < 0 ) - return luaL_error( L, "wrong arg range" ); - system_deep_sleep( us ); + s32 us, option; + //us = luaL_checkinteger( L, 1 ); + // Set deleep option, skip if nil + if ( lua_isnumber(L, 2) ) + { + option = lua_tointeger(L, 2); + if ( option < 0 || option > 4) + return luaL_error( L, "wrong arg range" ); + else + deep_sleep_set_option( option ); + } + // Set deleep time, skip if nil + if ( lua_isnumber(L, 1) ) + { + us = lua_tointeger(L, 1); + // if ( us <= 0 ) + if ( us < 0 ) + return luaL_error( L, "wrong arg range" ); + else + system_deep_sleep( us ); + } return 0; } // Lua: dsleep_set_options -static int node_deepsleep_setoption( lua_State* L ) -{ - s32 option; - option = luaL_checkinteger( L, 1 ); - if ( option < 0 || option > 4) - return luaL_error( L, "wrong arg range" ); - else - deep_sleep_set_option( option ); - return 0; -} +// Combined to dsleep( us, option ) +// static int node_deepsleep_setoption( lua_State* L ) +// { +// s32 option; +// option = luaL_checkinteger( L, 1 ); +// if ( option < 0 || option > 4) +// return luaL_error( L, "wrong arg range" ); +// else +// deep_sleep_set_option( option ); +// return 0; +// } // Lua: info() + static int node_info( lua_State* L ) { lua_pushinteger(L, NODE_VERSION_MAJOR); @@ -307,7 +325,8 @@ const LUA_REG_TYPE node_map[] = { LSTRKEY( "input" ), LFUNCVAL( node_input ) }, { LSTRKEY( "output" ), LFUNCVAL( node_output ) }, { LSTRKEY( "readvdd33" ), LFUNCVAL( node_readvdd33) }, - { LSTRKEY( "dsleepsetoption" ), LFUNCVAL( node_deepsleep_setoption) }, +// Combined to dsleep(us, option) +// { LSTRKEY( "dsleepsetoption" ), LFUNCVAL( node_deepsleep_setoption) }, #if LUA_OPTIMIZE_MEMORY > 0 #endif