Skip to content
Merged
Show file tree
Hide file tree
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
6 changes: 6 additions & 0 deletions cores/esp8266/cont.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,12 @@ int cont_get_free_stack(cont_t* cont);
// continuation stack
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
}
#endif
Expand Down
15 changes: 15 additions & 0 deletions cores/esp8266/cont_util.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,18 @@ bool ICACHE_RAM_ATTR cont_can_yield(cont_t* cont) {
return !ETS_INTR_WITHINISR() &&
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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

#include <ESP8266WiFi.h>
#include <time.h>
#include <cont.h>

const char *ssid = "....";
const char *pass = "....";
Expand Down Expand Up @@ -38,6 +39,8 @@ void fetchURL(BearSSL::WiFiClientSecure *client, const char *host, const uint16_
path = "/";
}

cont_repaint_stack(g_pcont);
uint32_t freeStackStart = cont_get_free_stack(g_pcont);
Serial.printf("Trying: %s:443...", host);
client->connect(host, port);
if (!client->connected()) {
Expand Down Expand Up @@ -72,7 +75,8 @@ void fetchURL(BearSSL::WiFiClientSecure *client, const char *host, const uint16_
} while (millis() < to);
}
client->stop();
Serial.printf("\n-------\n\n");
uint32_t freeStackEnd = cont_get_free_stack(g_pcont);
Serial.printf("\nCONT stack used: %d\n-------\n\n", freeStackStart - freeStackEnd);
}

void fetchNoConfig() {
Expand Down