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

📄 avio.c

📁 用于TM1300/PNX1300系列DSP(主要用于视频处理)的外部设备的源码
💻 C
📖 第 1 页 / 共 2 页
字号:
/*
 * 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              : avio.c    1.37
 *
 *  Last update              : 17:15:54 - 00/11/09
 *
 *  Description              :
 *
 *        A test and demonstration for the TriMedia audio
 *              and video I/O modules.
 *
 *  Revision                 :
 *
 *
 */

/**************************************************************************
 * 									  *
 * 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 <tmlib/tmlibc.h>
#include <tm1/mmio.h>

#include <tm1/tmAI.h>
#include <tm1/tmVI.h>
#include <tm1/tmAO.h>
#include <tm1/tmVO.h>
#include <tm1/tmIIC.h>
#include <tm1/tmProcessor.h>
#include <tm1/tmAvFormats.h>
#include <tm1/tmLibdevErr.h>

#include <tmlib/AppModel.h>
#include <tmlib/dprintf.h>

#include <tm1/tmHelp.h>

#define  AUD_BUFSIZE  768   /* must be multiple of 64 and 3 for 6ch */
#define  AUD_NUMBUFS  4
#define  VID_NUMBUFS  4

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;

/********************************** globals:  *************************/

static volatile Bool AudioOutSyncError = False, AudioInSyncError = False;

static Int      fullStride = 768;
static Int      fullWidth = 720;
static Int      fullHeight = 480;

static Bool     firstField = True;

static int      aiInst, aoInst;

aiInstanceSetup_t aiInstSup;
aoInstanceSetup_t aoInstSup;

static Int     *audBuf[AUD_NUMBUFS];
static Int      aiNum, aoNum;

static Int      viInst, voInst;

static vBuf     vidBuf[VID_NUMBUFS];
static int      viNum, voNum;

static UInt     videoStandard = vasNTSC;
static UInt     adapterType = vaaCVBS;

#define  VID_RDY_VI     1   /* buffer is ready for vi to use */
#define  VID_RDY_VO     2   /* buffer is ready for vo to use */

#define  AUD_RDY_AI     1   /* buffer is ready for ai to use */
#define  AUD_RDY_AO     2   /* buffer is ready for ao to use */

static Char    *Header = "\nTriMedia audio/video Example Program Version 3.0\n";

/***************************************************************
 *                                                             *
 *                error & reporting                            *
 *                                                             *
 ***************************************************************/

static void
my_abort(Char * name, Int err)
{
    assert(name != Null);
    fprintf(stderr, "%s failed, error code %x\n", name, err);
    exit(-1);
}

void
SetDP()
{
    DPsize(32000);
}



void
vivoDetectworkarounds(void)
{
    tmLibdevErr_t err;
    pprocCapabilities_t cap;

    if (err = procGetCapabilities(&cap))
        my_abort("procGetCapabilities", err);

    if (cap->revisionID <= PROC_REVISION_1_0S && cap->deviceID <= PROC_DEVICE_TM1000) {
	fprintf(stderr, "Detected tm1s1.0 or older version of chip. "
		"They are no longer supported.\n" 
		"Please contact Philips TriMedia to exchange to "
		"a newer version of chip.\n");
	exit(-1);
    }

}

/***************************************************************
 *                                                             *
 *                memory allocation                            *
 *                                                             *
 ***************************************************************/

Pointer
allocSz(Int bufSz)
{
    Char           *temp;

    if ((temp = (char *) _cache_malloc(bufSz, -1)) == Null)
        my_abort("_cache_malloc", 0);

    memset(temp, 0, bufSz);
    _cache_copyback((void *) temp, bufSz);
    return (Pointer) temp;
}


static void
allocAudio(void)
{
    Int             i;

    for (i = 0; i < AUD_NUMBUFS; i++) {
        /* cache align malloc, zero, and copyback */
        audBuf[i] = (int *) allocSz(AUD_BUFSIZE * 4);
    }
}

static void
allocVideo()
{
    Int             i, szY, szUV;

    szY = (fullStride * (fullHeight + 4));
    szUV = ((fullStride >> 1) * (fullHeight + 4));
    for (i = 0; i < VID_NUMBUFS; i++) {
        /* cache align malloc, zero, and copyback */
        vidBuf[i].Y = allocSz(szY);
        vidBuf[i].U = allocSz(szUV);
        vidBuf[i].V = allocSz(szUV);
        vidBuf[i].flag = VID_RDY_VI;
    }
}

void
avioAlloc()
{
    allocAudio();
    allocVideo();
}


/***************************************************************
 *                                                             *
 *                Audio ISRs stuff                             *
 *                                                             *
 ***************************************************************/

#define    AO_SYNCHRONIZATION_CHECK(x) \
    {if (aiBUF1_ACTIVE(MMIO(AI_STATUS))) { \
        if (aiGetBASE1() == (UInt32)x) AudioOutSyncError = True;\
    }                            \
    else    {                        \
        if (aiGetBASE2() == (UInt32)x) AudioOutSyncError = True;\
    }}

static void
_aoISR(void)
{
    Int             ao_status = MMIO(AO_STATUS);

    if (aoBUF1_EMPTY(ao_status)) {
        aoNum = (aoNum + 1) % AUD_NUMBUFS;
        aoSetBASE1(audBuf[aoNum]);
        AO_SYNCHRONIZATION_CHECK(audBuf[aoNum])
            aoAckACK1();
    }
    else if (aoBUF2_EMPTY(ao_status)) {
        aoNum = (aoNum + 1) % AUD_NUMBUFS;
        aoSetBASE2(audBuf[aoNum]);
        AO_SYNCHRONIZATION_CHECK(audBuf[aoNum]);
        aoAckACK2();
    }
    else if (aoHBE(ao_status)) {
        aoAckACK_HBE();
    }
    else if (aoUNDERRUN(ao_status)) {
        DP(("AO-ISR: Under run occurred\n"));
        aoAckACK_UDR();
    }
}

static void
aoISR(void)
{
#pragma TCS_handler
    AppModel_suspend_scheduling();
    AppModel_run_on_sstack((AppModel_Fun)_aoISR, Null);
    AppModel_resume_scheduling();
}

#define    AI_SYNCHRONIZATION_CHECK(x) \
    {if (aoBUF1_ACTIVE(MMIO(AO_STATUS))) {\
        if (aoGetBASE1() == (UInt32)x) AudioInSyncError = True; \
    }                            \
    else    {                        \
        if (aoGetBASE2() == (UInt32)x) AudioInSyncError = True;    \
    }}

static void
_aiISR(void)
{
    Int             ai_status = MMIO(AI_STATUS);

    if (aiBUF1_FULL(ai_status)) {
        aiNum = (aiNum + 1) % AUD_NUMBUFS;
        AI_SYNCHRONIZATION_CHECK(audBuf[aiNum]);
        aiSetBASE1(audBuf[aiNum]);
        aiAckACK1();
    }
    else if (aiBUF2_FULL(ai_status)) {
        aiNum = (aiNum + 1) % AUD_NUMBUFS;
        AI_SYNCHRONIZATION_CHECK(audBuf[aiNum]);
        aiSetBASE2(audBuf[aiNum]);
        aiAckACK2();
    }
    else if (aiHBE(ai_status)) {
        aiAckACK_HBE();
    }
    else if (aiOVERRUN(ai_status)) {
        DP(("AI-ISR: Over run occurred\n"));
        aiAckACK_OVR();
    }
}

static void
aiISR(void)
{
#pragma TCS_handler
    AppModel_suspend_scheduling();
    AppModel_run_on_sstack((AppModel_Fun)_aiISR, Null);
    AppModel_resume_scheduling();
}


/***************************************************************
 *                                                             *
 *                Audio device Library Calls                   *
 *                                                             *
 ***************************************************************/

static void
OpenAudioAPI(void)
{
    tmLibdevErr_t   err;
    Float           srate = 44100.0;

    aoNum = 1;      /* gets incremented first in ISR */
    aiNum = 1;      /* gets incremented first in ISR */

    /*
     * Initialize audio out
     */
    if (err = aoOpen(&aoInst))
        my_abort("aoOpen", err);

    memset((char *) (&aoInstSup), 0, sizeof(aoInstanceSetup_t));
    aoInstSup.isr = aoISR;
    aoInstSup.interruptPriority = intPRIO_4;
    aoInstSup.audioTypeFormat = atfLinearPCM;
    aoInstSup.audioSubtypeFormat = apfStereo16;
    aoInstSup.sRate = srate;
    aoInstSup.output = aaaNone;
    aoInstSup.size = AUD_BUFSIZE;
    aoInstSup.base1 = audBuf[3];
    aoInstSup.base2 = audBuf[0];

    aoInstSup.underrunEnable = True;
    aoInstSup.hbeEnable = True;
    aoInstSup.buf1emptyEnable = True;
    aoInstSup.buf2emptyEnable = True;

    if (err = aoInstanceSetup(aoInst, &aoInstSup))
        my_abort("aoInstanceSetup", err);

    /*
     * and audio in
     */

    if (err = aiOpen(&aiInst))
        my_abort("aiOpen", err);

    memset((char *) (&aiInstSup), 0, sizeof(aiInstanceSetup_t));
    aiInstSup.isr = aiISR;
    aiInstSup.interruptPriority = intPRIO_4;
    aiInstSup.audioTypeFormat = atfLinearPCM;
    aiInstSup.audioSubtypeFormat = apfStereo16;
    aiInstSup.sRate = srate;

⌨️ 快捷键说明

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