📄 halsrf04.h
字号:
//------------------------------------------------------------------------------------------------------
// SETUP_GDO2_INT(trigger, polarity)
//
// DESCRIPTION:
// This macro is setting up the GDO2 interrupt from CCxx00. The interrupt is on P0.7 and is
// assign to external interrupt1. The macro enables external interrupt1.
//
// ARGUMENTS:
// trigger
// EDGE (interrupt is edge sensitive)
// LEVEL (interrupt is level sensitive)
// polarity
// HIGH (input is active high)
// LOW (input is active low)
//------------------------------------------------------------------------------------------------------
#define SETUP_GDO2_INT(trigger, polarity) \
do { \
IT1 = trigger; \
IT01CF = ((IT01CF & 0x0F) | ((polarity << 7) | 0x70)); \
INT_ENABLE(INUM_EXTERNAL1, INT_ON); \
} while (0)
//------------------------------------------------------------------------------------------------------
// where trigger is one of:
#define LEVEL 0
#define EDGE 1
// where polarity is one of:
#define LOW 0
#define HIGH 1
//------------------------------------------------------------------------------------------------------
/*******************************************************************************************************
*******************************************************************************************************
************************** UART SERIAL PORT ***************************
*******************************************************************************************************
*******************************************************************************************************/
//-------------------------------------------------------------------------------------------------------
// This section contains useful macros for configuring the UART and for TX and RX using the UART
// UART_SETUP(baudRate, options)
// UART_TX_ENABLE()
// UART_RX_ENABLE()
// UART_TX_WAIT()
// UART_RX_WAIT()
// UART_TX(x)
// UART_RX(x)
// UART_WAIT_AND_SEND(x)
// UART_WAIT_AND_RECEIVE(x)
//-------------------------------------------------------------------------------------------------------
//-------------------------------------------------------------------------------------------------------
// Options for UART configuration
#define DEFAULT_MODE 0x00 // 8-bit Uart with variable baudrate, logic level of stop bit is
// ignored. User must poll the RI_0 and TI_0 flag to determine when a
// byte arrives or when the TX buffer is empty. The user must manually
// clear RI0 and TI0 if not using the printf() / scanf() functions
// which do this automatically.
#define UART_ISR 0x01 // Use interrupt service routines to signal that a byte has arrived or
// that the TX buffer is empty. The user must manually clear RI_0 and
// TI_0 in the corresponding ISRs.
//-------------------------------------------------------------------------------------------------------
//-------------------------------------------------------------------------------------------------------
// Defines used for the _baudrate_ variable
#define UART_BAUDRATE_4800 0
#define UART_BAUDRATE_9600 1
#define UART_BAUDRATE_19200 2
#define UART_BAUDRATE_38400 3
#define UART_BAUDRATE_57600 4
#define UART_BAUDRATE_115200 5
//-------------------------------------------------------------------------------------------------------
//------------------------------------------------------------------------------------------------------
// void halUartSetup(UINT16 baudRate, UINT8 options)
//
// DESCRIPTION:
// Function which implements all the initialization necessary to establish a simple serial link.
// Timer1 is used as a baudrate generator and is initialized according to _baudRate_. Timer 1
// is enabled and configures for Mode 2; 8-bit counter/timer with auto-reload. The UART
// is configured according to _options_.
// The system clock needs to be configured to run at 24 MHz.
//
// ARGUMENTS:
// UINT16 baudRate
// UART_BAUDRATE_4800
// UART_BAUDRATE_9600
// UART_BAUDRATE_19200
// UART_BAUDRATE_38400
// UART_BAUDRATE_57600
// UART_BAUDRATE_115200
// UINT16 clkFreq
// Device clock frequency in kHz
// UINT8 options
// DEFAULT_MODE
// UART_ISR
//------------------------------------------------------------------------------------------------------
void halUartSetup(UINT8 baudRate, UINT8 options);
//-------------------------------------------------------------------------------------------------------
// Macros which are helpful when transmitting and receiving data over the serial interface.
//
// Example of usage:
//
// UART_TX_ENABLE();
// UART_TX(data);
//
// for (i = 1; i < len; i++) {
// UART_WAIT_AND_SEND(pData[i]);
// }
//
// UART_RX_ENABLE();
// len = UART_RX();
//
// while (len-- > 0) {
// UART_WAIT_AND_RECEIVE(data[i++]);
// }
#define UART_TX_ENABLE() do { REN0 = 0; } while (0)
#define UART_RX_ENABLE() do { REN0 = 1; } while (0)
#define UART_TX_WAIT() do {while (!INT_GETFLAG(INUM_UART0_TX)); } while (0)
#define UART_RX_WAIT() do {while (!INT_GETFLAG(INUM_UART0_RX)); } while (0)
#define UART_TX(x) do { SBUF0 = (x); } while (0)
#define UART_RX(x) do { (x) = SBUF0; } while (0)
#define UART_WAIT_AND_SEND(x) \
do { \
UART_TX_WAIT(); \
INT_SETFLAG(INUM_UART0_TX, INT_CLR); \
UART_TX(x); \
} while (0)
#define UART_WAIT_AND_RECEIVE(x) \
do { \
UART_RX_WAIT(); \
UART_RX(x); \
INT_SETFLAG(INUM_UART0_RX, INT_CLR); \
} while (0)
//-------------------------------------------------------------------------------------------------------
/*******************************************************************************************************
*******************************************************************************************************
******************************* SPI functions/macros ******************************
*******************************************************************************************************
*******************************************************************************************************/
//-------------------------------------------------------------------------------------------------------
// This section contains useful macros and functions for setting up the SPI and for reading/writing
// CC2500 registers
// SPI_INIT(freq)
// SPI_ENABLE()
// SPI_DISABLE()
// SPI_WAIT()
// void halSpiStrobe(BYTE addr)
// void halSpiWriteReg(BYTE addr, BYTE value)
// BYTE halSpiReadReg(BYTE addr)
// void halSpiWriteBurstReg(BYTE addr, BYTE *buffer, BYTE count)
// halSpiReadBurstReg(BYTE addr, BYTE *buffer, BYTE count)
// RESET_CCxxx0()
// POWER_UP_CCxxx0()
//-------------------------------------------------------------------------------------------------------
//-------------------------------------------------------------------------------------------------------
// Definitions to support burst/single access:
#define WRITE_BURST 0x40
#define READ_SINGLE 0x80
#define READ_BURST 0xC0
//-------------------------------------------------------------------------------------------------------
//-------------------------------------------------------------------------------------------------------
// SPI enable/disable macros:
#define SPI_ENABLE() (SPI0CN |= BM_SPIEN)
#define SPI_DISABLE() (SPI0CN &= ~BM_SPIEN)
//-------------------------------------------------------------------------------------------------------
//-------------------------------------------------------------------------------------------------------
// Initialization
// Enble SPI (4-wire Single Master Mode, data centered on first edge of SCK period.
// SCK low in Idle State
#define SPI_INIT(freq) \
do { \
SPI0CFG = BM_MSTEN; \
SPI0CN = BM_NSSMD1; \
SPI0CKR = freq; \
SPI_ENABLE(); \
} while (0)
// where freq is one of:
#define SCLK_6_MHZ 1
#define SCLK_4_MHZ 2
#define SCLK_3_MHZ 3
#define SCLK_2_4_MHZ 4
#define SCLK_2_MHZ 5
#define SCLK_1_5_MHZ 7
#define SCLK_1_2_MHZ 9
#define SCLK_1_MHZ 11
//-------------------------------------------------------------------------------------------------------
//-------------------------------------------------------------------------------------------------------
// Macro used for communication data polling and wait on the SPI bus
#define SPI_WAIT() \
do { \
while (!INT_GETFLAG(INUM_SPI0_IF)); \
INT_SETFLAG(INUM_SPI0_IF, INT_CLR); \
} while (0)
//-------------------------------------------------------------------------------------------------------
//-------------------------------------------------------------------------------------------------------
// void halSpiStrobe(BYTE strobe)
//
// DESCRIPTION:
// Function for writing a strobe command to the CCxxx0
//
// ARGUMENTS:
// BYTE strobe
// Strobe command
//-------------------------------------------------------------------------------------------------------
void halSpiStrobe(BYTE strobe);
//-------------------------------------------------------------------------------------------------------
// BYTE halSpiReadStatus(BYTE addr)
//
// DESCRIPTION:
// This function reads a CCxxx0 status register.
//
// ARGUMENTS:
// BYTE addr
// Address of the CCxxx0 status register to be accessed.
//
// RETURN VALUE:
// BYTE
// Value of the accessed CCxxx0 status register.
//-------------------------------------------------------------------------------------------------------
BYTE halSpiReadStatus(BYTE addr);
//-------------------------------------------------------------------------------------------------------
// void halSpiWriteReg(BYTE addr, BYTE value)
//
// DESCRIPTION:
// Function for writing to a single CCxxx0 register
//
// ARGUMENTS:
// BYTE addr
// Address of a specific CCxxx0 register to accessed.
// BYTE value
// Value to be written to the specified CCxxx0 register.
//-------------------------------------------------------------------------------------------------------
void halSpiWriteReg(BYTE addr, BYTE value);
//-------------------------------------------------------------------------------------------------------
// BYTE halSpiReadReg(BYTE addr)
//
// DESCRIPTION:
// This function gets the value of a single specified CCxxx0 register.
//
// ARGUMENTS:
// BYTE addr
// Address of the CCxxx0 register to be accessed.
//
// RETURN VALUE:
// BYTE
// Value of the accessed CCxxx0 register.
//-------------------------------------------------------------------------------------------------------
BYTE halSpiReadReg(BYTE addr);
//-------------------------------------------------------------------------------------------------------
// void halSpiWriteBurstReg(BYTE addr, BYTE *buffer, BYTE count)
//
// DESCRIPTION:
// This function writes to multiple CCxxx0 register, using SPI burst access.
//
// ARGUMENTS:
// BYTE addr
// Address of the first CCxxx0 register to be accessed.
// BYTE *buffer
// Array of bytes to be written into a corresponding range of
// CCxx00 registers, starting by the address specified in _addr_.
// BYTE count
// Number of bytes to be written to the subsequent CCxxx0 registers.
//-------------------------------------------------------------------------------------------------------
void halSpiWriteBurstReg(BYTE addr, BYTE *buffer, BYTE count);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -