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:
parent
5a4a39afb3
commit
6655c876f2
11 changed files with 483 additions and 16 deletions
|
@ -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());
|
||||
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue