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

📄 hal.h

📁 TI的CC1110、CC2510、CC2430射频SOC的驱动程序
💻 H
📖 第 1 页 / 共 5 页
字号:
*******************    USART-SPI specific functions/macros  *******************
*******************************************************************************

The macros in this section simplify SPI operation.

******************************************************************************/

// Macro for setting up an SPI connection. The macro configures the appropriate
// pins for peripheral operation, sets the baudrate if the chip is configured
// to be SPI master, and sets the desired clock polarity and phase. Whether to
// transfer MSB or LSB first is also determined. _spi_ indicates whether
// to use spi 0 or 1. _baudRate_ must be one of 2400, 4800, 9600, 14400, 19200,
// 28800, 38400, 57600, 76800, 115200, 153600, 230400 or 307200.
// Possible options are defined below.

#define SPI_SETUP(spi, baudRate, options)           \
   do {                                             \
      U##spi##UCR = 0x80;                           \
      U##spi##CSR = 0x00;                           \
                                                    \
      if((options) & SPI_SLAVE){  /* Slave        */\
         if(spi == 0){            /* USART0       */\
            if(PERCFG & 0x01){    /* Alt 2        */\
               P1SEL |= 0x3C;                       \
            } else {              /* Alt 1        */\
               P0SEL |= 0x3C;                       \
            }                                       \
         } else {                 /* USART1       */\
            if(PERCFG & 0x02){    /* Alt 2        */\
               P1SEL |= 0xF0;                       \
            } else {                                \
              P0SEL |= 0x3C;      /* Alt 1        */\
            }                                       \
         }                                          \
         U##spi##CSR = 0x20;                        \
      }                                             \
      else {                      /* Master       */\
         if(spi == 0){            /* USART0       */\
            if(PERCFG & 0x01){    /* Alt 2        */\
                P1SEL |= 0x38;                      \
                P1SEL &= ~0x04;                     \
            } else {              /* Alt 1        */\
               P0SEL |= 0x2C;                       \
               P0SEL &= ~0x10;                      \
            }                                       \
         } else {                 /* USART 1      */\
            if(PERCFG & 0x02){    /* Alt 2        */\
               P1SEL |= 0xE0;                       \
               P1SEL &= ~0x10;                      \
            } else {              /* Alt 1        */\
               P0SEL |= 0x38;                       \
               P0SEL &= ~0x04;                      \
            }                                       \
         }                                          \
         U##spi##GCR = BAUD_E(baudRate, CLKSPD);    \
         U##spi##BAUD = BAUD_M(baudRate);           \
      }                                             \
      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.

******************************************************************************/

#if (chip == 2430 || chip == 2431)
//Macro for erasing a given flash page
#define FLASH_ERASE_PAGE(page)    \
   do{                            \
      FADDRH = (page) << 1;       \
      FCTL = 0x01;                \
      asm("NOP");                 \
      while(FCTL == 0x80);        \
   }while (0)

#define SET_FLASH_WRITE_TIME()    \
   FWT  = 0x2A >> CLKSPD;

#endif

#if (chip == 2510 || chip == 1110 || chip == 1111 || chip == 2511)
//Macro for erasing a given flash page - NOT TESTED/VERIFIED!
#define FLASH_ERASE_PAGE(page)    \
   do{                            \
      FADDRH = (page) << 1;       \
      FADDRL = 0x00;              \
      FLASH_CONFIG(0x01);        \
   }while (0)

#define SET_FLASH_WRITE_TIME()    \
   FWT  = 0x22 >> CLKSPD;

#endif

#if (chip == 2510 || chip == 1110 || chip == 1111 || chip == 2511)
#define FLASH_CONFIG(options)     \
   do {                           \
      FWT  = ( 0x22 >> CLKSPD );  \
      FCTL = (options);           \
   } while (0)
#endif

#if (chip == 2510 || chip == 1110 || chip == 1111 || chip == 2511)
// _options_ may be the following:
#define READ_WHEN_NEED  0x00
#define CONTINOUS_READ  0x10
#define WRITE           0x02
#define FLASH_BUSY      0x80
#endif

/******************************************************************************
* @fn  halFlashDmaTrigger
*
* @brief
*       This function gives the first FLASH DMA trigger.
*
* Parameters:
*
* @param  void
*
* @return void
*
******************************************************************************/
void halFlashDmaTrigger(void);


/******************************************************************************
* @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);


/******************************************************************************
*******************      Power and clock management        ********************
*******************************************************************************

These macros are used to set power-mode, clock source and clock speed.

******************************************************************************/

// Macro for getting the clock division factor
#if (chip == 2430 || chip == 2431)
#define CLKSPD  ( CLKCON & 0x01 )
#endif

#if (chip == 2510 || chip == 2511 || chip == 1110 || chip == 1111)
#define CLKSPD  (CLKCON & 0x07)
#endif

// 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 {                         \
      SLEEP &= ~0x03;           \
      SLEEP |= mode;            \
      PCON |= 0x01;             \
   }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
// Please not that this macro only can be run when the device run on the RC osc
#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. Settings TICKSPD
// equal CLKSPD
#if (chip == 2430 || chip == 2431 )
// Use this for CC2430 rev. B
#define REV_B_SET_MAIN_CLOCK_SOURCE(source)   \
   do {                                       \
      if(source) {                            \
        CLKCON |= 0x40;                       \
        while(!HIGH_FREQUENCY_RC_OSC_STABLE); \
        SLEEP |= 0x04;                        \
      }                                       \
      else {                                  \
        SLEEP &= ~0x04;                       \
        while(!XOSC_STABLE);                  \
        asm("NOP");                           \
        CLKCON &= ~0x40;                      \
        SLEEP |= 0x04;                        \
      }                                       \
   }while (0)

// Use this for CC2430 rev. C ->
#define REV_C_SET_MAIN_CLOCK_SOURCE(source)   \
   do {                                       \
      if(source) {                            \
        CLKCON |= 0x40;                       \
        while( !(CLKCON & 0x40) );            \
      }                                       \
      else {                                  \
        CLKCON &= ~0x40;                      \
        while( CLKCON & 0x40 );               \
      }                                       \
   }while (0)

#define SET_MAIN_CLOCK_SOURCE( source )       \
  do {                                        \
    if( CHVER < REV_C )                       \
      REV_B_SET_MAIN_CLOCK_SOURCE( source );  \
    else                                      \
      REV_C_SET_MAIN_CLOCK_SOURCE( source );  \
  }while(0)
#endif

#if (chip == 1110 || chip == 1111 || chip == 2510 || chip == 2511)
#define SET_MAIN_CLOCK_SOURCE( source )       \
  do {                                        \
    if(source) {                              \
      CLKCON |= 0x40;                         \
      while(!HIGH_FREQUENCY_RC_OSC_STABLE);   \
      SLEEP |= 0x04;                          \
    }                                         \
    else {                                    \
      SLEEP &= ~0x04;                         \
      while(!XOSC_STABLE);                    \
      asm("NOP");                             \
      CLKCON &= ~0x47;                        \
      SLEEP |= 0x04;                          \
    }                                         \
  }while(0)
#endif


#if (chip == 1110 || chip == 2510)
// 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
#endif

#if (chip == 1111 || chip == 2511)
// Macro for setting the main clock division,
#define SET_MAIN_CLOCK_SPEED(frequency)   \

⌨️ 快捷键说明

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