switch to us timer

fix-master
Thorsten von Eicken 8 years ago
parent 02b31b1818
commit d7823b0947
No known key found for this signature in database
GPG Key ID: C7F972A59D834B46
  1. 6
      esp-link/cgiflash.c
  2. 2
      esp-link/cgiservices.c
  3. 10
      esp-link/cgiwifi.c
  4. 1
      esp-link/config.c
  5. 10
      esp-link/main.c
  6. 8
      esp-link/status.c
  7. 4
      include/esp8266.h
  8. 2
      mqtt/mqtt.c
  9. 2
      serial/serled.c
  10. 2
      syslog/syslog.c

@ -13,9 +13,7 @@ Some flash handling cgi routines. Used for reading the existing flash and updati
* ---------------------------------------------------------------------------- * ----------------------------------------------------------------------------
*/ */
#include <esp8266.h> #include <esp8266.h>
#include <osapi.h>
#include "cgi.h" #include "cgi.h"
#include "cgiflash.h" #include "cgiflash.h"
@ -181,7 +179,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 +193,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;
} }

@ -38,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()) {

@ -335,7 +335,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);
@ -349,7 +349,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);
} }
} }
@ -527,7 +527,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);
@ -700,7 +700,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
@ -815,7 +815,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

@ -2,7 +2,6 @@
/* Configuration stored in flash */ /* Configuration stored in flash */
#include <esp8266.h> #include <esp8266.h>
#include <osapi.h>
#include "config.h" #include "config.h"
#include "espfs.h" #include "espfs.h"
#include "crc16.h" #include "crc16.h"

@ -161,10 +161,12 @@ user_rf_cal_sector_set(void) {
// Main routine to initialize esp-link. // Main routine to initialize esp-link.
void ICACHE_FLASH_ATTR void ICACHE_FLASH_ATTR
user_init(void) { user_init(void) {
// uncomment the following three lines to see flash config messages for troubleshooting system_timer_reinit();
//uart_init(CALC_UARTMODE(8, 0, 1), 115200, 115200);
// uncomment the following three lines to see flash config messages for troubleshooting
//uart_init(115200, 115200);
//logInit(); //logInit();
//os_delay_us(60000L); //os_delay_us(100000L);
// get the flash config so we know how to init things // get the flash config so we know how to init things
//configWipe(); // uncomment to reset the config for testing purposes //configWipe(); // uncomment to reset the config for testing purposes
bool restoreOk = configRestore(); bool restoreOk = configRestore();
@ -201,7 +203,7 @@ user_init(void) {
#ifdef SHOW_HEAP_USE #ifdef SHOW_HEAP_USE
os_timer_disarm(&prHeapTimer); os_timer_disarm(&prHeapTimer);
os_timer_setfn(&prHeapTimer, prHeapTimerCb, NULL); os_timer_setfn(&prHeapTimer, prHeapTimerCb, NULL);
os_timer_arm(&prHeapTimer, 10000, 1); os_timer_arm_us(&prHeapTimer, 10 * 1000000, 1);
#endif #endif
struct rst_info *rst_info = system_get_rst_info(); struct rst_info *rst_info = system_get_rst_info();

@ -92,7 +92,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 +101,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 +117,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
} }

@ -5,8 +5,6 @@
#undef MEMLEAK_DEBUG #undef MEMLEAK_DEBUG
#define USE_OPTIMIZE_PRINTF #define USE_OPTIMIZE_PRINTF
#define os_timer_arm_us(a,b,c) os_timer_arm(a,b/1000,c)
#include <user_config.h> #include <user_config.h>
#include <ctype.h> #include <ctype.h>
#include <stdio.h> #include <stdio.h>
@ -19,6 +17,8 @@
#include <ets_sys.h> #include <ets_sys.h>
#include <gpio.h> #include <gpio.h>
#include <mem.h> #include <mem.h>
#define USE_US_TIMER
#include <osapi.h> #include <osapi.h>
#include <upgrade.h> #include <upgrade.h>

@ -703,7 +703,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",

@ -25,7 +25,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) {

@ -91,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