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

📄 dtv_ref4_audio.c

📁 用于TM1300/PNX1300系列DSP(主要用于视频处理)的设备库的源码
💻 C
📖 第 1 页 / 共 2 页
字号:
/*
 * Copyright (c) 1995,1996,1997 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              : dtv_ref4_audio.c    1.6
 *
 *  Last update              : 19:01:55 - 00/11/09
 *
 *  Description              :
 *
 *
 */


/* TriMedia standard shared includes */
#include <tm1/tmAssert.h>
#include <tmlib/dprintf.h>
#include <tmlib/tmtypes.h>
#include <tm1/tmAOmmio.h>
#include <tm1/tmAImmio.h>
#include <tm1/tmSPDOmmio.h>
#include <tm1/tmIIC.h>
#include <tm1/tmProcessor.h>
#include <tm1/tmLibdevErr.h>

#include "uda13xx.h"
#include "xioReg.h"

#include "philips_dtv_ref4.h"
#include "dtv_ref4_audio.h"

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

/* flag to indicate that the 32-bit mode is enabled */
static Float    dtvRef4CPUClock               = 0.0;

static l3Param_t            hdUdaL3Param =
{
    l3ModeXIO, /* mode */
    0,         /* address */
    0,         /* l3Address, will be changed by uda13xx lib */
    0x40,      /* l3Data */
    0x20,      /* l3Mode */
    0x01,      /* l3Clock */
    0,         /* usrPin0 */
    0,         /* usrPin1 */
    0,         /* usrPin2 */
    0,         /* l3AddressAdd */
    0x01,      /* l3DataAdd */
    0x01,      /* l3ModeAdd */
    0x03,      /* l3ClockAdd */
    0,         /* usrPin0Add */
    0,         /* usrPin1Add */
    0,         /* usrPin2Add */
    0,         /* numberOfBytes */
    Null       /* data */
};

static uda13xxRegisters_t   hdUdaRegs; 
static uda13xxParam_t       hdUdaParam = 
{
    uda13xxXIOMode,          /* mode */
    (Pointer) &hdUdaL3Param, /* modeParams */
    &hdUdaRegs               /* regs */
};

static uda13xxOutputParam_t hdUdaOutputParam = 
{
    False,     /* muteOn */
    &hdUdaRegs /* regs */
};

static l3Param_t            sdUdaL3Param =
{
    l3ModeXIO, /* mode */
    0,         /* address */
    0,         /* l3Address, will be changed by uda13xx lib */
    0x40,      /* l3Data */
    0x20,      /* l3Mode */
    0x01,      /* l3Clock */
    0,         /* usrPin0 */
    0,         /* usrPin1 */
    0,         /* usrPin2 */
    0,         /* l3AddressAdd */
    0x01,      /* l3DataAdd */
    0x01,      /* l3ModeAdd */
    0x03,      /* l3ClockAdd */
    0,         /* usrPin0Add */
    0,         /* usrPin1Add */
    0,         /* usrPin2Add */
    0,         /* numberOfBytes */
    Null       /* data */
};

static uda13xxRegisters_t   sdUdaRegs; 
static uda13xxParam_t       sdUdaParam = 
{
    uda13xxXIOMode,          /* mode */
    (Pointer) &sdUdaL3Param, /* modeParams */
    &sdUdaRegs               /* regs */
};

static uda13xxOutputParam_t sdUdaOutputParam = 
{
    False,     /* muteOn */
    &sdUdaRegs /* regs */
};

/*******************************************************/
extern tmLibdevErr_t dtvRef4_AO_Init_1(boardAOParam_t * param)
{
    Float               val;
    pprocCapabilities_t procCap;
    Int                 err = TMLIBDEV_OK;

    /* get the clock frequency of the TriMedia CPU */       
    err = procGetCapabilities(&procCap);
    if (err) return err;
    
    dtvRef4CPUClock = (Float) procCap->cpuClockFrequency;
    
    /* reset the audio output peripheral */
    aoRESETM(AO1_STATUS);

    /* Set initial frequency to get AO into a stable state */
    val = param->sRate * 256.0; /* 256 * sampleRate */
    val = 0.5 + (477218588.0 * (val / dtvRef4CPUClock));    /* 2**32 / 9 */
    aoSetFREQM(AO1_STATUS, ((UInt) val) | 0x80000000);
    
    aoEnableSER_MASTERM(AO1_STATUS);
    microsleep(10); /* wait until AO unit stabalized */

    if (! (param->audioTypeFormat & DTV_REF4_SUPPORTED_AUDIO_OUT_TYPES_1) )
        return AIO_ERR_UNSUPPORTED_FORMAT;
    if (! (param->audioSubtypeFormat & DTV_REF4_SUPPORTED_AUDIO_OUT_SUBTYPES_1) )
        return AIO_ERR_UNSUPPORTED_FORMAT;

    /* enable LCLK 1-4 to enable L3 clocks for HD DACs */
    err = xioRegWriteBit(0x00, 0x01, False);
    err |= xioRegWriteBit(0x00, 0x02, False);
    err |= xioRegWriteBit(0x00, 0x04, False);
    err |= xioRegWriteBit(0x00, 0x08, False);
    if (err != TMLIBDEV_OK)
    {
        aoRESETM(AO1_STATUS);
        return err;
    }

    /* initialize the DACs (UDA 1320) */
    err = uda13xxInitOutput(&hdUdaParam, &hdUdaOutputParam);
    if (err != TMLIBDEV_OK)
    {
        aoRESETM(AO1_STATUS);
        return err;
    }

    /* disable LCLK 1-4 to enable L3 clocks for HD DACs */
    err = xioRegWriteBit(0x00, 0x01, True);
    err |= xioRegWriteBit(0x00, 0x02, True);
    err |= xioRegWriteBit(0x00, 0x04, True);
    err |= xioRegWriteBit(0x00, 0x08, True);
    if (err != TMLIBDEV_OK)
    {
        aoRESETM(AO1_STATUS);
        return err;
    }

#ifdef __LITTLE_ENDIAN__
    aoEnableLITTLE_ENDIANM(AO1_STATUS);
#else
    aoDisableLITTLE_ENDIANM(AO1_STATUS);
#endif
    aoMsbFirstM(AO1_STATUS);
    aoStartRisingEdgeWSM(AO1_STATUS);  
    aoSampleRisingCLOCK_EDGEM(AO1_STATUS); /* sample on rising edge */
    aoSetSSPOSM(AO1_STATUS, 0);               /* Left and right channel start at bit 0 */
    aoDisableSIGN_CONVERTM(AO1_STATUS);    /* Disable Sign Convert for MSB */
    aoDisableWS_PULSEM(AO1_STATUS);        /* word strobe in pulse mode */
    aoDisableTRANS_ENABLEM(AO1_STATUS);
    
    switch (param->audioSubtypeFormat) {
        case apfStereo16:               /* Two channel Audio */
        {   /* 64 * 4 * 1 = 256fs */
            DP(("stereo 16 bit\n"));
            aoSetTRANS_MODEM(AO1_STATUS, 3);
            aoSetWSDIVM(AO1_STATUS, 63);
            aoSetSCKDIVM(AO1_STATUS, 3);
            aoSetNR_CHANM(AO1_STATUS, 0);
            aoSetLEFTPOSM(AO1_STATUS, 0);
            aoSetRIGHTPOSM(AO1_STATUS, 32);
            aoSetSIZEM(AO1_STATUS, param->size);
            break;
        }
        case apfStereo32:               /* Two channel Audio, 32-bit */
        {   /* 64 * 4 * 1 = 256 fs */
            DP(("stereo 32 bit\n"));
            aoSetTRANS_MODEM(AO1_STATUS, 1);
            aoSetWSDIVM(AO1_STATUS, 63);
            aoSetSCKDIVM(AO1_STATUS, 3);
            aoSetNR_CHANM(AO1_STATUS, 0);
            aoSetLEFTPOSM(AO1_STATUS, 0);
            aoSetRIGHTPOSM(AO1_STATUS, 32);
            aoSetSIZEM(AO1_STATUS, param->size);
            break;
        }
        case apfFourCh_3_1_0_16:       /* Four channel Audio */
        case apfFourCh_2_2_0_16:       /* Four channel Audio */
        case apfFourCh_2_1_1_16:       /* Four channel Audio */
        case apfFourCh_3_0_1_16:       /* Four channel Audio */
        {
            DP(("four channels 16 bit\n"));
            aoSetTRANS_MODEM(AO1_STATUS, 3);
            aoSetWSDIVM(AO1_STATUS, 63);
            aoSetSCKDIVM(AO1_STATUS, 3);
            aoSetNR_CHANM(AO1_STATUS, 1);
            aoSetLEFTPOSM(AO1_STATUS, 0);
            aoSetRIGHTPOSM(AO1_STATUS, 32);
            aoSetSIZEM(AO1_STATUS, param->size * 2);
            break;
        }
        case apfFourCh_3_1_0_32:       /* Four channel Audio, 32-bit */
        case apfFourCh_2_2_0_32:       /* Four channel Audio, 32-bit */
        case apfFourCh_2_1_1_32:       /* Four channel Audio, 32-bit */
        case apfFourCh_3_0_1_32:       /* Four channel Audio, 32-bit */
        {
            DP(("four channels 32 bit\n"));
            aoSetTRANS_MODEM(AO1_STATUS, 1);
            aoSetWSDIVM(AO1_STATUS, 63);
            aoSetSCKDIVM(AO1_STATUS, 3);
            aoSetNR_CHANM(AO1_STATUS, 1);
            aoSetLEFTPOSM(AO1_STATUS, 0);
            aoSetRIGHTPOSM(AO1_STATUS, 32);
            aoSetSIZEM(AO1_STATUS, param->size * 2);
            break;
        }
        case apfFiveDotOne16:  /* Six Channel Audio */
        {
            DP(("six channels 16 bit\n"));
            aoSetTRANS_MODEM(AO1_STATUS, 3);
            aoSetWSDIVM(AO1_STATUS, 63);
            aoSetSCKDIVM(AO1_STATUS, 3);
            aoSetNR_CHANM(AO1_STATUS, 2);
            aoSetLEFTPOSM(AO1_STATUS, 0);
            aoSetRIGHTPOSM(AO1_STATUS, 32);
            aoSetSIZEM(AO1_STATUS, param->size * 3);
            break;
        }
        case apfFiveDotOne32:  /* Six Channel Audio, 32-bit */
        {
            DP(("six channels 32 bit\n"));
            aoSetTRANS_MODEM(AO1_STATUS, 1);
            aoSetWSDIVM(AO1_STATUS, 63);
            aoSetSCKDIVM(AO1_STATUS, 3);
            aoSetNR_CHANM(AO1_STATUS, 2);
            aoSetLEFTPOSM(AO1_STATUS, 0);
            aoSetRIGHTPOSM(AO1_STATUS, 32);
            aoSetSIZEM(AO1_STATUS, param->size * 3);
            break;
        }
        case apfSevenDotOne16:  /* Eight Channel Audio */
        {
            DP(("eight channels 16 bit\n"));
            aoSetTRANS_MODEM(AO1_STATUS, 3);
            aoSetWSDIVM(AO1_STATUS, 63);
            aoSetSCKDIVM(AO1_STATUS, 3);
            aoSetNR_CHANM(AO1_STATUS, 3);
            aoSetLEFTPOSM(AO1_STATUS, 0);
            aoSetRIGHTPOSM(AO1_STATUS, 32);
            aoSetSIZEM(AO1_STATUS, param->size * 4);
            break;
        }
        case apfSevenDotOne32:  /* Eight Channel Audio, 32-bit */
        {
            DP(("eight channels 32 bit\n"));
            aoSetTRANS_MODEM(AO1_STATUS, 1);
            aoSetWSDIVM(AO1_STATUS, 63);
            aoSetSCKDIVM(AO1_STATUS, 3);
            aoSetNR_CHANM(AO1_STATUS, 3);
            aoSetLEFTPOSM(AO1_STATUS, 0);
            aoSetRIGHTPOSM(AO1_STATUS, 32);
            aoSetSIZEM(AO1_STATUS, param->size * 4);
            break;
        }
        default:
            /* unsupported subtype */
            return(AIO_ERR_UNSUPPORTED_FORMAT);
    }

    /* set sample rate */    
    err = dtvRef4_AO_SetSRate_1(param->sRate);
    if (err)
        return err;

    return TMLIBDEV_OK;
}   /* end of dtvRef4_AO_Init() */


/*******************************************************/
extern tmLibdevErr_t dtvRef4_AO_Term_1(void)
{
    Int     err = TMLIBDEV_OK;

    /* reset statics */
    
    aoRESETM(AO1_STATUS);
    return err;
}

⌨️ 快捷键说明

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