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.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()); + + +}