📄 encode.c
字号:
/*********************************************************************************/
/*
编写人 : 周闰
修改者 : 魏亚锋
完成时间 : 2002/11/25
函数名 : main()
函数功能 : 完成板上设备的初始化
以及在主函数中查询adv601的状态,从其中读出数据
以及将视频、音频、控制数据组合成数据块
*/
/*****************************************************************/
/*********************************************************************************/
/* this program is used for the TMS320C6211 chip */
/*********************************************************************************/
/* the function of this program is to read the data from ADV601 and to control */
/* the speed of coding speed of ADV601, this program is also to complete the */
/* audio coding task and to multiplex the video stream and audio stream for */
/* outputting by MCBSP. */
/*********************************************************************************/
#define MAIN_MODEL
#include "globalvar.h"
#include "address.h"
#include "c6x.h"
#include "intr.h"
#include "regs.h"
#include "cache.h"
#include "dma.h"
#include "common.h"
#include "mcbsp.h"
#include "mcbspdrv.h"
#include "dma_util.h"
#include "emif.h"
#include "hpi.h"
#include "timer.h"
/******************Global various******************************/
unsigned int* gpAddVideo[2];
unsigned int e1transtartflag;
int giPPchoose;
unsigned int dmasendoffset;
unsigned char* dmasendbaseaddr;
unsigned int edmasendnum;
short * audiobaseaddr;
unsigned int audiobufpoint;
unsigned int* gpAudioAddr[2];
unsigned int giAudioPPchoose;
unsigned short audiodatabuf1[32];
unsigned short audiodatabuf2[32];
int databuf1;
int databuf2;
unsigned int databuflong;
/*******************************************************************************/
/* The following program is main function */
//gpAddVideo[2] : 视频数据缓冲区地址数组
//gpAudioAddr[2] : 音频数据缓冲区地址数组
/********************************************************************************/
void main()
{
unsigned int i;
unsigned int Resetnum;
unsigned int temp,ttemp2;
unsigned int datatemp;
unsigned int *ptemp;
unsigned int *lptemp;
unsigned int *lptemp2;
unsigned int lastdata=0;
unsigned int invideodataflag;
unsigned int voidvedio=0;
unsigned int datanum=0;
initiCache();
initiEMIF();
my_intr_reset();
restart:
gpAddVideo[0] =(unsigned int *)0x80000000;//(unsigned int *)0x00003c00;//&databuf1; //全局视频数据存储地址;
gpAddVideo[1] =(unsigned int *)0x80004000;//(unsigned int *)0x00005e00;//&databuf2; //全局视频数据存储地址;
gpAudioAddr[0]=(unsigned int*)audiodatabuf1;
gpAudioAddr[1]=(unsigned int*)audiodatabuf2;
initiInterrupt();
audiobaseaddr=(short* )gpAudioAddr[0];
// emptydatabuf();
InitGlobalData();
// emptyAdvFifo(56);
/*****Here should load logon Picture************************************/
giPPchoose=0;
ptemp=gpAddVideo[giPPchoose];
ptemp[2]=0;
databuflong=0;
invideodataflag=0;
i=0;
Resetnum=0;
audiobufpoint=0;
while(1)
{
/*********************************************************/
/* temp=*(volatile unsigned int *)(EDMA_CIPR_ADDR);
while ((temp&0x2)==0)
{
temp=*(volatile unsigned int *)(EDMA_CIPR_ADDR);
i++;
if (i>=250) temp=2;
}
*/
/********************************************************/
temp=*(volatile unsigned int *) ADV601_DIR_REG3_ADDR;
if ((temp&0x00000008)==8)
//是否可以从adv601读取数据
{
datatemp=*(volatile unsigned int *)ADV601_DIR_REG2_ADDR;
datanum++;
if ((datatemp==0x40000000)&&(lastdata==0xffffffff))
//是否桢头
{
if (voidvedio==0)
//在两桢发一桢的处理中,是否是要发送的桢
{
if(databuflong<4000)
{
ptemp[2]=databuflong;
edmasendnum=databuflong*4;
}
else
{
ptemp[2]=40;
edmasendnum=40*4;
}
/*******Edma control manage*************/
dmasendoffset=0;
dmasendbaseaddr=(unsigned char*)ptemp;//gpAddVideo[giPPchoose];
e1transtartflag=1;
giPPchoose=(giPPchoose+1)%2;
ptemp=gpAddVideo[giPPchoose];
//组合数据块初始化
ptemp[0]=0xffffffff;
ptemp[1]=0x40000000;
*(int*)0xa0380000=1;
/*******Audio data manage*************/
// audiodatatranaddr=(unsigned short*)(audiobaseaddr+audiobufpoint-audiobufpoint%8);
lptemp=ptemp+4;
lptemp2=(unsigned int*)audiobaseaddr;
// ttemp=(int)audiobufpoint/18;
ttemp2=audiobufpoint-(audiobufpoint%18);
giAudioPPchoose=(giAudioPPchoose+1)%2;
audiobaseaddr=(short *)gpAudioAddr[giAudioPPchoose];
audiobufpoint=0;
if(ttemp2>72) ttemp2=72;
for(i=0;i<ttemp2/2;i++)
lptemp[i]=lptemp2[i];
for(i=ttemp2/2;i<36;i++)
lptemp[i]=0;
invideodataflag=1;
databuflong=40;
i=0;
}
giFrameNum=datanum;
datanum=0;
voidvedio=(voidvedio+1)%2;
}
else if ((datatemp==0x41000000)&&(lastdata==0xffffffff))
//是否桢结束
{
giFrameNum=datanum;
datanum=0;
invideodataflag=0;
}
else if (invideodataflag==1)
//是否是桢内数据
{
ptemp[databuflong]=datatemp;
databuflong++;
if(databuflong>4500)
invideodataflag=0;
}
lastdata=datatemp;
Resetnum=0;
}
else
{
Resetnum++;
if (Resetnum>=1000000)
goto restart;
}
// temp=*(volatile unsigned int *) ADV601_DIR_REG3_ADDR;
}
}
/********************************************************************************/
void initiEMIF()
{
/*****DSP_CE0 is configured as SDRAM space*************************************/
/*****DSP_CE1,DSP_CE2,DSP_CE3 is configured as Asynchronize RAM space*********/
/***setup=2,strobe=7,hold=2.this value can be changed************************/
/***DSP_CE1 is configured as 32bit SRAM space********************************/
/***DSP_CE2 is configured as 32bit SRAM space********************************/
/***DSP_CE3 is configured as 8bit SRAM(FLASH) space**************************/
*(volatile unsigned int *)(EMIF_GBLCTL_ADDR)=0x00003060; //clkout2 enabled to clock
*(volatile unsigned int *)(EMIF_CECTL1_ADDR)=0x21e2c702; //0x21e2c722 //DSP_CE1 is configured as flash
*(volatile unsigned int *)(EMIF_CECTL0_ADDR)=0x00000090; //DSP_CE0 is configured as SDRAM space
*(volatile unsigned int *)(EMIF_CECTL2_ADDR)=0x2122c722; //0x21e2c722; //0xffffff2f
*(volatile unsigned int *)(EMIF_CECTL3_ADDR)=0x21e2c722; //
*(volatile unsigned int *)(EMIF_SDCTL_ADDR)=0x57114000;
*(volatile unsigned int *)(EMIF_SDTIM_ADDR)=0x01000400; //the maximun is 0x411
*(volatile unsigned int *)(EMIF_SDEXT_ADDR)=0x000d8d87; //this setting may be problemic
return;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -