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
**********************/
void haspLoop(void)
void IRAM_ATTR haspLoop(void)
{}
/*
@ -483,7 +483,7 @@ void hasp_background(uint16_t pageid, uint16_t imageid)
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);
return buffer;
}

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -7,7 +7,7 @@
#include <Arduino.h>
void eepromSetup(void);
void eepromLoop(void);
void IRAM_ATTR eepromLoop(void);
void eepromWrite(uint16_t addr, std::string & data);
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());
eth_connected = true;
networkStart();// Start network services
networkStart(); // Start network services
break;
case SYSTEM_EVENT_ETH_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);
}
void ethernetLoop(void)
{
//
}
void IRAM_ATTR ethernetLoop(void)
{}
bool ethernetEvery5Seconds()
{

View File

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

View File

@ -637,7 +637,7 @@ void guiSetup()
}
}
void IRAM_ATTR guiLoop()
void IRAM_ATTR guiLoop(void)
{
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)
{
// uint8_t buffer[128];
// memset(buffer, 0, sizeof(buffer));
memset(buffer, 0, bufsize);
lv_disp_t * disp = lv_disp_get_default();

View File

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

View File

@ -155,7 +155,7 @@ String getOption(String value, String label, bool selected)
}
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);
#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
#endif
sprintf_P(buffer, HTTP_HEADER, nodename);
snprintf_P(buffer, sizeof(buffer), HTTP_HEADER, nodename);
webServer.sendContent(buffer); // 17-2+len
}
@ -486,7 +486,8 @@ void webHandleInfo()
byte mac[6];
WiFi.macAddress(mac);
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 += String(WiFi.localIP());
httpMessage += F("</br><b>Gateway: </b>");
@ -786,8 +787,8 @@ void handleFileDelete()
{
if(!httpIsAuthenticated(F("filedelete"))) return;
char mimetype[128];
sprintf(mimetype, PSTR("text/plain"));
char mimetype[16];
snprintf(mimetype, sizeof(mimetype), PSTR("text/plain"));
if(webServer.args() == 0) {
return webServer.send_P(500, mimetype, PSTR("BAD ARGS"));
@ -1750,8 +1751,8 @@ void httpSetup()
// load editor
webServer.on(F("/edit"), HTTP_GET, []() {
if(!handleFileRead("/edit.htm")) {
char mimetype[128];
sprintf(mimetype, PSTR("text/plain"));
char mimetype[16];
snprintf(mimetype, sizeof(mimetype), PSTR("text/plain"));
webServer.send_P(404, mimetype, PSTR("FileNotFound"));
}
});
@ -1854,7 +1855,7 @@ void httpReconnect()
}
////////////////////////////////////////////////////////////////////////////////////////////////////
void httpLoop()
void IRAM_ATTR httpLoop(void)
{
if(httpEnable) webServer.handleClient();
}

View File

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

View File

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

View File

@ -8,7 +8,7 @@
/* ===== Default Event Processors ===== */
void mdnsSetup();
void mdnsLoop(void);
void IRAM_ATTR mdnsLoop(void);
void mdnsStart(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
mqttResult(res, tmp_topic, "ON");
}
// Log.notice(TAG_MQTT, F("binary_sensor state: [status] : ON"));
} else {
// already ON
// Log.notice(TAG_MQTT, F("ignoring status = ON"));
}
} else {
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)];
snprintf_P(tmp_topic, sizeof(tmp_topic), format, data);
@ -325,11 +324,15 @@ void mqttSubscribeTo(const char * format, const char * data)
void mqttStart()
{
char buffer[128];
char buffer[64];
char mqttClientId[64];
char lastWillPayload[4];
static uint8_t mqttReconnectCount = 0;
bool mqttFirstConnect = true;
mqttClient.setServer(mqttServer, 1883);
/* Construct unique Client ID*/
{
String mac = halGetMacAddress(3, "");
mac.toLowerCase();
@ -338,11 +341,11 @@ void mqttStart()
Log.trace(TAG_MQTT, mqttClientId);
}
mqttClient.setServer(mqttServer, 1883);
// Attempt to connect and set LWT and Clean Session
snprintf_P(buffer, sizeof(buffer), PSTR("%sstatus"), mqttNodeTopic);
if(!mqttClient.connect(mqttClientId, mqttUser, mqttPassword, buffer, 0, false, "OFF", true)) { // Literal String
snprintf_P(buffer, sizeof(buffer), PSTR("%sstatus"), mqttNodeTopic); // lastWillTopic
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
mqttReconnectCount++;
@ -404,15 +407,6 @@ void mqttStart()
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
mqttSubscribeTo(PSTR("%scommand/#"), mqttGroupTopic);
mqttSubscribeTo(PSTR("%scommand/#"), mqttNodeTopic);
@ -460,14 +454,17 @@ void mqttSetup()
}
}
void mqttLoop()
void IRAM_ATTR mqttLoop(void)
{
if(mqttEnabled) mqttClient.loop();
}
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()

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -27,7 +27,7 @@ unsigned long updatLedPeriod = 1000; // timer in msec for tele mqtt send
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
// 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);
}
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];
memset(cBuffer, 0 ,sizeof(cBuffer));
@ -151,7 +151,7 @@ void slaveSetup()
Log.notice(TAG_TASM,F("HASP SLAVE LOADED"));
}
void slaveLoop(void)
void IRAM_ATTR slaveLoop(void)
{
slave.loop();
// demo code to run the led without tasmota

View File

@ -10,14 +10,14 @@
void TASMO_EVERY_SECOND(void);
void TASMO_DATA_RECEIVE(char *data);
void IRAM_ATTR 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_state(const __FlashStringHelper * subtopic, const char * payload);
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_statusupdate();
void slaveSetup();
void slaveLoop(void);
void IRAM_ATTR slaveLoop(void);
#endif

View File

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