hal_sleep.s51

来自「TI的基于ZIGBEE2006的协议栈」· S51 代码 · 共 1,601 行 · 第 1/5 页

S51
1,601
字号
        CFI R6 SameValue
        CFI R7 SameValue
        CFI V0 SameValue
        CFI V1 SameValue
        CFI V2 SameValue
        CFI V3 SameValue
        CFI V4 SameValue
        CFI V5 SameValue
        CFI V6 SameValue
        CFI V7 SameValue
        CFI PSPH Undefined
        CFI PSPL Undefined
        CFI XSPH Undefined
        CFI XSPL Undefined
        CFI ?RET Concat
        CFI ?BRET_EXT Frame(CFA_SP, 3)
        CFI ?RET_HIGH Frame(CFA_SP, 2)
        CFI ?RET_LOW Frame(CFA_SP, 1)
        CFI EndCommon cfiCommon0
        
        
        CFI Common cfiCommon1 Using cfiNames0
        CFI CodeAlign 1
        CFI DataAlign -1
        CFI ReturnAddress ?RET CODE
        CFI CFA_DOVERLAY Used
        CFI CFA_IOVERLAY Used
        CFI CFA_SP SP+-2
        CFI CFA_PSP16 PSP16+0
        CFI CFA_XSP16 XSP16+0
        CFI `PSW.CY` SameValue
        CFI `B.BR0` SameValue
        CFI `B.BR1` SameValue
        CFI `B.BR2` SameValue
        CFI `B.BR3` SameValue
        CFI `B.BR4` SameValue
        CFI `B.BR5` SameValue
        CFI `B.BR6` SameValue
        CFI `B.BR7` SameValue
        CFI `VB.BR8` SameValue
        CFI `VB.BR9` SameValue
        CFI `VB.BR10` SameValue
        CFI `VB.BR11` SameValue
        CFI `VB.BR12` SameValue
        CFI `VB.BR13` SameValue
        CFI `VB.BR14` SameValue
        CFI `VB.BR15` SameValue
        CFI VB SameValue
        CFI B SameValue
        CFI A SameValue
        CFI PSW SameValue
        CFI DPL0 SameValue
        CFI DPH0 SameValue
        CFI R0 SameValue
        CFI R1 SameValue
        CFI R2 SameValue
        CFI R3 SameValue
        CFI R4 SameValue
        CFI R5 SameValue
        CFI R6 SameValue
        CFI R7 SameValue
        CFI V0 SameValue
        CFI V1 SameValue
        CFI V2 SameValue
        CFI V3 SameValue
        CFI V4 SameValue
        CFI V5 SameValue
        CFI V6 SameValue
        CFI V7 SameValue
        CFI PSPH Undefined
        CFI PSPL Undefined
        CFI XSPH Undefined
        CFI XSPL Undefined
        CFI ?RET Concat
        CFI ?BRET_EXT SameValue
        CFI ?RET_HIGH Frame(CFA_SP, 2)
        CFI ?RET_LOW Frame(CFA_SP, 1)
        CFI EndCommon cfiCommon1
        
halSleepTimerIsr    SYMBOL "halSleepTimerIsr"
`halSleepTimerIsr??INTVEC 43` SYMBOL "??INTVEC 43", halSleepTimerIsr

        EXTERN MAC_PwrNextTimeout
        FUNCTION MAC_PwrNextTimeout,0202H
        ARGFRAME XSTACK, 21, STACK
        EXTERN osalNextActiveTask
        FUNCTION osalNextActiveTask,0202H
        ARGFRAME XSTACK, 21, STACK
        EXTERN MAC_PwrOffReq
        FUNCTION MAC_PwrOffReq,0202H
        ARGFRAME XSTACK, 21, STACK
        EXTERN HalKeyEnterSleep
        FUNCTION HalKeyEnterSleep,0202H
        ARGFRAME XSTACK, 21, STACK
        EXTERN HalLedEnterSleep
        FUNCTION HalLedEnterSleep,0202H
        ARGFRAME XSTACK, 21, STACK
        EXTERN HalLedExitSleep
        FUNCTION HalLedExitSleep,0202H
        ARGFRAME XSTACK, 21, STACK
        EXTERN HalKeyExitSleep
        FUNCTION HalKeyExitSleep,0202H
        ARGFRAME XSTACK, 21, STACK
        EXTERN MAC_PwrOnReq
        FUNCTION MAC_PwrOnReq,0202H
        ARGFRAME XSTACK, 21, STACK
        EXTERN osal_adjust_timers
        FUNCTION osal_adjust_timers,0202H
        ARGFRAME XSTACK, 21, STACK

// C:\Texas Instruments\ZStack-1.4.2\Components\hal\target\CC2430EB\hal_sleep.c
//    1 /**************************************************************************************************
//    2     Filename:       hal_sleep.c
//    3     Revised:        $Date: 2007-05-15 15:37:47 -0700 (Tue, 15 May 2007) $
//    4     Revision:       $Revision: 14304 $
//    5 
//    6     Description:
//    7 
//    8     This module contains the HAL power management procedures for the CC2430.
//    9 
//   10 
//   11     Copyright (c) 2006 by Texas Instruments, Inc.
//   12     All Rights Reserved.  Permission to use, reproduce, copy, prepare
//   13     derivative works, modify, distribute, perform, display or sell this
//   14     software and/or its documentation for any purpose is prohibited
//   15     without the express written consent of Texas Instruments, Inc.
//   16 **************************************************************************************************/
//   17 
//   18 /* ------------------------------------------------------------------------------------------------
//   19  *                                          Includes
//   20  * ------------------------------------------------------------------------------------------------
//   21  */
//   22 #include "hal_types.h"
//   23 #include "hal_mcu.h"

        ASEGN SFR_AN:DATA:NOROOT,087H
// unsigned char volatile __sfr PCON
PCON:
        DS 1

        ASEGN SFR_AN:DATA:NOROOT,08fH
// unsigned char volatile __sfr P0INP
P0INP:
        DS 1

        ASEGN SFR_AN:DATA:NOROOT,095H
// unsigned char volatile __sfr ST0
ST0:
        DS 1

        ASEGN SFR_AN:DATA:NOROOT,096H
// unsigned char volatile __sfr ST1
ST1:
        DS 1

        ASEGN SFR_AN:DATA:NOROOT,097H
// unsigned char volatile __sfr ST2
ST2:
        DS 1

        ASEGN SFR_AN:DATA:NOROOT,09aH
// unsigned char volatile __sfr IEN2
IEN2:
        DS 1

        ASEGN SFR_AN:DATA:NOROOT,0beH
// unsigned char volatile __sfr SLEEP
SLEEP:
        DS 1

        ASEGN SFR_AN:DATA:NOROOT,0c6H
// unsigned char volatile __sfr CLKCON
CLKCON:
        DS 1

        ASEGN SFR_AN:DATA:NOROOT,0fdH
// unsigned char volatile __sfr P0DIR
P0DIR:
        DS 1
//   24 #include "hal_board.h"
//   25 #include "hal_sleep.h"
//   26 #include "hal_led.h"
//   27 #include "hal_key.h"
//   28 #include "mac_api.h"
//   29 #include "OSAL.h"
//   30 #include "OSAL_Timers.h"
//   31 #include "OSAL_Tasks.h"
//   32 #include "OSAL_PwrMgr.h"
//   33 #include "OnBoard.h"
//   34 #include "hal_drivers.h"
//   35 
//   36 #if !defined (RTR_NWK) && defined (NWK_AUTO_POLL)
//   37 #include "nwk_globals.h"
//   38 #include "ZGlobals.h"
//   39 #endif
//   40 
//   41 /* ------------------------------------------------------------------------------------------------
//   42  *                                           Macros
//   43  * ------------------------------------------------------------------------------------------------
//   44  */
//   45 
//   46 /* 32 kHz clock source select in CLKCON */
//   47 #if !defined (OSC32K_CRYSTAL_INSTALLED) || (defined (OSC32K_CRYSTAL_INSTALLED) && (OSC32K_CRYSTAL_INSTALLED == TRUE))
//   48 #define OSC_32KHZ                        0x00  /* external 32 KHz xosc */
//   49 #else
//   50 #define OSC_32KHZ                        0x80  /* internal 32 KHz rcosc */
//   51 #endif
//   52 
//   53 /* POWER CONSERVATION DEFINITIONS
//   54  * Sleep mode H/W definitions (enabled with POWER_SAVING compile option)
//   55  */
//   56 #define CC2430_PM0            0  /* PM0, Clock oscillators on, voltage regulator on */
//   57 #define CC2430_PM1            1  /* PM1, 32.768 kHz oscillators on, voltage regulator on */
//   58 #define CC2430_PM2            2  /* PM2, 32.768 kHz oscillators on, voltage regulator off */
//   59 #define CC2430_PM3            3  /* PM3, All clock oscillators off, voltage regulator off */
//   60 
//   61 /* HAL power management mode is set according to the power management state. The default
//   62  * setting is HAL_SLEEP_OFF. The actual value is tailored to different HW platform. Both
//   63  * HAL_SLEEP_TIMER and HAL_SLEEP_DEEP selections will:
//   64  *   1. turn off the system clock, and
//   65  *   2. halt the MCU.
//   66  * HAL_SLEEP_TIMER can be woken up by sleep timer interrupt, I/O interrupt and reset.
//   67  * HAL_SLEEP_DEEP can be woken up by I/O interrupt and reset.
//   68  */
//   69 #define HAL_SLEEP_OFF         CC2430_PM0
//   70 #define HAL_SLEEP_TIMER       CC2430_PM2
//   71 #define HAL_SLEEP_DEEP        CC2430_PM3
//   72 
//   73 /* MAX_SLEEP_TIME calculation:
//   74  *   Sleep timer maximum duration = 0xFFFF7F / 32768 Hz = 511.996 seconds
//   75  *   Round it to 510 seconds or 510000 ms
//   76  */
//   77 #define MAX_SLEEP_TIME                   510000             /* maximum time to sleep allowed by ST */
//   78 
//   79 /* minimum time to sleep, this macro is to:
//   80  * 1. avoid thrashing in-and-out of sleep with short OSAL timer (~2ms)
//   81  * 2. define minimum safe sleep period for different CC2430 revisions
//   82  * AN044 - MINIMUM SLEEP PERIODS WITH PULL-DOWN RESISTOR
//   83  */
//   84 #if !defined (PM_MIN_SLEEP_TIME)
//   85 #define PM_MIN_SLEEP_TIME                14                 /* default to minimum safe sleep time for CC2430 Rev B */
//   86 #endif
//   87 
//   88 /* to disallow PM2/PM3 and use PM1 only set this value to false
//   89  * AN044 - RESTRICT_USE_TO_PM1_ONLY
//   90  */
//   91 #if !defined (PM1_ONLY)
//   92 #define PM1_ONLY                         FALSE              /* default to no AN044 - RESTRICT USE TO PM1 ONLY */
//   93 #endif
//   94 
//   95 /* when a device is waken up be key interrupt, it
//   96  * should stay in PM1 for PM2_HOLDOFF_TIME expecting
//   97  * more key presses. When the timer is expired, the device
//   98  * is allowed to go back to PM2 sleep.
//   99  * AN044 - COMBINING POWER MODES
//  100  */
//  101 #if !defined (PM2_HOLDOFF_TIME)
//  102 #define PM2_HOLDOFF_TIME                 0
//  103 #endif
//  104 
//  105 /* Add code to set external interrupt line to output, drive the line to inactive level,
//  106  * delay for 180us (30us if P1.0 or P1.1), set the line to input as close to PCON.IDLE = 1
//  107  * as possible, and set the line tri-state. The following macro is using S1 key as an example.
//  108  * User should tailor this macro for different interrupt line(s). On CC2430EB or CC2430DB boards,
//  109  * the S1 key is mapped to P0.1. Thus 180us should be used for delays.
//  110  * AN044 - DELAYING EXTERNAL INTERRUPTS
//  111  */
//  112 #define EXTERNAL_INTERRUPT_DELAY()          st(P0DIR |= BV(1);    /* set P0.1 output */            \ 
//  113                                                P0_1 = 1;          /* drive P0.1 inactive (high) */ \ 
//  114                                                halSleepWait(180); /* delay 180us */                \ 
//  115                                                P0DIR &= ~BV(1);   /* set P0.1 input */             \ 
//  116                                                P0INP |= BV(1);)   /* set P0.1 tri-state */
//  117 
//  118 /* This value is used to adjust the sleep timer compare value such that the sleep timer
//  119  * compare takes into account the amount of processing time spent in function halSleep().
//  120  * The first value is determined by measuring the number of sleep timer ticks it from
//  121  * the beginning of the function to entering sleep mode.  The second value is determined
//  122  * by measuring the number of sleep timer ticks from exit of sleep mode to the call to
//  123  * osal_adjust_timers().
//  124  */
//  125 #define HAL_SLEEP_ADJ_TICKS   (9 + 25)
//  126 
//  127 #ifndef HAL_SLEEP_DEBUG_POWER_MODE
//  128 /* set CC2430 power mode; always use PM2 */
//  129 #define HAL_SLEEP_SET_POWER_MODE(mode)      st( if( CHVER <= REV_D )                    \ 
//  130                                                 {                                       \ 
//  131                                                   HAL_SLEEP_SET_POWER_MODE_REV_D(mode); \ 
//  132                                                 }                                       \ 
//  133                                                 else                                    \ 
//  134                                                 {                                       \ 
//  135                                                   HAL_SLEEP_SET_POWER_MODE_REV_E(mode); \ 
//  136                                                 }; )
//  137 #else
//  138 /* Debug: don't set power mode, just block until sleep timer interrupt */
//  139 #define HAL_SLEEP_SET_POWER_MODE(mode)      st( while(halSleepInt == FALSE); \ 
//  140                                                 halSleepInt = FALSE; )
//  141 #endif
//  142 
//  143 /* for revision E, this sw workaround require additional code in all
//  144  * ISR's that are used to wake up from PM.
//  145  */
//  146 #define HAL_SLEEP_SET_POWER_MODE_REV_E(mode) st( SLEEP &= ~0x03;  /* clear mode bits */               \ 
//  147                                                  SLEEP |= mode;   /* set mode bits   */               \ 
//  148                                                  asm("NOP");                                          \ 
//  149                                                  asm("NOP");                                          \ 
//  150                                                  asm("NOP");                                          \ 
//  151                                                  if( SLEEP & 0x03 )                                   \ 
//  152                                                  {                                                    \ 
//  153                                                    PCON |= 0x01;  /* enable mode */                   \ 
//  154                                                    asm("NOP");    /* first instruction after sleep*/  \ 
//  155                                                  }; )
//  156 
//  157 /* for revision D and earlier */
//  158 #define HAL_SLEEP_SET_POWER_MODE_REV_D(mode)   st(SLEEP &= ~0x03;  /* clear mode bits */               \ 
//  159                                                   SLEEP |= mode;   /* set mode bits   */               \ 
//  160                                                   PCON |= 0x01;    /* enable mode     */               \ 
//  161                                                   asm("NOP");)     /* first instruction after sleep*/
//  162 
//  163 /* set main clock source to crystal (exit sleep) */
//  164 #define HAL_SLEEP_SET_MAIN_CLOCK_CRYSTAL()  st(SLEEP &= ~0x04;          /* turn on both oscs */ \ 
//  165                                                while(!(SLEEP & 0x40));  /* wait for XOSC */     \ 

⌨️ 快捷键说明

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