ESP8266 Developer Zone The Official ESP8266 Forum 2016-09-27T01:20:12+08:00 https://bbs.espressif.com:443/feed.php?f=7&t=2774 2016-09-27T01:20:12+08:00 2016-09-27T01:20:12+08:00 https://bbs.espressif.com:443/viewtopic.php?t=2774&p=9952#p9952 <![CDATA[Re: system_get_time() 返回奇怪的值]]> Statistics: Posted by esp8266 — Tue Sep 27, 2016 1:20 am


]]>
2016-09-21T17:23:51+08:00 2016-09-21T17:23:51+08:00 https://bbs.espressif.com:443/viewtopic.php?t=2774&p=9905#p9905 <![CDATA[Re: system_get_time() 返回奇怪的值]]> Statistics: Posted by tobewinner — Wed Sep 21, 2016 5:23 pm


]]>
2016-09-14T11:13:21+08:00 2016-09-14T11:13:21+08:00 https://bbs.espressif.com:443/viewtopic.php?t=2774&p=9820#p9820 <![CDATA[system_get_time() 返回奇怪的值]]>
我让esp8266进入light_sleep,并定时唤醒,唤醒周期设为0xFFFFFF0(为268435440us),每次唤醒,调用一次system_get_time(),这个函数一开始返回的数据是正常的,但是后来就变得不对,像是右移了8位。如下图所示。唤醒周期没有错,基本上是4分多钟醒来一次。
捕获.PNG

我的代码是这样的:

Code:

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


请帮忙看看是什么原因?

Statistics: Posted by wawaii — Wed Sep 14, 2016 11:13 am


]]>