Added functions for deep sleep to mbxxx platform.

This commit is contained in:
Salvatore Pitrulli 2011-04-27 14:45:44 +02:00
parent 4b5d380c74
commit 5eabf33211
7 changed files with 151 additions and 10 deletions

View file

@ -0,0 +1,25 @@
/**
* \file
* Declarations for sensor-related functions that are
* common to all stm32w platforms.
*
*
* \author Salvatore Pitrulli <salvopitru@users.sourceforge.net>
*/
/**
* 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();

View file

@ -314,7 +314,7 @@ void halBoardPowerDown(void)
(GPIOCFG_IN <<PC7_CFG_BIT); /* OSC32K */
#endif
#ifdef EMBERZNET_HAL
/* Configure GPIO for BUTTONSs */
{
ButtonResourceType *buttons = (ButtonResourceType *) boardDescription->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);

View file

@ -32,7 +32,7 @@
#include "contiki-net.h"
#include "sleep.h"
#include "board-mb851.h"
#include "board-sensors.h"
#include <string.h>

View file

@ -1,4 +0,0 @@
void sensorsPowerDown();
void sensorsPowerUp();

View file

@ -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

View file

@ -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);
}
}

View file

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