⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pwrlib.c

📁 freescale的基于802.15.4的无线通讯例程
💻 C
📖 第 1 页 / 共 3 页
字号:

#if (cPWR_UsePowerDownMode==1)

//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
// RADIO interface functions
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------

/*****************************************************************************/
/* Please see in PWRLib.h for description   */
uint8_t PWRLib_RadioWakeReq(void) {
  uint8_t res;
#if (gMacStandAlone_d == 1)
  Asp_WakeReq(); /* No retun value */
  res = gSuccess_c;
#else
  aspMsg_t aspWake;
  aspWakeReq_t *pWakeReq;
  pWakeReq = &aspWake.appToAspMsg.msgData.aspWakeReq;
  /* Set the type. */
  aspWake.msgType = gAppAspWakeReq_c;
   /* Values greater than 1 byte must be little endian byte arrays. */
  pWakeReq->dummy = 0x00;
  /* Send the request to the ASP SAP. */
  res = MSG_Send(APP_ASP, &aspWake);
#endif
  mRADIO_SetStatus( RADIO_Idle);
  return(res);
} /* PWRLib_RadioWakeReq ======*/


/*****************************************************************************/
/* Please see in PWRLib.h for description   */
uint8_t PWRLib_RadioDozeReq(zbClock24_t DozeDuration, bool_t ClkOutEnabled) {
  zbClock24_t   actualDozeTime;
  uint8_t       *pTmpTime;
#if (gMacStandAlone_d == 1) 
  if (gSuccess_c == Asp_DozeReq(&DozeDuration, ClkOutEnabled)) {    
    pTmpTime = (uint8_t *)&DozeDuration;
#else
  aspMsg_t      aspDoze;
  aspDozeReq_t  *pDozeReq;

  pDozeReq = &aspDoze.appToAspMsg.msgData.aspDozeReq;
  aspDoze.msgType = gAppAspDozeReq_c;

  /* Values greater than 1 byte must be little endian byte arrays. */
  pDozeReq->dozeDuration[0] = (uint8_t)(0xFF & DozeDuration);
  pDozeReq->dozeDuration[1] = (uint8_t)(0xFF & (DozeDuration>>8));
  pDozeReq->dozeDuration[2] = (uint8_t)(0xFF & (DozeDuration>>16));
  #if (cPWR_MACVersionUsed != 1.05)
    pDozeReq->clko_en = ClkOutEnabled;
  #endif
  /* Send the request to the ASP SAP. */
  (void) MSG_Send(APP_ASP, &aspDoze);

  if(aspDoze.aspToAppMsg.msgData.appDozeCfm.status == gSuccess_c) {
    pTmpTime = aspDoze.aspToAppMsg.msgData.appDozeCfm.actualDozeDuration;
#endif /*gMacStandAlone_d*/    
    FLib_MemCpyReverseOrder( &actualDozeTime, pTmpTime, sizeof(zbClock24_t));
    actualDozeTime &= 0xffffff;                             /* Only 3 bytes internally */
    if( DozeDuration == actualDozeTime ) {
      mRADIO_SetStatus( RADIO_Doze);
       MC1319xDrv_AttEnable();                                            /* Set att. pin high so we do not waste any power..*/
      return(TRUE);
    } else {
      mRADIO_SetStatus( RADIO_Idle);
      return(FALSE);
    }
  }
  mRADIO_SetStatus( RADIO_Idle);
  #if (cPWR_MACVersionUsed == 1.05)
    ClkOutEnabled = FALSE;
    return(ClkOutEnabled);
  #else
    return(FALSE);
  #endif
} /* PWRLib_RadioDozeReq ======*/


/*****************************************************************************/
/* Please see in PWRLib.h for description      */
uint8_t PWRLib_RadioAcomaDozeReq(bool_t ClkOutEnabled) {
  #if (cPWR_MACVersionUsed != 1.05)
#if (gMacStandAlone_d == 1)
    if (gSuccess_c == Asp_AcomaReq(ClkOutEnabled)) {      
#else
    aspMsg_t      aspAcoma;
    aspAcomaReq_t *pAcomaReq;

    pAcomaReq = &aspAcoma.appToAspMsg.msgData.aspAcomaReq;
    /* Set the type. */
    aspAcoma.msgType = gAppAspAcomaReq_c;

    /* Use clko or not!!*/
    #if (cPWR_MACVersionUsed != 1.05)
      pAcomaReq->clko_en = ClkOutEnabled;
    #endif
    /* Send the request to the ASP SAP. */
    (void) MSG_Send(APP_ASP, &aspAcoma);

    if(aspAcoma.aspToAppMsg.msgData.appAcomaCfm.status == gSuccess_c) {
#endif    
      mRADIO_SetStatus( RADIO_AcomaDoze);
        MC1319xDrv_AttEnable();/* Set att. pin high so we do not waste any power..*/
      return(TRUE);
    } else {
      mRADIO_SetStatus( RADIO_Idle);
      return(FALSE);
    }
  #else
    ClkOutEnabled = FALSE;
    return(ClkOutEnabled);
  #endif
} /* PWRLib_RadioAcomaDozeReq ======*/


/*****************************************************************************/
/* Please see in PWRLib.h for description     */
uint8_t PWRLib_RadioHibernateReq(void) {
#if (gMacStandAlone_d == 1)
  if (gSuccess_c == Asp_HibernateReq()) {    
#else
  aspMsg_t          aspHibernate;
  aspHibernateReq_t *pHibernateReq;

  pHibernateReq = &aspHibernate.appToAspMsg.msgData.aspHibernateReq;
  /* Set the type. */
  aspHibernate.msgType = gAppAspHibernateReq_c;

   /* Values greater than 1 byte must be little endian byte arrays. */
  pHibernateReq->dummy = 0x00;
  /* Send the request to the ASP SAP. */
  (void) MSG_Send(APP_ASP, &aspHibernate);
  if(aspHibernate.aspToAppMsg.msgData.appHibernateCfm.status == gSuccess_c) {
#endif
    mRADIO_SetStatus( RADIO_Hibernate);
     MC1319xDrv_AttEnable(); /* Set att. pin high so we do not waste any power.*/
    return(TRUE);
  } else {
    mRADIO_SetStatus( RADIO_Idle);
    return(FALSE);
  }
} /* PWRLib_RadioHibernateReq ======*/


/*****************************************************************************/
/* Please see in PWRLib.h for description     */
void PWRLib_RadioOffReq(void) {
  #if (cPWR_MACVersionUsed != 1.05)
    MC1319xDrv_AssertReset(); 			 /* Reset RADIO */
    mPWRLib_SETUPFOR_RADIORESET;  
  #endif
  mRADIO_SetStatus( RADIO_Off);
} /* PWRLib_RadioOffReq ======*/


/*****************************************************************************/
/* Please see in PWRLib.h for description     */
void PWRLib_RadioOnReq(void) {
  #if (cPWR_MACVersionUsed != 1.05)
    mPWRLib_SETUPAFTER_RADIORESET;
    MC1319xDrv_DeassertReset();
	MC1319xDrv_AttDisable(); 
  #endif
  mRADIO_SetStatus( RADIO_Idle);
} /* PWRLib_RadioOnReq ======*/


/*****************************************************************************/
/* Please see in PWRLib.h for description        */
uint8_t PWRLib_GetMacStateReq() {
  #if (cPWR_MACVersionUsed != 1.05)
#if (gMacStandAlone_d == 1)
    return Asp_GetMacStateReq();
#else
    aspMsg_t             aspGetMacState;
    aspGetMacStateReq_t *pGetMacStateReq;

    pGetMacStateReq = &aspGetMacState.appToAspMsg.msgData.aspGetMacStateReq;
    /* Set the type. */
    aspGetMacState.msgType = gAppAspGetMacStateReq_c;

     /* Values greater than 1 byte must be little endian byte arrays.*/
    pGetMacStateReq->dummy = 0x00;
    /* Send the request to the ASP SAP. */
    (void) MSG_Send(APP_ASP, &aspGetMacState);
    return(aspGetMacState.aspToAppMsg.msgData.appGetMacStateCfm.status);
#endif
  #else
    return( TRUE);
  #endif
}  /* PWRLib_GetMacStateReq() =====*/


//----------------------------------------------------------------------------
//----------------------------------------------------------------------------
// Zigbee stack interface functions
//----------------------------------------------------------------------------
//----------------------------------------------------------------------------
/*#define PWRLib_GetCurrentZigbeeStackPowerState     PWRLib_StackPS;*/
/*#define PWRLib_SetCurrentZigbeeStackPowerState( x) PWRLib_StackPS = x;*/


//----------------------------------------------------------------------------
//----------------------------------------------------------------------------
// Common init function
//----------------------------------------------------------------------------
//----------------------------------------------------------------------------

/*****************************************************************************/
/* Please see in PWRLib.h for description     */
void PWRLib_Init(void) {
  #if (cPWR_UsePowerDownMode)
    PWRLib_ICGMode              = FEE;
    mMCU_SetStatus( MCU_Running);
    mRADIO_SetStatus( RADIO_Idle);
    #if (cPWR_SetupIOWhenInPD >= 1)
      SavedPTAD             = PTAD ;
      SavedPTBD             = PTBD ;
      SavedPTCD             = PTCD ;
      SavedPTDD             = PTDD ;
      SavedPTED             = PTED ;
      SavedPTFD             = PTFD ;
      SavedPTGD             = PTGD ;
    #endif  /* (cPWR_SetupIOWhenInPD >= 1) */
    #if (cPWR_SetupIOWhenInPD == 1)
      SavedPTADD            = PTADD;
      SavedPTBDD            = PTBDD;
      SavedPTCDD            = PTCDD;
      SavedPTDDD            = PTDDD;
      SavedPTEDD            = PTEDD;
      SavedPTFDD            = PTFDD;
      SavedPTGDD            = PTGDD;
      SavedPTAPE            = PTAPE;
      SavedPTBPE            = PTBPE;
      SavedPTCPE            = PTCPE;
      SavedPTDPE            = PTDPE;
      SavedPTEPE            = PTEPE;
      SavedPTFPE            = PTFPE;
      SavedPTGPE            = PTGPE;
    #endif  /* #if (cPWR_SetupIOWhenInPD == 1) */
    mRESETPIN_STOP2_MODE;
    #if (cPWR_KBIInitAndVectorEnable)
      #if (cPWR_KBIWakeupEnable)
        KBI1PE = cKBI1PE;                                         /* KBI setup */
        KBI1SC = cKBI1SC | cKBI1SC_Ack;
      #endif
    #endif
    PWRLib_MCU_WakeupReason.AllBits = 0;
    if ( SPMSC2 & 0x08) {
      PWRLib_MCU_WakeupReason.Bits.FromStop2 = 1;                     /* Wakeup from STOP2 mode */
    } else {
      PWRLib_MCU_WakeupReason.Bits.FromReset = 1;                     /* Ordinary reset */
    }
    PWRLib_SetCurrentZigbeeStackPowerState( StackPS_DeepSleep);
    #if (cPWR_LVD_Enable==0)
      SPMSC1 = cSPMSC1Init_LVD_Disable; /* Write once (SRTISC). Done here to conserve power */
    #else
      SPMSC1 = cSPMSC1Init_LVD_Enable;  /* Write once (SRTISC). Done here enable power level */
                                        /* in running state */
    #endif /* #if(cPWR_LVD_Enable) */
    #if (cPWR_LVD_Enable > 0)
      PWRLib_LVD_SavedLevel = PWR_NODEPOWER_LEVEL_100;
      PWRLib_LVD_L2Counter  = cPWR_LVD_LEVEL_50_Ticks;
    #endif  /* #if (cPWR_LVD_Enable > 0) */
    #if (cPWR_LVD_Enable==2)
      PWRLib_LVD_CollectCounter = cPWR_LVD_Ticks;
    #endif  /* #if (cPWR_LVD_Enable==2) */
    SPMSC2 |=  0x04;      /* Sets PPDACK bit to restore output drivers after Stop2 mode */
  #endif  /*#if (cPWR_UsePowerDownMode) */

} /*PWR_Init =====*/


#endif  /*#if (cPWR_UsePowerDownMode==1) */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -