📄 its_rf.c
字号:
/******************************************************************************
Filename: ITS_rf.c
This file contains functions for accessing the CC1100/CC1100 family
of RF ICs from Texas Instruments.
Copyright 2007 Texas Instruments, Inc.
******************************************************************************/
#include "ITS_types.h"
#include "ITS_board.h"
#include "ITS_spi.h"
#include "ITS_spi_config.h"
#include "ITS_mcu.h"
#include "ITS_defs.h"
#include "ITS_rf.h"
#include "cc1100.h"
//----------------------------------------------------------------------------------
// void ITSRfResetChip(void)
//
// DESCRIPTION:
// Resets the chip using the procedure described in the datasheet.
//----------------------------------------------------------------------------------
void ITSRfResetChip(void)
{
// Toggle chip select signal
HAL_SPI_CS_DEASSERT;
ITSMcuWaitUs(30);
HAL_SPI_CS_ASSERT;
ITSMcuWaitUs(30);
HAL_SPI_CS_DEASSERT;
ITSMcuWaitUs(45);
// Send SRES command
HAL_SPI_CS_ASSERT;
while(HAL_SPI_SOMI_VAL);
HAL_SPI_TXBUF_SET(CC1100_SRES);
HAL_SPI_WAIT_TXFIN;
// Wait for chip to finish internal reset
while (HAL_SPI_SOMI_VAL);
HAL_SPI_CS_DEASSERT;
}
//----------------------------------------------------------------------------------
// void ITSRfConfig(const HAL_RF_CONFIG* rfConfig, const uint8* rfPaTable, uint8 rfPaTableLen)
//
// DESCRIPTION:
// Used to configure the CC1100/CC1100 registers with exported register
// settings from SmartRF Studio.
//
// ARGUMENTS:
// rfConfig - register settings (as exported from SmartRF Studio)
// rfPaTable - array of PA table values (from SmartRF Studio)
// rfPaTableLen - length of PA table
//
//----------------------------------------------------------------------------------
void ITSRfConfigCC1100(const HAL_RF_CONFIG* rfConfig, const uint8* rfPaTable, uint8 rfPaTableLen)
{
ITSRfWriteReg(CC1100_FSCTRL1, rfConfig->fsctrl1); // Frequency synthesizer control.
ITSRfWriteReg(CC1100_FSCTRL0, rfConfig->fsctrl0); // Frequency synthesizer control.
ITSRfWriteReg(CC1100_FREQ2, rfConfig->freq2); // Frequency control word, high byte.
ITSRfWriteReg(CC1100_FREQ1, rfConfig->freq1); // Frequency control word, middle byte.
ITSRfWriteReg(CC1100_FREQ0, rfConfig->freq0); // Frequency control word, low byte.
ITSRfWriteReg(CC1100_MDMCFG4, rfConfig->mdmcfg4); // Modem configuration.
ITSRfWriteReg(CC1100_MDMCFG3, rfConfig->mdmcfg3); // Modem configuration.
ITSRfWriteReg(CC1100_MDMCFG2, rfConfig->mdmcfg2); // Modem configuration.
ITSRfWriteReg(CC1100_MDMCFG1, rfConfig->mdmcfg1); // Modem configuration.
ITSRfWriteReg(CC1100_MDMCFG0, rfConfig->mdmcfg0); // Modem configuration.
ITSRfWriteReg(CC1100_CHANNR, rfConfig->channr); // Channel number.
ITSRfWriteReg(CC1100_DEVIATN, rfConfig->deviatn); // Modem deviation setting (when FSK modulation is enabled).
ITSRfWriteReg(CC1100_FREND1, rfConfig->frend1); // Front end RX configuration.
ITSRfWriteReg(CC1100_FREND0, rfConfig->frend0); // Front end RX configuration.
ITSRfWriteReg(CC1100_MCSM0, rfConfig->mcsm0); // Main Radio Control State Machine configuration.
ITSRfWriteReg(CC1100_FOCCFG, rfConfig->foccfg); // Frequency Offset Compensation Configuration.
ITSRfWriteReg(CC1100_BSCFG, rfConfig->bscfg); // Bit synchronization Configuration.
ITSRfWriteReg(CC1100_AGCCTRL2, rfConfig->agcctrl2); // AGC control.
ITSRfWriteReg(CC1100_AGCCTRL1, rfConfig->agcctrl1); // AGC control.
ITSRfWriteReg(CC1100_AGCCTRL0, rfConfig->agcctrl0); // AGC control.
ITSRfWriteReg(CC1100_FSCAL3, rfConfig->fscal3); // Frequency synthesizer calibration.
ITSRfWriteReg(CC1100_FSCAL2, rfConfig->fscal2); // Frequency synthesizer calibration.
ITSRfWriteReg(CC1100_FSCAL1, rfConfig->fscal1); // Frequency synthesizer calibration.
ITSRfWriteReg(CC1100_FSCAL0, rfConfig->fscal0); // Frequency synthesizer calibration.
ITSRfWriteReg(CC1100_FSTEST, rfConfig->fstest); // Frequency synthesizer calibration.
ITSRfWriteReg(CC1100_TEST2, rfConfig->test2); // Various test settings.
ITSRfWriteReg(CC1100_TEST1, rfConfig->test1); // Various test settings.
ITSRfWriteReg(CC1100_TEST0, rfConfig->test0); // Various test settings.
ITSRfWriteReg(CC1100_IOCFG2, rfConfig->iocfg2); // GDO2 output pin configuration.
ITSRfWriteReg(CC1100_IOCFG0, rfConfig->iocfg0); // GDO0 output pin configuration.
ITSRfWriteReg(CC1100_PKTCTRL1, rfConfig->pktctrl1); // Packet automation control.
ITSRfWriteReg(CC1100_PKTCTRL0, rfConfig->pktctrl0); // Packet automation control.
ITSRfWriteReg(CC1100_ADDR, rfConfig->addr); // Device address.
ITSRfWriteReg(CC1100_PKTLEN, rfConfig->pktlen); // Packet length.
// ITSRfWriteReg(CC1100_SYNC1 , rfConfig->sync1); // Packet length.
// ITSRfWriteReg(CC1100_SYNC0 , rfConfig->sync0); // Packet length.
ITSSpiWrite(CC1100_PATABLE | CC1100_WRITE_BURST, rfPaTable, rfPaTableLen);
}
//----------------------------------------------------------------------------------
// void ITSRfBurstConfig(const HAL_RF_BURST_CONFIG rfConfig, const uint8* rfPaTable, uint8 rfPaTableLen)
//
// DESCRIPTION:
// Used to configure all of the CC1100/CC1100 registers in one burst write.
//
// ARGUMENTS:
// rfConfig - register settings
// rfPaTable - array of PA table values (from SmartRF Studio)
// rfPaTableLen - length of PA table
//
//----------------------------------------------------------------------------------
void ITSRfBurstConfig(const HAL_RF_BURST_CONFIG rfConfig, const uint8* rfPaTable, uint8 rfPaTableLen)
{
ITSSpiWrite(CC1100_IOCFG2 | CC1100_WRITE_BURST, rfConfig, sizeof(rfConfig));
ITSSpiWrite(CC1100_PATABLE | CC1100_WRITE_BURST, rfPaTable, rfPaTableLen);
}
//----------------------------------------------------------------------------------
// uint8 ITSRfGetChipId(void)
//----------------------------------------------------------------------------------
uint8 ITSRfGetChipId(void)
{
return(ITSRfReadStatusReg(CC1100_PARTNUM));
}
//----------------------------------------------------------------------------------
// uint8 ITSRfGetChipVer(void)
//----------------------------------------------------------------------------------
uint8 ITSRfGetChipVer(void)
{
return(ITSRfReadStatusReg(CC1100_VERSION));
}
//----------------------------------------------------------------------------------
// HAL_RF_STATUS ITSRfStrobe(uint8 cmd)
//----------------------------------------------------------------------------------
HAL_RF_STATUS ITSRfStrobe(uint8 cmd)
{
return(ITSSpiStrobe(cmd));
}
//----------------------------------------------------------------------------------
// uint8 ITSRfReadStatusReg(uint8 addr)
//
// NOTE:
// When reading a status register over the SPI interface while the register
// is updated by the radio hardware, there is a small, but finite, probability
// that the result is corrupt. The CC1100 and CC1100 errata notes explain the
// problem and propose several workarounds.
//
//----------------------------------------------------------------------------------
uint8 ITSRfReadStatusReg(uint8 addr)
{
uint8 reg;
ITSSpiRead(addr | CC1100_READ_BURST, ®, 1);
return(reg);
}
//----------------------------------------------------------------------------------
// uint8 ITSRfReadReg(uint8 addr)
//----------------------------------------------------------------------------------
uint8 ITSRfReadReg(uint8 addr)
{
uint8 reg;
ITSSpiRead(addr | CC1100_READ_SINGLE, ®, 1);
return(reg);
}
//----------------------------------------------------------------------------------
// HAL_RF_STATUS ITSRfWriteReg(uint8 addr, uint8 data)
//----------------------------------------------------------------------------------
HAL_RF_STATUS ITSRfWriteReg(uint8 addr, uint8 data)
{
uint8 rc;
rc = ITSSpiWrite(addr, &data, 1);
return(rc);
}
//----------------------------------------------------------------------------------
// HAL_RF_STATUS ITSRfWriteFifo(uint8* data, uint8 length)
//----------------------------------------------------------------------------------
HAL_RF_STATUS ITSRfWriteFifo(const uint8* data, uint8 length)
{
return(ITSSpiWrite(CC1100_TXFIFO | CC1100_WRITE_BURST, data, length));
}
//----------------------------------------------------------------------------------
// HAL_RF_STATUS ITSRfReadFifo(uint8* data, uint8 length)
//----------------------------------------------------------------------------------
HAL_RF_STATUS ITSRfReadFifo(uint8* data, uint8 length)
{
return(ITSSpiRead(CC1100_RXFIFO | CC1100_READ_BURST, data, length));
}
//----------------------------------------------------------------------------------
// uint8 ITSRfGetTxStatus(void)
//
// DESCRIPTION:
// This function transmits a No Operation Strobe (SNOP) to get the status of
// the radio and the number of free bytes in the TX FIFO
//
// Status byte:
//
// ---------------------------------------------------------------------------
// | | | |
// | CHIP_RDY | STATE[2:0] | FIFO_BYTES_AVAILABLE (free bytes in the TX FIFO |
// | | | |
// ---------------------------------------------------------------------------
//
// NOTE:
// When reading a status register over the SPI interface while the register
// is updated by the radio hardware, there is a small, but finite, probability
// that the result is corrupt. This also applies to the chip status byte. The
// CC1100 and CC1100 errata notes explain the problem and propose several
// workarounds.
//
//----------------------------------------------------------------------------------
HAL_RF_STATUS ITSRfGetTxStatus(void)
{
return(ITSSpiStrobe(CC1100_SNOP));
}
//----------------------------------------------------------------------------------
// uint8 ITSRfGetRxStatus(void)
//
// DESCRIPTION:
// This function transmits a No Operation Strobe (SNOP) with the read bit set
// to get the status of the radio and the number of available bytes in the RX
// FIFO.
//
// Status byte:
//
// --------------------------------------------------------------------------------
// | | | |
// | CHIP_RDY | STATE[2:0] | FIFO_BYTES_AVAILABLE (available bytes in the RX FIFO |
// | | | |
// --------------------------------------------------------------------------------
//
// NOTE:
// When reading a status register over the SPI interface while the register
// is updated by the radio hardware, there is a small, but finite, probability
// that the result is corrupt. This also applies to the chip status byte. The
// CC1100 and CC1100 errata notes explain the problem and propose several
// workarounds.
//
//----------------------------------------------------------------------------------
HAL_RF_STATUS ITSRfGetRxStatus(void)
{
return(ITSSpiStrobe(CC1100_SNOP | CC1100_READ_SINGLE));
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -