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

📄 rxmain.c

📁 MIMO 2x2接收端选择全系统仿真代码
💻 C
📖 第 1 页 / 共 4 页
字号:
/*****************************************************************************
  Module     : Main Receiver Application
******************************************************************************

  Function   : Contains the main processes for the receiver.

  Procedures : main()
  			   processBuffer()
  			   checkDIPswitch()

  Author     : $Author: Adrian $

  Revision   : $Revision: 15 $

  Modified   : $Modtime: 05-05-31 23:21 $

  File       : $Workfile: rxmain.c $

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

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

/* import */
#include "receivercfg.h"
#include "../common/commondef.h"
#include "rxinit.h"
#include "rxfunctions.h"
#include "rxdownconv.h"
#include "rxpll.h"
#include "rxdemodulator.h"
#include "rxsync.h"
#include "rxchannelest.h"
#include "rxswitchmgr.h"
#include "rxdetector.h"
#include "rxhostcomm.h"

/*
 *  These are include files that support interfaces to BIOS and CSL modules
 *  used by the program.
 */
#include <std.h>
#include <swi.h>
#include <log.h>
#include <mem.h>
#include <sem.h>
#include <tsk.h>
#include <c6x.h>
#include <csl.h>
#include <math.h>

#include "dsk6713.h"
#include "dsk6713_led.h"
#include "dsk6713_dip.h"
#include "dsk6713_aic23.h"

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

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


/*--- Global variables definition ------------------------------------------*/
/*=== 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 -------------------------------------------*/

#pragma DATA_ALIGN(gBufferXmtPing,32);
Int16 gBufferXmtPing[BUFFSIZE];  // Transmit PING buffer
#pragma DATA_ALIGN(gBufferXmtPong,32);
Int16 gBufferXmtPong[BUFFSIZE];  // Transmit PONG buffer

#pragma DATA_ALIGN(gBufferRcvPing,32);
Int16 gBufferRcvPing[BUFFSIZE];  // Receive PING buffer
#pragma DATA_ALIGN(gBufferRcvPong,32);
Int16 gBufferRcvPong[BUFFSIZE];  // Receive PONG buffer

/* the whole working buffer is used for the PLL,
but also for the synchronization and demodulation (split into 4 buffers of equal length) */
#pragma DATA_ALIGN(pfWorkingBuffer,32);
float pfWorkingBuffer[4*WORKBUFFLEN];
float *pfWorkBuf1 = &pfWorkingBuffer[WORKBUFFLEN*0];
float *pfWorkBuf2 = &pfWorkingBuffer[WORKBUFFLEN*1];
float *pfWorkBuf3 = &pfWorkingBuffer[WORKBUFFLEN*2];
float *pfWorkBuf4 = &pfWorkingBuffer[WORKBUFFLEN*3];

#pragma DATA_ALIGN(pTempBuffer1I,32);
float pTempBuffer1I[BUFFSIZE/2+MFFILTLEN-1];
#pragma DATA_ALIGN(pTempBuffer1Q,32);
float pTempBuffer1Q[BUFFSIZE/2+MFFILTLEN-1];
#pragma DATA_ALIGN(pTempBuffer2I,32);
float pTempBuffer2I[BUFFSIZE/2+MFFILTLEN-1];
#pragma DATA_ALIGN(pTempBuffer2Q,32);
float pTempBuffer2Q[BUFFSIZE/2+MFFILTLEN-1];

float pfSymbolBuffer1I[SYMBOLBUFFLEN];
float pfSymbolBuffer1Q[SYMBOLBUFFLEN];
float pfSymbolBuffer2I[SYMBOLBUFFLEN];
float pfSymbolBuffer2Q[SYMBOLBUFFLEN];

float cos_table[COS_TAB_SIZE];

typCOM_fCPLXBUFF fCplxTempBufferFilt1, fCplxTempBufferFilt2;
typCOM_fCPLXBUFF fCplxTempBuffer1, fCplxTempBuffer2;
typCOM_fCPLXBUFF fCplxSymbolBuffer1, fCplxSymbolBuffer2;
//typCOM_fCPLXBUFF cplxFiltStat1,cplxFiltStat2;
typCOM_fCPLXBUFF fCplxWorkBuf1, fCplxWorkBuf2;
typCOM_fCPLXBUFF fCplxChSymbBuff1, fCplxChSymbBuff2;

extern typRX_DOWNCONVSTATE DownConvState;
extern typRX_ENERGYDETSTATE EnergyDetState;
extern typRX_PLLPARAM PLLparam;
extern typRX_MFDEMODSTATE MFDemodStat1;
extern typRX_MFDEMODSTATE MFDemodStat2;
extern typRX_SYNCSTATE SyncState;
extern typRX_CHANNELESTSTATE ChannelState;
extern typRX_DETECTORSTATE DetectorStat;
extern typRX_SWITCHSTATE SwitchState;
extern typRXHST_HOSTCOMMSTATE HostCommState; 
extern DSK6713_AIC23_Config AIC23config;

extern float pH_pre_r[4][2];
extern float pH_pre_i[4][2];

Int16 *pBufferXmt, *pBufferRcv;

static unsigned int uiBuffIndex;
static unsigned int uiBuffCount;
static int iSyncCtrl, iSampIdxError;

#ifdef _DEBUG
char BufferLock = 0; // Lock to indicate the use of the 'ping-pong' buffers
#endif

float fNoisePower;		// 
float fEnergyThrs;		// threshold for energy detection (start of transmission)

/* state variable for receiver states */
typRX_eRxState RxState;

/* receiver states */
typRX_RECEIVESTATE ReceiverState;

// place the pDataBuff in SDRAM
#pragma DATA_SECTION(pDataBuff, ".file")
char pDataBuff[FILEBUFF];	// File buffer for the data to send (host writes data here)

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


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


/*--- Local functions definition -------------------------------------------*/
/****************************************************************************
  Function    : init_cos_table()
 ****************************************************************************

  Description : Creat the cosin lookup table

  Inputs      : none

  Outputs     : none

  By          : 2005-05-05 Jinfeng Du

 ****************************************************************************/
static void init_cos_table(void)
{
	int n = 0;
	float gamma = 2*PI/COS_TAB_SIZE;
	
	while(n<COS_TAB_SIZE)
	{
		cos_table[n] = (float)cosf(n*gamma);
		n++;
	}
	
}


/****************************************************************************
  Function    : CpyConvInt2Float
 ****************************************************************************

  Description : Copies the Int16 values from both channels to one averaged
  				float value.

  Inputs      : pointer to the input buffer
  				pointer to the output buffer
  				number of values to copy in output buffer (input buffer
  				is interleaved and has double the size of the output buffer)

  Outputs     : none

  By          : 2005-05-17 Adrian Schumacher

 ****************************************************************************/
static void CpyConvInt2Float(Int16 *piInBuffer, float *pfOutBuffer,
	const unsigned int uiBufLen)
{
	unsigned int n = 0;
	while(n < uiBufLen)
	{
		pfOutBuffer[n] = (float)(piInBuffer[2*n]/2 + piInBuffer[2*n+1]/2);
		n++;
	}
}

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


/*--- Global functions definition ------------------------------------------*/

/****************************************************************************
  Function    : main()
 ****************************************************************************

  Description : The main user task. Performs application initialization and
				starts the data transfer.

  Inputs      : none

  Outputs     : none

  By          : 2005-04-18 Adrian Schumacher / source by Texas Instruments

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

void main()
{
    /* Initialize Board Support Library */
    DSK6713_init();

    /* Initialize LEDs and DIP switches */
    DSK6713_LED_init();
    DSK6713_DIP_init();

#ifdef _DEBUG
	/* Check the buffer sizes */
	if (4*WORKBUFFLEN < (IFSYNCSAMP+BUFFSIZE/2)){
    	LOG_printf(&trace,"fatal error: working buffer is too small!");
		exit(EXIT_WORKBUFF_TOOSMALL);
	}
	if (BUFFSIZE/2 > FRAMESAMPLENGTH/3){
    	LOG_printf(&trace,"fatal error: EDMA buffer is too large! %d, %d",BUFFSIZE/2,FRAMESAMPLENGTH/3);
		exit(EXIT_EDMABUFF_TOO_LARGE);
	}
	if (FRAMESYMBLENGTH != SYNCSYMBLENGTH){
    	LOG_printf(&trace,"fatal error: sync frame length not equal data frame length!");
		exit(EXIT_SYNCFRMLEN_NEQ_DATAFRMLEN);
	}
#endif

    /* Clear buffers */
    memset((void *)gBufferXmtPing, 0, BUFFSIZE * sizeof(Int16));
    memset((void *)gBufferXmtPong, 0, BUFFSIZE * sizeof(Int16));
    memset((void *)gBufferRcvPing, 0, BUFFSIZE * sizeof(Int16));
    memset((void *)gBufferRcvPong, 0, BUFFSIZE * sizeof(Int16));
    memset((void *)pTempBuffer1I, 0, (BUFFSIZE/2+MFFILTLEN-1) * sizeof(float));
    memset((void *)pTempBuffer1Q, 0, (BUFFSIZE/2+MFFILTLEN-1) * sizeof(float));
    memset((void *)pTempBuffer2I, 0, (BUFFSIZE/2+MFFILTLEN-1) * sizeof(float));
    memset((void *)pTempBuffer2Q, 0, (BUFFSIZE/2+MFFILTLEN-1) * sizeof(float));
    memset((void *)pfWorkingBuffer, 0, 4*WORKBUFFLEN * sizeof(float));
    memset((void *)pfSymbolBuffer1I, 0, SYMBOLBUFFLEN * sizeof(float));
    memset((void *)pfSymbolBuffer1Q, 0, SYMBOLBUFFLEN * sizeof(float));
    memset((void *)pfSymbolBuffer2I, 0, SYMBOLBUFFLEN * sizeof(float));
    memset((void *)pfSymbolBuffer2Q, 0, SYMBOLBUFFLEN * sizeof(float));

    /* Initialize cosine lookup table */
    init_cos_table();
    
    /* Initialize variables */
    RxState = eRX_INIT;
#ifdef _DEBUG
    BufferLock = 0;

⌨️ 快捷键说明

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