system_get_time() 返回奇怪的值

wawaii
Posts: 25
Joined: Thu Aug 11, 2016 3:15 pm

system_get_time() 返回奇怪的值

Postby wawaii » Wed Sep 14, 2016 11:13 am

你好!

我让esp8266进入light_sleep,并定时唤醒,唤醒周期设为0xFFFFFF0(为268435440us),每次唤醒,调用一次system_get_time(),这个函数一开始返回的数据是正常的,但是后来就变得不对,像是右移了8位。如下图所示。唤醒周期没有错,基本上是4分多钟醒来一次。
捕获.PNG
捕获.PNG (7.43 KiB) Viewed 4891 times

我的代码是这样的:

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);
}


请帮忙看看是什么原因?

tobewinner
Posts: 45
Joined: Tue Jan 19, 2016 2:39 pm

Re: system_get_time() 返回奇怪的值

Postby tobewinner » Wed Sep 21, 2016 5:23 pm

system_get_rtc_time呢?

esp8266
Posts: 1
Joined: Tue Sep 27, 2016 1:11 am

Re: system_get_time() 返回奇怪的值

Postby esp8266 » Tue Sep 27, 2016 1:20 am

你好!我最近也遇到相似的问题,可以加个好友嘛?一起探讨下 我qq 2260571610

Who is online

Users browsing this forum: Google [Bot], MSN [Bot] and 8 guests