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

📄 dsk_app.c

📁 详细的OFDM设计过程
💻 C
📖 第 1 页 / 共 3 页
字号:
#include "dsk_appcfg.h"
#include "target.h" /* defines TARGET_INITIALIZE() */
/*
 *  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 <c6x.h>
#include <csl.h>
#include <csl_edma.h>
#include <csl_irq.h>
#include <csl_mcbsp.h>
#include <math.h>
#include <rtdx.h> /* defines RTDX target API calls */
/*
 *  The 6713 DSK Board Support Library is divided into several modules, each
 *  of which has its own include file.  The file dsk6713.h must be included
 *  in every program that uses the BSL.  This example also uses the
 *  DIP, LED and AIC23 modules.
 */
#include "dsk6713.h"
#include "dsk6713_led.h"
#include "dsk6713_dip.h"
#include "dsk6713_aic23.h"
#include "./functions/genfct.h"
#include "./functions/modulation.h"
#include "./functions/upsampling.h"
#include "./functions/complex.h"
#include "./functions/idft_dsp.h"
#include "./functions/bit_rev.h"
#include "C:/ti/c6000/dsplib/include/dspf_sp_convol.h"
#include "C:/ti/c6000/dsplib/include/dspf_sp_maxval.h"
#include "C:/ti/c6000/dsplib/include/dspf_sp_minval.h"
#define MAX(a,b) ((a) > (b) ? (a):(b))


/* Function prototypes */
void initIrq(void);
void initMcbsp(void);
void initEdma(void);
void copyData(Int16 *inbuf, Int16 *outbuf, Int16 length);
void processBuffer(void);
void edmaHwi(void);
void readRDTX(void);
void copy2Data(const short *inbuf, short *outbuf, const short length);
void correlation(const short *reference, const short *input, const short len_ref, const short len_inp, int *res);
void framesync(short *databuf, short *startindex, short length);
/* Constants for the buffered ping-pong transfer */

#define PING 0
#define PONG 1

#define DATABUFFSIZE 	17000
#define SINE_TABLE_SIZE 48
#define TEMPBUFFSIZE	40 //buffer to hold temporary variables for processing
#define SUBCARSIZE 		124
#define	DFTSIZE			256
#define CPSIZE			32 //cyclic prefix size
#define UPFACTOR 		4
#define UPFACTOR2		2
#define LASTBUFF 		(DFTSIZE+CPSIZE) // size of the transmitted buffer before upsampling
#define FILTER_LENGTH 	41
#define BUFFSIZE 		(2*((LASTBUFF*UPFACTOR)+FILTER_LENGTH-1)) //2384
#define MAX_ELEMENTS 	200
#define TOTFRAMES		3000
/* declare a global input channel */
RTDX_CreateInputChannel( ichan );

/*
 * Data buffer declarations - the program uses four logical buffers of size
 * BUFFSIZE, one ping and one pong buffer on both receive and transmit sides.
 */
Int16 gBufferXmtPing[BUFFSIZE];  // Transmit PING buffer
Int16 gBufferXmtPong[BUFFSIZE];  // Transmit PONG buffer

Int16 gBufferRcvPing[BUFFSIZE];  // Receive PING buffer
Int16 gBufferRcvPong[BUFFSIZE];  // Receive PONG buffer

EDMA_Handle hEdmaXmt;            // EDMA channel handles
EDMA_Handle hEdmaReloadXmtPing;
EDMA_Handle hEdmaReloadXmtPong;
EDMA_Handle hEdmaRcv;
EDMA_Handle hEdmaReloadRcvPing;
EDMA_Handle hEdmaReloadRcvPong;

MCBSP_Handle hMcbsp1;                 // McBSP1 (codec data) handle

Int16 gXmtChan;                       // TCC codes (see initEDMA()) 
Int16 gRcvChan;

/*Databuffer: File to transmitter*/
#pragma DATA_SECTION(dataBuffer,"mydata");

/*Buffers for pulseshaping*/
#pragma DATA_ALIGN(cosfilter,8);
#pragma DATA_ALIGN(upBuffer,8);
/*Allign buffer for IDFT*/
//#pragma DATA_ALIGN(modulationBuffer, 8);
#pragma DATA_ALIGN(upsampBuffer, 8);
//#pragma DATA_ALIGN(bitAlloc, 8);

Uint32 dataBuffer[DATABUFFSIZE];
Uint32 tempBuffer[TEMPBUFFSIZE]; //tempBuffer to extract temporary frames for processing
Uint32 	arraydata[MAX_ELEMENTS]; 
/*Buffers for Data Processing*/
//#pragma DATA_ALIGN(modulationBuffer,8);
float constellation[TOTFRAMES];
float maxtime[TOTFRAMES];
float modulationBuffer[2*SUBCARSIZE]; /*Modulation Buffer SIZE:254*/
#pragma DATA_ALIGN(idftBuffer,8);
float idftBuffer[DFTSIZE+CPSIZE]; //Buffer after IDFT SIZE:288 real
float upBuffer[LASTBUFF*UPFACTOR+2*(FILTER_LENGTH-1)]; 	//1232 Add zeros between symbols
float upsampBuffer[LASTBUFF*UPFACTOR+FILTER_LENGTH-1]; //1192 Output of Pulseshaping
Int16 upsampBufferInterleaved[2*(LASTBUFF*UPFACTOR+FILTER_LENGTH-1)]; //BUFFSIZE
Int16 downsampBuffer[UPFACTOR2*SUBCARSIZE*4];

/*
The states in the transmitter
*/
typedef enum states{
		START, TRAINING,SYNC,RUNNING, LASTFRAME, END} state_t;

state_t State = START;

/* Sinetable for sync */
Int16 sinetable[SINE_TABLE_SIZE] = {
    0x0000, 0x10b4, 0x2120, 0x30fb, 0x3fff, 0x4dea, 0x5a81, 0x658b,
    0x6ed8, 0x763f, 0x7ba1, 0x7ee5, 0x7ffd, 0x7ee5, 0x7ba1, 0x76ef,
    0x6ed8, 0x658b, 0x5a81, 0x4dea, 0x3fff, 0x30fb, 0x2120, 0x10b4,
    0x0000, 0xef4c, 0xdee0, 0xcf06, 0xc002, 0xb216, 0xa57f, 0x9a75,
    0x9128, 0x89c1, 0x845f, 0x811b, 0x8002, 0x811b, 0x845f, 0x89c1,
    0x9128, 0x9a76, 0xa57f, 0xb216, 0xc002, 0xcf06, 0xdee0, 0xef4c
};
								  
// root raised cosine coefficients
float cosfilter[FILTER_LENGTH]={
	0xBBDC2D0B,	0xBBA97F94,	0x3B316F59,	0x3C3B2845,	0x3C506113,	0x3B1700C5,	0xBC74AB1F,
	0xBCD66122,	0xBC9C6383,	0x3BF3F3A4,	0x3D1E2D51,	0x3D4DBE5C,	0x3CCAC8E7,	0xBD05AA56,
	0xBDB79002,	0xBDCC96EA,	0xBCEACC12,	0x3DFC8710,	0x3EA00801,	0x3EF0490D,	0x3F07B1C6,
	0x3EF0490D,	0x3EA00801,	0x3DFC8710,	0xBCEACC12,	0xBDCC96EA,	0xBDB79002,	0xBD05AA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,	-1,	1,	1,	1,	-1,	1,
	1,	1,	-1,	-1,	1,	1,	1,	1,	
	1,	1,	1,	-1,	-1,	-1,	1,	-1
			
};
		

float eAlloc[SUBCARSIZE]; /*= {  1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
								  1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
								  1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
								  1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
								  1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
								  1};*/
								  

short bitAlloc[SUBCARSIZE] = {	 	4,	4,	4,	4,	4,	4,	4,	4,	4,	4,	4,
									4,	4,	4,	4,	4,	4,	4,	4,	4,	4,	4,
									4,	4,	4,	4,	4,	4,	4,	4,	4,	4,	4,
									4,	4,	4,	4,	4,	4,	4,	4,	4,	4,	4,
									4,	4,	4,	4,	4,	4,	4,	4,	4,	4,	4,
									4,	4,	4,	4,	4,	4,	4,	4,	4,	4,	4,
									4,	4,	4,	4,	4,	4,	4,	4,	4,	4,	4,
									4,	4,	4,	4,	4,	4,	4,	4,	4,	4,	4,
									4,	4,	4,	4,	4,	4,	4,	4,	4,	4,	4,
									4,	4,	4,	4,	4,	4,	4,	4,	4,	4,	4,
									4,	4,	4,	4,	4,	4,	4,	4,	4,	4,	4,
									4,	4,	4
	
								};  
								
/*short bitAlloc[SUBCARSIZE] = {	 	0,	0,	0,	8,	8,	8,	8,	8,	8,	8,	8,
									8,	8,	8,	8,	8,	8,	8,	8,	8,	8,	8,
									8,	8,	8,	8,	8,	8,	8,	8,	8,	8,	8,
									8,	8,	8,	8,	8,	8,	8,	8,	8,	8,	8,
									8,	8,	8,	8,	8,	8,	8,	8,	8,	8,	8,
									8,	8,	8,	8,	8,	8,	8,	8,	8,	8,	8,
									8,	8,	8,	8,	8,	8,	8,	8,	8,	8,	8,
									8,	8,	8,	8,	8,	8,	8,	8,	8,	8,	8,
									8,	8,	8,	8,	8,	8,	8,	8,	8,	8,	8,
									8,	8,	8,	8,	8,	8,	8,	8,	8,	8,	8,
									8,	8,	8,	8,	8,	8,	8,	8,	8,	8,	8,
									8,	8,	8
	
								};  */								
/*
 *  EDMA Config data structure 
 */
 
/* Transmit side EDMA configuration */
EDMA_Config gEdmaConfigXmt = {  
    EDMA_FMKS(OPT, PRI, HIGH)          |  // Priority
    EDMA_FMKS(OPT, ESIZE, 16BIT)       |  // Element size
    EDMA_FMKS(OPT, 2DS, NO)            |  // 2 dimensional source?
    EDMA_FMKS(OPT, SUM, INC)           |  // Src update mode
    EDMA_FMKS(OPT, 2DD, NO)            |  // 2 dimensional dest
    EDMA_FMKS(OPT, DUM, NONE)          |  // Dest update mode
    EDMA_FMKS(OPT, TCINT, YES)         |  // Cause EDMA interrupt?
    EDMA_FMKS(OPT, TCC, OF(0))         |  // Transfer complete code
    EDMA_FMKS(OPT, LINK, YES)          |  // Enable link parameters?
    EDMA_FMKS(OPT, FS, NO),               // Use frame sync?

    (Uint32)&gBufferXmtPing,              // Src address

    EDMA_FMK (CNT, FRMCNT, NULL)       |  // Frame count
    EDMA_FMK (CNT, ELECNT, BUFFSIZE),     // Element count
    
    EDMA_FMKS(DST, DST, OF(0)),           // Dest address

    EDMA_FMKS(IDX, FRMIDX, DEFAULT)    |  // Frame index value
    EDMA_FMKS(IDX, ELEIDX, DEFAULT),      // Element index value

    EDMA_FMK (RLD, ELERLD, NULL)       |  // Reload element
    EDMA_FMK (RLD, LINK, NULL)            // Reload link
};

/* Receive side EDMA configuration */
EDMA_Config gEdmaConfigRcv = {  
    EDMA_FMKS(OPT, PRI, HIGH)          |  // Priority
    EDMA_FMKS(OPT, ESIZE, 16BIT)       |  // Element size
    EDMA_FMKS(OPT, 2DS, NO)            |  // 2 dimensional source?
    EDMA_FMKS(OPT, SUM, NONE)          |  // Src update mode
    EDMA_FMKS(OPT, 2DD, NO)            |  // 2 dimensional dest
    EDMA_FMKS(OPT, DUM, INC)           |  // Dest update mode
    EDMA_FMKS(OPT, TCINT, YES)         |  // Cause EDMA interrupt?
    EDMA_FMKS(OPT, TCC, OF(0))         |  // Transfer complete code
    EDMA_FMKS(OPT, LINK, YES)          |  // Enable link parameters?
    EDMA_FMKS(OPT, FS, NO),               // Use frame sync?
    
    EDMA_FMKS(SRC, SRC, OF(0)),           // Src address
 
    EDMA_FMK (CNT, FRMCNT, NULL)       |  // Frame count 
    EDMA_FMK (CNT, ELECNT, BUFFSIZE),     // Element count
    
    (Uint32)&gBufferRcvPing,              // Dest address
          
    EDMA_FMKS(IDX, FRMIDX, DEFAULT)    |  // Frame index value
    EDMA_FMKS(IDX, ELEIDX, DEFAULT),      // Element index value

    EDMA_FMK (RLD, ELERLD, NULL)       |  // Reload element
    EDMA_FMK (RLD, LINK, NULL)            // Reload link
};

/* McBSP codec data channel configuration */
static MCBSP_Config mcbspCfg1 = {
        MCBSP_FMKS(SPCR, FREE, NO)              |
        MCBSP_FMKS(SPCR, SOFT, NO)              |
        MCBSP_FMKS(SPCR, FRST, YES)             |
        MCBSP_FMKS(SPCR, GRST, YES)             |
        MCBSP_FMKS(SPCR, XINTM, XRDY)           |
        MCBSP_FMKS(SPCR, XSYNCERR, NO)          |
        MCBSP_FMKS(SPCR, XRST, YES)             |
        MCBSP_FMKS(SPCR, DLB, OFF)              |
        MCBSP_FMKS(SPCR, RJUST, RZF)            |
        MCBSP_FMKS(SPCR, CLKSTP, DISABLE)       |
        MCBSP_FMKS(SPCR, DXENA, OFF)            |
        MCBSP_FMKS(SPCR, RINTM, RRDY)           |
        MCBSP_FMKS(SPCR, RSYNCERR, NO)          |

⌨️ 快捷键说明

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