From 9a63e8c027ba6912f2a2eb093c71b3e29b5d5269 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philippe=20R=C3=A9tornaz?= Date: Thu, 23 Aug 2012 16:16:04 +0200 Subject: [PATCH] cc253x: Add stack monitoring helpers --- cpu/cc253x/soc.c | 30 ++++++++++++++++++++++++++++++ cpu/cc253x/soc.h | 3 +++ 2 files changed, 33 insertions(+) diff --git a/cpu/cc253x/soc.c b/cpu/cc253x/soc.c index 36d9531e4..94b3935e8 100644 --- a/cpu/cc253x/soc.c +++ b/cpu/cc253x/soc.c @@ -52,3 +52,33 @@ soc_init() ENABLE_INTERRUPTS(); } +#ifndef STACK_POISON +#define STACK_POISON 0xAA +#endif + +void +cc253x_stack_poison(void) +{ + __asm + mov r1, _SP +poison_loop: + inc r1 + mov @r1, #STACK_POISON + cjne r1, #0xFF, poison_loop + __endasm; +} + +uint8_t +cc253x_get_max_stack(void) +{ + __data uint8_t * sp = (__data uint8_t *) 0xff; + uint8_t free = 0; + + while(*sp-- == STACK_POISON) { + free++; + } + + return 0xff - free; +} + + diff --git a/cpu/cc253x/soc.h b/cpu/cc253x/soc.h index bcf858ba0..e4d4c855c 100644 --- a/cpu/cc253x/soc.h +++ b/cpu/cc253x/soc.h @@ -61,4 +61,7 @@ void soc_init(); +void cc253x_stack_poison(void); +uint8_t cc253x_get_max_stack(void); + #endif /* __SOC_H__ */