Skip to content

Code size optimisation of ESP.getResetReason() #7029

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 30, 2020
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Code size optimisation of ESP.getResetReason()
doing if/else snakes for something that is a switch/case
is wasteful, as it repeatedly evaluates the same if() condition.
Also repeating strcpy_P is adding code bloat.

This simplification reduces size from 111 to 41 bytes.
  • Loading branch information
dirkmueller committed Jan 30, 2020
commit 422733c463446ed97d6196836c2feec104f004fa
35 changes: 18 additions & 17 deletions cores/esp8266/Esp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -468,23 +468,24 @@ bool EspClass::checkFlashCRC() {


String EspClass::getResetReason(void) {
char buff[32];
if (resetInfo.reason == REASON_DEFAULT_RST) { // normal startup by power on
strcpy_P(buff, PSTR("Power on"));
} else if (resetInfo.reason == REASON_WDT_RST) { // hardware watch dog reset
strcpy_P(buff, PSTR("Hardware Watchdog"));
} else if (resetInfo.reason == REASON_EXCEPTION_RST) { // exception reset, GPIO status won’t change
strcpy_P(buff, PSTR("Exception"));
} else if (resetInfo.reason == REASON_SOFT_WDT_RST) { // software watch dog reset, GPIO status won’t change
strcpy_P(buff, PSTR("Software Watchdog"));
} else if (resetInfo.reason == REASON_SOFT_RESTART) { // software restart ,system_restart , GPIO status won’t change
strcpy_P(buff, PSTR("Software/System restart"));
} else if (resetInfo.reason == REASON_DEEP_SLEEP_AWAKE) { // wake up from deep-sleep
strcpy_P(buff, PSTR("Deep-Sleep Wake"));
} else if (resetInfo.reason == REASON_EXT_SYS_RST) { // external system reset
strcpy_P(buff, PSTR("External System"));
} else {
strcpy_P(buff, PSTR("Unknown"));
const __FlashStringHelper* buff;

switch(resetInfo.reason) {
// normal startup by power on
case REASON_DEFAULT_RST: buff = F("Power On"); break;
// hardware watch dog reset
case REASON_WDT_RST: buff = F("Hardware Watchdog"); break;
// exception reset, GPIO status won’t change
case REASON_EXCEPTION_RST: buff = F("Exception"); break;
// software watch dog reset, GPIO status won’t change
case REASON_SOFT_WDT_RST: buff = F("Software Watchdog"); break;
// software restart ,system_restart , GPIO status won’t change
case REASON_SOFT_RESTART: buff = F("Software/System restart"); break;
// wake up from deep-sleep
case REASON_DEEP_SLEEP_AWAKE: buff = F("Deep-Sleep Wake"); break;
// // external system reset
case REASON_EXT_SYS_RST: buff = F("External System"); break;
default: buff = F("Unknown");
}
return String(buff);
}
Expand Down
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy