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

📄 config.h

📁 CC2510 timer1 PWM输出2M波形
💻 H
📖 第 1 页 / 共 5 页
字号:


// Macros for turning timers on or off
#define TIMER1_RUN(value)      (T1CTL = (value) ? T1CTL|0x02 : T1CTL&~0x03)
#define TIMER3_RUN(value)      (T3CTL = (value) ? T3CTL|0x10 : T3CTL&~0x10)
#define TIMER4_RUN(value)      (T4CTL = (value) ? T4CTL|0x10 : T4CTL&~0x10)

// Macro for enabling/ disabling interrupts from the channels of timer 1, 3 or 4.
#define TIMER_CHANNEL_INTERRUPT_ENABLE(timer, channel, value) \
   do{                                                        \
      if(value){                                              \
         T##timer##CCTL##channel## |= 0x40;                   \
      } else {                                                \
         T##timer##CCTL##channel## &= ~0x40;                  \
      }                                                       \
   } while(0)

// Sleep Timer / Wake On Radio (WOR) Timer

//Macro for initialising the sleep timer / WOR timer.
#define SLEEP_TIMER_INIT()                                    \
   do{                                                        \
      WOREVT1 = 0x87;                                         \
      WOREVT0 = 0x6B;                                         \
      WORCTL = 0x74;                                          \
      WORIRQ = 0x00;                                          \
   } while(0)

// Macros for enabling / disabling interrupt for event 0 and 1.
#define SLEEP_TIMER_ENABLE_EVENT0_INT(val) do{ WORIRQ = (val) ? WORIRQ | 0x10 : WORIRQ & ~0x10; }while(0)
#define SLEEP_TIMER_ENABLE_EVENT1_INT(val) do{ WORIRQ = (val) ? WORIRQ | 0x20 : WORIRQ & ~0x20; }while(0)

// Macro for resetting the Sleep / WOR timer
#define SLEEP_TIMER_RESET()      WORCTL |= 0x04




/******************************************************************************
*******************          Watch Dog Timer (WDT)          *******************
*******************************************************************************

The WDT may be used to prevent the unit from being trapped in a system
stalemate, i.e. an endless waiting state. The WDT must be reset before it times
out. If a timeout occurs, the system is reset.

The WDT can also be configured as a normal timer which generates interrupt at
each timeout. This must be configured manually.
******************************************************************************/

// Macro for setting the WDT timeout interval.
#define WDT_SET_TIMEOUT_PERIOD(timeout) \
   do {  WDCTL &= ~0x03; WDCTL |= timeout; } while (0)

// Where _timeout_ is one of
#define SEC_1          0x00     // after 1 second
#define M_SEC_250      0x01     // after 250 ms
#define M_SEC_15       0x02     // after 15 ms
#define M_SEC_2        0x03     // after 2 ms

// Macro for resetting the WDT. If this is not done before the WDT times out,
// the system is reset.
#define WDT_RESET() do {           \
   WDCTL = (WDCTL & ~0xF0) | 0xA0; \
   WDCTL = (WDCTL & ~0xF0) | 0x50; \
} while (0)

// Macro for turning on the WDT
#define WDT_ENABLE()   WDCTL |= 0x08


/******************************************************************************
*******************             ADC macros/functions        *******************
*******************************************************************************

These functions/macros simplifies usage of the ADC.

******************************************************************************/
// Macro for setting up a single conversion. If ADCCON1.STSEL = 11, using this
// macro will also start the conversion.
#define ADC_SINGLE_CONVERSION(settings) \
   do{ ADCCON3 = (settings); }while(0)

// Macro for setting up a single conversion
#define ADC_SEQUENCE_SETUP(settings) \
   do{ ADCCON2 = (settings); }while(0)

// Where _settings_ are the following:
// Reference voltage:
#define ADC_REF_1_25_V      0x00     // Internal 1.25V reference
#define ADC_REF_P0_7        0x40     // External reference on AIN7 pin
#define ADC_REF_AVDD        0x80     // AVDD_SOC pin
#define ADC_REF_P0_6_P0_7   0xC0     // External reference on AIN6-AIN7 differential input

// Resolution (decimation rate):
#define ADC_8_BIT           0x00     //  64 decimation rate
#define ADC_10_BIT          0x10     // 128 decimation rate
#define ADC_12_BIT          0x20     // 256 decimation rate
#define ADC_14_BIT          0x30     // 512 decimation rate
// Input channel:
#define ADC_AIN0            0x00     // single ended P0_0
#define ADC_AIN1            0x01     // single ended P0_1
#define ADC_AIN2            0x02     // single ended P0_2
#define ADC_AIN3            0x03     // single ended P0_3
#define ADC_AIN4            0x04     // single ended P0_4
#define ADC_AIN5            0x05     // single ended P0_5
#define ADC_AIN6            0x06     // single ended P0_6
#define ADC_AIN7            0x07     // single ended P0_7
#define ADC_GND             0x0C     // Ground
#define ADC_TEMP_SENS       0x0E     // on-chip temperature sensor
#define ADC_VDD_3           0x0F     // (vdd/3)


//-----------------------------------------------------------------------------
// Macro for starting the ADC in continuous conversion mode
#define ADC_SAMPLE_CONTINUOUS() \
   do { ADCCON1 &= ~0x30; ADCCON1 |= 0x10; } while (0)

// Macro for stopping the ADC in continuous mode (and setting the ADC to be
// started manually by ADC_SAMPLE_SINGLE() )
#define ADC_STOP() \
  do { ADCCON1 |= 0x30; } while (0)

// Macro for initiating a single sample in single-conversion mode (ADCCON1.STSEL = 11).
#define ADC_SAMPLE_SINGLE() \
  do { ADC_STOP(); ADCCON1 |= 0x40;  } while (0)

// Macro for configuring the ADC to be started from T1 channel 0. (T1 ch 0 must be in compare mode!!)
#define ADC_TRIGGER_FROM_TIMER1()  do { ADC_STOP(); ADCCON1 &= ~0x10;  } while (0)

// Expression indicating whether a conversion is finished or not.
#define ADC_SAMPLE_READY()  (ADCCON1 & 0x80)

// Macro for setting/clearing a channel as input of the ADC
#define ADC_ENABLE_CHANNEL(ch)   ADCCFG |=  (0x01<<ch)
#define ADC_DISABLE_CHANNEL(ch)  ADCCFG &= ~(0x01<<ch)



#define STOP_RADIO()        SIDLE();
// RF interrupt flags
#define IRQ_TXUNF           0x80
#define IRQ_RXOVF           0x40
#define IRQ_TIMEOUT         0x20
//#define IRQ_DONE            0x10
#define IRQ_CS              0x08
#define IRQ_PQT             0x04
#define IRQ_CCA             0x02
#define IRQ_SFD             0x01

// RF status flags
#define CRC_OK_FLAG         0x80
#define CS_FLAG             0x40
#define PQT_REACHED_FLAG    0x20
#define CCA_FLAG            0x10
#define SFD_FLAG            0x08

// Radio status flags
#define CRC_OK_FLAG         0x80
#define CS_FLAG             0x40
#define PQT_REACHED_FLAG    0x20
#define CCA_FLAG            0x10
#define SFD_FLAG            0x08

// Radio status states
#define CRC_OK             (PKTSTATUS & CRC_OK_FLAG)
#define CS                 (PKTSTATUS & CS_FLAG)
#define PQT_REACHED        (PKTSTATUS & PQT_REACHED_FLAG)
#define CCA                (PKTSTATUS & CCA_FLAG)
#define SFD                (PKTSTATUS & SFD_FLAG)

// Various radio settings
#define APPEND_STATUS         0x04
#define WHITE_DATA            0x40
#define CRC_EN                0x04
#define VARIABLE_PKT_LEN      0x01
#define STAY_INR_RX_AFTER_RX  0x0C
#define RX_AFTER_TX           0x03
#define CALIBRATE_WHEN_COMING_FROM_IDLE   0x10
#define CALIBRATE_EVERY_4TH   0x30
#define PA_POWER_7            0x07
#define PA_POWER_0            0x00



//------------------------------------------------------------------------------------------------------
//------------------------------------------------------------------------------------------------------
// Command Strobes
//------------------------------------------------------------------------------------------------------
#define SFSTXON()     do{RFST = 0x00;}while(0)
#define SCAL()        do{RFST = 0x01;}while(0)
#define SRX()         do{RFST = 0x02;}while(0)
#define STX()         do{RFST = 0x03;}while(0)
#define SIDLE()       do{RFST = 0x04;}while(0)
#define SAFC()        do{RFST = 0x05;}while(0)
#define SNOP()        do{RFST = 0xFF;}while(0)
//------------------------------------------------------------------------------------------------------



// Conditions _c_ for the RPT and SKIP instructions of the CSP
#define CCA_TRUE            0x00;
#define RECEIVING           0x01;
#define MCU_BIT_IS_1        0x02;
#define COMMAND_BUF_EMPT    0x03;
#define REGX_IS_0           0x04;
#define REGY_IS_0           0x05;
#define REGZ_IS_0           0x06;
#define NO_OP               0x07;




/******************************************************************************
******************* Memory space mapping macros/functions  ********************
*******************************************************************************/

// Macros for enabling or disabling unified code space.
// Unified code space is generally used when executing programs from RAM.
#define ENABLE_UINIFIED_CODE_SPACE()   do { MEMCTR |= 0x40;  } while (0)
#define DISABLE_UINIFIED_CODE_SPACE()  do { MEMCTR &= ~0x40;  } while (0)


/******************************************************************************
*******************   AES encryption / decryption functions *******************
*******************************************************************************/



#define AES_BUSY    0x08
#define ENCRYPT     0x00
#define DECRYPT     0x01

// Macro for setting the mode of the AES operation
#define AES_SETMODE(mode) do { ENCCS &= ~0x70; ENCCS |= mode; } while (0)

// _mode_ is one of
#define CBC         0x00
#define CFB         0x10
#define OFB         0x20
#define CTR         0x30
#define ECB         0x40
#define CBC_MAC     0x50

// Macro for starting or stopping encryption or decryption
#define AES_SET_ENCR_DECR_KEY_IV(mode) \
   do {                                \
    ENCCS = (ENCCS & ~0x07) | mode;    \
   } while(0)

// Where _mode_ is one of
#define AES_ENCRYPT     0x00
#define AES_DECRYPT     0x02
#define AES_LOAD_KEY    0x04
#define AES_LOAD_IV     0x06


// Macro for starting the AES module for either encryption, decryption,
// key or initialisation vector loading.
#define AES_START()     ENCCS |= 0x01


/******************************************************************************
*************         Random Generator macros / functions          ************
******************************************************************************/
//
// Example usage:
//
//    BYTE rnd;
//
//    //first initialise the random generator:
//    halInitRandomGenerator();
//
//
//    // Each time the random generator is read, the following sequence should
//    // be used (clock the random generator for each read):
//       CLOCK_RANDOM_GENERATOR();
//       rnd = GET_RANDOM_VALUE();
//
//

// Macro for enabling the random generator
#define ENABLE_RANDOM_GENERATOR()   do{ ADCCON1 &= ~0x0C; } while(0)

// Macro for clocking the random generator
#define CLOCK_RANDOM_GENERATOR()   do{ ADCCON1 |= 0x04; } while(0)

// Macro for getting a random byte
#define GET_RANDOM_BYTE(a)      \
   do{                           \
      CLOCK_RANDOM_GENERATOR();  \
      a = RNDH;                  \
   }while(0)


// Macro for getting a random word
#define GET_RANDOM_WORD(a)      \
   do{                           \
      CLOCK_RANDOM_GENERATOR();  \
      a = (((WORD)RNDH << 8) | RNDL);                  \
   }while(0)


#endif //HAL_H

⌨️ 快捷键说明

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