gzc1017 发表于 2010-3-18 17:33:24

求助 在RTT操作系统的空闲钩子函数里实现低功耗

现在我的空闲钩子函数设置是
extern void EnterSTOPMode_RTCAlarm(void);
void rt_thread_idle_sethook(void EnterSTOPMode_RTCAlarm(void))
{
    rt_thread_idle_hook=EnterSTOPMode_RTCAlarm;
}
下面是具体实现
#include "stm32f10x.h"
#include "stm32_eval.h"

extern void RTC_Configuration(void);
ErrorStatus HSEStartUpStatus;
/**
* @briefConfigures system clock after wake-up from STOP: enable HSE, PLL
*   and select PLL as system clock source.
* @paramNone
* @retval None
*/
void SYSCLKConfig_STOP(void)
{
/* Enable HSE */
RCC_HSEConfig(RCC_HSE_ON);

/* Wait till HSE is ready */
HSEStartUpStatus = RCC_WaitForHSEStartUp();

if(HSEStartUpStatus == SUCCESS)
{

#ifdef STM32F10X_CL
    /* Enable PLL2 */
    RCC_PLL2Cmd(ENABLE);

    /* Wait till PLL2 is ready */
    while(RCC_GetFlagStatus(RCC_FLAG_PLL2RDY) == RESET)
    {
    }
#endif

    /* Enable PLL */
    RCC_PLLCmd(ENABLE);

    /* Wait till PLL is ready */
    while(RCC_GetFlagStatus(RCC_FLAG_PLLRDY) == RESET)
    {
    }

    /* Select PLL as system clock source */
    RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK);

    /* Wait till PLL is used as system clock source */
    while(RCC_GetSYSCLKSource() != 0x08)
    {
    }
}
}

/**
* @briefConfigures EXTI Lines.
* @paramNone
* @retval None
*/
void EXTI_Configuration(void)
{
EXTI_InitTypeDef EXTI_InitStructure;

/* Configure EXTI Line17(RTC Alarm) to generate an interrupt on rising edge */
EXTI_ClearITPendingBit(EXTI_Line17);
EXTI_InitStructure.EXTI_Line = EXTI_Line17;
EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising;
EXTI_InitStructure.EXTI_LineCmd = ENABLE;
EXTI_Init(&EXTI_InitStructure);
}


/**
* @briefConfigures NVIC and Vector Table base location.
* @paramNone
* @retval None
*/
static void NVIC_Configuration(void)
{
NVIC_InitTypeDef NVIC_InitStructure;

/* 2 bits for Preemption Priority and 2 bits for Sub Priority */
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);

NVIC_InitStructure.NVIC_IRQChannel = RTCAlarm_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
}



void EnterSTOPMode_RTCAlarm(void)
{

/* Initialize LEDs and Key Button mounted on STM3210X-EVAL board */      
STM_EVAL_LEDInit(LED1);
STM_EVAL_LEDInit(LED2);
STM_EVAL_LEDInit(LED3);
STM_EVAL_PBInit(Button_KEY, Mode_EXTI);

/* Configure EXTI Line to generate an interrupt on falling edge */
EXTI_Configuration();

/* Configure RTC clock source and prescaler */
RTC_Configuration();

/* NVIC configuration */
NVIC_Configuration();

/* Turn on LED1 */
STM_EVAL_LEDOn(LED1);

while (1)
{

    /* Wait till RTC Second event occurs */
    RTC_ClearFlag(RTC_FLAG_SEC);
    while(RTC_GetFlagStatus(RTC_FLAG_SEC) == RESET);

    /* Alarm in 1 second */
    RTC_SetAlarm(RTC_GetCounter()+ 1);
    /* Wait until last write operation on RTC registers has finished */
    RTC_WaitForLastTask();

    /* Turn off LED1 */
    STM_EVAL_LEDOff(LED1);
    //rt_kprintf("Enter stop mode...\n");

    /* Request to enter STOP mode with regulator in low power mode*/
    PWR_EnterSTOPMode(PWR_Regulator_LowPower, PWR_STOPEntry_WFI);

    /* At this stage the system has resumed from STOP mode -------------------*/
    /* Turn on LED1 */
    STM_EVAL_LEDOn(LED1);
    //rt_kprintf("Wake from stop mode\n");
    /* Configures system clock after wake-up from STOP: enable HSE, PLL and select
       PLL as system clock source (HSE and PLL are disabled in STOP mode) */
    SYSCLKConfig_STOP();
       

}
}
其中RTC的配置是
void RTC_Configuration(void)
{
   /* Enable PWR and BKP clocks */
   RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR | RCC_APB1Periph_BKP, ENABLE);

   /* Allow access to BKP Domain */
   PWR_BackupAccessCmd(ENABLE);

   /* Reset Backup Domain */
   BKP_DeInit();

   /* Enable LSE */
   RCC_LSEConfig(RCC_LSE_ON);
   /* Wait till LSE is ready */
   while (RCC_GetFlagStatus(RCC_FLAG_LSERDY) == RESET)
   {
   }

   /* Select LSE as RTC Clock Source */
   RCC_RTCCLKConfig(RCC_RTCCLKSource_LSE);

   /* Enable RTC Clock */
   RCC_RTCCLKCmd(ENABLE);

   /* Wait for RTC registers synchronization */
   RTC_WaitForSynchro();

   /* Wait until last write operation on RTC registers has finished */
   RTC_WaitForLastTask();

   /* Set RTC prescaler: set RTC period to 1sec */
   RTC_SetPrescaler(32767); /* RTC period = RTCCLK/RTC_PR = (32.768 KHz)/(32767+1) */

   /* Wait until last write operation on RTC registers has finished */
   RTC_WaitForLastTask();

}
但是我把程序下载进去后,低功耗程序根本没有执行,请大家分析哈原因,谢谢!困惑中

gzc1017 发表于 2010-3-18 17:41:34

自己顶一下,现在只知道在RTT的IDLE钩子中不能有while (1)因为空闲线程里有个while(1),但其他的问题就不知道了,请有经验的大侠指导哈,在空闲钩子函数里应该怎么实现低功耗呢?谢谢!

ffxz 发表于 2010-3-18 17:49:12

extern void EnterSTOPMode_RTCAlarm(void);
void rt_thread_idle_sethook(void EnterSTOPMode_RTCAlarm(void))
{
    rt_thread_idle_hook=EnterSTOPMode_RTCAlarm;
}

这个是?rt_thraed_idle_sethook不是系统提供的调用吗,不需要修改函数本身的实现

应该在初始化中调用:
rt_thread_idle_sethook(EnterSTOPMode_RTCAlarm)

这样钩子函数才能设置上。

litteworm 发表于 2010-3-22 00:37:37

idle 裏面跑低功耗 是個好idea
畢竟嵌入式板子 功耗是永遠的話題
還有 我覺得 可以通過idle 計算cpu使用率
然後根據cpu使用率 自動調整stm32的倍頻
這樣 也可以降低功耗
页: [1]
查看完整版本: 求助 在RTT操作系统的空闲钩子函数里实现低功耗