Update all timer instances to microsecond timers

pull/138/head
Alastair D'Silva 9 years ago
parent e8f569dc5f
commit 19c56c80c8
  1. 5
      esp-link/cgiflash.c
  2. 6
      esp-link/cgioptiboot.c
  3. 14
      esp-link/cgiservices.c
  4. 20
      esp-link/cgiwifi.c
  5. 10
      esp-link/status.c
  6. 4
      mqtt/mqtt.c
  7. 4
      serial/serled.c
  8. 4
      syslog/syslog.c

@ -13,6 +13,7 @@ Some flash handling cgi routines. Used for reading the existing flash and updati
* ---------------------------------------------------------------------------- * ----------------------------------------------------------------------------
*/ */
#define USE_US_TIMER
#include <esp8266.h> #include <esp8266.h>
#include <osapi.h> #include <osapi.h>
@ -181,7 +182,7 @@ int ICACHE_FLASH_ATTR cgiRebootFirmware(HttpdConnData *connData) {
system_upgrade_flag_set(UPGRADE_FLAG_FINISH); system_upgrade_flag_set(UPGRADE_FLAG_FINISH);
os_timer_disarm(&flash_reboot_timer); os_timer_disarm(&flash_reboot_timer);
os_timer_setfn(&flash_reboot_timer, (os_timer_func_t *)system_upgrade_reboot, NULL); 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; return HTTPD_CGI_DONE;
} }
@ -195,6 +196,6 @@ int ICACHE_FLASH_ATTR cgiReset(HttpdConnData *connData) {
// Schedule a reboot // Schedule a reboot
os_timer_disarm(&flash_reboot_timer); os_timer_disarm(&flash_reboot_timer);
os_timer_setfn(&flash_reboot_timer, (os_timer_func_t *)system_restart, NULL); 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; return HTTPD_CGI_DONE;
} }

@ -1,5 +1,7 @@
// Copyright (c) 2015 by Thorsten von Eicken, see LICENSE.txt in the esp-link repo // Copyright (c) 2015 by Thorsten von Eicken, see LICENSE.txt in the esp-link repo
#define USE_US_TIMER
#include <esp8266.h> #include <esp8266.h>
#include <osapi.h> #include <osapi.h>
#include "cgi.h" #include "cgi.h"
@ -140,7 +142,7 @@ int ICACHE_FLASH_ATTR cgiOptibootSync(HttpdConnData *connData) {
// start sync timer // start sync timer
os_timer_disarm(&optibootTimer); os_timer_disarm(&optibootTimer);
os_timer_setfn(&optibootTimer, optibootTimerCB, NULL); 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 // respond with optimistic OK
noCacheHeaders(connData, 204); noCacheHeaders(connData, 204);
@ -491,7 +493,7 @@ static bool ICACHE_FLASH_ATTR programPage(void) {
static void ICACHE_FLASH_ATTR armTimer(uint32_t ms) { static void ICACHE_FLASH_ATTR armTimer(uint32_t ms) {
os_timer_disarm(&optibootTimer); 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 }; static int baudRates[] = { 0, 9600, 57600, 115200 };

@ -1,3 +1,5 @@
#define USE_US_TIMER
#include <esp8266.h> #include <esp8266.h>
#include "cgiwifi.h" #include "cgiwifi.h"
#include "cgi.h" #include "cgi.h"
@ -36,7 +38,7 @@ int ICACHE_FLASH_ATTR cgiSystemSet(HttpdConnData *connData) {
// schedule hostname change-over // schedule hostname change-over
os_timer_disarm(&reassTimer); os_timer_disarm(&reassTimer);
os_timer_setfn(&reassTimer, configWifiIP, NULL); 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()) { if (configSave()) {
@ -92,10 +94,10 @@ int ICACHE_FLASH_ATTR cgiSystemInfo(HttpdConnData *connData) {
} }
void ICACHE_FLASH_ATTR cgiServicesSNTPInit() { void ICACHE_FLASH_ATTR cgiServicesSNTPInit() {
if (flashConfig.sntp_server[0] != '\0') { if (flashConfig.sntp_server[0] != '\0') {
sntp_stop(); sntp_stop();
if (true == sntp_set_timezone(flashConfig.timezone_offset)) { if (true == sntp_set_timezone(flashConfig.timezone_offset)) {
sntp_setservername(0, flashConfig.sntp_server); sntp_setservername(0, flashConfig.sntp_server);
sntp_init(); sntp_init();
} }
DBG("SNTP timesource set to %s with offset %d\n", flashConfig.sntp_server, flashConfig.timezone_offset); 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. if (connData->conn == NULL) return HTTPD_CGI_DONE; // Connection aborted. Clean up.
os_sprintf(buff, os_sprintf(buff,
"{ " "{ "
"\"syslog_host\": \"%s\", " "\"syslog_host\": \"%s\", "
"\"syslog_minheap\": %d, " "\"syslog_minheap\": %d, "
@ -118,7 +120,7 @@ int ICACHE_FLASH_ATTR cgiServicesInfo(HttpdConnData *connData) {
"\"sntp_server\": \"%s\", " "\"sntp_server\": \"%s\", "
"\"mdns_enable\": \"%s\", " "\"mdns_enable\": \"%s\", "
"\"mdns_servername\": \"%s\"" "\"mdns_servername\": \"%s\""
" }", " }",
flashConfig.syslog_host, flashConfig.syslog_host,
flashConfig.syslog_minheap, flashConfig.syslog_minheap,
flashConfig.syslog_filter, flashConfig.syslog_filter,
@ -168,7 +170,7 @@ int ICACHE_FLASH_ATTR cgiServicesSet(HttpdConnData *connData) {
int8_t mdns = 0; int8_t mdns = 0;
mdns |= getBoolArg(connData, "mdns_enable", &flashConfig.mdns_enable); mdns |= getBoolArg(connData, "mdns_enable", &flashConfig.mdns_enable);
if (mdns < 0) return HTTPD_CGI_DONE; if (mdns < 0) return HTTPD_CGI_DONE;
if (mdns > 0) { if (mdns > 0) {
if (flashConfig.mdns_enable){ if (flashConfig.mdns_enable){
DBG("Services: MDNS Enabled\n"); DBG("Services: MDNS Enabled\n");

@ -13,6 +13,8 @@ Cgi/template routines for the /wifi url.
* ---------------------------------------------------------------------------- * ----------------------------------------------------------------------------
*/ */
#define USE_US_TIMER
#include <esp8266.h> #include <esp8266.h>
#include "cgiwifi.h" #include "cgiwifi.h"
#include "cgi.h" #include "cgi.h"
@ -222,7 +224,7 @@ static int ICACHE_FLASH_ATTR cgiWiFiStartScan(HttpdConnData *connData) {
cgiWifiAps.scanInProgress = 1; cgiWifiAps.scanInProgress = 1;
os_timer_disarm(&scanTimer); os_timer_disarm(&scanTimer);
os_timer_setfn(&scanTimer, scanStartCb, NULL); os_timer_setfn(&scanTimer, scanStartCb, NULL);
os_timer_arm(&scanTimer, 200, 0); os_timer_arm_us(&scanTimer, 200000, 0);
} }
return HTTPD_CGI_DONE; return HTTPD_CGI_DONE;
} }
@ -314,7 +316,7 @@ static void ICACHE_FLASH_ATTR resetTimerCb(void *arg) {
// We're happily connected, go to STA mode // We're happily connected, go to STA mode
DBG("Wifi got IP. Going into STA mode..\n"); DBG("Wifi got IP. Going into STA mode..\n");
wifi_set_opmode(1); 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 #endif
} }
log_uart(false); log_uart(false);
@ -328,7 +330,7 @@ static void ICACHE_FLASH_ATTR resetTimerCb(void *arg) {
} }
log_uart(true); log_uart(true);
DBG("Enabling/continuing uart log\n"); 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 // IP address
os_timer_disarm(&resetTimer); os_timer_disarm(&resetTimer);
os_timer_setfn(&resetTimer, resetTimerCb, NULL); 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 // 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 //Schedule disconnect/connect
os_timer_disarm(&reassTimer); os_timer_disarm(&reassTimer);
os_timer_setfn(&reassTimer, reassTimerCb, NULL); 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); jsonHeader(connData, 200);
} else { } else {
jsonHeader(connData, 400); jsonHeader(connData, 400);
@ -500,7 +502,7 @@ int ICACHE_FLASH_ATTR cgiWiFiSpecial(HttpdConnData *connData) {
// schedule change-over // schedule change-over
os_timer_disarm(&reassTimer); os_timer_disarm(&reassTimer);
os_timer_setfn(&reassTimer, configWifiIP, NULL); 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 // return redirect info
jsonHeader(connData, 200); jsonHeader(connData, 200);
httpdSend(connData, url, -1); httpdSend(connData, url, -1);
@ -669,7 +671,7 @@ int ICACHE_FLASH_ATTR cgiWiFiSetMode(HttpdConnData *connData) {
wifi_station_connect(); wifi_station_connect();
os_timer_disarm(&resetTimer); os_timer_disarm(&resetTimer);
os_timer_setfn(&resetTimer, resetTimerCb, NULL); 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){ if(previous_mode == 1){
// moving to AP or STA+AP from STA, so softap config call needed // 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. // Reset into AP-only mode sooner.
os_timer_disarm(&resetTimer); os_timer_disarm(&resetTimer);
os_timer_setfn(&resetTimer, resetTimerCb, NULL); os_timer_setfn(&resetTimer, resetTimerCb, NULL);
os_timer_arm(&resetTimer, 1000, 0); os_timer_arm_us(&resetTimer, 1 * 1000000, 0);
} }
} }
#endif #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 // check on the wifi in a few seconds to see whether we need to switch mode
os_timer_disarm(&resetTimer); os_timer_disarm(&resetTimer);
os_timer_setfn(&resetTimer, resetTimerCb, NULL); os_timer_setfn(&resetTimer, resetTimerCb, NULL);
os_timer_arm(&resetTimer, RESET_TIMEOUT, 0); os_timer_arm_us(&resetTimer, RESET_TIMEOUT * 1000, 0);
} }

@ -1,5 +1,7 @@
// Copyright 2015 by Thorsten von Eicken, see LICENSE.txt // Copyright 2015 by Thorsten von Eicken, see LICENSE.txt
#define USE_US_TIMER
#include <esp8266.h> #include <esp8266.h>
#include "config.h" #include "config.h"
#include "serled.h" #include "serled.h"
@ -92,7 +94,7 @@ static void ICACHE_FLASH_ATTR ledTimerCb(void *v) {
} }
setLed(ledState); setLed(ledState);
os_timer_arm(&ledTimer, time, 0); os_timer_arm_us(&ledTimer, time * 1000, 0);
} }
// change the wifi state indication // 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) // schedule an update (don't want to run into concurrency issues)
os_timer_disarm(&ledTimer); os_timer_disarm(&ledTimer);
os_timer_setfn(&ledTimer, ledTimerCb, NULL); os_timer_setfn(&ledTimer, ledTimerCb, NULL);
os_timer_arm(&ledTimer, 500, 0); os_timer_arm_us(&ledTimer, 500000, 0);
} }
//===== Init status stuff //===== Init status stuff
@ -117,12 +119,12 @@ void ICACHE_FLASH_ATTR statusInit(void) {
os_timer_disarm(&ledTimer); os_timer_disarm(&ledTimer);
os_timer_setfn(&ledTimer, ledTimerCb, NULL); os_timer_setfn(&ledTimer, ledTimerCb, NULL);
os_timer_arm(&ledTimer, 2000, 0); os_timer_arm_us(&ledTimer, 2 * 1000000, 0);
#ifdef MQTT #ifdef MQTT
os_timer_disarm(&mqttStatusTimer); os_timer_disarm(&mqttStatusTimer);
os_timer_setfn(&mqttStatusTimer, mqttStatusCb, NULL); 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 #endif // MQTT
} }

@ -37,6 +37,8 @@
// Allow messages that don't require ACK to be sent even when pending_buffer is != NULL // Allow messages that don't require ACK to be sent even when pending_buffer is != NULL
// Set dup flag in retransmissions // Set dup flag in retransmissions
#define USE_US_TIMER
#include <esp8266.h> #include <esp8266.h>
#include "pktbuf.h" #include "pktbuf.h"
#include "mqtt.h" #include "mqtt.h"
@ -704,7 +706,7 @@ MQTT_Connect(MQTT_Client* client) {
// start timer function to tick every second // start timer function to tick every second
os_timer_disarm(&client->mqttTimer); os_timer_disarm(&client->mqttTimer);
os_timer_setfn(&client->mqttTimer, (os_timer_func_t *)mqtt_timer, client); 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 // initiate the TCP connection or DNS lookup
os_printf("MQTT: Connect to %s:%d %p (client=%p)\n", os_printf("MQTT: Connect to %s:%d %p (client=%p)\n",

@ -1,5 +1,7 @@
// Copyright 2015 by Thorsten von Eicken, see LICENSE.txt // Copyright 2015 by Thorsten von Eicken, see LICENSE.txt
#define USE_US_TIMER
#include <esp8266.h> #include <esp8266.h>
#include <config.h> #include <config.h>
#include <serled.h> #include <serled.h>
@ -25,7 +27,7 @@ void ICACHE_FLASH_ATTR serledFlash(int duration) {
setSerled(1); setSerled(1);
os_timer_disarm(&serledTimer); os_timer_disarm(&serledTimer);
os_timer_setfn(&serledTimer, serledTimerCb, NULL); 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) { void ICACHE_FLASH_ATTR serledInit(void) {

@ -8,6 +8,8 @@
* *
*/ */
#define USE_US_TIMER
#include <esp8266.h> #include <esp8266.h>
#include "config.h" #include "config.h"
#include "syslog.h" #include "syslog.h"
@ -89,7 +91,7 @@ static void ICACHE_FLASH_ATTR syslog_timer_arm(int delay) {
syslog_timer_armed = true; syslog_timer_armed = true;
os_timer_disarm(&wifi_chk_timer); os_timer_disarm(&wifi_chk_timer);
os_timer_setfn(&wifi_chk_timer, (os_timer_func_t *)syslog_chk_status, NULL); 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);
} }
/****************************************************************************** /******************************************************************************

Loading…
Cancel
Save