?? main_edma1.c
字號(hào):
/********************************************************************************/
/* b_perph.c */
/* written by David Bell */
/* on 01/09/01 */
/* */
/* b_perph uses a single EDMA channel to service an external AFE. Channel 4 is */
/* used to burst a frame of data for every EXT_INT4 event received. The data is */
/* transferred from the AFE to L2 memory. */
/********************************************************************************/
/***********************6713初始化(xt1029)************************/
#define CHIP_6713 1
#include "math.h"
#include <stdio.h>
#include <csl_cache.h>
#include <csl_timer.h>
#include <csl_irq.h>
#include <csl.h>
#include <csl_edma.h>
#include <c6x.h>
#include "c6211dsk.h"
#include "math.h"
/* definitions */
#define MEM_SRC 0x8000 /* Source address for transfer */
#define MEM_DST 0xB0280000 /* Switch(2..0) = 001 0xB0000000 Switch(2..0) =000 */
#define EL_COUNT 2049 /* Element count for transfer */
#define FR_COUNT 1
/* PLL configuration */ //屏蔽pll(xt1029)
#define PLL_DIV0 0
#define PLL_DIV1 1
#define PLL_DIV2 2
#define PLL_DIV3 3
/****************CDMA過(guò)程所需參數(shù)(xt1029)***************/
#define InputLength 25 /*設(shè)有25個(gè)數(shù)字序列*/
#define SineLength 32 /*一個(gè)周期正諧波的長(zhǎng)度*/
#define p1 0 /*零相位*/
#define p2 8 /*pi相位*///(xt1031)原來(lái)為16,sin函數(shù)包括1個(gè)波形
#define OutputLength InputLength*SineLength /*輸出數(shù)據(jù)的總長(zhǎng)度*/
#define pi 3.1416
/****************CDMA過(guò)程所需參數(shù)(xt1029)***************/
int w;
void submit_qdmas(void);
void submit_qdma(void);
void wait(void);
void startPLL();
void delay();
extern far void vectors();
void setupInterrupts(void);
/***********************************submit_qdma**********************************/
/* Submit a QDMA request to transfer the data. */
/********************************************************************************/
void
submit_qdma(void)
{
EDMA_Config config;
config.opt = (Uint32) /* 0x21200001 */
((EDMA_OPT_PRI_HIGH << _EDMA_OPT_PRI_SHIFT )
| (EDMA_OPT_ESIZE_32BIT << _EDMA_OPT_ESIZE_SHIFT )
| (EDMA_OPT_2DS_NO << _EDMA_OPT_2DS_SHIFT )
| (EDMA_OPT_SUM_INC << _EDMA_OPT_SUM_SHIFT )
| (EDMA_OPT_2DD_NO << _EDMA_OPT_2DD_SHIFT )
| (EDMA_OPT_DUM_NONE << _EDMA_OPT_DUM_SHIFT )
| (EDMA_OPT_TCINT_NO << _EDMA_OPT_TCINT_SHIFT )
| (EDMA_OPT_TCC_DEFAULT << _EDMA_OPT_TCC_SHIFT )
#if (C64_SUPPORT)
| (EDMA_OPT_TCCM_DEFAULT << _EDMA_OPT_TCCM_SHIFT )
| (EDMA_OPT_ATCINT_NO << _EDMA_OPT_ATCINT_SHIFT)
| (EDMA_OPT_ATCC_DEFAULT << _EDMA_OPT_ATCC_SHIFT )
| (EDMA_OPT_PDTS_DISABLE << _EDMA_OPT_PDTS_SHIFT )
| (EDMA_OPT_PDTD_DISABLE << _EDMA_OPT_PDTD_SHIFT )
#endif
| (EDMA_OPT_LINK_NO << _EDMA_OPT_LINK_SHIFT )
| (EDMA_OPT_FS_YES << _EDMA_OPT_FS_SHIFT ));
config.src = (unsigned int)MEM_SRC; /* 0x80000000 */
config.cnt = (unsigned int)EL_COUNT; /* 0x00000100 */
config.dst = (unsigned int)MEM_DST; /* 0x00002000 */
config.idx = (unsigned int)0; /* 0x00000000 */
EDMA_qdmaConfig(&config);
} /* end submit_qdma */
/**************************************wait**************************************/
/* Wait until the transfer completes, as indicated by the status of the low- */
/* priority queue in the queue status register (QSR). */
/********************************************************************************/
void
wait(void)
{
while (!(EDMA_getPriQStatus() & EDMA_OPT_PRI_HIGH));
} /* end wait */
/******************************以上為6713所需初始化(xt1029)****************/
/*******************手動(dòng)給一個(gè)輸入數(shù)據(jù)(xt1029)*************/
// unsigned input_crc[]={1,1,0,0,1,1,0,0};
/************************完畢(xt1029)************************/
/***************全局變量,子函數(shù)聲明(xt1029)*********/
int m=0;
static int BPSK[OutputLength+32];/*輸出數(shù)據(jù)的數(shù)組,后面32位為0數(shù)據(jù)位*/
static int sin_data[SineLength*2]; /*共有多少個(gè)正諧波*/
void PhaseSelection(int a); /*相位選擇函數(shù)聲明*/
// void Expriment10_Output();/*輸出函數(shù)聲明*/
void main()
{
/**************************** 配置6713(xt1029)*******************/
int data_squence[InputLength]={1,0,1,0,1,1,0,0,1,0,1,0,0,1,1,0,1,1,0,0,1,0,1,0,1};
int i=0,j=0,n,k,a;
/**************************** 配置6713(xt1029)*******************/
/* DSP initialization */
CSR=0x100; /* Disable all interrupts */
IER=1; /* Disable all interrupts except NMI */
ICR=0xffff; /* Clear all pending interrupts */
// PLL Configuration
startPLL();
delay();
*(unsigned volatile int *)EMIF_GCR = 0x3778;
*(unsigned volatile int *)EMIF_CE0 = 0x30; /* EMIF CE1 control, 32bit */
*(unsigned volatile int *)EMIF_CE1 = CE1_8; /* EMIF CE1 control, 32bit */
*(unsigned volatile int *)EMIF_CE2 = 0x30; /* EMIF CE1 control, 32bit */
*(unsigned volatile int *)EMIF_CE3 = CE1_32; /* EMIF CE1 control, 32bit */
*(unsigned volatile int *)EMIF_SDCTRL = 0x07126000; /* EMIF SDRAM control */
*(unsigned volatile int *)EMIF_SDRP = 0x61a; /* EMIF SDRM refresh period */
*(unsigned volatile int *)EMIF_SDEXT= 0x54529; /* EMIF SDRM extension */
/* Configure L2 for 64K Cache and enable caching of external memory*/
for(i=0;i<5;i++)
{
*(short int *)(0xB0040000) = 0x000;
}
for(i=0;i<5;i++)
{
*(short int *)(0xB0040000) = 0x001;
}
for(n=0;n<100;n++)
{
for(i=0;i<40;i++)
{
*( int *)(0x8000+4*i+160*n)=0;
}
}
submit_qdma();
wait();
i=0;
submit_qdma();
wait();
i=0;
for(i=0;i<5;i++)
{
*(short int *)(0xB0040000) = 0x000;
}
for(i=0;i<5;i++)
{
*(short int *)(0xB0040000) = 0xFFFFFFFF;
*(short int *)(0xB004000C) = 0xFFFFFFFF;
*(short int *)(0xB0040010) = 0xFFFFFFFF;
}
IRQ_setVecs(vectors);
IRQ_globalEnable();
IRQ_nmiEnable();
IRQ_map(IRQ_EVT_EXTINT4, 4);
IRQ_reset(IRQ_EVT_EXTINT4);
IRQ_enable(IRQ_EVT_EXTINT4);
/*************************配置完畢(xt1029)****************************/
for(i=0;i<SineLength;i++)/*在sin_data[]里面存儲(chǔ)一個(gè)正弦波*/
{
sin_data[i]=1023+(int)(1023.0*sin(4*pi*i/(SineLength)));/*調(diào)用sin函數(shù)*///每個(gè)sin函數(shù)包括兩個(gè)波形(xt1031)
}
for(j=0;j<SineLength;j++)/*再往sin_data[]里存儲(chǔ)2個(gè)sin波形,這樣sin_data[]里有4個(gè)sin波行(xt1031)*/
{
sin_data[i++]=sin_data[j];
}
for(j=0;j<OutputLength+32;j++) //將輸出數(shù)組初始化
{
BPSK[j]=0;
}
for(j=0;j<InputLength;j++) //BPSK相位選擇
{
if(data_squence[j]==1) /*I碼片與Q前半個(gè)碼片組合進(jìn)行相位選擇*/
{
PhaseSelection(p1);
}
else
{
PhaseSelection(p2);
}
}
for(i=OutputLength;i<OutputLength+32;i++)
{BPSK[i]=0;}
for(i=0;i<OutputLength+32;i++)//循環(huán)次數(shù)不要更改否則會(huì)出錯(cuò)
{
*( int *)(0x30000+4*i) =BPSK[i];//把數(shù)據(jù)給一個(gè)地址,然后從這個(gè)地址看結(jié)果(xt1029)
*( int *)(0x31000+4*i) =sin_data[k++];
a=*( int *)(0x30000+4*i);
*( int *)(0x8000+4*i)=a; //將數(shù)據(jù)傳給地址進(jìn)行輸出
}
for(;;)
// for(n=0;n<0xffff;n++)
{
submit_qdma();
wait();
}
// Expriment10_Output();
}
/***************相位選擇函數(shù)定義開(kāi)始*******************/
void PhaseSelection(int a)
{int count=0;
for(m;m<OutputLength;m++) //主意:此處m已經(jīng)確定,無(wú)需賦初值,盡管在該處出現(xiàn)編譯警告
{
BPSK[m]=sin_data[a++];/*從a點(diǎn)開(kāi)始讀入*/
//count++;/*只存入一個(gè)完整的波形*/
if(count++==SineLength)
{break;}
}
}
/***************相位選擇函數(shù)定義結(jié)束*******************/
/************************函數(shù)輸出(xt1029)***********************/
/*
void Expriment10_Output()
{ int i=0,k=0,a,n;
for(i=0;i<OutputLength+32;i++)//循環(huán)次數(shù)不要更改否則會(huì)出錯(cuò)
{
*( int *)(0x30000+4*i) =BPSK[i];//把數(shù)據(jù)給一個(gè)地址,然后從這個(gè)地址看結(jié)果(xt1029)
*( int *)(0x31000+4*i) =sin_data[k++];
a=*( int *)(0x30000+4*i);
*( int *)(0x8000+4*i)=a; //將數(shù)據(jù)傳給地址進(jìn)行輸出
}
for(;;)
// for(n=0;n<0xffff;n++)
{
submit_qdma();
wait();
}
}
*/
/******************* 輸出函數(shù)結(jié)束xt1029)*****************************/
/*
for(i=0;i<10;i++)
{
a =*(int *)(0x30000+i);
*( int *)(0x8000)=a;
}
for(;;)
{
submit_qdma();
wait();
}
*/
/***********************************屏蔽PLL等(原因:編譯時(shí)地址出錯(cuò))(xt1029)***********/
/******************************************************************************\
* PLL initial Programm
\******************************************************************************/
void startPLL()
{
PLL_bypass();
delay();
PLL_reset();
delay();
PLL_setPllRatio(PLL_DIV0,0x1); /* DIVD0 Ndiv */ //clock_in = 40MHz
PLL_enablePllDiv(PLL_DIV0);
PLL_setMultiplier(20); /* Mmul Multiply by the number */
// system_clock=(clock_in/Ndiv)* Mmul
// system_clock=(40/1)*5=200MHz
PLL_setOscRatio(0x0); // clock out3
PLL_enableOscDiv();
delay();
// PLL_operational();
PLL_setPllRatio(PLL_DIV1,0x1); // system_clk1 for DSP core
// DSPcore = system_clock/1 = 200MHz
PLL_enablePllDiv(PLL_DIV1); /* dsp core divide bu the number+1*/
delay();
PLL_setPllRatio(PLL_DIV2,0x09); /* peripheral sysclk2 divide by the number+1*/
PLL_enablePllDiv(PLL_DIV2); // Peripherals R62 測(cè)量
// peripheral sysclk2 = system_clock/(9+1) = 20MHz
delay();
PLL_setPllRatio(PLL_DIV3,0x4); /* sysclk3 divide bu the number+1*/
PLL_enablePllDiv(PLL_DIV3); // EMIF interface clock
// EMIF sysclk = 200/2 =100MHz
delay();
delay();
PLL_deassert();
delay();
delay();
PLL_enable();
delay();
delay();
return;
}
void delay()
{
int i;
for(i=0;i<0xfff;i++){}
return;
}
/************************************************************************\
name: SetInterruptsEdma
purpose: Sets up interrupts to service EDMA transfers
inputs: void
returns: void
\************************************************************************/
void setupInterrupts(void)
{
IRQ_setVecs(vectors); /* point to the IRQ vector table */
IRQ_nmiEnable();
IRQ_globalEnable();
IRQ_map(IRQ_EVT_EXTINT4, 4);
IRQ_reset(IRQ_EVT_EXTINT4);
} /* End of SetInterruptsEdma() */
/************************************************************************\
name: Interrupt Service Routine c_int04
\************************************************************************/
interrupt void
c_int04(void)
{
int i;
IER = 0;
IRQ_clear(IRQ_EVT_EXTINT4);
submit_qdma();
w=!w;
//*(short int *)(0x90080000) = w;
// wait();
IRQ_enable(IRQ_EVT_EXTINT4);
return;
}
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -