我让esp8266进入light_sleep,并定时唤醒,唤醒周期设为0xFFFFFF0(为268435440us),每次唤醒,调用一次system_get_time(),这个函数一开始返回的数据是正常的,但是后来就变得不对,像是右移了8位。如下图所示。唤醒周期没有错,基本上是4分多钟醒来一次。
我的代码是这样的:
Code: Select all
uint32_t ICACHE_FLASH_ATTR
current_local_time() {
uint32_t rtc = system_get_time();
uint32_t passed;
if (rtc < last_sntp_rtc) {
passed = 0xFFFFFFFF - last_sntp_rtc + rtc;
} else {
passed = rtc - last_sntp_rtc;
}
DB_LOG("current_local_time: last_sntp_rtc = %d, rtc = %d, last_sntp_time = %d\n", last_sntp_rtc, rtc, last_sntp_time);
passed /= 1000000;
last_sntp_time += passed;
last_sntp_rtc = rtc;
return last_sntp_time;
}
void ICACHE_FLASH_ATTR
wakeup_cb() {
uint32_t time = current_local_time();
//light_led(CHARGE_LED);
DB_LOG("enter wake up: %d %s\n", time, sntp_get_real_time(time));
if (1 == GPIO_INPUT_GET(GPIO_ID_PIN(KEY_SWITCH_NUM))) {
DB_LOG("sleep again\n");
wifi_fpm_do_sleep(FPM_SLEEP_MAX_TIME);
}
void ICACHE_FLASH_ATTR
save_power() {
//low_power_config();
gpio_pin_wakeup_enable(KEY_SWITCH_NUM, GPIO_PIN_INTR_LOLEVEL);
wifi_station_disconnect();
wifi_set_opmode_current(NULL_MODE); // set WiFi mode to null mode
wifi_fpm_set_sleep_type(LIGHT_SLEEP_T); // set modem sleep
wifi_fpm_open(); // enable force sleep
wifi_fpm_set_wakeup_cb(wakeup_cb);
SET_PERI_REG_MASK(UART_CONF0(0), UART_TXFIFO_RST);//RESET FIFO
CLEAR_PERI_REG_MASK(UART_CONF0(0), UART_TXFIFO_RST);
wifi_fpm_do_sleep(FPM_SLEEP_MAX_TIME);
}
请帮忙看看是什么原因?