hwctxt.h

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

H
472
字号
    // Define the timed delay interval that will be used between the completion
    // of an audio I/O operation and the disabling of the audio CODEC hardware.
    // On some hardware platforms, enabling the audio CODEC hardware can require
    // a significant ramp-up time (up to 150 ms in the case of the MC13783 PMIC).
    // Therefore, when back-to-back audio I/O operations are performed, it is
    // best to just leave the audio CODEC hardware enabled in between the two
    // audio streams.
    //
    // The delay interval that is defined here will be used to determine how
    // long after an audio stream has been completed before the audio CODEC
    // hardware is actually disabled. If another audio stream operation is
    // started, before the interval has expired, then the timeout is simply
    // cancelled and the audio CODEC will not need to be reenabled for the
    // second audio stream.
    //
    // For the MC13783 PMIC, a delay of 1 sec is recommended since that should
    // give enough time to perform back-to-back audio I/O operations. We don't
    // want the delay interval to be too long, however, or else we end up
    // wasting power by keeping the audio CODEC enabled when it is not being
    // used.
    //
    // Making the delay interval shorter than 1 sec is also not recommended
    // since that can cause the audio CODEC to be disabled just before another
    // audio stream is processed. This would eliminate any benefit of having
    // this delayed CODEC disable feature.
    //
    // Note that for audio CODECs that don't have any noticeable ramp-up or
    // enable delay period, a timer value of 0 is allowed. Setting the timer
    // delay interval to 0 will immediately disable the audio CODEC upon the
    // completion of each audio stream I/O operation.

    static const PLAYBACK_DISABLE_DELAY_MSEC = 1000; // Default 1000

#ifdef AUDIO_RECORDING_EANBLED

    static const RECORD_DISABLE_DELAY_MSEC   = 1000; // Default 1000

#else

    static const RECORD_DISABLE_DELAY_MSEC   = 0;    // Must be zero if audio
                                                     // recording is disabled.
#endif // #ifdef AUDIO_RECORDING_ENABLED

    DWORD m_dwDriverIndex;
    CRITICAL_SECTION m_Lock;

    BOOL m_Initialized;

    static const int NUM_DMA_BUFFERS = 2; // For DMA transfers to/from the
                                          // audio hardware we need to allocate
                                          // 2 buffers and we just alternate
                                          // between them. Note that we allocate
                                          // separate pairs of DMA buffers for
                                          // output/playback and for
                                          // input/recording.

    static const int INTR_PRIORITY = 249; // Default interrupt thread priority.
    static const unsigned short INTR_PRIORITY_REGKEY[12];

    OutputDeviceContext m_OutputDeviceContext;
   
    DWORD m_dwOutputGain;
    BOOL  m_fOutputMute;

    // Track how many data bytes in each input/output buffers
    ULONG m_OutBytes[2];
    ULONG m_InBytes[2];
	
    UINT32          m_DmaTxBuffer[2];
    UINT32          m_DmaRxBuffer[2];

    UINT8           m_TxBufIndex;
    
    PBYTE m_Output_pbDMA_PAGES[NUM_DMA_BUFFERS];
    BOOL  m_OutputDMARunning;
    WORD  m_nOutputVolume;                   // Current HW Playback Volume.
                                             // Volume.

#ifdef AUDIO_RECORDING_ENABLED
    UINT8 m_RxBufIndex;
    InputDeviceContext m_InputDeviceContext;

    DWORD m_dwInputGain;
    BOOL  m_fInputMute;

    PBYTE m_Input_pbDMA_PAGES[NUM_DMA_BUFFERS];
    BOOL  m_InputDMARunning;
    WORD  m_nInputVolume;                    // Current HW Input (Microphone)
 
    // Declare 2 timer IDs (one for playback and another one for recording)
    // that will be used to control the timed delay when disabling the audio
    // hardware. This allows for better performance when back-to-back audio
    // operations are performed.
    MMRESULT m_AudioDelayDisableTimerID[2];
    HANDLE   m_hAudioDelayDisableEvent[2];

#else

    // Declare 1 timer ID (for playback only) that will be used to control the
    // timed delay when disabling the audio hardware. This allows for better
    // performance when back-to-back audio operations are performed.
    MMRESULT m_AudioDelayDisableTimerID[1];
    HANDLE   m_hAudioDelayDisableEvent[1];

#endif // #ifdef AUDIO_RECORDING_ENABLED

    BOOL m_audioPowerdown;  // Flag to indicate if PowerDown() has been called.

    BOOL InitInterruptThread();

    BOOL InitOutputDMA();
    BOOL DeinitOutputDMA();
    
    UINT32 TransferOutputBuffer(UINT8 bufIndex);
    UINT32 TransferOutputBuffers(void);

#ifdef AUDIO_RECORDING_ENABLED

    BOOL  InitInputDMA();
    BOOL  DeinitInputDMA();
    UINT32 TransferInputBuffers(void);
    UINT32 TransferInputBuffer(UINT8 bufIndex);

#endif // #ifdef AUDIO_RECORDING_ENABLED
    
    BOOL MapRegisters();
    BOOL UnmapRegisters();
    BOOL MapDMABuffers();
    BOOL UnmapDMABuffers();

    DWORD GetInterruptThreadPriority();

    DWORD m_dwSysintrOutput;
    DWORD m_dwSysintrInput;
    
    HANDLE m_hAudioInterrupt;                // Handle to Audio Interrupt event.
    HANDLE m_hAudioInterruptThread;          // Handle to thread which waits on
                                             // an audio interrupt event.

    HANDLE m_hAudioDelayedDisableThread;     // Handle for thread that will
                                             // process all timeout events from
                                             // the CODEC delayed disable timer.

    //-------------------- Platform specific members ---------------------------

    volatile DWORD  m_dwOutputDMAStatus;       // Output DMA channel's status
    UINT8  m_OutputDMAChan;                  // Ouput DMA virtual channel index

#ifdef AUDIO_RECORDING_ENABLED

    volatile DWORD  m_dwInputDMAStatus;        // Input DMA channel's status
    UINT8  m_InputDMAChan;                   // Input DMA virtual channel index

#endif

    AUDIO_PWR_STATE m_CodecPwrState;
                                                    
    PCSP_SSI_REG m_pSSI1;
    DWORD m_dwSysintrSSI1;
    PCSP_SSI_REG m_pSSI2;
    DWORD m_dwSysintrSSI2;

    PCSP_AUDMUX_REG m_pAUDMUX;
    

    //------------------- Board Support Package Interface ----------------------

    BOOL BSPAudioInit();
    BOOL BSPAudioDeinit();

    PBYTE BSPAudioAllocDMABuffers(PHYSICAL_ADDRESS *pPhysicalAddress);
    void BSPAudioDeallocDMABuffers(PVOID virtualAddress);

    void BSPAudioInitCodec(AUDIO_BUS bus);
    void BSPAudioSetCodecPower(AUDIO_PWR_STATE state);
    
    void BSPAudioPowerUp(const BOOL fullPowerUp);
    void BSPAudioPowerDown(const BOOL fullPowerOff);

    void BSPAudioInitSsi(AUDIO_BUS bus, PCSP_SSI_REG pSSI);

    void BSPAudioRoute(void);
    PCSP_SSI_REG BSPAudioGetStDACSSI();
    void HardwareContext::BSPSSIShowReg(CSP_SSI_REG *pSSI);	
    void HardwareContext::BSPAUDMUXShowReg(PCSP_AUDMUX_REG pAUD);
    void HardwareContext::SetPortConfig(AUDMUX_PORT_ID port, AUDMUX_PORT_CONFIG *config);
    UINT32 BSPGetSsiFifoPhyAddr(SSI_TRANSFER_DIR dir, SSI_CHANNEL ch, CSP_SSI_REG *SsiSrc);	
    BOOL BSPAudioInitOutput(AUDIO_BUS bus, UINT32 txBuffer, UINT32 txBufferSize);

   BOOL BSPAudioStartOutput(AUDIO_BUS bus, AUDIO_PATH path);
    BOOL BSPAudioStopOutput(AUDIO_BUS bus, AUDIO_PATH path);
    BOOL BSPAudioSetOutputGain(AUDIO_BUS bus, const DWORD dwGain);



    void BSPAudioStartSsiOutput(PCSP_SSI_REG pSSI);
                                

    void BSPAudioStopSsiOutput(PCSP_SSI_REG pSSI);

    void BSPAudioStartCodecOutput(AUDIO_BUS bus, AUDIO_PATH path);
    void BSPAudioStopCodecOutput(AUDIO_BUS bus, AUDIO_PATH path);

#ifdef AUDIO_RECORDING_ENABLED

    PCSP_SSI_REG BSPAudioGetVCodecSSI();
    
    BOOL BSPAudioInitInput(AUDIO_BUS bus, UINT32	rxBuffer,
                    									UINT32	rxBufferSize);
    BOOL BSPAudioStartInput(AUDIO_BUS bus, AUDIO_PATH path);
    BOOL BSPAudioStopInput(AUDIO_BUS bus, AUDIO_PATH path);
    BOOL BSPAudioSetInputGain(AUDIO_BUS bus, const DWORD dwGain);

    void BSPAudioStartSsiInput(PCSP_SSI_REG pSSI);
    void BSPAudioStopSsiInput(PCSP_SSI_REG pSSI);

    void BSPAudioStartCodecInput(AUDIO_BUS bus, AUDIO_PATH path);
    void BSPAudioStopCodecInput(AUDIO_BUS bus, AUDIO_PATH path);

#endif // #ifdef AUDIO_RECORDING_ENABLED

};

    
void SetPortConfig(AUDMUX_PORT_ID port, AUDMUX_PORT_CONFIG *config);
BOOL SetIntNetworkMode(AUDMUX_PORT_ID port, BOOL enable, UINT8 portmask);
   


extern DWORD CALLBACK CallInterruptThread(HardwareContext *pHWContext);
extern DWORD CALLBACK BSPAudioDisableDelayHandler(HardwareContext *pHWContext);

//--------------------------------- Externs ------------------------------------

extern HardwareContext *g_pHWContext;

⌨️ 快捷键说明

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