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. 4
      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 <osapi.h>
@ -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;
}

@ -1,5 +1,7 @@
// Copyright (c) 2015 by Thorsten von Eicken, see LICENSE.txt in the esp-link repo
#define USE_US_TIMER
#include <esp8266.h>
#include <osapi.h>
#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 };

@ -1,3 +1,5 @@
#define USE_US_TIMER
#include <esp8266.h>
#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()) {

@ -13,6 +13,8 @@ Cgi/template routines for the /wifi url.
* ----------------------------------------------------------------------------
*/
#define USE_US_TIMER
#include <esp8266.h>
#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);
}

@ -1,5 +1,7 @@
// Copyright 2015 by Thorsten von Eicken, see LICENSE.txt
#define USE_US_TIMER
#include <esp8266.h>
#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
}

@ -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 <esp8266.h>
#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",

@ -1,5 +1,7 @@
// Copyright 2015 by Thorsten von Eicken, see LICENSE.txt
#define USE_US_TIMER
#include <esp8266.h>
#include <config.h>
#include <serled.h>
@ -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) {

@ -8,6 +8,8 @@
*
*/
#define USE_US_TIMER
#include <esp8266.h>
#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);
}
/******************************************************************************

Loading…
Cancel
Save