📄 tmao.c
字号:
/*
* Copyright (c) 1998, 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 : tmAO.c 1.74
*
* Last update : 18:22:33 - 00/11/09
*
* Description :
*
* TriMedia audio output library.
* Supports control and use of TriMedia audio output hardware
*
* This is part of the TriMedia device libraries.
*
* The AO driver relies on the board support package.
*
* Revision :
* Built for the TCS 2.0 release
*
*
*/
/* normally, these come from the Makefile */
#ifndef MAJOR_VERSION
#define MAJOR_VERSION 3
#endif
#ifndef MINOR_VERSION
#define MINOR_VERSION 0
#endif
#ifndef BUILD_VERSION
#define BUILD_VERSION 0
#endif
#include <tm1/tmBoard.h>
#include <tmlib/tmtypes.h>
#include <tm1/tmProcessor.h>
#include <tm1/tmInterrupts.h>
#include <tm1/tmAO.h>
#include <tm1/tmAOmmio.h>
#include <tm1/tmAssert.h>
#include <tmlib/dprintf.h>
#include <tmlib/AppModel.h>
#include <tm1/tmGPIO.h>
#include <string.h>
#define AO_MAGIC 0x75289357
#define DBG 1
/*--------------------------------types--------------------------------------*/
typedef struct aoInstanceInfo_t {
UInt32 magic;
aoInstanceSetup_t setup;
Bool initialized;
unitSelect_t unitName;
boardAOConfig_t *boardAOConfig;
Int gpioInstance;
} aoInstVars_t, *paoInstVars_t;
typedef struct
{
UInt32 numberOfUnits;
aoCapabilities_t *unitCapabilities;
} aoCapabilitiesList_t;
/*-------------------------------statics-------------------------------------*/
static aoCapabilitiesList_t aoCaps =
{
0, /* numberOfUnits */
Null /* array of capabilities */
};
static tmLibdevErr_t prepareCapabilities(void);
/*------------------------------functions------------------------------------*/
/*****************************************************************************/
extern tmLibdevErr_t aoGetNumberOfUnits(UInt32 *pNumberOfUnits)
{
UInt32 i = 0;
boardAOConfig_t *dummyConfig;
tmAssert(pNumberOfUnits, TMLIBDEV_ERR_NULL_PARAMETER);
/* this code is not very fast, since it uses the different layers */
/* we can make it faster by directly accessing the registry, since*/
/* in this function, we do not need the contents of the registry */
/* but only the number of units */
/* one memcpy per call can be avoided */
while (tsaBoardGetAO(i, &dummyConfig) == TMLIBDEV_OK)
i++;
*pNumberOfUnits = i;
return TMLIBDEV_OK;
}
extern tmLibdevErr_t aoGetCapabilities(paoCapabilities_t *pCap)
{
return aoGetCapabilitiesM(pCap, unit0);
}
extern tmLibdevErr_t aoGetCapabilitiesM(paoCapabilities_t *pCap, unitSelect_t unitName)
{
tmLibdevErr_t err;
boardAOConfig_t *AOConfig;
tmAssert(pCap, TMLIBDEV_ERR_NULL_PARAMETER);
err = prepareCapabilities();
if (err != TMLIBDEV_OK)
return err;
if (unitName >= aoCaps.numberOfUnits)
return TMLIBDEV_ERR_NOT_AVAILABLE_IN_HW;
if (TMLIBDEV_OK != tsaBoardGetAO(unitName, &AOConfig))
{
/* this should never happen, since we have just checked the */
/* number of units */
/* FIXME : anyway, the error code should not be not supported */
return TMLIBDEV_ERR_NOT_AVAILABLE_IN_HW;
}
/* Update capabilities, prepareCapabilities() only writes initial values into this struct.
Some of the values can change (depending on the selected input). */
aoCaps.unitCapabilities[unitName].maxSRate = AOConfig->maxSRate;
aoCaps.unitCapabilities[unitName].minSRate = AOConfig->minSRate;
if ((AOConfig->codecName != Null))
{
strncpy(aoCaps.unitCapabilities[unitName].codecName, AOConfig->codecName, DEVICE_NAME_LENGTH);
}
*pCap = &aoCaps.unitCapabilities[unitName];
return TMLIBDEV_OK;
}
/* This code is only executed once. */
static tmLibdevErr_t prepareCapabilities(void)
{
UInt32 numberOfUnits, i;
boardAOConfig_t *AOConfig;
tmLibdevErr_t err = TMLIBDEV_OK;
AppModel_suspend_scheduling();
if (aoCaps.unitCapabilities == Null)
{
/* the number of units should not be contained in the board */
/* structure. Indeed, a developer might want to add a new unit */
/* without being able to modify the board config struct, since */
/* (s)he does not have access to the source */
if ((err= aoGetNumberOfUnits(&numberOfUnits)) != TMLIBDEV_OK)
goto prepareCapabilitiesExit;
if (numberOfUnits == 0)
{
err = TMLIBDEV_ERR_NOT_AVAILABLE_IN_HW;
goto prepareCapabilitiesExit;
}
aoCaps.numberOfUnits = numberOfUnits;
aoCaps.unitCapabilities = (paoCapabilities_t) malloc(aoCaps.numberOfUnits * sizeof(aoCapabilities_t));
if (aoCaps.unitCapabilities == Null)
{
err = TMLIBDEV_ERR_MEMALLOC_FAILED;
goto prepareCapabilitiesExit;
}
for (i = 0; i < aoCaps.numberOfUnits; i++)
{
if (TMLIBDEV_OK != tsaBoardGetAO(i, &AOConfig))
{
/* this should never happen, since we have just checked the */
/* number of units */
/* FIXME : anyway, the error code should not be not supported */
free(aoCaps.unitCapabilities);
aoCaps.unitCapabilities = Null;
err = TMLIBDEV_ERR_NOT_AVAILABLE_IN_HW;
goto prepareCapabilitiesExit;
}
aoCaps.unitCapabilities[i].version.majorVersion = MAJOR_VERSION;
aoCaps.unitCapabilities[i].version.minorVersion = MINOR_VERSION;
aoCaps.unitCapabilities[i].version.buildVersion = BUILD_VERSION;
aoCaps.unitCapabilities[i].numSupportedInstances = 1;
aoCaps.unitCapabilities[i].numCurrentInstances = 0;
aoCaps.unitCapabilities[i].audioTypeFormats = AOConfig->audioTypeFormats;
aoCaps.unitCapabilities[i].audioSubtypeFormats = AOConfig->audioSubtypeFormats;
aoCaps.unitCapabilities[i].audioAdapters = AOConfig->audioAdapters;
aoCaps.unitCapabilities[i].maxSRate = AOConfig->maxSRate;
aoCaps.unitCapabilities[i].minSRate = AOConfig->minSRate;
aoCaps.unitCapabilities[i].mmioBase = AOConfig->mmioBase;
aoCaps.unitCapabilities[i].intNumber = AOConfig->intNumber;
if (AOConfig->codecName != Null)
{
strncpy(aoCaps.unitCapabilities[i].codecName, AOConfig->codecName, DEVICE_NAME_LENGTH);
}
}
}
prepareCapabilitiesExit:
AppModel_resume_scheduling();
return err;
}
/**************************************************************************************/
extern tmLibdevErr_t aoOpen(Int * instance)
{
return aoOpenM(instance, unit0);
}
extern tmLibdevErr_t aoOpenM(Int * instance, unitSelect_t unitName)
{
gpioInstanceSetup_t gpioSetup;
tmLibdevErr_t rVal;
paoInstVars_t instVars;
boardAOConfig_t *aoBoardConfig;
UInt32 i;
printf("aoOpenM start\n");
tmAssert(instance != Null, TMLIBDEV_ERR_NULL_PARAMETER);
rVal = tsaBoardGetAO(unitName, &aoBoardConfig);
if (rVal != TMLIBDEV_OK)
return TMLIBDEV_ERR_NOT_AVAILABLE_IN_HW;
AppModel_suspend_scheduling();
/* make sure the capabilities are valid */
rVal = prepareCapabilities();
if (rVal != TMLIBDEV_OK)
goto aoOpenExit;
if (aoCaps.unitCapabilities[unitName].numCurrentInstances >=
aoCaps.unitCapabilities[unitName].numSupportedInstances)
{
rVal = TMLIBDEV_ERR_NO_MORE_INSTANCES;
goto aoOpenExit;
}
rVal = intOpen(aoBoardConfig->intNumber);
if (rVal != TMLIBDEV_OK)
{
goto aoOpenExit;
}
/* allocate and initialize instVars struct */
instVars = (paoInstVars_t) malloc(sizeof(aoInstVars_t));
if (instVars == Null)
{
rVal = TMLIBDEV_ERR_MEMALLOC_FAILED;
intClose(aoBoardConfig->intNumber);
goto aoOpenExit;
}
instVars->magic = AO_MAGIC;
instVars->unitName = unitName;
instVars->boardAOConfig = aoBoardConfig;
instVars->initialized = False;
instVars->gpioInstance = 0;
#if DBG
printf("gpio configue\n");
#endif
if (gpioOpen(&(instVars->gpioInstance)) == TMLIBDEV_OK)
{
/* Get the default instance setup */
gpioGetInstanceSetup(instVars->gpioInstance, &gpioSetup);
for (i = aoBoardConfig->gpioFirstPin; i <= aoBoardConfig->gpioLastPin; i++)
{
gpioInsertMode(gpioSetup.pinMode[i >> 4], i - (aoBoardConfig->gpioFirstPin & 0xfffffff0), gpioRegularMode);
gpioInsertPin(gpioSetup.pinMask[i >> 5], i - (aoBoardConfig->gpioFirstPin & 0xffffffe0), 1);
}
rVal = gpioInstanceSetup(instVars->gpioInstance, &gpioSetup);
if (rVal != TMLIBDEV_OK)
{
gpioClose(instVars->gpioInstance);
intClose(aoBoardConfig->intNumber);
free(instVars);
goto aoOpenExit;
}
}
*instance = (Int) instVars;
aoCaps.unitCapabilities[unitName].numCurrentInstances++;
aoOpenExit:
AppModel_resume_scheduling();
return rVal;
}
/**************************************************************************************/
extern tmLibdevErr_t aoInstanceSetup(Int instance, paoInstanceSetup_t pSetup)
{
paoInstVars_t instVars = (paoInstVars_t) instance;
tmLibdevErr_t rval = TMLIBDEV_OK;
boardAOParam_t param;
intInstanceSetup_t setup;
boardAOConfig_t *boardAOConfig = instVars->boardAOConfig;
UInt32 mmioBase = boardAOConfig->mmioBase;
printf("tmAO.c : aoInstancesetup\n");
tmAssert(instance, TMLIBDEV_ERR_NOT_OWNER);
tmAssert(pSetup, TMLIBDEV_ERR_NULL_PARAMETER);
tmAssert((pSetup->size % AO_SIZE_GRANULARITY) == 0, AIO_ERR_INVALID_SIZE);
tmAssert(((UInt) pSetup->base1 % AO_BASE_GRANULARITY) == 0, AIO_ERR_INVALID_BASE);
tmAssert(((UInt) pSetup->base2 % AO_BASE_GRANULARITY) == 0, AIO_ERR_INVALID_BASE);
if (instVars->magic != AO_MAGIC)
return TMLIBDEV_ERR_NOT_OWNER;
AppModel_suspend_scheduling();
param.audioTypeFormat = pSetup->audioTypeFormat;
param.audioSubtypeFormat = pSetup->audioSubtypeFormat;
param.sRate = pSetup->sRate;
param.size = pSetup->size;
param.output = pSetup->output;
if (!(param.audioTypeFormat & boardAOConfig->audioTypeFormats))
{
rval = AIO_ERR_UNSUPPORTED_DATA_TYPE;
goto aoInstanceSetupExit;
}
if (!(param.audioSubtypeFormat & boardAOConfig->audioSubtypeFormats))
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -