From b3de052e0135c6e54c5c04becedd2a3666d42b26 Mon Sep 17 00:00:00 2001 From: George Oikonomou Date: Mon, 2 Apr 2012 17:05:08 +0100 Subject: [PATCH] Ported the stack-friendly clock ISR code over from cc243x to cc253x --- cpu/cc253x/dev/clock.c | 9 +++++++++ platform/cc2530dk/contiki-conf.h | 8 ++++++++ platform/cc2530dk/contiki-main.c | 14 ++++++++++++++ 3 files changed, 31 insertions(+) diff --git a/cpu/cc253x/dev/clock.c b/cpu/cc253x/dev/clock.c index 937151dcf..c67b3a93b 100644 --- a/cpu/cc253x/dev/clock.c +++ b/cpu/cc253x/dev/clock.c @@ -47,6 +47,11 @@ /* One clock tick is 7.8 ms */ #define TICK_VAL (32768/128) /* 256 */ /*---------------------------------------------------------------------------*/ +#if CLOCK_CONF_STACK_FRIENDLY +volatile __bit sleep_flag; +#else +#endif +/*---------------------------------------------------------------------------*/ /* Do NOT remove the absolute address and do NOT remove the initialiser here */ __xdata __at(0x0000) static unsigned long timer_value = 0; @@ -158,10 +163,14 @@ clock_isr(void) __interrupt(ST_VECTOR) ++seconds; } +#if CLOCK_CONF_STACK_FRIENDLY + sleep_flag = 1; +#else if(etimer_pending() && (etimer_next_expiration_time() - count - 1) > MAX_TICKS) { etimer_request_poll(); } +#endif STIF = 0; /* IRCON.STIF */ ENERGEST_OFF(ENERGEST_TYPE_IRQ); diff --git a/platform/cc2530dk/contiki-conf.h b/platform/cc2530dk/contiki-conf.h index 647cb39b3..27d7317d5 100644 --- a/platform/cc2530dk/contiki-conf.h +++ b/platform/cc2530dk/contiki-conf.h @@ -10,6 +10,14 @@ #include "project-conf.h" #endif /* PROJECT_CONF_H */ +/* + * Define this as 1 to poll the etimer process from within main instead of from + * the clock ISR. This reduces the ISR's stack usage and may prevent crashes. + */ +#ifndef CLOCK_CONF_STACK_FRIENDLY +#define CLOCK_CONF_STACK_FRIENDLY 1 +#endif + /* Energest Module */ #ifndef ENERGEST_CONF_ON #define ENERGEST_CONF_ON 0 diff --git a/platform/cc2530dk/contiki-main.c b/platform/cc2530dk/contiki-main.c index bbf469dff..63d42eaab 100644 --- a/platform/cc2530dk/contiki-main.c +++ b/platform/cc2530dk/contiki-main.c @@ -45,6 +45,10 @@ PROCESS_NAME(viztool_process); #define PUTCHAR(...) do {} while(0) #endif /*---------------------------------------------------------------------------*/ +#if CLOCK_CONF_STACK_FRIENDLY +extern volatile __bit sleep_flag; +#endif +/*---------------------------------------------------------------------------*/ extern rimeaddr_t rimeaddr_node_addr; static __data int r; static __data int len; @@ -252,6 +256,16 @@ main(void) do { /* Reset watchdog and handle polls and events */ watchdog_periodic(); + +#if CLOCK_CONF_STACK_FRIENDLY + if(sleep_flag) { + if(etimer_pending() && + (etimer_next_expiration_time() - clock_time() - 1) > MAX_TICKS) { + etimer_request_poll(); + } + sleep_flag = 0; + } +#endif r = process_run(); } while(r > 0); len = NETSTACK_RADIO.pending_packet();