📄 ad1847.c
字号:
/*
* 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 : ad1847.c 1.47
*
* Last update : 20:04:17 - 98/08/14
*
* Description :
*
* Initialize and control routines for ad1847 audio codec.
* There are three sections to this file:
* Section 1: Support code common to all 1847 modes.
* Section 2: Master version functions
* Section 3: Slave version functions (commented out)
*
* In master mode, the 1847 masters the IIS bus.
* In slave mode, TM-1 masters the IIS bus.
*
* Revision :
* Built for the TCS 1.1 release
*
*
*/
#include <ops/custom_defs.h>
#include <tmlib/tmtypes.h>
#include <tm1/tmProcessor.h>
#include <tm1/tmInterrupts.h>
#include <tm1/tmIIC.h>
#include <tm1/tmAImmio.h>
#include <tm1/tmAOmmio.h>
#include <tm1/tmBoard.h>
#include <tm1/tmAssert.h>
#include <tm1/tmAvFormats.h>
#include <string.h>
#include <stdlib.h>
/* for debugging */
#include <tmlib/dprintf.h> /* for debugging with DP(()) */
#include "ad1847.h"
static Bool writeAoCC(UInt value);
static tmLibdevErr_t ad1847WriteRegisters(void);
/*********************** Statics: *******************************/
static Bool __ad1847Initialized = False;
/* this is a mirror of what is in the 1847 */
static UInt8 Reg1847[16];
/*********************** *******************************
* there are three sections to this file:
* Section 1: Support code common to all 1847 modes.
* Section 2: Master version functions
* Section 3: Slave version functions
*
* In master mode, the 1847 masters the IIS bus.
* In slave mode, TM-1 masters the IIS bus. Slave mode does not work.
*
*/
/***********************
* COMMON SECTION:
**********************/
/*
* perform a write to AO_CC (codec control)
* with timeout loop, etc. returns True
* if there was an error, False if success.
* Checks for busy before AND after.
*
*/
static Bool writeAoCC(UInt value)
{
Int i;
microsleep(40); /* minimum */
for (i = 0; MMIO(AO_STATUS) & AO_CC_BUSY; i++)
{ /* busy wait until CC_BUSY is clear */
if (i > 40) /* wait 800uSec: s/b OK down to 2khz */
return True; /* timeout error */
microsleep(20);
}
MMIO(AO_CC) = value; /* aoSetCC2((UInt16) value); */
microsleep(40); /* minimum */
for (i = 0; MMIO(AO_STATUS) & AO_CC_BUSY; i++)
{ /* busy wait until CC_BUSY is clear */
if (i > 40) /* wait 800uSec: s/b OK down to 2khz */
return True; /* timeout error */
microsleep(20);
}
/* set defined value for codec control -> 0 sets volume and source for left input */
aoSetCC2(0x0F00);
return False;
}
/*******************************************************/
/*
* Choose one of four sources Set input gain in 100th db. Range 0 to 2250.
*/
extern tmLibdevErr_t ad1847ConfigureInput(Int src, Int lvol, Int rvol)
{
tmLibdevErr_t err = TMLIBDEV_OK;
UInt8 r0val = Reg1847[0];
UInt8 r1val = Reg1847[1];
if (!__ad1847Initialized)
return (AIO_ERR_INIT_REQUIRED);
/* cast the volume spec to the 1847's control spec */
lvol = lvol / 150;
if (lvol > 15) {
lvol = 15;
err = AIO_ERR_VOLUME_TOO_HIGH;
}
if (lvol < 0) {
lvol = 0;
err = AIO_ERR_VOLUME_TOO_LOW;
}
rvol = rvol / 150;
if (rvol > 15) {
rvol = 15;
err = AIO_ERR_VOLUME_TOO_HIGH;
}
if (rvol < 0) {
rvol = 0;
err = AIO_ERR_VOLUME_TOO_LOW;
}
r0val = src + lvol;
r1val = src + rvol;
Reg1847[0] = r0val;
Reg1847[1] = r1val;
if (writeAoCC(0x8000 + r0val))
return AIO_ERR_TIMEOUT0;
if (writeAoCC(0x8100 + r1val))
return AIO_ERR_TIMEOUT1;
return err;
}
/*******************************************************/
/*
* volumes given in 100th db. vol < -9600 implies mute. Part has 1.5db
* resolution. Max is 0db (0)
*/
extern tmLibdevErr_t ad1847ConfigureOutput(Int lgain, Int rgain)
{
tmLibdevErr_t err = TMLIBDEV_OK;
UInt8 r6val = Reg1847[6];
UInt8 r7val = Reg1847[7];
if (!__ad1847Initialized)
return (AIO_ERR_INIT_REQUIRED);
if (lgain > 0) {
lgain = 0;
err = AIO_ERR_VOLUME_TOO_HIGH;
}
if (rgain > 0) {
rgain = 0;
err = AIO_ERR_VOLUME_TOO_HIGH;
}
/* too low -> mute */
if (lgain <= -9600)
r6val |= 0x80;
else
r6val = -lgain / 150;
if (rgain <= -9600)
r7val |= 0x80;
else
r7val = -rgain / 150;
Reg1847[6] = r6val;
Reg1847[7] = r7val;
if (writeAoCC(0x8600 + r6val))
return AIO_ERR_TIMEOUT2;
if (writeAoCC(0x8700 + r7val))
return AIO_ERR_TIMEOUT3;
return err;
}
/*********************** *******************************/
extern tmLibdevErr_t ad1847Term(void)
{
tmLibdevErr_t rval;
UInt iicd;
aoRESET();
aiRESET();
/* shut down the AD 1847 */
rval = iicReadReg(TM_IREF_IIC_EXPANDER_ADDRESS, -1, &iicd);
if (rval)
{
return rval;
}
iicd &= 0x7; /* only keep video signals high */
iicd |= 0x80; /* standby for 6ch DAC */
rval = iicWriteReg(TM_IREF_IIC_EXPANDER_ADDRESS, -1, iicd);
if (rval)
{
return rval;
}
__ad1847Initialized = False;
return TMLIBDEV_OK;
}
/*******************************************************************
* MASTER SECTION:
*
* The AD1847 operates in master mode (BM pin is high)
* OSCLCK comes from the TM-1 DDS.
* 1847 produces IIS serial port clocks.
*
******************************************************************/
/*********************** ad1847MasterInit() ******************************/
/* values used for Master initialization */
static UInt8 InitReg1847M[] =
{
0x00, /* left input gain */
0x00, /* right input gain */
0x80, /* left aux1 */
0x80, /* right aux1 */
0x80, /* left aux2 */
0x80, /* right aux2 */
0x00, /* left output */
0x00, /* right output */
0x5C, /* 5C: sample rate: Xtal 1, divide by 512 */
0x09, /* calibrate / play */
0x00, /* pin control */
0x00, /* invalid */
0xC0, /* misc */
0x00, /* digital mix */
0x00, /* invalid */
0x00 /* invalid */
};
#define _TEMP_BUFSIZE 64
extern tmLibdevErr_t ad1847MasterInit(tmAudioPcmFormat_t pcmFormat, Float sRate)
{
Int i;
Int dummyBuffer[ 2 * _TEMP_BUFSIZE + 63];
Int *ob1, *ob2;
UInt ddsFrequency = MMIO(AO_FREQ); /* remember audio out frequency */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -