定義POWER_SAVING,CC2541會(huì)進(jìn)入睡眠模式—— 文件:
OSAL.c 函數(shù):
osal_run_system( void )
#if defined( POWER_SAVING )
else // Complete pass through all task events with no activity?
{
osal_pwrmgr_powerconserve(); // Put the processor/system into sleep
}
#endif
省電管理函數(shù):osal_pwrmgr_powerconserve()—— 文件:OSAL_PwrMgr.c 定義: void osal_pwrmgr_powerconserve( void )
{
uint32 next;
halIntState_t intState;
// Should we even look into power conservation
if ( pwrmgr_attribute.pwrmgr_device != PWRMGR_ALWAYS_ON )
{
// Are all tasks in agreement to conserve
if ( pwrmgr_attribute.pwrmgr_task_state == 0 )
{
// Hold off interrupts.
HAL_ENTER_CRITICAL_SECTION( intState );
// Get next time-out
next = osal_next_timeout();
// Re-enable interrupts.
HAL_EXIT_CRITICAL_SECTION( intState );
// Put the processor into sleep mode
OSAL_SET_CPU_INTO_SLEEP( next );
}
}
}
上述函數(shù)說(shuō)明CC2541要進(jìn)入睡眠,除了需要定義POWER_SAVING外,還要當(dāng)
pwrmgr_attribute.pwrmgr_task_state清零時(shí)才可以, 那么
pwrmgr_attribute.pwrmgr_task_state是什么時(shí)候清零的呢?且看下文。 設(shè)置電源管理狀態(tài)的語(yǔ)句—— 文件:
hal_drivers.c 函數(shù):
Hal_ProcessEvent( uint8 task_id, uint16 events ) 語(yǔ)句: if ( events & HAL_PWRMGR_HOLD_EVENT )
{
(void)osal_pwrmgr_task_state(Hal_TaskID, PWRMGR_HOLD);
(void)osal_stop_timerEx(Hal_TaskID, HAL_PWRMGR_CONSERVE_EVENT);
(void)osal_clear_event(Hal_TaskID, HAL_PWRMGR_CONSERVE_EVENT);
return (events & ~(HAL_PWRMGR_HOLD_EVENT | HAL_PWRMGR_CONSERVE_EVENT));
} if ( events & HAL_PWRMGR_CONSERVE_EVENT )
{
(void)osal_pwrmgr_task_state(Hal_TaskID, PWRMGR_CONSERVE);
return events ^ HAL_PWRMGR_CONSERVE_EVENT;
} 在這里好像看到眉目了,但是是哪里發(fā)出的事件
HAL_PWRMGR_HOLD_EVENT/
HAL_PWRMGR_CONSERVE_EVENT呢? 經(jīng)過(guò)一番搜索,找到發(fā)出響應(yīng)事件的位置 發(fā)出電源保持/省電事件—— 文件:_hal_uart_dma.c 函數(shù):static void HalUARTPollDMA(void) 語(yǔ)句: if (dmaRdyDly == 0)
{
(void)osal_set_event(Hal_TaskID, HAL_PWRMGR_HOLD_EVENT);
}
else if ((dmaRdyDly != 0) && (!DMA_PM_DLY || ((uint8)(ST0 - dmaRdyDly) > DMA_PM_DLY)))
{
dmaRdyDly = 0;
(void)osal_set_event(Hal_TaskID, HAL_PWRMGR_CONSERVE_EVENT);
}
注意,上述if else if并不是并列的??磥?lái)
dmaRdyDly起了非常重要的作用,具體這個(gè)變量是什么作用呢? |
|