From dd26accc07b4c11c10674ffa8d54fb02add77461 Mon Sep 17 00:00:00 2001 From: George Oikonomou Date: Sun, 1 Apr 2012 20:07:53 +0100 Subject: [PATCH] We can now use SDCC's __nonbanked feature This allows us to reduce CODE footprint of SDCC projects built with --model-huge. Use carefully! * Added a facility which allows us to enable/disable the feature from the CPU dir (CC_CONF_NON_BANKED_OPTIMIZATION) * Added the CC_NON_BANKED keyword to some platform files (expands to __nonbanked) * Started using this for some examples --- cpu/cc2430/8051def.h | 7 +++++++ cpu/cc253x/8051def.h | 7 +++++++ .../sensinode/border-router/border-router.c | 10 ++++++---- platform/cc2530dk/contiki-main.c | 7 ++++--- platform/cc2530dk/viztool.c | 4 ++-- platform/sensinode/apps/batmon/batmon.c | 4 ++-- platform/sensinode/contiki-sensinode-main.c | 4 ++-- platform/sensinode/dev/m25p16.c | 8 ++++---- platform/sensinode/disco.c | 18 ++++++++++-------- platform/sensinode/viztool.c | 4 ++-- 10 files changed, 46 insertions(+), 27 deletions(-) diff --git a/cpu/cc2430/8051def.h b/cpu/cc2430/8051def.h index e8627ddc4..a1fa15e80 100644 --- a/cpu/cc2430/8051def.h +++ b/cpu/cc2430/8051def.h @@ -38,6 +38,13 @@ #define CC_CONF_UNSIGNED_CHAR_BUGS 0 #define CC_CONF_REGISTER_ARGS 0 #define CC_CONF_FUNCTION_POINTER_KEYWORD __reentrant +#define CC_CONF_NON_BANKED_OPTIMIZATION 1 + +#if (defined(__SDCC_mcs51) || defined(SDCC_mcs51)) && CC_CONF_NON_BANKED_OPTIMIZATION +#define CC_NON_BANKED __nonbanked +#else +#define CC_NON_BANKED +#endif /* Generic types. */ typedef unsigned short uip_stats_t; diff --git a/cpu/cc253x/8051def.h b/cpu/cc253x/8051def.h index e19fd8d31..7785d0bec 100644 --- a/cpu/cc253x/8051def.h +++ b/cpu/cc253x/8051def.h @@ -38,6 +38,13 @@ #define CC_CONF_UNSIGNED_CHAR_BUGS 0 #define CC_CONF_REGISTER_ARGS 0 #define CC_CONF_FUNCTION_POINTER_KEYWORD __reentrant +#define CC_CONF_NON_BANKED_OPTIMIZATION 1 + +#if (defined(__SDCC_mcs51) || defined(SDCC_mcs51)) && CC_CONF_NON_BANKED_OPTIMIZATION +#define CC_NON_BANKED __nonbanked +#else +#define CC_NON_BANKED +#endif /* Generic types. */ typedef unsigned short uip_stats_t; diff --git a/examples/sensinode/border-router/border-router.c b/examples/sensinode/border-router/border-router.c index a59ce6e0b..8c1e4952f 100644 --- a/examples/sensinode/border-router/border-router.c +++ b/examples/sensinode/border-router/border-router.c @@ -50,7 +50,7 @@ PROCESS(border_router_process, "Border Router process"); AUTOSTART_PROCESSES(&border_router_process); /*---------------------------------------------------------------------------*/ static void -print_local_addresses(void) +print_local_addresses(void) CC_NON_BANKED { int i; uint8_t state; @@ -70,8 +70,9 @@ print_local_addresses(void) } } /*---------------------------------------------------------------------------*/ -void -request_prefix(void) { +static void +request_prefix(void) CC_NON_BANKED +{ /* mess up uip_buf with a dirty request... */ uip_buf[0] = '?'; uip_buf[1] = 'P'; @@ -82,7 +83,8 @@ request_prefix(void) { /*---------------------------------------------------------------------------*/ /* Set our prefix when we receive one over SLIP */ void -set_prefix_64(uip_ipaddr_t *prefix_64) { +set_prefix_64(uip_ipaddr_t *prefix_64) +{ rpl_dag_t *dag; uip_ipaddr_t ipaddr; memcpy(&ipaddr, prefix_64, 16); diff --git a/platform/cc2530dk/contiki-main.c b/platform/cc2530dk/contiki-main.c index 23cb272c1..5767f3fe4 100644 --- a/platform/cc2530dk/contiki-main.c +++ b/platform/cc2530dk/contiki-main.c @@ -59,7 +59,7 @@ static unsigned long irq_energest = 0; #endif /*---------------------------------------------------------------------------*/ static void -fade(int l) +fade(int l) CC_NON_BANKED { volatile int i, a; int k, j; @@ -78,7 +78,7 @@ fade(int l) } /*---------------------------------------------------------------------------*/ static void -set_rime_addr(void) +set_rime_addr(void) CC_NON_BANKED { char i; @@ -136,10 +136,11 @@ set_rime_addr(void) #endif cc2530_rf_set_addr(IEEE802154_PANID); + return; } /*---------------------------------------------------------------------------*/ int -main(void) +main(void) CC_NON_BANKED { /* Hardware initialization */ clock_init(); diff --git a/platform/cc2530dk/viztool.c b/platform/cc2530dk/viztool.c index bfa354982..642cb2f5c 100644 --- a/platform/cc2530dk/viztool.c +++ b/platform/cc2530dk/viztool.c @@ -73,7 +73,7 @@ extern uip_ds6_nbr_t uip_ds6_nbr_cache[UIP_DS6_NBR_NB]; extern uip_ds6_defrt_t uip_ds6_defrt_list[UIP_DS6_DEFRT_NB]; /*---------------------------------------------------------------------------*/ static uint8_t -process_request() +process_request() CC_NON_BANKED { uint8_t len; uint8_t count; /* How many did we pack? */ @@ -251,7 +251,7 @@ process_request() PROCESS(viztool_process, "Network Visualization Tool Process"); /*---------------------------------------------------------------------------*/ static void -tcpip_handler(void) +tcpip_handler(void) CC_NON_BANKED { if(uip_newdata()) { memset(buf, 0, VIZTOOL_MAX_PAYLOAD_LEN); diff --git a/platform/sensinode/apps/batmon/batmon.c b/platform/sensinode/apps/batmon/batmon.c index 5f8797ef7..a4e59ab28 100644 --- a/platform/sensinode/apps/batmon/batmon.c +++ b/platform/sensinode/apps/batmon/batmon.c @@ -99,7 +99,7 @@ static struct etimer et; PROCESS(batmon_process, "Logger Process"); /*---------------------------------------------------------------------------*/ static int -find_gap() +find_gap() CC_NON_BANKED { uint8_t seq[3]; uint32_t address = FLASH_START_ADDR; @@ -124,7 +124,7 @@ find_gap() } /*---------------------------------------------------------------------------*/ static void -abort() +abort() CC_NON_BANKED { PRINTF("BatMon: Abort\n"); etimer_stop(&et); diff --git a/platform/sensinode/contiki-sensinode-main.c b/platform/sensinode/contiki-sensinode-main.c index 24862336a..905695526 100644 --- a/platform/sensinode/contiki-sensinode-main.c +++ b/platform/sensinode/contiki-sensinode-main.c @@ -72,7 +72,7 @@ static unsigned long irq_energest = 0; #endif /*---------------------------------------------------------------------------*/ static void -fade(int l) +fade(int l) CC_NON_BANKED { volatile int i, a; int k, j; @@ -91,7 +91,7 @@ fade(int l) } /*---------------------------------------------------------------------------*/ static void -set_rime_addr(void) +set_rime_addr(void) CC_NON_BANKED { uint8_t *addr_long = NULL; uint16_t addr_short = 0; diff --git a/platform/sensinode/dev/m25p16.c b/platform/sensinode/dev/m25p16.c index 5239dbf74..d842a3421 100644 --- a/platform/sensinode/dev/m25p16.c +++ b/platform/sensinode/dev/m25p16.c @@ -63,7 +63,7 @@ /*---------------------------------------------------------------------------*/ /* Bit-Bang write a byte to the chip */ static void -bit_bang_write(uint8_t byte) +bit_bang_write(uint8_t byte) CC_NON_BANKED { uint8_t i; uint8_t bit; @@ -85,7 +85,7 @@ bit_bang_write(uint8_t byte) /*---------------------------------------------------------------------------*/ /* Bit-Bang read a byte from the chip */ static uint8_t -bit_bang_read() +bit_bang_read() CC_NON_BANKED { int8_t i; uint8_t bits = 0; @@ -102,7 +102,7 @@ bit_bang_read() } /*---------------------------------------------------------------------------*/ static void -select() +select() CC_NON_BANKED { /* Read current ser/par value */ uint8_t ser_par = n740_ser_par_get(); @@ -116,7 +116,7 @@ select() } /*---------------------------------------------------------------------------*/ static void -deselect() +deselect() CC_NON_BANKED { /* Read current ser/par value */ uint8_t ser_par = n740_ser_par_get(); diff --git a/platform/sensinode/disco.c b/platform/sensinode/disco.c index 12c1146cb..39e023980 100644 --- a/platform/sensinode/disco.c +++ b/platform/sensinode/disco.c @@ -95,7 +95,7 @@ __xdata __at(BOOTTY_CMD_LOCATION) static uint8_t bd; static void timer_handler(void * p); /*---------------------------------------------------------------------------*/ static void -abort() +abort() CC_NON_BANKED { PRINTF("Disco: Abort @ %lu\n", clock_seconds()); n740_analog_deactivate(); @@ -108,7 +108,7 @@ abort() } /*---------------------------------------------------------------------------*/ static void -restart_timer(uint16_t t) +restart_timer(uint16_t t) CC_NON_BANKED { interval = t; ctimer_stop(&disco_timer); @@ -160,7 +160,9 @@ timer_handler(void * p) } } /*---------------------------------------------------------------------------*/ -static uint8_t is_protected(uint8_t a) { +static uint8_t +is_protected(uint8_t a) CC_NON_BANKED +{ uint8_t bp = M25P16_BP() >> 2; if(bp > 5) { @@ -176,7 +178,7 @@ static uint8_t is_protected(uint8_t a) { } /*---------------------------------------------------------------------------*/ static uint8_t -cmd_init() +cmd_init() CC_NON_BANKED { PRINTF("Disco: Init 0x%02x\n", req->addr[0]); if(uip_datalen() != DISCO_LEN_INIT) { @@ -209,7 +211,7 @@ cmd_init() } /*---------------------------------------------------------------------------*/ static uint8_t -cmd_write() +cmd_write() CC_NON_BANKED { PRINTF("Disco: Write 0x%02x%02x%02x\n", req->addr[0], req->addr[1], req->addr[2]); if(uip_datalen() != DISCO_LEN_WRITE) { @@ -228,7 +230,7 @@ cmd_write() } /*---------------------------------------------------------------------------*/ static uint8_t -cmd_switch() +cmd_switch() CC_NON_BANKED { PRINTF("Disco: Switch 0x%02x\n", req->addr[0]); if(uip_datalen() != DISCO_LEN_SWITCH) { @@ -253,7 +255,7 @@ cmd_switch() } /*---------------------------------------------------------------------------*/ static uint8_t -cmd_done() +cmd_done() CC_NON_BANKED { PRINTF("Disco: Done\n"); if(uip_datalen() != DISCO_LEN_DONE) { @@ -268,7 +270,7 @@ cmd_done() } /*---------------------------------------------------------------------------*/ static uint8_t -event_handler(process_event_t ev) +event_handler(process_event_t ev) CC_NON_BANKED { uint8_t rv = DISCO_RESPONSE_NONE; diff --git a/platform/sensinode/viztool.c b/platform/sensinode/viztool.c index bfa354982..642cb2f5c 100644 --- a/platform/sensinode/viztool.c +++ b/platform/sensinode/viztool.c @@ -73,7 +73,7 @@ extern uip_ds6_nbr_t uip_ds6_nbr_cache[UIP_DS6_NBR_NB]; extern uip_ds6_defrt_t uip_ds6_defrt_list[UIP_DS6_DEFRT_NB]; /*---------------------------------------------------------------------------*/ static uint8_t -process_request() +process_request() CC_NON_BANKED { uint8_t len; uint8_t count; /* How many did we pack? */ @@ -251,7 +251,7 @@ process_request() PROCESS(viztool_process, "Network Visualization Tool Process"); /*---------------------------------------------------------------------------*/ static void -tcpip_handler(void) +tcpip_handler(void) CC_NON_BANKED { if(uip_newdata()) { memset(buf, 0, VIZTOOL_MAX_PAYLOAD_LEN);