您好,欢迎访问三七文档
当前位置:首页 > 行业资料 > 酒店餐饮 > CC2530程序代码
/***********************************************************************************Filename:per_test.cDescription:Thisapplicationfunctionsasapacketerrorrate(PER)tester.Onenodeissetupastransmitterandtheotherasreceiver.TheroleandconfigurationparametersforthePERtestofthenodeischosenoninitalisationbynavigatingthejoystickandconfirmthechoiceswithS1.Theconfigurationparametersarechannel,burstsizeandtxpower.PushS1toenterthemenu.Thentheconfigurationparametersaresetbypressingjoysticktorightorleft(increase/decreasevalue)andconfirmwithS1.Afterconfigurationofboththereceiverandtransmitter,thePERtestisstartedbypressingjoystickuponthetransmitter.Bypressingjoystickupagainthetestisstopped.***********************************************************************************//************************************************************************************INCLUDES*/#includehal_lcd.h#includehal_led.h#includehal_int.h#includehal_timer_32k.h#includehal_joystick.h#includehal_button.h#includehal_board.h#includehal_rf.h#includehal_assert.h#includeutil_lcd.h#includebasic_rf.h#includeper_test.h/************************************************************************************CONSTANTS*///Applicationstates#defineIDLE0#defineTRANSMIT_PACKET1/************************************************************************************LOCALVARIABLES*/staticbasicRfCfg_tbasicRfConfig;staticperTestPacket_ttxPacket;staticperTestPacket_trxPacket;staticvolatileuint8appState;staticvolatileuint8appStarted;/************************************************************************************LOCALFUNCTIONS*/staticvoidappTimerISR(void);staticvoidappStartStop(void);staticvoidappTransmitter();staticvoidappReceiver();/************************************************************************************@fnappTimerISR**@brief32KHztimerinterruptserviceroutine.SignalsPERtesttransmitter*applicationtotransmitapacketbysettingapplicationstate.**@paramnone**@returnnone*/staticvoidappTimerISR(void)//¶¨Ê±Æ÷´¥·¢¸ÄΪ·¢Éä״̬£¬·¢ËÍÒ»¸öÊý¾Ý°ü{appState=TRANSMIT_PACKET;}/************************************************************************************@fnappStartStop**@briefJoystickupinterruptserviceroutine.Startorstop32KHztimer,*andtherebystartorstopPERtestpackettransmission.*ÖжϷþÎñ³ÌÐòµÄ²Ù×ݸˡ£Æô¶¯»òÍ£Ö¹32KHzµÄ¶¨Ê±Æ÷£¬´Ó¶øÆô¶¯»òֹͣÿ¸ö²âÊÔÊý¾Ý°ü´«Êä¡£*@paramnone**@returnnone*/staticvoidappStartStop(void){//togglevalueappStarted^=1;if(appStarted){halTimer32kIntEnable();}else{halTimer32kIntDisable();}}/************************************************************************************@fnappConfigTimer**@briefConfiguretimerinterruptsforapplication.Uses32KHztimer*ÅäÖÃÓ¦ÓóÌÐòµÄ¶¨Ê±Æ÷Öжϡ£Ê¹ÓÃ32KHzµÄ¼ÆʱÆ÷*@paramuint16rate-Frequencyoftimerinterrupt.Thisvaluemustbe*between1and32768Hz**@returnnone*/staticvoidappConfigTimer(uint16rate)//¶¨Ê±Æ÷ÉèÖÃ{halTimer32kInit(TIMER_32K_CLK_FREQ/rate);halTimer32kIntConnect(&appTimerISR);}/************************************************************************************@fnappReceiver½ÓÊÕÆ÷**@briefApplicationcodeforthereceivermode.PutsMCUinendlessloop**@parambasicRfConfig-filescopevariable.BasicRFconfigurationdata*rxPacket-filescopevariableoftypeperTestPacket_t**@returnnone*/staticvoidappReceiver(){uint32segNumber=0;int16perRssiBuf[RSSI_AVG_WINDOW_SIZE]={0};//RingbufferforRSSIuint8perRssiBufCounter=0;//Countertokeeptrackofthe//oldestnewestbyteinRSSI//ringbufferperRxStats_trxStats={0,0,0,0};int16rssi;uint8resetStats=FALSE;#ifdefINCLUDE_PAuint8gain;//Selectgain(formoduleswithCC2590/91only)gain=appSelectGain();halRfSetGain(gain);#endif//InitializeBasicRF³õʼ»¯ÎÞÏßÄ£¿ébasicRfConfig.myAddr=RX_ADDR;if(basicRfInit(&basicRfConfig)==FAILED){HAL_ASSERT(FALSE);}basicRfReceiveOn();halLcdClear();halLcdWriteLines(PERTester,Receiver,Ready);//Mainloopwhile(TRUE){while(!basicRfPacketIsReady());if(basicRfReceive((uint8*)&rxPacket,MAX_PAYLOAD_LENGTH,&rssi)0){halLedSet(3);//ChangebyteorderfromnetworktohostorderUINT32_NTOH(rxPacket.seqNumber);segNumber=rxPacket.seqNumber;//Ifstatisticsisresetsetexpectedsequencenumberto//receivedsequencenumberif(resetStats){rxStats.expectedSeqNum=segNumber;resetStats=FALSE;}//SubtractoldRSSIvaluefromsum//ͳ¼Æ½ÓÊÕÐźÅÇ¿¶Èƽ¾ùÖµrxStats.rssiSum-=perRssiBuf[perRssiBufCounter];//StorenewRSSIvalueinringbuffer,willaddittosumlaterperRssiBuf[perRssiBufCounter]=rssi;//AddthenewRSSIvaluetosumrxStats.rssiSum+=perRssiBuf[perRssiBufCounter];if(++perRssiBufCounter==RSSI_AVG_WINDOW_SIZE){perRssiBufCounter=0;//Wrapringbuffercounter}//Checkifreceivedpacketistheexpectedpacketif(rxStats.expectedSeqNum==segNumber){rxStats.expectedSeqNum++;}//Ifthereisajumpinthesequencenumberingthismeanssomepacketsin//betweenhasbeenlost.elseif(rxStats.expectedSeqNumsegNumber){rxStats.lostPkts+=segNumber-rxStats.expectedSeqNum;rxStats.expectedSeqNum=segNumber+1;}//Ifthesequencenumberislowerthanthepreviousone,wewillassumea//newdatabursthasstartedandwewillresetourstatisticsvariables.else{//UpdateourexpectationsassumingthisisanewburstrxStats.expectedSeqNum=segNumber
本文标题:CC2530程序代码
链接地址:https://www.777doc.com/doc-4368168 .html