[ESP8266] Switch to using 2nd heap with Arduino SDK 3.1.2

This commit is contained in:
TD-er
2023-11-14 13:31:58 +01:00
parent 08b90a8e28
commit 69103b1d0d
41 changed files with 361 additions and 79 deletions
+25 -19
View File
@@ -50,7 +50,7 @@ lib_ignore = ESP32_ping
TinyWireM
LittleFS(esp8266)
I2C AXP192 Power management
EspSoftwareSerial
; EspSoftwareSerial
[esp82xx_2_5_x]
build_flags = -DNDEBUG
@@ -184,7 +184,7 @@ lib_ignore = ${esp82xx_defaults.lib_ignore}
[core_4_1_0]
extends = esp82xx_3_0_x
platform = espressif8266@4.1.0
platform = espressif8266@4.2.1
platform_packages =
build_flags = ${esp82xx_3_0_x.build_flags}
-DPIO_FRAMEWORK_ARDUINO_ESPRESSIF_SDK3
@@ -197,29 +197,35 @@ lib_ignore = ${esp82xx_defaults.lib_ignore}
ServoESP32
TinyWireM
[core_stage_2ndheap]
extends = esp82xx_3_0_x
platform = espressif8266@4.1.0
build_flags = ${esp82xx_3_0_x.build_flags}
-DPIO_FRAMEWORK_ARDUINO_ESPRESSIF_SDK3
-DPIO_FRAMEWORK_ARDUINO_MMU_CACHE16_IRAM48_SECHEAP_SHARED
-DUSE_SECOND_HEAP
-DPHASE_LOCKED_WAVEFORM
platform_packages =
; platformio/framework-arduinoespressif8266 @ https://github.com/esp8266/Arduino.git
; mcspr/toolchain-xtensa @ ~5.100300.211127
[core_stage]
extends = esp82xx_3_0_x
platform = https://github.com/platformio/platform-espressif8266.git
platform_packages =
; platformio/framework-arduinoespressif8266 @ https://github.com/esp8266/Arduino.git
; mcspr/toolchain-xtensa @ ~5.100300.211127
platform = espressif8266@4.2.1
platform_packages =
build_flags = ${esp82xx_3_0_x.build_flags}
-DPIO_FRAMEWORK_ARDUINO_ESPRESSIF_SDK3
-DUSES_LATEST_SOFTWARE_SERIAL_LIBRARY=1
-DLIBRARIES_NO_LOG=1
-DPHASE_LOCKED_WAVEFORM
lib_ignore = ESP32_ping
ESP32WebServer
ESP32HTTPUpdateServer
ServoESP32
IRremoteESP8266
HeatpumpIR
TinyWireM
LittleFS(esp8266)
I2C AXP192 Power management
; See: https://arduino-esp8266.readthedocs.io/en/latest/mmu.html
[core_stage_2ndheap]
extends = esp82xx_3_0_x
platform = espressif8266@4.2.1
platform_packages =
build_flags = ${core_stage.build_flags}
-DPIO_FRAMEWORK_ARDUINO_MMU_CACHE16_IRAM48_SECHEAP_SHARED
-DUSE_SECOND_HEAP
lib_ignore = ${core_stage.lib_ignore}
+4 -4
View File
@@ -4,10 +4,10 @@
[regular_platform]
build_flags = ${core_2_7_4.build_flags}
platform = ${core_2_7_4.platform}
platform_packages = ${core_2_7_4.platform_packages}
lib_ignore = ${core_2_7_4.lib_ignore}
build_flags = ${core_stage_2ndheap.build_flags}
platform = ${core_stage_2ndheap.platform}
platform_packages = ${core_stage_2ndheap.platform_packages}
lib_ignore = ${core_stage_2ndheap.lib_ignore}
[regular_platform_alt_wifi]
build_flags = ${core_2_7_4_alt_wifi.build_flags}
+1 -1
View File
@@ -120,7 +120,7 @@ platform_packages = ${beta_platform_2ndheap.platform_packages}
build_flags = ${beta_platform_2ndheap.build_flags}
${esp8266_4M1M.build_flags}
-DPLUGIN_BUILD_CUSTOM
lib_ignore = ${esp8266_custom_common.lib_ignore}
lib_ignore = ${esp8266_custom_common_302.lib_ignore}
extra_scripts = ${esp8266_custom_common.extra_scripts}
[env:custom_beta_IR_ESP8266_4M1M]
+2 -2
View File
@@ -142,7 +142,7 @@ bool CPlugin_011(CPlugin::Function function, struct EventStruct *event, String&
{
// Try to allocate on 2nd heap
#ifdef USE_SECOND_HEAP
// HeapSelectIram ephemeral;
HeapSelectIram ephemeral;
#endif
std::shared_ptr<C011_ConfigStruct> tmp_shared(new (std::nothrow) C011_ConfigStruct);
customConfig = std::move(tmp_shared);
@@ -232,7 +232,7 @@ bool load_C011_ConfigStruct(controllerIndex_t ControllerIndex, String& HttpMetho
{
// Try to allocate on 2nd heap
#ifdef USE_SECOND_HEAP
// HeapSelectIram ephemeral;
HeapSelectIram ephemeral;
#endif
std::shared_ptr<C011_ConfigStruct> tmp_shared(new (std::nothrow) C011_ConfigStruct);
customConfig = std::move(tmp_shared);
+2 -1
View File
@@ -20,7 +20,6 @@
# define CPLUGIN_ID_013 13
# define CPLUGIN_NAME_013 "ESPEasy P2P Networking"
WiFiUDP C013_portUDP;
// Forward declarations
void C013_SendUDPTaskInfo(uint8_t destUnit,
@@ -202,6 +201,8 @@ void C013_sendUDP(uint8_t unit, const uint8_t *data, uint8_t size)
statusLED(true);
WiFiUDP C013_portUDP;
if (!beginWiFiUDP_randomPort(C013_portUDP)) { return; }
FeedSW_watchdog();
+3 -6
View File
@@ -132,8 +132,7 @@ bool CPlugin_018(CPlugin::Function function, struct EventStruct *event, String&
{
// Try to allocate on 2nd heap
# ifdef USE_SECOND_HEAP
// HeapSelectIram ephemeral;
HeapSelectIram ephemeral;
# endif // ifdef USE_SECOND_HEAP
std::shared_ptr<C018_ConfigStruct> tmp_shared(new (std::nothrow) C018_ConfigStruct);
customConfig = std::move(tmp_shared);
@@ -154,8 +153,7 @@ bool CPlugin_018(CPlugin::Function function, struct EventStruct *event, String&
{
// Try to allocate on 2nd heap
# ifdef USE_SECOND_HEAP
// HeapSelectIram ephemeral;
HeapSelectIram ephemeral;
# endif // ifdef USE_SECOND_HEAP
std::shared_ptr<C018_ConfigStruct> tmp_shared(new (std::nothrow) C018_ConfigStruct);
customConfig = std::move(tmp_shared);
@@ -315,8 +313,7 @@ bool C018_init(struct EventStruct *event) {
{
// Try to allocate on 2nd heap
# ifdef USE_SECOND_HEAP
// HeapSelectIram ephemeral;
HeapSelectIram ephemeral;
# endif // ifdef USE_SECOND_HEAP
std::shared_ptr<C018_ConfigStruct> tmp_shared(new (std::nothrow) C018_ConfigStruct);
customConfig = std::move(tmp_shared);
+8
View File
@@ -60,6 +60,10 @@ boolean Plugin_002(uint8_t function, struct EventStruct *event, String& string)
P002_data->webformLoad(event);
success = true;
} else {
# ifdef USE_SECOND_HEAP
HeapSelectIram ephemeral;
# endif // ifdef USE_SECOND_HEAP
P002_data = new (std::nothrow) P002_data_struct();
if (nullptr != P002_data) {
@@ -95,6 +99,10 @@ boolean Plugin_002(uint8_t function, struct EventStruct *event, String& string)
case PLUGIN_INIT:
{
# ifdef USE_SECOND_HEAP
HeapSelectIram ephemeral;
# endif // ifdef USE_SECOND_HEAP
initPluginTaskData(event->TaskIndex, new (std::nothrow) P002_data_struct());
P002_data_struct *P002_data =
static_cast<P002_data_struct *>(getPluginTaskData(event->TaskIndex));
+4
View File
@@ -249,6 +249,10 @@ boolean Plugin_004(uint8_t function, struct EventStruct *event, String& string)
Plugin_004_DallasPin_TX = Plugin_004_DallasPin_RX;
}
# ifdef USE_SECOND_HEAP
HeapSelectIram ephemeral;
# endif // ifdef USE_SECOND_HEAP
initPluginTaskData(event->TaskIndex, new (std::nothrow) P004_data_struct(
event->TaskIndex,
Plugin_004_DallasPin_RX,
+4
View File
@@ -186,6 +186,10 @@ boolean Plugin_023(uint8_t function, struct EventStruct *event, String& string)
font_spacing = static_cast<P023_data_struct::Spacing>(PCONFIG(4));
}
# ifdef USE_SECOND_HEAP
HeapSelectIram ephemeral;
# endif // ifdef USE_SECOND_HEAP
initPluginTaskData(event->TaskIndex, new (std::nothrow) P023_data_struct(PCONFIG(0), type, font_spacing, PCONFIG(2), PCONFIG(5)));
P023_data_struct *P023_data = static_cast<P023_data_struct *>(getPluginTaskData(event->TaskIndex));
+3
View File
@@ -119,6 +119,9 @@ boolean Plugin_028(uint8_t function, struct EventStruct *event, String& string)
case PLUGIN_INIT:
{
# ifdef USE_SECOND_HEAP
HeapSelectIram ephemeral;
# endif // ifdef USE_SECOND_HEAP
const float tempOffset = P028_TEMPERATURE_OFFSET / 10.0f;
initPluginTaskData(event->TaskIndex,
new (std::nothrow) P028_data_struct(P028_I2C_ADDRESS, tempOffset));
+3
View File
@@ -685,6 +685,9 @@ boolean Plugin_036(uint8_t function, struct EventStruct *event, String& string)
# ifdef P036_CHECK_HEAP
P036_CheckHeap(F("_INIT: Entering"));
# endif // P036_CHECK_HEAP
# ifdef USE_SECOND_HEAP
HeapSelectIram ephemeral;
# endif // ifdef USE_SECOND_HEAP
initPluginTaskData(event->TaskIndex, new (std::nothrow) P036_data_struct());
# ifdef P036_CHECK_HEAP
+31 -21
View File
@@ -204,34 +204,44 @@ boolean Plugin_037(uint8_t function, struct EventStruct *event, String& string)
}
# endif // if P037_REPLACE_BY_COMMA_SUPPORT
P037_data_struct *P037_data = new (std::nothrow) P037_data_struct(event->TaskIndex);
{
# ifdef USE_SECOND_HEAP
HeapSelectIram ephemeral;
# endif // ifdef USE_SECOND_HEAP
if (nullptr == P037_data) {
return success;
P037_data_struct *P037_data = new (std::nothrow) P037_data_struct(event->TaskIndex);
if (nullptr == P037_data) {
return success;
}
success = P037_data->loadSettings() && P037_data->webform_load(
# if P037_MAPPING_SUPPORT
P037_APPLY_MAPPINGS
# endif // if P037_MAPPING_SUPPORT
# if P037_MAPPING_SUPPORT && P037_FILTER_SUPPORT
,
# endif // if P037_MAPPING_SUPPORT && P037_FILTER_SUPPORT
# if P037_FILTER_SUPPORT
P037_APPLY_FILTERS
# endif // if P037_FILTER_SUPPORT
# if (P037_MAPPING_SUPPORT || P037_FILTER_SUPPORT) && P037_JSON_SUPPORT
,
# endif // if (P037_MAPPING_SUPPORT || P037_FILTER_SUPPORT) && P037_JSON_SUPPORT
# if P037_JSON_SUPPORT
P037_PARSE_JSON
# endif // if P037_JSON_SUPPORT
);
delete P037_data;
}
success = P037_data->loadSettings() && P037_data->webform_load(
# if P037_MAPPING_SUPPORT
P037_APPLY_MAPPINGS
# endif // if P037_MAPPING_SUPPORT
# if P037_MAPPING_SUPPORT && P037_FILTER_SUPPORT
,
# endif // if P037_MAPPING_SUPPORT && P037_FILTER_SUPPORT
# if P037_FILTER_SUPPORT
P037_APPLY_FILTERS
# endif // if P037_FILTER_SUPPORT
# if (P037_MAPPING_SUPPORT || P037_FILTER_SUPPORT) && P037_JSON_SUPPORT
,
# endif // if (P037_MAPPING_SUPPORT || P037_FILTER_SUPPORT) && P037_JSON_SUPPORT
# if P037_JSON_SUPPORT
P037_PARSE_JSON
# endif // if P037_JSON_SUPPORT
);
delete P037_data;
break;
}
case PLUGIN_WEBFORM_SAVE:
{
# ifdef USE_SECOND_HEAP
HeapSelectIram ephemeral;
# endif // ifdef USE_SECOND_HEAP
P037_data_struct *P037_data = new (std::nothrow) P037_data_struct(event->TaskIndex);
if (nullptr == P037_data) {
+5
View File
@@ -337,6 +337,11 @@ boolean Plugin_052(uint8_t function, struct EventStruct *event, String& string)
const int16_t serial_rx = CONFIG_PIN1;
const int16_t serial_tx = CONFIG_PIN2;
const ESPEasySerialPort port = static_cast<ESPEasySerialPort>(CONFIG_PORT);
# ifdef USE_SECOND_HEAP
HeapSelectIram ephemeral;
# endif // ifdef USE_SECOND_HEAP
initPluginTaskData(event->TaskIndex, new (std::nothrow) P052_data_struct());
P052_data_struct *P052_data =
static_cast<P052_data_struct *>(getPluginTaskData(event->TaskIndex));
+5
View File
@@ -316,6 +316,11 @@ boolean Plugin_082(uint8_t function, struct EventStruct *event, String& string)
const int16_t serial_rx = CONFIG_PIN1;
const int16_t serial_tx = CONFIG_PIN2;
const int16_t pps_pin = CONFIG_PIN3;
# ifdef USE_SECOND_HEAP
HeapSelectIram ephemeral;
# endif // ifdef USE_SECOND_HEAP
initPluginTaskData(event->TaskIndex, new (std::nothrow) P082_data_struct());
P082_data_struct *P082_data =
static_cast<P082_data_struct *>(getPluginTaskData(event->TaskIndex));
+12
View File
@@ -163,6 +163,10 @@ boolean Plugin_109(uint8_t function, struct EventStruct *event, String& string)
OLedFormContrast(F("contrast"), P109_CONFIG_CONTRAST);
{
# ifdef USE_SECOND_HEAP
HeapSelectIram ephemeral;
# endif // ifdef USE_SECOND_HEAP
P109_data_struct *P109_data = new (std::nothrow) P109_data_struct();
if (nullptr != P109_data) {
@@ -217,6 +221,10 @@ boolean Plugin_109(uint8_t function, struct EventStruct *event, String& string)
P109_FLAGS = lSettings;
{
# ifdef USE_SECOND_HEAP
HeapSelectIram ephemeral;
# endif // ifdef USE_SECOND_HEAP
P109_data_struct *P109_data = new (std::nothrow) P109_data_struct();
if (nullptr != P109_data) {
@@ -231,6 +239,10 @@ boolean Plugin_109(uint8_t function, struct EventStruct *event, String& string)
case PLUGIN_INIT:
{
# ifdef USE_SECOND_HEAP
HeapSelectIram ephemeral;
# endif // ifdef USE_SECOND_HEAP
initPluginTaskData(event->TaskIndex, new (std::nothrow) P109_data_struct());
P109_data_struct *P109_data = static_cast<P109_data_struct *>(getPluginTaskData(event->TaskIndex));
+33 -3
View File
@@ -57,20 +57,24 @@
bool init_c##NNN####M##_delay_queue(controllerIndex_t ControllerIndex); \
void exit_c##NNN####M##_delay_queue(); \
# ifdef USE_SECOND_HEAP
#define DEFINE_Cxxx_DELAY_QUEUE_MACRO_CPP(NNN, M) \
ControllerDelayHandlerStruct *C##NNN####M##_DelayHandler = nullptr; \
void process_c##NNN####M##_delay_queue() { \
if (C##NNN####M##_DelayHandler == nullptr) return; \
C##NNN####M##_DelayHandler->process( \
M, do_process_c##NNN####M##_delay_queue, TimingStatsElements::C##NNN####M##_DELAY_QUEUE, \
SchedulerIntervalTimer_e::TIMER_C##NNN####M##_DELAY_QUEUE); \
M, do_process_c##NNN####M##_delay_queue, TimingStatsElements::C##NNN####M##_DELAY_QUEUE, \
SchedulerIntervalTimer_e::TIMER_C##NNN####M##_DELAY_QUEUE); \
} \
bool init_c##NNN####M##_delay_queue(controllerIndex_t ControllerIndex) { \
if (C##NNN####M##_DelayHandler == nullptr) { \
HeapSelectIram ephemeral; \
C##NNN####M##_DelayHandler = new (std::nothrow) (ControllerDelayHandlerStruct); \
} \
if (C##NNN####M##_DelayHandler == nullptr) { return false; } \
return C##NNN####M##_DelayHandler->cacheControllerSettings(ControllerIndex); \
return C##NNN####M##_DelayHandler->cacheControllerSettings(ControllerIndex); \
} \
void exit_c##NNN####M##_delay_queue() { \
if (C##NNN####M##_DelayHandler != nullptr) { \
@@ -79,6 +83,32 @@
} \
} \
#else
#define DEFINE_Cxxx_DELAY_QUEUE_MACRO_CPP(NNN, M) \
ControllerDelayHandlerStruct *C##NNN####M##_DelayHandler = nullptr; \
void process_c##NNN####M##_delay_queue() { \
if (C##NNN####M##_DelayHandler == nullptr) return; \
C##NNN####M##_DelayHandler->process( \
M, do_process_c##NNN####M##_delay_queue, TimingStatsElements::C##NNN####M##_DELAY_QUEUE, \
SchedulerIntervalTimer_e::TIMER_C##NNN####M##_DELAY_QUEUE); \
} \
bool init_c##NNN####M##_delay_queue(controllerIndex_t ControllerIndex) { \
if (C##NNN####M##_DelayHandler == nullptr) { \
C##NNN####M##_DelayHandler = new (std::nothrow) (ControllerDelayHandlerStruct); \
} \
if (C##NNN####M##_DelayHandler == nullptr) { return false; } \
return C##NNN####M##_DelayHandler->cacheControllerSettings(ControllerIndex); \
} \
void exit_c##NNN####M##_delay_queue() { \
if (C##NNN####M##_DelayHandler != nullptr) { \
delete C##NNN####M##_DelayHandler; \
C##NNN####M##_DelayHandler = nullptr; \
} \
} \
#endif
@@ -219,7 +219,11 @@ private:
};
typedef std::shared_ptr<ControllerSettingsStruct> ControllerSettingsStruct_ptr_type;
# ifdef USE_SECOND_HEAP
#define MakeControllerSettings(T) HeapSelectIram ephemeral; ControllerSettingsStruct_ptr_type T(new (std::nothrow) ControllerSettingsStruct());
#else
#define MakeControllerSettings(T) ControllerSettingsStruct_ptr_type T(new (std::nothrow) ControllerSettingsStruct());
#endif
// Check to see if MakeControllerSettings was successful
#define AllocatedControllerSettings() (ControllerSettings.get() != nullptr)
@@ -33,6 +33,10 @@ bool ControllerCache_struct::flush() {
void ControllerCache_struct::init() {
if (_RTC_cache_handler == nullptr) {
# ifdef USE_SECOND_HEAP
HeapSelectIram ephemeral;
# endif // ifdef USE_SECOND_HEAP
_RTC_cache_handler = new (std::nothrow) RTC_cache_handler_struct;
if (_RTC_cache_handler != nullptr) {
_RTC_cache_handler->init();
+7 -1
View File
@@ -32,7 +32,13 @@ bool Modbus::begin(uint8_t function, uint8_t ModbusID, uint16_t ModbusRegister,
delay(1);
ModbusClient = nullptr;
}
ModbusClient = new (std::nothrow) WiFiClient();
{
# ifdef USE_SECOND_HEAP
HeapSelectIram ephemeral;
# endif // ifdef USE_SECOND_HEAP
ModbusClient = new (std::nothrow) WiFiClient();
}
if (ModbusClient == nullptr) {
return false;
}
+4
View File
@@ -399,6 +399,10 @@ void PluginStats_array::initPluginStats(taskVarIndex_t taskVarIndex)
_plugin_stats[taskVarIndex] = nullptr;
if (ExtraTaskSettings.enabledPluginStats(taskVarIndex)) {
# ifdef USE_SECOND_HEAP
HeapSelectIram ephemeral;
# endif // ifdef USE_SECOND_HEAP
_plugin_stats[taskVarIndex] = new (std::nothrow) PluginStats(
ExtraTaskSettings.TaskDeviceValueDecimals[taskVarIndex],
ExtraTaskSettings.TaskDeviceErrorValue[taskVarIndex]);
+4
View File
@@ -17,7 +17,11 @@
# ifndef PLUGIN_STATS_NR_ELEMENTS
# ifdef ESP8266
# ifdef USE_SECOND_HEAP
# define PLUGIN_STATS_NR_ELEMENTS 50
#else
# define PLUGIN_STATS_NR_ELEMENTS 16
#endif
# endif // ifdef ESP8266
# ifdef ESP32
# define PLUGIN_STATS_NR_ELEMENTS 250
@@ -15,6 +15,10 @@ void PluginTaskData_base::initPluginStats(taskVarIndex_t taskVarIndex)
{
if (taskVarIndex < VARS_PER_TASK) {
if (_plugin_stats_array == nullptr) {
# ifdef USE_SECOND_HEAP
HeapSelectIram ephemeral;
# endif // ifdef USE_SECOND_HEAP
_plugin_stats_array = new (std::nothrow) PluginStats_array();
}
+4
View File
@@ -7,6 +7,10 @@
UserVarStruct::UserVarStruct()
{
# ifdef USE_SECOND_HEAP
HeapSelectIram ephemeral;
# endif // ifdef USE_SECOND_HEAP
_data.resize(TASKS_MAX);
}
@@ -24,6 +24,10 @@ Web_StreamingBuffer::Web_StreamingBuffer(void) : lowMemorySkip(false),
initialRam(0), beforeTXRam(0), duringTXRam(0), finalRam(0), maxCoreUsage(0),
maxServerUsage(0), sentBytes(0), flashStringCalls(0), flashStringData(0)
{
# ifdef USE_SECOND_HEAP
HeapSelectIram ephemeral;
# endif // ifdef USE_SECOND_HEAP
buf.reserve(CHUNKED_BUFFER_SIZE + 50);
buf.clear();
}
+7
View File
@@ -535,6 +535,9 @@ bool MQTTpublish(controllerIndex_t controller_idx, taskIndex_t taskIndex, const
if (MQTT_queueFull(controller_idx)) {
return false;
}
# ifdef USE_SECOND_HEAP
HeapSelectIram ephemeral;
# endif // ifdef USE_SECOND_HEAP
const bool success = MQTTDelayHandler->addToQueue(std::unique_ptr<MQTT_queue_element>(new MQTT_queue_element(controller_idx, taskIndex, topic, payload, retained, callbackTask)));
scheduleNextMQTTdelayQueue();
@@ -549,6 +552,10 @@ bool MQTTpublish(controllerIndex_t controller_idx, taskIndex_t taskIndex, Strin
if (MQTT_queueFull(controller_idx)) {
return false;
}
# ifdef USE_SECOND_HEAP
HeapSelectIram ephemeral;
# endif // ifdef USE_SECOND_HEAP
const bool success = MQTTDelayHandler->addToQueue(std::unique_ptr<MQTT_queue_element>(new MQTT_queue_element(controller_idx, taskIndex, std::move(topic), std::move(payload), retained, callbackTask)));
scheduleNextMQTTdelayQueue();
@@ -75,9 +75,14 @@ void handle_unprocessedNetworkEvents()
WiFiEventData.processedDisconnect = true;
}
WiFiEventData.setWiFiServicesInitialized();
//#ifdef ESP32
setWebserverRunning(false);
setWebserverRunning(true);
// CheckRunningServices();
/*
#else
CheckRunningServices();
#endif
*/
}
}
}
+11 -1
View File
@@ -56,7 +56,13 @@ EspEasy_Console_t::EspEasy_Console_t()
config.rxBuffSize = 256;
config.txBuffSize = buffSize;
_mainSerial._serial = new (std::nothrow) ESPeasySerial(config);
{
# ifdef USE_SECOND_HEAP
HeapSelectIram ephemeral;
# endif // ifdef USE_SECOND_HEAP
_mainSerial._serial = new (std::nothrow) ESPeasySerial(config);
}
# if USES_ESPEASY_CONSOLE_FALLBACK_PORT
@@ -139,6 +145,10 @@ void EspEasy_Console_t::reInit()
}
if ((_mainSerial._serial == nullptr) && mustHaveSerial) {
# ifdef USE_SECOND_HEAP
HeapSelectIram ephemeral;
# endif // ifdef USE_SECOND_HEAP
_mainSerial._serial = new (std::nothrow) ESPeasySerial(
static_cast<ESPEasySerialPort>(_console_serial_port),
_console_serial_rxpin,
+5 -1
View File
@@ -248,11 +248,15 @@ void addLog(uint8_t logLevel, String&& string)
addToLogMove(logLevel, std::move(string));
}
#include "../Helpers/Memory.h"
void addToSerialLog(uint8_t logLevel, const String& string)
{
if (loglevelActiveFor(LOG_TO_SERIAL, logLevel)) {
ESPEasy_Console.addToSerialBuffer(String(millis()));
ESPEasy_Console.addToSerialBuffer(F(" : "));
ESPEasy_Console.addToSerialBuffer(F(" : ("));
ESPEasy_Console.addToSerialBuffer(String(FreeMem()));
ESPEasy_Console.addToSerialBuffer(F(") "));
{
String loglevelDisplayString = getLogLevelDisplayString(logLevel);
while (loglevelDisplayString.length() < 6) {
@@ -78,9 +78,9 @@ void backgroundtasks()
if (!UseRTOSMultitasking) {
serial();
if (webserverRunning) {
// if (webserverRunning) {
web_server.handleClient();
}
// }
#if FEATURE_ESPEASY_P2P
checkUDP();
#endif
+2
View File
@@ -292,7 +292,9 @@ void ESPEasy_setup()
// progMemMD5check();
LoadSettings();
#if FEATURE_DEFINE_SERIAL_CONSOLE_PORT
ESPEasy_Console.reInit();
#endif
#ifndef BUILD_NO_RAM_TRACKER
logMemUsageAfter(F("LoadSettings()"));
+21 -5
View File
@@ -103,11 +103,27 @@ bool CPluginCall(CPlugin::Function Function, struct EventStruct *event, String&
if (Function == CPlugin::Function::CPLUGIN_PROTOCOL_SEND) {
checkDeviceVTypeForTask(event);
}
success = CPluginCall(
getProtocolIndex_from_ControllerIndex(controllerindex),
Function,
event,
str);
# ifdef USE_SECOND_HEAP
if (Function == CPlugin::Function::CPLUGIN_INIT)
{
// Set 2nd heap active for the CPLUGIN_INIT call so controller service gets allocated on 2nd heap
HeapSelectIram ephemeral;
success = CPluginCall(
getProtocolIndex_from_ControllerIndex(controllerindex),
Function,
event,
str);
} else {
# endif // ifdef USE_SECOND_HEAP
success = CPluginCall(
getProtocolIndex_from_ControllerIndex(controllerindex),
Function,
event,
str);
# ifdef USE_SECOND_HEAP
}
# endif // ifdef USE_SECOND_HEAP
}
#ifdef ESP32
+20 -1
View File
@@ -350,7 +350,19 @@ bool PluginCallForTask(taskIndex_t taskIndex, uint8_t Function, EventStruct *Tem
}
START_TIMER;
retval = (PluginCall(DeviceIndex, Function, TempEvent, command));
# ifdef USE_SECOND_HEAP
if (Function == PLUGIN_INIT)
{
// Set 2nd heap active for the PLUGIN_INIT call so plugin task data gets allocated on 2nd heap
HeapSelectIram ephemeral;
retval = (PluginCall(DeviceIndex, Function, TempEvent, command));
} else {
# endif // ifdef USE_SECOND_HEAP
retval = (PluginCall(DeviceIndex, Function, TempEvent, command));
# ifdef USE_SECOND_HEAP
}
# endif // ifdef USE_SECOND_HEAP
STOP_TIMER_TASK(DeviceIndex, Function);
if (Function == PLUGIN_INIT) {
@@ -362,6 +374,10 @@ bool PluginCallForTask(taskIndex_t taskIndex, uint8_t Function, EventStruct *Tem
// Create Plugin Task data if it has "Stats" checked.
LoadTaskSettings(taskIndex);
if (ExtraTaskSettings.anyEnabledPluginStats()) {
# ifdef USE_SECOND_HEAP
HeapSelectIram ephemeral;
# endif // ifdef USE_SECOND_HEAP
initPluginTaskData(taskIndex, new (std::nothrow) _StatsOnly_data_struct());
}
}
@@ -384,6 +400,9 @@ bool PluginCallForTask(taskIndex_t taskIndex, uint8_t Function, EventStruct *Tem
// Create Plugin Task data if it has "Stats" checked.
LoadTaskSettings(taskIndex);
if (ExtraTaskSettings.anyEnabledPluginStats()) {
# ifdef USE_SECOND_HEAP
HeapSelectIram ephemeral;
# endif // ifdef USE_SECOND_HEAP
initPluginTaskData(taskIndex, new (std::nothrow) _StatsOnly_data_struct());
}
}
+4
View File
@@ -18,6 +18,10 @@ ESPEASY_RULES_FLOAT_TYPE getCustomFloatVar(uint32_t index) {
}
void setCustomFloatVar(uint32_t index, const ESPEASY_RULES_FLOAT_TYPE& value) {
# ifdef USE_SECOND_HEAP
HeapSelectIram ephemeral;
# endif // ifdef USE_SECOND_HEAP
customFloatVar[index] = value;
}
+4
View File
@@ -1109,6 +1109,10 @@ String LoadTaskSettings(taskIndex_t TaskIndex)
}
START_TIMER
# ifdef USE_SECOND_HEAP
HeapSelectIram ephemeral;
# endif // ifdef USE_SECOND_HEAP
ExtraTaskSettings.clear();
const deviceIndex_t DeviceIndex = getDeviceIndex_from_TaskIndex(TaskIndex);
if (!validDeviceIndex(DeviceIndex)) {
+7 -1
View File
@@ -45,7 +45,13 @@ bool ModbusRTU_struct::init(const ESPEasySerialPort port, const int16_t serial_r
return false;
}
reset();
easySerial = new (std::nothrow) ESPeasySerial(port, serial_rx, serial_tx);
{
# ifdef USE_SECOND_HEAP
HeapSelectIram ephemeral;
# endif // ifdef USE_SECOND_HEAP
easySerial = new (std::nothrow) ESPeasySerial(port, serial_rx, serial_tx);
}
if (easySerial == nullptr) { return false; }
easySerial->begin(baudrate);
+40
View File
@@ -29,6 +29,10 @@
// -V::569
String concat(const __FlashStringHelper * str, const String &val) {
#ifdef USE_SECOND_HEAP
HeapSelectIram ephemeral;
#endif
String res(str);
res.concat(val);
return res;
@@ -40,6 +44,10 @@ String concat(const __FlashStringHelper * str, const __FlashStringHelper *val) {
String concat(const char& str, const String &val)
{
#ifdef USE_SECOND_HEAP
HeapSelectIram ephemeral;
#endif
String res(str);
res.concat(val);
return res;
@@ -60,6 +68,10 @@ bool equals(const String& str, const char& c) {
String strformat(const String& format, ...)
{
#ifdef USE_SECOND_HEAP
HeapSelectIram ephemeral;
#endif
String res;
{
va_list arg;
@@ -88,6 +100,10 @@ String strformat(const String& format, ...)
String strformat(const __FlashStringHelper * format, ...)
{
#ifdef USE_SECOND_HEAP
HeapSelectIram ephemeral;
#endif
String res;
{
va_list arg;
@@ -508,6 +524,10 @@ String wrap_braces(const String& string) {
}
String wrap_String(const String& string, char wrap) {
#ifdef USE_SECOND_HEAP
HeapSelectIram ephemeral;
#endif
String result;
result.reserve(string.length() + 2);
result += wrap;
@@ -517,6 +537,10 @@ String wrap_String(const String& string, char wrap) {
}
String wrap_String(const String& string, char char1, char char2) {
#ifdef USE_SECOND_HEAP
HeapSelectIram ephemeral;
#endif
String result;
result.reserve(string.length() + 2);
result += char1;
@@ -585,6 +609,10 @@ String to_json_object_value(const __FlashStringHelper * object,
}
String to_json_object_value(const String& object, const String& value, bool wrapInQuotes) {
#ifdef USE_SECOND_HEAP
HeapSelectIram ephemeral;
#endif
String result;
result.reserve(object.length() + value.length() + 6);
result = wrap_String(object, '"');
@@ -830,6 +858,10 @@ String tolerantParseStringKeepCase(const String& string, uint8_t indexFind, char
* handles: 0xXX,text,0xXX," more text ",0xXX starting from index 2 (1-based)
****************************************************************************/
String parseHexTextString(const String& argument, int index) {
#ifdef USE_SECOND_HEAP
HeapSelectIram ephemeral;
#endif
String result;
// Ignore these characters when used as hex-byte separators (0x01ab 23-cd:45 -> 0x01,0xab,0x23,0xcd,0x45)
@@ -871,6 +903,10 @@ String parseHexTextString(const String& argument, int index) {
* handles: 0xXX,text,0xXX," more text ",0xXX starting from index 2 (1-based)
****************************************************************************/
std::vector<uint8_t> parseHexTextData(const String& argument, int index) {
#ifdef USE_SECOND_HEAP
HeapSelectIram ephemeral;
#endif
std::vector<uint8_t> result;
// Ignore these characters when used as hex-byte separators (0x01ab 23-cd:45 -> 0x01,0xab,0x23,0xcd,0x45)
@@ -1105,6 +1141,10 @@ void repl(const __FlashStringHelper * key1,
void repl(const String& key, const String& val, String& s, bool useURLencode)
{
#ifdef USE_SECOND_HEAP
HeapSelectIram ephemeral;
#endif
if (useURLencode) {
// URLEncode does take resources, so check first if needed.
if (s.indexOf(key) == -1) { return; }
+23 -6
View File
@@ -43,6 +43,10 @@ String parseTemplate_padded(String& tmpString, uint8_t minimal_lineSize)
String parseTemplate_padded(String& tmpString, uint8_t minimal_lineSize, bool useURLencode)
{
#ifdef USE_SECOND_HEAP
HeapSelectIram ephemeral;
#endif
#ifndef BUILD_NO_RAM_TRACKER
checkRAM(F("parseTemplate_padded"));
#endif // ifndef BUILD_NO_RAM_TRACKER
@@ -667,12 +671,16 @@ uint8_t findDeviceValueIndexByName(const String& valueName, taskIndex_t taskInde
// We need to use a cache search key including the taskIndex,
// to allow several tasks to have the same value names.
String cache_valueName;
cache_valueName.reserve(valueName.length() + 4);
cache_valueName = valueName;
cache_valueName += '#'; // The '#' cannot exist in a value name, use it in the cache key.
cache_valueName += taskIndex;
cache_valueName.toLowerCase(); // No need to store multiple versions of the same entry with only different case.
{
#ifdef USE_SECOND_HEAP
HeapSelectIram ephemeral;
#endif
cache_valueName.reserve(valueName.length() + 4);
cache_valueName = valueName;
cache_valueName += '#'; // The '#' cannot exist in a value name, use it in the cache key.
cache_valueName += taskIndex;
cache_valueName.toLowerCase(); // No need to store multiple versions of the same entry with only different case.
}
auto result = Cache.taskIndexValueName.find(cache_valueName);
@@ -686,6 +694,10 @@ uint8_t findDeviceValueIndexByName(const String& valueName, taskIndex_t taskInde
// Check case insensitive, since the user entered value name can have any case.
if (valueName.equalsIgnoreCase(getTaskValueName(taskIndex, valueNr)))
{
#ifdef USE_SECOND_HEAP
HeapSelectIram ephemeral;
#endif
Cache.taskIndexValueName[cache_valueName] = valueNr;
return valueNr;
}
@@ -732,6 +744,11 @@ bool findNextDevValNameInString(const String& input, int& startpos, int& endpos,
int hashpos;
if (!findNextValMarkInString(input, startpos, hashpos, endpos)) { return false; }
#ifdef USE_SECOND_HEAP
HeapSelectIram ephemeral;
#endif
deviceName = input.substring(startpos + 1, hashpos);
valueName = input.substring(hashpos + 1, endpos);
hashpos = valueName.indexOf('#');
+7 -1
View File
@@ -2222,7 +2222,13 @@ void PluginSetup()
Plugin_id_to_DeviceIndex[id] = INVALID_DEVICE_INDEX;
}
#ifdef ESP8266
Device = new (std::nothrow) DeviceStruct[DeviceIndex_to_Plugin_id_size];
{
# ifdef USE_SECOND_HEAP
HeapSelectIram ephemeral;
# endif // ifdef USE_SECOND_HEAP
Device = new (std::nothrow) DeviceStruct[DeviceIndex_to_Plugin_id_size];
}
#else
Device.resize(DeviceIndex_to_Plugin_id_size);
#endif
+14 -1
View File
@@ -50,7 +50,16 @@ String P036_LineContent::saveDisplayLines(taskIndex_t taskIndex) {
if (FreeMem() > 8000) {
// Write in one single chunk.
tDisplayLines_storage_full *tmp = new (std::nothrow) tDisplayLines_storage_full;
tDisplayLines_storage_full *tmp = nullptr;
# ifdef USE_SECOND_HEAP
{
HeapSelectIram ephemeral;
tmp = new (std::nothrow) tDisplayLines_storage_full;
}
# endif // ifdef USE_SECOND_HEAP
if (tmp == nullptr) {
tmp = new (std::nothrow) tDisplayLines_storage_full;
}
if (tmp != nullptr) {
for (int i = 0; i < P36_Nlines; ++i) {
@@ -286,6 +295,10 @@ void P036_data_struct::setOrientationRotated(bool rotated) {
void P036_data_struct::RestoreLineContent(taskIndex_t taskIndex,
uint8_t LoadVersion,
uint8_t LineNo) {
# ifdef USE_SECOND_HEAP
HeapSelectIram ephemeral;
# endif // ifdef USE_SECOND_HEAP
P036_LineContent *TempContent = new (std::nothrow) P036_LineContent();
if (TempContent != nullptr) {
+4
View File
@@ -346,6 +346,10 @@ class P036_LineContent {
public:
P036_LineContent() {
# ifdef USE_SECOND_HEAP
HeapSelectIram ephemeral;
# endif // ifdef USE_SECOND_HEAP
DisplayLinesV1.resize(P36_Nlines);
}
+4 -1
View File
@@ -66,11 +66,14 @@ else:
"-DFEATURE_DEFINE_SERIAL_CONSOLE_PORT=0",
"-DFEATURE_ESPEASY_P2P=1",
"-DEMBED_ESPEASY_DEFAULT_MIN_CSS",
"-DPLUGIN_STATS_NR_ELEMENTS=30",
# "-DPLUGIN_STATS_NR_ELEMENTS=30",
"-DFEATURE_PLUGIN_STATS=1",
"-DFEATURE_CHART_JS=1",
# "-DFEATURE_ADC_VCC=1",
"-DFEATURE_SETTINGS_ARCHIVE=1",
"-DDISABLE_SC16IS752_SPI"
]