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

📄 mac_power_management.h

📁 zigbee location examples
💻 H
字号:
/*******************************************************************************************************
 *                                                                                                     *
 *        **********                                                                                   *
 *       ************                                                                                  *
 *      ***        ***                                                                                 *
 *      ***   +++   ***                                                                                *
 *      ***   + +   ***                                                                                *
 *      ***   +                         CHIPCON CC2430 INTEGRATED 802.15.4 MAC AND PHY                 *
 *      ***   + +   ***                             CC2430 Power Management                            *
 *      ***   +++   ***                                                                                *
 *      ***        ***                                                                                 *
 *       ************                                                                                  *
 *        **********                                                                                   *
 *                                                                                                     *
 *******************************************************************************************************
 * CONFIDENTIAL                                                                                        *
 * The use of this file is restricted by the signed MAC software license agreement.                    *
 *                                                                                                     *
 * Copyright Chipcon AS, 2005                                                                          *
 *******************************************************************************************************/
#ifndef MACPOWERMANAGEMENT_H
#define MACPOWERMANAGEMENT_H




/*******************************************************************************************************
 *******************************************************************************************************
 **************************               CONSTANTS AND MACROS                **************************
 *******************************************************************************************************
 *******************************************************************************************************/


//-------------------------------------------------------------------------------------------------------
// The number of microseconds used to power up the CC2420 voltage regulator (taken from the data sheet)
#define MPM_VREG_TURN_ON_TIME 600
//-------------------------------------------------------------------------------------------------------


//-------------------------------------------------------------------------------------------------------
// Available power modes
// Note: A transition from MPM_CC2430_XOSC_OFF to MPM_CC2430_XOSC_AND_VREG_OFF is not possible
#define MPM_CC2430_ON                   0
#define MPM_CC2430_XOSC_OFF             1
#define MPM_CC2430_XOSC_AND_VREG_OFF    2

// The confirmation status codes used by mpmSetConfirm(...)
#define OK_POWER_MODE_CHANGED           0
#define OK_POWER_MODE_UNCHANGED         1
#define ERR_RX_ON_WHEN_IDLE             2
//-------------------------------------------------------------------------------------------------------

typedef enum
{
    POWER_MODE_PM1,
    POWER_MODE_PM2,
    POWER_MODE_PM3
} POWER_MODE;

typedef enum
{
    RESUME_MODE_ALL_PRESERVED,
    RESUME_MODE_PARTS_PRESERVED
} RESUME_MODE;

/*******************************************************************************************************
 *******************************************************************************************************
 **************************                   MODULE DATA                     **************************
 *******************************************************************************************************
 *******************************************************************************************************/


//-------------------------------------------------------------------------------------------------------
// Internal module data
typedef struct {
    BYTE currentState;
    BYTE selectedMode;
} MPM_INFO;
extern MPM_INFO mpmInfo;
//-------------------------------------------------------------------------------------------------------




/*******************************************************************************************************
 *******************************************************************************************************
 **************************               FUNCTION PROTOTYPES                 **************************
 *******************************************************************************************************
 *******************************************************************************************************/


//-------------------------------------------------------------------------------------------------------
//  void mpmSetRequest(BYTE mode)
//
//  DESCRIPTION:
//      This function allows the higher layer to power down CC2430 to extend battery lifetime. CC2430
//      must be powered up before any MLME or MCPS primitives can be used (both beacon/non-beacon modes).
//      Power-down is currently only supported for non-beacon PANs.
//
//      The change is not likely to happen instantaneously (under normal conditions the delay can be up
//      to 320 us). Use either the mpmSetConfirm callback, or poll the current power state by using
//      mpmGetState() (returns the selected power mode when it has become effective).
//
//  ARGUMENTS:
//      BYTE mode
//          MPM_CC2430_ON:                The CC2430 crystal oscillator is on, ready to receive/transmit
//          MPM_CC2430_XOSC_OFF:          The CC2430 crystal oscillator is off (startup time ~1 ms)
//          MPM_CC2430_XOSC_AND_VREG_OFF: The CC2430 voltage regulator is off (startup time ~1.6 ms)
//
//          Note: Nothing will happen if the current state is MPM_CC2430_XOSC_AND_VREG_OFF, and the new
//          mode is MPM_CC2430_XOSC_OFF.
//-------------------------------------------------------------------------------------------------------
ROOT void mpmSetRequest(BYTE mode);


//-------------------------------------------------------------------------------------------------------
//  void mpmSetRequest(BYTE mode)
//
//  DESCRIPTION:
//      Confirms that the CC2430 power mode change initiated by mpmSetRequest has become effective
//
//  ARGUMENTS:
//      BYTE status
//          OK_POWER_MODE_CHANGED:   The power mode was changed
//          OK_POWER_MODE_UNCHANGED: No change was required
//          ERR_RX_ON_WHEN_IDLE:     Could not proceed because "RX on when idle" was enabled
//-------------------------------------------------------------------------------------------------------
ROOT void mpmSetConfirm(BYTE status);


//-------------------------------------------------------------------------------------------------------
//  BYTE mpmGetState(void)
//
//  DESCRIPTION:
//      Returns the current power state when it has become effective (after a call to mpmSetRequest)
//
//  RETURN VALUE:
//      BYTE
//          MPM_CC2430_ON:                The CC2430 crystal oscillator is on, ready to receive/transmit
//          MPM_CC2430_XOSC_OFF:          The CC2430 crystal oscillator is off
//          MPM_CC2430_XOSC_AND_VREG_OFF: The CC2430 voltage regulator is off
//-------------------------------------------------------------------------------------------------------
ROOT BYTE mpmGetState(void);


//-------------------------------------------------------------------------------------------------------
//  ROOT mpmSetAndResumeMacAndCpuPowerMode (POWER_MODE  powerMode,
//                                          RESUME_MODE resumeMode,
//                                          BOOL        synchronousStart)
//
//  DESCRIPTION:
//      Turns off MAC, radio and sets CPU in correct power.  The CPU will halt in this routine.
//      Processing is resumed when an external interrupt or a sleep timer interrupt occurs. Mac processing
//      is also resumed as part of this routine. RxOnWhenIdle is restored to its value prior to the call
//      of this routine.
//      The external interrupt or the sleep timer interrupt must be intialized prior to the call of this
//      routine.
//
//  ARGUMENTS:
//      POWER_MODE  powerMode
//          Power mode according to data sheet for CC2430
//          POWER_MODE_PM1      Voltage regulator to the digital part is on. High speed oscillator is off,
//                              low speed oscillator is on
//          POWER_MODE_PM2      Voltage regulator to the digital part is off. High speed oscillator is off,
//                              low speed oscillator is on
//          POWER_MODE_PM3      Voltage regulator to the digital part is off. All oscillators is off.
//
//      RESUME_MODE resumeMode
//          Depends on how much of the MAC variables that was preserved during power down. In power control
//          PM1 or when all data are places in upper 4 kRAM, RESUME_MODE_ALL_PRESERVED can be used. The
//          XDATA segment and the PM0_XDATAsegment must be located in upper 4 kRAM.
//          If the PM0_XDATAsegment is located in lower 4 kRAM and XDATA in upper 4 kRAM,
//          the RESUME_MODE_PARTS_PRESERVED must be used.
//          RESUME_MODE_ALL_PRESERVED,      restarts only timer2
//          RESUME_MODE_PARTS_PRESERVED     restarts timer2, the task and memory pool system
//
//      BOOL synchronousStart
//          FALSE  Start timer2 immediate
//          TRUE   Start timer2 synchronous with external 32.768 kHz clock
//
//-------------------------------------------------------------------------------------------------------
ROOT void mpmSetAndResumeMacAndCpuPowerMode (POWER_MODE  powerMode,
                                             RESUME_MODE resumeMode,
                                             BOOL        synchronousStart);


//-------------------------------------------------------------------------------------------------------
//  ROOT void mpmPowerDownMac (BYTE *rxOnWhenIdle)
//
//  DESCRIPTION:
//      Stops MAC prosessing and turns the radio off.
//
//  ARGUMENTS:
//      BYTE rxOnWhenIdle
//          Contains the value of rxOnWhenIdle prior to power down
//
//-------------------------------------------------------------------------------------------------------
ROOT void mpmPowerDownMac (BYTE *rxOnWhenIdle);


//-------------------------------------------------------------------------------------------------------
//  void mpmResumeMacAfterPowerDown (RESUME_MODE resumeMode,
//                                   BOOL        synchronousStart,
//                                   BOOL        rxOnWhenIdle)
//
//  DESCRIPTION:
//      Resumes the mac protocol after a power down
//
//  ARGUMENTS:
//      RESUME_MODE resumeMode
//          Depends on how much of the MAC variables that was preserved during power down. In power control
//          PM1 or when all data are places in upper 4 kRAM, RESUME_MODE_ALL_PRESERVED can be used. The
//          XDATA segment and the PM0_XDATAsegment must be located in upper 4 kRAM.
//          If the PM0_XDATAsegment is located in lower 4 kRAM and XDATA in upper 4 kRAM,
//          the RESUME_MODE_PARTS_PRESERVED must be used.
//          RESUME_MODE_ALL_PRESERVED,      restarts only timer2. The fastest and less power consuming mode
//          RESUME_MODE_PARTS_PRESERVED     restarts timer2, the task and memory pool system
//
//      BOOL synchronousStart
//          FALSE  Start timer2 immediate
//          TRUE   Start timer2 synchronous with external 32.768 kHz clock
//
//      BOOL rxOnWhenIdle
//          FALSE  RX is off
//          TRUE   Turn RX on
//-------------------------------------------------------------------------------------------------------
ROOT void mpmResumeMacAfterPowerDown (RESUME_MODE resumeMode,
                                      BOOL        synchronousStart,
                                      BOOL        rxOnWhenIdle);


//-------------------------------------------------------------------------------------------------------
// Internal functions

// Power up/down
ROOT void mpmTurnOnVregAndReset(void);
ROOT void mpmTurnOffReset(void);
ROOT void mpmTurnOnXosc(void);
ROOT void mpmTurnOffVreg(void);
ROOT void mpmTurnOffXosc(void);

// Restores all CC2430 registers and RAM, assuming that there was no activity in the MAC layer at power-
// down
ROOT void mpmRestoreRegsAndRam(void);
//-------------------------------------------------------------------------------------------------------


#endif

⌨️ 快捷键说明

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