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

📄 pwrlib.c

📁 freescale的基于802.15.4的无线通讯例程
💻 C
📖 第 1 页 / 共 3 页
字号:
/******************************************************************************
* Functions to handle the different power states.
*
*
* (c) Copyright 2005, Freescale Semiconductor, Inc. All rights reserved.
*
* Freescale Confidential Proprietary
* Digianswer Confidential
*
* No part of this document must be reproduced in any form - including copied,
* transcribed, printed or by any electronic means - without specific written
* permission from Freescale.
*******************************************************************************/


/******************************************************************************
*******************************************************************************
* Includes
*******************************************************************************
*******************************************************************************/
#include "PublicConst.h"
#include "PortConfig.h"  
#include "AppAspInterface.h"
#include "MsgSystem.h"
#include "IoConfig.h"
#include "Mc1319xDrv.h"           /* For RADIO spi driver */
#include "Mc1319xReg.h"           /* For RADIO registers */
#include "NV_Data.h"              /* For RADIO trim value */
//#include "hwdrv_hcs08.h"        /* For RADIO register init */
#include "PWR_Configuration.h" 
#include "PWRLib.h"
#include "IrqControlLib.h"

/******************************************************************************
*******************************************************************************
* external declarations
*******************************************************************************
*******************************************************************************/

#ifndef gMacStandAlone_d
  #define gMacStandAlone_d 0
#endif /*gMacStandAlone_d*/
extern void FLib_MemCpyReverseOrder
  (
  void *pDst, /* Destination buffer */
  void *pSrc, /* Source buffer  */
  uint8_t n   /* Byte count */
  );

/******************************************************************************
*******************************************************************************
* Private memory declarations
*******************************************************************************
*******************************************************************************/

#if (cPWR_UsePowerDownMode)
  /*--- Variables for saving the port settings  --- */
  #if (cPWR_SetupIOWhenInPD >= 1)
    static uint8_t            SavedPTAD ;
    static uint8_t            SavedPTBD ;
    static uint8_t            SavedPTCD ;
    static uint8_t            SavedPTDD ;
    static uint8_t            SavedPTED ;
    static uint8_t            SavedPTFD ;
    static uint8_t            SavedPTGD ;
  #endif   /* (cPWR_SetupIOWhenInPD >= 1) */
  #if (cPWR_SetupIOWhenInPD == 1)
    static uint8_t            SavedPTADD;
    static uint8_t            SavedPTBDD;
    static uint8_t            SavedPTCDD;
    static uint8_t            SavedPTDDD;
    static uint8_t            SavedPTEDD;
    static uint8_t            SavedPTFDD;
    static uint8_t            SavedPTGDD;
    static uint8_t            SavedPTAPE;
    static uint8_t            SavedPTBPE;
    static uint8_t            SavedPTCPE;
    static uint8_t            SavedPTDPE;
    static uint8_t            SavedPTEPE;
    static uint8_t            SavedPTFPE;
    static uint8_t            SavedPTGPE;
  #endif   /* (cPWR_SetupIOWhenInPD == 1) */

  #if (cPWR_UseDebugOutputs)
    static uint8_t            SavedDebugPTBD;
    static uint8_t            SavedDebugPTCD;
    static uint8_t            SavedDebugPTDD;
  #endif  /* #if (cPWR_UseDebugOutputs) */


  /*--- Variables for saving clock mode ---*/
  static PWRLib_ICGMode_t         PWRLib_ICGMode;

  /*--- RTI variables ---*/
  static uint32_t                 PWRLib_RTIRemainingTicks;

  /*--- For Reset function ---*/
  static const uint16_t     illegal_opcode = 0x9e62;                /* An HCS08 illegal instruction. Used to force an illegal */
                                                                    /* instruction reset */
  const uint16_t * const    illegal_opcode_ptr = &illegal_opcode;   /* A pointer to the address of illegal opcode */
#endif /* #if (cPWR_UsePowerDownMode) */

/*--- For LVD function ---*/ 
#if (cPWR_LVD_Enable > 0)
  #if (cPWR_LVD_Enable == 2)
    uint16_t                   PWRLib_LVD_CollectCounter;
  #endif  /* #if (cPWR_LVD_Enable == 2) */
  uint16_t                     PWRLib_LVD_L2Counter;
  PWRLib_LVD_VoltageLevel_t    PWRLib_LVD_SavedLevel;
#endif /* #if (cPWR_LVD_Enable > 0) */

/******************************************************************************
*******************************************************************************
* Public memory declarations
*******************************************************************************
*******************************************************************************/
  /*--- Chip status ---*/
  #if (cPWR_UseMCUStatus)
    PWRLib_MCUStatus_t            PWRLib_MCUStatus;
  #endif  /* #if (cPWR_UseMCUStatus) */

  #if (cPWR_UseRADIOStatus)
    PWRLib_RADIOStatus_t          PWRLib_RADIOStatus;
  #endif  /* #if (cPWR_UseRADIOStatus) */

  /*--- Zigbee STACK status ---*/ 
  PWRLib_StackPS_t                PWRLib_StackPS;

  volatile PWRLib_WakeupReason_t       PWRLib_MCU_WakeupReason   cPlaceInZeroPageSegment;


/*---------------------------------------------------------------------------*/
/*--- Only include the rest if needed / enabled                           ---*/
#if (cPWR_UsePowerDownMode==1)


/******************************************************************************
*******************************************************************************
* Private definitions
*******************************************************************************
*******************************************************************************/
  /* SCM filter values for ~2 MHz bus clock (lowest possible value) */
  #define cICGFLTH_VALUE_2MHZ             0x00
  #define cICGFLTL_VALUE_2MHZ             0x11 /* 0x10 */
  #define mSCM_2MHZ_DEFAULT_ICG_FILTER    ICGFLTL = cICGFLTL_VALUE_2MHZ; \
                                          ICGFLTH = cICGFLTH_VALUE_2MHZ;

  /* SCM filter values for ~4 MHz bus clock */
  #define cICGFLTH_VALUE_DEFAULT          0x00
  #define cICGFLTL_VALUE_DEFAULT          0xC0
  #define mSCM_DEFAULT_ICG_FILTER         ICGFLTL = cICGFLTL_VALUE_DEFAULT; \
                                          ICGFLTH = cICGFLTH_VALUE_DEFAULT;

  /* SCM filter values for ~8 MHz bus clock */
  #define cICGFLTH_VALUE_8MHZ             0x02
  #define cICGFLTL_VALUE_8MHZ             0x40
  #define mSCM_8MHZ_DEFAULT_ICG_FILTER    ICGFLTL = cICGFLTL_VALUE_8MHZ; \
                                          ICGFLTH = cICGFLTH_VALUE_8MHZ;

  /* SCM filter values for ~16 MHz bus clock */
  #define cICGFLTH_VALUE_16MHZ            0x06
  #define cICGFLTL_VALUE_16MHZ            0x40
  #define mSCM_16MHZ_DEFAULT_ICG_FILTER   ICGFLTL = cICGFLTL_VALUE_16MHZ; \
                                          ICGFLTH = cICGFLTH_VALUE_16MHZ;

  /* SCM filter values for ~20 MHz bus clock */
  #define cICGFLTH_VALUE_20MHZ            0x08
  #define cICGFLTL_VALUE_20MHZ            0x40
  #define mSCM_20MHZ_DEFAULT_ICG_FILTER   ICGFLTL = cICGFLTL_VALUE_20MHZ; \
                                          ICGFLTH = cICGFLTH_VALUE_20MHZ;

  /* Some ICG module bit positions */
  #define cICG_IRQ_PENDING                0x01
  #define cICG_FLL_LOCKED                 0x08


/******************************************************************************
*******************************************************************************
* Private functions
*******************************************************************************
*******************************************************************************/

/******************************************************************************
* Description : Used for waiting 6-7 clock periods
* Inputs      : None
* Output      : None
* Errors      : Not handled
* History     : 20050805 pbbusk1  Created
******************************************************************************/
void WAIT_6_NOPS( void)  {
  __asm nop;
}


/******************************************************************************
*******************************************************************************
* Public functions
*******************************************************************************
*******************************************************************************/

//------------------------------------------------------------------------------ 
//------------------------------------------------------------------------------
// MCU interface functions
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------

/*******************************************************************************/
/* Please see in PWRLib.h for description     */
void PWRLib_Reset(void) {
  IrqControlLib_DisableAllIrqs();
  mEXECUTE_ILLEGAL_INSTRUCTION
}  /* PWRLib_Reset */


/*******************************************************************************/
/* Please see in PWRLib.h for description                                    */
void PWRLib_SaveDebugIOState(void) {
  #if (cPWR_UseDebugOutputs)
    SavedDebugPTBD = PTBD;
    SavedDebugPTCD = PTCD;
    SavedDebugPTDD = PTDD;
  #endif  /*#if (cPWR_UseDebugOutputs) */
}  /* PWRLib_SaveDebugIOState ===*/


/*******************************************************************************/
/* Please see in PWRLib.h for description                                    */
void PWRLib_RestoreDebugIOState(void) {
  #if (cPWR_UseDebugOutputs)
    PTBD = (PTBD & (~mPWRLib_DEBUG_MASK_PTBD)) | (SavedDebugPTBD & mPWRLib_DEBUG_MASK_PTBD);
    PTCD = (PTCD & (~mPWRLib_DEBUG_MASK_PTCD)) | (SavedDebugPTCD & mPWRLib_DEBUG_MASK_PTCD);
    PTDD = (PTDD & (~mPWRLib_DEBUG_MASK_PTDD)) | (SavedDebugPTDD & mPWRLib_DEBUG_MASK_PTDD);
  #endif  /*#if (cPWR_UseDebugOutputs) */
}  /* PWRLib_RestoreDebugIOState =====*/


/*******************************************************************************/
/* Please see in PWRLib.h for description                                    */
void PWRLib_SetMCUIOForPowerSavingMode(void) {
  #if (cPWR_SetupIOWhenInPD > 0)
    PWRLib_SaveDebugIOState();
    #if (cPWR_SetupIOWhenInPD >= 1)
      SavedPTAD  = PTAD ;
      SavedPTBD  = PTBD ;
      SavedPTCD  = PTCD ;
      SavedPTDD  = PTDD ;
      SavedPTED  = PTED ;
      SavedPTFD  = PTFD ;
      SavedPTGD  = PTGD ;
    #endif
    #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
    mPWRLib_SETUP_PORT_A;
    mPWRLib_SETUP_PORT_B;
    mPWRLib_SETUP_PORT_C;
    mPWRLib_SETUP_PORT_D;
    mPWRLib_SETUP_PORT_E;
    mPWRLib_SETUP_PORT_F;
    mPWRLib_SETUP_PORT_G;
    PWRLib_RestoreDebugIOState();
    mPWRLib_SPIPowerSaveMode;
  #endif  /* #if (cPWR_SetupIOWhenInPD) */
}   /* PWRLib_SetMCUIOForPowerSavingMode =====*/


⌨️ 快捷键说明

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