/** @file hal/micro/cortexm3/sleep.c
*
* @brief STM32W108 micro specific sleep functions.
*
* <!--(C) COPYRIGHT 2010 STMicroelectronics. All rights reserved. -->
*/
#include PLATFORM_HEADER
#include "hal/micro/micro-common.h"
#include "hal/micro/cortexm3/micro-common.h"
//We don't have a real register to hold this composite information.
//Pretend we do so halGetWakeInfo can operate like halGetResetInfo.
//This "register" is only ever set by halInternalSleep.
// [31] = WakeInfoValid
// [30] = SleepSkipped
// [29] = CSYSPWRUPREQ
// [28] = CDBGPWRUPREQ
// [27] = WAKE_CORE
// [26] = TIMER_WAKE_WRAP
// [25] = TIMER_WAKE_COMPB
// [24] = TIMER_WAKE_COMPA
// [23:0] = corresponding GPIO activity
#define WAKEINFOVALID_INTERNAL_WAKE_EVENT_BIT 31
#define SLEEPSKIPPED_INTERNAL_WAKE_EVENT_BIT 30
#define CSYSPWRUPREQ_INTERNAL_WAKE_EVENT_BIT 29
#define CDBGPWRUPREQ_INTERNAL_WAKE_EVENT_BIT 28
#define WAKE_CORE_INTERNAL_WAKE_EVENT_BIT 27
#define WRAP_INTERNAL_WAKE_EVENT_BIT 26
#define CMPB_INTERNAL_WAKE_EVENT_BIT 25
#define CMPA_INTERNAL_WAKE_EVENT_BIT 24
//This define shifts events from the PWRUP_EVENT register into the proper
//place in the halInternalWakeEvent variable
#define INTERNAL_WAKE_EVENT_BIT_SHIFT 20
static int32u halInternalWakeEvent=0;
int32u halGetWakeInfo(void)
{
return halInternalWakeEvent;
}
//forceSleepTmrCnt is a flag indicating that the system timer module
//should force a fake value for SLEEPTMR_CNT whenever the timer is
//accessed. For FogBugz 11909/11920 workaround.
boolean forceSleepTmrCnt = FALSE;
//wakeupSleepTmrCnt is a capturing of the SLEEPTMR_CNT immediately upon
//waking up from deep sleep. This value is used to know when the counter
//has ticked forward. For FogBugz 11909/11920 workaround.
int32u wakeupSleepTmrCnt = 0;
void halInternalSleep(SleepModes sleepMode)
{
//Timer restoring always takes place during the wakeup sequence. We save
//the state here in case SLEEPMODE_NOTIMER is invoked, which would disable
//the clocks.
int32u SLEEPTMR_CLKEN_SAVED = SLEEPTMR_CLKEN;
//This code assumes all wake source registers are properly configured.
//As such, it should be called from halSleepWithOptions() or from
// halSleepForQsWithOptions() which configues the wake sources.
//The parameter gpioWakeSel is a bitfield composite of the GPIO wake
//sources derived from the 3 ports, indicating which of the 24 GPIO
//are configured as a wake source.
int32u gpioWakeSel = (GPIO_PAWAKE<<0);
gpioWakeSel |= (GPIO_PBWAKE<<8);
gpioWakeSel |= (GPIO_PCWAKE<<16);
//PB2 is also WAKE_SC1. Set this wake source if PB2's GPIO wake is set.
if(GPIO_PBWAKE & PB2) {
WAKE_SEL |= WAKE_SC1;
}
//PA2 is also WAKE_SC2. Set this wake source if PA2's GPIO wake is set.
if(GPIO_PAWAKE & PA2) {
WAKE_SEL |= WAKE_SC2;
}
//The WAKE_IRQD source can come from any pin based on IRQD's sel register.
if(gpioWakeSel & BIT(GPIO_IRQDSEL)) {
WAKE_SEL |= WAKE_IRQD;
}
halInternalWakeEvent = 0; //clear old wake events
switch(sleepMode)
{
case SLEEPMODE_NOTIMER:
//The sleep timer clock sources (both RC and XTAL) are turned off.
//Wakeup is possible from only GPIO. System time is lost.
//NOTE: Timer restoring always takes place during the wakeup sequence.
SLEEPTMR_CLKEN = 0;
goto deepSleepCore;
case SLEEPMODE_WAKETIMER:
//The sleep timer clock sources remain running. The RC is always
//running and the 32kHz XTAL depends on the board header. Wakeup
//is possible from both GPIO and the sleep timer. System time
//is maintained. The sleep timer is assumed to be configured
//properly for wake events.
//NOTE: This mode assumes the caller has configured the *entire*
// sleep timer properly.
if(INT_SLEEPTMRCFG&INT_SLEEPTMRWRAP) {
WAKE_SEL |= WAKE_SLEEPTMRWRAP;
}
if(INT_SLEEPTMRCFG&INT_SLEEPTMRCMPB) {
WAKE_SEL |= WAKE_SLEEPTMRCMPB;
}
if(INT_SLEEPTMRCFG&INT_SLEEPTMRCMPA) {
WAKE_SEL |= WAKE_SLEEPTMRCMPA;
}
//fall into SLEEPMODE_MAINTAINTIMER's sleep code:
case SLEEPMODE_MAINTAINTIMER:
//The sleep timer clock sources remain running. The RC is always
//running and the 32kHz XTAL depends on the board header. Wakeup
//is possible from only GPIO. System time is maintained.
//NOTE: System time is maintained without any sleep timer interrupts
// because the hardware sleep timer counter is large enough
// to hold the entire count value and not need a RAM counter.
////////////////////////////////////////////////////////////////////////////
// Core deep sleep code
////////////////////////////////////////////////////////////////////////////
deepSleepCore:
// Interrupts *must* be/stay disabled for DEEP SLEEP operation
// INTERRUPTS_OFF will use BASEPRI to disable all interrupts except
// fault handlers and PendSV.
INTERRUPTS_OFF();
// This is the point of no return. From here on out, only the interrupt
// sources available in WAKE_SEL will be captured and propagated across
// deep sleep.
//stick all our saved info onto stack since it's only temporary
{
boolean restoreWatchdog = halInternalWatchDogEnabled();
boolean skipSleep = FALSE;
// Only three register blocks keep power across deep sleep:
// CM_HV, GPIO, SLOW_TIMERS
//
// All other register blocks lose their state across deep sleep:
// BASEBAND, MAC, SECURITY, SERIAL, TMR1, TMR2, EVENT, CM_LV, RAM_CTRL,
// AUX_ADC, CAL_ADC, FLASH_CONTROL, ITM, DWT, FPB, NVIC, TPIU
//
// The sleep code will only save and restore registers where it is
// meaningful and necessary to do so. In most cases, there must still
// be a powerup function to restore proper state.
//
// NOTE: halPowerUp() and halPowerDown() will always be called before
// and after this function. halPowerDown and halPowerUp should leave
// the modules in a safe state and then restart the modules.
// (For example, shutting down and restarting Timer1)
//
//----BASEBAND
// reinitialized by stStackPowerUp()
//----MAC
// reinitialized by stStackPowerUp()
//----SECURITY
// reinitialized by stStackPowerUp()
//----SERIAL
// reinitialized by halPowerUp() or similar
//----TMR1
// reinitialized by halPowerUp() or similar
//----TMR2
// reinitialized by halPowerUp() or similar
//----EVENT
//SRC or FLAG interrupts are not saved or restored
//MISS interrupts are not saved or restored
//MAC_RX_INT_MASK - reinitialized by stStackPowerUp()
//MAC_TX_INT_MASK - reinitialized by stStackPowerUp()
//MAC_TIMER_INT_MASK - reinitialized by stStackPowerUp()
//BB_INT_MASK - reinitialized by stStackPowerUp()
//SEC_INT_MASK - reinitialized by stStackPowerUp()
int32u INT_SLEEPTMRCFG_SAVED = INT_SLEEPTMRCFG_REG;
int32u INT_MGMTCFG_SAVED = INT_MGMTCFG_REG;
//INT_TIM1CFG - reinitialized by halPowerUp() or similar
//INT_TIM2CFG - reinitialized by halPowerUp() or similar
//INT_SC1CFG - reinitialized by halPowerUp() or similar
//INT_SC2CFG - reinitialized by halPowerUp() or similar
//INT_ADCCFG - reinitialized by halPowerUp() or similar
int32u GPIO_INTCFGA_SAVED = GPIO_INTCFGA_REG;
int32u GPIO_INTCFGB_SAVED = GPIO_INTCFGB_REG;
int32u GPIO_INTCFGC_SAVED = GPIO_INTCFGC_REG;
int32u GPIO_INTCFGD_SAVED = GPIO_INTCFGD_REG;
//SC1_INTMODE - reinitialized by halPower
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
STM32W demo程序 (173个子文件)
simplemac-library.a 111KB
libsimplemac-library-gnu.a 69KB
tx.cspy.bat 2KB
rx.cspy.bat 2KB
tx.cspy.bat 1KB
tx.pbd.browse 4.71MB
rx.pbd.browse 4.69MB
sleep.c 35KB
clocks.c 32KB
crt_stm32w108.c 18KB
micro-common-internal.c 14KB
board.c 14KB
nvm.c 13KB
flash.c 13KB
adc.c 11KB
low_level_init.c 11KB
system-timer.c 10KB
mems.c 9KB
uart.c 7KB
micro.c 5KB
App.c 4KB
micro-common.c 4KB
App.c 4KB
mfg-token.c 3KB
temperature_sensor.c 2KB
led.c 1KB
button.c 1KB
low_level_init.pbi.cout 11KB
low_level_init.pbi.cout 11KB
micro-common-internal.pbi.cout 11KB
micro-common-internal.pbi.cout 11KB
micro-common.pbi.cout 11KB
micro-common.pbi.cout 11KB
mfg-token.pbi.cout 11KB
mfg-token.pbi.cout 11KB
clocks.pbi.cout 11KB
clocks.pbi.cout 11KB
micro.pbi.cout 11KB
flash.pbi.cout 11KB
micro.pbi.cout 11KB
flash.pbi.cout 11KB
uart.pbi.cout 11KB
uart.pbi.cout 11KB
adc.pbi.cout 11KB
nvm.pbi.cout 11KB
nvm.pbi.cout 11KB
adc.pbi.cout 11KB
App.pbi.cout 11KB
App.pbi.cout 11KB
tx.dbgdt 11KB
rx.dbgdt 6KB
tx.dbgdt 3KB
regs.ddf 89KB
rx.dep 15KB
tx.dep 14KB
tx.dni 3KB
rx.dni 2KB
tx.dni 820B
tx.ewd 62KB
rx.ewd 62KB
tx.ewp 52KB
rx.ewp 52KB
rx.eww 156B
tx.eww 156B
regs.h 753KB
phy-library.h 32KB
iar.h 18KB
gnu.h 17KB
token-manufacturing.h 17KB
micro-common.h 15KB
error-def.h 13KB
nvm.h 12KB
platform-common.h 11KB
board.h 9KB
adc.h 7KB
adc.h 7KB
mfg-token.h 6KB
micro-common.h 5KB
flash.h 5KB
mems_regs.h 4KB
memmap.h 4KB
stm32w108_type.h 3KB
memmap.h 2KB
memmap-fat.h 2KB
system-timer.h 2KB
nvm-def.h 2KB
iap_bootloader.h 2KB
fib-bootloader.h 2KB
hal.h 2KB
asm.h 2KB
led.h 2KB
token-phy.h 1KB
error.h 1KB
mems.h 1KB
temperature_sensor.h 991B
uart.h 963B
button.h 676B
mpu.h 220B
iar-cfg.icf 2KB
tx_Debug.jlink 549B
共 173 条
- 1
- 2
资源评论
- looong20112013-12-23源码相当不错!谢谢分享
lzmxiang
- 粉丝: 0
- 资源: 3
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 通道处理过程的模拟通常涉及对通道处理机制的理解与实现.txt
- Flume进阶-自定义拦截器jar包
- Dubins曲线算法讲解和在运动规划中的使用.pdf
- 上市公司-股票性质数据-工具变量(民企、国企、央企)2003-2022年.dta
- 上市公司-股票性质数据-工具变量(民企、国企、央企)2003-2022年.xlsx
- Reeds+Shepp曲线算法讲解和实现.pdf
- 毕业设计基于SpringBoot+MyBatisPlus+MySQL+Vue的外卖配送信息系统源代码+数据库
- 词向量(Word Embeddings)是自然语言处理(NLP)领域的一种重要技术.txt
- Surfer,线性函数
- MyBatis 的动态 SQL 是其核心特性之一.txt
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功