📄 hal_cc2420db.h
字号:
/*******************************************************************************************************
* *
* ********** *
* ************ *
* *** *** *
* *** +++ *** *
* *** + + *** *
* *** + CHIPCON HARDWARE ABSTRACTION LIBRARY FOR THE CC2420 *
* *** + + *** CC2420DB Definitions *
* *** +++ *** *
* *** *** *
* ************ *
* ********** *
* *
*******************************************************************************************************
* Copyright Chipcon AS, 2004 / NEC Electronics Europe GmbH , 2004 *
*******************************************************************************************************
* 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 KF2 Taste It! development platform. *
*******************************************************************************************************
* Compiler: NEC Electronics PM plus V5.20 *
* Target platform: 78K0/KF2 *
*******************************************************************************************************
* The revision history is located at the bottom of this file *
*******************************************************************************************************/
#ifndef HAL_CC2400DB_H
#define HAL_CC2400DB_H
/*******************************************************************************************************
*******************************************************************************************************
************************** NEC 78K0/KF2+ I/O PORTS **************************
*******************************************************************************************************
*******************************************************************************************************/
//-------------------------------------------------------------------------------------------------------
// Port 0
#define MOSI P0.2 // P0.2 - Output: SPI Master out - slave in (MOSI)
#define MISO P0.3 // P14.3 - Input: SPI Master in - slave out (MISO)
#define SCK P0.4 // P0.4 - Output: SPI Serial Clock (SCLK)
#define SFD P0.6 // P0.6 - Input: SFD from CC2420
//-------------------------------------------------------------------------------------------------------
// Port 3
#define FIFOP P3.0 // P3.0 - Input: FIFOP from CC2420
//-------------------------------------------------------------------------------------------------------
// Port 4
#define CSN P4.3 // P4.3 - Output: SPI Chip Select (CS_N)
//-------------------------------------------------------------------------------------------------------
// Port 5
#define VREG_EN P5.0 // P5.0 - Output: VREG_EN to CC2420
#define RESET_N P5.1 // P5.1 - Output: RESET_N to CC2420
#define FIFO P5.2 // P5.2 - Input: FIFO from CC2420
#define CCA P5.3 // P5.3 - Input: CCA from CC2420
//-------------------------------------------------------------------------------------------------------
// Port setup macros
// CC2420 interface config
/* Port Setting Change about P0,P3,P14 */
#define MAC_PORT_INIT() { \
PM0 |= 0xc3; \
PU0 |= 0x01; \
PU0 &= 0xBF; \
PM3 = 0xFF; \
PU3 |= 0x03; \
PU0 |= 0x18; \
PU4 |= 0x08; \
SET_VREG_ACTIVE(); \
SET_WAIT(5000); \
SET_RESET_INACTIVE(); \
SPI_ENABLE(); \
}
// CC2420DB peripheral interface config
// Port7 setting - LEDs
// port 7 = output (8-bits)
// ext. Interrupt setting
// set output latch to 0xff
// setting ext.interrupt 2, 3: negative edge
// enable ext. interrupt 3 (Mask Flag Register)
// enable ext. interrupt 2 (Mask Flag Register)
#define DB_PERIPHERAL_PORT_INIT() { \
P7 = 0xFF; \
PM7 = 0x00; \
PMK3 = FALSE; \
PMK2 = FALSE; \
}
// Enables/disables the SPI interface
#define SPI_ENABLE() { CSIE11=1; CS_ENABLE(); }
#define SPI_DISABLE() { CS_DISABLE(); CSIE11=0; }
#define SPI_DISABLE_BIS() { P0 &=0xEF; SPI_DISABLE(); P0 |= 0x10; }
#define CS_ENABLE() { P4 &= 0xF7; }
#define CS_DISABLE() { P4 |= 0x08; }
//-------------------------------------------------------------------------------------------------------
/*******************************************************************************************************
*******************************************************************************************************
************************** CC2420 PIN ACCESS **************************
*******************************************************************************************************
*******************************************************************************************************/
// Pin status
#define FIFO_IS_1() (FIFO)
#define CCA_IS_1() (CCA)
#define RESET_IS_1() (RESET_N)
#define VREG_IS_1() (VREG_EN)
#define FIFOP_IS_1() (FIFOP)
#define SFD_IS_1() (SFD)
#define FIFO_IS_ACTIVE() FIFO_IS_1() // Used in hal.h and hal_cc2420.h
#define RESET_IS_ACTIVE() !RESET_IS_1() // Not used
#define VREG_IS_ACTIVE() VREG_IS_1() // Not used
#define FIFOP_IS_ACTIVE() !FIFOP_IS_1() // Used in mac_rx_engine.c and in hal_cc2420.h
#define SFD_IS_ACTIVE() SFD_IS_1()
#define CCA_IS_ACTIVE() CCA_IS_1() // Used 1 time in mac_tx_engine.c
// The CC2420 reset pin
#define SET_RESET_ACTIVE() { RESET_N = 0;}
#define SET_RESET_INACTIVE() { RESET_N = 1;}
// CC2420 voltage regulator enable pin
#define SET_VREG_ACTIVE() { VREG_EN = 1;}
#define SET_VREG_INACTIVE() { VREG_EN = 0;}
//MaxChanges
#define SET_WAIT(x)\
do {\
UINT16 NumLoop;{\
for (NumLoop = 0; NumLoop < (x); NumLoop++) { \
NOP();\
NOP();\
} \
}\
} while (0)
/*******************************************************************************************************
*******************************************************************************************************
************************** EXTERNAL INTERRUPTS **************************
*******************************************************************************************************
*******************************************************************************************************/
//-------------------------------------------------------------------------------------------------------
// Rising edge trigger for external interrupt 1 (FIFOP)
#define FIFOP_INT_INIT() { EGP |= 0x02; EGN &= ~(0x02); CLEAR_FIFOP_INT();}
// FIFOP on 78K0/KF2+ external interrupt 1
///#define ENABLE_FIFOP_INT() { PMK1 = 0; }
///#define DISABLE_FIFOP_INT() { PMK1 = 1; }
///#define CLEAR_FIFOP_INT() { PIF1 = 0; }
#define ENABLE_FIFOP_INT() { }
#define DISABLE_FIFOP_INT() { }
#define CLEAR_FIFOP_INT() { }
//-------------------------------------------------------------------------------------------------------
//-------------------------------------------------------------------------------------------------------
// SFD interrupt on timer 01 capture pin
#define ENABLE_SFD_CAPTURE_INT() { TMMK001 = 0; }
#define DISABLE_SFD_CAPTURE_INT() { TMMK001 = 1; }
#define CLEAR_SFD_CAPTURE_INT() { TMIF001 = 0; }
//-------------------------------------------------------------------------------------------------------
/*******************************************************************************************************
*******************************************************************************************************
************************** APPLICATION DEBUGGING **************************
*******************************************************************************************************
*******************************************************************************************************/
//-------------------------------------------------------------------------------------------------------
// Controlled application crash (flashes the LEDs forever to indicate an error code)
#define EXCEPTION(n) \
do { \
DISABLE_GLOBAL_INT(); \
SET_LED_MASK(n); \
halWait(15000); \
SET_LED_MASK(0); \
halWait(15000); \
} while (TRUE)
//-------------------------------------------------------------------------------------------------------
#endif
/*******************************************************************************************************
* Revision history:
*
* Revision 1.0 fr
* CC2420 MAC Release v0.7
*
*******************************************************************************************************/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -