Add IRAM_ATTR to Loops

This commit is contained in:
fvanroie 2020-11-23 12:19:47 +01:00
parent 1632e5fc24
commit 366c10ea3d
26 changed files with 65 additions and 77 deletions

View File

@ -425,7 +425,7 @@ void haspSetup()
* STATIC FUNCTIONS * STATIC FUNCTIONS
**********************/ **********************/
void haspLoop(void) void IRAM_ATTR haspLoop(void)
{} {}
/* /*
@ -483,7 +483,7 @@ void hasp_background(uint16_t pageid, uint16_t imageid)
String haspGetVersion() String haspGetVersion()
{ {
char buffer[128]; char buffer[16];
snprintf_P(buffer, sizeof(buffer), "%u.%u.%u", HASP_VERSION_MAJOR, HASP_VERSION_MINOR, HASP_VERSION_REVISION); snprintf_P(buffer, sizeof(buffer), "%u.%u.%u", HASP_VERSION_MAJOR, HASP_VERSION_MINOR, HASP_VERSION_REVISION);
return buffer; return buffer;
} }

View File

@ -48,7 +48,7 @@ enum hasp_event_t { // even = released, odd = pressed
* Create a hasp application * Create a hasp application
*/ */
void haspSetup(); void haspSetup();
void haspLoop(void); void IRAM_ATTR haspLoop(void);
void haspReconnect(void); void haspReconnect(void);
void haspDisconnect(void); void haspDisconnect(void);

View File

@ -9,7 +9,7 @@
/* ===== Default Event Processors ===== */ /* ===== Default Event Processors ===== */
void configSetup(void); void configSetup(void);
void configLoop(void); void IRAM_ATTR configLoop(void);
void configEverySecond(void); void configEverySecond(void);
void configStart(void); void configStart(void);
void configStop(void); void configStop(void);

View File

@ -90,7 +90,7 @@ uint16_t debugSerialBaud = SERIAL_SPEED / 10; // Multiplied by 10
bool debugSerialStarted = false; bool debugSerialStarted = false;
bool debugAnsiCodes = true; bool debugAnsiCodes = true;
ConsoleInput console(&Serial, 220); ConsoleInput debugConsole(&Serial, 220);
//#define TERM_COLOR_Black "\u001b[30m" //#define TERM_COLOR_Black "\u001b[30m"
#define TERM_COLOR_GRAY "\e[37m" #define TERM_COLOR_GRAY "\e[37m"
@ -111,7 +111,8 @@ uint16_t debugTelePeriod = 300;
// Send the HASP header and version to the output device specified // Send the HASP header and version to the output device specified
void debugPrintHaspHeader(Print * output) void debugPrintHaspHeader(Print * output)
{ {
if(debugAnsiCodes) output->println(TERM_COLOR_YELLOW); if(debugAnsiCodes) output->print(TERM_COLOR_YELLOW);
output->println();
output->print(F("" output->print(F(""
" _____ _____ _____ _____\r\n" " _____ _____ _____ _____\r\n"
" | | | _ | __| _ |\r\n" " | | | _ | __| _ |\r\n"
@ -152,7 +153,7 @@ void debugSetup()
// memset(serialInputBuffer, 0, sizeof(serialInputBuffer)); // memset(serialInputBuffer, 0, sizeof(serialInputBuffer));
// serialInputIndex = 0; // serialInputIndex = 0;
Log.notice(TAG_DEBG, F("Setting the console parser")); Log.notice(TAG_DEBG, F("Setting the console parser"));
console.setLineCallback(dispatchTextLine); debugConsole.setLineCallback(dispatchTextLine);
} }
void debugStartSyslog() void debugStartSyslog()
@ -592,13 +593,10 @@ void debugPrintSuffix(uint8_t tag, int level, Print * _logOutput)
_logOutput->println(); _logOutput->println();
if(_logOutput == &Serial) { if(_logOutput == &Serial) {
console.update(); debugConsole.update();
} else { } else {
_logOutput->print("hasp > "); _logOutput->print("hasp > ");
} }
// if(_logOutput == &Serial) debugPrintPrompt();
// syslogSend(level, debugOutput);
} }
void debugPreSetup(JsonObject settings) void debugPreSetup(JsonObject settings)
@ -668,9 +666,9 @@ void debugLvglLogEvent(lv_log_level_t level, const char * file, uint32_t line, c
} }
#endif #endif
void debugLoop() void IRAM_ATTR debugLoop(void)
{ {
int16_t keypress = console.readKey(); int16_t keypress = debugConsole.readKey();
switch(keypress) { switch(keypress) {

View File

@ -10,7 +10,7 @@
/* ===== Default Event Processors ===== */ /* ===== Default Event Processors ===== */
void debugPreSetup(JsonObject settings); void debugPreSetup(JsonObject settings);
void debugSetup(); void debugSetup();
void debugLoop(void); void IRAM_ATTR debugLoop(void);
void debugEverySecond(void); void debugEverySecond(void);
void debugStart(void); void debugStart(void);
void debugStop(void); void debugStop(void);

View File

@ -716,7 +716,7 @@ void dispatchSetup()
dispatch_add_command(PSTR("setupap"), oobeFakeSetup); dispatch_add_command(PSTR("setupap"), oobeFakeSetup);
} }
void dispatchLoop() void IRAM_ATTR dispatchLoop()
{ {
// Not used // Not used
} }

View File

@ -10,7 +10,7 @@
/* ===== Default Event Processors ===== */ /* ===== Default Event Processors ===== */
void dispatchSetup(void); void dispatchSetup(void);
void dispatchLoop(void); void IRAM_ATTR dispatchLoop(void);
void dispatchEverySecond(void); void dispatchEverySecond(void);
void dispatchStart(void); void dispatchStart(void);
void dispatchStop(void); void dispatchStop(void);

View File

@ -22,5 +22,5 @@ void eepromSetup()
// debugPrintln("EEPROM: Started Eeprom"); // debugPrintln("EEPROM: Started Eeprom");
} }
void eepromLoop() void IRAM_ATTR eepromLoop()
{} {}

View File

@ -7,7 +7,7 @@
#include <Arduino.h> #include <Arduino.h>
void eepromSetup(void); void eepromSetup(void);
void eepromLoop(void); void IRAM_ATTR eepromLoop(void);
void eepromWrite(uint16_t addr, std::string & data); void eepromWrite(uint16_t addr, std::string & data);
std::string eepromRead(uint16_t addr); std::string eepromRead(uint16_t addr);

View File

@ -35,7 +35,7 @@ void EthernetEvent(WiFiEvent_t event)
} }
Log.notice(TAG_ETH, F("LINK_SPEED %d Mbps"), ETH.linkSpeed()); Log.notice(TAG_ETH, F("LINK_SPEED %d Mbps"), ETH.linkSpeed());
eth_connected = true; eth_connected = true;
networkStart();// Start network services networkStart(); // Start network services
break; break;
case SYSTEM_EVENT_ETH_DISCONNECTED: case SYSTEM_EVENT_ETH_DISCONNECTED:
Log.notice(TAG_ETH, F("Disconnected")); Log.notice(TAG_ETH, F("Disconnected"));
@ -57,10 +57,8 @@ void ethernetSetup()
ETH.begin(ETH_ADDR, ETH_POWER_PIN, ETH_MDC_PIN, ETH_MDIO_PIN, ETH_TYPE, ETH_CLKMODE); ETH.begin(ETH_ADDR, ETH_POWER_PIN, ETH_MDC_PIN, ETH_MDIO_PIN, ETH_TYPE, ETH_CLKMODE);
} }
void ethernetLoop(void) void IRAM_ATTR ethernetLoop(void)
{ {}
//
}
bool ethernetEvery5Seconds() bool ethernetEvery5Seconds()
{ {

View File

@ -7,7 +7,7 @@
static bool eth_connected = false; static bool eth_connected = false;
void ethernetSetup(); void ethernetSetup();
void ethernetLoop(void); void IRAM_ATTR ethernetLoop(void);
bool ethernetEvery5Seconds(); bool ethernetEvery5Seconds();

View File

@ -637,7 +637,7 @@ void guiSetup()
} }
} }
void IRAM_ATTR guiLoop() void IRAM_ATTR guiLoop(void)
{ {
lv_task_handler(); // process animations lv_task_handler(); // process animations
@ -859,8 +859,6 @@ static void guiSetBmpHeader(uint8_t * buffer_p, int32_t data)
**/ **/
static void gui_get_bitmap_header(uint8_t * buffer, size_t bufsize) static void gui_get_bitmap_header(uint8_t * buffer, size_t bufsize)
{ {
// uint8_t buffer[128];
// memset(buffer, 0, sizeof(buffer));
memset(buffer, 0, bufsize); memset(buffer, 0, bufsize);
lv_disp_t * disp = lv_disp_get_default(); lv_disp_t * disp = lv_disp_get_default();

View File

@ -13,7 +13,7 @@
/* ===== Default Event Processors ===== */ /* ===== Default Event Processors ===== */
void guiSetup(); void guiSetup();
void guiLoop(void); void IRAM_ATTR guiLoop(void);
void guiEverySecond(void); void guiEverySecond(void);
void guiStart(void); void guiStart(void);
void guiStop(void); void guiStop(void);

View File

@ -155,7 +155,7 @@ String getOption(String value, String label, bool selected)
} }
void webSendFooter() void webSendFooter()
{ {
char buffer[128]; char buffer[16];
snprintf_P(buffer, sizeof(buffer), PSTR("%u.%u.%u"), HASP_VERSION_MAJOR, HASP_VERSION_MINOR, HASP_VERSION_REVISION); snprintf_P(buffer, sizeof(buffer), PSTR("%u.%u.%u"), HASP_VERSION_MAJOR, HASP_VERSION_MINOR, HASP_VERSION_REVISION);
#if defined(STM32F4xx) #if defined(STM32F4xx)
@ -199,7 +199,7 @@ void webSendPage(char * nodename, uint32_t httpdatalength, bool gohome = false)
webServer.send(200, ("text/html"), HTTP_DOCTYPE); // 122 webServer.send(200, ("text/html"), HTTP_DOCTYPE); // 122
#endif #endif
sprintf_P(buffer, HTTP_HEADER, nodename); snprintf_P(buffer, sizeof(buffer), HTTP_HEADER, nodename);
webServer.sendContent(buffer); // 17-2+len webServer.sendContent(buffer); // 17-2+len
} }
@ -486,7 +486,8 @@ void webHandleInfo()
byte mac[6]; byte mac[6];
WiFi.macAddress(mac); WiFi.macAddress(mac);
char macAddress[16]; char macAddress[16];
sprintf_P(macAddress, PSTR("%02x%02x%02x"), mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]); snprintf_P(macAddress, sizeof(macAddress), PSTR("%02x%02x%02x"), mac[0], mac[1], mac[2], mac[3], mac[4],
mac[5]);
httpMessage += F("</br><b>IP Address: </b>"); httpMessage += F("</br><b>IP Address: </b>");
httpMessage += String(WiFi.localIP()); httpMessage += String(WiFi.localIP());
httpMessage += F("</br><b>Gateway: </b>"); httpMessage += F("</br><b>Gateway: </b>");
@ -786,8 +787,8 @@ void handleFileDelete()
{ {
if(!httpIsAuthenticated(F("filedelete"))) return; if(!httpIsAuthenticated(F("filedelete"))) return;
char mimetype[128]; char mimetype[16];
sprintf(mimetype, PSTR("text/plain")); snprintf(mimetype, sizeof(mimetype), PSTR("text/plain"));
if(webServer.args() == 0) { if(webServer.args() == 0) {
return webServer.send_P(500, mimetype, PSTR("BAD ARGS")); return webServer.send_P(500, mimetype, PSTR("BAD ARGS"));
@ -1750,8 +1751,8 @@ void httpSetup()
// load editor // load editor
webServer.on(F("/edit"), HTTP_GET, []() { webServer.on(F("/edit"), HTTP_GET, []() {
if(!handleFileRead("/edit.htm")) { if(!handleFileRead("/edit.htm")) {
char mimetype[128]; char mimetype[16];
sprintf(mimetype, PSTR("text/plain")); snprintf(mimetype, sizeof(mimetype), PSTR("text/plain"));
webServer.send_P(404, mimetype, PSTR("FileNotFound")); webServer.send_P(404, mimetype, PSTR("FileNotFound"));
} }
}); });
@ -1854,7 +1855,7 @@ void httpReconnect()
} }
//////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////
void httpLoop() void IRAM_ATTR httpLoop(void)
{ {
if(httpEnable) webServer.handleClient(); if(httpEnable) webServer.handleClient();
} }

View File

@ -8,7 +8,7 @@
#include "ArduinoJson.h" #include "ArduinoJson.h"
void httpSetup(); void httpSetup();
void httpLoop(void); void IRAM_ATTR httpLoop(void);
void httpEvery5Seconds(void); void httpEvery5Seconds(void);
// void httpReconnect(void); // void httpReconnect(void);
void httpStart(void); void httpStart(void);

View File

@ -67,11 +67,10 @@ void mdnsStart()
MDNS.addService(F("telnet"), F("tcp"), 23); MDNS.addService(F("telnet"), F("tcp"), 23);
// } // }
Log.trace(TAG_MDNS, F("Responder started")); Log.trace(TAG_MDNS, F("Responder started"));
} }
void mdnsLoop() void IRAM_ATTR mdnsLoop(void)
{ {
#if defined(ARDUINO_ARCH_ESP8266) #if defined(ARDUINO_ARCH_ESP8266)
if(mdnsEnabled) { if(mdnsEnabled) {

View File

@ -8,7 +8,7 @@
/* ===== Default Event Processors ===== */ /* ===== Default Event Processors ===== */
void mdnsSetup(); void mdnsSetup();
void mdnsLoop(void); void IRAM_ATTR mdnsLoop(void);
void mdnsStart(void); void mdnsStart(void);
void mdnsStop(void); void mdnsStop(void);

View File

@ -302,17 +302,16 @@ static void mqtt_message_cb(char * topic, byte * payload, unsigned int length)
bool res = mqttPublish(tmp_topic, "ON"); //, true); // Literal String bool res = mqttPublish(tmp_topic, "ON"); //, true); // Literal String
mqttResult(res, tmp_topic, "ON"); mqttResult(res, tmp_topic, "ON");
} }
// Log.notice(TAG_MQTT, F("binary_sensor state: [status] : ON"));
} else { } else {
// already ON // Log.notice(TAG_MQTT, F("ignoring status = ON"));
} }
} else { } else {
dispatchTopicPayload(topic, (char *)payload); dispatchTopicPayload(topic, (char *)payload);
} }
} }
void mqttSubscribeTo(const char * format, const char * data) static void mqttSubscribeTo(const char * format, const char * data)
{ {
char tmp_topic[strlen(format) + 2 + strlen(data)]; char tmp_topic[strlen(format) + 2 + strlen(data)];
snprintf_P(tmp_topic, sizeof(tmp_topic), format, data); snprintf_P(tmp_topic, sizeof(tmp_topic), format, data);
@ -325,11 +324,15 @@ void mqttSubscribeTo(const char * format, const char * data)
void mqttStart() void mqttStart()
{ {
char buffer[128]; char buffer[64];
char mqttClientId[64]; char mqttClientId[64];
char lastWillPayload[4];
static uint8_t mqttReconnectCount = 0; static uint8_t mqttReconnectCount = 0;
bool mqttFirstConnect = true; bool mqttFirstConnect = true;
mqttClient.setServer(mqttServer, 1883);
/* Construct unique Client ID*/
{ {
String mac = halGetMacAddress(3, ""); String mac = halGetMacAddress(3, "");
mac.toLowerCase(); mac.toLowerCase();
@ -338,11 +341,11 @@ void mqttStart()
Log.trace(TAG_MQTT, mqttClientId); Log.trace(TAG_MQTT, mqttClientId);
} }
mqttClient.setServer(mqttServer, 1883);
// Attempt to connect and set LWT and Clean Session // Attempt to connect and set LWT and Clean Session
snprintf_P(buffer, sizeof(buffer), PSTR("%sstatus"), mqttNodeTopic); snprintf_P(buffer, sizeof(buffer), PSTR("%sstatus"), mqttNodeTopic); // lastWillTopic
if(!mqttClient.connect(mqttClientId, mqttUser, mqttPassword, buffer, 0, false, "OFF", true)) { // Literal String snprintf_P(lastWillPayload, sizeof(lastWillPayload), PSTR("OFF")); // lastWillPayload
if(!mqttClient.connect(mqttClientId, mqttUser, mqttPassword, buffer, 2, false, lastWillPayload, true)) {
// Retry until we give up and restart after connectTimeout seconds // Retry until we give up and restart after connectTimeout seconds
mqttReconnectCount++; mqttReconnectCount++;
@ -404,15 +407,6 @@ void mqttStart()
mqttLightBrightStateTopic = prefix + F("/brightness/state"); mqttLightBrightStateTopic = prefix + F("/brightness/state");
*/ */
// Set keepAlive, cleanSession, timeout
// mqttClient.setOptions(30, true, 5000);
mqttClient.setKeepAlive(30);
mqttClient.setSocketTimeout(5000);
// declare LWT
// mqttClient.setWill(mqttStatusTopic.c_str(), "OFF");
// Attempt to connect to broker, setting last will and testament
// Subscribe to our incoming topics // Subscribe to our incoming topics
mqttSubscribeTo(PSTR("%scommand/#"), mqttGroupTopic); mqttSubscribeTo(PSTR("%scommand/#"), mqttGroupTopic);
mqttSubscribeTo(PSTR("%scommand/#"), mqttNodeTopic); mqttSubscribeTo(PSTR("%scommand/#"), mqttNodeTopic);
@ -460,14 +454,17 @@ void mqttSetup()
} }
} }
void mqttLoop() void IRAM_ATTR mqttLoop(void)
{ {
if(mqttEnabled) mqttClient.loop(); if(mqttEnabled) mqttClient.loop();
} }
void mqttEvery5Seconds(bool networkIsConnected) void mqttEvery5Seconds(bool networkIsConnected)
{ {
if(mqttEnabled && networkIsConnected && !mqttClient.connected()) mqttStart(); if(mqttEnabled && networkIsConnected && !mqttClient.connected()) {
Log.notice(TAG_MQTT, F("Disconnected from broker, reconnection..."));
mqttStart();
}
} }
String mqttGetNodename() String mqttGetNodename()

View File

@ -7,7 +7,7 @@
#include "ArduinoJson.h" #include "ArduinoJson.h"
void mqttSetup(); void mqttSetup();
void mqttLoop(); void IRAM_ATTR mqttLoop();
void mqttEvery5Seconds(bool wifiIsConnected); void mqttEvery5Seconds(bool wifiIsConnected);
void mqttStart(); void mqttStart();
void mqttStop(); void mqttStop();

View File

@ -27,7 +27,7 @@ void networkStop(void)
haspProgressMsg(F("Network Disconnected")); haspProgressMsg(F("Network Disconnected"));
debugStopSyslog(); debugStopSyslog();
mqttStop(); // mqttStop();
httpStop(); httpStop();
mdnsStop(); mdnsStop();
} }
@ -43,14 +43,14 @@ void networkSetup()
#endif #endif
} }
void networkLoop(void) void IRAM_ATTR networkLoop(void)
{ {
#if HASP_USE_ETHERNET > 0 #if HASP_USE_ETHERNET > 0
ethernetSetup(); ethernetLoop();
#endif #endif
#if HASP_USE_WIFI > 0 #if HASP_USE_WIFI > 0
wifiSetup(); // wifiLoop();
#endif #endif
} }

View File

@ -6,7 +6,7 @@
/* ===== Default Event Processors ===== */ /* ===== Default Event Processors ===== */
void networkSetup(); void networkSetup();
void networkLoop(void); void IRAM_ATTR networkLoop(void);
void networkEvery5Seconds(void); void networkEvery5Seconds(void);
void networkEverySecond(void); void networkEverySecond(void);
void networkStart(void); void networkStart(void);

View File

@ -25,9 +25,6 @@
#endif #endif
static WiFiClient otaClient; static WiFiClient otaClient;
#define F_OTA_URL F("otaurl")
std::string otaUrl = "http://ota.netwize.be"; std::string otaUrl = "http://ota.netwize.be";
int16_t otaPort = HASP_OTA_PORT; int16_t otaPort = HASP_OTA_PORT;
int8_t otaPrecentageComplete = -1; int8_t otaPrecentageComplete = -1;
@ -126,7 +123,7 @@ void otaSetup(void)
} }
} }
void otaLoop(void) void IRAM_ATTR otaLoop(void)
{ {
ArduinoOTA.handle(); ArduinoOTA.handle();
} }

View File

@ -10,7 +10,7 @@
/* ===== Default Event Processors ===== */ /* ===== Default Event Processors ===== */
void otaSetup(void); void otaSetup(void);
void otaLoop(void); void IRAM_ATTR otaLoop(void);
void otaEverySecond(void); void otaEverySecond(void);
/* ===== Special Event Processors ===== */ /* ===== Special Event Processors ===== */

View File

@ -27,7 +27,7 @@ unsigned long updatLedPeriod = 1000; // timer in msec for tele mqtt send
bool ledstate = false; bool ledstate = false;
void IRAM_ATTR slave_send_state(const __FlashStringHelper * subtopic, const char * payload) void slave_send_state(const __FlashStringHelper * subtopic, const char * payload)
{ {
// page = 0 // page = 0
// p[0].b[0].attr = abc // p[0].b[0].attr = abc
@ -45,7 +45,7 @@ void IRAM_ATTR slave_send_state(const __FlashStringHelper * subtopic, const char
Log.notice(TAG_TASM,F("TAS PUB: %sstate/%S = %s"), slaveNodeTopic, subtopic, payload); Log.notice(TAG_TASM,F("TAS PUB: %sstate/%S = %s"), slaveNodeTopic, subtopic, payload);
} }
void IRAM_ATTR slave_send_obj_attribute_str(uint8_t pageid, uint8_t btnid, const char * attribute, const char * data) void slave_send_obj_attribute_str(uint8_t pageid, uint8_t btnid, const char * attribute, const char * data)
{ {
char cBuffer[192]; char cBuffer[192];
memset(cBuffer, 0 ,sizeof(cBuffer)); memset(cBuffer, 0 ,sizeof(cBuffer));
@ -151,7 +151,7 @@ void slaveSetup()
Log.notice(TAG_TASM,F("HASP SLAVE LOADED")); Log.notice(TAG_TASM,F("HASP SLAVE LOADED"));
} }
void slaveLoop(void) void IRAM_ATTR slaveLoop(void)
{ {
slave.loop(); slave.loop();
// demo code to run the led without tasmota // demo code to run the led without tasmota

View File

@ -10,14 +10,14 @@
void TASMO_EVERY_SECOND(void); void TASMO_EVERY_SECOND(void);
void TASMO_DATA_RECEIVE(char *data); void TASMO_DATA_RECEIVE(char *data);
void IRAM_ATTR slave_send_state(const __FlashStringHelper * subtopic, const char * payload); void slave_send_state(const __FlashStringHelper * subtopic, const char * payload);
void IRAM_ATTR slave_send_obj_attribute_str(uint8_t pageid, uint8_t btnid, const char * attribute, const char * data); void slave_send_obj_attribute_str(uint8_t pageid, uint8_t btnid, const char * attribute, const char * data);
void slave_send_input(uint8_t id, const char * payload); void slave_send_input(uint8_t id, const char * payload);
void slave_send_statusupdate(); void slave_send_statusupdate();
void slaveSetup(); void slaveSetup();
void slaveLoop(void); void IRAM_ATTR slaveLoop(void);
#endif #endif

View File

@ -9,7 +9,7 @@
#include "TFT_eSPI.h" #include "TFT_eSPI.h"
void tftSetup(TFT_eSPI & screen); void tftSetup(TFT_eSPI & screen);
void tftLoop(void); void IRAM_ATTR tftLoop(void);
void tftStop(void); void tftStop(void);
void tftShowConfig(TFT_eSPI & tft); void tftShowConfig(TFT_eSPI & tft);