新闻  |   论坛  |   博客  |   在线研讨会
CC2430DB Entering DEEP sleep
0750long | 2009-04-09 16:01:27    阅读:2189   发布文章

CC2430DB Entering DEEP sleep

 

前段时间有网友问起CC2430的睡眠问问题,在TI协议栈中的实现。近来一直比较忙,也没有深入看协议栈。以前在msstate R教授的协议栈里面试过是没有问题的,在TI的里面还没做实验,但是在ZStack-1.4.2-1.1.0ProjectszstackSamplesLocation 这个工程里面用到了睡眠定时器:,步骤如下所示:

1.  SampleAPP.c      //Ln288中

#if defined( POWER_SAVING ) //option预编译里面需要定义
        if ( rejoinPending )
        {
          rejoinPending = FALSE;

          //进入睡眠模式
          SampleApp_Sleep( TRUE );
        }
#endif

2.  void SampleApp_Sleep( uint8 allow ) //Ln339中
{
#if defined( POWER_SAVING )
  if ( allow )
  {
    osal_pwrmgr_task_state( NWK_TaskID, PWRMGR_CONSERVE );  //启动事件进入省电模式
    NLME_SetPollRate( 0 );
  }
  else
  {
    osal_pwrmgr_task_state( NWK_TaskID, PWRMGR_HOLD );
    NLME_SetPollRate( 1000 );
  }
#endif
}

3. OSAL_PwrMgr.c //Ln339中

uint8 osal_pwrmgr_task_state( uint8 task_id, uint8 state )
{
  if ( osalFindTask( task_id ) == NULL )
    return ( INVALID_TASK );

  if ( state == PWRMGR_CONSERVE )
  {
    // Clear the task state flag
    pwrmgr_attribute.pwrmgr_task_state &= ~(1 << task_id ); //起处实际就是启用了一个睡眠定时器
  }
  else
  {
    // Set the task state flag
    pwrmgr_attribute.pwrmgr_task_state |= (1 << task_id);
  }

  return ( ZSUCCESS );
}

4. OSAL_PwrMgr.c //Ln146中

void osal_pwrmgr_powerconserve( void )

{
  uint16        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 )
    {
      // 关中断.
      HAL_ENTER_CRITICAL_SECTION( intState );

      // Get next time-out
      next = osal_next_timeout();

      //全局终端使能
      HAL_EXIT_CRITICAL_SECTION( intState );

      // 进入睡眠模式
      OSAL_SET_CPU_INTO_SLEEP( next );
    }
  }
}

 

5. Onboard.h //Ln243中

#define OSAL_SET_CPU_INTO_SLEEP(timeout) halSleep(timeout); /* Called from OSAL_PwrMgr */

       因而实质上最终还是调用了halSleep(timeout)

/**************************************************************************************************
 * @fn          halSleep
 *
 * @brief       This function is called from the OSAL task loop using and existing OSAL
 *                   interface.  It sets the low power mode of the MAC and the CC2430.
 ***************************************************************************************************/

 

 

下面是TI community关于睡眠定时的一些帖子

http://community.ti.com/forums/t/1132.aspx

*博客内容为网友个人发布,仅代表博主个人观点,如有侵权请联系工作人员删除。

参与讨论
登录后参与讨论
推荐文章
最近访客