?? dcautl.cpp
字號:
W99200WriteReg(Vin_picture,0x00);
//5. Vstart command
W99200WriteReg(Vstart, 0xff);// any data
//6. Wait to end of data
do
{
dEnd=W99200ReadReg (Vint_source);
} while(!kbhit() && ((dEnd & 0x0001)!= 0x0001));
return TRUE;
}
//**************************************************************************
// Function :UTL_SFE
// Description :Single frame encoding
// Return :BOOL
//**************************************************************************
BOOL UTL_SFE(int Size_H, int Size_V,int iCompress)
{
int i;
FILE *fp1;
int dSize_H=0x00;
int dSize_V=0x00;
dSize_H=Size_H >>4;
dSize_V=Size_V >>4;
fp1=fopen(_SFE_OutFileName,"w+b");
if ( fp1==NULL)
{
printf(" \n encoding file open error !!! ");
return FALSE;
}
//1. Video Reset
W99200WriteReg(Video_reset, 0xFF);//any data
//2. Configuration
if ( iCompress==1)
W99200WriteReg(Vwork_mode, 0x03); // MPEG
else
W99200WriteReg(Vwork_mode, 0x13); // JPEG
W99200WriteReg(Vint_enable, 0x03);
W99200WriteReg(Vthreshold, 0x0f);// 60=15*4 int
W99200WriteReg(Vsize_h,dSize_H); //704:2c 352:16
W99200WriteReg(Vsize_v,dSize_V); //480:1e 240:0f
W99200WriteReg(Vquality,_Quality); // 01(High) ~ 1F (Low)
if ( _VideoStard==0 ) //NTSC
W99200WriteReg(Video_format,0x00);// 8:PAL, 0: NTSC, 4:SQUARE
if ( _VideoStard==1 ) //SQUARE
W99200WriteReg(Video_format,0x04);// 8:PAL, 0: NTSC, 4:SQUARE
if ( _VideoStard==2 ) //PAL
W99200WriteReg(Video_format,0x08);// 8:PAL, 0: NTSC, 4:SQUARE
//3. Start Command
W99200WriteReg(Vstart, 0xff);// any data
//4. Reverse data transfer according to data format
do
{
if ( W99200FIFO_Thr()== TRUE )
{
for( i=0 ; i < 60 ; i++)
_dMem_Data[i]=W99200Inpdw(_IOBase+_ulODPR);
fwrite(_dMem_Data,sizeof(int),60,fp1);
}
} while ( W99200FIFO_End()!=TRUE );// Pooling the End of Data
//5. Stop command
W99200WriteReg(Vstop,0xff); // any data
printf("\n OutPutFile : %s (Single Frame Encoding)",_SFE_OutFileName);
fclose(fp1);
return TRUE;
}
//**************************************************************************
// Function :UTL_WFR
// Description :Write a frame
// Return :BOOL
//**************************************************************************
BOOL UTL_WFR(int Size_H, int Size_V)
{
int dSize_H=0x00;
int dSize_V=0x00;
int *dtemp;
FILE *fp1;
dSize_H=Size_H >>4; // One Unit is 16 Pixel
dSize_V=Size_V >>4; // One Unit is 16 Pixel
fp1=fopen(_SFE_InFileName,"r+b");
if ( fp1==NULL)
{
printf(" \n File( %s ) open error (Write a Frame) !!!",_SFE_InFileName);
return FALSE;
}
//1. Video Reset
W99200WriteReg(Video_reset, 0xff);//any data
//2. Configuration
W99200WriteReg(Vwork_mode, 0x0004);
W99200WriteReg(Vsize_h, dSize_H);
W99200WriteReg(Vsize_v, dSize_V);
//3. Start Command
W99200WriteReg(Vstart, 0xff);// any data
//4. Forward data transfer according to data format
while ( fread(dtemp,sizeof(int),1,fp1) >= 1 )
{
W99200WriteReg(Vdata_in, *dtemp);
}
//5. Stop command
W99200WriteReg(Vstop,0xff); // any data
fclose(fp1);
return TRUE;
}
//**************************************************************************
// Function :UTL_RFR
// Description :Read a frame
// Return :BOOL
//**************************************************************************
BOOL UTL_RFR(int Size_H, int Size_V)
{
FILE *fp1;
int i;
int dSize_H=0x00;
int dSize_V=0x00;
dSize_H=Size_H >>4;
dSize_V=Size_V >>4;
fp1=fopen(_SFE_OutFileName,"w+b");
//1. Soft Reset
W99200WriteReg(Video_reset, 0xFF);//any data
// 2. Configuration
W99200WriteReg(Vint_enable, 0x03);
W99200WriteReg(Vthreshold, 0x0f);// 60=15*4 int
W99200WriteReg(Vsize_h,dSize_H); //704:2c 352:16
W99200WriteReg(Vsize_v,dSize_V); //480:1e 240:0f
W99200WriteReg(Vwork_mode, 0x0005);
// 3. Start
W99200WriteReg(Vstart, 0xff);// any data
//4. Reverse data transfer according to data format
do
{
if ( W99200FIFO_Thr()== TRUE )
{
for( i=0 ; i < 60 ; i++)
_dMem_Data[i]=W99200Inpdw(_IOBase+_ulODPR);
fwrite(_dMem_Data,sizeof(int),60,fp1);
}
} while ( W99200FIFO_End()!=TRUE );// Pooling the End of Data
fclose(fp1);
return TRUE;
}
BOOL UTL_RSDRam(int dwPage)
{
FILE *fp1;
int i;
int start, count, j;
char FileName[13];
sprintf(FileName, "sdram%03x.hex", dwPage);
fp1=fopen(FileName,"w+b");
//1. Soft Reset
if (dwPage==0x100)
{
start=0x00;
count=0x100;
}
else
{
start=dwPage;
count=1;
}
printf("start=%x, count=%x, dwPage=%x\n", start, count, dwPage);
for (j=start;j<(start+count);j++)
{
printf("Reading page %x\n", j);
// getch();
W99200WriteReg(Video_reset, 0xFF);//any data
// 2. Configuration
W99200WriteReg(Vint_enable, 0x03);
W99200WriteReg(Vthreshold, 0x0f);// 60=15*4 int
W99200WriteReg(Vmem_select, j);
W99200WriteReg(Vwork_mode, 0x0007);
// 3. Start
W99200WriteReg(Vstart, 0xff);// any data
//4. Reverse data transfer according to data format
do
{
if ( W99200FIFO_Thr()== TRUE )
{
for( i=0 ; i < 60 ; i++)
_dMem_Data[i]=W99200Inpdw(_IOBase+_ulODPR);
fwrite(_dMem_Data,sizeof(int),60,fp1);
}
} while ( W99200FIFO_End()!=TRUE );// Pooling the End of Data
}
fclose(fp1);
return TRUE;
}
#define PAGE_SIZE 8192
BOOL UTL_WSDRam(int dwPage, char *szFilename)
{
int i;
/* fp1=fopen(szFilename,"r+b");
if ( fp1==NULL)
{
printf(" \n File( %s ) open error (Write a Frame) !!!",szFilename);
return FALSE;
}
*/
//1. Video Reset
W99200WriteReg(Video_reset, 0xff);//any data
//2. Configuration
W99200WriteReg(Vwork_mode, 0x0006);
W99200WriteReg(Vmem_select, dwPage);
//3. Start Command
W99200WriteReg(Vstart, 0xff);// any data
//4. Forward data transfer according to data format
// while ( fread(dtemp,sizeof(int),1,fp1) >= 1 )
for(i=0;i<PAGE_SIZE;i++)
{
W99200WriteReg(Vdata_in, 0);
}
//5. Stop command
W99200WriteReg(Vstop,0xff); // any data
// fclose(fp1);
return TRUE;
}
BOOL UTL_ClearSDRam(void)
{
int i, j;
/* fp1=fopen(szFilename,"r+b");
if ( fp1==NULL)
{
printf(" \n File( %s ) open error (Write a Frame) !!!",szFilename);
return FALSE;
}
*/
//1. Video Reset
for (j=0;j<=0xff;j++)
{
W99200WriteReg(Video_reset, 0xff);//any data
//2. Configuration
W99200WriteReg(Vwork_mode, 0x0006);
W99200WriteReg(Vmem_select, j);
//3. Start Command
W99200WriteReg(Vstart, 0xff);// any data
//4. Forward data transfer according to data format
// while ( fread(dtemp,sizeof(int),1,fp1) >= 1 )
for(i=0;i<PAGE_SIZE;i++)
{
W99200WriteReg(Vdata_in, 0);
}
//5. Stop command
W99200WriteReg(Vstop,0xff); // any data
}
// fclose(fp1);
return TRUE;
}
BOOL UTL_RSDRaml(void)
{
int i;
int start, count, j;
//1. Soft Reset
start=0x00;
count=0x100;
printf("start=%x, count=%x\n", start, count);
while(!kbhit())
{
for (j=start;j<(start+count);j++)
{
printf("Reading page %x\n", j);
// getch();
W99200WriteReg(Video_reset, 0xFF);//any data
// 2. Configuration
W99200WriteReg(Vint_enable, 0x03);
W99200WriteReg(Vthreshold, 0x0f);// 60=15*4 int
W99200WriteReg(Vmem_select, j);
W99200WriteReg(Vwork_mode, 0x0007);
// 3. Start
W99200WriteReg(Vstart, 0xff);// any data
//4. Reverse data transfer according to data format
do
{
if ( W99200FIFO_Thr()== TRUE )
{
for( i=0 ; i < 60 ; i++)
_dMem_Data[i]=W99200Inpdw(_IOBase+_ulODPR);
}
} while ( W99200FIFO_End()!=TRUE );// Pooling the End of Data
}
}
return TRUE;
}
//**************************************************************************
// Function :UTL_SET_I2CVIDEO
// Description :Through I2C Set SAA7114
// Return :BOOL
//**************************************************************************
BOOL UTL_SET_I2CVIDEO(void)
{
FILE *fp;
int dIndex,dValue;
int dCount,i;
dIndex=0;
dValue=0;
dCount=0;
if ( _VideoStard == 0 ) // NTSC
{
if( (fp = fopen( "I2C_114N.IN", "r+" )) == NULL )
{
printf( "The file 'I2C_114N.IN' was not opened\n" );
return 0;
}
}
else
{
if( (fp = fopen( "I2C_114P.IN", "r+" )) == NULL )
{
printf( "The file 'I2C_114P.IN' was not opened\n" );
return 0;
}
}
fscanf(fp,"%d",&dCount); // Read the Count of Data
for ( i=0 ; i < dCount ; i++ )
{
fscanf(fp,"%x %x",&dIndex, &dValue); // Read the index and value
//printf(" Write I2C(114), index->%x,%x\n",dIndex,dValue);
W99200I2CWrite(dIndex,&dValue,1);
}
fclose(fp);
return 1;
}
BOOL UTL_AUDIOFIFO(char *szFileName, int dwLimit)// 11/18 Adding
{
// char cKey;
int dAudioTemp;
int LostData;
FILE *fp1;
int countIndex=0;
clock_t start_time,end_time;
int i;
int key;
key=0;
if (!szFileName)
{
printf("invalid filename\n");
return FALSE;
}
fp1=fopen(szFileName,"w+b");
// Initial the video decoder
UTL_SET_I2CVIDEO();
/* //---------
printf( " \n Please seletc external FIFO type: <1>4K <2>16K <3>64K <4>256K :");
cKey =getche();
switch (cKey)
{
case '1':dAudioTemp=0x04; // 0x04: 4K; 0x05: 16K; 0x06:64K; 0x07:256K;
break;
case '2':dAudioTemp=0x05; // 0x04: 4K; 0x05: 16K; 0x06:64K; 0x07:256K;
break;
case '3':dAudioTemp=0x06; // 0x04: 4K; 0x05: 16K; 0x06:64K; 0x07:256K;
break;
case '4':dAudioTemp=0x07; // 0x04: 4K; 0x05: 16K; 0x06:64K; 0x07:256K;
break;
}
*/
dAudioTemp=0x07;
// ### Initial OKI FIFO
W99200WriteReg(AFCR1,dAudioTemp);
dAudioTemp=0x0040;//Clear AIN_RST for lost data, first writ 1 then write 0
W99200WriteReg(AFCR0,dAudioTemp);
W99200WriteReg(AFCR0,0x0003);
// ### Set Audio Start
dAudioTemp=W99200ReadReg (AFCR1);
dAudioTemp=dAudioTemp | 0x10;
W99200WriteReg(AFCR1,dAudioTemp);// write "1" into A_START bit4
// ### Polling and Get Audio data
start_time=clock();
if (!dwLimit)
{
printf(" \n Press 's' or 'S' to stop audio capture \n");
do
{
key=_bios_keybrd(_KEYBRD_READY)&0xff;
if (key!=0 ) // any key is pressed
{
key=_bios_keybrd(_KEYBRD_READ)&0xff;
if((key=='S')||(key=='s') ) // "s" key is pressed
{
// ### Stop capture
dAudioTemp=W99200ReadReg (AFCR1);
dAudioTemp=dAudioTemp | 0x0008;
W99200WriteReg(AFCR1,dAudioTemp);// write "1" into A_START bit4
break;
}
}
dAudioTemp=W99200ReadReg(AFISR);
if((dAudioTemp=dAudioTemp & 0x01) == 0x01) // Audio Ready
{
W99200WriteReg( AFIRR, 0x01);
countIndex++;
W99200Outpdw( _IOBase, 0x67 );
for( i=0 ; i < 127 ; i++) // 508 bytes => 127 times: 127*4=508 bytes
{
_dSDRAM_Data[i] = W99200Inpdw( _IOBase+4 ); //_ulODPR );
}
fwrite( _dSDRAM_Data, sizeof(int), 127, fp1 );
}
}while((key!='S')|| (key!='s')|| (dAudioTemp=W99200ReadReg(AFISR) & 0x0020)!= 0x0020 );
}
else
{
do
{
dAudioTemp=W99200ReadReg(AFISR);
if((dAudioTemp=dAudioTemp & 0x01) == 0x01) // Audio Ready
{
W99200WriteReg( AFIRR, 0x01);
countIndex++;
W99200Outpdw( _IOBase, 0x67 );
for( i=0 ; i < 127 ; i++) // 508 bytes => 127 times: 127*4=508 bytes
{
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -