📄 hal_msp430fet.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() _EINT()
#define DISABLE_GLOBAL_INT() _DINT()
/*******************************************************************************************************
*******************************************************************************************************
************************** MSP430 I/O PORTS **************************
*******************************************************************************************************
*******************************************************************************************************/
//-------------------------------------------------------------------------------------------------------
// Port 1
//-------------------------------------------------------------------------------------------------------
#define LED1 0 // P1.0 - Output: LED1
#define LED2 1 // P1.1 - Output: LED2
#define LED3 2 // P1.2 - Output: LED3
#define LED4 3 // P1.3 - Output: LED4
#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 PORT_INIT()\
do {\
WDTCTL = WDTPW + WDTHOLD;\
P1DIR = BM(LED1) | BM(LED2) | BM(LED3) | BM(LED4);\
P2DIR = BM(VREG_EN) | BM(RESET_N);\
P1OUT = BM(LED1);\
P2OUT = BM(VREG_EN) | BM(RESET_N);\
} while (0)
#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_LED1() ( P1OUT |= BM(LED1) )
#define CLR_LED1() ( P1OUT &= ~BM(LED1) )
#define TOGGLE_LED1() ( P1OUT ^= BM(LED1) )
#define SET_LED2() ( P1OUT |= BM(LED2) )
#define CLR_LED2() ( P1OUT &= ~BM(LED2) )
#define TOGGLE_LED2() ( P1OUT ^= BM(LED2) )
#define SET_LED3() ( P1OUT |= BM(LED3) )
#define CLR_LED3() ( P1OUT &= ~BM(LED3) )
#define TOGGLE_LED3() ( P1OUT ^= BM(LED3) )
#define SET_LED4() ( P1OUT |= BM(LED4) )
#define CLR_LED4() ( P1OUT &= ~BM(LED4) )
#define TOGGLE_LED4() ( P1OUT ^= BM(LED4) )
/******************************************************************************************************
*******************************************************************************************************
************************** 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) )
//-------------------------------------------------------------------------------------------------------
/*******************************************************************************************************
*******************************************************************************************************
************************** SERIAL PORTS **************************
*******************************************************************************************************
*******************************************************************************************************/
/*******************************************************************************************************
*******************************************************************************************************
************************** 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 + -