diff --git a/esp-link/cgiflash.c b/esp-link/cgiflash.c index 4b9277d..f909e28 100644 --- a/esp-link/cgiflash.c +++ b/esp-link/cgiflash.c @@ -13,6 +13,7 @@ Some flash handling cgi routines. Used for reading the existing flash and updati * ---------------------------------------------------------------------------- */ +#define USE_US_TIMER #include #include @@ -181,7 +182,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 +196,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/cgioptiboot.c b/esp-link/cgioptiboot.c index ed87d0e..ecaa242 100644 --- a/esp-link/cgioptiboot.c +++ b/esp-link/cgioptiboot.c @@ -1,5 +1,7 @@ // Copyright (c) 2015 by Thorsten von Eicken, see LICENSE.txt in the esp-link repo +#define USE_US_TIMER + #include #include #include "cgi.h" @@ -140,7 +142,7 @@ int ICACHE_FLASH_ATTR cgiOptibootSync(HttpdConnData *connData) { // start sync timer os_timer_disarm(&optibootTimer); os_timer_setfn(&optibootTimer, optibootTimerCB, NULL); - os_timer_arm(&optibootTimer, INIT_DELAY, 0); + os_timer_arm_us(&optibootTimer, INIT_DELAY * 1000, 0); // respond with optimistic OK noCacheHeaders(connData, 204); @@ -491,7 +493,7 @@ static bool ICACHE_FLASH_ATTR programPage(void) { static void ICACHE_FLASH_ATTR armTimer(uint32_t ms) { os_timer_disarm(&optibootTimer); - os_timer_arm(&optibootTimer, ms, 0); + os_timer_arm_us(&optibootTimer, ms * 1000, 0); } static int baudRates[] = { 0, 9600, 57600, 115200 }; diff --git a/esp-link/cgiservices.c b/esp-link/cgiservices.c index 6b3f553..e284b9e 100644 --- a/esp-link/cgiservices.c +++ b/esp-link/cgiservices.c @@ -1,3 +1,5 @@ +#define USE_US_TIMER + #include #include "cgiwifi.h" #include "cgi.h" @@ -36,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()) { @@ -92,10 +94,10 @@ int ICACHE_FLASH_ATTR cgiSystemInfo(HttpdConnData *connData) { } void ICACHE_FLASH_ATTR cgiServicesSNTPInit() { - if (flashConfig.sntp_server[0] != '\0') { + if (flashConfig.sntp_server[0] != '\0') { sntp_stop(); if (true == sntp_set_timezone(flashConfig.timezone_offset)) { - sntp_setservername(0, flashConfig.sntp_server); + sntp_setservername(0, flashConfig.sntp_server); sntp_init(); } DBG("SNTP timesource set to %s with offset %d\n", flashConfig.sntp_server, flashConfig.timezone_offset); @@ -107,7 +109,7 @@ int ICACHE_FLASH_ATTR cgiServicesInfo(HttpdConnData *connData) { if (connData->conn == NULL) return HTTPD_CGI_DONE; // Connection aborted. Clean up. - os_sprintf(buff, + os_sprintf(buff, "{ " "\"syslog_host\": \"%s\", " "\"syslog_minheap\": %d, " @@ -118,7 +120,7 @@ int ICACHE_FLASH_ATTR cgiServicesInfo(HttpdConnData *connData) { "\"sntp_server\": \"%s\", " "\"mdns_enable\": \"%s\", " "\"mdns_servername\": \"%s\"" - " }", + " }", flashConfig.syslog_host, flashConfig.syslog_minheap, flashConfig.syslog_filter, @@ -168,7 +170,7 @@ int ICACHE_FLASH_ATTR cgiServicesSet(HttpdConnData *connData) { int8_t mdns = 0; mdns |= getBoolArg(connData, "mdns_enable", &flashConfig.mdns_enable); if (mdns < 0) return HTTPD_CGI_DONE; - + if (mdns > 0) { if (flashConfig.mdns_enable){ DBG("Services: MDNS Enabled\n"); diff --git a/esp-link/cgiwifi.c b/esp-link/cgiwifi.c index 6b88167..2be8b02 100644 --- a/esp-link/cgiwifi.c +++ b/esp-link/cgiwifi.c @@ -13,6 +13,8 @@ Cgi/template routines for the /wifi url. * ---------------------------------------------------------------------------- */ +#define USE_US_TIMER + #include #include "cgiwifi.h" #include "cgi.h" @@ -222,7 +224,7 @@ static int ICACHE_FLASH_ATTR cgiWiFiStartScan(HttpdConnData *connData) { cgiWifiAps.scanInProgress = 1; os_timer_disarm(&scanTimer); os_timer_setfn(&scanTimer, scanStartCb, NULL); - os_timer_arm(&scanTimer, 200, 0); + os_timer_arm_us(&scanTimer, 200000, 0); } return HTTPD_CGI_DONE; } @@ -314,7 +316,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); @@ -328,7 +330,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); } } @@ -347,7 +349,7 @@ static void ICACHE_FLASH_ATTR reassTimerCb(void *arg) { // IP address os_timer_disarm(&resetTimer); os_timer_setfn(&resetTimer, resetTimerCb, NULL); - os_timer_arm(&resetTimer, 4*RESET_TIMEOUT, 0); + os_timer_arm_us(&resetTimer, 4*RESET_TIMEOUT * 1000, 0); } // This cgi uses the routines above to connect to a specific access point with the @@ -376,7 +378,7 @@ int ICACHE_FLASH_ATTR cgiWiFiConnect(HttpdConnData *connData) { //Schedule disconnect/connect os_timer_disarm(&reassTimer); os_timer_setfn(&reassTimer, reassTimerCb, 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 jsonHeader(connData, 200); } else { jsonHeader(connData, 400); @@ -500,7 +502,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); @@ -669,7 +671,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 @@ -784,7 +786,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 @@ -926,5 +928,5 @@ void ICACHE_FLASH_ATTR wifiInit() { // check on the wifi in a few seconds to see whether we need to switch mode 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); } diff --git a/esp-link/status.c b/esp-link/status.c index 6905850..ef8813d 100644 --- a/esp-link/status.c +++ b/esp-link/status.c @@ -1,5 +1,7 @@ // Copyright 2015 by Thorsten von Eicken, see LICENSE.txt +#define USE_US_TIMER + #include #include "config.h" #include "serled.h" @@ -92,7 +94,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 +103,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 +119,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/mqtt/mqtt.c b/mqtt/mqtt.c index bf785f6..cce321b 100644 --- a/mqtt/mqtt.c +++ b/mqtt/mqtt.c @@ -37,6 +37,8 @@ // Allow messages that don't require ACK to be sent even when pending_buffer is != NULL // Set dup flag in retransmissions +#define USE_US_TIMER + #include #include "pktbuf.h" #include "mqtt.h" @@ -704,7 +706,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 6780eb6..653074d 100644 --- a/serial/serled.c +++ b/serial/serled.c @@ -1,5 +1,7 @@ // Copyright 2015 by Thorsten von Eicken, see LICENSE.txt +#define USE_US_TIMER + #include #include #include @@ -25,7 +27,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 27d8c58..7fc2cab 100644 --- a/syslog/syslog.c +++ b/syslog/syslog.c @@ -8,6 +8,8 @@ * */ +#define USE_US_TIMER + #include #include "config.h" #include "syslog.h" @@ -89,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); } /******************************************************************************