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

📄 yss903.c

📁 用于TM1300/PNX1300系列DSP(主要用于视频处理)的设备库的源码
💻 C
📖 第 1 页 / 共 3 页
字号:
/*                                                           
 * 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              : yss903.c  1.2                 
 *
 *  Last update              : 18:43:53  -  00/11/09         
 *
 *  Description              :
 *     These functions are used to control the audio functions of 
 *     the YSS903 Yamaha Karaoke chip.
 *
 * WARNING:  The matching C file assumes some hardware in an FPGA to write to the part.
 * If that changes, you need to change the read and write functions.
 *
 *
 */

/* includes of system H files */
#include <stdio.h>
#include <stdlib.h>                    
#include <math.h>                      
#include <tm1/mmio.h>     
#include <tmlib/dprintf.h>
#include <tm1/tmAssert.h>
#include <tm1/tmLibdevErr.h>

#include "yss903.h"

/* Macros to access Karaoke chip */
#define ReadKaraDataReg()		(xioSimpleRead(YssData))
#define ReadKaraCtrlReg()		(xioSimpleRead(YssCtrl))
#define WriteKaraDataReg(x)     xioSimpleWrite(YssData, x )
#define WriteKaraAddrReg(x)	    xioSimpleWrite(YssAddr, x )
#define WriteKaraCtrlReg(x)	    xioSimpleWrite(YssCtrl, x )

static Address YssData = 0;
static Address YssCtrl = 0;
static Address YssAddr = 0;

#define DP_L2(x) DP(x)

/* if USE_KARAOKE is defined, static variables are added 
 * taking up about 300 bytes.
 */

// #ifdef USE_KARAOKE
#if 1

static Bool InKaraokeMode = False;

/* hold an image of the current registers in karaoke mode */
/* WARNING:  The shadow structure must have the same size as the init structure! */
static UInt8 yssKaraokeModeShadow[]=
{
/* addr, data, */
    0x00, 0xcb,     // OPR: controls internal operations.
    0x01, 0x00,     // KSR: line in keyshift and surround mode
    0x02, 0x03,     // VCR: Fade control and voice cancel
    0x03, 0x00,     // TMR: Time for fade
    0x04, 0x04,     // DAR: format. 84 is pass through, 04 is process.
    0x07, 0x00,     // KER: Mic keyshift
    0x1c, 0x40,     // MDR: Mode, 0 for old karaoke.  40 for extended karaoke

    0x20, 0x00,     // C00: Echo L mix to output.  turn off.
    0x21, 0x00,     // C01: Surround L output mix
    0x22, 0x7F,     // C02: Audio L output level
    0x23, 0x00,     // C03: Echo R mix to output.  turn off.
    0x24, 0x00,     // C04: Surround R output mix
    0x25, 0x00,     // C05: Mic echo L channel delay
    0x26, 0x7F,     // C06: Audio R output level
    0x28, 0x00,     // C08: Mic echo R channel delay
    0x29, 0x7F,     // C09: Digital Input L-L mixing level
    0x2A, 0x00,     // C0A: Digital Input L-R mixing level
    0x2B, 0x00,     // C0B: Mic echo L feedback level
    0x2C, 0x00,     // C0C: Mic echo R feedback level
    0x2D, 0x00,     // C0D: Mic echo input level
    0x2E, 0x00,     // COE: Digital input R-L mixing level
    0x2F, 0x7F,     // COF: Digital input R-R mixing level
    0x34, 0x10,     // C14: Time constant for mic level detect
    0x35, 0x1F,     // C15: Mic direct sound output mix level
    0x36, 0x00,     // C16: Mic echo L mixing level
    0x37, 0x00,     // C17: Mic echo F mixing level
    0x38, 0x00,     // C18: Mic key control L mixing level
    0x39, 0x00,     // C19: Mic key control R mixing level
    0x3A, 0x00,     // C1A: reverb echo L mixing level
    0x3B, 0x00,     // C1B: reverb echo R mixing level
    0x3C, 0x00,     // C1C: mic echo Ymersion L mixing level
    0x3D, 0x00,     // C1D: mic echo Ymersion R mixing level
    0x3e, 0x7F,     // C1E: Left channel total ouput level
    0x3f, 0x7F,     // C1F: Right channel total ouput level

    0x05, 0x00,     // TCR: tone (bass, treble)
    0x06, 0x00,     // RVR: midrange and reverb (0x10)
};

 /* YSS903's Init values for karaoke mode */
static UInt8 yssKaraokeModeInit[]=
{
/* addr, data, */
    0x00, 0xcb,     // OPR: controls internal operations.
    0x01, 0x00,     // KSR: line in keyshift and surround mode
    0x02, 0x03,     // VCR: Fade control and voice cancel
    0x03, 0x00,     // TMR: Time for fade
    0x04, 0x04,     // DAR: format. 84 is pass through, 04 is process.
    0x07, 0x00,     // KER: Mic keyshift
    0x1c, 0x40,     // MDR: Mode, 0 for old karaoke.  40 for extended karaoke

    0x20, 0x00,     // C00: Echo L mix to output.  turn off.
    0x21, 0x00,     // C01: Surround L output mix
    0x22, 0x7F,     // C02: Audio L output level
    0x23, 0x00,     // C03: Echo R mix to output.  turn off.
    0x24, 0x00,     // C04: Surround R output mix
    0x25, 0x00,     // C05: Mic echo L channel delay
    0x26, 0x7F,     // C06: Audio R output level
    0x28, 0x00,     // C08: Mic echo R channel delay
    0x29, 0x7F,     // C09: Digital Input L-L mixing level
    0x2A, 0x00,     // C0A: Digital Input L-R mixing level
    0x2B, 0x00,     // C0B: Mic echo L feedback level
    0x2C, 0x00,     // C0C: Mic echo R feedback level
    0x2D, 0x00,     // C0D: Mic echo input level
    0x2E, 0x00,     // COE: Digital input R-L mixing level
    0x2F, 0x7F,     // COF: Digital input R-R mixing level
    0x34, 0x10,     // C14: Time constant for mic level detect
    0x35, 0x1F,     // C15: Mic direct sound output mix level
    0x36, 0x00,     // C16: Mic echo L mixing level
    0x37, 0x00,     // C17: Mic echo F mixing level
    0x38, 0x00,     // C18: Mic key control L mixing level
    0x39, 0x00,     // C19: Mic key control R mixing level
    0x3A, 0x00,     // C1A: reverb echo L mixing level
    0x3B, 0x00,     // C1B: reverb echo R mixing level
    0x3C, 0x00,     // C1C: mic echo Ymersion L mixing level
    0x3D, 0x00,     // C1D: mic echo Ymersion R mixing level
    0x3e, 0x7F,     // C1E: Left channel total ouput level
    0x3f, 0x7F,     // C1F: Right channel total ouput level

    0x05, 0x00,     // TCR: tone (bass, treble)
    0x06, 0x00,     // RVR: midrange and reverb (0x10)
};

/* hold an image of the current registers in movie mode */
/* WARNING:  The shadow structure must have the same size as the init structure! */
static UInt8 yssMovieModeShadow[]=
{
/* addr, data, */
    0x00, 0xcb,     // OPR: controls internal operations.
    0x01, 0x00,     // KSR: line in keyshift and surround mode
    0x02, 0x00,     // VCR: Fade control and voice cancel
    0x03, 0x00,     // TMR: Time for fade
    0x04, 0x04,     // DAR: format. 84 is pass through, 04 is process.
    0x07, 0x00,     // KER: Mic keyshift
    0x1c, 0x50,     // MDR: Mode, mute: 0 for old karaoke mode

    0x21, 0x0,      // C01: Surround Ymersion L output mix
    0x22, 0x7F,     // C02: Audio & surround L output level
    0x24, 0x0,      // C04: Surround Ymersion R output mix
    0x26, 0x7f,     // C06: Audio & surround R output level
    0x29, 0x7F,     // C09: Digital Input L-L mixing level
    0x2A, 0x0,      // C0A: Digital Input L-R mixing level
    0x2E, 0x00,     // COE: Digital input R-L mixing level
    0x2F, 0x7F,     // COF: Digital input R-R mixing level
    0x30, 0x00,     // C10: Surround input 1 to left channel
    0x31, 0x00,     // C11: Surround input 1 to right channel
    0x32, 0x00,     // C12: Surround input 2 to left channel
    0x33, 0x00,     // C13: Surround input 2 to right channel
    0x35, 0x1F,     // C15: Mic direct sound output mix level
    0x36, 0x7F,     // C16: Audio L ch mixing level
    0x37, 0x7F,     // C17: Audio R ch mixing level
    0x38, 0x00,     // C18: Surround L mixing level
    0x39, 0x00,     // C19: Surround R mixing level
    0x3A, 0x00,     // C1A: surround Ymersion input 1 L mixing level
    0x3B, 0x00,     // C1B: surround Ymersion input 1 R mixing level
    0x3C, 0x00,     // C1C: surround Ymersion input 2 L mixing level
    0x3D, 0x00,     // C1D: surround Ymersion input 2 R mixing level
    0x3e, 0x7F,     // C1E: Left channel total ouput level
    0x3f, 0x7F,     // C1F: Right channel total ouput level

    0x05, 0x00,     // TCR: tone (bass, treble)
    0x06, 0x00,     // RVR: midrange and reverb (0x10)
};

static UInt8 yssMovieModeInit[]=
{
/* addr, data, */
    0x00, 0xcb,     // OPR: controls internal operations.
    0x01, 0x00,     // KSR: line in keyshift and surround mode
    0x02, 0x00,     // VCR: Fade control and voice cancel
    0x03, 0x00,     // TMR: Time for fade
    0x04, 0x04,     // DAR: format. 84 is pass through, 04 is process.
    0x07, 0x00,     // KER: Mic keyshift
    0x1c, 0x50,     // MDR: Mode, mute: 0 for old karaoke mode

    0x21, 0x0,      // C01: Surround Ymersion L output mix
    0x22, 0x7F,     // C02: Audio & surround L output level
    0x24, 0x0,      // C04: Surround Ymersion R output mix
    0x26, 0x7f,     // C06: Audio & surround R output level
    0x29, 0x7F,     // C09: Digital Input L-L mixing level
    0x2A, 0x0,      // C0A: Digital Input L-R mixing level
    0x2E, 0x00,     // COE: Digital input R-L mixing level
    0x2F, 0x7F,     // COF: Digital input R-R mixing level
    0x30, 0x00,     // C10: Surround input 1 to left channel
    0x31, 0x00,     // C11: Surround input 1 to right channel
    0x32, 0x00,     // C12: Surround input 2 to left channel
    0x33, 0x00,     // C13: Surround input 2 to right channel
    0x35, 0x1F,     // C15: Mic direct sound output mix level
    0x36, 0x7F,     // C16: Audio L ch mixing level
    0x37, 0x7F,     // C17: Audio R ch mixing level
    0x38, 0x00,     // C18: Surround L mixing level
    0x39, 0x00,     // C19: Surround R mixing level
    0x3A, 0x00,     // C1A: surround Ymersion input 1 L mixing level
    0x3B, 0x00,     // C1B: surround Ymersion input 1 R mixing level
    0x3C, 0x00,     // C1C: surround Ymersion input 2 L mixing level
    0x3D, 0x00,     // C1D: surround Ymersion input 2 R mixing level
    0x3e, 0x7F,     // C1E: Left channel total ouput level
    0x3f, 0x7F,     // C1F: Right channel total ouput level

    0x05, 0x00,     // TCR: tone (bass, treble)
    0x06, 0x00,     // RVR: midrange and reverb (0x10)
};

/***************************************************************/
extern tmLibdevErr_t yss903Write(UInt8 addr, UInt8 data)
{
    int counter;
    int i;

    tmAssert(YssData != 0, ERR_YSS903_YSS_INVALID_BASE_REGISTER );
    tmAssert(YssCtrl != 0, ERR_YSS903_YSS_INVALID_BASE_REGISTER );
    tmAssert(YssAddr != 0, ERR_YSS903_YSS_INVALID_BASE_REGISTER );
    
    for (counter = 0; counter < 10; counter++)
    {   /* it must not be possible to hang in the BSP */
        if (((ReadKaraCtrlReg() & 0x01)) == 0)
            break;
        microsleep (100);
    }
    if (counter >= 10) 
    {
        DP(("yss903Write failed writing %x to %x\n", data, addr));
        return ERR_YSS903_YSS_WRITE_FAILED;
    }
    DP(("yss903Write %x to %x (%d) \n", data, addr, counter));
    WriteKaraAddrReg(addr);
    WriteKaraDataReg(data);
    WriteKaraCtrlReg(0x01);
    
    if (InKaraokeMode)
    {
        for (i=0; i< sizeof(yssKaraokeModeShadow); i+=2)
        {
            if (addr == yssKaraokeModeShadow[i]) 
            {
                yssKaraokeModeShadow[i+1] = data;
                return TMLIBDEV_OK; 
            }
        }
        DP(("yss903Write invalid shadow writing %x to %x in Karaoke mode\n", data, addr));
        return ERR_YSS903_YSS_WRITE_FAILED;
    }
    else
    {
        for (i=0; i< sizeof(yssMovieModeShadow); i+=2)
        {
            if (addr == yssMovieModeShadow[i])
            {
                yssMovieModeShadow[i+1] = data;
                return TMLIBDEV_OK; 
            }
        }
        DP(("yss903Write invalid shadow writing %x to %x in Movie mode\n", data, addr));
        return ERR_YSS903_YSS_WRITE_FAILED;
    }
}

/***************************************************************/
extern tmLibdevErr_t yss903WriteBits(UInt8 addr, UInt8 data, UInt8 mask)
{
    int i, counter;
    UInt8 readData;

    DP_L2(("Write bits %x:", data));
    yss903Read(addr, &readData);
    DP_L2((" read %x,", readData));
    readData &= ~mask;
    readData |= data;
    DP_L2((" write %x\n", readData));
      
    for (counter = 0; counter < 10; counter++)
    {   /* it must not be possible to hang in the BSP */
        if (((ReadKaraCtrlReg() & 0x01)) == 0)
            break;
        microsleep (100);
    }
    if (counter >= 10) 
    {
        DP(("yss903WriteBits timed out writing %x to %x (%d) \n", readData, addr, counter));
        return ERR_YSS903_YSS_WRITE_FAILED;
    }
    DP(("yss903WriteBits %x to %x (%d) \n", readData, addr, counter));
    WriteKaraAddrReg(addr);
    WriteKaraDataReg(readData);
    WriteKaraCtrlReg(0x01);
    if (InKaraokeMode)
    {
        for (i=0; i< sizeof(yssKaraokeModeShadow); i+=2)
        {
            if (addr == yssKaraokeModeShadow[i]) 
            {
                yssKaraokeModeShadow[i+1] = readData;
                return TMLIBDEV_OK; 
            }
        }
    }
    else
    {
        for (i=0; i< sizeof(yssMovieModeShadow); i+=2)
        {
            if (addr == yssMovieModeShadow[i])
            {
                yssMovieModeShadow[i+1] = readData;
                return TMLIBDEV_OK; 
            }
        }
    }
    DP(("yss903WriteBits invalid shadow writing %x to %x\n", readData, addr));
    return ERR_YSS903_YSS_WRITE_FAILED;
}

⌨️ 快捷键说明

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