4 * Created on: 23 Aug 2016
14 #include "build/build_config.h"
15 #include "build/debug.h"
17 #define STACK_FILL_CHAR 0xa5
19 extern char _estack
; // end of stack, declared in .LD file
20 extern char _Min_Stack_Size
; // declared in .LD file
23 * The ARM processor uses a full descending stack. This means the stack pointer holds the address
24 * of the last stacked item in memory. When the processor pushes a new item onto the stack,
25 * it decrements the stack pointer and then writes the item to the new memory location.
28 * RAM layout is generally as below, although some targets vary
31 * RAM is origin 0x20000000 length 20K that is:
32 * 0x20000000 to 0x20005000
35 * RAM is origin 0x20000000 length 40K that is:
36 * 0x20000000 to 0x2000a000
39 * RAM is origin 0x20000000 length 128K that is:
40 * 0x20000000 to 0x20020000
46 static uint32_t usedStackSize
;
48 void taskStackCheck(timeUs_t currentTimeUs
)
52 char * const stackHighMem
= &_estack
;
53 const uint32_t stackSize
= (uint32_t)&_Min_Stack_Size
;
54 char * const stackLowMem
= stackHighMem
- stackSize
;
55 const char * const stackCurrent
= (char *)&stackLowMem
;
58 for (p
= stackLowMem
; p
< stackCurrent
; ++p
) {
59 if (*p
!= STACK_FILL_CHAR
) {
64 usedStackSize
= (uint32_t)stackHighMem
- (uint32_t)p
;
67 debug
[0] = (uint32_t)stackHighMem
& 0xffff;
68 debug
[1] = (uint32_t)stackLowMem
& 0xffff;
69 debug
[2] = (uint32_t)stackCurrent
& 0xffff;
70 debug
[3] = (uint32_t)p
& 0xffff;
74 uint32_t stackUsedSize(void)
80 #if !defined(SITL_BUILD)
82 uint32_t stackTotalSize(void)
84 return (uint32_t)&_Min_Stack_Size
;
87 uint32_t stackHighMem(void)
89 return (uint32_t)&_estack
;