diff --git a/core/net/rime.h b/core/net/rime.h index 5cd296205..cfd36c6fe 100644 --- a/core/net/rime.h +++ b/core/net/rime.h @@ -94,7 +94,7 @@ extern const struct mac_driver *rime_mac; struct rime_sniffer { struct rime_sniffer *next; void (* input_callback)(void); - void (* output_callback)(void); + void (* output_callback)(int mac_status); }; #define RIME_SNIFFER(name, input_callback, output_callback) \ diff --git a/core/net/rime/rime.c b/core/net/rime/rime.c index 323743cff..08db5b8aa 100644 --- a/core/net/rime/rime.c +++ b/core/net/rime/rime.c @@ -151,7 +151,7 @@ static void packet_sent(void *ptr, int status, int num_tx) { struct channel *c = ptr; - + struct rime_sniffer *s; switch(status) { case MAC_TX_COLLISION: @@ -166,17 +166,14 @@ packet_sent(void *ptr, int status, int num_tx) default: PRINTF("rime: error %d after %d tx\n", status, num_tx); } - - if(status == MAC_TX_OK) { - struct rime_sniffer *s; - /* Call sniffers, but only if the packet was sent. */ - for(s = list_head(sniffers); s != NULL; s = list_item_next(s)) { - if(s->output_callback != NULL) { - s->output_callback(); - } + + /* Call sniffers, pass along the MAC status code. */ + for(s = list_head(sniffers); s != NULL; s = list_item_next(s)) { + if(s->output_callback != NULL) { + s->output_callback(status); } } - + abc_sent(c, status, num_tx); } /*---------------------------------------------------------------------------*/ diff --git a/core/net/rime/runicast.c b/core/net/rime/runicast.c index e03a881d1..946fef0e7 100644 --- a/core/net/rime/runicast.c +++ b/core/net/rime/runicast.c @@ -101,11 +101,12 @@ sent_by_stunicast(struct stunicast_conn *stunicast, int status, int num_tx) PRINTF("%d.%d: runicast: packet %d timed out\n", rimeaddr_node_addr.u8[0],rimeaddr_node_addr.u8[1], c->sndnxt); + c->sndnxt = (c->sndnxt + 1) % (1 << RUNICAST_PACKET_ID_BITS); } else { - int shift; +// int shift; - shift = c->rxmit > 4? 4: c->rxmit; - stunicast_set_timer(&c->c, (REXMIT_TIME) << shift); +// shift = c->rxmit > 4? 4: c->rxmit; +// stunicast_set_timer(&c->c, (REXMIT_TIME) << shift); } } } diff --git a/core/net/rime/stunicast.c b/core/net/rime/stunicast.c index 3309bfd64..554e81da0 100644 --- a/core/net/rime/stunicast.c +++ b/core/net/rime/stunicast.c @@ -113,9 +113,11 @@ send(void *ptr) PRINTF("%d.%d: stunicast: resend to %d.%d\n", rimeaddr_node_addr.u8[0],rimeaddr_node_addr.u8[1], c->receiver.u8[0], c->receiver.u8[1]); - queuebuf_to_packetbuf(c->buf); - unicast_send(&c->c, &c->receiver); - stunicast_set_timer(c, CLOCK_SECOND); + if(c->buf) { + queuebuf_to_packetbuf(c->buf); + unicast_send(&c->c, &c->receiver); + stunicast_set_timer(c, CLOCK_SECOND); + } /* if(c->u->sent != NULL) { c->u->sent(c); }*/ diff --git a/cpu/msp430/Makefile.msp430 b/cpu/msp430/Makefile.msp430 index 7ba93de7e..3c021700f 100644 --- a/cpu/msp430/Makefile.msp430 +++ b/cpu/msp430/Makefile.msp430 @@ -36,12 +36,13 @@ STRIP = strip ifndef IAR_PATH # This works with cygwin... -IAR_BIN_PATH = $(shell dirname `which $(CC)`) -IAR_PATH_C = $(shell dirname $(IAR_BIN_PATH)) -IAR_PATH = $(shell cygpath -m $(IAR_PATH_C)) +IAR_BIN_PATH = $(shell dirname "`which $(CC)`") +IAR_PATH_C = $(shell dirname "$(IAR_BIN_PATH)") +IAR_PATH = $(shell cygpath -m "$(IAR_PATH_C)") endif -CFLAGSNO = --dlib_config $(IAR_PATH)/LIB/DLIB/dl430xlfn.h -Ohz --multiplier=32 --multiplier_location=4C0 --hw_workaround=CPU40 --core=430X $(CFLAGSWERROR) --data_model large --double=32 +CFLAGSNO = --dlib_config "$(IAR_PATH)/LIB/DLIB/dl430xlfn.h" -Ohz --multiplier=32 --multiplier_location=4C0 --hw_workaround=CPU40 --core=430X $(CFLAGSWERROR) --data_model small --double=32 +# CFLAGSNO = --dlib_config $(IAR_PATH)/LIB/DLIB/dl430xlfn.h -Ohz --multiplier=32 --multiplier_location=4C0 --hw_workaround=CPU40 --core=430X $(CFLAGSWERROR) --data_model large --double=32 CUSTOM_RULE_C_TO_O = 1 %.o: %.c $(CC) $(CFLAGS) $< -o $@ @@ -55,7 +56,8 @@ CUSTOM_RULE_C_TO_CO = 1 $(CC) $(CFLAGS) -DAUTOSTART_ENABLE $< -o $@ AROPTS = -o -LDFLAGS += -B $(IAR_PATH)/lib/dlib/dl430xlfn.r43 -f $(IAR_PATH)/config/lnk430f5437.xcl -l contiki-$(TARGET).map -Fintel-extended -s __program_start +LDFLAGS += -B -xm "$(IAR_PATH)/lib/dlib/dl430xsfn.r43" -f "$(IAR_PATH)/config/lnk430f5437.xcl" -l contiki-$(TARGET).map -Fintel-extended -s __program_start -D_STACK_SIZE=80 -D_DATA16_HEAP_SIZE=80 -D_DATA20_HEAP_SIZE=80 + else GCC = 1 diff --git a/cpu/stm32w108/board-sensors.h b/cpu/stm32w108/board-sensors.h new file mode 100644 index 000000000..5c5fde709 --- /dev/null +++ b/cpu/stm32w108/board-sensors.h @@ -0,0 +1,25 @@ +/** + * \file + * Declarations for sensor-related functions that are + * common to all stm32w platforms. + * + * + * \author Salvatore Pitrulli + */ + + +/** + * Remember state of sensors (if active or not), in order to + * resume their original state after calling powerUpSensors(). + * Useful when entering in sleep mode, since all system + * peripherals have to be reinitialized. + */ +void sensorsPowerDown(); + +/** + * Resume the state of all on-board sensors on to the state + * that they had when sensorsPowerDown() was called. + * Useful when sensors have to be used after the micro was put + * in deep sleep mode. + */ +void sensorsPowerUp(); diff --git a/cpu/stm32w108/hal/micro/cortexm3/board.c b/cpu/stm32w108/hal/micro/cortexm3/board.c index 45586909f..456be9b40 100644 --- a/cpu/stm32w108/hal/micro/cortexm3/board.c +++ b/cpu/stm32w108/hal/micro/cortexm3/board.c @@ -314,7 +314,7 @@ void halBoardPowerDown(void) (GPIOCFG_IN <io->buttons; @@ -324,9 +324,23 @@ void halBoardPowerDown(void) halGpioSet(PORTx_PIN(buttons[i].gpioPort, buttons[i].gpioPin), GPIOOUT_PULLUP); } } -#endif + + /* Configure GPIO for LEDs */ + { + LedResourceType *leds = (LedResourceType *) boardDescription->io->leds; + int8u i; + for (i = 0; i < boardDescription->leds; i++) { + /* LED default off */ + halGpioConfig(PORTx_PIN(leds[i].gpioPort, leds[i].gpioPin), GPIOCFG_OUT); + halGpioSet(PORTx_PIN(leds[i].gpioPort, leds[i].gpioPin), 1); + } + } + /* Configure GPIO for power amplifier */ if (boardDescription->flags & BOARD_HAS_PA) { + /* SiGe Ant Sel to output */ + halGpioConfig(PORTB_PIN(5), GPIOCFG_OUT); + halGpioSet(PORTB_PIN(5), 1); /* SiGe Standby */ halGpioConfig(PORTB_PIN(6), GPIOCFG_OUT); halGpioSet(PORTB_PIN(6), 0); diff --git a/examples/mb851/udp-ipv6-sleep/udp-client.c b/examples/mb851/udp-ipv6-sleep/udp-client.c index dfae03ddc..73518dadb 100644 --- a/examples/mb851/udp-ipv6-sleep/udp-client.c +++ b/examples/mb851/udp-ipv6-sleep/udp-client.c @@ -32,7 +32,7 @@ #include "contiki-net.h" #include "sleep.h" -#include "board-mb851.h" +#include "board-sensors.h" #include diff --git a/platform/mb851/board-mb851.c b/platform/mb851/board-mb851.c index 4a8529869..138c32e6a 100644 --- a/platform/mb851/board-mb851.c +++ b/platform/mb851/board-mb851.c @@ -6,6 +6,7 @@ #include "dev/button-sensor.h" #include "dev/temperature-sensor.h" #include "dev/acc-sensor.h" +#include "dev/leds.h" void halBoardInit(void) { diff --git a/platform/mb851/board-mb851.h b/platform/mb851/board-mb851.h deleted file mode 100644 index 3731a2373..000000000 --- a/platform/mb851/board-mb851.h +++ /dev/null @@ -1,4 +0,0 @@ - -void sensorsPowerDown(); - -void sensorsPowerUp(); diff --git a/platform/mbxxx/Makefile.mbxxx b/platform/mbxxx/Makefile.mbxxx index 2403f2d70..e100e2991 100644 --- a/platform/mbxxx/Makefile.mbxxx +++ b/platform/mbxxx/Makefile.mbxxx @@ -4,7 +4,7 @@ ARCH= irq.c sensors.c acc-sensor.c button-sensor.c temperature-sensor.c mems.c CONTIKI_TARGET_DIRS = . dev ifndef CONTIKI_TARGET_MAIN -CONTIKI_TARGET_MAIN = contiki-main.c led.c button.c board.c +CONTIKI_TARGET_MAIN = contiki-main.c led.c button.c board.c board-mbxxx.c endif ifdef UIP_CONF_IPV6 diff --git a/platform/mbxxx/board-mbxxx.c b/platform/mbxxx/board-mbxxx.c new file mode 100644 index 000000000..db008df86 --- /dev/null +++ b/platform/mbxxx/board-mbxxx.c @@ -0,0 +1,54 @@ +/*#include PLATFORM_HEADER +#include BOARD_HEADER +#include "hal/micro/micro-common.h" +#include "hal/micro/cortexm3/micro-common.h"*/ + +#include "dev/button-sensor.h" +#include "dev/temperature-sensor.h" +#include "dev/acc-sensor.h" + +static uint8_t sensors_status; + +#define BUTTON_STATUS_ACTIVE (1 << 0) +#define TEMP_STATUS_ACTIVE (1 << 1) +#define ACC_STATUS_ACTIVE (1 << 2) + +/* Remember state of sensors (if active or not), in order to + * resume their original state after calling powerUpSensors(). + * Useful when entering in sleep mode, since all system + * peripherals have to be reinitialized. */ + +void sensorsPowerDown(){ + + sensors_status = 0; + + if(button_sensor.status(SENSORS_READY)){ + sensors_status |= BUTTON_STATUS_ACTIVE; + } + if(temperature_sensor.status(SENSORS_READY)){ + sensors_status |= TEMP_STATUS_ACTIVE; + } + if(acc_sensor.status(SENSORS_READY)){ + sensors_status |= ACC_STATUS_ACTIVE; + // Power down accelerometer to save power + SENSORS_DEACTIVATE(acc_sensor); + } +} + +/**/ +void sensorsPowerUp(){ + + button_sensor.configure(SENSORS_HW_INIT, 0); + temperature_sensor.configure(SENSORS_HW_INIT, 0); + acc_sensor.configure(SENSORS_HW_INIT, 0); + + if(sensors_status & BUTTON_STATUS_ACTIVE){ + SENSORS_ACTIVATE(button_sensor); + } + if(sensors_status & TEMP_STATUS_ACTIVE){ + SENSORS_ACTIVATE(temperature_sensor); + } + if(sensors_status & ACC_STATUS_ACTIVE){ + SENSORS_ACTIVATE(acc_sensor); + } +} diff --git a/platform/mbxxx/clock.c b/platform/mbxxx/clock.c index 76cfa4bf6..5128f639a 100644 --- a/platform/mbxxx/clock.c +++ b/platform/mbxxx/clock.c @@ -52,6 +52,12 @@ #include "sys/clock.h" #include "sys/etimer.h" #include "dev/button-sensor.h" +#include "uart1.h" +#include "dev/leds.h" +#include "dev/stm32w-radio.h" + +#define DEBUG DEBUG_NONE +#include "net/uip-debug.h" // The value that will be load in the SysTick value register. #define RELOAD_VALUE 24000-1 // 1 ms with a 24 MHz clock @@ -86,7 +92,7 @@ void SysTick_Handler(void) void clock_init(void) { - INTERRUPTS_OFF(); + ATOMIC( //Counts the number of ticks. count = 0; @@ -96,7 +102,7 @@ void clock_init(void) SysTick_ITConfig(ENABLE); SysTick_CounterCmd(SysTick_Counter_Enable); - INTERRUPTS_ON(); + ) } /*---------------------------------------------------------------------------*/ @@ -137,3 +143,49 @@ unsigned long clock_seconds(void) { return current_seconds; } + +void sleep_seconds(int seconds) +{ + int32u quarter_seconds = seconds * 4; + uint8_t radio_on; + + + halPowerDown(); + radio_on = stm32w_radio_is_on(); + stm32w_radio_driver.off(); + + halSleepForQsWithOptions(&quarter_seconds, 0); + + + ATOMIC( + + halPowerUp(); + + // Update OS system ticks. + current_seconds += seconds - quarter_seconds / 4 ; // Passed seconds + count += seconds * CLOCK_SECOND - quarter_seconds * CLOCK_SECOND / 4 ; + + if(etimer_pending()) { + etimer_request_poll(); + } + + SysTick_CLKSourceConfig(SysTick_CLKSource_HCLK); + SysTick_SetReload(RELOAD_VALUE); + SysTick_ITConfig(ENABLE); + SysTick_CounterCmd(SysTick_Counter_Enable); + + ) + + stm32w_radio_driver.init(); + if(radio_on){ + stm32w_radio_driver.on(); + } + + uart1_init(115200); + leds_init(); + rtimer_init(); + + PRINTF("WakeInfo: %04x\r\n", halGetWakeInfo()); + + +}