Skip to content

Commit

Permalink
Re #1643: added main stack (MSP) paint and free check
Browse files Browse the repository at this point in the history
  • Loading branch information
projectkk2glider committed Aug 31, 2014
1 parent b15ce6f commit a78c2b8
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 4 deletions.
8 changes: 5 additions & 3 deletions radio/src/gui/view_statistics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -204,12 +204,14 @@ void menuStatisticsDebug(uint8_t event)
lcd_putsLeft(6*FH, STR_FREESTACKMINB);

#if LCD_W >= 212
lcd_putsAtt(MENU_DEBUG_COL1_OFS, 6*FH+1, "[Main]", SMLSIZE);
lcd_putsAtt(MENU_DEBUG_COL1_OFS, 6*FH+1, "[G]", SMLSIZE);
lcd_outdezAtt(lcdLastPos, 6*FH, stack_free(0), UNSIGN|LEFT);
lcd_putsAtt(lcdLastPos+2, 6*FH+1, "[Mix]", SMLSIZE);
lcd_putsAtt(lcdLastPos+2, 6*FH+1, "[M]", SMLSIZE);
lcd_outdezAtt(lcdLastPos, 6*FH, stack_free(1), UNSIGN|LEFT);
lcd_putsAtt(lcdLastPos+2, 6*FH+1, "[Audio]", SMLSIZE);
lcd_putsAtt(lcdLastPos+2, 6*FH+1, "[A]", SMLSIZE);
lcd_outdezAtt(lcdLastPos, 6*FH, stack_free(2), UNSIGN|LEFT);
lcd_putsAtt(lcdLastPos+2, 6*FH+1, "[I]", SMLSIZE);
lcd_outdezAtt(lcdLastPos, 6*FH, stack_free(255), UNSIGN|LEFT);
#else
lcd_outdezAtt(MENU_DEBUG_COL1_OFS, 6*FH, stack_free(0), UNSIGN|LEFT);
lcd_puts(lcdLastPos, 6*FH, "/");
Expand Down
5 changes: 5 additions & 0 deletions radio/src/opentx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3304,6 +3304,11 @@ uint16_t stack_free(uint8_t tid)
stack = audioStack;
size = AUDIO_STACK_SIZE;
break;
case 255:
// main stack
stack = (OS_STK *)&_main_stack_start;
size = (_main_stack_size / 4);
break;
default:
return 0;
}
Expand Down
2 changes: 2 additions & 0 deletions radio/src/opentx.h
Original file line number Diff line number Diff line change
Expand Up @@ -694,6 +694,8 @@ extern uint8_t flightModeTransitionLast;
extern unsigned char *heap;
extern int _end;
extern unsigned char *_estack;
extern unsigned char * _main_stack_start;
extern const int _main_stack_size;
#define getAvailableMemory() ((unsigned int)((unsigned char *)&_estack - heap))
#endif

Expand Down
3 changes: 2 additions & 1 deletion radio/src/targets/sky9x/syscalls.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
extern int errno;
extern int _end;
extern int _estack;
extern const int _main_stack_size;

#define RAM_END (unsigned char *)&_estack

Expand All @@ -68,7 +69,7 @@ extern int _getpid ( void ) ;
unsigned char *heap = (unsigned char *)&_end;
extern caddr_t _sbrk(int nbytes)
{
if (heap + nbytes < RAM_END-4096) {
if (heap + nbytes < RAM_END-_main_stack_size) {
unsigned char *prev_heap = heap;
heap += nbytes;
return (caddr_t) prev_heap;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,17 @@ LoopFillZerobss:
ldr r3, = _ebss
cmp r2, r3
bcc FillZerobss

/*Paint Main Stack */
ldr r2, = _main_stack_start
PaintMainStack:
movs r3, #0x55555555
str r3, [r2], #4
LoopPaintMainStack:
ldr r3, = _estack
cmp r2, r3
bcc PaintMainStack

/* Call the clock system intitialization function.*/
bl SystemInit
/* Call the application's entry point.*/
Expand Down
2 changes: 2 additions & 0 deletions radio/src/targets/taranis/stm32_flash_bl.ld
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ ENTRY(Reset_Handler)

/* Highest address of the user mode stack */
_estack = 0x20020000; /* end of 128K SRAM */
_main_stack_size = 0x2000; /*size of main stack*/
_main_stack_start = _estack - _main_stack_size;

/* Generate a link error if heap and stack don't fit into RAM */
_Min_Heap_Size = 0; /* required amount of heap */
Expand Down
3 changes: 3 additions & 0 deletions radio/src/targets/taranis/stm32_ramBoot.ld
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ ENTRY(Reset_Handler)

/* Highest address of the user mode stack */
_estack = 0x20020000; /* end of 128K SRAM */
_main_stack_size = 0x2000; /*size of main stack*/
_main_stack_start = _estack - _main_stack_size;


/* Generate a link error if heap and stack don't fit into RAM */
_Min_Heap_Size = 0; /* required amount of heap */
Expand Down

0 comments on commit a78c2b8

Please sign in to comment.