diff --git a/firmware/console/eficonsole.cpp b/firmware/console/eficonsole.cpp index 3d01e95818..ed03e47c65 100644 --- a/firmware/console/eficonsole.cpp +++ b/firmware/console/eficonsole.cpp @@ -119,18 +119,17 @@ static void sayHello(void) { } #if CH_DBG_THREADS_PROFILING && CH_DBG_FILL_THREADS -static uintptr_t CountFreeStackSpace(const void* wabase) -{ +int CountFreeStackSpace(const void* wabase) { const uint8_t* stackBase = reinterpret_cast(wabase); const uint8_t* stackUsage = stackBase; - // thread stacks are filled with 0x55 + // thread stacks are filled with CH_DBG_STACK_FILL_VALUE // find out where that ends - that's the last thing we needed on the stack - while(*stackUsage == 0x55) { + while (*stackUsage == CH_DBG_STACK_FILL_VALUE) { stackUsage++; } - return stackUsage - stackBase; + return (int)(stackUsage - stackBase); } #endif @@ -144,15 +143,15 @@ static void cmd_threads(void) { scheduleMsg(&logger, "name\twabase\ttime\tfree stack"); - while(tp) { - uintptr_t freeBytes = CountFreeStackSpace(tp->wabase); - scheduleMsg(&logger, "%s\t%08x\t%lu\t%lu", tp->name, tp->wabase, tp->time, freeBytes); + while (tp) { + int freeBytes = CountFreeStackSpace(tp->wabase); + scheduleMsg(&logger, "%s\t%08x\t%lu\t%d", tp->name, tp->wabase, tp->time, freeBytes); tp = chRegNextThread(tp); } - uintptr_t isrSpace = CountFreeStackSpace(reinterpret_cast(0x20000000)); - scheduleMsg(&logger, "isr\t0\t0\t%lu", isrSpace); + int isrSpace = CountFreeStackSpace(reinterpret_cast(0x20000000)); + scheduleMsg(&logger, "isr\t0\t0\t%d", isrSpace); #else // CH_DBG_THREADS_PROFILING && CH_DBG_FILL_THREADS diff --git a/firmware/global.h b/firmware/global.h index 177a4c62c2..876b747871 100644 --- a/firmware/global.h +++ b/firmware/global.h @@ -50,7 +50,8 @@ typedef unsigned int time_t; * project-wide default thread stack size * See also PORT_INT_REQUIRED_STACK * See getRemainingStack() - * See getMaxUsedStack() + * See getMaxUsedStack() and CountFreeStackSpace() + * See "threadsinfo" command cmd_threads */ #ifndef UTILITY_THREAD_STACK_SIZE #define UTILITY_THREAD_STACK_SIZE 400 diff --git a/firmware/os_access.h b/firmware/os_access.h index 36406f7606..9b63feffac 100644 --- a/firmware/os_access.h +++ b/firmware/os_access.h @@ -29,5 +29,6 @@ extern "C" * See also getMaxUsedStack() */ EXTERNC int getRemainingStack(thread_t *otp); +int CountFreeStackSpace(const void* wabase); #define HAS_OS_ACCESS