hwctxt.cpp

来自「i.mx27 soc for wince 6.0」· C++ 代码 · 共 1,746 行 · 第 1/4 页

CPP
1,746
字号

    m_Initialized = FALSE;

    DEBUGMSG(ZONE_FUNCTION,(_T("-HardwareContext::Deinit\n")));

    return TRUE;
}


//-----------------------------------------------------------------------------
//
//  Function:  MapDMABuffers
//
//  This function maps the DMA buffers used for audio input/output.
//
//  Parameters:
//      None.
//
//  Returns:
//      Returns TRUE if successful, otherwise returns FALSE.
//
//-----------------------------------------------------------------------------
BOOL HardwareContext::MapDMABuffers()
{
    PBYTE pVirtDMABufferAddr = NULL;

    DEBUGMSG(ZONE_FUNCTION,(_T("+HardwareContext::MapDMABuffers\n")));

    // Allocate a block of virtual memory (physically contiguous) for the
    // DMA buffers. Note that a platform-specific API call is used here to
    // allow for the DMA buffers to be allocated from different memory regions
    // (e.g., internal vs. external memory).
    pVirtDMABufferAddr = BSPAudioAllocDMABuffers(&g_PhysDMABufferAddr);

    if (pVirtDMABufferAddr == NULL)
    {
        RETAILMSG(TRUE, (TEXT("WAVEDEV.DLL:HardwareContext::MapDMABuffers() - ")
                         TEXT("Failed to allocate DMA buffer.\r\n")));
        return(FALSE);
    }

    // Setup the DMA page pointers.
    //
    // NOTE: Currently, input and output each have two DMA pages: these pages
    //       are used in a round-robin fashion so that the OS can read/write
    //       one buffer while the audio codec chip read/writes the other buffer.
    //
    m_Output_pbDMA_PAGES[0] = pVirtDMABufferAddr;
    m_Output_pbDMA_PAGES[1] = pVirtDMABufferAddr + AUDIO_DMA_PAGE_SIZE;
#ifdef AUDIO_RECORDING_ENABLED
    m_Input_pbDMA_PAGES[0]  = pVirtDMABufferAddr + (2 * AUDIO_DMA_PAGE_SIZE);
    m_Input_pbDMA_PAGES[1]  = pVirtDMABufferAddr + (3 * AUDIO_DMA_PAGE_SIZE);
#endif

    // Return physical addresses for TX and RX buffer
    m_DmaTxBuffer[0] = (UINT32)g_PhysDMABufferAddr.QuadPart;
    m_DmaTxBuffer[1] = (UINT32)g_PhysDMABufferAddr.QuadPart + AUDIO_DMA_PAGE_SIZE;

    #ifdef AUDIO_RECORDING_ENABLED
    m_DmaRxBuffer[0] = (UINT32)g_PhysDMABufferAddr.QuadPart + (2 * AUDIO_DMA_PAGE_SIZE);
    m_DmaRxBuffer[1] = (UINT32)g_PhysDMABufferAddr.QuadPart + (3 * AUDIO_DMA_PAGE_SIZE);
    #endif
    
    DEBUGMSG(ZONE_FUNCTION,(_T("-HardwareContext::MapDMABuffers\n")));

    return(TRUE);

}


//-----------------------------------------------------------------------------
//
//  Function:  UnmapDMABuffers
//
//  This function unmaps the DMA buffers previously mapped with the
//  MapDMABuffers function.
//
//  Parameters:
//      None.
//
//  Returns:
//      Returns TRUE if successful, otherwise returns FALSE.
//
//-----------------------------------------------------------------------------
BOOL HardwareContext::UnmapDMABuffers()
{
   DEBUGMSG(ZONE_FUNCTION,(_T("+HardwareContext::UnmapDMABuffers\n")));

    if (m_Output_pbDMA_PAGES[0])
    {
        BSPAudioDeallocDMABuffers((PVOID)(m_Output_pbDMA_PAGES[0]));
        m_Output_pbDMA_PAGES[0] = NULL;
        m_Output_pbDMA_PAGES[1] = NULL;
#ifdef AUDIO_RECORDING_ENABLED
        m_Input_pbDMA_PAGES[0]  = NULL;
        m_Input_pbDMA_PAGES[1]  = NULL;
#endif
    }

    DEBUGMSG(ZONE_FUNCTION,(_T("-HardwareContext::UnmapDMABuffers\n")));

    return TRUE;
}


//-----------------------------------------------------------------------------
//
//  Function:  SetOutputGain
//
//  Parameters:
//      DWORD dwGain - new gain level
//
//  Returns:
//      Returns MMSYSERR_NOERROR if successful, otherwise returns
//      MMSYSERR_ERROR.
//
//-----------------------------------------------------------------------------
MMRESULT HardwareContext::SetOutputGain (DWORD dwGain)
{
    DEBUGMSG(ZONE_FUNCTION,(_T("+HardwareContext::SetOutputGain\n")));

    BSPAudioSetOutputGain(AUDIO_BUS_STEREO_OUT, dwGain);
    m_dwOutputGain = dwGain;

    DEBUGMSG(ZONE_FUNCTION,(_T("-HardwareContext::SetOutputGain\n")));

    return MMSYSERR_NOERROR;
}


//-----------------------------------------------------------------------------
//
//  Function:  SetOutputMute
//
//  Parameters:
//      BOOL  fmute - TRUE / FALSE to indicate mute or no mute
//
//  Returns:
//      Returns MMSYSERR_NOERROR if successful, otherwise returns
//      MMSYSERR_ERROR.
//
//-----------------------------------------------------------------------------

MMRESULT HardwareContext::SetOutputMute (BOOL fMute)
{
    // TODO: Call down to PMIC driver for codec mute configuration
    
    // Save output mute configuration
    m_fOutputMute = fMute;

    return MMSYSERR_NOERROR;
}

//-----------------------------------------------------------------------------
//
//  Function:  GetOutputMute
//  This function gets the mute state.
//  Parameters:
//     None.
//
//  Returns:
//      m_fOutputMute	- Indicates the mute state.
//
//-----------------------------------------------------------------------------
BOOL HardwareContext::GetOutputMute (void)
{
    return m_fOutputMute;
}

//-----------------------------------------------------------------------------
//
//  Function:  GetOutputGain
//  This function gets the Output Gain state.
//  Parameters:
//     None.
//
//  Returns:
//      m_dwOutputGain	- Indicates the gain state.
//
//-----------------------------------------------------------------------------

DWORD HardwareContext::GetOutputGain (void)
{
    return m_dwOutputGain;
}

#ifdef AUDIO_RECORDING_ENABLED
//-----------------------------------------------------------------------------
//
//  Function:  GetInputMute
//  This function gets the mute state.
//  Parameters:
//     None.
//
//  Returns:
//      m_fInputMute	- Indicates the mute state.
//
//-----------------------------------------------------------------------------

BOOL HardwareContext::GetInputMute (void)
{
    return m_fInputMute;
}

//-----------------------------------------------------------------------------
//
//  Function:  SetInputMute
//
//  Parameters:
//      DWORD fmute - TRUE / FALSE to indicate mute or no mute
//
//  Returns:
//      Returns MMSYSERR_NOERROR if successful, otherwise returns
//      MMSYSERR_ERROR.
//
//----------------------------------------------------------------------------
MMRESULT HardwareContext::SetInputMute (BOOL fMute)
{
    // TODO: Call down to PMIC driver for codec mute configuration
    
    // Save input mute configuration
    m_fInputMute = fMute;
    
    return m_InputDeviceContext.SetGain(fMute ? 0: m_dwInputGain);
}

//-----------------------------------------------------------------------------
//
//  Function:  GetInputGain
//  This function gets the Input Gain state.
//  Parameters:
//     None.
//
//  Returns:
//      m_dwInputGain	- Indicates the gain state.
//
//-----------------------------------------------------------------------------
DWORD HardwareContext::GetInputGain (void)
{
    return m_dwInputGain;
}


//-----------------------------------------------------------------------------
//
//  Function:  SetInputGain
//
//
//  Parameters:
//      DWORD dwGain	- Set the gain values
//
//  Returns:
//      Returns TRUE if successful, otherwise returns FALSE.
//
//-----------------------------------------------------------------------------
MMRESULT HardwareContext::SetInputGain (DWORD dwGain)
{
    DEBUGMSG(ZONE_FUNCTION,(_T("+HardwareContext::SetInputGain\n")));

    BSPAudioSetInputGain(AUDIO_BUS_VOICE_IN, dwGain);

    m_dwInputGain = dwGain;

    DEBUGMSG(ZONE_FUNCTION,(_T("-HardwareContext::SetInputGain\n")));

    return MMSYSERR_NOERROR;
}

#endif // #ifdef AUDIO_RECORDING_ENABLED

//-----------------------------------------------------------------------------
//
//  Function:  InitOutputDMA
//
//  This function initializes the DMA channel for output.
//
//  Parameters:
//      None.
//
//  Returns:
//      Returns TRUE if successful, otherwise returns FALSE.
//
//-----------------------------------------------------------------------------
BOOL HardwareContext::InitOutputDMA()
{
    BOOL rc = FALSE;
    //TODO: Replace the DMAC_TRANSFER_SIZE with appropriate macro name
    //when changed in mx27_ddk.h    
    
    DEBUGMSG(ZONE_FUNCTION,(_T("+HardwareContext::InitOutputDMA\n")));

    // Confirm that DMA buffer has been allocated.
    if (!g_PhysDMABufferAddr.LowPart)
    {
        ERRORMSG(ZONE_ERROR, (_T("Invalid DMA buffer physical address.\r\n")));
        goto cleanUp;
    }

    // Configure the platform-specific output DMA channel
    if (!BSPAudioInitOutput(AUDIO_BUS_STEREO_OUT, m_DmaTxBuffer[0], AUDIO_DMA_PAGE_SIZE	))
    {
        ERRORMSG(ZONE_ERROR, (_T("BSPAudioInitOutput failed.\r\n")));
        goto cleanUp;
    }

    rc = TRUE;

cleanUp:
    if (!rc)
    {
        DeinitOutputDMA();
    }

    DEBUGMSG(ZONE_FUNCTION,(_T("-HardwareContext::InitOutputDMA\n")));

    return rc;
}


//-----------------------------------------------------------------------------
//
//  Function:  DeinitOutputDMA
//
//  This function deinitializes the DMA channel for output.
//
//  Parameters:
//      None.
//
//  Returns:
//      Returns TRUE if successful, otherwise returns FALSE.
//
//-----------------------------------------------------------------------------
BOOL HardwareContext::DeinitOutputDMA()
{    
    DEBUGMSG(ZONE_FUNCTION,(_T("+HardwareContext::DeinitOutputDMA\n")));

    // Stop the audio output devices
    BSPAudioStopOutput(AUDIO_BUS_STEREO_OUT, AUDIO_PATH_HEADSET);
    
    DDKDmacStopChan(m_OutputDMAChan);
    DDKDmacReleaseChan(m_OutputDMAChan);
    DDKDmacClearChannelIntr(m_OutputDMAChan);

    DEBUGMSG(ZONE_FUNCTION,(_T("-HardwareContext::DeinitOutputDMA\n")));

    return TRUE;
}


//------------------------------------------------------------------------------
//
//  FUNCTION:       InterruptClear
//
//  DESCRIPTION:    Clears the SSI interrupt status by doing a
//                  status register read followed by a erad/write to 
//                  the appropriate data fifo register
//
//  PARAMETERS:     
//                  dir - transfer dir
//                  ch - SSI channel
//
//  RETURNS:        
//                  NONE
//
//------------------------------------------------------------------------------
UINT32 HardwareContext::ClearInterruptStatus(SSI_TRANSFER_DIR dir, SSI_CHANNEL ch)
{
    PCSP_SSI_REG pStDACSSI = BSPAudioGetStDACSSI();
    UINT32 dummy;
    UINT32 sisr;
    UINT32 sfscr;
    UINT32 i;

    DEBUGMSG(1, (TEXT("SsiClass::ClearInterruptStatus+\r\n")));
    
    sisr = pStDACSSI->SISR;
    sfscr = pStDACSSI->SFCSR;
    DEBUGMSG(1, (TEXT("ClearInterruptStatus: SISR=0x%x\r\n"), sisr));

    if(ch == SSI_CHANNEL0)
    {
        if(dir == SSI_TRANSFER_TX)
        {

            if((sisr & CSP_BITFMASK(SSI_SISR_TFS)) != 0)
                for(i = 0; i < (8 - CSP_BITFEXT(sfscr, SSI_SFCSR_TFWM0)); i++)                    
                    pStDACSSI->STX0 = 0;
        }
        else
        {
            if((sisr & CSP_BITFMASK(SSI_SISR_RFS)) != 0)
                for(i = 0; i < (8 - CSP_BITFEXT(sfscr, SSI_SFCSR_RFWM0)); i++)
                    dummy = pStDACSSI->SRX0;
        }
    }
    else
    {
        if(dir == SSI_TRANSFER_TX)
        {
            if((sisr & CSP_BITFMASK(SSI_SISR_TFS)) != 0)
                for(i = 0; i < (8 - CSP_BITFEXT(sfscr, SSI_SFCSR_TFWM1)); i++)
                    pStDACSSI->STX1 = 0;
        }
        else
        {
            if((sisr & CSP_BITFMASK(SSI_SISR_RFS)) != 0)
                for(i = 0; i < (8 - CSP_BITFEXT(sfscr, SSI_SFCSR_RFWM1)); i++)
                    dummy = pStDACSSI->SRX1;
        }
    }

    DEBUGMSG(1, (TEXT("SsiClass::ClearInterruptStatus- sisr=0x%x\r\n"), sisr));

    return sisr;
    
}


/****** End of Online.wav ************/

//------------------------------------------------------------------------------
//
//  FUNCTION:       StartOutputDMA
//
//  DESCRIPTION:    Start playback DMA
//
//  PARAMETERS:     
//                  None
//
//  RETURNS:        
//                  TRUE
//
//------------------------------------------------------------------------------

BOOL HardwareContext::StartOutputDMA()
{
    DEBUGMSG(ZONE_FUNCTION, (TEXT("+StartOutputDMA\r\n")));    

⌨️ 快捷键说明

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