📄 hal_rf.c
字号:
* @brief Write PAN Id to chip
*
* @param none
*
* @return none
*/
void halRfSetPanId(uint16 panId)
{
CC2520_MEMWR16(CC2520_RAM_PANID, panId);
}
/***********************************************************************************
* @fn halRfSetTxPower
*
* @brief Set TX output power
*
* @param uint8 power - power level
*
* @return SUCCESS or FAILED
*/
uint8 halRfSetTxPower(uint8 power)
{
uint8 n;
switch(power)
{
#ifdef INCLUDE_PA
case HAL_RF_TXPOWER_5_DBM: n = CC2520_TXPOWER_5_DBM; break;
case HAL_RF_TXPOWER_10_DBM: n = CC2520_TXPOWER_10_DBM; break;
case HAL_RF_TXPOWER_13_DBM: n = CC2520_TXPOWER_13_DBM; break;
case HAL_RF_TXPOWER_15_DBM: n = CC2520_TXPOWER_15_DBM; break;
case HAL_RF_TXPOWER_17_DBM: n = CC2520_TXPOWER_17_DBM; break;
#else
case HAL_RF_TXPOWER_MIN_4_DBM: n = CC2520_TXPOWER_MIN_4_DBM; break;
case HAL_RF_TXPOWER_0_DBM: n = CC2520_TXPOWER_0_DBM; break;
case HAL_RF_TXPOWER_4_DBM: n = CC2520_TXPOWER_4_DBM; break;
#endif
default:
return FAILED;
}
CC2520_REGWR8(CC2520_TXPOWER, n);
return SUCCESS;
}
/***********************************************************************************
* @fn halRfSetGain
*
* @brief Set gain mode - only applicable for units with CC2590/91.
*
* @param uint8 - gain mode
*
* @return none
*/
void halRfSetGain(uint8 gainMode)
{
if (gainMode==HAL_RF_GAIN_LOW) {
HAL_PA_LNA_RX_LGM();
rssiOffset = RSSI_OFFSET_LNA_LOWGAIN;
} else {
HAL_PA_LNA_RX_HGM();
rssiOffset = RSSI_OFFSET_LNA_HIGHGAIN;
}
}
/***********************************************************************************
* @fn halRfWriteTxBuf
*
* @brief Write to TX buffer
*
* @param uint8* data - buffer to write
* uint8 length - number of bytes
*
* @return none
*/
void halRfWriteTxBuf(uint8* data, uint8 length)
{
// Copy packet to TX FIFO
CC2520_TXBUF(length,data);
}
/***********************************************************************************
* @fn halRfReadRxBuf
*
* @brief Read RX buffer
*
* @param uint8* data - data buffer. This must be allocated by caller.
* uint8 length - number of bytes
*
* @return none
*/
void halRfReadRxBuf(uint8* data, uint8 length)
{
CC2520_RXBUF(length, data);
}
/***********************************************************************************
* @fn halRfTransmit
*
* @brief Transmit frame with Clear Channel Assessment.
*
* @param none
*
* @return uint8 - SUCCESS or FAILED
*/
uint8 halRfTransmit(void)
{
uint16 timeout = 2500; // 2500 x 20us = 50ms
uint8 status=0;
// Wait for RSSI to become valid
while(!CC2520_RSSI_VALID_PIN);
// Reuse GPIO2 for TX_FRM_DONE exception
HAL_INT_OFF();
CC2520_CFG_GPIO_OUT(2, 1 + CC2520_EXC_TX_FRM_DONE);
HAL_INT_ON();
// Wait for the transmission to begin before exiting (makes sure that this function cannot be called
// a second time, and thereby cancelling the first transmission.
while(--timeout > 0) {
HAL_INT_OFF();
CC2520_INS_STROBE(CC2520_INS_STXONCCA);
HAL_INT_ON();
if (CC2520_SAMPLED_CCA_PIN) break;
halMcuWaitUs(20);
}
if (timeout == 0) {
status = FAILED;
CC2520_INS_STROBE(CC2520_INS_SFLUSHTX);
}
else {
status = SUCCESS;
// Wait for TX_FRM_DONE exception
while(!CC2520_TX_FRM_DONE_PIN);
HAL_INT_OFF();
CC2520_CLEAR_EXC(CC2520_EXC_TX_FRM_DONE);
HAL_INT_ON();
}
// Reconfigure GPIO2
HAL_INT_OFF();
CC2520_CFG_GPIO_OUT(2, CC2520_GPIO_RSSI_VALID);
HAL_INT_ON();
return status;
}
/***********************************************************************************
* @fn halRfReceiveOn
*
* @brief Turn receiver on
*
* @param none
*
* @return none
*/
void halRfReceiveOn(void)
{
CC2520_INS_STROBE(CC2520_INS_SRXON);
}
/***********************************************************************************
* @fn halRfReceiveOff
*
* @brief Turn receiver off
*
* @param none
*
* @return none
*/
void halRfReceiveOff(void)
{
CC2520_INS_STROBE(CC2520_INS_SRFOFF);
}
/***********************************************************************************
* @fn halRfDisableRxInterrupt
*
* @brief Clear and disable RX interrupt.
*
* @param none
*
* @return none
*/
void halRfDisableRxInterrupt(void)
{
// Clear the exception and the IRQ
CLEAR_EXC_RX_FRM_DONE();
halDigioIntClear(&pinRadio_GPIO0);
halDigioIntDisable(&pinRadio_GPIO0);
}
/***********************************************************************************
* @fn halRfEnableRxInterrupt
*
* @brief Enable RX interrupt.
*
* @param none
*
* @return none
*/
void halRfEnableRxInterrupt(void)
{
halDigioIntEnable(&pinRadio_GPIO0);
}
/***********************************************************************************
* @fn halRfRxInterruptConfig
*
* @brief Enable RX interrupt.
*
* @param none
*
* @return none
*/
void halRfRxInterruptConfig(ISR_FUNC_PTR pfISR)
{
halDigioIntSetEdge(&pinRadio_GPIO0, HAL_DIGIO_INT_RISING_EDGE);
halDigioIntConnect(&pinRadio_GPIO0, pfISR);
halDigioIntEnable(&pinRadio_GPIO0);
// And clear the exception
CLEAR_EXC_RX_FRM_DONE();
}
/***********************************************************************************
* @fn halRfWaitTransceiverReady
*
* @brief Wait until the transceiver is ready (SFD low).
*
* @param none
*
* @return none
*/
void halRfWaitTransceiverReady(void)
{
#ifdef INCLUDE_PA
// GPIO3 is not conncted to combo board; use SFD at GPIO2 instead
HAL_INT_OFF();
// GPIO2 = SFD
CC2520_CFG_GPIO_OUT(2,CC2520_GPIO_SFD);
while (CC2520_GPIO2_IPIN);
// GPIO2 = default (RSSI_VALID)
CC2520_CFG_GPIO_OUT(2,CC2520_GPIO_RSSI_VALID);
HAL_INT_ON();
#else
while (CC2520_GPIO3_IPIN);
#endif
}
/***********************************************************************************
* LOCAL FUNCTIONS
*/
/***********************************************************************************
* @fn halRfWaitRadioReady
*
* @brief Wait for the crystal oscillator to stabilise.
*
* @param none
*
* @return SUCCESS if oscillator starts, FAILED otherwise
*/
static uint8 halRfWaitRadioReady(void)
{
uint8 i;
// Wait for XOSC stable to be announced on the MISO pin
i= 100;
CC2520_CSN_OPIN(0);
while (i>0 && !CC2520_MISO_IPIN) {
halMcuWaitUs(10);
--i;
}
CC2520_CSN_OPIN(1);
return i>0 ? SUCCESS : FAILED;
}
/***********************************************************************************
* @fn halRfGetStatusByte
*
* @brief Get chip status byte
*
* @param none
*
* @return uint8 - chip status byte
*/
uint8 halRfGetStatusByte(void)
{
return CC2520_INS_STROBE(CC2520_INS_SNOP);
}
/***********************************************************************************
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 + -