📄 vitest.c
字号:
/*
* Copyright (c) 1995-1999 by TriMedia Technologies.
*
* +------------------------------------------------------------------+
* | This software is furnished under a license and may only be used |
* | and copied in accordance with the terms and conditions of such |
* | a license and with the inclusion of this copyright notice. This |
* | software or any other copies of this software may not be provided|
* | or otherwise made available to any other person. The ownership |
* | and title of this software is not transferred. |
* | |
* | The information in this software is subject to change without |
* | any prior notice and should not be construed as a commitment by |
* | TriMedia Technologies. |
* | |
* | this code and information is provided "as is" without any |
* | warranty of any kind, either expressed or implied, including but |
* | not limited to the implied warranties of merchantability and/or |
* | fitness for any particular purpose. |
* +------------------------------------------------------------------+
*
* Module name : vitest.c 1.52
*
* Last update : 17:35:05 - 00/11/09
*
* Description :
*
* An example program that demonstrate the use of video input.
*
*/
/**************************************************************************
* *
* Please ignore this, if you have tm1s1.1 or better. *
* *
* ======>>>>>>>>> IMPORTANT NOTICE <<<<<<<<<<<<<========== *
* If you have tm1s1.0 or older version of chip, please contact Philips *
* TriMedia to exchange to newer version of chip. *
* *
* The tm1s1.0 or older version chips contain video-in hardware bugs *
* # 3016, 21217, 21336, 21390, and require extensive workaround. We *
* are no longer supporting the software workaround. *
* *
**************************************************************************/
#include <stdio.h>
#include <assert.h>
#include <stdlib.h>
#include <tm1/mmio.h>
#include <tm1/tmPCSW.h>
#include <tm1/tmProcessor.h>
#include <tm1/tmICP.h>
#include <tm1/tmVI.h>
#include <tm1/tmAvFormats.h>
#include <tmlib/dprintf.h>
#include <tmlib/tmlibc.h>
#include <tmlib/AppModel.h>
#include <tm1/tmHelp.h>
#define VI_READY 2
#define VI_NOT_READY 4
#define NUM_VI_BUF 2
typedef struct _videoBuf { /* video buffer structure example */
Pointer Y; /* buffer pointer for Y */
Pointer U; /* buffer pointer for U */
Pointer V; /* buffer pointer for V */
UInt32 flag; /* flags used in buffer management */
} vBuf, *pvBuf;
static vBuf viBuf[NUM_VI_BUF];
static Int bufNum = 0;
static Int tmpNum = 0;
static Int displayNum = 0;
static Int viInst = -1;
static Int icpInst = -1;
static icpInstanceSetup_t icpInstSup;
static icpImageColorConversion_t icpImage;
static viInstanceSetup_t viInstSup;
static viYUVSetup_t viYUVInstSup;
static volatile Int got1SField = 0;
static Int LOOPCOUNT = 1000;
static Int not555a = 0;
/*
* These are really constants in this program,
* when proper PAL/NTSC detection is done these
* need to be variables.
*/
static Int vidWidth = 352;
static Int vidHeight = 240;
static Int yScanWidth = 384; /* half resolution */
static Int uvScanWidth = 192;
static Int yScanHeight = 288;
static Int uvScanHeight = 288;
static UInt8 *DPhyAdr = (UInt8 *) 0xfe000000;
static Int Dstride = 2048;
static Int Dbpp = 2;
static tmVideoAnalogStandard_t videoStandard = vasNone;
static tmVideoAnalogAdapter_t adapterType = vaaCVBS;
static void my_abort(Char * name, Int err);
static Char *Header = "\nTriMedia Video-In Example Program Version 2.0\n\n";
/***************************************************************/
/* */
/* ICP stuff */
/* */
/***************************************************************/
static void
icpDisplay()
{
Int err;
/*
* If you process the buffers, then invalidate them first. Also if
* you write into the buffers then do an appropriate copyback or
* invalidate before passing it back to vi.
*/
icpImage.yBase = viBuf[displayNum].Y;
icpImage.uBase = viBuf[displayNum].U;
icpImage.vBase = viBuf[displayNum].V;
if (err = icpColorConversion(icpInst, &icpImage))
my_abort("icpColorConversion", err);
while (icpCheckBUSY());
viBuf[displayNum].flag = VI_READY;
}
static void
icp_handler(void)
{
/* too short to switch to the system stack */
#pragma TCS_handler
#pragma TCS_atomic
/*
* TCS_atomic to ensure that the acknowledge is 2 cycles seperated
* from the next interruptible jump
*/
icpEnableACK_DONE();
}
static void
SetupICP()
{
tmLibdevErr_t err;
if (err = icpOpen(&icpInst))
my_abort("icpOpen", err);
memset((Char *) &icpInstSup, 0, sizeof (icpInstanceSetup_t));
icpInstSup.interruptPriority = intPRIO_4;
icpInstSup.isr = icp_handler;
if (err = icpInstanceSetup(icpInst, &icpInstSup))
my_abort("icpInstanceSetup", err);
if (err = icpLoadCoeff(icpInst, NULL))
my_abort("icpLoadCoeff", err);
memset((Char *) &icpImage, 0, sizeof (icpImageColorConversion_t));
icpImage.yInputStride = yScanWidth;
icpImage.uvInputStride = uvScanWidth;
icpImage.inputHeight = vidHeight;
icpImage.inputWidth = vidWidth;
icpImage.outputImage = DPhyAdr;
icpImage.outputStride = Dstride;
icpImage.outputHeight = vidHeight;
icpImage.outputWidth = vidWidth;
icpImage.filterBypass = icpBYPASS;
icpImage.outputPixelOffset = 0.0;
icpImage.inType = vtfYUV;
icpImage.inu.inYUVFormat = vdfYUV422Planar;
icpImage.outputDestination = icpPCI;
#ifdef __LITTLE_ENDIAN__
icpImage.littleEndian = True;
#else
#if defined(__BIG_ENDIAN__) && defined(__TCS_WinNT__)
icpImage.littleEndian = True;
#else
icpImage.littleEndian = False;
#endif
#endif
icpImage.outType = vtfRGB;
if (Dbpp == 1)
icpImage.outu.outRGBFormat = vcfRGB8A_233;
else if (Dbpp == 2 && not555a)
icpImage.outu.outRGBFormat = vcfRGB16;
else if (Dbpp == 2 && (!not555a))
icpImage.outu.outRGBFormat = vcfRGB15Alpha;
else if (Dbpp == 3)
icpImage.outu.outRGBFormat = vcfRGB24;
else if (Dbpp == 4)
icpImage.outu.outRGBFormat = vcfRGB24Alpha;
}
/***************************************************************/
/* */
/* VI stuff */
/* */
/***************************************************************/
static void
_viMyISR()
{
UInt32 vi_status;
vi_status = MMIO(VI_STATUS);
if ((vi_status & 0x1) == 0) {
/*
* This is due to hardware bug 21390, a spurious interrupt
* may occur. Since we have only enabled capture_enable (0x1)
* we should not check on threshold_reached (0x2)
*/
return;
}
if (viHBE(vi_status)) {
/*
* Highway banmdwidth, VI needs more bandwidth. You can play
* with the highway arbitration setting
*/
viAckHBE_ACK();
return;
}
/*
* skip odd field, after each capture, disable vi, ack, and set flag
*
* Do not de-assert capture enable due to hardware bug 3016.
*/
if (viODD(vi_status)) {
viAckCAP_ACK();
}
else {
tmpNum = bufNum ? 0 : 1;
if (viBuf[tmpNum].flag == VI_READY) {
viBuf[bufNum].flag = VI_NOT_READY;
displayNum = bufNum;
bufNum = tmpNum;
/* tm1s1.1 and later code */
viYUVChangeBuffer(viInst, viBuf[bufNum].Y,
viBuf[bufNum].U, viBuf[bufNum].V);
got1SField = 1;
}
viAckCAP_ACK();
}
}
static void
viMyISR()
{
/*
* Do not make it interruptible since VI executes level triggered
* only
*/
#pragma TCS_handler
AppModel_suspend_scheduling();
AppModel_run_on_sstack((AppModel_Fun)_viMyISR, Null);
AppModel_resume_scheduling();
}
static void
SetupVI()
{
tmLibdevErr_t err;
UInt startX, startY, endX, endY;
if (err = viOpen(&viInst))
my_abort("viOpen", err);
fprintf(stderr, "If input device is not proper connected, the viGetVideoStandard routine will take a while.\n");
if (videoStandard == vasNone)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -