debi.c

来自「driver wdk」· C语言 代码 · 共 1,196 行 · 第 1/3 页

C
1,196
字号
#define VSLICE_HEADER	0x1a
#define VGOP_HEADER	0x1b
#define VIN_OFFSET	0x20
#define VIN_CNTL	0x21
#define VIN_PICTURE	0x22
#define I2SIN_CONFA	0x24
#define I2SOUT_CONFA	0x26
#define I2SOUT_CONFB	0x27
#define ARATE		0x28
#define AUDIO_CNTL	0x29
#define CD_FORMATTING	0x2d
#define INIT_MINUTE	0x30
#define INIT_SECOND	0x31
#define INIT_SECTOR	0x32
#define PAUSE_LENGTH	0x33
#define LINK_LENGTH	0x34
#define REAR_MARGIN	0x35
#define SECTOR_NUM_L	0x36
#define SECTOR_NUM_M	0x37

//DSP register bits
#define CM_RESET	0x00
#define CM_SLEEP	0x01
#define CM_WAKEUP	0x02
#define CM_START	0x04
#define CM_STOP		0x05
#define CM_RELEASE	0x08
#define CM_TOGLOGO	0x0c
#define CM_GPUPDATE	0xff

#define WORK_AV		0x05

#define VF_PAL		0x08
#define VF_NTSC		0x00

#define SCDETECT_EN	0x40
#define SCDETECT_DS	0x00

#define BITMAP_NONE	0x00
#define BITMAP_YES	0x02

#define OUT_MASTER	0x04
#define OUT_SLAVE	0x00

#define INSERTHEADER 0x00
#define FILLHEADER0	 0x00
#define SCRAMBLE	 0x01

WORD GetDSPStatus(PDEVICE_EXTENSION pDE, int nChannel)
{
	WORD u;
  SelectDSP(pDE);
  if(nChannel==0)
	u=GetDSPReg(pDE,DSP_STATUS);
  else
	u=GetDSPReg2(pDE,DSP_STATUS);
  DisselectDSP(pDE);
  ClearDSPStatus(pDE, nChannel);
  return u;
}
void ClearDSPStatus(PDEVICE_EXTENSION pDE, int nChannel)
{
  SelectDSP(pDE);
  if(nChannel==0)
		SetDSPReg(pDE,DSP_STATUS,0);
  else	
	  SetDSPReg2(pDE,DSP_STATUS,0);
  DisselectDSP(pDE);
}

int Start(PDEVICE_EXTENSION pDE, int nChannel)
{
	SelectDSP(pDE);
	if(nChannel==0){
		SetDSPReg(pDE,DSP_COMMAND,CM_START);
		InformDSP(pDE);
	}
	else{
		SetDSPReg2(pDE,DSP_COMMAND,CM_START);
		InformDSP2(pDE);
	}
	DisselectDSP(pDE);
	if(WaitDSPInt(pDE,nChannel))
		return 1;
	else
		return 0;
}

int Stop(PDEVICE_EXTENSION pDE, int nChannel)
{
	SelectDSP(pDE);
	if(nChannel==0){
		SetDSPReg(pDE,DSP_COMMAND,CM_STOP);
		InformDSP(pDE);
	}
	else{
		SetDSPReg2(pDE,DSP_COMMAND,CM_STOP);
		InformDSP2(pDE);
	}
	DisselectDSP(pDE);
	if(WaitDSPInt(pDE,nChannel))
		return 1;
	else
		return 0;
}

int Release(PDEVICE_EXTENSION pDE, int nChannel)
{
	SelectDSP(pDE);
	if(nChannel==0){
		SetDSPReg(pDE,DSP_COMMAND,CM_RELEASE);
		InformDSP(pDE);
	}
	else{
		SetDSPReg2(pDE,DSP_COMMAND,CM_RELEASE);
		InformDSP2(pDE);
	}
	DisselectDSP(pDE);
	return 0;
}
int TestAFGPIO(PDEVICE_EXTENSION pDE, int nChannel)
{
	SelectDSP(pDE);
	if(nChannel==0){
		SetDSPReg(pDE,GPIO_CNTL, 0x0f);
		SetDSPReg(pDE,GPIO_OUT, 0x05);
		SetDSPReg(pDE,DSP_COMMAND, CM_GPUPDATE);
		InformDSP(pDE);
	}
	else{
		SetDSPReg2(pDE,GPIO_CNTL, 0x0f);
		SetDSPReg2(pDE,GPIO_OUT, 0x05);
		SetDSPReg2(pDE,DSP_COMMAND, CM_GPUPDATE);
		InformDSP2(pDE);
	}
	DisselectDSP(pDE);
	if(WaitDSPInt(pDE,nChannel))
		return 1;
	else
		return 0;
}
int Reset(PDEVICE_EXTENSION pDE, int nChannel)
{
	SelectDSP(pDE);
	if(nChannel==0){
		SetDSPReg(pDE,DSP_COMMAND, CM_RESET);
		InformDSP(pDE);
	}
	else{
		SetDSPReg2(pDE,DSP_COMMAND, CM_RESET);
		InformDSP2(pDE);
	}
	DisselectDSP(pDE);
	if(WaitDSPInt(pDE,nChannel))
		return 1;
	else
		return 0;
}
int WaitDSPInt(PDEVICE_EXTENSION pDE, int nChannel)
{
	int i=0;
	SelectDSP(pDE);
	if(nChannel==0){
		while(i<60){
			if(GetDSPInt(pDE)){
				ClearDSPInt(pDE);
				DisselectDSP(pDE);
				return 1;
			}
			ave2kDelay(10000);
			i++;
		}
	}
	else{
		while(i<60){
			if(GetDSPInt2(pDE)){
				ClearDSPInt2(pDE);
				DisselectDSP(pDE);
				return 1;
			}
			ave2kDelay(10000);
			i++;
		}
	}
  DisselectDSP(pDE);
  return 0;
}
#if (LOGOTEST==1)
#define GetY(YUV) ((UCHAR)(((YUV)>>24)&0xff))
#define GetU(YUV) ((UCHAR)(((YUV)>>16)&0xff))
#define GetV(YUV) ((UCHAR)(((YUV)>>8)&0xff))
#define GetT(RGB) ((UCHAR)(((RGB)>>24)&0xff))
#define GetB(RGB) ((UCHAR)(((RGB)>>16)&0xff))
#define GetG(RGB) ((UCHAR)(((RGB)>>8)&0xff))
#define GetR(RGB) ((UCHAR)((RGB)&0xff))

static ULONG RGB2YUV(ULONG RGB)
{
	int r, g, b;
	int Y, U, V;
	int yo, uo, vo;
	r=GetR(RGB);
	g=GetG(RGB);
	b=GetB(RGB);
	Y = ((3L * r)/10L ) + ((59L * g)/100L) + ((11L * b)/100L);
	U = (((long)b - Y) * 50L )/ 89L;
	V = (((long)r - Y) * 5L ) / 7L;

	yo = ((219L * Y/ 256L) + (165L/10L)); // nominal range: 16..235
	uo = ((224L * U/ 256L) + (1285L/10L));    // 16..240
	vo = ((224L * V/ 256L) + (1285L/10L));    // 16..240
	return (yo<<24)|(uo<<16)|(vo<<8);
}
void BuildLogo(PDEVICE_EXTENSION pDE, int nChannel, PULONG pBitmap, int nXPos, int nYPos)
{
	int i, j;
	PULONG pDot,pBlock;
	ULONG Dot[4],YUV[4];
	int nDotCount,nDot;
	PUCHAR pY, pU, pV;
	int nBlock;
	int nTotalU, nTotalV;
	PUCHAR pLogo=pDE->Logo[nChannel].Logo;
	for(nBlock=0; nBlock<12; nBlock++){
		pBlock=pBitmap+(nBlock/2)*16+(nBlock%2)*96*16;
		pY=pLogo;
		pU=pLogo+256;
		pV=pLogo+384;
		pLogo+=512;
		for(i=0; i<16; i+=2, pY+=16){//line
			for(j=0; j<16; j+=2, pY+=2, pU++, pV++){//column
				pDot=pBlock+i*96+j;
				Dot[0]=*pDot;
				nDotCount=0;
				if(GetT(Dot[0])==0xff)//transparent
					*pY=0;
				else{
					YUV[nDotCount]=RGB2YUV(Dot[0]);
					*pY=GetY(YUV[nDotCount]);
					nDotCount++;
				}
				Dot[1]=*(pDot+1);
				if(GetT(Dot[1])==0xff)//transparent
					*(pY+1)=0;
				else{
					YUV[nDotCount]=RGB2YUV(Dot[1]);
					*(pY+1)=GetY(YUV[nDotCount]);
					nDotCount++;
				}
				Dot[2]=*(pDot+96);
				if(GetT(Dot[2])==0xff)//transparent
					*(pY+16)=0;
				else{
					YUV[nDotCount]=RGB2YUV(Dot[2]);
					*(pY+16)=GetY(YUV[nDotCount]);
					nDotCount++;
				}
				Dot[3]=*(pDot+96+1);
				if(GetT(Dot[3])==0xff)//transparent
					*(pY+17)=0;
				else{
					YUV[nDotCount]=RGB2YUV(Dot[3]);
					*(pY+17)=GetY(YUV[nDotCount]);
					nDotCount++;
				}
				if(nDotCount==0){
					*pU=0;
					*pV=0;
					continue;
				}
				nTotalU=0;
				nTotalV=0;
				for(nDot=0; nDot<nDotCount; nDot++){
					nTotalU+=GetU(YUV[nDot]);
					nTotalV+=GetV(YUV[nDot]);
				}
				nTotalU/=nDotCount;
				nTotalV/=nDotCount;
				*pU=(UCHAR)nTotalU;
				*pV=(UCHAR)nTotalV;
			}
		}
	}
	pLogo=pDE->Logo[nChannel].Logo;
	pLogo[6144]=nXPos/16;
	pLogo[6145]=nYPos/8;
}

void static GenLogo(PUCHAR pLogo)
{
	int i,j;
	PUCHAR pBak=pLogo;
	//for(i=0; i<LOGOSIZE; i++)
	//	*pLogo++=0xff;
	for(i=0; i<12; i++){
		for(j=0; j<256; j++){
			*pLogo++=0x80;//0xe9;
		}
		for(j=0; j<64; j++)
			*pLogo++=0x80;
		for(j=0; j<64; j++)
			*pLogo++=0x0;
		for(j=0; j<64; j++)
			*pLogo++=0x80;
		for(j=0; j<64; j++)
			*pLogo++=0x0;
	}
	//memset(pLogo, 0x80, 6144);
	pBak[6144]=150/16;
	pBak[6145]=100/8;
}
//unsigned char Logo[LOGOSIZE];//[6146];
#endif
int ConfigMPEG(PDEVICE_EXTENSION pDE, int nChannel)
{
	int nAudioRate;
	int nStereo=AUDIO_STEREO;
	int nVideoMode, nAudioMode;
	if(pDE->VideoType[nChannel]==VIDEOTYPE_UNKNOWN)
	{//	pDE->VideoType = GetVideoType(pDE);
		int nVT=GetVideoType(pDE,nChannel);
		if(nVT==VIDEOTYPE_NONE)
			pDE->VideoType[nChannel]=pDE->nPreVideoType[nChannel];
		else
			pDE->VideoType[nChannel] =nVT;
	}
	if(pDE->VideoType[nChannel]==VIDEOTYPE_NTSC)
		nVideoMode=VF_NTSC;
	else
		nVideoMode=VF_PAL;
	SelectDSP(pDE);
	nAudioRate=pDE->AudioDataRate[nChannel];
	if(nAudioRate>=ARATE_224)
		nAudioMode=0x01;
	else
		nAudioMode=0x31;
	//GenLogo(pDE->Logo[nChannel].Logo);
	//LoadLogo(pDE, nChannel);
	//pDE->bLogoEnable[nChannel]=TRUE;
	if(pDE->bLogoEnable[nChannel]){

#if (LOGOTEST==1)
		LoadLogo(pDE, nChannel);
#endif
	}
	if(nChannel==0){
		
		SetDSPReg(pDE,WORK_MODE, WORK_AV);
		SetDSPReg(pDE,VIDEO_FORMAT, nVideoMode);
		SetDSPReg(pDE,VENC_CNTL, SCDETECT_EN);
		SetDSPReg(pDE,VFRAME_PATTERN, 0x16);
		SetDSPReg(pDE,VSLICE_HEADER, 1);
		SetDSPReg(pDE,VGOP_HEADER, (1<<4)|1); //sequency_hdr<<4+gop_hdr
		SetDSPReg(pDE,VIN_OFFSET, 0);
		SetDSPReg(pDE,VIN_CNTL, 0x0c);
		if(pDE->bLogoEnable[nChannel])
//#if (LOGOTEST==1)
			SetDSPReg(pDE,VIN_PICTURE, BITMAP_YES);
		else
//#else
			SetDSPReg(pDE,VIN_PICTURE, BITMAP_NONE);//BITMAP_YES);
//#endif
		SetDSPReg(pDE,I2SIN_CONFA, 0x19);
//#if USING_AUDIO_CHANNEL==1
//  #pragma message("Using channel 1")
		SetDSPReg(pDE,I2SOUT_CONFA, 0x19);
//#else
//  #pragma message("Using channel 2")
//		SetDSPReg(pDE,I2SOUT_CONFA, 0x99);
//#endif
		SetDSPReg(pDE,I2SOUT_CONFB, OUT_SLAVE);
		//if(nAudioRate<ARATE_32 || nAudioRate>ARATE_384)
		//   return 0;
		SetDSPReg(pDE,ARATE, nAudioRate);
		SetDSPReg(pDE,AUDIO_CNTL, nAudioMode);
		SetDSPReg(pDE,CD_FORMATTING,INSERTHEADER);
		SetDSPReg(pDE,INIT_MINUTE,0);
		SetDSPReg(pDE,INIT_SECOND,0);
		SetDSPReg(pDE,INIT_SECTOR,0);
		SetDSPReg(pDE,PAUSE_LENGTH, 0x1);
		//  SetDSPReg(pDE,LINK_LENGTH, 0);
		SetDSPReg(pDE,REAR_MARGIN, 0x0f);
		//SetDSPReg(SECTOR_NUM_M, 0);
		//SetDSPReg(SECTOR_NUM_L, 0);
		SetDSPReg(pDE,0x15,pDE->VideoDataRate[0]&0xff);
		SetDSPReg(pDE,0x16,pDE->VideoDataRate[0]>>8);
	}
	else{
		SetDSPReg2(pDE,WORK_MODE, WORK_AV);
		SetDSPReg2(pDE,VIDEO_FORMAT, nVideoMode);
		SetDSPReg2(pDE,VENC_CNTL, SCDETECT_EN);
		SetDSPReg2(pDE,VFRAME_PATTERN, 0x16);
		SetDSPReg2(pDE,VSLICE_HEADER, 1);
		SetDSPReg2(pDE,VGOP_HEADER, (1<<4)|1); //sequency_hdr<<4+gop_hdr
		SetDSPReg2(pDE,VIN_OFFSET, 0);
		SetDSPReg2(pDE,VIN_CNTL, 0x0c);
		if(pDE->bLogoEnable[nChannel])
//#if (LOGOTEST==1)
			SetDSPReg2(pDE,VIN_PICTURE, BITMAP_YES);

⌨️ 快捷键说明

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