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

📄 halsrf04.h

📁 CC1100_CC1101_CC2500_Examples_Libraries_(Rev. E)-(swrc021e)
💻 H
📖 第 1 页 / 共 3 页
字号:




//-------------------------------------------------------------------------------------------------------
//  void halSpiReadBurstReg(BYTE addr, BYTE *buffer, BYTE count)
//
//  DESCRIPTION:
//      This function reads multiple CCxxx0 register, using SPI burst access.
//
//  ARGUMENTS:
//      BYTE addr
//          Address of the first CCxxx0 register to be accessed.
//      BYTE *buffer
//          Pointer to a byte array which stores the values read from a
//          corresponding range of CCxxx0 registers.
//      BYTE count
//          Number of bytes to be read from the subsequent CCxxx0 registers.
//-------------------------------------------------------------------------------------------------------
void halSpiReadBurstReg(BYTE addr, BYTE *buffer, BYTE count);




//-------------------------------------------------------------------------------------------------------
// Macro to reset the CCxxx0 and wait for it to be ready
#define RESET_CCxxx0() \
    do { \
        NSSMD0 = 0; \
        while (P0_1); \
        SPI0DAT = CCxxx0_SRES; \
        SPI_WAIT(); \
        NSSMD0 = 1; \
    } while (0)
//-------------------------------------------------------------------------------------------------------




//-------------------------------------------------------------------------------------------------------
// Macro to reset the CCxxx0 after power_on and wait for it to be ready
// IMPORTANT NOTICE:
// The file Wait.c must be included if this macro shall be used
// The file is located under: ..\Lib\Chipcon\Hal\CCxx00
//
//                 min 40 us
//             <----------------------->
// CSn      |--|  |--------------------|          |-----------
//          |  |  |                    |          |
//              --                      ----------
//
// MISO                                       |---------------
//          - - - - - - - - - - - - - - - -|  |         
//                                          --          
//               Unknown / don't care
//
// MOSI     - - - - - - - - - - - - - - - ---------- - - - - - 
//                                         | SRES |
//          - - - - - - - - - - - - - - - ---------- - - - - -                    
//
#define POWER_UP_RESET_CCxxx0() \
    do { \
        NSSMD0 = 1; \
        halWait(1); \
        NSSMD0 = 0; \
        halWait(1); \
        NSSMD0 = 1; \
        halWait(41); \
        RESET_CCxxx0(); \
    } while (0)
//-------------------------------------------------------------------------------------------------------





/*******************************************************************************************************
 *******************************************************************************************************
 **************************              Timer macros/functions             ****************************
 *******************************************************************************************************
 *******************************************************************************************************/
//-------------------------------------------------------------------------------------------------------
// This section contains macros and functions for setting up the 4 different timers available
//      TIMER0_RUN(x)
//      TIMER1_RUN(x)
//      TIMER2_RUN(x)
//      TIMER3_RUN(x)
//      SET_RELOAD_VALUE_TIMER0(period_us, clock_kHz)
//      SET_RELOAD_VALUE_TIMER1(period_us, clock_kHz)
//      SET_RELOAD_VALUE_TIMER2_8BIT(periodH_us, periodL_us, clock_kHzH, clock_kHzL)
//      SET_RELOAD_VALUE_TIMER3_8BIT(periodH_us, periodL_us, clock_kHzH, clock_kHzL)
//      SET_RELOAD_VALUE_TIMER2_16BIT(period_us, clock_kHz)
//      SET_RELOAD_VALUE_TIMER3_16BIT(period_us, clock_kHz)
//      void halSetupTimer01(UINt8 timer01, UINT8 clkSource, UINT8 mode, BOOL timerInt)
//      void halSetupTimer23(UINT8 timer23, UINT8 clkSourceH, UINT8 clkSourceL, UINT8 mode, BOOL timerInt)
//-------------------------------------------------------------------------------------------------------




//-------------------------------------------------------------------------------------------------------
// Defines used for variable _clkSource_, _clkSourceL_, and _clkSourceH_
#define SYSCLK_DIV_12   0
#define SYSCLK_DIV_4    1
#define SYSCLK_DIV_48   2
#define EXTCLK_DIV_8    3
#define SYSCLK_DIV_1    4

// Define used for variable _timer01_ 
#define TIMER_0     0
#define TIMER_1     1

// Define used for variable _timer23_ 
#define TIMER_2     2
#define TIMER_3     3

// Defines used for variable _mode_
#define MODE_0      0       // Timer0, timer1, timer2, and timer3
#define MODE_1      1       // Timer0, timer1, timer2, and timer3
#define MODE_2      2       // Timer0 and timer1
//-------------------------------------------------------------------------------------------------------




//-------------------------------------------------------------------------------------------------------
// Macro for stopping and starting the timers.
#define TIMER0_RUN(x)    (TR0 = !!(x))
#define TIMER1_RUN(x)    (TR1 = !!(x))
#define TIMER2_RUN(x)    (TR2 = !!(x))
#define TIMER3_RUN(x)    (x ? (TMR3CN |= BM_TR3) : (TMR3CN &= (~BM_TR3)))
//-------------------------------------------------------------------------------------------------------




//-------------------------------------------------------------------------------------------------------
//  SET_RELOAD_VALUE_TIMERx(period_us, clock_kHz)
//
//  DESCRIPTION:
//      Macros used to calculate the reload value and update the reload registers.
//      x = 0 or 1
//
//      Below is a table showing what periods are possible for the different clock sources
//
//      Clock Source:   |   Freq:   |   Min. period |   Max period
//      ----------------------------------------------------------
//      SYSCLK_DIV_1    |   24 MHz  |   41.7 ns     |   10.6 us      
//      SYSCLK_DIV_4    |   6 MHz   |   166.7 ns    |   42.6 us
//      SYSCLK_DIV_12   |   2 MHz   |   500 ns      |   128 us
//      SYSCLK_DIV_48   |   0.5 MHz |   2 us        |   512 us
//      ----------------------------------------------------------
//
//      Example of usage:
//
//      SET_RELOAD_VALUE_TIMER0(0.0417, 24000);
//  
//      halSetupTimer01(TIMER_0, SYSCLK_DIV_1, MODE_2, INT_ON);
//
//      IMPORTANT NOTICE:
//      Constants should be used as arguments when using the SET_RELOAD_VALUE_TIMERx macro in order
//      to reduce code size.
//      
//  ARGUMENTS:
//      period_us
//          The period between interrupts. The period must be given in us.
//
//      clock_kHz
//          The frequency of the clock source (in kHz)
//-------------------------------------------------------------------------------------------------------
// This macro is only for internal use in this library file
#define SET_RELOAD_VALUE_TIMER01(timer01, period_us, clock_kHz) \
    do { \
        UINT8 count; \
        count = (UINT8)(((float)period_us * (float)clock_kHz) / 1000); \
        TH##timer01 = 256 - count; \
        TL##timer01 = TH##timer01; \
    } while (0)
//-------------------------------------------------------------------------------------------------------
// These macros are available for the user
#define SET_RELOAD_VALUE_TIMER0(period_us, clock_kHz)  SET_RELOAD_VALUE_TIMER01(0, period_us, clock_kHz)
#define SET_RELOAD_VALUE_TIMER1(period_us, clock_kHz)  SET_RELOAD_VALUE_TIMER01(1, period_us, clock_kHz)
//-------------------------------------------------------------------------------------------------------




//-------------------------------------------------------------------------------------------------------
//  SET_RELOAD_VALUE_TIMERx_8BIT(periodH_us, periodL_us, clock_kHzH, clock_kHzL)
//
//  DESCRIPTION:
//      Macros used to calculate the reload value and update the reload registers.
//      x = 2 or 3
//
//      Below is a table showing what periods are possible for the different clock sources
//
//      Clock Source:   |   Freq:   |   Min. period |   Max period
//      ----------------------------------------------------------
//      SYSCLK_DIV_1    |   24 MHz  |   41.7 ns     |   10.6 us      
//      SYSCLK_DIV_12   |   2 MHz   |   500 ns      |   128 us
//      ----------------------------------------------------------
//
//      Example of usage:
//
//      SET_RELOAD_VALUE_TIMER2_8BIT(3, 60, 24000, 2000);
//  
//      halSetupTimer23(TIMER_2, SYSCLK_DIV_1, SYSCLK_DIV_12, MODE_1, INT_ON);
//
//      IMPORTANT NOTICE:
//      Constants should be used as arguments when using the SET_RELOAD_VALUE_TIMERx_8BIT macro in order
//      to reduce code size.
//      
//  ARGUMENTS:
//      periodH_us
//          The period between interrupts (high byte overflow). The period must be given in us.
//
//      periodL_us
//          The period between interrupts (low byte overflow). The period must be given in us.
//
//      clock_kHzH
//          The frequency of the clock source for timer TMRxH (in kHz)
//
//      clock_kHzL
//          The frequency of the clock source for timer TMRxL (in kHz)
//-------------------------------------------------------------------------------------------------------
// This macro is only for internal use in this library file
#define SET_RELOAD_VALUE_TIMER23_8BIT(timer23, periodH_us, periodL_us, clock_kHzH, clock_kHzL) \
    do { \
        UINT8 countH; \
        UINT8 countL; \
        countH = (UINT8)(((float)periodH_us * (float)clock_kHzH) / 1000); \
        countL = (UINT8)(((float)periodL_us * (float)clock_kHzL) / 1000); \          
        TMR##timer23##RLH = 256 - countH; \
        TMR##timer23##H = TMR##timer23##RLH; \
        TMR##timer23##RLL = 256 - countL; \
        TMR##timer23##L = TMR##timer23##RLL; \
    } while (0)
//-------------------------------------------------------------------------------------------------------
// These macros are available for the user
#define SET_RELOAD_VALUE_TIMER2_8BIT(periodH_us, periodL_us, clock_kHzH, clock_kHzL) \
    do { \
        SET_RELOAD_VALUE_TIMER23_8BIT(2, periodH_us, periodL_us, clock_kHzH, clock_kHzL); \
    } while (0)

#define SET_RELOAD_VALUE_TIMER3_8BIT(periodH_us, periodL_us, clock_kHzH, clock_kHzL) \
    do { \
        SET_RELOAD_VALUE_TIMER23_8BIT(3, periodH_us, periodL_us, clock_kHzH, clock_kHzL); \
    } while (0)
//-------------------------------------------------------------------------------------------------------




//-------------------------------------------------------------------------------------------------------
//  SET_RELOAD_VALUE_TIMERx_16BIT(period_us, clock_kHz)
//
//  DESCRIPTION:
//      Macros used to calculate the reload value and update the reload registers.
//      x = 2 or 3
//
//      Below is a table showing what periods are possible for the different clock sources
//
//      Clock Source:   |   Freq:   |   Min. period |   Max period
//      ----------------------------------------------------------
//      SYSCLK_DIV_1    |   24 MHz  |   41.7 ns     |   2.73 ms      
//      SYSCLK_DIV_12   |   2 MHz   |   500 ns      |   32.75 ms
//      ----------------------------------------------------------
//
//      Example of usage:
//
//      SET_RELOAD_VALUE_TIMER2_16BIT(100, 24000);
//  
//      halSetupTimer23(TIMER_2, NULL, SYSCLK_DIV_1, MODE_0, INT_ON);
//
//      IMPORTANT NOTICE:
//      Constants should be used as arguments when using the SET_RELOAD_VALUE_TIMERx_16BIT macro in order
//      to reduce code size.
//      
//  ARGUMENTS:
//      period_us
//          The period between interrupts. The period must be given in us.
//
//      clock_kHzH
//          The frequency of the clock source (in kHz)
//-------------------------------------------------------------------------------------------------------
// This macro is only for internal use in this library file
#define SET_RELOAD_VALUE_TIMER23_16BIT(timer23, period_us, clock_kHz) \
    do { \
        UINT16 count; \
        UINT16 reloadValue; \
        count = (UINT16)(((float)period_us * (float)clock_kHz) / 1000); \
        reloadValue = (UINT16)(65536 - count); \
        TMR##timer23##RLL = reloadValue; \
        TMR##timer23##RLH = reloadValue >> 8; \
        TMR##timer23##L = TMR##timer23##RLL; \
        TMR##timer23##H = TMR##timer23##RLH; \
    } while (0)
//-------------------------------------------------------------------------------------------------------
// These macros are available for the user
#define SET_RELOAD_VALUE_TIMER2_16BIT(period_us, clock_kHz) \
    do { \
        SET_RELOAD_VALUE_TIMER23_16BIT(2, period_us, clock_kHz); \
    } while (0)

#define SET_RELOAD_VALUE_TIMER3_16BIT(period_us, clock_kHz) \
    do { \
        SET_RELOAD_VALUE_TIMER23_16BIT(3, period_us, clock_kHz); \
    } while (0)
//-------------------------------------------------------------------------------------------------------




//-------------------------------------------------------------------------------------------------------
#define INTERRUPT       TRUE
#define NO_INTERRUPT    FALSE
//-------------------------------------------------------------------------------------------------------




//-------------------------------------------------------------------------------------------------------
// void halSetupTimer01(UINT8 timer01, UINT8 clkSource, UINT8 mode, BOOL timerInt)
//
//  DESCRIPTION:
//      Function used to set up timer 0 or timer 1. Be aware that Timer 0 and Timer 1 share the same
//      prescaler. The function enables the given timer. Allowing the timer to be controlled by the 
//      external input signal can be done manually by setting GATE0 or GATE1 to 

⌨️ 快捷键说明

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