📄 hal.h
字号:
/************************************************************************************
Filename: hal.h
Description: This file contains MCU definitons for the MSP430F1611.
************************************************************************************/
#ifndef HAL_H
#define HAL_H
/************************************************************************************
SPI: Low level functions
************************************************************************************/
#define SPI_WAITFOREOTx() while ((U1TCTL & TXEPT) == 0) // USART1 Tx buffer ready?
#define SPI_WAITFOREORx() while ((IFG2 & URXIFG1) == 0) // USART1 Rx buffer ready?
#define FASTSPI_TX(x)\
do {\
U1TXBUF = x;\
SPI_WAITFOREOTx();\
} while(0)
#define FASTSPI_RX(x)\
do {\
U1TXBUF = 0;\
SPI_WAITFOREORx();\
x = U1RXBUF;\
} while(0)
#define FASTSPI_RX_GARBAGE()\
do {\
U1TXBUF = 0;\
SPI_WAITFOREORx();\
U1RXBUF;\
} while(0)
#define FASTSPI_TX_MANY(p,c)\
do {\
for (UINT8 spiCnt = 0; spiCnt < (c); spiCnt++) {\
FASTSPI_TX(((UINT8*)(p))[spiCnt]);\
}\
} while(0)
#define FASTSPI_RX_WORD(x)\
do {\
U1TXBUF = 0;\
SPI_WAITFOREORx();\
x = U1RXBUF << 8;\
U1TXBUF = 0;\
SPI_WAITFOREORx();\
x |= U1RXBUF;\
} while (0)
#define FASTSPI_TX_ADDR(a)\
do {\
U1TXBUF = a;\
SPI_WAITFOREOTx();\
} while (0)
#define FASTSPI_RX_ADDR(a)\
do {\
U1TXBUF = (a) | 0x40;\
SPI_WAITFOREOTx();\
} while (0)
/***********************************************************
FAST SPI: Radio register access
***********************************************************/
// s = command strobe
// a = register address
// v = register value
#define FASTSPI_STROBE(s) \
do {\
SPI_ENABLE();\
FASTSPI_TX_ADDR(s);\
SPI_DISABLE();\
} while (0)
#define FASTSPI_SETREG(a,v)\
do {\
SPI_ENABLE();\
FASTSPI_TX_ADDR(a);\
FASTSPI_TX((UINT8) ((v) >> 8));\
FASTSPI_TX((UINT8) (v));\
SPI_DISABLE();\
} while (0)
#define FASTSPI_GETREG(a,v)\
do {\
SPI_ENABLE();\
FASTSPI_RX_ADDR(a);\
v= (UINT8)U1RXBUF;\
FASTSPI_RX_WORD(v);\
halWait(1);\
SPI_DISABLE();\
} while (0)
// Updates the SPI status UINT8
#define FASTSPI_UPD_STATUS(s)\
do {\
SPI_ENABLE();\
U1TXBUF = CC2420_SNOP;\
SPI_WAITFOREOTx();\
s = U1RXBUF;\
SPI_DISABLE();\
} while (0)
/***********************************************************
FAST SPI: FIFO Access
***********************************************************/
// p = pointer to the UINT8 array to be read/written
// c = the number of UINT8s to read/write
// b = single data UINT8
#define FASTSPI_WRITE_FIFO(p,c)\
do {\
SPI_ENABLE();\
FASTSPI_TX_ADDR(CC2420_TXFIFO);\
for (UINT8 i = 0; i < (c); i++) {\
FASTSPI_TX(((UINT8*)(p))[i]);\
}\
SPI_DISABLE();\
} while (0)
#define FASTSPI_WRITE_FIFO_NOCE(p,c)\
do {\
FASTSPI_TX_ADDR(CC2420_TXFIFO);\
for (UINT8 spiCnt = 0; spiCnt < (c); spiCnt++) {\
FASTSPI_TX(((UINT8*)(p))[spiCnt]);\
}\
} while (0)
#define FASTSPI_READ_FIFO_UINT8(b)\
do {\
SPI_ENABLE();\
FASTSPI_RX_ADDR(CC2420_RXFIFO);\
U1RXBUF;\
FASTSPI_RX(b);\
halWait(1);\
SPI_DISABLE();\
} while (0)
#define FASTSPI_READ_FIFO_NO_WAIT(p,c)\
do {\
SPI_ENABLE();\
FASTSPI_RX_ADDR(CC2420_RXFIFO);\
U1RXBUF;\
for (UINT8 spiCnt = 0; spiCnt < (c); spiCnt++) {\
FASTSPI_RX(((UINT8*)(p))[spiCnt]);\
}\
halWait(1);\
SPI_DISABLE();\
} while (0)
#define FASTSPI_READ_FIFO_GARBAGE(c)\
do {\
SPI_ENABLE();\
FASTSPI_RX_ADDR(CC2420_RXFIFO);\
U1RXBUF;\
for (UINT8 spiCnt = 0; spiCnt < (c); spiCnt++) {\
FASTSPI_RX_GARBAGE();\
}\
halWait(1);\
SPI_DISABLE();\
} while (0)
/***********************************************************
FAST SPI: CC2420 RAM access (big or little-endian order)
***********************************************************/
// FAST SPI: CC2420 RAM access (big or little-endian order)
// p = pointer to the variable to be written
// a = the CC2420 RAM address
// c = the number of UINT8s to write
// n = counter variable which is used in for/while loops (UINT8)
//
// Example of usage:
// UINT8 n;
// UINT16 shortAddress = 0xBEEF;
// FASTSPI_WRITE_RAM_LE(&shortAddress, CC2420RAM_SHORTADDR, 2);
#define FASTSPI_WRITE_RAM_LE(p,a,c,n)\
do {\
SPI_ENABLE();\
FASTSPI_TX(0x80 | (a & 0x7F));\
FASTSPI_TX((a >> 1) & 0xC0);\
for (n = 0; n < (c); n++) {\
FASTSPI_TX(((UINT8*)(p))[n]);\
}\
SPI_DISABLE();\
} while (0)
//-----------------------------------------------------------------------------------
// void halWait(UINT16 timeout)
//
// DESCRIPTION:
// Runs an idle loop for [timeout] microseconds.
//
// ARGUMENTS:
// UINT16 timeout
// The timeout in microseconds
//-----------------------------------------------------------------------------------
void halWait(UINT16 timeout);
void halSpiInit(void);
#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 + -