diff --git a/esp-link/cgiflash.c b/esp-link/cgiflash.c index 6b8de5c..1ce8469 100644 --- a/esp-link/cgiflash.c +++ b/esp-link/cgiflash.c @@ -13,9 +13,7 @@ Some flash handling cgi routines. Used for reading the existing flash and updati * ---------------------------------------------------------------------------- */ - #include -#include #include "cgi.h" #include "cgiflash.h" @@ -181,7 +179,7 @@ int ICACHE_FLASH_ATTR cgiRebootFirmware(HttpdConnData *connData) { system_upgrade_flag_set(UPGRADE_FLAG_FINISH); os_timer_disarm(&flash_reboot_timer); os_timer_setfn(&flash_reboot_timer, (os_timer_func_t *)system_upgrade_reboot, NULL); - os_timer_arm(&flash_reboot_timer, 2000, 1); + os_timer_arm_us(&flash_reboot_timer, 2 * 1000000, 1); return HTTPD_CGI_DONE; } @@ -195,6 +193,6 @@ int ICACHE_FLASH_ATTR cgiReset(HttpdConnData *connData) { // Schedule a reboot os_timer_disarm(&flash_reboot_timer); os_timer_setfn(&flash_reboot_timer, (os_timer_func_t *)system_restart, NULL); - os_timer_arm(&flash_reboot_timer, 2000, 1); + os_timer_arm_us(&flash_reboot_timer, 2 * 1000000, 1); return HTTPD_CGI_DONE; } diff --git a/esp-link/cgiservices.c b/esp-link/cgiservices.c index ef76287..905d6af 100644 --- a/esp-link/cgiservices.c +++ b/esp-link/cgiservices.c @@ -38,7 +38,7 @@ int ICACHE_FLASH_ATTR cgiSystemSet(HttpdConnData *connData) { // schedule hostname change-over os_timer_disarm(&reassTimer); os_timer_setfn(&reassTimer, configWifiIP, NULL); - os_timer_arm(&reassTimer, 1000, 0); // 1 second for the response of this request to make it + os_timer_arm_us(&reassTimer, 1 * 1000000, 0); // 1 second for the response of this request to make it } if (configSave()) { diff --git a/esp-link/cgiwifi.c b/esp-link/cgiwifi.c index bf699ca..f15aa21 100644 --- a/esp-link/cgiwifi.c +++ b/esp-link/cgiwifi.c @@ -335,7 +335,7 @@ static void ICACHE_FLASH_ATTR resetTimerCb(void *arg) { // We're happily connected, go to STA mode DBG("Wifi got IP. Going into STA mode..\n"); wifi_set_opmode(1); - os_timer_arm(&resetTimer, RESET_TIMEOUT, 0); // check one more time after switching to STA-only + os_timer_arm_us(&resetTimer, RESET_TIMEOUT * 1000, 0); // check one more time after switching to STA-only #endif } log_uart(false); @@ -349,7 +349,7 @@ static void ICACHE_FLASH_ATTR resetTimerCb(void *arg) { } log_uart(true); DBG("Enabling/continuing uart log\n"); - os_timer_arm(&resetTimer, RESET_TIMEOUT, 0); + os_timer_arm_us(&resetTimer, RESET_TIMEOUT * 1000, 0); } } @@ -527,7 +527,7 @@ int ICACHE_FLASH_ATTR cgiWiFiSpecial(HttpdConnData *connData) { // schedule change-over os_timer_disarm(&reassTimer); os_timer_setfn(&reassTimer, configWifiIP, NULL); - os_timer_arm(&reassTimer, 1000, 0); // 1 second for the response of this request to make it + os_timer_arm_us(&reassTimer, 1 * 1000000, 0); // 1 second for the response of this request to make it // return redirect info jsonHeader(connData, 200); httpdSend(connData, url, -1); @@ -700,7 +700,7 @@ int ICACHE_FLASH_ATTR cgiWiFiSetMode(HttpdConnData *connData) { wifi_station_connect(); os_timer_disarm(&resetTimer); os_timer_setfn(&resetTimer, resetTimerCb, NULL); - os_timer_arm(&resetTimer, RESET_TIMEOUT, 0); + os_timer_arm_us(&resetTimer, RESET_TIMEOUT * 1000, 0); } if(previous_mode == 1){ // moving to AP or STA+AP from STA, so softap config call needed @@ -815,7 +815,7 @@ int ICACHE_FLASH_ATTR cgiWiFiConnStatus(HttpdConnData *connData) { // Reset into AP-only mode sooner. os_timer_disarm(&resetTimer); os_timer_setfn(&resetTimer, resetTimerCb, NULL); - os_timer_arm(&resetTimer, 1000, 0); + os_timer_arm_us(&resetTimer, 1 * 1000000, 0); } } #endif diff --git a/esp-link/config.c b/esp-link/config.c index d12f7a7..224f047 100644 --- a/esp-link/config.c +++ b/esp-link/config.c @@ -2,7 +2,6 @@ /* Configuration stored in flash */ #include -#include #include "config.h" #include "espfs.h" #include "crc16.h" diff --git a/esp-link/main.c b/esp-link/main.c index c132786..88cc705 100644 --- a/esp-link/main.c +++ b/esp-link/main.c @@ -161,10 +161,12 @@ user_rf_cal_sector_set(void) { // Main routine to initialize esp-link. void ICACHE_FLASH_ATTR user_init(void) { - // uncomment the following three lines to see flash config messages for troubleshooting - //uart_init(CALC_UARTMODE(8, 0, 1), 115200, 115200); + system_timer_reinit(); + +// uncomment the following three lines to see flash config messages for troubleshooting + //uart_init(115200, 115200); //logInit(); - //os_delay_us(60000L); + //os_delay_us(100000L); // get the flash config so we know how to init things //configWipe(); // uncomment to reset the config for testing purposes bool restoreOk = configRestore(); @@ -201,7 +203,7 @@ user_init(void) { #ifdef SHOW_HEAP_USE os_timer_disarm(&prHeapTimer); os_timer_setfn(&prHeapTimer, prHeapTimerCb, NULL); - os_timer_arm(&prHeapTimer, 10000, 1); + os_timer_arm_us(&prHeapTimer, 10 * 1000000, 1); #endif struct rst_info *rst_info = system_get_rst_info(); diff --git a/esp-link/status.c b/esp-link/status.c index 6905850..70a96d0 100644 --- a/esp-link/status.c +++ b/esp-link/status.c @@ -92,7 +92,7 @@ static void ICACHE_FLASH_ATTR ledTimerCb(void *v) { } setLed(ledState); - os_timer_arm(&ledTimer, time, 0); + os_timer_arm_us(&ledTimer, time * 1000, 0); } // change the wifi state indication @@ -101,7 +101,7 @@ void ICACHE_FLASH_ATTR statusWifiUpdate(uint8_t state) { // schedule an update (don't want to run into concurrency issues) os_timer_disarm(&ledTimer); os_timer_setfn(&ledTimer, ledTimerCb, NULL); - os_timer_arm(&ledTimer, 500, 0); + os_timer_arm_us(&ledTimer, 500000, 0); } //===== Init status stuff @@ -117,12 +117,12 @@ void ICACHE_FLASH_ATTR statusInit(void) { os_timer_disarm(&ledTimer); os_timer_setfn(&ledTimer, ledTimerCb, NULL); - os_timer_arm(&ledTimer, 2000, 0); + os_timer_arm_us(&ledTimer, 2 * 1000000, 0); #ifdef MQTT os_timer_disarm(&mqttStatusTimer); os_timer_setfn(&mqttStatusTimer, mqttStatusCb, NULL); - os_timer_arm(&mqttStatusTimer, MQTT_STATUS_INTERVAL, 1); // recurring timer + os_timer_arm_us(&mqttStatusTimer, MQTT_STATUS_INTERVAL * 1000, 1); // recurring timer #endif // MQTT } diff --git a/include/esp8266.h b/include/esp8266.h index 90de764..3cb71cf 100644 --- a/include/esp8266.h +++ b/include/esp8266.h @@ -5,8 +5,6 @@ #undef MEMLEAK_DEBUG #define USE_OPTIMIZE_PRINTF -#define os_timer_arm_us(a,b,c) os_timer_arm(a,b/1000,c) - #include #include #include @@ -19,6 +17,8 @@ #include #include #include + +#define USE_US_TIMER #include #include diff --git a/mqtt/mqtt.c b/mqtt/mqtt.c index cce3436..f6a557e 100644 --- a/mqtt/mqtt.c +++ b/mqtt/mqtt.c @@ -703,7 +703,7 @@ MQTT_Connect(MQTT_Client* client) { // start timer function to tick every second os_timer_disarm(&client->mqttTimer); os_timer_setfn(&client->mqttTimer, (os_timer_func_t *)mqtt_timer, client); - os_timer_arm(&client->mqttTimer, 1000, 1); + os_timer_arm_us(&client->mqttTimer, 1 * 1000000, 1); // initiate the TCP connection or DNS lookup os_printf("MQTT: Connect to %s:%d %p (client=%p)\n", diff --git a/serial/serled.c b/serial/serled.c index 5bd66a2..8d533e1 100644 --- a/serial/serled.c +++ b/serial/serled.c @@ -25,7 +25,7 @@ void ICACHE_FLASH_ATTR serledFlash(int duration) { setSerled(1); os_timer_disarm(&serledTimer); os_timer_setfn(&serledTimer, serledTimerCb, NULL); - os_timer_arm(&serledTimer, duration, 0); + os_timer_arm_us(&serledTimer, duration * 1000, 0); } void ICACHE_FLASH_ATTR serledInit(void) { diff --git a/syslog/syslog.c b/syslog/syslog.c index 5c88901..3c8ae48 100644 --- a/syslog/syslog.c +++ b/syslog/syslog.c @@ -91,7 +91,7 @@ static void ICACHE_FLASH_ATTR syslog_timer_arm(int delay) { syslog_timer_armed = true; os_timer_disarm(&wifi_chk_timer); os_timer_setfn(&wifi_chk_timer, (os_timer_func_t *)syslog_chk_status, NULL); - os_timer_arm(&wifi_chk_timer, delay, 0); + os_timer_arm_us(&wifi_chk_timer, delay * 1000, 0); } /******************************************************************************