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

📄 mac_power_management.c

📁 ucos在NEC平台下的移植
💻 C
字号:
#pragma  section @@DATA power at 0xF100

#include "includes.h"
 
//-------------------------------------------------------------------------------------------------------
// Internal module data
MPM_INFO mpmInfo;
//-------------------------------------------------------------------------------------------------------


//-------------------------------------------------------------------------------------------------------
// Internal module function
void mpmSetTask(MAC_TASK_INFO *pTask);
//-------------------------------------------------------------------------------------------------------
//



//-------------------------------------------------------------------------------------------------------
// Simple power up/down functions
void mpmTurnOnVregAndReset(void)  
{
	//DISABLE_GLOBAL_INT();
	//SET_RESET_ACTIVE();
	//SET_VREG_ACTIVE();
	//ENABLE_GLOBAL_INT();  --li
}
void mpmTurnOffReset(void)       
{
	//DISABLE_GLOBAL_INT();
	//SET_RESET_INACTIVE();
	//ENABLE_GLOBAL_INT();  --li
}
void mpmTurnOnXosc(void)    
{
	//DISABLE_GLOBAL_INT();
	//FASTSPI_STROBE(CC2420_SXOSCON);
	//ENABLE_GLOBAL_INT();  --li
}
void mpmTurnOffVreg(void)     
{ 
	//DISABLE_GLOBAL_INT();
	//SET_RESET_ACTIVE();
	//SET_VREG_INACTIVE();
	//ENABLE_GLOBAL_INT();  --li
}
void mpmTurnOffXosc(void)   
{
	//DISABLE_GLOBAL_INT();
	//FASTSPI_STROBE(CC2420_SXOSCOFF);
	//ENABLE_GLOBAL_INT();  --li
}
//-------------------------------------------------------------------------------------------------------




//-------------------------------------------------------------------------------------------------------
//  void mpmRestoreRegsAndRam(void)
//
//  DESCRIPTION:
//      Restores all CC2420 registers and RAM, assuming that there was no activity in the MAC layer at 
//      power-down. That includes:
//          MDMCTRL0 (register) (PAN coordinator bit)
//          MDMCTRL1 (register) (Correlation threshold, only required by old chip revisions, see data 
//              sheets)
//          SECCTRL0 (register)
//          PANID (RAM) 
//          IEEEADDR (RAM) 
//          SHORTADDR (RAM)
//          FSCTRL (register)
//-------------------------------------------------------------------------------------------------------
void mpmRestoreRegsAndRam(void) {
//    WORD oldRegVal;
//    
//    // Write default register values     
//    DISABLE_GLOBAL_INT();
//#if MAC_OPT_FFD
//    FASTSPI_SETREG(CC2420_MDMCTRL0, GET_MF(MF_PAN_COORDINATOR) ? 0x0BE2 : 0x0AE2);
//#endif
//    FASTSPI_SETREG(CC2420_MDMCTRL1, 0x0500);
//    FASTSPI_SETREG(CC2420_IOCFG0, 0x0203);
//#if MAC_OPT_SECURITY
//    FASTSPI_SETREG(CC2420_SECCTRL0, CC2420_SECCTRL0_RXFIFO_PROTECTION | CC2420_SECCTRL0_SEC_CBC_HEAD | CC2420_SECCTRL0_NO_SECURITY);
//#else
//    FASTSPI_SETREG(CC2420_SECCTRL0, CC2420_SECCTRL0_NO_SECURITY);
//#endif
//    FASTSPI_GETREG(CC2420_RXCTRL1, oldRegVal);    
//    oldRegVal |= 0x2000;
//    FASTSPI_SETREG(CC2420_RXCTRL1, oldRegVal);    
//    ENABLE_GLOBAL_INT();
//    
//    // PAN ID, extended and short addresses
//    msupWriteRam(&mpib.macPANId, CC2420RAM_PANID, 2, TRUE);
//    msupWriteRam(&aExtendedAddress, CC2420RAM_IEEEADDR, 8, TRUE);
//    msupWriteRam(&mpib.macShortAddress, CC2420RAM_SHORTADDR, 2, TRUE);
//    
//    // Frequency word
//    msupSetChannel(ppib.phyCurrentChannel, FALSE);  --li

} // mpmRestoreRegsAndRam




//-------------------------------------------------------------------------------------------------------
//  void mpmSetTask(MAC_TASK_INFO *pTask)
//
//  DESCRIPTION:
//      This task is responsible for controlling CC2420 power, as requested by the higher layer through
//      mpmSetRequest. Power-down is currently only supported for non-beacon PANs.
//
//  TASK DATA:
//      The new power mode (MPM_CC2420_ON, MPM_CC2420_XOSC_OFF, or MPM_CC2420_XOSC_AND_VREG_OFF)
//-------------------------------------------------------------------------------------------------------
void mpmSetTask(MAC_TASK_INFO *pTask) {
    
    //// Powerdown is not permitted in non-beacon mode when "RX on when idle" is enabled
    //if ((mpib.macBeaconOrder == 15) && mpib.macRxOnWhenIdle) {
    //    mschRemoveTask(pTask->priority, 0);
    //    mpmSetConfirm(ERR_RX_ON_WHEN_IDLE);
    //    return;
    //}

    //// Come back later if we're not in the default MAC state (there's something going on...)
    //if (macInfo.state != MAC_STATE_DEFAULT) {
    //    mschRescheduleTask(pTask, 0);
    //    return;
    //}

    //// Switch to the new power mode
    //mpmInfo.selectedMode = (BYTE) pTask->taskData;

    //// In a beacon-enabled network the beacon handler will control powerup and powerdown
    //// In a non-beacon network the changes will be made directly from here:
    //switch (mpmInfo.selectedMode) {
    //case MPM_CC2420_ON:
    //        
    //    // Turn on VREG?
    //    if (mpmInfo.currentState == MPM_CC2420_XOSC_AND_VREG_OFF) {
    //        mpmTurnOnVregAndReset();
    //        halWait(MPM_VREG_TURN_ON_TIME);
    //        mpmTurnOffReset();                
    //    }
    //    
    //    // Turn on XOSC?
    //    if (mpmInfo.currentState != MPM_CC2420_ON) {
    //        mpmTurnOnXosc();
    //        halRfWaitForCrystalOscillator();
    //    }
    //    
    //    // Restore registers and RAM if the voltage regulator was turned off
    //    if (mpmInfo.currentState == MPM_CC2420_XOSC_AND_VREG_OFF) {
    //        mpmRestoreRegsAndRam();
    //    }

    //    mrxInfo.keepFifopIntOff = FALSE;
    //    ENABLE_FIFOP_INT();
    //    
    //    mpmInfo.currentState = MPM_CC2420_ON;
    //    break;
    //    
    //case MPM_CC2420_XOSC_OFF:
    //    TIMER1_STOP();
    //    DISABLE_FIFOP_INT();
    //    mrxInfo.keepFifopIntOff = TRUE;
    //    mpmTurnOffXosc();
    //    break;
    //    
    //case MPM_CC2420_XOSC_AND_VREG_OFF:
    //    TIMER1_STOP();
    //    DISABLE_FIFOP_INT();
    //    mrxInfo.keepFifopIntOff = TRUE;
    //    mpmTurnOffVreg();
    //    break;
    //}
    //
    //// Update with the new transceiver state
    //mpmInfo.currentState = mpmInfo.selectedMode;
    //
    //// Clean up and make the callback
    //mschRemoveTask(pTask->priority, 0);
    //mpmSetConfirm(OK_POWER_MODE_CHANGED);  --li
    
} // mpmSetTask




//-------------------------------------------------------------------------------------------------------
//  void mpmSetRequest(BYTE mode)
//
//  DESCRIPTION:
//      This function allows the higher layer to power down CC2420 to extend battery lifetime. CC2420
//      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_CC2420_ON:                The CC2420 crystal oscillator is on, ready to receive/transmit
//          MPM_CC2420_XOSC_OFF:          The CC2420 crystal oscillator is off (startup time ~1 ms)
//          MPM_CC2420_XOSC_AND_VREG_OFF: The CC2420 voltage regulator is off (startup time ~1.6 ms)
//
//          Note: Nothing will happen if the current state is MPM_CC2420_XOSC_AND_VREG_OFF, and the new
//          mode is MPM_CC2420_XOSC_OFF.
//-------------------------------------------------------------------------------------------------------
void mpmSetRequest(BYTE mode) {
    //UINT8 taskNumber;
    //
    //// Any changes?
    //if (mode == mpmInfo.selectedMode) {
    //    mpmSetConfirm(OK_POWER_MODE_UNCHANGED);
    //} else {
    //    
    //    // Reserve the task to be used
    //    do {
    //        taskNumber = mschReserveTask();
    //    } while (taskNumber == NO_TASK);
    //    
    //    // Start the timer so that the task will be executed
    //    if (mpmInfo.selectedMode != MPM_CC2420_ON) TIMER1_START(TIMER1_CLK_DIV1);
    //    mschAddTask(taskNumber, MAC_TASK_PRI_LOW, mpmSetTask, mode);
    //}  --li

} // mpmSetRequest




//-------------------------------------------------------------------------------------------------------
//  BYTE mpmGetState(void)
//
//  DESCRIPTION:
//      Returns the current power state when it has become effective (after a call to mpmSetRequest)
//
//  RETURN VALUE:
//      BYTE
//          MPM_CC2420_ON:                The CC2420 crystal oscillator is on, ready to receive/transmit
//          MPM_CC2420_XOSC_OFF:          The CC2420 crystal oscillator is off
//          MPM_CC2420_XOSC_AND_VREG_OFF: The CC2420 voltage regulator is off
//-------------------------------------------------------------------------------------------------------
BYTE mpmGetState(void) {
    return mpmInfo.currentState;
} // mpmGetState




/*******************************************************************************************************
 * Revision history:
 *
 * $Log: mac_power_management.c,v $
 * Revision 1.9  2005/03/01 12:42:51  thl
 * Inn CC2420_RXCTRL1 the RXBPF_LOCUR is now enabled,
 * result is about 1,2-1,5mA reduction in RX current for the chip.
 *
 * Revision 1.8  2004/11/18 15:07:58  thl
 * Added support for pending frame bit in outgoing data frames.
 * Only apply to outgoing data frames and wherer the address matches
 * one or more packet in the indirect packet quee.
 *
 * Revision 1.7  2004/11/10 09:33:14  thl
 * Fixed a number of bugs according to: MAC software check lists.xls
 *
 * Revision 1.6  2004/08/13 13:04:46  jol
 * CC2420 MAC Release v0.7
 *
 *
 *******************************************************************************************************/

⌨️ 快捷键说明

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