mirror of
https://github.com/esp8266/Arduino.git
synced 2025-04-19 23:22:16 +03:00
Add function to measure stack high water mark (thanks @g3gg0)
This commit is contained in:
parent
66a88ac8d2
commit
60baf802e1
@ -60,6 +60,10 @@ void cont_yield(cont_t*);
|
|||||||
// return 1 if guard bytes were overwritten.
|
// return 1 if guard bytes were overwritten.
|
||||||
int cont_check(cont_t* cont);
|
int cont_check(cont_t* cont);
|
||||||
|
|
||||||
|
// Go through stack and check how many bytes are most probably still unchanged
|
||||||
|
// and thus weren't used by the user code. i.e. that stack space is free. (high water mark)
|
||||||
|
int cont_get_free_stack(cont_t* cont);
|
||||||
|
|
||||||
// Check if yield() may be called. Returns true if we are running inside
|
// Check if yield() may be called. Returns true if we are running inside
|
||||||
// continuation stack
|
// continuation stack
|
||||||
bool cont_can_yield(cont_t* cont);
|
bool cont_can_yield(cont_t* cont);
|
||||||
|
@ -30,6 +30,12 @@ void ICACHE_RAM_ATTR cont_init(cont_t* cont) {
|
|||||||
cont->stack_guard2 = CONT_STACKGUARD;
|
cont->stack_guard2 = CONT_STACKGUARD;
|
||||||
cont->stack_end = cont->stack + (sizeof(cont->stack) / 4);
|
cont->stack_end = cont->stack + (sizeof(cont->stack) / 4);
|
||||||
cont->struct_start = (unsigned*) cont;
|
cont->struct_start = (unsigned*) cont;
|
||||||
|
|
||||||
|
// fill stack with magic values to check high water mark
|
||||||
|
for(int pos = 0; pos < sizeof(cont->stack) / 4; pos++)
|
||||||
|
{
|
||||||
|
cont->stack[pos] = CONT_STACKGUARD;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int ICACHE_RAM_ATTR cont_check(cont_t* cont) {
|
int ICACHE_RAM_ATTR cont_check(cont_t* cont) {
|
||||||
@ -38,6 +44,19 @@ int ICACHE_RAM_ATTR cont_check(cont_t* cont) {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int ICACHE_RAM_ATTR cont_get_free_stack(cont_t* cont) {
|
||||||
|
uint32_t *head = cont->stack;
|
||||||
|
int freeWords = 0;
|
||||||
|
|
||||||
|
while(*head == CONT_STACKGUARD)
|
||||||
|
{
|
||||||
|
head++;
|
||||||
|
freeWords++;
|
||||||
|
}
|
||||||
|
|
||||||
|
return freeWords * 4;
|
||||||
|
}
|
||||||
|
|
||||||
bool ICACHE_RAM_ATTR cont_can_yield(cont_t* cont) {
|
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;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user