rusEFI
The most advanced open source ECU
Loading...
Searching...
No Matches
Functions
global_shared.h File Reference

Functions

int getRemainingStack (thread_t *otp)
 
int CountFreeStackSpace (const void *wabase)
 

Function Documentation

◆ CountFreeStackSpace()

int CountFreeStackSpace ( const void *  wabase)

Definition at line 171 of file eficonsole.cpp.

171 {
172 const uint8_t* stackBase = reinterpret_cast<const uint8_t*>(wabase);
173 const uint8_t* stackUsage = stackBase;
174
175 // thread stacks are filled with CH_DBG_STACK_FILL_VALUE
176 // find out where that ends - that's the last thing we needed on the stack
177 while (*stackUsage == CH_DBG_STACK_FILL_VALUE) {
178 stackUsage++;
179 }
180
181 return (int)(stackUsage - stackBase);
182}

Referenced by cmd_threads().

Here is the caller graph for this function:

◆ getRemainingStack()

int getRemainingStack ( thread_t *  otp)

Of note is that interrupts are NOT serviced on the stack of the thread that was running when the interrupt occurred. The only thing that happens on that thread's stack is that its registers are pushed (by hardware) when an interrupt occurs, just before swapping the stack pointer out for the main stack (currently 0x400=1024 bytes), where the ISR actually runs. see also main_stack_size see also process_stack_size

see also http://www.chibios.org/dokuwiki/doku.php?id=chibios:kb:stacks

In the firmware we are using 'extern *Engine' - in the firmware Engine is a singleton

On the other hand, in order to have a meaningful unit test we are passing Engine * engine as a parameter

Definition at line 164 of file at32_common.cpp.

164 {
165#if CH_DBG_ENABLE_STACK_CHECK
166 // this would dismiss coverity warning - see http://rusefi.com/forum/viewtopic.php?f=5&t=655
167 // coverity[uninit_use]
168 register intctx_t *r13 asm ("r13");
169 otp->activeStack = r13;
170
171 int remainingStack;
172 if (ch0.dbg.isr_cnt > 0) {
173 // ISR context
174 remainingStack = (int)(r13 - 1) - (int)&__main_stack_base__;
175 } else {
176 remainingStack = (int)(r13 - 1) - (int)otp->wabase;
177 }
178 otp->remainingStack = remainingStack;
179 return remainingStack;
180#else
181 UNUSED(otp);
182 return 99999;
183#endif /* CH_DBG_ENABLE_STACK_CHECK */
184}
uint32_t __main_stack_base__
struct port_intctx intctx_t
UNUSED(samplingTimeSeconds)
Here is the call graph for this function:

Go to the source code of this file.