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

📄 hal_msp430fet.h

📁 基于msp430f149与CC2420的无线传感器网络平台
💻 H
字号:
/************************************************************************************

  Filename:     hal_msp430FET.h

  Description:  HAL interface for the MSP430FET/CC2400EB combination referred to in
                AN033. The 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.

************************************************************************************/
#ifndef HAL_MSP430FET_H
#define HAL_MSP430FET_H

/////////////////////////////////////////////////////////////////////////////////////
// PUBLIC MACROS
//

#define ENABLE_GLOBAL_INT()     _EINT()
#define DISABLE_GLOBAL_INT()    _DINT()



/////////////////////////////////////////////////////////////////////////////////////
// MSP430 IO 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)

//-----------------------------------------------------------------------------------
// 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) )
//-----------------------------------------------------------------------------------



/////////////////////////////////////////////////////////////////////////////////////
// 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))


//-----------------------------------------------------------------------------------


/////////////////////////////////////////////////////////////////////////////////////
// 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

/***********************************************************************************
  Copyright 2007 Texas Instruments Incorporated. All rights reserved.

  IMPORTANT: Your use of this Software is limited to those specific rights
  granted under the terms of a software license agreement between the user
  who downloaded the software, his/her employer (which must be your employer)
  and Texas Instruments Incorporated (the "License").  You may not use this
  Software unless you agree to abide by the terms of the License. The License
  limits your use, and you acknowledge, that the Software may not be modified,
  copied or distributed unless embedded on a Texas Instruments microcontroller
  or used solely and exclusively in conjunction with a Texas Instruments radio
  frequency transceiver, which is integrated into your product.  Other than for
  the foregoing purpose, you may not use, reproduce, copy, prepare derivative
  works of, modify, distribute, perform, display or sell this Software and/or
  its documentation for any purpose.

  YOU FURTHER ACKNOWLEDGE AND AGREE THAT THE SOFTWARE AND DOCUMENTATION ARE
  PROVIDED 揂S IS

⌨️ 快捷键说明

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