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

📄 copy of rxmain.c

📁 MIMO 2x2接收端选择全系统仿真代码
💻 C
📖 第 1 页 / 共 4 页
字号:
/*                    ChannelState.pfCplxSymbBuff1->pIBuffer = &pfSymbolBuffer1I[MFDemodStat1.uiNextReadSymb];
                    ChannelState.pfCplxSymbBuff1->pQBuffer = &pfSymbolBuffer1Q[MFDemodStat1.uiNextReadSymb];
                    ChannelState.pfCplxSymbBuff2->pIBuffer = &pfSymbolBuffer2I[MFDemodStat2.uiNextReadSymb];
                    ChannelState.pfCplxSymbBuff2->pQBuffer = &pfSymbolBuffer2Q[MFDemodStat2.uiNextReadSymb];
*/                    ChannelState.ioffset = MFDemodStat1.uiNextReadSymb;
                    ChannelState.Ch1Switch = SwitchState.uiPos2SetSwitch1;
                    ChannelState.Ch2Switch = SwitchState.uiPos2SetSwitch2;
                    // call the estimation function
	                channelestimation(&ChannelState);
                    // update the counters/indices
                    MFDemodStat1.uiNoOfSymb -= TRAINLEN;
                    MFDemodStat2.uiNoOfSymb -= TRAINLEN;
                    IncCircIndex(&(MFDemodStat1.uiNextReadSymb), SYMBOLBUFFLEN, TRAINLEN);
                    //MFDemodStat1.uiNextReadSymb += TRAINLEN;
                    IncCircIndex(&(MFDemodStat2.uiNextReadSymb), SYMBOLBUFFLEN, TRAINLEN);
                    //MFDemodStat2.uiNextReadSymb += TRAINLEN;
                    ReceiverState.RcvState = eRX_ANTENNASEL;
                }
                else
                {   // not enough samples, wait for more
		    		DSK6713_LED_off(0);
				    // suspend task
				    SEM_pend(&rxsem,SYS_FOREVER);
				    TSK_sleep(1);
                }
                break;
            case eRX_ANTENNASEL:
                // set the LEDs according to the antenna selection for the following data
	            if (SwitchState.uiPosSwitch1 == eSWITCH1)
	            	DSK6713_LED_off(2);
	            else
	            	DSK6713_LED_on(2);
	            if (SwitchState.uiPosSwitch2 == eSWITCH3)
	            	DSK6713_LED_off(3);
	            else
	            	DSK6713_LED_on(3);
                // run the antenna selection algorithm only after we collected channel estimates for all channels
	            if ((ReceiverState.uFrameNo > 0) && (SwitchState.uiAnteSelType != eAnteNO))
	            	antennaselection(&SwitchState);
                // next state
                if (ReceiverState.uFrameNo == 0)
                {
                    DetectorStat.iWhichByte = 0;
                    DetectorStat.uiNextWriteByte = 0;
                    DetectorStat.nibble = 0;
                }
                // initialize some state variables
                iBytesWritten = 0;
                // check how many symbols need to be decoded for the current frame:
                if (((ReceiverState.iSyncRep == 0) || (iSyncCtrl < ReceiverState.iSyncRep-1)) && (ReceiverState.uFrameNo != 0))
                    iBytesPerFrame = DATASYMBOLS; // actually ((DATASYMBOLS*BITSPERSYMBOL)/8)*CHANNELS = 256*4/8*2 = DATASYMBOLS
                else
                    iBytesPerFrame = DATASYMBSYNC;// same: no. of symbols = no. of bytes
                ReceiverState.RcvState = eRX_RCVDATA;
// DEBUG!!!!!!!!!!
//				SEM_post(&hstsem);
// DEBUG!!!!!!!!!!
                break;
			case eRX_RCVDATA:
				#ifdef _DEBUGLOG
//					LOG_printf(&trace,"tskReceiver: eRX_RCVDATA");
				#endif
			    // demodulate/downsample channel 1
			    //downsampling(&MFDemodStat1);
			    // demodulate/downsample channel 2
			    //downsampling(&MFDemodStat2);
                // check how many symbols belong to the current frame
//                iTemp = iBytesPerFrame - iBytesWritten;
//                if (iTemp > (int)MFDemodStat1.uiNoOfSymb)
                    DetectorStat.uiNoOfSymb = MFDemodStat1.uiNoOfSymb;
//                else
//                {
                	// ensure that uiNoOfSymb doesn't get a negative value
//                    DetectorStat.uiNoOfSymb = (iTemp >= 0 ? (unsigned int)iTemp : 0);
//                }
                if (DetectorStat.uiNoOfSymb > 0)
                {
	                DetectorStat.uiNextSymb = MFDemodStat1.uiNextReadSymb;
	                // detect the data
	                detection(&DetectorStat);
	                // update the counters/indices
	                MFDemodStat1.uiNoOfSymb -= DetectorStat.uiNoOfSymb;
	                MFDemodStat2.uiNoOfSymb -= DetectorStat.uiNoOfSymb;
	                IncCircIndex(&(MFDemodStat1.uiNextReadSymb), SYMBOLBUFFLEN, DetectorStat.uiNoOfSymb);
	                //MFDemodStat1.uiNextReadSymb += DetectorStat.uiNoOfSymb;
	                IncCircIndex(&(MFDemodStat2.uiNextReadSymb), SYMBOLBUFFLEN, DetectorStat.uiNoOfSymb);
	                //MFDemodStat2.uiNextReadSymb += DetectorStat.uiNoOfSymb;
	                iBytesWritten += (int)DetectorStat.uiBytesWritten;
	                // check if a frame is ended
	                if (DetectorStat.uiNextWriteByte > 1500)
	                {
			      		disableEdma();
		    			LOG_printf(&trace,"stop");
	                }
/*	                if (iBytesWritten == iBytesPerFrame)
	                //if (iBytesWritten >= 150)
	                {
			      		//disableEdma();
	                    // one frame finished...
	                    iSyncCtrl++;
			            #ifdef _DEBUGLOG
    			            LOG_printf(&trace,"frame no. %d received",ReceiverState.uFrameNo);
			            #endif
	                    // check if the first frame is received
	                    if (ReceiverState.uFrameNo == 0)
	                    {
	                        iTemp = decodeStartFrame((Uint8*)pDataBuff,DetectorStat.uiNextWriteByte,&ReceiverState);
	                        if (iTemp == TRUE)
	                        {
					            #ifdef _DEBUGLOG
		    			            LOG_printf(&trace,"start frame successfully received.");
		    			            LOG_printf(&trace,"file size: %d, number of frames: %d",ReceiverState.uFileSize,ReceiverState.uNoOfBlocks);
					            #endif
	                        }
	                        else
	                        {
					            #ifdef _DEBUGLOG
		    			            LOG_printf(&trace,"could not restore information in start frame!");
					            #endif
	                        }
	                        // reset the index since the information in the startframe is captured and not used anymore
	                        DetectorStat.uiNextWriteByte = 0;
							HostCommState.cNewFrameReady = 1;
	                        // resume host communication
	                        SEM_post(&hstsem);
	                    }
	                    else
	                    {
							HostCommState.cNewFrameReady = 1;
	                        
	                        // check if the last frame is received
	                        if (ReceiverState.uFrameNo == ReceiverState.uNoOfBlocks)
	                        {
	    				        // end of transmission
		    			        RxState = eRX_INIT;
	                            ReceiverState.RcvState = eRX_RCVIDLE;
					            #ifdef _DEBUGLOG
		    			            LOG_printf(&trace,"end of transmission!!!!!!!!!");
					            #endif
								// reset switch
								memset(pBufferXmt,0,BUFFSIZE*sizeof(Int16));
	                        }
	                        // resume host communication
							SEM_post(&hstsem);
							
	                    }
						// check if the last frame was received
						if (ReceiverState.RcvState != eRX_RCVIDLE)
	                    {
	                        // check what format the next frame has
	                        if ((ReceiverState.iSyncRep == 0) || (iSyncCtrl < ReceiverState.iSyncRep))
	                        {
	                            // next is a data frame
	                            // estimate the channel
	                            ReceiverState.RcvState = eRX_CHANNELEST1;
	                        }
	                        else
	                        {
	                            // next is a sync frame
	                            // compute the approximate index of the first sample belonging to the sync. seq.
                            	uiIndex = DetectorStat.uiNoOfSymb*OVERSAMPLING;
	                            MFDemodStat1.uiSamplesProcessed -= uiIndex;
	                            MFDemodStat2.uiSamplesProcessed -= uiIndex;
	                            MFDemodStat1.uiRcvSigLen -= uiIndex;
	                            MFDemodStat2.uiRcvSigLen -= uiIndex;
	                            uiLen = MFDemodStat1.uiSamplesProcessed;
	                            // move the samples relevant for the synchronization to the beginning of the buffer
	                            memmove(pfWorkBuf1,&pfWorkBuf1[uiIndex],uiLen*sizeof(float));
	                            memmove(pfWorkBuf2,&pfWorkBuf2[uiIndex],uiLen*sizeof(float));
	                            memmove(pfWorkBuf3,&pfWorkBuf3[uiIndex],uiLen*sizeof(float));
	                            memmove(pfWorkBuf4,&pfWorkBuf4[uiIndex],uiLen*sizeof(float));
				                // update the pointers to append data to the buffers
				                MFDemodStat1.pfCplxOutBuff->pIBuffer = &pfWorkBuf1[uiLen];
				                MFDemodStat1.pfCplxOutBuff->pQBuffer = &pfWorkBuf2[uiLen];
				                MFDemodStat2.pfCplxOutBuff->pIBuffer = &pfWorkBuf3[uiLen];
				                MFDemodStat2.pfCplxOutBuff->pQBuffer = &pfWorkBuf4[uiLen];
	                            // initialize some states
	                            iSyncCtrl = 0;
	                            uiIndex = 0;
	                            iSampIdxError = MFDemodStat1.iStartIndex;
	                            // change to synchronization
	            				ReceiverState.RcvState = eRX_RCVSYNC;
	            				RxState = eRX_RECSYNC;
	                        }
	                        // initialize variables for the next frame
	                    }
	                    ReceiverState.uFrameNo++;
	                }
	                else
	                {
						MFDemodStat1.uiSamplesProcessed = 0;
						MFDemodStat2.uiSamplesProcessed = 0;
			    		//DSK6713_LED_off(0);
					    // suspend task
					    //SEM_pend(&rxsem,SYS_FOREVER);
					    //TSK_sleep(1);
	                }*/
	            }
                else
                {
					MFDemodStat1.uiSamplesProcessed = 0;
					MFDemodStat2.uiSamplesProcessed = 0;
		    		DSK6713_LED_off(0);
				    // suspend task
				    SEM_pend(&rxsem,SYS_FOREVER);
				    TSK_sleep(1);
                }
				break;
			default:
				#ifdef _DEBUGLOG
	    			LOG_printf(&trace,"fatal error: default state in tskReceiver (invalid state %d)",ReceiverState.RcvState);
				#endif
				exit(EXIT_INVALID_RCVSTATE);
				break;
		}
		DSK6713_LED_off(0);
		TSK_yield(); // yield task
        // (just in case there is another task with the same priority, not the case at the moment)
	}
}


/****************************************************************************
  Function    : checkDIPswitch()
 ****************************************************************************

  Description : Checks the DIP switches to get their state.

  Inputs      : none

  Outputs     : none

  By          : 2005-04-19 Adrian Schumacher

 ****************************************************************************/

void checkDIPswitch(void)
{
    if (!DSK6713_DIP_get(0))
    {
    	// switch is in down position (pressed)
    }
    else
    {
    	// switch is in up position
    }
}


/*=== End of global functions definition ===================================*/

/*--- AUTOMATICALLY GENERATED VERSION HISTORY --------------------------------

$Log: /MIMO/Receiver/rxmain.c $ 
 * 
 * 14    05-05-29 23:39 Adrian
 * many changes, updates and bugfixes
 * it is working now up to the last frame
 * 
 * 13    05-05-28 20:17 Adrian
 * corrected the switching start index initialization
 * 
 * 12    05-05-27 20:46 Adrian
 * many extensions, bugfixes and modifications
 * 
 * 11    05-05-26 19:24 Adrian
 * initializations, clear memory, update counters/indices in demodulator
 * states
 * 
 * 10    05-05-25 13:54 Adrian
 * added more initialization instructions and downsampling in the
 * tskReceiver
 * 
 * 9     05-05-24 19:14 Adrian
 * extended and debugged tskReceiver
 * 
 * 8     23/05/05 11:22 Maxime
 * Linked to the HostComm
 * 
 * 7     05-05-22 19:14 Adrian
 * removed some bugs, moved the BufferLock stuff and commented out some
 * lines producing errors
 * 
 * 6     20.05.05 9:00 Adrian
 * renamed pWorkBuff to pfWorkBuff, added a call to the switch_control()
 * function and extended the tskReceiver() task
 * 
 * 5     05-05-19 12:30 Adrian
 * many changes, basically extended the receiver implementation (PLL,
 * sync, channel estimation)
 * 
 * 4     05-05-17 19:30 Adrian
 * Updated the initialization, moved some variables from inside
 * processBuffer() to the file header, moved and modified parts of the
 * state machine from processBuffer() to tskReceiver(), added the local
 * function CpyConvInt2Float().
 * 
 * 2     05-05-13 17:52 Adrian
 * Removed DetectorStat1 and 2, since DetectorStat contains all necessary
 * data now. Also removed SwitchCntrl (no longer needed).
 * 
 * 1     05-05-11 17:00 Adrian
 * created and added to VSS

===== END OF AUTOMATICALLY GENERATED VERSION HISTORY =======================*/

/**** End of file ***********************************************************/

⌨️ 快捷键说明

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