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

📄 cc1110 sleep.txt

📁 讲述了CC1110sleep的设置
💻 TXT
📖 第 1 页 / 共 4 页
字号:
      }                                             \   
      U##spi##GCR |= (options & 0xE0);              \   
   } while(0)   
   
   
// Options for the SPI_SETUP macro.    
#define SPI_SLAVE              0x01    
#define SPI_MASTER             0x00    
#define SPI_CLOCK_POL_LO       0x00    
#define SPI_CLOCK_POL_HI       0x80    
#define SPI_CLOCK_PHA_0        0x00    
#define SPI_CLOCK_PHA_1        0x40    
#define SPI_TRANSFER_MSB_FIRST 0x20    
#define SPI_TRANSFER_MSB_LAST  0x00    
   
   
   
/******************************************************************************   
*******************       FLASH programming functions       *******************   
*******************************************************************************   
 _halFlashWritePage(...)_ writes a whole flash page. Because code memory cannot   
be read during flash write, the writing routines are copied to XDATA RAM. The   
function is implemented in assembly code with file extensions .s51 rather than .c   
   
The Direct Memory Access (DMA) may also be used for flash write.   
******************************************************************************/   
   
//Macro for erasing a given flash page    
#define FLASH_ERASE_PAGE(page) \    
   do{                         \   
      FADDRH = (page) << 1;    \   
      FADDRL = 0x00;           \   
      FLASH_CONFIG(ERASE);     \   
   }while (0)   
   
   
// Macro for configuring flash access and setting flash access mode.    
#define FLASH_CONFIG(options)     \    
   do {                           \   
      FWT  = ( 0x22 >> CLKSPD );  \   
      FCTL = options;             \   
   } while (0)   
// _options_ may be the following:    
#define READ_WHEN_NEED  0x00    
#define CONTINOUS_READ  0x10    
#define WRITE           0x02    
#define ERASE           0x01    
#define FLASH_BUSY      0x80    
   
/******************************************************************************  
* @fn  halFlashWritePage  
*  
* @brief  
*       This function writes a byte field in XDATA RAM to a given flash  
*       page. Normal program execution is run from flash. However during flash  
*       write, flash memory is not available for reading. To circumvent this  
*       problem the core operation of this procedure, namely the actual flash  
*       write procedure, is copied to XDATA RAM and run from there. The flash  
*       write procedure is copied to a 35 byte XDATA RAM buffer.  
*       Prior to a write the page is erased.  
*  
*       This function disables interrupts when running, and re-enables interrupt  
*       if interrupts were enabled at function entry.  
*  
* Parameters:  
*  
* @param  byte*  pSrcAddr  
*         Pointer to first byte in xdata space which is to be written to  
*         flash. The number of bytes a flash page consists of starting from  
*         this address will be written to the page _page_.  
* @param  byte*  pBuffer  
*         Pointer to a buffer of 35 bytes in XDATA RAM to which the flash  
*         write procedure  
*         can be copied.  
* @param  byte      page  
*         Indicates which of the flash pages the data is to be written to.  
*  
* @return void  
*  
******************************************************************************/   
void halFlashWritePage(byte *pSrcAddr, byte *pBuffer, byte page);   
   
   
/******************************************************************************  
* @fn  halFlashErasePage  
*  
* @brief  
*       This function erases a given flash page.  
*  
*       This function disables interrupts when running, and re-enables interrupt  
*       if interrupts were enabled at function entry.  
*  
* Parameters:  
*  
* @param  byte*  pBuffer  
*         Pointer to a buffer of 10 bytes in XDATA RAM to which the flash  
*         erase procedure can be copied.  
* @param  byte      page  
*         Indicates which of the flash pages is to be erased.  
*  
* @return void  
*  
******************************************************************************/   
void halFlashErasePage(byte* buffer, byte page);   
   
   
   
/******************************************************************************  
*******************      Power and clock management        ********************  
*******************************************************************************  
  
These macros are used to set power-mode, clock source and clock speed.  
  
******************************************************************************/   
   
// Macro for getting the clock division factor    
#define CLKSPD  (CLKCON & 0x07)    
   
// Macro for getting the timer tick division factor.    
#define TICKSPD ((CLKCON & 0x38) >> 3)    
   
// Macro for checking status of the crystal oscillator    
#define XOSC_STABLE (SLEEP & 0x40)    
   
// Macro for checking status of the high frequency RC oscillator.    
#define HIGH_FREQUENCY_RC_OSC_STABLE    (SLEEP & 0x20)    
   
   
// Macro for setting power mode    
#define SET_POWER_MODE(mode)                   \    
   do {                                        \   
      if(mode == 0)        { SLEEP &= ~0x03; } \   
      else if (mode == 3)  { SLEEP |= 0x03;  } \   
      else { SLEEP &= ~0x03; SLEEP |= mode;  } \   
      PCON |= 0x01;                            \   
      asm("NOP");                              \   
   }while (0)   
   
   
// Where _mode_ is one of    
#define POWER_MODE_0  0x00  // Clock oscillators on, voltage regulator on    
#define POWER_MODE_1  0x01  // 32.768 KHz oscillator on, voltage regulator on    
#define POWER_MODE_2  0x02  // 32.768 KHz oscillator on, voltage regulator off    
#define POWER_MODE_3  0x03  // All clock oscillators off, voltage regulator off    
   
// Macro for setting the 32 KHz clock source    
#define SET_32KHZ_CLOCK_SOURCE(source) \    
   do {                                \   
      if( source ) {                   \   
         CLKCON |= 0x80;               \   
      } else {                         \   
         CLKCON &= ~0x80;              \   
      }                                \   
   } while (0)   
   
// Where _source_ is one of    
#define CRYSTAL 0x00    
#define RC      0x01    
   
// Macro for setting the main clock oscillator source,    
//turns off the clock source not used    
//changing to XOSC will take approx 150 us    
#define SET_MAIN_CLOCK_SOURCE(source) \    
   do {                               \   
      if(source) {                    \   
        CLKCON |= 0x40;               \   
        while(!HIGH_FREQUENCY_RC_OSC_STABLE); \   
        if(TICKSPD == 0){             \   
          CLKCON |= 0x08;             \   
        }                             \   
        SLEEP |= 0x04;                \   
      }                               \   
      else {                          \   
        SLEEP &= ~0x04;               \   
        while(!XOSC_STABLE);          \   
        asm("NOP");                   \   
        CLKCON &= ~0x47;              \   
        SLEEP |= 0x04;                \   
      }                               \   
   }while (0)   
   
   
// Macro for setting the main clock division,    
#define SET_MAIN_CLOCK_SPEED(frequency)   \    
   do {                                   \   
        CLKCON = ((CLKCON & ~0x07) | (frequency & 0x07));     \   
   }while (0)   
   
// where frequency is one of    
#define MHZ_26          0x00    
#define MHZ_13          0x01    
#define MHZ_6_5         0x02    
#define MHZ_3_25        0x03    
#define MHZ_1_62        0x04    
#define MHZ_0_81        0x05    
#define MHZ_0_40        0x06    
#define MHZ_0_20        0x07    
   
/******************************************************************************  
*******************           Timer macros/functions        *******************  
*******************************************************************************  
General:  
The timers/counters can be configured in a number of ways. The following  
functions allow basic configuration of the timers as interrupt timers,  
pulse width modulators (PWM) and capture timers. Other uses require manual  
configuration of the timers/counters.  
  
Generally 3 steps are nescessary to start a timer:  
  
   TIMERx_INIT();  
   bool halSetTimerxPeriod(period);  
   TIMERx_RUN(TRUE);  
  
where x is the timer number. Please see the function / macro in question for  
details.  
  
All timers can generate interrupts. The configuration of interrupts is not  
included in the HAL.  
  
******************************************************************************/   
   
   
/******************************************************************************  
* @fn  halSetTimer1Period  
*  
* @brief  
*      This function sets up timer 1 to run with a given period. If _period_ is  
*      set to 0, maximum period length will be used. The first time the timer  
*      is used the macro TIMER1_INIT() should be run to clear all settings. The  
*      timer is started and stopped with the macro TIMER1_RUN(TRUE / FALSE).  
*  
* Parameters:  
*  
* @param  dword  period  
*         The desired timer period in u-seconds.  
*  
* @return word  
*         The timer value written to the register if the configuration was  
*         successful and 0 if the period could not be achieved. This return  
*         value can be used for determining pulse widths when the timer is  
*         used in PWM mode.  
*  
******************************************************************************/   
word halSetTimer1Period(dword period);   
   
   
// Macro for initialising timer 1. Resets all involved registers and disables    
// all interrupt masks.    
#define TIMER1_INIT()   \    
   do {                 \   
      T1CTL  = 0x00;    \   
      T1CCTL0 = 0x00;   \   
      T1CCTL1 = 0x00;   \   
      T1CCTL2 = 0x00;   \   
      TIMIF &= ~0x40;   \   
   } while (0)   
   
// Macro for configuring a channel of timer 1 for PWM. Channel may be    
// either 1 or 2.    
#define TIMER1_PWM_CONFIG(channel)               \    
   do {                                          \   
      T1CCTL##channel## = 0x24;                  \   
      if(PERCFG&0x40) {                          \   
         if(channel == 0x01){                    \   
            IO_FUNC_PORT_PIN(1,1,IO_FUNC_PERIPH);\   
         }                                       \   
         else {                                  \   
            IO_FUNC_PORT_PIN(1,0,IO_FUNC_PERIPH);\   
         }                                       \   
      }                                          \   
      else {                                     \   
         if(channel == 0x01){                    \   
            IO_FUNC_PORT_PIN(0,3,IO_FUNC_PERIPH);\   
         }                                       \   
         else {                                  \   
            IO_FUNC_PORT_PIN(0,4,IO_FUNC_PERIPH);\   
         }                                       \   
      }                                          \   
   } while(0)   
   
// Macro for changing the pulse length of a timer in PWM mode. The value is    
// not scaled and the user must verify that it is correct. _channel_ is the    
// channel (1 or 2) configured for PWM operation, whereas _value_ is the    
// 16 bit word giving the pulse length. This argument should be shorter than    
// or equal to the value returned from the function halSetTimer1Period(...).    
#define TIMER1_SET_PWM_PULSE_LENGTH(channel, value) \    
   do {                                             \   
      T1CC##channel##L = (byte)value;               \   
      T1CC##channel##H = (byte)(value >> 8);        \   
   } while(0)   
   
   
// Macro for configuring a channel of timer 1 for capture.    
#define TIMER1_CAPTURE_CHANNEL(channel, edge)      \    
   do {                                            \   
      T1CCTL ##channel = edge;                     \   
      if(PERCFG&0x40) {                            \   
         if(channel == 0x01){                      \   
            IO_FUNC_PORT_PIN(1,1,IO_FUNC_PERIPH);  \   
         }                                         \   
         else {                                    \   
            IO_FUNC_PORT_PIN(1,0,IO_FUNC_PERIPH);  \   
         }                                         \   

⌨️ 快捷键说明

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