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

📄 vivot.c

📁 TM1300/PNX1300系列DSP(主要用于视频处理)的自动boot程序
💻 C
📖 第 1 页 / 共 2 页
字号:
		memcpy(pb + (hsize >> 1), pb, (hsize >> 1));
		pb += hsize;
	}
	copybackRange((void*)ubuf, uvSize);
	fclose(fp);

	/* just read V file: binary */
	sprintf(fn, "%s.v", baseName);
	fp = fopen(fn, "rb");
	if (!fp)
		return (4);
	pb = (unsigned char *) vbuf;
	count = 0;
	for (row = 0; row < (vsize >> 1); row++) {
		count += fread(pb, 1, hsize >> 1, fp);
		memcpy(pb + (hsize >> 1), pb, hsize >> 1);
		pb += hsize;
	}
	copybackRange((void*)vbuf, uvSize);
	fclose(fp);

	return (0);
}

void 
voOpenAPI()
{
	tmLibdevErr_t err;
	pprocCapabilities_t procCap;

	if (err = voOpen(&voInst))
		my_abort("voOpen", err);
		
	memset((char *) (&voInstSup), 0, sizeof (voInstanceSetup_t));

	voInstSup.interruptPriority = intPRIO_6;
	voInstSup.isr               = voTestISR;
	voInstSup.videoStandard     = videoStandard;
	voInstSup.adapterType       = adapterType;

	procGetCapabilities(&procCap);
	/* see formula on VO, Figure 7.6 in the Databook */
        voInstSup.ddsFrequency = (unsigned int)
        (0.5 + (1431655765.0 * 27000000 / (float) procCap->cpuClockFrequency));

	voInstSup.hbeEnable         = True;
	voInstSup.underrunEnable    = True;

	if (err = voInstanceSetup(voInst, &voInstSup))
		my_abort("voInstanceSetup", err);
}

void 
voYUVAPI(voYUVModes_t mode,
	 int imageWidth, int imageHeight, int imageStride,
	 int imageVertOffset, int imageHorzOffset,
	 Pointer yBase, Pointer uBase, Pointer vBase)
{
	tmLibdevErr_t err;

	memset((char *) (&voYUVSup), 0, sizeof (voYUVSetup_t));
	voYUVSup.mode             = mode;
	voYUVSup.buf1emptyEnable  = True;
	voYUVSup.yThresholdEnable = False;
	voYUVSup.yThreshold       = False;
	voYUVSup.yBase            = yBase;
	voYUVSup.uBase            = uBase;
	voYUVSup.vBase            = vBase;

	voYUVSup.imageVertOffset  = imageVertOffset;
	voYUVSup.imageHorzOffset  = imageHorzOffset;
	voYUVSup.imageHeight      = (imageHeight >> 1);
	voYUVSup.yStride          = (2 * imageStride);
	voYUVSup.uStride          = imageStride;
	voYUVSup.vStride          = imageStride;

	switch (mode) {
	case vo422_COSITED_UNSCALED:
	case vo422_INTERSPERSED_UNSCALED:
	case vo420_UNSCALED:
		voYUVSup.imageWidth = imageWidth;
		break;
	case vo422_COSITED_SCALED:
	case vo422_INTERSPERSED_SCALED:
	case vo420_SCALED:
	default:
		voYUVSup.imageWidth = imageWidth << 1;
		break;
	}

	if (err = voYUVSetup(voInst, &voYUVSup))
		my_abort("voYUVSetup", err);

	if (err = voStart(voInst))
		my_abort("voStart", err);
}

void 
voOverlayAPI(int sLine, int sPixel, int width, int height,
	     UInt alpha0, UInt alpha1, int offset, Pointer base)
{
	tmLibdevErr_t err;

	memset((char *) (&voOverlaySup), 0, sizeof (voOverlaySetup_t));
	voOverlaySup.overlayEnable      = True;
	voOverlaySup.overlayStartY      = sLine;
	voOverlaySup.overlayStartX      = sPixel;
	voOverlaySup.overlayWidth       = width;
	voOverlaySup.overlayHeight      = height;
	voOverlaySup.alpha0             = alpha0;
	voOverlaySup.alpha1             = alpha1;
	voOverlaySup.overlayStride      = offset;
	voOverlaySup.overlayBase        = base;

	if (err = voOverlaySetup(voInst, &voOverlaySup))
		my_abort("voOverlaySetup", err);
}

void 
viOpenAPI()
{
	tmLibdevErr_t err;

	if (err = viOpen(&viInst))
		my_abort("viOpen", err);

	memset((char *) (&viInstSup), 0, sizeof (viInstanceSetup_t));

	viInstSup.interruptPriority = intPRIO_3;
	viInstSup.isr               = viTestISR;
	viInstSup.videoStandard     = videoStandard;
	viInstSup.adapterType       = adapterType;

	if (err = viInstanceSetup(viInst, &viInstSup))
		my_abort("viInstanceSetup", err);

}

void 
viYUVAPI(int mode, int width, int height, int stride, int fieldBuf,
	 int startx, int starty, Pointer yBase, Pointer uBase, Pointer vBase)
{
	tmLibdevErr_t err;

	memset((char *) (&viYUVSup), 0, sizeof (viYUVSetup_t));

	viYUVSup.thresholdReachedEnable = False;
	viYUVSup.captureCompleteEnable  = True;
	viYUVSup.cositedSampling        = True;

	viYUVSup.mode        = viFULLRES;
	viYUVSup.yThreshold  = 0;
	viYUVSup.startX      = startx;
	viYUVSup.startY      = starty;
	viYUVSup.width       = width;

	viYUVSup.yBase       = yBase;
	viYUVSup.uBase       = (DummyCode) ? (Pointer)MMIO(DRAM_BASE) : uBase;
	viYUVSup.vBase       = vBase;

	if (fieldBuf) {
		viYUVSup.height = height;
		viYUVSup.yDelta =  (stride - width) + 1;
		viYUVSup.uDelta = ((stride - width) >> 1) + 1;
		viYUVSup.vDelta = ((stride - width) >> 1) + 1;
	}
	else {
		viYUVSup.height = (height >> 1);
		viYUVSup.yDelta =  (stride - width) + stride + 1;
		viYUVSup.uDelta = ((stride - width) >> 1) + (stride >> 1) + 1;
		viYUVSup.vDelta = ((stride - width) >> 1) + (stride >> 1) + 1;
	}
	if (err = viYUVSetup(viInst, &viYUVSup))
		my_abort("viYUVSetup", err);

	if (err = viStart(viInst))
		my_abort("viStart", err);
}

void 
vivoFreeOverlay()
{
	int         i;

	_cache_free((Pointer) bkBuf[0].Y);
	_cache_free((Pointer) bkBuf[0].U);
	_cache_free((Pointer) bkBuf[0].V);
}
void 
vivoRunOverlay()
{
	tmLibdevErr_t	err;

	printf("\nStarting overlay mode\n");

	cpGenBuf(cif422Buf, VID_NUMBUFS, VID_RDY_VI);
	viNum = mmNum = voNum = 0;
	
	yFieldStride       = 720;
	uvFieldStride      = 360;
	overlayFieldStride = (cifWidth << 1);
	capField           = True;
	firstField         = False ;
	yScanWidth         = 0;
	uvScanWidth        = 0;
	runningOverlay     = True;
	cpUsize            = ((cifStride * cifHeight) >> 1);

	viYUVAPI(viHALFRES, cifWidth, cifHeight, cifStride, 1, 
		 0xc,	/* x offset */ 
		 0xc,	/* y offset */
		 (Pointer) (cif422Buf[0].Y),
		 (Pointer) (cif422Buf[0].U),
		 (Pointer) (cif422Buf[0].V));


	voYUVAPI(vo422_COSITED_UNSCALED, fullWidth, fullHeight, fullWidth, 0, 0,
		 (Pointer) fullResBuf[0].Y,
		 (Pointer) fullResBuf[0].U,
		 (Pointer) fullResBuf[0].V);

	voOverlayAPI(64, 128, 352, 120, 64, 64, 1408, (Pointer) cif422Buf[0].Y);

	for (voISRCount = 0; voISRCount < loopCount;) {
		mmOvlyBufUpdate();
	}

	if (err = viStop(viInst))
		my_abort("viStop", err);
	if (err = voStop(voInst))
		my_abort("voStop", err);
}

void 
vivoFreeFullRes()
{
	int         i;

	for (i = 0; i < VID_NUMBUFS; i++) {
		_cache_free((Pointer) fullResBuf[i].Y);
		_cache_free((Pointer) fullResBuf[i].U);
		_cache_free((Pointer) fullResBuf[i].V);
	}
}

void 
vivoRunFullRes()
{
	tmLibdevErr_t	err;
	
	printf("\nStarting full resolution mode\n");

	cpGenBuf(fullResBuf, VID_NUMBUFS, VID_RDY_VI);
	viNum = mmNum = voNum = 0;
	
	yFieldStride       = fullStride;
	uvFieldStride      = (fullStride >> 1);
	overlayFieldStride = 0;
	capField           = False;
	firstField         = True;
	yScanWidth         = fullStride;
	uvScanWidth        = (fullStride >> 1);
	cpUsize            = ((fullStride * fullHeight) >> 1);
	runningOverlay    = False;

	viYUVAPI(viFULLRES, fullWidth, fullHeight, fullStride, 0, 0, 21,
		 (Pointer) (fullResBuf[0].Y),
		 (Pointer) (fullResBuf[0].U),
		 (Pointer) (fullResBuf[0].V));

	voYUVAPI(vo422_COSITED_UNSCALED, fullWidth, fullHeight, fullStride, 0, 0,
		 (Pointer) fullResBuf[0].Y,
		 (Pointer) fullResBuf[0].U,
		 (Pointer) fullResBuf[0].V);

#ifdef __TCS_nohost__
	while (1) {	/* get stuck in here forever */
#else
	for (voISRCount = 0; voISRCount < loopCount;) {
#endif
		mmBufUpdate();
	}

	if (err = viStop(viInst))
		my_abort("viStop", err);
	if (err = voStop(voInst))
		my_abort("voStop", err);
}

void 
vivoFreeCif422()
{
	int         i;

	for (i = 0; i < VID_NUMBUFS; i++) {
		_cache_free((Pointer) cif422Buf[i].Y);
		_cache_free((Pointer) cif422Buf[i].U);
		_cache_free((Pointer) cif422Buf[i].V);
	}
}

void 
vivoRunCIF()
{
	tmLibdevErr_t	err;
	
	printf("\nStarting CIF resolution mode\n");

	cpGenBuf(cif422Buf, VID_NUMBUFS, VID_RDY_VI);
	viNum = mmNum = voNum = 0;

	yFieldStride       = cifStride;
	uvFieldStride      = (cifStride >> 1);
	overlayFieldStride = 0;
	capField           = True;
	firstField         = False;
	yScanWidth         = 0;
	uvScanWidth        = 0;
	cpUsize            = ((cifStride * cifHeight) >> 1);
	runningOverlay     = False;

	viYUVAPI(viHALFRES, cifWidth, cifHeight, cifStride, 1, 4, 11,
		 (Pointer) (cif422Buf[0].Y),
		 (Pointer) (cif422Buf[0].U),
		 (Pointer) (cif422Buf[0].V));

	voYUVAPI(vo422_COSITED_UNSCALED, cifWidth, cifHeight, cifStride, 64, 128,
		 (Pointer) cif422Buf[0].Y,
		 (Pointer) cif422Buf[0].U,
		 (Pointer) cif422Buf[0].V);

	for (voISRCount = 0; voISRCount < loopCount;) {
		mmBufUpdate();
	}
	
	if (err = viStop(viInst))
		my_abort("viStop", err);
	if (err = voStop(voInst))
		my_abort("voStop", err);
}

void 
vivoOpenAPI()
{
	voOpenAPI();
	viOpenAPI();
}

void 
vivoCloseAPI()
{
	vivoFreeCif422();
	vivoFreeFullRes();
	vivoFreeOverlay();
}

void 
vivoAlloc()
{
	int         err;

	allocFullRes();
	allocCif422();
	allocBkBuf();

#ifndef __TCS_nohost__
	err = readYUVFiles("tmlogo", 720, 480, 
				bkBuf[0].Y, bkBuf[0].U, bkBuf[0].V);
	if (err)
		my_abort("readYUVFiles", err);
#endif
}

void 
vivoRun()
{
	vivoAlloc();
	vivoOpenAPI();

	vivoRunCIF();
	vivoRunFullRes();
#ifndef __TCS_nohost__
	vivoRunOverlay();
#endif

	vivoCloseAPI();
}

void 
SetDP()
{	
	DPsize(32000);	/* for debugging */
}

void
vivoDetectworkarounds(void)
{
	tmLibdevErr_t err;
	pprocCapabilities_t cap;
	
	/*
	 * workaround when dummycode is needed: remap U to SDRAM base,
	 * hardware bug 21217 fixed in tm1s1.1
	 */
	if (err = procGetCapabilities(&cap)) 
		my_abort("procGetCapabilities", err);

	if (cap->revisionID == PROC_REVISION_1_0S) {
		fprintf(stderr, "can not execute on a tm1s1.0 due to "
			"hardware bug 21217\nUsually it is OK but it "
			"may overwrite something in memory which\n"
			"produces unpredictable results\n"
			"Press any key to continue or ^C to stop\n");
#ifndef __TCS_nohost__
			getchar();
#endif
	}

	if (cap->revisionID <= PROC_REVISION_1_0S) {
		fprintf(stderr, "make sure the dummycode is inserted as "
			"workaround\nfor hardware bug 21217, (do this "
			"in the tmconfig)\n");
		DummyCode = True;
	}
}

static void 
reportSys(void)
{
	UInt        id;
	pprocCapabilities_t procCap;

	procGetCapabilities(&procCap);
	printf("Sys reports ");
	switch (procCap->deviceID) {
	case PROC_DEVICE_UNKNOWN:
		printf("unknown processor ");
		break;
	case PROC_DEVICE_TM1000:
		switch (procCap->revisionID) {
		default:
		case PROC_REVISION_UNKNOWN:
			printf("TM1000, revision %d unknown ", procCap->revisionID);
			break;
		case PROC_REVISION_CTC:
			printf("TM1000, CTC revision\n");
			printf("IICtest not supported on CTC\n");
			break;
		case PROC_REVISION_1_0:
			printf("TM1000, revision 1.0 ");
			break;
		case PROC_REVISION_1_1:
			printf("TM1000, revision 1.1 ");
			break;
		case PROC_REVISION_1_0S:
			printf("TM1000, revision 1.0S ");
			break;
		case PROC_REVISION_1_1S:
			printf("TM1000, revision 1.1S ");
			break;
		}
		break;
	case PROC_DEVICE_TM1100:
		printf("TM1100, revision %d unknown ", procCap->revisionID);
		break;
	default:
		printf("Unknown processor %d, revision %d ", procCap->deviceID, procCap->revisionID);
		break;
	}
	printf("running at %3.2f MHz on ", 0.000001 * (float) procCap->cpuClockFrequency);

	boardGetID(&id);
	switch (id) {
	case BOARD_VERSION_UNKNOWN:
		printf("unknown board type\n");
		break;
	case BOARD_VERSION_PHILIPS_CTC:
		printf("CTC board: \n");
		break;
	case BOARD_VERSION_PHILIPS_TM1_DEBUG:
		printf("TM1 Debug board\n");
		break;
	case BOARD_VERSION_PHILIPS_TM1_IREF:
		printf("TM1 IREF board\n");
		break;
	default:
		printf("Unrecognized board type.\n");
		break;
	}
	printf("\n");
}


void vivoUsage(void)
{
	printf("usage: vivot [ntsc|pal] [cvbs|s-video] \n");
}
 
void vivoCheckArgcv(int argc, char **argv)
{
	int             mark = 1;
 
	argc--;
	while (argc > 0) {
		if (strcmp(argv[mark], "ntsc") == 0) {          /* NTSC */
			videoStandard = vasNTSC;
			argc--; 
			mark++;
		} 
		else if (strcmp(argv[mark], "pal") == 0) {     /* PAL */
			videoStandard = vasPAL;
			fullHeight = 576;
			argc--; 
			mark++;
		} 
		else if (strcmp(argv[mark], "cvbs") == 0) {    /* CVBS */
			adapterType = vaaCVBS;
			argc--; 
			mark++;
		} 
		else if (strcmp(argv[mark], "s-video") == 0) { /* S-Video */
			adapterType = vaaSvideo;
			argc--; 
			mark++;
		} 
		else {
			vivoUsage();
			argc--; 
			mark++;
			exit(-1);
		}
	}
}

/***************************************************************************/

int 
main(int argc, char **argv)
{
	SetDP();
	DP((Header));
	printf(Header);
	reportSys();
	vivoDetectworkarounds();

#ifndef __TCS_nohost__
	vivoCheckArgcv(argc, argv);
#endif

	vivoRun();

	exit(0);
}

⌨️ 快捷键说明

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