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

📄 pwrlib.h

📁 freescale的基于802.15.4的无线通讯例程
💻 H
📖 第 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.
*
************************************************************************************/
#ifndef _PWRLIB_H_
#define _PWRLIB_H_


/************************************************************************************
*************************************************************************************
* Includes
*************************************************************************************
************************************************************************************/
#include "EmbeddedTypes.h"
#include "MsgSystem.h"
//#include "hwdrv_hcs08.h"
#include "crt0.h"
#include "PWR_Configuration.h"

/************************************************************************************
*************************************************************************************
* Segment definitions
*************************************************************************************
************************************************************************************/
#pragma DATA_SEG __SHORT_SEG MY_ZEROPAGE
#pragma DATA_SEG DEFAULT
#define cPlaceInZeroPageSegment   @ "MY_ZEROPAGE"


/************************************************************************************
*************************************************************************************
* Module configuration constants
*************************************************************************************
************************************************************************************/


//---------------------------------------------------------------------------//
//--- Definitions for RTI timer setup (SRTISC @0x1808)                    ---//
#define cSRTISC_IntDisabled   0b000
#define cSRTISC_Int0008ms     0b001
#define cSRTISC_Int0032ms     0b010
#define cSRTISC_Int0064ms     0b011
#define cSRTISC_Int0128ms     0b100
#define cSRTISC_Int0256ms     0b101
#define cSRTISC_Int0512ms     0b110
#define cSRTISC_Int1024ms     0b111
//                              .--------- RTIF(R)  : Real-Time Interrupt flag
//                              |.-------- RTIACK(W): RTI acknowledge
//                              ||.------- RTICLKS  : Clock select. 1: Ext. 0: Int. 1kHz
//                              |||.------ RTIE     : Real Time Interrupt Enable
//                              ||||.----- 0
//                              |||||...-- RTIS0-2  : Delay Select. See above
#define cSRTISC_Start         0b00010000
#define cSRTISC_External      0b00100000
#define cSRTISC_Stop          0b00000000
#define cSRTISC_IntClear      0b01000000


//---------------------------------------------------------------------------//
//--- Definitions for SPMSC1 (PMCSC1 @0x1809)                             ---//
//                                .---------  LVDF(R)   : Low Voltage Detect flag
//                                |.--------  LVDACK(W) : Low Voltage Detect Acknowledge
//                                ||.-------  LVDIE     : Low Voltage Detect Interrupt Enable
//                                |||.------  LVDRE     : Low Voltage Detect Reset Enable (Writable only once)
//                                ||||.-----  LVDSE     : Low Voltage Detect Stop Enable (Writable only once)
//                                |||||.----  LVDDE     : Low Voltage Detect Detect Enable (Writable only once)
//                                ||||||..--  00        : Unused
#define cSPMSC1Init_LVD_Disable 0b00000000    // Write ONCE (SRTISC). Done to conserve power -> no Low voltage detection
#define cSPMSC1Init_LVD_Enable  0b00000100    // No interrupt on low voltage, no low voltage detection in STOP mode,
                                              // Enable voltage detection - Write ones register
#define cSPMSC1_LVDFlag         0b10000000    // Low voltage flag set when threshold value reaced


//---------------------------------------------------------------------------//
//--- Definitions for SPMSC2 (PMCSC2 @0x180a)                             ---//
//                                .---------  LVWF(R)   : Low Voltage Warning flag
//                                |.--------  LVWACK(W) : Low Voltage Warning Acknowledge
//                                ||.-------  LVDV      : Low Voltage Detect Voltage Select
//                                |||.------  LVWV      : Low Voltage Warning Voltage Select
//                                ||||.-----  PPDF      : Partial Power Down Flag
//                                |||||.----  PPDACK    : Partial Power Down Acknowledge (W) Clears PPDF bit
//                                ||||||.---  PDC       : Power Down Control
//                                |||||||.--  PPDC      : Partial Power Down Control
#define cSPMSC2_HighTripVoltage 0b00010000      // Set high trip voltage
#define cSPMSC2_LowTripVoltage  0b00000000      // Set low  trip voltage
#define cSPMSC2_ClearWarning    0b01000000      // Clear warning flag
#define cSPMSC2_LVWFlag         0b10000000      // Low voltage flag set when threshold value reached


//---------------------------------------------------------------------------//
//--- Register redefinitions for compliance with MC9S08GB60/D             ---//
#define KBI1SC                    KBISC                     // Register at 0x0016
#define KBI1PE                    KBIPE                     // Register at 0x0017
#define SPI1C1                    SPIC1                     // Register at 0x0028
#define SRTISC                    PMCRSC                    // Register at 0x1808
#define SPMSC1                    PMCSC1                    // Register at 0x1809
#define SPMSC2                    PMCSC2                    // Register at 0x180a


//---------------------------------------------------------------------------//
//--- Definitions for the reset function                                  ---//
#define mEXECUTE_ILLEGAL_INSTRUCTION __asm ldhx illegal_opcode_ptr; \
                                     __asm jmp ,x;


/************************************************************************************
*************************************************************************************
* Public types
*************************************************************************************
************************************************************************************/

//---------------------------------------------------------------------------//
//--- Specifics for setting clock modes                                   ---//
typedef enum {Normal_16MHz=0, Precice_1MHz, SelfClk_2MHz, \
              SelfClk_1MHz, SelfClk_125kHz}               PWRLib_ICGClkMode_t;
typedef enum {SCM = 0,FEI, FBE, FEE}                      PWRLib_ICGMode_t;
typedef enum {LOW_CLOCK = 0, HIGH_CLOCK}                  PWRLib_ICGClockType_t;
typedef enum {N4 = 0, N6, N8, N10, N12, N14, N16, N18}    PWRLib_ICGMultiplier_t;
typedef enum {R1 = 0, R2, R4, R8, R16, R32, R64, R128}    PWRLib_ICGDivider_t;


//---------------------------------------------------------------------------//
//--- Specifics for chip modes and wakeup reason                          ---//
typedef enum {MCU_Running=66, MCU_Wait, MCU_Stop3, MCU_Stop2, MCU_Stop1}  PWRLib_MCUStatus_t;
typedef enum {RADIO_Idle=88, RADIO_Doze, RADIO_AcomaDoze, \
              RADIO_Hibernate, RADIO_Off}                                 PWRLib_RADIOStatus_t;


//---------------------------------------------------------------------------//
//--- RADIO CLKO register valuedefines. Note: Has to start at 0           ---//
typedef enum {RADIO_CLKO_16MHZ = 0, RADIO_CLKO_8MHZ, RADIO_CLKO_4MHZ, RADIO_CLKO_2MHZ, \
              RADIO_CLKO_1MHZ, RADIO_CLKO_62_50KHZ, RADIO_CLKO_32_78KHZ, \
              RADIO_CLKO_16_39KHZ}                                        PWRLib_RADIO_CLKO_t;


//---------------------------------------------------------------------------//
//--- Zigbee stack power state                                            ---//
typedef enum {StackPS_Running=122, StackPS_Sleep, StackPS_DeepSleep}      PWRLib_StackPS_t;


//---------------------------------------------------------------------------//
//--- Wakeup reason UNION definitions                                     ---//
typedef  union {
  uint8_t AllBits;
  struct {
    unsigned int   FromReset       :1;                // Comming from Reset
    unsigned int   FromStop2       :1;                // Comming from Stop2 mode
    unsigned int   FromKBI         :1;                // Wakeup by KBI interrupt
    unsigned int   FromRTI         :1;                // Wakeup by RTI timer interrupt
    unsigned int   FromTimer       :1;
    unsigned int   DeepSleepTimeout:1;                // DeepSleep timer ran out
    unsigned int   SleepTimeout    :1;                // Sleep timer ran out
    unsigned int   LVD_Updated     :1;                //
  } Bits;
} PWRLib_WakeupReason_t;


//---------------------------------------------------------------------------//
//--- Reported voltage levels. Level 4 is highest (best)                  ---//
//---        Highest ----------------------------- Lowest voltage         ---//
typedef enum{ PWR_NODEPOWER_LEVEL_100 = 0x0c, PWR_NODEPOWER_LEVEL_66=0x08, \
              PWR_NODEPOWER_LEVEL_50, PWR_NODEPOWER_LEVEL_33=0x04, \
              PWR_NODEPOWER_LEVEL_CRITICAL=0x00}             PWRLib_LVD_VoltageLevel_t;


/************************************************************************************
*************************************************************************************
* External variable declarations
*************************************************************************************
************************************************************************************/


/************************************************************************************
*************************************************************************************
* Public macroes
*************************************************************************************
************************************************************************************/

//---------------------------------------------------------------------------//
//--- Definitions for PWRLib_RADIOStatus writing                          ---//
#if (cPWR_UseRADIOStatus)
  #define mRADIO_SetStatus( x)     PWRLib_RADIOStatus = x;
  #define mRADIO_GetStatus         PWRLib_RADIOStatus
#else
  #define mRADIO_SetStatus( x)     ;
  #define mRADIO_GetStatus
#endif  // #if (cPWR_UseRADIOStatus)


//---------------------------------------------------------------------------//
//--- Definitions for PWRLib_MCUStatus writing                            ---//
#if (cPWR_UseMCUStatus)
  #define mMCU_SetStatus( x)     PWRLib_MCUStatus = x;
#else
  #define mMCU_SetStatus( x)     ;
#endif  // #if (cPWR_UseMCUStatus)


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

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

extern volatile PWRLib_WakeupReason_t     PWRLib_MCU_WakeupReason   cPlaceInZeroPageSegment;

⌨️ 快捷键说明

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