📄 mac_power_management.s51
字号:
// 135 mpmSetConfirm(ERR_RX_ON_WHEN_IDLE);
// 136 return;
// 137 }
// 138
// 139 // Come back later if we're not in the default MAC state (there's something going on...)
// 140 if (macInfo.state != MAC_STATE_DEFAULT) {
// 141 mschRescheduleTask(pTask, 0);
// 142 return;
// 143 }
// 144
// 145 // Switch to the new power mode
// 146 mpmInfo.selectedMode = (BYTE) pTask->taskData;
// 147
// 148 // In a beacon-enabled network the beacon handler will control powerup and powerdown
// 149 // In a non-beacon network the changes will be made directly from here:
// 150 switch (mpmInfo.selectedMode) {
// 151 case MPM_CC2430_ON:
// 152
// 153 // Turn on VREG?
// 154 if (mpmInfo.currentState == MPM_CC2430_XOSC_AND_VREG_OFF) {
// 155 mpmTurnOnVregAndReset();
// 156 }
// 157
// 158 /*
// 159 // Restore registers and RAM if the voltage regulator was turned off
// 160 if (mpmInfo.currentState == MPM_CC2430_XOSC_AND_VREG_OFF) {
// 161 mpmRestoreRegsAndRam();
// 162 }
// 163 */
// 164
// 165 // Turn on XOSC?
// 166 if (mpmInfo.currentState != MPM_CC2430_ON) {
// 167 mpmTurnOnXosc();
// 168 }
// 169
// 170 mrxInfo.keepFifopIntOff = FALSE;
// 171
// 172 mpmInfo.currentState = MPM_CC2430_ON;
// 173 break;
// 174
// 175 case MPM_CC2430_XOSC_OFF:
// 176 T2_STOP();
// 177 mrxInfo.keepFifopIntOff = TRUE;
// 178 mpmTurnOffXosc();
// 179 break;
// 180
// 181 case MPM_CC2430_XOSC_AND_VREG_OFF:
// 182 T2_STOP();
// 183 mrxInfo.keepFifopIntOff = TRUE;
// 184 mpmTurnOffVreg();
// 185 break;
// 186 }
// 187
// 188 // Update with the new transceiver state
// 189 mpmInfo.currentState = mpmInfo.selectedMode;
// 190
// 191 // Clean up and make the callback
// 192 mschRemoveTask(pTask->priority, 0);
// 193 mpmSetConfirm(OK_POWER_MODE_CHANGED);
// 194
// 195 } // mpmSetTask
// 196
// 197
// 198
// 199
// 200 //-------------------------------------------------------------------------------------------------------
// 201 // void mpmSetRequest(BYTE mode)
// 202 //
// 203 // DESCRIPTION:
// 204 // This function allows the higher layer to power down CC2430 to extend battery lifetime. CC2430
// 205 // must be powered up before any MLME or MCPS primitives can be used (both beacon/non-beacon modes).
// 206 // Power-down is currently only supported for non-beacon PANs.
// 207 //
// 208 // The change is not likely to happen instantaneously (under normal conditions the delay can be up
// 209 // to 320 us). Use either the mpmSetConfirm callback, or poll the current power state by using
// 210 // mpmGetState() (returns the selected power mode when it has become effective).
// 211 //
// 212 // ARGUMENTS:
// 213 // BYTE mode
// 214 // MPM_CC2430_ON: The CC2430 crystal oscillator is on, ready to receive/transmit
// 215 // MPM_CC2430_XOSC_OFF: The CC2430 crystal oscillator is off (startup time ~1 ms)
// 216 // MPM_CC2430_XOSC_AND_VREG_OFF: The CC2430 voltage regulator is off (startup time ~1.6 ms)
// 217 //
// 218 // Note: Nothing will happen if the current state is MPM_CC2430_XOSC_AND_VREG_OFF, and the new
// 219 // mode is MPM_CC2430_XOSC_OFF.
// 220 //-------------------------------------------------------------------------------------------------------
RSEG NEAR_CODE:CODE:NOROOT(0)
// 221 ROOT void mpmSetRequest(BYTE mode) {
mpmSetRequest:
CFI Block cfiBlock7 Using cfiCommon0
CFI Function mpmSetRequest
FUNCALL mpmSetRequest, mpmSetConfirm
LOCFRAME XSTACK, 10, STACK
ARGFRAME XSTACK, 10, STACK
FUNCALL mpmSetRequest, mschReserveTask
LOCFRAME XSTACK, 10, STACK
ARGFRAME XSTACK, 10, STACK
FUNCALL mpmSetRequest, mschAddTask
LOCFRAME XSTACK, 13, STACK
ARGFRAME XSTACK, 13, STACK
MOV A,#-0xa
LCALL ?FUNC_ENTER_XDATA
CFI DPH0 load(1, XDATA, add(CFA_XSP16, literal(-1)))
CFI DPL0 load(1, XDATA, add(CFA_XSP16, literal(-2)))
CFI ?RET_HIGH load(1, XDATA, add(CFA_XSP16, literal(-3)))
CFI ?RET_LOW load(1, XDATA, add(CFA_XSP16, literal(-4)))
CFI R7 load(1, XDATA, add(CFA_XSP16, literal(-5)))
CFI V2 load(1, XDATA, add(CFA_XSP16, literal(-6)))
CFI V1 load(1, XDATA, add(CFA_XSP16, literal(-7)))
CFI V0 load(1, XDATA, add(CFA_XSP16, literal(-8)))
CFI VB load(1, XDATA, add(CFA_XSP16, literal(-9)))
CFI R6 load(1, XDATA, add(CFA_XSP16, literal(-10)))
CFI CFA_SP SP+0
CFI CFA_XSP16 add(XSP16, 10)
; Saved register size: 10
; Auto size: 0
MOV A,R1
MOV R6,A
// 222 BYTE taskNumber;
// 223
// 224 // Any changes?
// 225 if (mode == mpmInfo.selectedMode) {
MOV DPTR,#(mpmInfo + 1)
MOVX A,@DPTR
XRL A,R6
JNZ ??mpmSetRequest_0
// 226 mpmSetConfirm(OK_POWER_MODE_UNCHANGED);
; Setup parameters for call to function mpmSetConfirm
MOV R1,#0x1
LCALL mpmSetConfirm
SJMP ??mpmSetRequest_1
// 227 } else {
// 228
// 229 // Reserve the task to be used
// 230 do {
// 231 taskNumber = mschReserveTask();
??mpmSetRequest_0:
; Setup parameters for call to function mschReserveTask
LCALL mschReserveTask
// 232 } while (taskNumber == NO_TASK);
MOV A,#-0x1
XRL A,R1
JZ ??mpmSetRequest_0
// 233
// 234 mschAddTask(taskNumber, MAC_TASK_PRI_LOW, mpmSetTask, (WORD)mode);
; Setup parameters for call to function mschAddTask
MOV ?V0 + 0,#(mpmSetTask & 0xff)
MOV ?V0 + 1,#((mpmSetTask >> 8) & 0xff)
MOV ?V0 + 2,#((mpmSetTask >> 16) & 0xff)
MOV R0,#?V0 + 0
LCALL ?PUSH_XSTACK_I_THREE
CFI CFA_XSP16 add(XSP16, 13)
MOV A,R6
MOV R4,A
MOV R5,#0x0
MOV R2,#0x0
LCALL mschAddTask
MOV A,#0x3
LCALL ?DEALLOC_XSTACK8
CFI CFA_XSP16 add(XSP16, 10)
// 235 }
// 236
// 237 } // mpmSetRequest
??mpmSetRequest_1:
MOV R7,#0x3
LJMP ?FUNC_LEAVE_XDATA
CFI EndBlock cfiBlock7
// 238
// 239
// 240
// 241
// 242 //-------------------------------------------------------------------------------------------------------
// 243 // BYTE mpmGetState(void)
// 244 //
// 245 // DESCRIPTION:
// 246 // Returns the current power state when it has become effective (after a call to mpmSetRequest)
// 247 //
// 248 // RETURN VALUE:
// 249 // BYTE
// 250 // MPM_CC2430_ON: The CC2430 crystal oscillator is on, ready to receive/transmit
// 251 // MPM_CC2430_XOSC_OFF: The CC2430 crystal oscillator is off
// 252 // MPM_CC2430_XOSC_AND_VREG_OFF: The CC2430 voltage regulator is off
// 253 //-------------------------------------------------------------------------------------------------------
RSEG NEAR_CODE:CODE:NOROOT(0)
// 254 ROOT BYTE mpmGetState(void) {
mpmGetState:
CFI Block cfiBlock8 Using cfiCommon0
CFI Function mpmGetState
PUSH DPL
CFI DPL0 Frame(CFA_SP, 3)
CFI CFA_SP SP+-3
PUSH DPH
CFI DPH0 Frame(CFA_SP, 4)
CFI CFA_SP SP+-4
; Saved register size: 2
; Auto size: 0
// 255 return mpmInfo.currentState;
MOV DPTR,#mpmInfo
MOVX A,@DPTR
MOV R1,A
SJMP ??Subroutine0_0
CFI EndBlock cfiBlock8
// 256 } // mpmGetState
// 257
// 258
// 259 //-------------------------------------------------------------------------------------------------------
// 260 // ROOT mpmSetAndResumeMacAndCpuPowerMode (POWER_MODE powerMode,
// 261 // RESUME_MODE resumeMode,
// 262 // BOOL synchronousStart)
// 263 //
// 264 // DESCRIPTION:
// 265 // Turns off MAC, radio and sets CPU in correct power. The CPU will halt in this routine.
// 266 // Processing is resumed when an external interrupt or a sleep timer interrupt occurs. Mac processing
// 267 // is also resumed as part of this routine. RxOnWhenIdle is restored to its value prior to the call
// 268 // of this routine.
// 269 // The external interrupt or the sleep timer interrupt must be intialized prior to the call of this
// 270 // routine.
// 271 //
// 272 // ARGUMENTS:
// 273 // POWER_MODE powerMode
// 274 // Power mode according to data sheet for CC2430
// 275 // POWER_MODE_PM1 Voltage regulator to the digital part is on. High speed oscillator is off,
// 276 // low speed oscillator is on
// 277 // POWER_MODE_PM2 Voltage regulator to the digital part is off. High speed oscillator is off,
// 278 // low speed oscillator is on
// 279 // POWER_MODE_PM3 Voltage regulator to the digital part is off. All oscillators is off.
// 280 //
// 281 // RESUME_MODE resumeMode
// 282 // Depends on how much of the MAC variables that was preserved during power down. In power control
// 283 // PM1 or when all data are places in upper 4 kRAM, RESUME_MODE_ALL_PRESERVED can be used. The
// 284 // XDATA segment and the PM0_XDATA segment must be located in upper 4 kRAM.
// 285 // If the PM0_XDATA segment is located in lower 4 kRAM and XDATA in upper 4 kRAM,
// 286 // the RESUME_MODE_PARTS_PRESERVED must be used.
// 287 // RESUME_MODE_ALL_PRESERVED, restarts only timer2
// 288 // RESUME_MODE_PARTS_PRESERVED restarts timer2, the task and memory pool system
// 289 //
// 290 // BOOL synchronousStart
// 291 // FALSE Start timer2 immediate
// 292 // TRUE Start timer2 synchronous with external 32.768 kHz clock
// 293 //
// 294 //-------------------------------------------------------------------------------------------------------
RSEG NEAR_CODE:CODE:NOROOT(0)
// 295 ROOT void mpmSetAndResumeMacAndCpuPowerMode (POWER_MODE powerMode,
mpmSetAndResumeMacAndCpuPowerMode:
CFI Block cfiBlock9 Using cfiCommon0
CFI Function mpmSetAndResumeMacAndCpuPowerMode
// 296 RESUME_MODE resumeMode,
// 297 BOOL synchronousStart)
// 298 {
FUNCALL mpmSetAndResumeMacAndCpuPowerMode, mpmPowerDownMac
LOCFRAME XSTACK, 9, STACK
ARGFRAME XSTACK, 9, STACK
FUNCALL mpmSetAndResumeMacAndCpuPowerMode, mpmResumeMacAfterPowerDown
LOCFRAME XSTACK, 9, STACK
ARGFRAME XSTACK, 9, STACK
MOV A,#-0x8
LCALL ?FUNC_ENTER_XDATA
CFI DPH0 load(1, XDATA, add(CFA_XSP16, literal(-1)))
CFI DPL0 load(1, XDATA, add(CFA_XSP16, literal(-2)))
CFI ?RET_HIGH load(1, XDATA, add(CFA_XSP16, literal(-3)))
CFI ?RET_LOW load(1, XDATA, add(CFA_XSP16, literal(-4)))
CFI R7 load(1, XDATA, add(CFA_XSP16, literal(-5)))
CFI V0 load(1, XDATA, add(CFA_XSP16, literal(-6)))
CFI VB load(1, XDATA, add(CFA_XSP16, literal(-7)))
CFI R6 load(1, XDATA, add(CFA_XSP16, literal(-8)))
CFI CFA_SP SP+0
CFI CFA_XSP16 add(XSP16, 8)
; Saved register size: 8
; Auto size: 1
MOV A,#-0x1
LCALL ?ALLOC_XSTACK8
CFI CFA_XSP16 add(XSP16, 9)
MOV A,R1
MOV R6,A
MOV A,R2
MOV R7,A
MOV ?V0 + 0,R3
// 299 BYTE rxOnWhenIdle;
// 300
// 301 mpmPowerDownMac (&rxOnWhenIdle);
; Setup parameters for call to function mpmPowerDownMac
MOV DPL,?XSP + 0
MOV DPH,?XSP + 1
MOV R2,DPL
MOV R3,DPH
LCALL mpmPowerDownMac
// 302
// 303 // Power down cpu
// 304 SLEEP &= 0xFC;
ANL 0xbe,#0xfc
MOV A,0xbe
// 305
// 306 switch (powerMode)
MOV A,R6
LCALL ?UC_SWITCH_DENSE
`?<Jumptable for mpmSetAndResumeMacAndCpuPowerM_0`:
DB 0
DB 2
DW ??mpmSetAndResumeMacAndCpuPowerMode_0
DW ??mpmSetAndResumeMacAndCpuPowerMode_1
DW ??mpmSetAndResumeMacAndCpuPowerMode_2
DW ??mpmSetAndResumeMacAndCpuPowerMode_3
// 307 {
// 308 case POWER_MODE_PM1:
// 309 SLEEP |= CC2430_PM1;
??mpmSetAndResumeMacAndCpuPowerMode_1:
ORL 0xbe,#0x1
SJMP ??mpmSetAndResumeMacAndCpuPowerMode_0
// 310 break;
// 311
// 312 case POWER_MODE_PM2:
// 313 SLEEP |= CC2430_PM2;
??mpmSetAndResumeMacAndCpuPowerMode_2:
ORL 0xbe,#0x2
SJMP ??mpmSetAndResumeMacAndCpuPowerMode_0
// 314 break;
// 315
// 316 case POWER_MODE_PM3:
// 317 SLEEP |= CC2430_PM3;
??mpmSetAndResumeMacAndCpuPowerMode_3:
ORL 0xbe,#0x3
MOV A,0xbe
// 318 break;
// 319
// 320 }
// 321
// 322 PCON = 1;
??mpmSetAndResumeMacAndCpuPowerMode_0:
MOV 0x87,#0x1
// 323 // CPU will HALT here. Processing is resumed when an external interrupt or a sleep timer interrupt
// 324 // occurs
// 325
// 326 // Correction of active power up bug
// 327 asm("NOP");
NOP
// 328 asm("NOP");
NOP
// 329 mpmResumeMacAfterPowerDown (resumeMode,
// 330 synchronousStart,
// 331 rxOnWhenIdle);
; Setup parameters for call to function mpmResumeMacAfterPowerDown
MOV DPL,?XSP + 0
MOV DPH,?XSP + 1
MOVX A,@DPTR
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -