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

📄 defines.h

📁 cc1110,cc2510透传代码,IAR环境的
💻 H
字号:
/*------------------------------------------------------------------------------
 * defines.h
 * Copyright 1994-2006 Infortech Technology Co.,Ltd.
 * DESCRIPTION:
 * Author : Shutingzhong 2008-09-13
 -----------------------------------------------------------------------------*/

#ifndef _DEFINES_H
#define _DEFINES_H

/*-------------------------------------*
 *	             宏定义               *
 *---------------------------------------------------------------------------*/

/* Common values */
/* ============= */
#ifndef false
   #define false 0
#endif

#ifndef true
   #define true 1
#endif

#ifndef NULL
   #define NULL 0
#endif

#ifndef HIGH
   #define HIGH 1
#endif

#ifndef LOW
   #define LOW 0
#endif

/* Common types */
/* ============= */

/* Boolean */
//typedef unsigned char       BOOL;

/* Data */
typedef unsigned char       byte;
typedef unsigned short      word;
typedef unsigned long       dword;

/* Unsigned numbers */
typedef unsigned char       uint8;
typedef unsigned short      uint16;
typedef unsigned long       uint32;

/* Signed numbers */
typedef signed char         int8;
typedef signed short        int16;
typedef signed long         int32;

/******************************************************************************
*******************        Bit, byte and word macros        *******************
******************************************************************************/

// Bit mask
#define BM( b )       ( 0x01 << ( b ))

#define HIBYTE(a)     (byte) ((word)(a) >> 8 )
#define LOBYTE(a)     (byte)  (word)(a)

#define SET_WORD(regH, regL, Word) \
   do{                             \
      (regH) = HIBYTE( Word );     \
      (regL) = LOBYTE( Word );     \
   }while(0)

// Macro to read a word out
// Must not be used for all registers as e.g. Timer1 and Timers2 require that regL is read first
#define GET_WORD(regH, regL, Word) \
   do{                             \
      Word = (word)regH << 8;      \
      Word |= regL;                \
   }while(0)


// 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 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)

// 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

// Macro for setting the main clock division,
#define SET_MAIN_CLOCK_SPEED(frequency)   \
   do {                                   \
        CLKCON = ((CLKCON & ~0x07) | (frequency & 0x07));     \
   }while (0)

//------------------------------------------------------------------------------------------------------
//------------------------------------------------------------------------------------------------------
// 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)


// 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 enabling or disabling overflow interrupts of timer 1.
#define TIMER1_ENABLE_OVERFLOW_INT(val) \
   (TIMIF =  (val) ? TIMIF | 0x40 : TIMIF & ~0x40)
// Macros for turning timers on or off
#define TIMER1_RUN(value)      (T1CTL = (value) ? T1CTL|0x02 : T1CTL&~0x03)


#define IO_DIR_PORT_PIN(port, pin, dir)  \
   do {                                  \
      if (dir == IO_OUT)                 \
         P##port##DIR |= (0x01<<(pin));  \
      else                               \
         P##port##DIR &= ~(0x01<<(pin)); \
   }while(0)
#define IO_IN   0
#define IO_OUT  1

#define IO_IMODE_PORT_PIN(port, pin, imode) \
   do {                                     \
      if (imode == IO_IMODE_TRI)            \
         P##port##INP |= (0x01<<(pin));     \
      else                                  \
         P##port##INP &= ~(0x01<<(pin));    \
   } while (0)

// where imode is one of:
#define IO_IMODE_PUD  0 // Pull-up/pull-down
#define IO_IMODE_TRI  1 // Tristate


#define INT_ENABLE(inum, on)                                                    \
   do {                                                                         \
      if      (inum==INUM_RFTXRX) { RFTXRXIE = on; }                            \
      else if (inum==INUM_ADC)    { ADCIE   = on;  }                            \
      else if (inum==INUM_URX0)   { URX0IE  = on;  }                            \
      else if (inum==INUM_URX1)   { URX1IE  = on;  }                            \
      else if (inum==INUM_ENC)    { ENCIE   = on;  }                            \
      else if (inum==INUM_ST)     { STIE    = on;  }                            \
      else if (inum==INUM_P2INT)  { (on) ? (IEN2 |= 0x02) : (IEN2 &= ~0x02); }  \
      else if (inum==INUM_UTX0)   { (on) ? (IEN2 |= 0x04) : (IEN2 &= ~0x04); }  \
      else if (inum==INUM_DMA)    { DMAIE   = on;  }                            \
      else if (inum==INUM_T1)     { T1IE    = on;  }                            \
      else if (inum==INUM_T2)     { T2IE    = on;  }                            \
      else if (inum==INUM_T3)     { T3IE    = on;  }                            \
      else if (inum==INUM_T4)     { T4IE    = on;  }                            \
      else if (inum==INUM_P0INT)  { P0IE    = on;  }                            \
      else if (inum==INUM_UTX1)   { (on) ? (IEN2 |= 0x08) : (IEN2 &= ~0x08); }  \
      else if (inum==INUM_P1INT)  { (on) ? (IEN2 |= 0x10) : (IEN2 &= ~0x10); }  \
      else if (inum==INUM_RF)     { (on) ? (IEN2 |= 0x01) : (IEN2 &= ~0x01); }  \
      else if (inum==INUM_WDT)    { (on) ? (IEN2 |= 0x20) : (IEN2 &= ~0x20); }  \
   } while (0)

#define INT_ON   1
#define INT_OFF  0
#define INT_SET  1
#define INT_CLR  0

#define INUM_RFTXRX 0
#define INUM_ADC   1
#define INUM_URX0  2
#define INUM_URX1  3
#define INUM_ENC   4
#define INUM_ST    5
#define INUM_P2INT 6
#define INUM_UTX0  7
#define INUM_DMA   8
#define INUM_T1    9
#define INUM_T2    10
#define INUM_T3    11
#define INUM_T4    12
#define INUM_P0INT 13
#define INUM_UTX1  14
#define INUM_P1INT 15
#define INUM_RF    16
#define INUM_WDT   17

#define INT_SETFLAG(inum, f)                                                    \
   do {                                                                         \
      if      (inum==INUM_RFTXRX){ RFTXRXIF = f; }                              \
      else if (inum==INUM_ADC)   { ADCIF  = f; }                                \
      else if (inum==INUM_URX0)  { URX0IF = f; }                                \
      else if (inum==INUM_URX1)  { URX1IF = f; }                                \
      else if (inum==INUM_ENC)   { ENCIF_1 = ENCIF_0 = f; }                     \
      else if (inum==INUM_ST)    { STIF  = f;  }                                \
      else if (inum==INUM_P2INT) { P2IF  = f;  }                                \
      else if (inum==INUM_UTX0)  { UTX0IF= f;  }                                \
      else if (inum==INUM_DMA)   { DMAIF = f;  }                                \
      else if (inum==INUM_T1)    { T1IF  = f;  }                                \
      else if (inum==INUM_T2)    { T2IF  = f;  }                                \
      else if (inum==INUM_T3)    { T3IF  = f;  }                                \
      else if (inum==INUM_T4)    { T4IF  = f;  }                                \
      else if (inum==INUM_P0INT) { P0IF  = f;  }                                \
      else if (inum==INUM_UTX1)  { UTX1IF= f;  }                                \
      else if (inum==INUM_P1INT) { P1IF  = f;  }                                \
      else if (inum==INUM_RF)    { (f) ? (S1CON |= 0x03) : (S1CON &= ~0x03); }  \
      else if (inum==INUM_WDT)   { WDTIF = f;  }                                \
   } while (0)

#endif /* _DEFINES_H */


⌨️ 快捷键说明

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