📄 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 YLED 0 // P1.0 - Output: Yellow LED
#define BTN_SUPPLY 5 // P1.5 - Output: VCC push-button
#define BUTTON 6 // P1.6 - 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 3 // P2.3 - Input: FIFO from CC2420
#define FIFO_P 4 // P2.4 - Input: FIFOP from CC2420
//-------------------------------------------------------------------------------------------------------
// Port 3
//-------------------------------------------------------------------------------------------------------
// Port 4
#define SFD 0 // P4.0 - Input: SFD from CC2420
#define CCA 1 // P4.1 - Input: CCA from CC2420
//-------------------------------------------------------------------------------------------------------
// Port 5
#define SCK 1 // P5.1 - Output: SPI Serial Clock (SCLK)
#define MOSI 2 // P5.2 - Output: SPI Master out - slave in (MOSI)
#define MISO 3 // P5.3 - Input: SPI Master in - slave out (MISO)
#define CSN 4 // P5.4 - Output: SPI Chip Select (CS_N)
#define PORT_INIT()\
do {\
WDTCTL = WDTPW + WDTHOLD;\
P1DIR |= BM(YLED) | BM(BTN_SUPPLY);\
P2DIR |= BIT0+BIT1;\
P1OUT = BM(YLED) | BM(BTN_SUPPLY);\
} 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)
//-------------------------------------------------------------------------------------------------------
/*******************************************************************************************************
*******************************************************************************************************
************************** CC2420 PIN ACCESS **************************
*******************************************************************************************************
*******************************************************************************************************/
// LED
//
#define SET_YLED() ( P1OUT |= BM(YLED) )
#define CLR_YLED() ( P1OUT &= ~BM(YLED) )
#define TOGGLE_YLED() ( P1OUT ^= BM(YLED) )
//-------------------------------------------------------------------------------------------------------
// CC2420 pin access
// Pin status
#define FIFO_IS_1 (!!(P2IN & BM(FIFO)))
#define CCA_IS_1 (!!(P4IN & 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 (!!(P4IN & 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(TICIE1); } while (0)
#define DISABLE_SFD_CAPTURE_INT() do { TIMSK &= ~BM(TICIE1); } while (0)
#define CLEAR_SFD_CAPTURE_INT() do { TIFR = BM(ICF1); } while (0)
//-------------------------------------------------------------------------------------------------------
/*******************************************************************************************************
*******************************************************************************************************
************************** BUTTONS **************************
*******************************************************************************************************
*******************************************************************************************************/
//-------------------------------------------------------------------------------------------------------
// S2 button
#define BUTTON_PRESSED() !(P1IN & BM(BUTTON))
//-------------------------------------------------------------------------------------------------------
/*******************************************************************************************************
*******************************************************************************************************
************************** LEDS **************************
*******************************************************************************************************
*******************************************************************************************************/
/*******************************************************************************************************
*******************************************************************************************************
************************** 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 + -