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

📄 hal_msp430fet.h

📁 RF tranceiver MSP430F1611+CC2420 with FreeRTOS
💻 H
字号:
/*******************************************************************************************************
 *                                                                                                     *
 *        **********                                                                                   *
 *       ************                                                                                  *
 *      ***        ***                                                                                 *
 *      ***   +++   ***                                                                                *
 *      ***   + +   ***                                                                                *
 *      ***   +                        CHIPCON HARDWARE ABSTRACTION LIBRARY FOR THE CC2420             *
 *      ***   + +   ***                             MSP430FET defintion file                           *
 *      ***   +++   ***                                                                                *
 *      ***        ***                                                                                 *
 *       ************                                                                                  *
 *        **********                                                                                   *
 *                                                                                                     *
 *******************************************************************************************************
 * The Chipcon Hardware Abstraction Library is a collection of functions, macros and constants, which  *
 * can be used to ease access to the hardware on the CC2420 and the target microcontroller.            *
 *                                                                                                     *
 * This file contains all definitions that are specific for the MSP-FET430P140 development board.      *
 *******************************************************************************************************
 * Compiler: MSP430-GCC and IAR Embedded Workbench                                                     *
 * Target platform: MSP430FET                                                                          *
 *******************************************************************************************************
 * Revision history:                                                                                   *
 *                                                                                                     *
 *                                                                                                     *
 *******************************************************************************************************/
#ifndef HAL_MSP430FET_H
#define HAL_MSP430FET_H

/*******************************************************************************************************
 *******************************************************************************************************
 **************************                   Global macros                   **************************
 *******************************************************************************************************
 *******************************************************************************************************/

//#define ENABLE_GLOBAL_INT()     __enable_interrupt();
//#define DISABLE_GLOBAL_INT()    __disable_interrupt();



/*******************************************************************************************************
 *******************************************************************************************************
 **************************                   MSP430 I/O PORTS                **************************
 *******************************************************************************************************
 *******************************************************************************************************/

//-------------------------------------------------------------------------------------------------------
// Port 1
//-------------------------------------------------------------------------------------------------------
#define BTN_SUPPLY     2  // P1.5 - Output: VCC push-button
#define BUTTON         4  // P1.4 - Input: Push button detect


//-------------------------------------------------------------------------------------------------------
// Port 2
//-------------------------------------------------------------------------------------------------------
#define VREG_EN        0  // P2.0 - Output: VREG_EN to CC2420
#define RESET_N        1  // P2.1 - Output: RESET_N to CC2420
#define FIFO           2  // P2.2 - Input: FIFO from CC2420
#define FIFO_P         3  // P2.3 - Input: FIFOP from CC2420
#define CCA            4  // P2.4 - Input:  CCA from CC2420
#define SFD            6  // P2.6 - Input:  SFD from CC2420



//-------------------------------------------------------------------------------------------------------
// Port 3
//-------------------------------------------------------------------------------------------------------



//-------------------------------------------------------------------------------------------------------
// Port 4
//-------------------------------------------------------------------------------------------------------



//-------------------------------------------------------------------------------------------------------
// Port 5
//-------------------------------------------------------------------------------------------------------
#define CSN            0  // P5.0 - Output: SPI Chip Select (CS_N)
#define MOSI           1  // P5.1 - Output: SPI Master out - slave in (MOSI)
#define MISO           2  // P5.2 - Input:  SPI Master in - slave out (MISO)
#define SCK            3  // P5.3 - Output: SPI Serial Clock (SCLK)


//-------------------------------------------------------------------------------------------------------
// Port 6
//-------------------------------------------------------------------------------------------------------
#define RLED           0  // P6.0 - Output: Red  LED
#define YLED           5  // P6.5 - Output: Yellow LED
#define OLED           7  // P6.7 - Output: Orange LED

#define PORT_INIT()\
        do {\
                WDTCTL = WDTPW + WDTHOLD;\
		P6DIR = BM(YLED) | BM(OLED) | BM(RLED);\
                P2DIR = BM(VREG_EN) | BM(RESET_N);\
		P6OUT = BM(YLED) | BM(OLED) | BM(RLED);\
		P2OUT = BM(VREG_EN) | BM(RESET_N);\
	} while (0)


/*******************************************************************************************************
 *******************************************************************************************************
 **************************                   SERIAL PORTS                    **************************
 *******************************************************************************************************
 *******************************************************************************************************/
#define SPI_INIT()      halSpiInit()


//-------------------------------------------------------------------------------------------------------        
// Enables/disables the SPI interface
//-------------------------------------------------------------------------------------------------------

#define SPI_ENABLE()    ( P5OUT &= ~BM(CSN) ) // ENABLE CSn (active low)
#define SPI_DISABLE()	( P5OUT |=  BM(CSN) ) // DISABLE CSn (active low)




/*******************************************************************************************************
 *******************************************************************************************************
 **************************                        LEDS                       **************************
 *******************************************************************************************************
 *******************************************************************************************************/
//-------------------------------------------------------------------------------------------------------
// LED
//-------------------------------------------------------------------------------------------------------
#define SET_YLED()      ( P6OUT |=  BM(YLED) )
#define CLR_YLED()      ( P6OUT &= ~BM(YLED) )
#define TOGGLE_YLED()   ( P6OUT ^=  BM(YLED) )

#define SET_OLED()      ( P6OUT |=  BM(OLED) )
#define CLR_OLED()      ( P6OUT &= ~BM(OLED) )
#define TOGGLE_OLED()   ( P6OUT ^=  BM(OLED) )

#define SET_RLED()      ( P6OUT |=  BM(RLED) )
#define CLR_RLED()      ( P6OUT &= ~BM(RLED) )
#define TOGGLE_RLED()   ( P6OUT ^=  BM(RLED) )
 
/*******************************************************************************************************
 *******************************************************************************************************
 **************************                 CC2420 PIN ACCESS                 **************************
 *******************************************************************************************************
 *******************************************************************************************************/
//-------------------------------------------------------------------------------------------------------
// CC2420 pin access
//-------------------------------------------------------------------------------------------------------

// Pin status
#define FIFO_IS_1               (!!(P2IN & BM(FIFO)))
#define CCA_IS_1                (!!(P2IN & BM(CCA) ))
#define RESET_IS_1              (!!(P2IN & BM(RESET_N)))
#define VREG_IS_1               (!!(P2IN & BM(VREG_EN)))
#define FIFOP_IS_1              (!!(P2IN & BM(FIFO_P)))
#define SFD_IS_1                (!!(P2IN & BM(SFD)))

// The CC2420 reset pin
#define SET_RESET_INACTIVE()    ( P2OUT |=  BM(RESET_N) )
#define SET_RESET_ACTIVE()      ( P2OUT &= ~BM(RESET_N) )

// CC2420 voltage regulator enable pin
#define SET_VREG_ACTIVE()       ( P2OUT |=  BM(VREG_EN) )
#define SET_VREG_INACTIVE()     ( P2OUT &= ~BM(VREG_EN) )








/*******************************************************************************************************
 *******************************************************************************************************
 **************************               EXTERNAL INTERRUPTS                 **************************
 *******************************************************************************************************
 *******************************************************************************************************/

// Rising edge trigger for external interrupt 0 (FIFOP)
#define FIFOP_INT_INIT()            do { P2IES &= ~BM(FIFO_P); CLEAR_FIFOP_INT(); } while (0)

// FIFOP on external interrupt 0
#define ENABLE_FIFOP_INT()          do { P2IE |= BM(FIFO_P); } while (0)
#define DISABLE_FIFOP_INT()         do { P2IE &= ~BM(FIFO_P); } while (0)
#define CLEAR_FIFOP_INT()           do { P2IFG &= ~BM(FIFO_P); } while (0)



//-------------------------------------------------------------------------------------------------------
// SFD interrupt on timer 1 capture pin
//-------------------------------------------------------------------------------------------------------
#define ENABLE_SFD_CAPTURE_INT()    do { TIMSK |= BM(TICIE0); } while (0)
#define DISABLE_SFD_CAPTURE_INT()   do { TIMSK &= ~BM(TICIE0); } while (0)
#define CLEAR_SFD_CAPTURE_INT()     do { TIFR = BM(ICF0); } while (0)




/*******************************************************************************************************
 *******************************************************************************************************
 **************************                      BUTTONS                      **************************
 *******************************************************************************************************
 *******************************************************************************************************/

//-------------------------------------------------------------------------------------------------------
// S2 button
//-------------------------------------------------------------------------------------------------------
// #define BUTTON_PRESSED()            !(P1IN & BM(BUTTON))


/*******************************************************************************************************
 *******************************************************************************************************
 **************************               APPLICATION DEBUGGING               **************************
 *******************************************************************************************************
 *******************************************************************************************************/


//-------------------------------------------------------------------------------------------------------
// Controlled application crash (flashes the LEDs forever to indicate an error code)
//-------------------------------------------------------------------------------------------------------
#define EXCEPTION(n) \
    do { \
        DISABLE_GLOBAL_INT(); \
        TOGGLE_YLED(); \
        halWait(20000); \
        TOGGLE_YLED(); \
        halWait(50000); \
    } while (TRUE)



#endif

⌨️ 快捷键说明

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