mirror of
https://github.com/esp8266/Arduino.git
synced 2025-04-22 21:23:07 +03:00
Add stack repainting call to ESP class (#5221)
Allow the unused stack to be reset to the check value at any time in the application, allowing for delta-stack calculations to be done. Add ESP.resetFreeContStack() class method for general use. Add in some dumping in the BearSSL_Validation example to show the usage for those that care.
This commit is contained in:
parent
d17ffc2874
commit
1b1b0a28a8
@ -183,6 +183,11 @@ uint32_t EspClass::getFreeContStack()
|
|||||||
return cont_get_free_stack(g_pcont);
|
return cont_get_free_stack(g_pcont);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void EspClass::resetFreeContStack()
|
||||||
|
{
|
||||||
|
cont_repaint_stack(g_pcont);
|
||||||
|
}
|
||||||
|
|
||||||
uint32_t EspClass::getChipId(void)
|
uint32_t EspClass::getChipId(void)
|
||||||
{
|
{
|
||||||
return system_get_chip_id();
|
return system_get_chip_id();
|
||||||
|
@ -111,6 +111,7 @@ class EspClass {
|
|||||||
void getHeapStats(uint32_t* free = nullptr, uint16_t* max = nullptr, uint8_t* frag = nullptr);
|
void getHeapStats(uint32_t* free = nullptr, uint16_t* max = nullptr, uint8_t* frag = nullptr);
|
||||||
|
|
||||||
uint32_t getFreeContStack();
|
uint32_t getFreeContStack();
|
||||||
|
void resetFreeContStack();
|
||||||
|
|
||||||
const char * getSdkVersion();
|
const char * getSdkVersion();
|
||||||
String getCoreVersion();
|
String getCoreVersion();
|
||||||
|
@ -74,6 +74,12 @@ int cont_get_free_stack(cont_t* cont);
|
|||||||
// continuation stack
|
// continuation stack
|
||||||
bool cont_can_yield(cont_t* cont);
|
bool cont_can_yield(cont_t* cont);
|
||||||
|
|
||||||
|
// Repaint the stack from the current SP to the end, to allow individual
|
||||||
|
// routines' stack usages to be calculated by re-painting, checking current
|
||||||
|
// free, running the routine, then checking the max free
|
||||||
|
void cont_repaint_stack(cont_t *cont);
|
||||||
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@ -64,3 +64,18 @@ bool ICACHE_RAM_ATTR cont_can_yield(cont_t* cont) {
|
|||||||
return !ETS_INTR_WITHINISR() &&
|
return !ETS_INTR_WITHINISR() &&
|
||||||
cont->pc_ret != 0 && cont->pc_yield == 0;
|
cont->pc_ret != 0 && cont->pc_yield == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// No need for this to be in IRAM, not expected to be IRQ called
|
||||||
|
void cont_repaint_stack(cont_t *cont)
|
||||||
|
{
|
||||||
|
register uint32_t *sp asm("a1");
|
||||||
|
// Ensure 64 bytes adjacent to the current SP don't get touched to endure
|
||||||
|
// we don't accidentally trounce over locals or IRQ temps.
|
||||||
|
uint32_t sp_safe = CONT_STACKSIZE/4 - ((sp - &cont->stack[0] - 64)/4);
|
||||||
|
|
||||||
|
// Fill stack with magic values
|
||||||
|
for(uint32_t pos = 0; pos < sp_safe; pos++)
|
||||||
|
{
|
||||||
|
cont->stack[pos] = CONT_STACKGUARD;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -38,6 +38,8 @@ void fetchURL(BearSSL::WiFiClientSecure *client, const char *host, const uint16_
|
|||||||
path = "/";
|
path = "/";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ESP.resetFreeContStack();
|
||||||
|
uint32_t freeStackStart = ESP.getFreeContStack();
|
||||||
Serial.printf("Trying: %s:443...", host);
|
Serial.printf("Trying: %s:443...", host);
|
||||||
client->connect(host, port);
|
client->connect(host, port);
|
||||||
if (!client->connected()) {
|
if (!client->connected()) {
|
||||||
@ -72,7 +74,8 @@ void fetchURL(BearSSL::WiFiClientSecure *client, const char *host, const uint16_
|
|||||||
} while (millis() < to);
|
} while (millis() < to);
|
||||||
}
|
}
|
||||||
client->stop();
|
client->stop();
|
||||||
Serial.printf("\n-------\n\n");
|
uint32_t freeStackEnd = ESP.getFreeContStack();
|
||||||
|
Serial.printf("\nCONT stack used: %d\n-------\n\n", freeStackStart - freeStackEnd);
|
||||||
}
|
}
|
||||||
|
|
||||||
void fetchNoConfig() {
|
void fetchNoConfig() {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user