📄 ia443x_rf.lst
字号:
884 1
885 1 if( fPacketReceived == TRUE )
886 1 {
887 2 return RF_OK;
888 2 }
889 1 else
890 1 {
891 2 return RF_ERROR_PARAMETER;
892 2 }
893 1 }
894
895 /*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
896 +
897 + FUNCTION NAME: void RFTimerISR(void)
898 +
899 + DESCRIPTION: RF timer ISR routine
900 +
901 + INPUT: None
902 +
903 + RETURN: None
904 +
905 + NOTES:
906 +
907 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
908 INTERRUPT(RFTimerISR, INTERRUPT_TIMER2)
909 {
910 1 #ifdef RF_LED_DEBUG
LED2_PIN = 1;
#endif
913 1 ClearTmr2It();
914 1 if( --Tmr2SwPrescaler == 0 )
915 1 {
916 2 #ifdef RF_LED_DEBUG
LED2_PIN = 0;
#endif
919 2 #ifdef RF_LED_DEBUG
C51 COMPILER V8.00 IA443X_RF 11/17/2008 10:50:33 PAGE 16
LED2_PIN = 1;
#endif
922 2 StopTmr2();
923 2 RFStateMachine( RF_TIMER_IT );
924 2 DisableTmr2It();
925 2 }
926 1 #ifdef RF_LED_DEBUG
LED2_PIN = 0;
#endif
929 1 }
930
931
932 /*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
933 +
934 + FUNCTION NAME: void RFExtISR(void)
935 +
936 + DESCRIPTION: RF external ISR routine
937 +
938 + INPUT: None
939 +
940 + RETURN: None
941 +
942 + NOTES:
943 +
944 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
945 INTERRUPT(RFExtISR, INTERRUPT_INT0)
946 {
947 1 #ifdef RF_LED_DEBUG
LED3_PIN = 1;
#endif
950 1
951 1 DisableTmr2It();
952 1 ItStatus1 = SpiRfReadRegister( InterruptStatus1 );
953 1 ItStatus2 = SpiRfReadRegister( InterruptStatus2 );
954 1 RFStateMachine( RF_EXT_IT );
955 1
956 1 #ifdef RF_LED_DEBUG
LED3_PIN = 0;
#endif
959 1 }
960
961 /*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
962 +
963 + FUNCTION NAME: void GotoPreambleSearchState(void)
964 +
965 + DESCRIPTION: it resets the receiver state machine
966 +
967 + INPUT: None
968 +
969 + RETURN: None
970 +
971 + NOTES:
972 +
973 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
974 void GotoPreambleSearchState(void)
975 {
976 1 //enable the wanted ITs
977 1 SpiRfWriteAddressData((REG_WRITE | InterruptEnable2), 0xc0);
978 1 //enable EXT IT
979 1 EnableExt0It();
980 1 //disable PHY timer
981 1 StopTmr2();
C51 COMPILER V8.00 IA443X_RF 11/17/2008 10:50:33 PAGE 17
982 1 //set next state
983 1 RfState = sRFPreambleSearch;
984 1 }
985
986 /*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
987 +
988 + FUNCTION NAME: void RFStateMachine(RF_ENUM ItSource)
989 +
990 + DESCRIPTION: the state machine of the RF stack
991 +
992 + INPUT: ItSource - the interrupt source which called the state
993 + machine (RF_TIMER_IT or RF_EXT_IT)
994 +
995 + RETURN: None
996 +
997 + NOTES:
998 +
999 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
1000 void RFStateMachine(RF_ENUM ItSource)
1001 {
1002 1 idata uint8 temp8;
1003 1
1004 1 switch( RfState )
1005 1 {
1006 2 case sRFStandBy:
1007 2 case sRFPOR:
1008 2 case sRFIdle:
1009 2 break;
1010 2
1011 2 case sRFWakingUp:
1012 2 StopTmr2();
1013 2 DisableExt0It();
1014 2 //check whether the chip woke up correctly or not
1015 2 if( ItSource == RF_EXT_IT )
1016 2 {//XTAL is running correctly
1017 3 RfState = sRFIdle;
1018 3 }
1019 2 else
1020 2 {//wake up error! XTAL is not running
1021 3 RfState = sRFWakeUpError;
1022 3 }
1023 2 break;
1024 2
1025 2 case sRFWakeUpError:
1026 2 case sRFTxWaiting:
1027 2 break;
1028 2
1029 2 case sRFTransmitting:
1030 2 //disable transmitter
1031 2 temp8 = SpiRfReadRegister( OperatingFunctionControl1 );
1032 2 temp8 &= 0xF1;
1033 2 SpiRfWriteAddressData((REG_WRITE | OperatingFunctionControl1), temp8);
1034 2 //disable TMR and EXT IT
1035 2 StopTmr2();
1036 2 DisableExt0It();
1037 2 //check whether the packet sent correctly
1038 2 if( (ItSource == RF_EXT_IT) && ((ItStatus1 & 0x04) == 0x04) )
1039 2 {//packet sent
1040 3 RfCbPacketSent();
1041 3 RfState = sRFPacketSent;
1042 3 }
1043 2 else
C51 COMPILER V8.00 IA443X_RF 11/17/2008 10:50:33 PAGE 18
1044 2 {//TMR IT occured or ERROR during transmission
1045 3 RfCbTxError();
1046 3 RfState = sRFTxError;
1047 3 }
1048 2 break;
1049 2
1050 2 case sRFTxError:
1051 2 case sRFPacketSent:
1052 2 case sRFRxWaiting:
1053 2 break;
1054 2
1055 2 case sRFPreambleSearch:
1056 2 if( ItSource == RF_EXT_IT )
1057 2 {//EXT IT occured -> preamble detected?
1058 3 if( (ItStatus2 & 0x40) == 0x40 )
1059 3 {//preamble detected
1060 4 RfCbPreambleDetected();
1061 4 RfState = sRFSynchSearch;
1062 4 //enable the FALSE preamble interrupt
1063 4 SpiRfWriteAddressData((REG_WRITE | InterruptEnable2), 0xe0);
1064 4 }
1065 3 }
1066 2 else
1067 2 {//TMR overflow -> HW error
1068 3 GotoPreambleSearchState();
1069 3 //call callback function
1070 3 RfCbRxError();
1071 3 }
1072 2 break;
1073 2
1074 2 case sRFSynchSearch:
1075 2 if( ItSource == RF_EXT_IT )
1076 2 {//EXT IT occured -> Synch word detected
1077 3 if( (ItStatus2 & 0x80) == 0x80 )
1078 3 {//synch word detected
1079 4 //disable the FALSE preamble interrupt
1080 4 SpiRfWriteAddressData((REG_WRITE | InterruptEnable2), 0x00);
1081 4 SpiRfWriteAddressData((REG_WRITE | InterruptEnable1), 0x03);
1082 4 //get RSSI value
1083 4 if( SelectedAntennaType == ANTENNA_DIVERSITY )
1084 4 {
1085 5 Rssi_ant2 = SpiRfReadRegister( AntennaDiversityRegister2 );
1086 5 Rssi_ant1 = SpiRfReadRegister( AntennaDiversityRegister1 );
1087 5 }
1088 4 else
1089 4 {
1090 5 Rssi_ant1 = SpiRfReadRegister( ReceivedSignalStrengthIndicator );
1091 5 }
1092 4 //call callback function
1093 4 RfCbSynchWordDetected();
1094 4 RfState = sRFReceiving;
1095 4 //start timeout for packet receiving
1096 4 RfTimer.U16 = ByteTime * RX_PACKET_LENGTH;
1097 4 Tmr2SwPrescaler = BYTE_TIME_SW_DIV;
1098 4 StartTmr2(BYTE_TIME_DIV,RfTimer,TRUE);
1099 4 return;
1100 4 }
1101 3 if( (ItStatus2 & 0x40) == 0x40 )
1102 3 {//preamble detected
1103 4 return;
1104 4 }
1105 3 if( (ItStatus2 & 0x20) == 0x20 )
C51 COMPILER V8.00 IA443X_RF
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -