Added functions and example for deep sleep on mb851.

The added function let a process to make the system go
into deep sleep for maximum power saving.
The udp-ipv6-example shows how to use these new functions.
This commit is contained in:
Salvatore Pitrulli 2011-04-08 11:38:16 +00:00
parent 5a4a39afb3
commit 6655c876f2
11 changed files with 483 additions and 16 deletions

View file

@ -18,7 +18,7 @@ CONTIKI_CPU_DIRS = . dev hal simplemac hal/micro/cortexm3 hal/micro/cortexm3/stm
STM32W_C = leds-arch.c leds.c clock.c watchdog.c uart1.c uart1-putchar.c slip_uart1.c slip.c\
stm32w-radio.c stm32w_systick.c uip_arch.c rtimer-arch.c adc.c micro.c sleep.c \
micro-common.c micro-common-internal.c clocks.c mfg-token.c nvm.c flash.c rand.c
micro-common.c micro-common-internal.c clocks.c mfg-token.c nvm.c flash.c rand.c system-timer.c
STM32W_S = spmr.s79 context-switch.s79

View file

@ -45,8 +45,14 @@
#include "hal/hal.h"
#include "dev/stm32w_systick.h"
#include "sys/clock.h"
#include "sys/etimer.h"
#include "contiki.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
@ -77,9 +83,9 @@ void SysTick_Handler(void)
void clock_init(void)
{
INTERRUPTS_OFF();
//Counts the number of ticks.
ATOMIC(
//Counts the number of ticks.
count = 0;
SysTick_CLKSourceConfig(SysTick_CLKSource_HCLK);
@ -87,7 +93,8 @@ void clock_init(void)
SysTick_ITConfig(ENABLE);
SysTick_CounterCmd(SysTick_Counter_Enable);
INTERRUPTS_ON();
)
}
/*---------------------------------------------------------------------------*/
@ -128,3 +135,51 @@ unsigned long clock_seconds(void)
{
return current_seconds;
}
#include <stdio.h>
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());
}

View file

@ -395,7 +395,11 @@ static int stm32w_radio_on(void)
return 1;
}
/*---------------------------------------------------------------------------*/
int stm32w_radio_is_on(void)
{
return onoroff == ON;
}
/*---------------------------------------------------------------------------*/
@ -512,7 +516,7 @@ PROCESS_THREAD(stm32w_radio_process, ev, data)
NETSTACK_RDC.input();
}
if(!RXBUFS_EMPTY()){
// Some data packet still in rx buffer (this appens because process_poll doesn't queue requests),
// Some data packet still in rx buffer (this happens because process_poll doesn't queue requests),
// so stm32w_radio_process need to be called again.
process_poll(&stm32w_radio_process);
}

View file

@ -53,5 +53,7 @@ short last_packet_rssi();
extern const struct radio_driver stm32w_radio_driver;
int stm32w_radio_is_on(void);
#endif /* __STM32W_H__ */

10
cpu/stm32w108/sleep.h Normal file
View file

@ -0,0 +1,10 @@
/* Enter system in deep sleep 1 (core power domain is fully
* powered down and sleep timer is active).
* Execution is suspended for a given number of seconds.
*
* Pay attention! All system peripherals (including sensors) have
* to be reinitialized before being used again. UART, LEDs and
* real timers are automatically reinitialized. */
void sleep_seconds(int seconds);