Change ESP32 freeHeap to MaxAllocHeap

This commit is contained in:
Theo Arends 2020-04-22 16:07:52 +02:00
parent d013fbbab8
commit be1fb3756c
9 changed files with 63 additions and 86 deletions

View File

@ -47,7 +47,7 @@ uint16_t SendMail(char *buffer) {
// return if not enough memory
uint16_t mem=ESP.getFreeHeap();
uint16_t mem=ESP_getFreeHeap();
if (mem<SEND_MAIL_MINRAM) {
return 4;
}

View File

@ -52,7 +52,7 @@ void OsWatchTicker(void)
#ifdef DEBUG_THEO
int32_t rssi = WiFi.RSSI();
AddLog_P2(LOG_LEVEL_DEBUG, PSTR(D_LOG_APPLICATION D_OSWATCH " FreeRam %d, rssi %d %% (%d dBm), last_run %d"), ESP.getFreeHeap(), WifiGetRssiAsQuality(rssi), rssi, last_run);
AddLog_P2(LOG_LEVEL_DEBUG, PSTR(D_LOG_APPLICATION D_OSWATCH " FreeRam %d, rssi %d %% (%d dBm), last_run %d"), ESP_getFreeHeap(), WifiGetRssiAsQuality(rssi), rssi, last_run);
#endif // DEBUG_THEO
if (last_run >= (OSWATCH_RESET_TIME * 1000)) {
// AddLog_P(LOG_LEVEL_INFO, PSTR(D_LOG_APPLICATION D_OSWATCH " " D_BLOCKED_LOOP ". " D_RESTARTING)); // Save iram space

View File

@ -465,7 +465,7 @@ void CmndStatus(void)
#endif
",\"" D_JSON_FLASHMODE "\":%d,\""
D_JSON_FEATURES "\":[\"%08X\",\"%08X\",\"%08X\",\"%08X\",\"%08X\",\"%08X\",\"%08X\"]"),
ESP_getSketchSize()/1024, ESP.getFreeSketchSpace()/1024, ESP.getFreeHeap()/1024,
ESP_getSketchSize()/1024, ESP.getFreeSketchSpace()/1024, ESP_getFreeHeap()/1024,
ESP.getFlashChipSize()/1024, ESP.getFlashChipRealSize()/1024
#ifdef ESP8266
, ESP.getFlashChipId()

View File

@ -27,28 +27,27 @@ extern "C" {
extern struct rst_info resetInfo;
}
uint32_t ESP_ResetInfoReason(void)
{
uint32_t ESP_ResetInfoReason(void) {
return resetInfo.reason;
}
String ESP_getResetReason(void)
{
String ESP_getResetReason(void) {
return ESP.getResetReason();
}
uint32_t ESP_getChipId(void)
{
uint32_t ESP_getChipId(void) {
return ESP.getChipId();
}
uint32_t ESP_getSketchSize(void)
{
uint32_t ESP_getSketchSize(void) {
return ESP.getSketchSize();
}
void ESP_Restart(void)
{
uint32_t ESP_getFreeHeap(void) {
return ESP.getFreeHeap();
}
void ESP_Restart(void) {
// ESP.restart(); // This results in exception 3 on restarts on core 2.3.0
ESP.reset();
}
@ -64,8 +63,7 @@ void ESP_Restart(void)
#include <nvs.h>
#include <rom/rtc.h>
void NvmLoad(const char *sNvsName, const char *sName, void *pSettings, unsigned nSettingsLen)
{
void NvmLoad(const char *sNvsName, const char *sName, void *pSettings, unsigned nSettingsLen) {
nvs_handle handle;
noInterrupts();
nvs_open(sNvsName, NVS_READONLY, &handle);
@ -75,8 +73,7 @@ void NvmLoad(const char *sNvsName, const char *sName, void *pSettings, unsigned
interrupts();
}
void NvmSave(const char *sNvsName, const char *sName, const void *pSettings, unsigned nSettingsLen)
{
void NvmSave(const char *sNvsName, const char *sName, const void *pSettings, unsigned nSettingsLen) {
nvs_handle handle;
noInterrupts();
nvs_open(sNvsName, NVS_READWRITE, &handle);
@ -86,8 +83,7 @@ void NvmSave(const char *sNvsName, const char *sName, const void *pSettings, uns
interrupts();
}
void NvmErase(const char *sNvsName)
{
void NvmErase(const char *sNvsName) {
nvs_handle handle;
noInterrupts();
nvs_open(sNvsName, NVS_READWRITE, &handle);
@ -97,16 +93,10 @@ void NvmErase(const char *sNvsName)
interrupts();
}
void SettingsErase(uint8_t type)
{
if (1 == type) // SDK parameter area
{
}
else if (2 == type) // Tasmota parameter area (0x0F3xxx - 0x0FBFFF)
{
}
else if (3 == type) // Tasmota and SDK parameter area (0x0F3xxx - 0x0FFFFF)
{
void SettingsErase(uint8_t type) {
if (1 == type) { // SDK parameter area
} else if (2 == type) { // Tasmota parameter area (0x0F3xxx - 0x0FBFFF)
} else if (3 == type) { // Tasmota and SDK parameter area (0x0F3xxx - 0x0FFFFF)
}
NvmErase("main");
@ -114,23 +104,19 @@ void SettingsErase(uint8_t type)
AddLog_P2(LOG_LEVEL_DEBUG, PSTR(D_LOG_APPLICATION D_ERASE " t=%d"), type);
}
void SettingsRead(void *data, size_t size)
{
void SettingsRead(void *data, size_t size) {
NvmLoad("main", "Settings", data, size);
}
void SettingsWrite(const void *pSettings, unsigned nSettingsLen)
{
void SettingsWrite(const void *pSettings, unsigned nSettingsLen) {
NvmSave("main", "Settings", pSettings, nSettingsLen);
}
void QPCRead(void *pSettings, unsigned nSettingsLen)
{
void QPCRead(void *pSettings, unsigned nSettingsLen) {
NvmLoad("qpc", "pcreg", pSettings, nSettingsLen);
}
void QPCWrite(const void *pSettings, unsigned nSettingsLen)
{
void QPCWrite(const void *pSettings, unsigned nSettingsLen) {
NvmSave("qpc", "pcreg", pSettings, nSettingsLen);
}
@ -139,13 +125,11 @@ void QPCWrite(const void *pSettings, unsigned nSettingsLen)
//
static bool bNetIsTimeSync = false;
//
void SntpInit()
{
void SntpInit() {
bNetIsTimeSync = true;
}
uint32_t SntpGetCurrentTimestamp(void)
{
uint32_t SntpGetCurrentTimestamp(void) {
time_t now = 0;
if (bNetIsTimeSync || ntp_force_sync)
{
@ -163,20 +147,17 @@ uint32_t SntpGetCurrentTimestamp(void)
// Crash stuff
//
void CrashDump(void)
{
void CrashDump(void) {
}
bool CrashFlag(void)
{
bool CrashFlag(void) {
return false;
}
void CrashDumpClear(void)
{
void CrashDumpClear(void) {
}
void CmndCrash(void)
{
void CmndCrash(void) {
/*
volatile uint32_t dummy;
dummy = *((uint32_t*) 0x00000000);
@ -184,8 +165,7 @@ void CmndCrash(void)
}
// Do an infinite loop to trigger WDT watchdog
void CmndWDT(void)
{
void CmndWDT(void) {
/*
volatile uint32_t dummy = 0;
while (1) {
@ -194,8 +174,7 @@ void CmndWDT(void)
*/
}
// This will trigger the os watch after OSWATCH_RESET_TIME (=120) seconds
void CmndBlockedLoop(void)
{
void CmndBlockedLoop(void) {
/*
while (1) {
delay(1000);
@ -210,8 +189,7 @@ void CmndBlockedLoop(void)
#include "soc/soc.h"
#include "soc/rtc_cntl_reg.h"
void DisableBrownout(void)
{
void DisableBrownout(void) {
// https://github.com/espressif/arduino-esp32/issues/863#issuecomment-347179737
WRITE_PERI_REG(RTC_CNTL_BROWN_OUT_REG, 0); // Disable brownout detector
}
@ -220,8 +198,7 @@ void DisableBrownout(void)
// ESP32 Alternatives
//
String ESP32GetResetReason(uint32_t cpu_no)
{
String ESP32GetResetReason(uint32_t cpu_no) {
// tools\sdk\include\esp32\rom\rtc.h
switch (rtc_get_reset_reason( (RESET_REASON) cpu_no)) {
case POWERON_RESET : return F("Vbat power on reset"); // 1
@ -243,13 +220,11 @@ String ESP32GetResetReason(uint32_t cpu_no)
}
}
String ESP_getResetReason(void)
{
String ESP_getResetReason(void) {
return ESP32GetResetReason(0); // CPU 0
}
uint32_t ESP_ResetInfoReason(void)
{
uint32_t ESP_ResetInfoReason(void) {
RESET_REASON reason = rtc_get_reset_reason(0);
if (POWERON_RESET == reason) { return REASON_DEFAULT_RST; }
if (SW_CPU_RESET == reason) { return REASON_SOFT_RESTART; }
@ -257,8 +232,7 @@ uint32_t ESP_ResetInfoReason(void)
if (SW_RESET == reason) { return REASON_EXT_SYS_RST; }
}
uint32_t ESP_getChipId(void)
{
uint32_t ESP_getChipId(void) {
uint32_t id = 0;
for (uint32_t i = 0; i < 17; i = i +8) {
id |= ((ESP.getEfuseMac() >> (40 - i)) & 0xff) << i;
@ -266,8 +240,7 @@ uint32_t ESP_getChipId(void)
return id;
}
uint32_t ESP_getSketchSize(void)
{
uint32_t ESP_getSketchSize(void) {
static uint32_t sketchsize = 0;
if (!sketchsize) {
@ -276,8 +249,12 @@ uint32_t ESP_getSketchSize(void)
return sketchsize;
}
void ESP_Restart(void)
{
uint32_t ESP_getFreeHeap(void) {
// return ESP.getFreeHeap();
return ESP.getMaxAllocHeap();
}
void ESP_Restart(void) {
ESP.restart();
}

View File

@ -629,7 +629,7 @@ void MqttShowState(void)
#endif
ResponseAppend_P(PSTR(",\"" D_JSON_HEAPSIZE "\":%d,\"SleepMode\":\"%s\",\"Sleep\":%u,\"LoadAvg\":%u,\"MqttCount\":%u"),
ESP.getFreeHeap()/1024, GetTextIndexed(stemp1, sizeof(stemp1), Settings.flag3.sleep_normal, kSleepMode), // SetOption60 - Enable normal sleep instead of dynamic sleep
ESP_getFreeHeap()/1024, GetTextIndexed(stemp1, sizeof(stemp1), Settings.flag3.sleep_normal, kSleepMode), // SetOption60 - Enable normal sleep instead of dynamic sleep
ssleep, loop_load_avg, MqttConnectCount());
for (uint32_t i = 1; i <= devices_present; i++) {

View File

@ -2110,7 +2110,7 @@ void HandleInformation(void)
char stopic[TOPSZ];
int freeMem = ESP.getFreeHeap();
int freeMem = ESP_getFreeHeap();
WSContentStart_P(S_INFORMATION);
// Save 1k of code space replacing table html with javascript replace codes

View File

@ -1415,7 +1415,7 @@ chknext:
goto exit;
}
if (!strncmp(vname,"heap",4)) {
fvar=ESP.getFreeHeap();
fvar=ESP_getFreeHeap();
goto exit;
}
if (!strncmp(vname,"hn(",3)) {

View File

@ -202,8 +202,8 @@ void hydrateDevices(const SBuffer &buf) {
for (uint32_t i = 0; (i < num_devices) && (k < buf_len); i++) {
uint32_t dev_record_len = buf.get8(k);
// AddLog_P2(LOG_LEVEL_INFO, PSTR(D_LOG_ZIGBEE "Device %d Before Memory = %d // DIFF %d // record_len %d"), i, ESP.getFreeHeap(), before - ESP.getFreeHeap(), dev_record_len);
// before = ESP.getFreeHeap();
// AddLog_P2(LOG_LEVEL_INFO, PSTR(D_LOG_ZIGBEE "Device %d Before Memory = %d // DIFF %d // record_len %d"), i, ESP_getFreeHeap(), before - ESP_getFreeHeap(), dev_record_len);
// before = ESP_getFreeHeap();
SBuffer buf_d = buf.subBuffer(k, dev_record_len);
@ -238,7 +238,7 @@ void hydrateDevices(const SBuffer &buf) {
// ignore
}
}
//AddLog_P2(LOG_LEVEL_INFO, PSTR(D_LOG_ZIGBEE "Device 0x%04X Memory3.shrink = %d"), shortaddr, ESP.getFreeHeap());
//AddLog_P2(LOG_LEVEL_INFO, PSTR(D_LOG_ZIGBEE "Device 0x%04X Memory3.shrink = %d"), shortaddr, ESP_getFreeHeap());
// parse 3 strings
char empty[] = "";
@ -269,14 +269,14 @@ void hydrateDevices(const SBuffer &buf) {
// next iteration
k += dev_record_len;
//AddLog_P2(LOG_LEVEL_INFO, PSTR(D_LOG_ZIGBEE "Device %d After Memory = %d"), i, ESP.getFreeHeap());
//AddLog_P2(LOG_LEVEL_INFO, PSTR(D_LOG_ZIGBEE "Device %d After Memory = %d"), i, ESP_getFreeHeap());
}
}
void loadZigbeeDevices(void) {
z_flashdata_t flashdata;
memcpy_P(&flashdata, z_dev_start, sizeof(z_flashdata_t));
// AddLog_P2(LOG_LEVEL_DEBUG, PSTR(D_LOG_ZIGBEE "Memory %d"), ESP.getFreeHeap());
// AddLog_P2(LOG_LEVEL_DEBUG, PSTR(D_LOG_ZIGBEE "Memory %d"), ESP_getFreeHeap());
AddLog_P2(LOG_LEVEL_DEBUG, PSTR(D_LOG_ZIGBEE "Zigbee signature in Flash: %08X - %d"), flashdata.name, flashdata.len);
// Check the signature
@ -291,7 +291,7 @@ void loadZigbeeDevices(void) {
} else {
AddLog_P2(LOG_LEVEL_INFO, PSTR(D_LOG_ZIGBEE "No zigbee devices data in Flash"));
}
// AddLog_P2(LOG_LEVEL_DEBUG, PSTR(D_LOG_ZIGBEE "Memory %d"), ESP.getFreeHeap());
// AddLog_P2(LOG_LEVEL_DEBUG, PSTR(D_LOG_ZIGBEE "Memory %d"), ESP_getFreeHeap());
}
void saveZigbeeDevices(void) {

View File

@ -160,7 +160,7 @@ void ZigbeeInit(void)
// update commands with the current settings
Z_UpdateConfig(Settings.zb_channel, Settings.zb_pan_id, Settings.zb_ext_panid, Settings.zb_precfgkey_l, Settings.zb_precfgkey_h);
// AddLog_P2(LOG_LEVEL_INFO, PSTR("ZigbeeInit Mem1 = %d"), ESP.getFreeHeap());
// AddLog_P2(LOG_LEVEL_INFO, PSTR("ZigbeeInit Mem1 = %d"), ESP_getFreeHeap());
zigbee.active = false;
if ((pin[GPIO_ZIGBEE_RX] < 99) && (pin[GPIO_ZIGBEE_TX] < 99)) {
AddLog_P2(LOG_LEVEL_DEBUG_MORE, PSTR(D_LOG_ZIGBEE "GPIOs Rx:%d Tx:%d"), pin[GPIO_ZIGBEE_RX], pin[GPIO_ZIGBEE_TX]);
@ -172,16 +172,16 @@ void ZigbeeInit(void)
uint32_t aligned_buffer = ((uint32_t)serial_in_buffer + 3) & ~3;
zigbee_buffer = new PreAllocatedSBuffer(sizeof(serial_in_buffer) - 3, (char*) aligned_buffer);
} else {
// AddLog_P2(LOG_LEVEL_INFO, PSTR("ZigbeeInit Mem2 = %d"), ESP.getFreeHeap());
// AddLog_P2(LOG_LEVEL_INFO, PSTR("ZigbeeInit Mem2 = %d"), ESP_getFreeHeap());
zigbee_buffer = new SBuffer(ZIGBEE_BUFFER_SIZE);
// AddLog_P2(LOG_LEVEL_INFO, PSTR("ZigbeeInit Mem3 = %d"), ESP.getFreeHeap());
// AddLog_P2(LOG_LEVEL_INFO, PSTR("ZigbeeInit Mem3 = %d"), ESP_getFreeHeap());
}
zigbee.active = true;
zigbee.init_phase = true; // start the state machine
zigbee.state_machine = true; // start the state machine
ZigbeeSerial->flush();
}
// AddLog_P2(LOG_LEVEL_INFO, PSTR("ZigbeeInit Mem9 = %d"), ESP.getFreeHeap());
// AddLog_P2(LOG_LEVEL_INFO, PSTR("ZigbeeInit Mem9 = %d"), ESP_getFreeHeap());
}
/*********************************************************************************************\