From c6ec22c4c867dce60b52cf625326bd671473404a Mon Sep 17 00:00:00 2001 From: George Oikonomou Date: Wed, 5 Sep 2012 16:00:23 +0100 Subject: [PATCH] cc2530: Added a method to maximise stack depth This was oringinally contributed/reported/discussed/patched by Philippe Retornaz (EPFL) but it's implemented in a more configurable fashion here. --- cpu/cc253x/8051def.h | 20 ++++++++++++++++++++ cpu/cc253x/dev/cc2530-rf.c | 2 +- cpu/cc253x/dev/clock.c | 10 ++++++++-- cpu/cc253x/dev/dma_intr.c | 6 ++++++ cpu/cc253x/dev/uart-intr.c | 12 ++++++++++++ cpu/cc253x/rtimer-arch.c | 6 ++++++ platform/cc2530dk/contiki-main.c | 2 +- platform/cc2530dk/dev/button-sensor.c | 8 +++++++- 8 files changed, 61 insertions(+), 5 deletions(-) diff --git a/cpu/cc253x/8051def.h b/cpu/cc253x/8051def.h index 72945ca31..2e1d92fd2 100644 --- a/cpu/cc253x/8051def.h +++ b/cpu/cc253x/8051def.h @@ -56,6 +56,26 @@ #define CC_NON_BANKED #endif +/* + * Max Stack Depth manipulation. It is possible to get up to 247 bytes + * allocated for the stack if: + * - You set this to 1 and + * - You have a patched toolchain and + * - You don't use __bit variables + * - You do not link libraries using BIT registers (e.g. printf_large) + * Enabling this will mean ISRs will NOT push bits (#pragma exclude bits) so + * make sure you know what you're doing + * + * More information on the wiki + */ +#define CC_CONF_OPTIMIZE_STACK_SIZE 0 + +#if CC_CONF_OPTIMIZE_STACK_SIZE +#define CC_AT_DATA +#else +#define CC_AT_DATA __data +#endif + /* Generic types. */ typedef unsigned short uip_stats_t; diff --git a/cpu/cc253x/dev/cc2530-rf.c b/cpu/cc253x/dev/cc2530-rf.c index b590b7f2d..5c16d099d 100644 --- a/cpu/cc253x/dev/cc2530-rf.c +++ b/cpu/cc253x/dev/cc2530-rf.c @@ -107,7 +107,7 @@ static const uint8_t magic[] = { 0x53, 0x6E, 0x69, 0x66 }; /* Snif */ #define CC2530_RF_AUTOACK 1 #endif /*---------------------------------------------------------------------------*/ -static uint8_t __data rf_flags; +static uint8_t CC_AT_DATA rf_flags; static int on(void); /* prepare() needs our prototype */ static int off(void); /* transmit() needs our prototype */ diff --git a/cpu/cc253x/dev/clock.c b/cpu/cc253x/dev/clock.c index a2d43987b..e91fcb962 100644 --- a/cpu/cc253x/dev/clock.c +++ b/cpu/cc253x/dev/clock.c @@ -55,8 +55,8 @@ volatile uint8_t sleep_flag; /* Do NOT remove the absolute address and do NOT remove the initialiser here */ __xdata __at(0x0000) static unsigned long timer_value = 0; -static volatile __data clock_time_t count = 0; /* Uptime in ticks */ -static volatile __data clock_time_t seconds = 0; /* Uptime in secs */ +static volatile CC_AT_DATA clock_time_t count = 0; /* Uptime in ticks */ +static volatile CC_AT_DATA clock_time_t seconds = 0; /* Uptime in secs */ /*---------------------------------------------------------------------------*/ /** * Each iteration is ~1.0xy usec, so this function delays for roughly len usec @@ -132,6 +132,11 @@ clock_init(void) STIE = 1; /* IEN0.STIE interrupt enable */ } /*---------------------------------------------------------------------------*/ +/* avoid referencing bits, we don't call code which use them */ +#pragma save +#if CC_CONF_OPTIMIZE_STACK_SIZE +#pragma exclude bits +#endif void clock_isr(void) __interrupt(ST_VECTOR) { @@ -177,4 +182,5 @@ clock_isr(void) __interrupt(ST_VECTOR) ENERGEST_OFF(ENERGEST_TYPE_IRQ); ENABLE_INTERRUPTS(); } +#pragma restore /*---------------------------------------------------------------------------*/ diff --git a/cpu/cc253x/dev/dma_intr.c b/cpu/cc253x/dev/dma_intr.c index 9f2336293..222a9f3ae 100644 --- a/cpu/cc253x/dev/dma_intr.c +++ b/cpu/cc253x/dev/dma_intr.c @@ -32,6 +32,11 @@ extern void spi_rx_dma_callback(void); * * if callback defined a poll is made to that process */ +/* Avoid referencing bits, we don't call code which use them */ +#pragma save +#if CC_CONF_OPTIMIZE_STACK_SIZE +#pragma exclude bits +#endif void dma_isr(void) __interrupt (DMA_VECTOR) { @@ -65,4 +70,5 @@ dma_isr(void) __interrupt (DMA_VECTOR) #endif EA = 1; } +#pragma restore /*---------------------------------------------------------------------------*/ diff --git a/cpu/cc253x/dev/uart-intr.c b/cpu/cc253x/dev/uart-intr.c index b70acfb03..ebe1814c1 100644 --- a/cpu/cc253x/dev/uart-intr.c +++ b/cpu/cc253x/dev/uart-intr.c @@ -33,6 +33,11 @@ uart0_set_input(int (*input)(unsigned char c)) } /*---------------------------------------------------------------------------*/ #if UART0_CONF_WITH_INPUT +/* avoid referencing bits since we're not using them */ +#pragma save +#if CC_CONF_OPTIMIZE_STACK_SIZE +#pragma exclude bits +#endif void uart0_rx_isr(void) __interrupt (URX0_VECTOR) { @@ -44,6 +49,7 @@ uart0_rx_isr(void) __interrupt (URX0_VECTOR) } ENERGEST_OFF(ENERGEST_TYPE_IRQ); } +#pragma restore #endif #endif /* UART0_ENABLE */ #if UART1_ENABLE @@ -55,6 +61,11 @@ uart1_set_input(int (*input)(unsigned char c)) } /*---------------------------------------------------------------------------*/ #if UART_ONE_CONF_WITH_INPUT +/* avoid referencing bits since we're not using them */ +#pragma save +#if CC_CONF_OPTIMIZE_STACK_SIZE +#pragma exclude bits +#endif void uart1_rx_isr(void) __interrupt (URX1_VECTOR) { @@ -65,6 +76,7 @@ uart1_rx_isr(void) __interrupt (URX1_VECTOR) } ENERGEST_OFF(ENERGEST_TYPE_IRQ); } +#pragma restore /*---------------------------------------------------------------------------*/ #endif /* UART_ONE_CONF_WITH_INPUT */ #endif /* UART1_ENABLE */ diff --git a/cpu/cc253x/rtimer-arch.c b/cpu/cc253x/rtimer-arch.c index 01512a724..6bf4405ca 100644 --- a/cpu/cc253x/rtimer-arch.c +++ b/cpu/cc253x/rtimer-arch.c @@ -96,6 +96,11 @@ rtimer_arch_schedule(rtimer_clock_t t) T1CCTL1 |= T1CCTL_IM; } /*---------------------------------------------------------------------------*/ +/* avoid referencing bits, we don't call code which use them */ +#pragma save +#if CC_CONF_OPTIMIZE_STACK_SIZE +#pragma exclude bits +#endif void rtimer_isr(void) __interrupt(T1_VECTOR) { @@ -111,3 +116,4 @@ rtimer_isr(void) __interrupt(T1_VECTOR) ENERGEST_OFF(ENERGEST_TYPE_IRQ); T1IE = 1; /* Acknowledge Timer 1 Interrupts */ } +#pragma restore diff --git a/platform/cc2530dk/contiki-main.c b/platform/cc2530dk/contiki-main.c index b10238286..83a6480ed 100644 --- a/platform/cc2530dk/contiki-main.c +++ b/platform/cc2530dk/contiki-main.c @@ -44,6 +44,7 @@ extern volatile uint8_t sleep_flag; #endif /*---------------------------------------------------------------------------*/ extern rimeaddr_t rimeaddr_node_addr; +static CC_AT_DATA uint16_t len; /*---------------------------------------------------------------------------*/ #if ENERGEST_CONF_ON static unsigned long irq_energest = 0; @@ -260,7 +261,6 @@ main(void) CC_NON_BANKED while(1) { uint8_t r; - static uint16_t len; do { /* Reset watchdog and handle polls and events */ watchdog_periodic(); diff --git a/platform/cc2530dk/dev/button-sensor.c b/platform/cc2530dk/dev/button-sensor.c index 7ab7a3dd7..c1a6f593c 100644 --- a/platform/cc2530dk/dev/button-sensor.c +++ b/platform/cc2530dk/dev/button-sensor.c @@ -36,7 +36,7 @@ #include "dev/button-sensor.h" #include "dev/watchdog.h" /*---------------------------------------------------------------------------*/ -static __data struct timer debouncetimer; +static CC_AT_DATA struct timer debouncetimer; /*---------------------------------------------------------------------------*/ /* Button 1 - SmartRF and cc2531 USB Dongle */ /*---------------------------------------------------------------------------*/ @@ -133,6 +133,11 @@ int configure_b2(int type, int value) /*---------------------------------------------------------------------------*/ /* ISRs */ /*---------------------------------------------------------------------------*/ +/* avoid referencing bits, we don't call code which use them */ +#pragma save +#if CC_CONF_OPTIMIZE_STACK_SIZE +#pragma exclude bits +#endif #if MODEL_CC2531 void port_1_isr(void) __interrupt(P1INT_VECTOR) @@ -187,6 +192,7 @@ port_0_isr(void) __interrupt(P0INT_VECTOR) EA = 1; } #endif +#pragma restore /*---------------------------------------------------------------------------*/ SENSORS_SENSOR(button_1_sensor, BUTTON_SENSOR, value_b1, configure_b1, status_b1); #if MODEL_CC2531