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

📄 rxhostcomm.c

📁 MIMO 2x2接收端选择全系统仿真代码
💻 C
📖 第 1 页 / 共 2 页
字号:
/*****************************************************************************
  Module     : Host Communication (DSP-PC)
******************************************************************************

  Function   : Contains the initialization, functions and tasks to provide
               the communication with the host.

  Procedures : tskHostComm()

  Author     : $Author: Adrian $

  Revision   : $Revision: 10 $

  Modified   : $Modtime: 05-05-31 16:45 $

  File       : $Workfile: rxhostcomm.c $

******************************************************************************
 KTH, Royal Institute of Technology, S3, Stockholm
*****************************************************************************/

/*--- Include files --------------------------------------------------------*/

/* import */
#include <std.h>
#include <csl_stdinc.h>
#include <log.h>
#include <tsk.h>
#include <rtdx.h>
#include "receivercfg.h"
#include "../common/commondef.h"

/* export */
#include "rxhostcomm.h"

/*=== End of include files =================================================*/


/*--- Global variables definition ------------------------------------------*/

typRXHST_HOSTCOMMSTATE HostCommState;

// Introduced from rxchannelest.c
// Read by the HostComm
extern float pH_pre_r[4][2];
extern float pH_pre_i[4][2];

/*=== End of global variables definition ===================================*/


/*--- Global constants definition ------------------------------------------*/
/*=== End of global constants definition ===================================*/


/*--- Local defines --------------------------------------------------------*/
/*=== End of local defines =================================================*/


/*--- Local types declaration ----------------------------------------------*/
/*=== End of local types declaration =======================================*/


/*--- Local variables definition -------------------------------------------*/

static typRXHST_eHostCommState CommState;
static unsigned int arraycrtl[INITLEN];
static unsigned int arraydata[DATABURSTLEN];

/*=== End of local variables definition ====================================*/


/*--- Local constants definition -------------------------------------------*/
/*=== End of local constants definition ====================================*/


/*--- Local functions definition -------------------------------------------*/
/*=== End of local functions definition ====================================*/


/*--- Global functions definition ------------------------------------------*/
/****************************************************************************
  Function   : tskHostComm
 ****************************************************************************

  Description : State machine for communication with the host 

  Inputs      : None

  Outputs     : None

  By          : 2005-05-19 Maxime Maury
	
 ****************************************************************************/
void tskHostComm()
{
						
	unsigned int uiNbrDataBursts; // Number of data bursts
	
	unsigned int uiCrtl; // Value sent to the receiver host
	
	unsigned int uiFileSize; // (Sent by the host)
	
	char* pFileBuffer = HostCommState.pDataBuff; // Relative pointer to the file data section
	
	int iStatus; // RTDX status
	
	int p; // Data burst index
	
 	float pH_a[8]; // Channel amplitude
	
	int i,j;	// Loop variables
	
	int n;
	unsigned int un;
	
	unsigned int uiSwitchPos;	// Integer holding the switch state	(predicted)
	
	unsigned int uiNoOfFrames;	// Number of frames to receive
	
	HostCommState.cTransReady = 0;	// The number of frames is not set
	
	HostCommState.cNewFrameReady = 0; // The processed frame number has not changed
	
	uiSwitchPos = 1 + 2; // Antennas 1 and 3 are selected for the start

    while(1)
    {
						
        switch(CommState) {
		
			case eRXHST_IDLE:
			
				#ifdef _RTDXDEBUGLOG
						LOG_printf(&trace,"Comm: Idle state");
				#endif
							
				// Asychronous read
				iStatus = RTDX_readNB( &ichancrtl, arraycrtl, sizeof(arraycrtl) );
				
				if ( iStatus != RTDX_OK ) { 
					#ifdef _RTDXDEBUGLOG
							LOG_printf(&trace,"ERROR: RTDX_readNB failed!");
					#endif
					exit(EXIT_RTDX_READ_FAILED);
				}
				
				
				CommState = eRXHST_WAITING;
				break;

				
			case eRXHST_WAITING:

				
				iStatus = RTDX_channelBusy( &ichancrtl ); 
				
				#ifdef _RTDXDEBUGLOG
						LOG_printf(&trace,"Comm: Waiting state %d",iStatus);
				#endif
				
				if (!iStatus) // A value has been read from the host
					CommState = eRXHST_GETPARAMS;

				TSK_sleep(1);
				break;	
				
			case eRXHST_GETPARAMS:

				if (arraycrtl[0] & 1)
					*(HostCommState.pTxMode) = eCOM_SISO; 
				else
					*(HostCommState.pTxMode) = eCOM_MIMO; 
					
				// Debug: Force to MIMO
				*(HostCommState.pTxMode) = eCOM_MIMO;
				
				*(HostCommState.piSyncRep) = arraycrtl[1]; 
				uiFileSize = arraycrtl[2]; 
				uiNbrDataBursts = arraycrtl[3]; 
				
				switch(arraycrtl[4])
				{
					case 1:
						*(HostCommState.puiDetector) =  eRX_ZF;
						break;
					case 2:
						*(HostCommState.puiDetector) =  eRX_JMMSE;
						break;
					default:
						*(HostCommState.puiDetector) =  eRX_ML;  
						break;
				}
				
				switch(arraycrtl[5])
				{
					case 1:
						*(HostCommState.puiAntennaSelection) =  eAnteMMNP;
						break;
					case 2:
						*(HostCommState.puiAntennaSelection) =  eAnteMBER;
						break;
					case 3:
						*(HostCommState.puiAntennaSelection) =  eAnteMMI;
						break;
					default:
						*(HostCommState.puiAntennaSelection) =  eAnteNO;  
						break;
				}
				
							
				#ifdef _RTDXDEBUGLOG
					LOG_printf(&trace,"SysSelection = %d was received from the host", *(HostCommState.pTxMode));
					LOG_printf(&trace,"SyncInterval = %d was received from the host", *(HostCommState.piSyncRep));					
      				LOG_printf(&trace, "FileSize = %d was received from the host", uiFileSize ); 
     				LOG_printf(&trace, "NbrDataBursts = %d was received from the host", uiNbrDataBursts );
					LOG_printf(&trace, "Detector = %d was received from the host", *(HostCommState.puiDetector) ); 
					LOG_printf(&trace, "AntennaSelection = %d was received from the host", *(HostCommState.puiDetector) ); 
             	#endif        		
             	
             	//*(HostCommState.puiFileSizeHat) = uiFileSize;
        

		    	// Send back to the host
				uiCrtl = uiNbrDataBursts;
				
				iStatus = RTDX_write( &ochancrtl, &uiCrtl, sizeof(uiCrtl) ); 
		
		        if ( iStatus == 0 ) {
		     		#ifdef _RTDXDEBUGLOG
							LOG_printf(&trace,"ERROR: RTDX_write failed!");
					#endif     		            
		            exit(EXIT_RTDX_WRITE_FAILED);
		        }
		        

				while ( RTDX_writing != NULL ) { 
					#if RTDX_POLLING_IMPLEMENTATION
					RTDX_Poll(); 
					#endif
					TSK_sleep(1);
				}
				
				//*(HostCommState.pRxState) = eRX_FINDSTART;
				//startEdma();				
				
				CommState = eRXHST_GETNBRFRAMES;
				break;	
			
			case eRXHST_GETNBRFRAMES:
			
				#ifdef _RTDXDEBUGLOG
						LOG_printf(&trace,"Comm: GetNbrFrames State");
				#endif
			
				// compute the number of blocks/frames to transmit
				uiNoOfFrames = 0;
				if (*(HostCommState.piSyncRep) > 0)
				{
					un = uiFileSize;
					n = 0;
					while (un >= DATABUFFSIZE)
					{
						uiNoOfFrames += 1;
						n = (n < *(HostCommState.piSyncRep)-1 ? n+1 : 0);
						un -= (n == 0 ? DATASYMBSYNC : DATABUFFSIZE);
					}
					// check if the last part can be sent in one frame
					n = (n < *(HostCommState.piSyncRep)-1 ? n+1 : 0);
					if (un > 0)
					{
						if (n == 0)
						{
							if (un >= DATASYMBSYNC)
							{
								uiNoOfFrames += 1;
								un -= DATASYMBSYNC;
								if (un > 0)
								{
									// still a few bytes left
									uiNoOfFrames += 1;
								}
							}
							else
							{
								// not all data fits in a sync frame, add one to make room for the rest of the data
								uiNoOfFrames += 1;
							}
						}
						else
						{

⌨️ 快捷键说明

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