Fix memory checker for ESP32 compatibility

This commit is contained in:
Noah Laptop 2020-01-06 09:38:39 -08:00
parent 231da37762
commit 576e34487e
69 changed files with 83 additions and 118 deletions

View file

@ -30,13 +30,10 @@ static constexpr auto VECTKEY_MASK = (0x0000ffffUL);
(*(uint32_t*)0xe000ed0cUL)=((*(uint32_t*)0xe000ed0cUL)&VECTKEY_MASK)|VECTKEY|SYSRESETREQ;
while(1) { }
}
#endif
#ifdef __arm__
// should use uinstd.h to define sbrk but Due causes a conflict
extern "C" char* sbrk(int incr);
#elif defined(ESP8266) // esp8266
#define SYSTEM_STACK_END_ADDRESS 0x3FFFC000
#else // __ARM__
extern char *__brkval;
#endif // __arm__
@ -46,15 +43,13 @@ static int freeMemory() {
char top;
#ifdef __arm__
return &top - reinterpret_cast<char*>(sbrk(0));
#elif defined(ESP8266) // ESP8266
register volatile uint32_t stackAddress asm("a1");
return stackAddress-SYSTEM_STACK_END_ADDRESS;
#elif defined(CORE_TEENSY) || (ARDUINO > 103 && ARDUINO != 151)
return &top - __brkval;
#else // __arm__
return __brkval ? &top - __brkval : &top - __malloc_heap_start;
#endif // __arm__
}
#endif // ARDUINO_ARCH_SAMD
/* see SSLClient.h */
SSLClient::SSLClient( Client& client,
@ -565,8 +560,8 @@ unsigned SSLClient::m_update_engine() {
// do we have the record you're looking for?
const auto avail = get_arduino_client().available();
if (avail > 0) {
int mem = freeMemory();
#if defined(ARDUINO_ARCH_SAMD)
int mem = freeMemory();
// check for a stack overflow
// if the stack overflows we basically have to crash, and
// hope the user is ok with that
@ -576,7 +571,6 @@ unsigned SSLClient::m_update_engine() {
// software reset
RESET();
}
#endif
// debug info
m_info("Memory: ", func_name);
m_info(mem, func_name);
@ -590,6 +584,7 @@ unsigned SSLClient::m_update_engine() {
stop();
return 0;
}
#endif
// I suppose so!
int rlen = get_arduino_client().read(buf, avail < len ? avail : len);
if (rlen <= 0) {