⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ia443x_demo.c

📁 silicon wireless开发套件F920+Si4432原理图,源码
💻 C
📖 第 1 页 / 共 3 页
字号:
			//set the payload of PING message
			RxTxBuffer[0] = MenuItems.name.self_id;				//source address field
			RxTxBuffer[1] = MenuItems.name.dest_id;				//destination address field
			RxTxBuffer[2] = (uint8)(NmbrOfSentPackets >> 8);		//16bit packet ID (incremented after every
			RxTxBuffer[3] = (uint8)(NmbrOfSentPackets & 0x00FF);	//		PING packet transmission
			RxTxBuffer[4] = PING_PACKET;									//packet type field
			//set the PING message
			MessageBuffer.header = HeaderBuffer;
			MessageBuffer.length = 5;								
			MessageBuffer.payload = &RxTxBuffer[0];
			//start sending the PING packet
			LED_TX = 1;
			RFTransmit(&MessageBuffer);
			//set flag ->PING packet sent
			fPacketSent = PING_PACKET;
			//next state
			DemoStates = sDemoWaitForSendPacket;
		break;

		case sDemoWaitForSendPacket:
			if( fChangeDemoStates == TRUE )
			{
				fChangeDemoStates = FALSE;
				DemoStates = NewDemoStates;
			}

		break;

		case sDemoPacketSent:
			//check what kind of packet has sent
			LED_TX = 0;
			if( MenuItems.name.demo_mode == DEMO_MODE_TX )
			{
				//stop the RF stack
				RFIdle();
				MenuReportSentPackets( NmbrOfSentPackets );
				DemoStates = sDemoTxStartTransmit;
				return;
			}
			if( fPacketSent == PING_PACKET )
			{//PING packet sent -> goto RX state immediatelly: wait for ACK
				//stop the RF stack
				RFIdle();
				//set flags -> wait for simple packet and not for ACK
				fWaitForPacketOrAck = ACK_PACKET;
				//start receiving
				RFReceive(&RxCommand);
				//start timeout (~300ms)
				LongDelay = 3;
				DemoTimer.U16 = 65530;
				StartTmr3(TMR3_12, DemoTimer, FALSE);
				//next state
				DemoStates = sDemoWaitForAck;
			}
			if( fPacketSent == ACK_PACKET )
			{//ACK packet sent -> goto RX state: wait for push button or another PING packet
				//stop the RF stack
				RFIdle();
				//report that ACK sent correctly
				DemoAckSent(TRUE);	
				//next state
				DemoStates = sDemoStartReceive;
			}
		break;
		
		case sDemoTxError:
			//error occured during packet transmission
			LED_TX = 0;
			if( fPacketSent == PING_PACKET)
			{//ping packet didn't send, because error occured
				PerformMenu( sMenuPingTxError );
				if( MenuItems.name.demo_mode == DEMO_MODE_TX )
				{
					RFIdle();
					DemoStates = sDemoTxStartTransmit;
					return;
				}
				else
				{
					DemoStates = sDemoStartReceive;
				}
			}
			if( fPacketSent == ACK_PACKET )	
			{//ACK packet didn't send, because error occured
			}
		break;

		case sDemoWaitForAck:
			if( fChangeDemoStates == TRUE )
			{
				fChangeDemoStates = FALSE;
				DemoStates = NewDemoStates;
				return;
			}
			if( Tmr3Expired() == TRUE )
			{//ACK didn't receive within timeout
				if( --LongDelay == 0 )
				{
					//stop timer & RF Stack
					StopTmr3();
					RFIdle();
					//report that timeout occured and ACK didn't receive
					DemoAckReceived(FALSE);
					//goto RX state: wait for push button or another PING packet
					DemoStates = sDemoStartReceive;
					return;
				}
				else
				{//restart timer
					DemoTimer.U16 = 65530;
					StartTmr3(TMR3_12, DemoTimer, FALSE);
				}
			}
		break;		

		case sDemoDoNothing:
		break;

		default:
		break;
	}
}

/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  +
  + FUNCTION NAME:  void DemoAckSent(uint8 success)
  +
  + DESCRIPTION:    the function is called if the ACK packet sent correctly
  +					or there was a problem to send it. It reports the result
  +					on the LCD and to the UART.
  +
  +	INPUT:			success - status of the ACK transmition (TRUE/FALSE)
  +
  + RETURN:         None
  +
  + NOTES:          
  +
  +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
void DemoAckSent(uint8 success)
{
	if( success == TRUE )
	{//packet sent correctly
		LED_TX = 1;
		PerformMenu( sMenuAckSent );
		LED_TX = 0;
	}
	else
	{//error occured during packet transmission
		PerformMenu( sMenuAckTxError	 );
	}
	//timeout to show the result (~98ms)
	DemoTimer.U16 = 65530;
	StartTmr3(TMR3_12, DemoTimer, FALSE);
	while( Tmr3Expired() == FALSE );	
	StopTmr3();
	PerformMenu( sMenuDeleteMessageRow );
}

/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  +
  + FUNCTION NAME:  void DemoPingReceived(uint16 pid)
  +
  + DESCRIPTION:    the function is called if a PING packet received correctly
  +					It reports the result on the LCD and to the UART.
  +
  +	INPUT:			pid		- packet ID of the received PING packet
  +
  + RETURN:         None
  +
  + NOTES:          
  +
  +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
void DemoPingReceived(void)
{
	LED_RX = 1;
	BLED_PIN = 1;
	//print RSSI result
	PerformMenu(sMenuPingReceived);
	DemoTimer.U16 = 15000;
	StartTmr3(TMR3_12, DemoTimer, FALSE);
	while( Tmr3Expired() == FALSE );	
	StopTmr3();
	LED_RX = 0;
	BLED_PIN = 0;
}

/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  +
  + FUNCTION NAME:  void DemoAckReceived(uint8 success, uint16 pid)
  +
  + DESCRIPTION:    the function is called if an ACK packet received correctly
  +					or there was a problem during the ACK reception.
  +					It reports the result on the LCD and to the UART.
  +
  +	INPUT:			success - status of the ACK reception (TRUE/FALSE)
  +					pid		- packet ID of the received ACK
  +
  + RETURN:         None
  +
  + NOTES:          
  +
  +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
void DemoAckReceived(uint8 success)
{
float temp_float;

	//set the variable
	if( success == TRUE )
	{
		LED_RX = 1;
		BLED_PIN = 1;
		NmbrOfReceivedPackets++;
		PerformMenu( sMenuAckReceivedMessage );
	}
	else
	{
		PerformMenu(sMenuAckReceivingErrorMessage);
	}
	//calc the PER
	temp_float = CalcPer(NmbrOfSentPackets,NmbrOfReceivedPackets);
	
	//report the result
	MenuReportPer(NmbrOfSentPackets,NmbrOfReceivedPackets,temp_float);

	LED_RX = 0;
	BLED_PIN = 0;
	DemoTimer.U16 = 65530;
	StartTmr3(TMR3_12, DemoTimer, FALSE);
	while( Tmr3Expired() == FALSE );	
	StopTmr3();
	PerformMenu( sMenuDeleteMessageRow);
}

/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  +
  + FUNCTION NAME:  float CalcPer(uint16 total, uint16 received)
  +
  + DESCRIPTION:    calculate the PER
  +	
  + RETURN:         PER in percentage
  +
  +	INPUT:			total    - total number of expected packages
  +					received - number of received packages
  +
  + NOTES:          
  +
  +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
float CalcPer(uint16 total, uint16 received)
{
	float temp_float;

	temp_float = 0;

	if( total != 0 )
	{
		temp_float = ((float)(total - received) / (float)total) * 100;		
		if(temp_float > 100)
		{
			temp_float = 100;
		}
	}

	return temp_float;
}


/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  +
  + FUNCTION NAME:  void SetRadio(void)
  +
  + DESCRIPTION:    set radio parameters
  +	
  + RETURN:         Freq number
  +
  +	INPUT:			data rate
  +
  + NOTES:          
  +
  +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
void SetRadio(void)
{
uint8 temp8;

	//wake up the RF chip if it was in standby state
	temp8 = RFWakeUp();
	if( temp8 == RF_OK )
	{//wait for waking up	
		do{RFGetStatus(&RfStatus);} while( RfStatus.status == sRFWakingUp );
		RFGetStatus(&RfStatus);
		if( RfStatus.status == sRFWakeUpError )
		{
			PerformMenu( sMenuXTALError );
		}
	}
	else
	{//reset the RF stack
		RFIdle();
	}

	//set frequency
	if( MenuItems.name.arib_mode == FALSE )
	{
		rf_param[0] = demo_freqs[MenuItems.name.frequency].frequency_band;
		rf_param[1] = (uint8)(demo_freqs[MenuItems.name.frequency].frequency >> 8);
		rf_param[2] = (uint8)(demo_freqs[MenuItems.name.frequency].frequency & 0x00FF);
	}
	else
	{
		rf_param[0] = arib_freqs[MenuItems.name.frequency].frequency_band;
		rf_param[1] = (uint8)(arib_freqs[MenuItems.name.frequency].frequency >> 8);
		rf_param[2] = (uint8)(arib_freqs[MenuItems.name.frequency].frequency & 0x00FF);
	}
	RFSetParameter(pRfFrequency, rf_param, 3);

	//header fields are not used in the packet
	HeaderBuffer.enabled_headers = 0;
	RxCommand.header = HeaderBuffer;
	//synch word
	rf_param[0] = 2;
	rf_param[1] = 0x2D;
	rf_param[2] = 0xD4;
	RFSetParameter(pRfSynchronWord, rf_param, 3);
	//GPIOs
	switch( SelectedAntennaType )
	{
		case RX_TX_SWITCH:
			rf_param[0] = FALSE;
			RFSetParameter(pRfAntennaDiversity, rf_param, 1);
			//TRX switch control - GPIO1: TX_STATE, GPIO2: RX_STATE 
			rf_param[0] = GPIO_GND;
			rf_param[1] = GPIO_TX_STATE;
			rf_param[2] = GPIO_RX_STATE;
		break;
		case ANTENNA_DIVERSITY:
			rf_param[0] = TRUE;
			RFSetParameter(pRfAntennaDiversity, rf_param, 1);
			//ANT diversity - GPIO1 & 2 is ANT DIV switch signals
			rf_param[0] = GPIO_RX_DATA;//GPIO_GND;
			rf_param[1] = GPIO_ANT1_SWITCH;
			rf_param[2] = GPIO_ANT2_SWITCH;
		break;
		case DIVERSITY_FIX_A:
			rf_param[0] = FALSE;
			RFSetParameter(pRfAntennaDiversity, rf_param, 1);
			//TRX switch control - GPIO1: RX_STATE, GPIO2: TX_STATE 
			rf_param[0] = GPIO_GND;
			rf_param[1] = GPIO_RX_STATE;
			rf_param[2] = GPIO_TX_STATE;
		break;
		case DIVERSITY_FIX_B:
			rf_param[0] = FALSE;
			RFSetParameter(pRfAntennaDiversity, rf_param, 1);
			//TRX switch control - GPIO1: TX_STATE, GPIO2: RX_STATE 
			rf_param[0] = GPIO_GND;
			rf_param[1] = GPIO_TX_STATE;
			rf_param[2] = GPIO_RX_STATE;
		break;
		case SEPARATE_RX_TX:
		default:
			rf_param[0] = FALSE;
			RFSetParameter(pRfAntennaDiversity, rf_param, 1);
			//separate RX & TX SMA connector - GPIOs are not used -> ground them
			rf_param[0] = GPIO_GND;
			rf_param[1] = GPIO_GND;
			rf_param[2] = GPIO_GND;
		break;
	}
	RFSetParameter(pRfGpios, rf_param, 3);
	//set rf parameters according the requirements
	RFSetRfParameters( MenuItems.name.modulation_mode, MenuItems.name.arib_mode, MenuItems.name.data_rate );	
}

/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  +
  + FUNCTION NAME:  void GetAntDiversityResult(void)
  +
  + DESCRIPTION:    switch the ANT LEDs according the RSSI on the antennas 
  +	
  + RETURN:         
  +
  +	INPUT:			
  +
  + NOTES:          
  +
  +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
void GetAntDiversityResult(void)
{
	uint8 RssiAnt1, RssiAnt2;
	
	//get RSSI info from the PHY layer
	RFGetRssiResult(&RssiAnt1, &RssiAnt2);
	//switch the LEDs accordingly
	switch( SelectedAntennaType )
	{
		//antenna div used -> find out which is the stronger signal
		case ANTENNA_DIVERSITY:
			if( RssiAnt1 > RssiAnt2 )
			{//the reception is done on ANT1
				LED_ANT1 = 1;
				LED_ANT2 = 0;
			}
			else
			{//the reception is done on ANT2
				LED_ANT1 = 0;
				LED_ANT2 = 1;
			}
		break;

		//ANT2 is selected as fix antenna
		case DIVERSITY_FIX_B:
			LED_ANT1 = 0;
			LED_ANT2 = 1;
		break;

		//no diversity is used, show ANT1 LED
		default:
			LED_ANT1 = 1;
			LED_ANT2 = 0;
		break;
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -