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

📄 dsk_app_up8_sine.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 	400
#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 		8
#define UPFACTOR2		4
#define LASTBUFF 		(DFTSIZE+CPSIZE) // size of the transmitted buffer before upsampling
#define FILTER_LENGTH 	81
#define BUFFSIZE 		(2*((LASTBUFF*UPFACTOR)+FILTER_LENGTH-1)) //4768
#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)]; 	//2464 Add zeros between symbols
float upsampBuffer[LASTBUFF*UPFACTOR+FILTER_LENGTH-1]; //2384 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]={
-0.0048 ,  -0.0048 ,  -0.0037 ,  -0.0013  ,  0.0019 ,   0.0053 ,   0.0081,
0.0095  ,  0.0090 ,   0.0063 ,   0.0016 ,  -0.0043  , -0.0106  ,  -0.0157,
-0.0185 ,  -0.0179 ,  -0.0135 ,  -0.0054 ,   0.0053 ,    0.0169 , 0.0273,
0.0342,    0.0355 ,   0.0300  ,  0.0175,   -0.0010  ,  -0.0231  , -0.0453,
-0.0634 ,  -0.0731 ,  -0.0706 ,  -0.0533 ,  -0.0203 ,   0.0276 ,  0.0872,
0.1537 ,   0.2210 ,   0.2825   , 0.3319  ,  0.3638    ,0.3748 ,   0.3638,
0.3319  ,  0.2825 ,   0.2210  ,  0.1537   , 0.0872  ,  0.0276 ,  -0.0203,
-0.0533  , -0.0706  , -0.0731 ,  -0.0634 ,  -0.0453 ,  -0.0231  , -0.0010,
0.0175 ,   0.0300   , 0.0355  ,  0.0342   , 0.0273  ,  0.0169   , 0.0053,
-0.0054 ,  -0.0135 ,  -0.0179  , -0.0185 ,  -0.0157  , -0.0106  , -0.0043,
0.0016  ,  0.0063 ,   0.0090  ,  0.0095  ,  0.0081   , 0.0053  ,  0.0019,
-0.0013 ,  -0.0037 ,  -0.0048  , -0.0048
};

/* Buffers for the training sequence in the first frame*/
float trainingBuffer[2*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,	-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,	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] = {	 	0,	0,	2,	2,	2,	2,	2,	2,	2,	2,	2,
									2,	2,	2,	2,	2,	2,	2,	2,	2,	2,	2,
									2,	2,	2,	2,	2,	2,	2,	2,	2,	2,	2,
									2,	2,	2,	2,	2,	2,	0,	0,	2,	2,	2,
									6,	6,	6,	6,	6,	6,	6,	6,	6,	6,	6,
									6,	6,	6,	6,	6,	6,	6,	6,	6,	6,	6,
									6,	6,	6,	6,	6,	6,	6,	6,	6,	0,	0,
									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,	0,	0
	
								};  
*/								
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)       |

⌨️ 快捷键说明

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