STATIC mp_obj_t machine_deepsleep(void) { // default to sleep forever uint32_t sleep_us = 0; // see if RTC.ALARM0 should wake the device if (pyb_rtc_alarm0_wake & MACHINE_WAKE_DEEPSLEEP) { uint64_t t = pyb_rtc_get_us_since_2000(); if (pyb_rtc_alarm0_expiry <= t) { sleep_us = 1; // alarm already expired so wake immediately } else { uint64_t delta = pyb_rtc_alarm0_expiry - t; if (delta <= 0xffffffff) { // sleep for the desired time sleep_us = delta; } else { // overflow, just set to maximum sleep time sleep_us = 0xffffffff; } } } // prepare for RTC reset at wake up rtc_prepare_deepsleep(sleep_us); // put the device in a deep-sleep state system_deep_sleep_set_option(0); // default power down mode; TODO check this system_deep_sleep(sleep_us); for (;;) { // we must not return ets_loop_iter(); } return mp_const_none; }
static enum v7_err dsleep(struct v7 *v7, v7_val_t *res) { enum v7_err rcode = V7_OK; v7_val_t time_v = v7_arg(v7, 0); double time = v7_to_number(time_v); v7_val_t flags_v = v7_arg(v7, 1); uint8 flags = v7_to_number(flags_v); if (!v7_is_number(time_v) || time < 0) { *res = v7_mk_boolean(false); goto clean; } if (v7_is_number(flags_v)) { if (!system_deep_sleep_set_option(flags)) { *res = v7_mk_boolean(false); goto clean; } } system_deep_sleep((uint32_t) time); *res = v7_mk_boolean(true); goto clean; clean: return rcode; }
// Lua: dsleep( us, option ) static int node_deepsleep( lua_State* L ) { uint32 us; uint8 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 system_deep_sleep_set_option( option ); } // Set deleep time, skip if nil if ( lua_isnumber(L, 1) ) { us = luaL_checknumber(L, 1); // if ( us <= 0 ) if ( us < 0 ) return luaL_error( L, "wrong arg range" ); else system_deep_sleep( us ); } return 0; }
STATIC mp_obj_t esp_deepsleep(mp_uint_t n_args, const mp_obj_t *args) { uint32_t sleep_us = n_args > 0 ? mp_obj_get_int(args[0]) : 0; // prepare for RTC reset at wake up rtc_prepare_deepsleep(sleep_us); system_deep_sleep_set_option(n_args > 1 ? mp_obj_get_int(args[1]) : 0); system_deep_sleep(sleep_us); return mp_const_none; }
static void do_sleep_opt (lua_State *L, int idx) { if (lua_isnumber (L, idx)) { uint32_t opt = lua_tonumber (L, idx); if (opt < 0 || opt > 4) luaL_error (L, "unknown sleep option"); system_deep_sleep_set_option (opt); } }
/****************************************************************************** * FunctionName : user_init * Description : entry of user application, init user function here * Parameters : none * Returns : none *******************************************************************************/ void ICACHE_FLASH_ATTR user_init(void) { sys_read_cfg(); if(!syscfg.cfg.b.debug_print_enable) system_set_os_print(0); uart_init(); #if USE_TMP2NET_PORT GPIO0_MUX = 0; #else GPIO0_MUX = VAL_MUX_GPIO0_SDK_DEF; #endif GPIO4_MUX = VAL_MUX_GPIO4_SDK_DEF; GPIO5_MUX = VAL_MUX_GPIO5_SDK_DEF; GPIO12_MUX = VAL_MUX_GPIO12_SDK_DEF; GPIO14_MUX = VAL_MUX_GPIO14_SDK_DEF; system_timer_reinit(); #if DEBUGSOO > 0 os_printf("\nSimple WEB version: " WEB_SVERSION "\nOpenLoaderSDK v1.2\n"); #endif if(syscfg.cfg.b.pin_clear_cfg_enable) test_pin_clr_wifi_config(); set_cpu_clk(); // select cpu frequency 80 or 160 MHz #if DEBUGSOO > 0 if(eraminfo.size > 0) os_printf("Found free IRAM: base: %p, size: %d bytes\n", eraminfo.base, eraminfo.size); os_printf("System memory:\n"); system_print_meminfo(); os_printf("Start 'heap' size: %d bytes\n", system_get_free_heap_size()); #endif #if DEBUGSOO > 0 os_printf("Set CPU CLK: %u MHz\n", ets_get_cpu_frequency()); #endif Setup_WiFi(); #if USE_TMP2NET_PORT tpm2net_init(); #endif #ifdef USE_NETBIOS if(syscfg.cfg.b.netbios_ena) netbios_init(); #endif /* #ifdef USE_SNTP if(syscfg.cfg.b.sntp_ena) sntp_init(); #endif */ #ifdef UDP_TEST_PORT if(syscfg.udp_port) udp_test_port_init(syscfg.udp_port); #endif // инициализация и запуск tcp серверa(ов) #ifdef USE_SRV_WEB_PORT if(syscfg.web_port) webserver_init(syscfg.web_port); #endif /// if(syscfg.tcp2uart_port) tcp2uart_init(syscfg.tcp2uart_port); #ifdef USE_MODBUS mdb_tcp_init(502); #endif #ifdef USE_WDRV init_wdrv(); #endif system_deep_sleep_set_option(0); system_init_done_cb(init_done_cb); }
/****************************************************************************** * FunctionName : user_init * Description : entry of user application, init user function here * Parameters : none * Returns : none *******************************************************************************/ void ICACHE_FLASH_ATTR user_init(void) { if(eraminfo.size > 0) os_printf("Found free IRAM: base: %p, size: %d bytes\n", eraminfo.base, eraminfo.size); os_printf("System memory:\n"); system_print_meminfo(); os_printf("bssi : 0x%x ~ 0x%x, len: %d\n", &_lit4_start, &_lit4_end, (uint32)(&_lit4_end) - (uint32)(&_lit4_start)); os_printf("free : 0x%x ~ 0x%x, len: %d\n", (uint32)(&_lit4_end), (uint32)(eraminfo.base) + eraminfo.size, (uint32)(eraminfo.base) + eraminfo.size - (uint32)(&_lit4_end)); os_printf("Start 'heap' size: %d bytes\n", system_get_free_heap_size()); os_printf("Set CPU CLK: %u MHz\n", ets_get_cpu_frequency()); system_deep_sleep_set_option(0); wifi_set_event_handler_cb(wifi_handle_event_cb); system_init_done_cb(init_done_cb); }
static v7_val_t dsleep(struct v7 *v7) { v7_val_t time_v = v7_arg(v7, 0); uint32 time = v7_to_number(time_v); v7_val_t flags_v = v7_arg(v7, 1); uint8 flags = v7_to_number(flags_v); if (!v7_is_number(time_v) || time < 0) return v7_create_boolean(false); if (v7_is_number(flags_v)) { if (!system_deep_sleep_set_option(flags)) return v7_create_boolean(false); } system_deep_sleep(time); return v7_create_boolean(true); }
/****************************************************************************** * FunctionName : user_init * Description : entry of user application, init user function here * Parameters : none * Returns : none *******************************************************************************/ void ICACHE_FLASH_ATTR user_init(void) { sys_read_cfg(); if(!syscfg.cfg.b.debug_print_enable) system_set_os_print(0); GPIO0_MUX = VAL_MUX_GPIO0_SDK_DEF; GPIO4_MUX = VAL_MUX_GPIO4_SDK_DEF; GPIO5_MUX = VAL_MUX_GPIO5_SDK_DEF; GPIO12_MUX = VAL_MUX_GPIO12_SDK_DEF; GPIO13_MUX = VAL_MUX_GPIO13_SDK_DEF; GPIO14_MUX = VAL_MUX_GPIO14_SDK_DEF; GPIO15_MUX = VAL_MUX_GPIO15_SDK_DEF; // vad7 //power_meter_init(); // //uart_init(); // in tcp2uart.h system_timer_reinit(); #if (DEBUGSOO > 0 && defined(USE_WEB)) os_printf("\nSimple WEB version: " WEB_SVERSION "\n"); #endif //if(syscfg.cfg.b.pin_clear_cfg_enable) test_pin_clr_wifi_config(); // сброс настроек, если замкнут пин RX set_cpu_clk(); // select cpu frequency 80 or 160 MHz #ifdef USE_GDBSTUB extern void gdbstub_init(void); gdbstub_init(); #endif #if DEBUGSOO > 0 if(eraminfo.size > 0) os_printf("Found free IRAM: base: %p, size: %d bytes\n", eraminfo.base, eraminfo.size); os_printf("System memory:\n"); system_print_meminfo(); os_printf("bssi : 0x%x ~ 0x%x, len: %d\n", &_lit4_start, &_lit4_end, (uint32)(&_lit4_end) - (uint32)(&_lit4_start)); os_printf("free : 0x%x ~ 0x%x, len: %d\n", (uint32)(&_lit4_end), (uint32)(eraminfo.base) + eraminfo.size, (uint32)(eraminfo.base) + eraminfo.size - (uint32)(&_lit4_end)); os_printf("Start 'heap' size: %d bytes\n", system_get_free_heap_size()); #endif #if DEBUGSOO > 0 os_printf("Set CPU CLK: %u MHz\n", ets_get_cpu_frequency()); #endif Setup_WiFi(); WEBFSInit(); // файловая система system_deep_sleep_set_option(0); system_init_done_cb(init_done_cb); }
/****************************************************************************** * FunctionName : user_init * Description : entry of user application, init user function here * Parameters : none * Returns : none *******************************************************************************/ void ICACHE_FLASH_ATTR user_init(void) { sys_read_cfg(); if(!syscfg.cfg.b.debug_print_enable) system_set_os_print(0); uart_init(); GPIO0_MUX = VAL_MUX_GPIO0_SDK_DEF; GPIO4_MUX = VAL_MUX_GPIO4_SDK_DEF; GPIO5_MUX = VAL_MUX_GPIO5_SDK_DEF; GPIO12_MUX = VAL_MUX_GPIO12_SDK_DEF; GPIO14_MUX = VAL_MUX_GPIO14_SDK_DEF; system_timer_reinit(); #if (DEBUGSOO > 0 && defined(USE_WEB)) os_printf("\nSimple WEB version: " WEB_SVERSION "\nOpenLoaderSDK v1.2\n"); #endif if(syscfg.cfg.b.pin_clear_cfg_enable) test_pin_clr_wifi_config(); set_cpu_clk(); // select cpu frequency 80 or 160 MHz #ifdef USE_GDBSTUB extern void gdbstub_init(void); gdbstub_init(); #endif #if DEBUGSOO > 0 if(eraminfo.size > 0) os_printf("Found free IRAM: base: %p, size: %d bytes\n", eraminfo.base, eraminfo.size); os_printf("System memory:\n"); system_print_meminfo(); os_printf("Start 'heap' size: %d bytes\n", system_get_free_heap_size()); #endif #if DEBUGSOO > 0 os_printf("Set CPU CLK: %u MHz\n", ets_get_cpu_frequency()); #endif Setup_WiFi(); #ifdef USE_WDRV init_wdrv(); #endif Set_WiFi(&wificonfig, Cmp_WiFi_chg(&wificonfig) & (WIFI_MASK_SLEEP|WIFI_MASK_STDHCP|WIFI_MASK_APIPDHCP)); WEBFSInit(); // файловая система system_deep_sleep_set_option(0); system_init_done_cb(init_done_cb); }
bool SystemClass::deepSleep(uint32 timeMilliseconds, DeepSleepOptions options /* = eDSO_RF_CAL_BY_INIT_DATA */) { if (!system_deep_sleep_set_option((uint8)options)) return false; system_deep_sleep(timeMilliseconds * 1000); return true; }
void EspClass::deepSleep(uint32_t time_us, WakeMode mode) { system_deep_sleep_set_option(static_cast<int>(mode)); system_deep_sleep(time_us); }
void user_rf_pre_init(void) { system_deep_sleep_set_option(2); // No radio calibration after deep-sleep wake up; this reduces the current consumption }
static void ICACHE_FLASH_ATTR deepSleepCb(void *arg) { system_deep_sleep_set_option(2); system_deep_sleep(100*1000); }