hwctxt.h

来自「i.mx27 soc for wince 6.0」· C头文件 代码 · 共 472 行 · 第 1/2 页

H
472
字号
//
// Copyright (c) Microsoft Corporation.  All rights reserved.
//
//
// Use of this source code is subject to the terms of the Microsoft end-user
// license agreement (EULA) under which you licensed this SOFTWARE PRODUCT.
// If you did not accept the terms of the EULA, you are not authorized to use
// this source code. For a copy of the EULA, please see the LICENSE.RTF on your
// install media.
//
#pragma once
//
//
//
// Use of this source code is subject to the terms of the Microsoft end-user
// license agreement (EULA) under which you licensed this SOFTWARE PRODUCT.
// If you did not accept the terms of the EULA, you are not authorized to use
// this source code. For a copy of the EULA, please see the LICENSE.RTF on your
// install media.
//
/*++
THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
PARTICULAR PURPOSE.

   
Module Name:    HWCTXT.H

Abstract:       Platform dependent code for the mixing audio driver.
  
Environment:    Freescale Power Management ICs with WinCE 5.0 or later.
    
-*/
//------------------------------------------------------------------------------
//
//  Copyright (C) 2005-2006, Freescale Semiconductor, Inc. All Rights Reserved.
//  THIS SOURCE CODE, AND ITS USE AND DISTRIBUTION, IS SUBJECT TO THE TERMS
//  AND CONDITIONS OF THE APPLICABLE LICENSE AGREEMENT 
//
//------------------------------------------------------------------------------

#include "csp.h"
#include <ceddk.h> // Needed for typedef of PHYSICAL_ADDRESS

//-----------------------------------------------------------------------------
// Defines for audio hardware capabilities.

// Select whether audio recording will be supported. Comment out the following
// to remove support for audio recording. This will also reduce the code size
// for the audio driver and the number of DMA buffers that are allocated.
#ifndef AUDIO_RECORDING_ENABLED
#define AUDIO_RECORDING_ENABLED
#endif


#ifdef AUDIO_RECORDING_ENABLED

#define INCHANNELS    (1)    // PMIC Voice CODEC has one input channel.
                             // (TODO: MC13783 has option of using two input
                             // channels.)
#else

#define INCHANNELS    (0)    // Audio recording capability has been disabled.

#endif // #ifdef AUDIO_RECORDING_ENABLED

#define OUTCHANNELS   (2)    // PMIC Stereo DAC has two output channels.
#define BITSPERSAMPLE (16)    // Voice CODEC and Stereo DAC uses 16 bits/sample

#define INSAMPLERATE  (16000)    // Voice CODEC input at 16 kHz.
#define OUTSAMPLERATE (44100)    // Stereo DAC output at 44.1 kHz.

// Inverse sample rate, in .32 fixed format, with 1 added at bottom to ensure
// round up.
#define INVSAMPLERATE ((UINT32)(((1i64<<32)/OUTSAMPLERATE)+1))

// Define the size of each audio data word. The valid choices are:
//
//     INT8    for 8 bits/word
//     INT16   for 16 bits/word
//     INT32   for 24 bits/word
//
// The correct value to use depends upon the audio CODEC hardware. Note that
// the SSI hardware only supports a maximum of 24 bits/word.
//
// The required definition for the MC13783 and SC5512 PMICs is INT16.
//
// The word size that is defined here is also used to set the corresponding
// SDMA and SSI transfer sizes.
//
typedef INT16 HWSAMPLE;

// Set USE_MIX_SATURATE to 1 if you want the mixing code to guard against
// saturation. This costs a couple of extra instructions in the inner
// signal resampling/mixing loop.
#define USE_MIX_SATURATE    (1)

// The code will use the follwing values as saturation points. These values
// should match the word size defined for HWSAMPLE above.
#define AUDIO_SAMPLE_MAX    (32767)
#define AUDIO_SAMPLE_MIN    (-32768)

// Size in bytes of each DMA buffer. We allocate 2 DMA buffers each for audio
// playback and recording.
#define AUDIO_DMA_PAGE_SIZE     6144 // Default 4096 bytes.

//----- Used to track DMA controllers status -----
#define DMA_CLEAR           0x00000000
#define DMA_DONEA           0x00000002
#define DMA_DONEB           0x00000004
#define DMA_STOP            0x00000010 // Stop DMA after buffers exhausted

//----- Used for scheduling DMA transfers -----
#define  OUT_BUFFER_A       0                            
#define  OUT_BUFFER_B       1

#define  IN_BUFFER_A        0
#define  IN_BUFFER_B        1

#define AUDIO_REGKEY_PREFIX TEXT("Drivers\\BuiltIn\\Audio\\PMIC\\Config")

// AUDMUX class port configuration
typedef struct {
    BOOL            txFsInput;      // TRUE if port is connected to transmit frame sync source
    BOOL            txClkInput;     // TRUE if port provides transmit clock
    AUDMUX_PORT_ID  txFsClkSrcPort; // port ID of clock source port if clock not provided by port
    BOOL            txFsClkFromRx;  // TRUE if tx clock to be sourced from RX clock
    BOOL            rxFsInput;      // TRUE if port is connected to transmit source
    BOOL            rxClkInput;     // TRUE if port provides transmit clock
    AUDMUX_PORT_ID  rxFsClkSrcPort; // Port ID of clock source port if clock not provided by port
    BOOL            rxFsClkFromRx;  // TRUE if tx clock to be sourced from RX clock
    AUDMUX_PORT_ID  rxDataSrcPort;  // PORT ID of data port if not connected directly to source
    BOOL            syncModeEn;     // TRUE to enable SYNC mode
    BOOL            txRxSwitchEn;   // TRUE to enable TX/RX pin swap on port3 only
    BOOL            intNetworkEn;   // TRUE to enable internal network mode
} AUDMUX_PORT_CONFIG, *PAUDMUX_PORT_CONFIG;

class HardwareContext
{
public:
    static BOOL CreateHWContext(DWORD Index);
    HardwareContext();
    ~HardwareContext();

    void Lock()   {EnterCriticalSection(&m_Lock);}
    void Unlock() {LeaveCriticalSection(&m_Lock);}

    DWORD GetNumInputDevices()
    {
#ifdef AUDIO_RECORDING_ENABLED
        return 1;
#else
        return 0;
#endif
    }
    DWORD GetNumOutputDevices() {return 1;}
    DWORD GetNumMixerDevices()  {return 1;}

    DeviceContext *GetInputDeviceContext(UINT DeviceId)
    {
     UNREFERENCED_PARAMETER(DeviceId);
#ifdef AUDIO_RECORDING_ENABLED
        return &m_InputDeviceContext;
#else
        return NULL;
#endif
    }
    DeviceContext *GetOutputDeviceContext(UINT DeviceId)
    {
     UNREFERENCED_PARAMETER(DeviceId);
        return &m_OutputDeviceContext;
    }

    BOOL Init(DWORD Index);                                        
    BOOL Deinit();

    void PowerUp();
    void PowerDown();	
    BOOL        StartOutputDMA();
    void        StopOutputDMA();
    DWORD       GetOutputGain (void);
    MMRESULT    SetOutputGain (DWORD dwVolume);
    BOOL        GetOutputMute (void);
    MMRESULT    SetOutputMute (BOOL fMute);

#ifdef AUDIO_RECORDING_ENABLED

    BOOL        StartInputDMA();
    void        StopInputDMA();
    DWORD       GetInputGain (void);
    MMRESULT    SetInputGain (DWORD dwVolume);
    BOOL        GetInputMute (void);
    MMRESULT    SetInputMute (BOOL fMute);

#endif // #ifdef AUDIO_RECORDING_ENABLED

    void InterruptThread();

    void DisableDelayThread();

    UINT32 ClearInterruptStatus(SSI_TRANSFER_DIR dir, SSI_CHANNEL ch);

protected:
    typedef enum {
        AUDIO_BUS_STEREO_OUT,
        AUDIO_BUS_VOICE_IN
    } AUDIO_BUS;

    typedef enum {
        AUDIO_PATH_EARPIECE,
        AUDIO_PATH_SPEAKER,
        AUDIO_PATH_HEADSET,
        AUDIO_PATH_LINEOUT,
        AUDIO_PATH_LINEIN,
        AUDIO_PATH_MIC
    } AUDIO_PATH;

    typedef enum {
        AUDIO_PWR_STATE_OFF,
        AUDIO_PWR_STATE_STANDBY,
        AUDIO_PWR_STATE_ON
    } AUDIO_PWR_STATE;

    typedef enum {
        PORT1 = 0,
        PORT2 = 1,
        PORT3 = 2,
    } AUDMUX_INTERNAL_PORT;

    typedef enum {
        PORT4 = 0,
        PORT5 = 1,
        PORT6 = 2,
    } AUDMUX_EXTERNAL_PORT;	

⌨️ 快捷键说明

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