📄 ia443x_rf.c
字号:
{//header and header filter are disabled
SpiRfWriteAddressData((REG_WRITE | HeaderControl1 ), 0x00);
temp8 = SpiRfReadRegister( HeaderControl2 );
temp8 &= 0x07;
SpiRfWriteAddressData((REG_WRITE | HeaderControl2 ), temp8);
}
else
{//TODO: header and header filter are enabled - NOT YET IMPLEMENTED
}
//enable receiver chain
temp8 = SpiRfReadRegister( OperatingFunctionControl1 );
temp8 |= 0x05;
SpiRfWriteAddressData((REG_WRITE | OperatingFunctionControl1), temp8);
//enable the wanted ITs
SpiRfWriteAddressData((REG_WRITE | InterruptEnable1), 0x00);
GotoPreambleSearchState();
//release all IT flag
ItStatus1 = SpiRfReadRegister( InterruptStatus1 );
ItStatus2 = SpiRfReadRegister( InterruptStatus2 );
return RF_OK;
}
/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+
+ FUNCTION NAME: RF_ENUM RFGetStatus(PHY_STATUS * Struct)
+
+ DESCRIPTION: gives back the actual state of the PHY
+
+ INPUT: PHY_STATUS structure
+
+ RETURN: RF_OK: The operation was succesfull
+
+ NOTES:
+
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
RF_ENUM RFGetStatus(PHY_STATUS * Struct)
{
Struct -> status = RfState;
return RF_OK;
}
/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+
+ FUNCTION NAME: RF_ENUM RFGetBuffer(RECEIVED_DATA * Struct)
+
+ DESCRIPTION: gives back the received packet and RSSI value. If packet was not
+ recived it gives back only the RSSI value.
+
+ INPUT: RECEIVED_DATA structure
+
+ RETURN: RF_OK: operation was succesfull.
+
+ NOTES:
+
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
RF_ENUM RFGetBuffer(RECEIVED_DATA * Struct)
{
uint8 i;
Struct -> fPacketReceived = fPacketReceived;
//get header
if( Struct -> message.header.enabled_headers != 0 )
{
//TODO: implement this
}
//get received data and length
Struct -> message.length = SpiRfReadRegister( ReceivedPacketLength );
for(i=0;i<Struct -> message.length;i++)
{
*Struct -> message.payload++ = SpiRfReadRegister( FIFOAccess );
}
return RF_OK;
}
/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+
+ FUNCTION NAME: RF_ENUM RFGetRssiResult(uint8 * ant1, uint8 * ant2)
+
+ DESCRIPTION: gives back the RSSI values. If packet was not received
+ it returns with RF_ERROR_PARAMETER
+
+ INPUT: None
+
+ RETURN: RF_OK: operation was succesfull.
+ RF_ERROR_PARAMETER: packet was not received - the values are may not relevant
+ ant1 - RSSI on ANT1 or RSSI register value (in case not using ant diversity)
+ ant2 - RSSI on ANT2 (valid only if diersity is used)
+
+ NOTES:
+
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
RF_ENUM RFGetRssiResult(uint8 * ant1, uint8 * ant2)
{
*ant1 = Rssi_ant1;
*ant2 = Rssi_ant2;
if( fPacketReceived == TRUE )
{
return RF_OK;
}
else
{
return RF_ERROR_PARAMETER;
}
}
/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+
+ FUNCTION NAME: void RFTimerISR(void)
+
+ DESCRIPTION: RF timer ISR routine
+
+ INPUT: None
+
+ RETURN: None
+
+ NOTES:
+
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
INTERRUPT(RFTimerISR, INTERRUPT_TIMER2)
{
#ifdef RF_LED_DEBUG
LED2_PIN = 1;
#endif
ClearTmr2It();
if( --Tmr2SwPrescaler == 0 )
{
#ifdef RF_LED_DEBUG
LED2_PIN = 0;
#endif
#ifdef RF_LED_DEBUG
LED2_PIN = 1;
#endif
StopTmr2();
RFStateMachine( RF_TIMER_IT );
DisableTmr2It();
}
#ifdef RF_LED_DEBUG
LED2_PIN = 0;
#endif
}
/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+
+ FUNCTION NAME: void RFExtISR(void)
+
+ DESCRIPTION: RF external ISR routine
+
+ INPUT: None
+
+ RETURN: None
+
+ NOTES:
+
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
INTERRUPT(RFExtISR, INTERRUPT_INT0)
{
#ifdef RF_LED_DEBUG
LED3_PIN = 1;
#endif
DisableTmr2It();
ItStatus1 = SpiRfReadRegister( InterruptStatus1 );
ItStatus2 = SpiRfReadRegister( InterruptStatus2 );
RFStateMachine( RF_EXT_IT );
#ifdef RF_LED_DEBUG
LED3_PIN = 0;
#endif
}
/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+
+ FUNCTION NAME: void GotoPreambleSearchState(void)
+
+ DESCRIPTION: it resets the receiver state machine
+
+ INPUT: None
+
+ RETURN: None
+
+ NOTES:
+
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
void GotoPreambleSearchState(void)
{
//enable the wanted ITs
SpiRfWriteAddressData((REG_WRITE | InterruptEnable2), 0xc0);
//enable EXT IT
EnableExt0It();
//disable PHY timer
StopTmr2();
//set next state
RfState = sRFPreambleSearch;
}
/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+
+ FUNCTION NAME: void RFStateMachine(RF_ENUM ItSource)
+
+ DESCRIPTION: the state machine of the RF stack
+
+ INPUT: ItSource - the interrupt source which called the state
+ machine (RF_TIMER_IT or RF_EXT_IT)
+
+ RETURN: None
+
+ NOTES:
+
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
void RFStateMachine(RF_ENUM ItSource)
{
idata uint8 temp8;
switch( RfState )
{
case sRFStandBy:
case sRFPOR:
case sRFIdle:
break;
case sRFWakingUp:
StopTmr2();
DisableExt0It();
//check whether the chip woke up correctly or not
if( ItSource == RF_EXT_IT )
{//XTAL is running correctly
RfState = sRFIdle;
}
else
{//wake up error! XTAL is not running
RfState = sRFWakeUpError;
}
break;
case sRFWakeUpError:
case sRFTxWaiting:
break;
case sRFTransmitting:
//disable transmitter
temp8 = SpiRfReadRegister( OperatingFunctionControl1 );
temp8 &= 0xF1;
SpiRfWriteAddressData((REG_WRITE | OperatingFunctionControl1), temp8);
//disable TMR and EXT IT
StopTmr2();
DisableExt0It();
//check whether the packet sent correctly
if( (ItSource == RF_EXT_IT) && ((ItStatus1 & 0x04) == 0x04) )
{//packet sent
RfCbPacketSent();
RfState = sRFPacketSent;
}
else
{//TMR IT occured or ERROR during transmission
RfCbTxError();
RfState = sRFTxError;
}
break;
case sRFTxError:
case sRFPacketSent:
case sRFRxWaiting:
break;
case sRFPreambleSearch:
if( ItSource == RF_EXT_IT )
{//EXT IT occured -> preamble detected?
if( (ItStatus2 & 0x40) == 0x40 )
{//preamble detected
RfCbPreambleDetected();
RfState = sRFSynchSearch;
//enable the FALSE preamble interrupt
SpiRfWriteAddressData((REG_WRITE | InterruptEnable2), 0xe0);
}
}
else
{//TMR overflow -> HW error
GotoPreambleSearchState();
//call callback function
RfCbRxError();
}
break;
case sRFSynchSearch:
if( ItSource == RF_EXT_IT )
{//EXT IT occured -> Synch word detected
if( (ItStatus2 & 0x80) == 0x80 )
{//synch word detected
//disable the FALSE preamble interrupt
SpiRfWriteAddressData((REG_WRITE | InterruptEnable2), 0x00);
SpiRfWriteAddressData((REG_WRITE | InterruptEnable1), 0x03);
//get RSSI value
if( SelectedAntennaType == ANTENNA_DIVERSITY )
{
Rssi_ant2 = SpiRfReadRegister( AntennaDiversityRegister2 );
Rssi_ant1 = SpiRfReadRegister( AntennaDiversityRegister1 );
}
else
{
Rssi_ant1 = SpiRfReadRegister( ReceivedSignalStrengthIndicator );
}
//call callback function
RfCbSynchWordDetected();
RfState = sRFReceiving;
//start timeout for packet receiving
RfTimer.U16 = ByteTime * RX_PACKET_LENGTH;
Tmr2SwPrescaler = BYTE_TIME_SW_DIV;
StartTmr2(BYTE_TIME_DIV,RfTimer,TRUE);
return;
}
if( (ItStatus2 & 0x40) == 0x40 )
{//preamble detected
return;
}
if( (ItStatus2 & 0x20) == 0x20 )
{//false preamble detected
GotoPreambleSearchState();
//call callback function
RfCbFalsePreambleDetected();
return;
}
//Not expected operation -> goto preamble search state
GotoPreambleSearchState();
}
else
{//TMR overflow -> HW error
GotoPreambleSearchState();
//call callback function
RfCbRxError();
}
break;
case sRFReceiving:
if( ItSource == RF_EXT_IT )
{//EXT IT occured -> Packet valid?
if( (ItStatus1 & 0x02) == 0x02 )
{//packet received
//disable receiver
temp8 = SpiRfReadRegister( OperatingFunctionControl1 );
temp8 &= 0xF1;
SpiRfWriteAddressData((REG_WRITE | OperatingFunctionControl1), temp8);
//call callback function
RfCbPacketReceived();
RfState = sRFPacketReceived;
StopTmr2();
DisableExt0It();
fPacketReceived = TRUE;
return;
}
if( (ItStatus1 & 0x01) == 0x01 )
{//CRC Error
GotoPreambleSearchState();
//call callback function
RfCbCrcError();
return;
}
//Not expected operation -> goto preamble search state
GotoPreambleSearchState();
}
else
{//TMR overflow -> HW error
GotoPreambleSearchState();
//call callback function
RfCbRxError();
}
break;
case sRFPacketReceived:
break;
default:
break;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -