📄 hdvotest.c
字号:
/*
* +-------------------------------------------------------------------+
* | Copyright (c) 1998- 2000 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 : hdvotest.c 1.23
*
* Last update : 17:22:09 - 00/11/09
*
*
* Description :
*
* Demonstrates the use of the HDVO device library.
*
* Four separate video buffers are used to store 1920x1080, 1280x720,
* 704x480, and 704x480 Natural Motion images. The images contain color
* bars with the following characteristics:
*
* Resolution : Column1 | Column2 | Column3 | Column4
* --------------------------------+---------+---------+--------
* 1920x1080: red | blue | yellow | green
* 1280x720: blue | yellow | green | red
* 704x480: yellow | green | red | blue
* Natural Motion 704x480: green | red | blue | yellow
*
* These buffers are then rendered using the HDVO device.
* The output format is 1920*1080 interlaced RGB888.
*
* The example initially renders 1080 to 1080. It then renders 720 to 1080,
* then 480 to 1080, and finally renders 480 natural Motion to 1080.
*
* The number of fields rendered per mode (1080, 720, 480, 480NM) is
* defined using NUMBER_FIELDS_PER_TYPE, which is defined below.
*
* The graphics overlay can be enabled/disabled by setting the
* GRAPHICS_FLAG definition to HDVO_ON/HDVO_OFF respectively.
*
* Revision :
*
*/
/* ------------------------- Includes--------------------------------------- */
#include <tm1/tmAssert.h>
#include <tm1/tmHDVO.h>
#include "hdvotest_microcode.h"
#include <tmlib/tmlibc.h>
#include <tmlib/AppModel.h>
#include <tm1/tmBoardDef.h>
#include <tm1/tmHelp.h>
/* ------------------------- Defines --------------------------------------- */
#define NUMBER_INPUT_TYPES 4 /* 1080, 720, 480, 480 NM */
#define NUMBER_FIELDS_PER_TYPE 1000
#define TOTAL_NUMBER_OF_FIELDS NUMBER_INPUT_TYPES * NUMBER_FIELDS_PER_TYPE
#define GRAPHICS_FLAG HDVO_OFF
/*
* The following is used to display run time information such as interrupts
* being received and parameters being set. Set to Zero for off, One for on.
*/
#define VERBOSE 0
#define HD_1080_Y_WIDTH 1920
#define HD_1080_Y_HEIGHT 1080 /* one freme */
#define HD_1080_UV_WIDTH HD_1080_Y_WIDTH
#define HD_1080_UV_HEIGHT HD_1080_Y_HEIGHT/2 /* one frame 4:2:0 */
#define HD_720_Y_WIDTH 1280
#define HD_720_Y_HEIGHT 720 /* one freme */
#define HD_720_UV_WIDTH HD_720_Y_WIDTH
#define HD_720_UV_HEIGHT HD_720_Y_HEIGHT/2 /* one frame 4:2:0 */
#define HD_480_Y_WIDTH 704
#define HD_480_Y_HEIGHT 480 /* one frame */
#define HD_480_UV_WIDTH HD_480_Y_WIDTH
#define HD_480_UV_HEIGHT HD_480_Y_HEIGHT/2 /* one frame 4:2:0 */
#define NM_Y_WIDTH 768
#define NM_Y_HEIGHT 480 /* one frame */
#define NM_U_WIDTH 384
#define NM_U_HEIGHT NM_Y_HEIGHT /* one frame 4:2:2 */
#define NM_V_WIDTH 384
#define NM_V_HEIGHT NM_Y_HEIGHT /* one frame 4:2:2 */
/* Note: Graphics is currently set for sample silicon (1/4 resolution) */
#define GFX_Y_WIDTH 960
#define GFX_Y_HEIGHT 540
#define GFX_U_WIDTH GFX_Y_WIDTH/2
#define GFX_U_HEIGHT GFX_Y_HEIGHT
#define GFX_V_WIDTH GFX_Y_WIDTH/2
#define GFX_V_HEIGHT GFX_Y_HEIGHT
#define GFX_A_WIDTH GFX_Y_WIDTH/2
#define GFX_A_HEIGHT GFX_Y_HEIGHT
/* ------------------------- Types ----------------------------------------- */
typedef enum {
INPUT_1080,
INPUT_720,
INPUT_480,
INPUT_480NM
} inputType_t;
/* ------------------------- Prototypes ------------------------------------ */
void hdvoISR(void);
void set704x480NMTopParameters (phdvoContext_t context);
void set704x480NMBottomParameters (phdvoContext_t context);
void set704x480TopParameters (phdvoContext_t context);
void set704x480BottomParameters (phdvoContext_t context);
void set1280x720TopParameters (phdvoContext_t context);
void set1280x720BottomParameters (phdvoContext_t context);
void set1920x1080TopParameters (phdvoContext_t context);
void set1920x1080BottomParameters (phdvoContext_t context);
void setupVideoPointers(phdvoContext_t context,
UInt8 *hdYTopPtr, UInt8 *hdYBottomPtr,
UInt8 *hdUVTopPtr, UInt8 *hdUVBottomPtr);
void fillYUVBuffer(UInt8 * yPtr, UInt8 * uvPtr,
UInt16 height, UInt16 width,
UInt8 yCol1, UInt8 yCol2, UInt8 yCol3, UInt8 yCol4,
UInt8 uCol1, UInt8 uCol2, UInt8 uCol3, UInt8 uCol4,
UInt8 vCol1, UInt8 vCol2, UInt8 vCol3, UInt8 vCol4);
void fillNMBuffer(UInt8 * yPtr, UInt8 * uPtr, UInt8 * VPtr,
UInt16 height, UInt16 width,
UInt16 uvHeight, UInt16 uvWidth,
UInt8 yCol1, UInt8 yCol2, UInt8 yCol3, UInt8 yCol4,
UInt8 uCol1, UInt8 uCol2, UInt8 uCol3, UInt8 uCol4,
UInt8 vCol1, UInt8 vCol2, UInt8 vCol3, UInt8 vCol4);
void fillGFXBuffer(UInt8 * gfxYPtr, UInt8 * gfxUPtr, UInt8 * gfxVPtr,
UInt8 * gfxAPtr);
/* ------------------------- Globals --------------------------------------- */
volatile Int32 receivedInterrupt;
static Bool updatedContext = False;
static phdvoContext_t dspcpuContext;
static phdvoContext_t mcpContext;
static hdvoInstanceSetup_t hdvoSetup;
volatile hdvoFieldType_t field = HDVO_TOP_FIELD;
/* ------------------------------------------------------------------------- */
int main (void)
{
tmLibdevErr_t rval;
Int hdvoInstance;
inputType_t inputType;
UInt32 totalNumberOfFields = 0;
UInt32 fieldCounter = 0;
UInt8 *hd1080YPtr;
UInt8 *hd1080UVPtr;
UInt8 *hd720YPtr;
UInt8 *hd720UVPtr;
UInt8 *hd480YPtr;
UInt8 *hd480UVPtr;
UInt8 *nmYPtr;
UInt8 *nmUPtr;
UInt8 *nmVPtr;
UInt8 *gfxYPtr;
UInt8 *gfxUPtr;
UInt8 *gfxVPtr;
UInt8 *gfxAPtr;
receivedInterrupt = 0;
printf("HDVO Test\n\n");
tmHelpReportSystem(stdout);
/*
* allocate the memory for the field buffers and fill them with data
*/
hd1080YPtr = _cache_malloc(HD_1080_Y_WIDTH*HD_1080_Y_HEIGHT, -1);
hd1080UVPtr = _cache_malloc(HD_1080_UV_WIDTH*HD_1080_UV_HEIGHT, -1);
hd720YPtr = _cache_malloc(HD_720_Y_WIDTH*HD_720_Y_HEIGHT, -1);
hd720UVPtr = _cache_malloc(HD_720_UV_WIDTH*HD_720_UV_HEIGHT, -1);
hd480YPtr = _cache_malloc(HD_480_Y_WIDTH*HD_480_Y_HEIGHT, -1);
hd480UVPtr = _cache_malloc(HD_480_UV_WIDTH*HD_480_UV_HEIGHT, -1);
nmYPtr = _cache_malloc(NM_Y_WIDTH*NM_Y_HEIGHT, -1);
nmUPtr = _cache_malloc(NM_U_WIDTH*NM_U_HEIGHT, -1);
nmVPtr = _cache_malloc(NM_V_WIDTH*NM_V_HEIGHT, -1);
gfxYPtr = _cache_malloc(GFX_Y_WIDTH*GFX_Y_HEIGHT, -1);
gfxUPtr = _cache_malloc(GFX_U_WIDTH*GFX_U_HEIGHT, -1);
gfxVPtr = _cache_malloc(GFX_V_WIDTH*GFX_V_HEIGHT, -1);
gfxAPtr = _cache_malloc(GFX_A_WIDTH*GFX_A_HEIGHT, -1);
if (!hd1080YPtr || !hd1080UVPtr
|| !hd720YPtr || !hd720UVPtr
|| !hd480YPtr || !hd480UVPtr
|| !nmYPtr || !nmUPtr || !nmVPtr
|| !gfxYPtr || !gfxUPtr || !gfxVPtr || !gfxAPtr) {
printf("Failed to allocate memory for video/gfx buffers!\n");
exit(1);
}
/* 1920*1080 (red, blue, yellow, green) */
printf("Initializing buffers:\n");
printf("Filling 1920x1080 with red, blue, yellow, green color bars\n");
fillYUVBuffer(hd1080YPtr, hd1080UVPtr,
HD_1080_Y_HEIGHT, HD_1080_Y_WIDTH,
0x28, 0x96, 0xae, 0x85,
0x69, 0x95, 0x20, 0x37,
0xdf, 0x20, 0x8a, 0x2b);
/* 1280*720 (blue, yellow, green, red) */
printf("Filling 1280x720 with blue, yellow, green, red color bars\n");
fillYUVBuffer(hd720YPtr, hd720UVPtr,
HD_720_Y_HEIGHT, HD_720_Y_WIDTH,
0x96, 0xae, 0x85, 0x28,
0x95, 0x20, 0x37, 0x69,
0x20, 0x8a, 0x2b, 0xdf);
/* 704*480 (yellow, green, red, blue) */
printf("Filling 704x480 with yellow, green, red, blue color bars\n");
fillYUVBuffer(hd480YPtr, hd480UVPtr,
HD_480_Y_HEIGHT, HD_480_Y_WIDTH,
0xae, 0x85, 0x28, 0x96,
0x20, 0x37, 0x69, 0x95,
0x8a, 0x2b, 0xdf, 0x20);
/* 640*480 Natural Motion (green, red, blue, yellow) */
printf("Filling 704x480 NM with green, red, blue, yellow color bars\n");
fillNMBuffer(nmYPtr, nmUPtr, nmVPtr,
NM_Y_HEIGHT, NM_Y_WIDTH,
NM_U_HEIGHT, NM_U_WIDTH,
0x85, 0x28, 0x96, 0xae,
0x37, 0x69, 0x95, 0x20,
0x2b, 0xdf, 0x20, 0x8a);
/* graphics */
fillGFXBuffer(gfxYPtr, gfxUPtr, gfxVPtr, gfxAPtr);
/*
* Create the hdvo context structures. Two are created, one for the DSPCPU
* and one for the MCP. This allows the DSPCPU to wtite to its own context
* whilst the MCP is reading its parameters. Then when we want to update
* the context we simply copy the buffer and flush it out to SDRAM.
*
* The structures must be aligned on a 16 byte boundary, so use
*_cache_malloc to ensure this.
*/
dspcpuContext = (phdvoContext_t) _cache_malloc(sizeof(hdvoContext_t), -1);
mcpContext = (phdvoContext_t) _cache_malloc(sizeof(hdvoContext_t), -1);
if ((!dspcpuContext) || (!mcpContext)) {
printf("Failed to allocate memory for context structures!\n");
return -1;
}
memset(dspcpuContext, 0, sizeof(hdvoContext_t));
memset(mcpContext, 0, sizeof(hdvoContext_t));
/*
* --- Open and instance of the hdvo device ---
*/
rval = hdvoOpenM(&hdvoInstance, unit0);
tmAssert(rval == TMLIBDEV_OK, rval);
/*
* --- Initialise the instance setup structure ---
*/
hdvoSetup.reset = True;
hdvoSetup.interruptPriority = intPRIO_5; /* Priority 5 Interrupt */
hdvoSetup.isr = &hdvoISR;
hdvoSetup.context = mcpContext;
hdvoSetup.stmParameters = &_hdvo_stm_100_1920x1080i_data_start;
hdvoSetup.arbiterWait = 0;
hdvoSetup.arbiterDelta = 0;
hdvoSetup.clockFrequency = 74250000;
/*
* setup the kernel pointers
*/
hdvoSetup.kernelProg0Addr = &_hdvo_ucode0_kernel_text_start;
hdvoSetup.kernelProg1Addr = &_hdvo_ucode1_kernel_text_start;
hdvoSetup.kernelProg2Addr = &_hdvo_ucode2_kernel_text_start;
hdvoSetup.kernelProgSize =
&_hdvo_ucode0_kernel_text_end - &_hdvo_ucode0_kernel_text_start;
hdvoSetup.kernelDataAddr = &_hdvo_ucode_kernel_data_start;
hdvoSetup.kernelDataSize =
((UInt32)&_hdvo_ucode_kernel_data_end)
- ((UInt32)&_hdvo_ucode_kernel_data_start);
/*
* Setup the context structure
*
* Fill in the Apps part...
* The video pointers will initially be 1920*1080.
*/
setupVideoPointers(dspcpuContext,
hd1080YPtr,
hd1080YPtr+(HD_1080_Y_WIDTH*HD_1080_Y_HEIGHT/2),
hd1080UVPtr,
hd1080UVPtr+(HD_1080_UV_WIDTH*HD_1080_UV_HEIGHT/2));
dspcpuContext->gfxYAddr3 = hdvoExtractAddr3(gfxYPtr);
dspcpuContext->gfxYAddr2 = hdvoExtractAddr2(gfxYPtr);
dspcpuContext->gfxYAddr1 = hdvoExtractAddr1(gfxYPtr);
dspcpuContext->gfxUAddr3 = hdvoExtractAddr3(gfxUPtr);
dspcpuContext->gfxUAddr2 = hdvoExtractAddr2(gfxUPtr);
dspcpuContext->gfxUAddr1 = hdvoExtractAddr1(gfxUPtr);
dspcpuContext->gfxVAddr3 = hdvoExtractAddr3(gfxVPtr);
dspcpuContext->gfxVAddr2 = hdvoExtractAddr2(gfxVPtr);
dspcpuContext->gfxVAddr1 = hdvoExtractAddr1(gfxVPtr);
dspcpuContext->gfxAlphaAddr3 = hdvoExtractAddr3(gfxAPtr);
dspcpuContext->gfxAlphaAddr2 = hdvoExtractAddr2(gfxAPtr);
dspcpuContext->gfxAlphaAddr1 = hdvoExtractAddr1(gfxAPtr);
dspcpuContext->mdxAddr3 = hdvoExtractAddr3(&_hdvo_mdxrgb_data_start);
dspcpuContext->mdxAddr2 = hdvoExtractAddr2(&_hdvo_mdxrgb_data_start);
dspcpuContext->mdxAddr1 = hdvoExtractAddr1(&_hdvo_mdxrgb_data_start);
dspcpuContext->hflCmpAddr3 = hdvoExtractAddr3(&_hdvo_hflcmp_data_start);
dspcpuContext->hflCmpAddr2 = hdvoExtractAddr2(&_hdvo_hflcmp_data_start);
dspcpuContext->hflCmpAddr1 = hdvoExtractAddr1(&_hdvo_hflcmp_data_start);
dspcpuContext->hflExpAddr3 = hdvoExtractAddr3(&_hdvo_hflexp_data_start);
dspcpuContext->hflExpAddr2 = hdvoExtractAddr2(&_hdvo_hflexp_data_start);
dspcpuContext->hflExpAddr1 = hdvoExtractAddr1(&_hdvo_hflexp_data_start);
dspcpuContext->lutAddr3 = hdvoExtractAddr3(&_hdvo_lut_data_start);
dspcpuContext->lutAddr2 = hdvoExtractAddr2(&_hdvo_lut_data_start);
dspcpuContext->lutAddr1 = hdvoExtractAddr1(&_hdvo_lut_data_start);
dspcpuContext->enableGraphics = GRAPHICS_FLAG;
dspcpuContext->enableVcr = HDVO_OFF;
dspcpuContext->enablePip = HDVO_OFF;
/*
* Fill in the Kernel part...
*/
dspcpuContext->stmReload = HDVO_OFF;
dspcpuContext->appReload = HDVO_ON;
dspcpuContext->stmAddr3 =
hdvoExtractAddr3(&_hdvo_stm_100_1920x1080i_data_start);
dspcpuContext->stmAddr2 =
hdvoExtractAddr2(&_hdvo_stm_100_1920x1080i_data_start);
dspcpuContext->stmAddr1 =
hdvoExtractAddr1(&_hdvo_stm_100_1920x1080i_data_start);
/*
* set the microcode pointers starting with the top field.
* Start of with 1920x1080.
*/
set1920x1080TopParameters(dspcpuContext);
inputType = INPUT_1080;
/* inputType = INPUT_480NM; */
/*
* Setup the context structure address. Remember that the MCP will be
* reading this so the address must be the MCP structure.
*/
dspcpuContext->contextAddr3 = hdvoExtractAddr3(mcpContext);
dspcpuContext->contextAddr2 = hdvoExtractAddr2(mcpContext);
dspcpuContext->contextAddr1 = hdvoExtractAddr1(mcpContext);
/*
* Copy the DSPCPU context to the MCP context. We don't have to do a
* copyback as this is done by the device library.
*/
memcpy(mcpContext, dspcpuContext, sizeof(hdvoContext_t));
/*
* Set up the device instance. This will download the context structure,
* the initialised data segment, and the microcode into HDVO MCP memory. It
* will then enable the MCP. The MCP will download it's application data and
* associated parameters and begin rendering video.
*/
rval = hdvoInstanceSetup(hdvoInstance, &hdvoSetup);
tmAssert(rval == TMLIBDEV_OK, rval);
#if VERBOSE
printf("hdvoInstanceSetup returned 0x%x\n", rval);
#endif
/*
* Enter a loop to render the specified number of fields.
*
* Whilst the MCP is rendering a field, the DSPCPU can setup the next fields
* parameters.
*/
printf("\nRendering to 1920x1080 Interlaced RGB888 Output\n\n");
printf("Current input buffer size is 1920x1080\n");
printf("red, blue, yellow, green color bars should be displayed\n\n");
while (totalNumberOfFields < TOTAL_NUMBER_OF_FIELDS) {
/*
* The kernal is now rendering a field. Set the microcode pointers to the
* respective code.
*/
switch (inputType) {
case INPUT_1080:
if (field == HDVO_TOP_FIELD) {
set1920x1080TopParameters(dspcpuContext);
}
else {
set1920x1080BottomParameters(dspcpuContext);
}
setupVideoPointers(dspcpuContext,
hd1080YPtr,
hd1080YPtr+(HD_1080_Y_WIDTH*HD_1080_Y_HEIGHT/2),
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -