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

📄 audio.h

📁 windows ce 下ARM9音频驱动代码
💻 H
字号:
/*++
Copyright (c) 2001, 2002 BSQUARE Corporation.  All rights reserved.

Module Name:

    Audio.h

Module Description:

    This module is the main include file that is used by all source files
    for the platform wave device driver.

Author:

    Benny Ng    25-june-2001

Revision History:

    Yuqun Cao   16-Jan-2002

        1. Add critical section protection in WaveProc(). It is called from
           different threads. The MDD layer does not synchronize the access.
        2. Add mapping to the APB clock control registers.

--*/

#ifndef __AUDIO_H__
#define __AUDIO_H__

#include <platform.h>
#include <waveddsi.h>
#include <mmreg.h>

#include <bceddk.h>
#include <chip.h>

#define DIR_STR(x) \
    (((x) == WAPI_IN) ? TEXT("WAPI_IN") : TEXT("WAPI_OUT"))

//
// Macro for converting 8 bit samples to 16 bit samples.  Note
// that 8-bit samples are signed while 16-bit samples are unsigned.
//

#define BITS_8_TO_16(x)        (((SHORT)((UCHAR)(x) - 128)) << 8)

//
// Size of each DMA buffer.
//

#define DMA_BUFFER_SIZE             1024*2

//
// Number of 16-bit samples per DMA buffer.
//

#define DMA_SAMPLES_PER_BUFFER      (DMA_BUFFER_SIZE / 2)

//
// BYTES_PER_SAMPLE is the number of bytes per sample of the UDA1341TS.  The
// codec is 16-bit stereo, meaning there are two bytes for the left and right
// channel for each sample, for a total of four bytes per sample.
//

#define BYTES_PER_SAMPLE 4

//
// MAX_VOLUME is the maximum possible setting for volume.
//

#define MAX_VOLUME 0xFFFF

//
// This event is declared in the MDD.  The IST waits on the event.
//

extern HANDLE hAudioInterrupt;

//
// The CODEC_DEVICE structure holds information particular to the codec.
//

typedef struct _CODEC_DEVICE {

    ULONG   Volume;

    APB_AAC_REGS*      AacRegPtr;      // Pointer to AAC registers.

} CODEC_DEVICE, *PCODEC_DEVICE;

//
// The WAVE_DEVICE_INSTANCE structure holds information about the wave device,
// such as the SSP registers, what DMA channels to use, etc.
//

typedef struct _WAVE_DEVICE {

    APB_CLK_STATE_CTL_REGS*
                        ABPClkCtrlRegPrt;         // Pointer to APB clock control registers

    APB_AAC_REGS*       AacRegPtr;                // Pointer to AAC registers.

    AHB_DMA_CTL_REGS*   AHBDmaCtrlRegPtr;         // Pointer to AHB DMA registers (base).

    DMA_CHANNEL_REG*    DmaCtrlInput;             // Pointer to Input  DMA channel
    DMA_CHANNEL_REG*    DmaCtrlOutput;            // Pointer to Output DMA channel

    ULONG               DmaBufferSize;            // Size in bytes of a
                                                  //   single DMA buffer
                                                  //   (2/channel).

    PULONG              DmaBuffersBase;           // Virtual base for memory
                                                  //   used for DMA buffers.

    PMDL                DmaBuffersMdl;            // MDL for the DMA buffers.

    ULONG               DmaChannelInput;          // DMA channel number for
    ULONG               DmaChannelOutput;         //   input and output.

    PADAPTER_OBJECT     AdapterObjectInput;       // DMA adapter object for
    PADAPTER_OBJECT     AdapterObjectOutput;      //   input and output.

    PVOID               MapRegsBaseInput;         // DMA map registers base
    PVOID               MapRegsBaseOutput;        //   for input and output.

    ULONG               SysIntrInput;             // SYSINTR for input and
    ULONG               SysIntrOutput;            //   output DMA.

    PCODEC_DEVICE       CodecDevice;              // Codec device specific
                                                  //   information.

    BOOLEAN             SysIntrInputInitialized;  // Result of call to
    BOOLEAN             SysIntrOutputInitialized; //   InterruptInitialize
                                                  //   for intput and output.

    CRITICAL_SECTION    Cs;                       // Protect PDD_WaveProc

} WAVE_DEVICE_INSTANCE, *PWAVE_DEVICE_INSTANCE;

//
// The WAVE_RESOURCE structure stores parameters and resources for a
// particular wave stream.  It is used for both input and output.
//

typedef struct _WAVE_STREAM_RESOURCES {

    ULONG               SysIntr;

    ULONG               DmaBufferSize;

    PADAPTER_OBJECT     AdapterObject;

    PVOID               MapRegsBase;

    PMDL                DmaBufferMdl;

    ULONG               StartBuffer;

    PHYSICAL_ADDRESS    BufferAPhysAddr;

    PULONG              DmaBufferA;

    ULONG               DmaBufferABytes;

    PHYSICAL_ADDRESS    BufferBPhysAddr;

    PULONG              DmaBufferB;

    ULONG               DmaBufferBBytes;

    ULONG               NextDMABuf;

    APB_CLK_STATE_CTL_REGS*
                        ABPClkCtrlRegPrt;  // Pointer to APB clock control registers
    APB_AAC_REGS*       AacRegPtr;         // Pointer to AAC registers.
    AHB_DMA_CTL_REGS*   AHBDmaCtrlRegPtr;  // Pointer to AHB DMA registers (base).
    DMA_CHANNEL_REG*    DmaRegPtr;         // Pointer to DMA channel registers.

    LONG                InUse;          // TRUE if actively recording/playing;
                                        //   FALSE otherwise.

    PWAVEHDR            WaveHeader;     // Header of current wave buffer.

    WAVEFORMATEX        WaveFormat;     // Stream format information.

    WAPI_INOUT          WaveDirection;  // Input (record) or output (play).

    BOOLEAN             MoreData;       // TRUE if there is more data to play/
                                        //   record; FALSE otherwise.

} WAVE_RESOURCE, *PWAVE_RESOURCE;

extern
BOOLEAN
CodecInitialize(
    IN OUT PWAVE_DEVICE_INSTANCE WaveInstance
    );

extern
BOOLEAN
CodecSetVolume(
    IN OUT PCODEC_DEVICE CodecDevice,
    IN ULONG Volume
    );

extern
ULONG
CodecGetVolume(
    IN PCODEC_DEVICE CodecDevice
    );

//
// Prototypes for functions from waveout.c.
//

extern
MMRESULT
GetOutputVolume(
    IN PWAVE_DEVICE_INSTANCE WaveInstance,
    OUT PULONG VolumeSetting
    );

extern
MMRESULT
SetOutputVolume(
    IN PWAVE_DEVICE_INSTANCE WaveInstance,
    IN ULONG VolumeSetting
    );

extern
VOID
WaveOutStart(
    IN OUT PWAVE_RESOURCE WaveResource,
    IN OUT PWAVEHDR WaveHeader
    );

extern
VOID
WaveOutContinue (
    IN OUT PWAVE_RESOURCE WaveResource,
    IN OUT PWAVEHDR WaveHeader
    );

extern
VOID
WaveOutEndOfData(
    IN OUT PWAVE_RESOURCE WaveResource
    );

//
// Prototypes for functions from wavein.c.
//

extern
VOID
WaveInStart(
    IN OUT PWAVE_RESOURCE WaveResource,
    IN OUT PWAVE_RESOURCE WaveOutResource,
    IN OUT PWAVEHDR WaveHeader
    );

extern
VOID
WaveInContinue (
    IN OUT PWAVE_RESOURCE WaveResource,
    IN OUT PWAVE_RESOURCE WaveOutResource,
    IN OUT PWAVEHDR WaveHeader
    );

extern
VOID
WaveInStop(
    IN OUT PWAVE_RESOURCE WaveResource,
    IN OUT PWAVE_RESOURCE WaveOutResource
    );

//
// Prototypes for functions from waveutil.c.
//

extern
PULONG
GetNextDmaBuffer(
    IN PWAVE_RESOURCE WaveResource
    );

extern
VOID
NextDmaBuffer(
    IN PWAVE_RESOURCE WaveResource
    );

extern
VOID
SetBufferSize(
    IN PWAVE_RESOURCE WaveResource,
    IN PULONG Buffer,
    IN ULONG NumBytes
    );

extern
ULONG
GetBufferSize(
    IN PWAVE_RESOURCE WaveResource,
    IN PULONG Buffer,
    IN ULONG NumBytes
    );

extern
VOID
InitiateDma(
    IN PWAVE_RESOURCE WaveResource
    );

extern
VOID
ShutdownDma(
    IN PWAVE_RESOURCE WaveResource
    );

extern
VOID
StartDmaOut(
    IN PWAVE_RESOURCE WaveResource
    );

extern
VOID
StartDmaIn(
    IN PWAVE_RESOURCE WaveResource
    );

extern
VOID
StopDma(
    IN PWAVE_RESOURCE WaveResource
    );

extern
VOID
ClearDmaStatus(
    IN PWAVE_RESOURCE WaveResource
    );

extern
VOID
WaitForDmaComplete(
    IN PWAVE_RESOURCE WaveResource
    );

extern
VOID
MapTransfer(
    IN BOOLEAN Start,
    IN PWAVE_RESOURCE WaveResource,
    IN PULONG Buffer
    );

#endif // __AUDIO_H__

⌨️ 快捷键说明

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