📄 bsphwctxt_for5620.cpp
字号:
//
// 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.
//
//------------------------------------------------------------------------------
//
// Copyright (C) 2004, Freescale Semiconductor, Inc. All Rights Reserved
// THIS SOURCE CODE IS CONFIDENTIAL AND PROPRIETARY AND MAY NOT
// BE USED OR DISTRIBUTED WITHOUT THE WRITTEN PERMISSION OF
// FREESCALE SEMICONDUCTOR, INC.
//
//------------------------------------------------------------------------------
//
// Copyright (C) 2005, MOTOROLA, INC. All Rights Reserved
// THIS SOURCE CODE IS CONFIDENTIAL AND PROPRIETARY AND MAY NOT
// BE USED OR DISTRIBUTED WITHOUT THE WRITTEN PERMISSION OF
// MOTOROLA, INC.
//
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
//
// Module: hwctxt.cpp
//
// Hardware context for audio driver. Contains code to support RT5620
// codecs. The audio driver uses DMA chaining with double buffering to
// remove SSI overruns/underruns.
//
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
// INCLUDE FILES
//------------------------------------------------------------------------------
#include "bsp.h"
#include "wavemain.h"
#include "audio.h"
#include <ceddk.h>
//------------------------------------------------------------------------------
// GLOBAL DEFINITIONS
//------------------------------------------------------------------------------
#if AC97
// Set 1 to use variable rate mode, default is fixed rate.
#define VRA 0
#endif
#ifndef AC97
#endif
//#define AUDIO_CH_OUT 2
//#define AUDIO_CH_IN 1
//-----------------------------------------------------------------------------
//
// Function: BSPAudioInit
//
// This function maps the peripheral registers of the audio devices for
// direct access by the driver.
//
// Parameters:
// None.
//
// Returns:
// Returns TRUE if successful, otherwise returns FALSE.
//
//-----------------------------------------------------------------------------
BOOL HardwareContext::BSPAudioInit()
{
UINT32 Irq;
#if AC97
BOOL VRAEn;
#endif
DEBUGMSG(ZONE_FUNCTION, (TEXT("+BSPAudioInit\r\n")));
// Call the OAL to translate the audio IRQ into a SYSINTR value.
//
Irq = BSP_WAVEDEV_TX_IRQ; // audio output DMA interrupt.
if (!KernelIoControl(IOCTL_HAL_REQUEST_SYSINTR, &Irq, sizeof(UINT32), &m_dwSysintrOutput, sizeof(UINT32), NULL))
{
ERRORMSG(TRUE, (TEXT("HardwareContext::Init: Failed to obtain sysintr value for output interrupt.\r\n")));
return FALSE;
}
Irq = BSP_WAVEDEV_RX_IRQ; // audio input DMA interrupt.
if (!KernelIoControl(IOCTL_HAL_REQUEST_SYSINTR, &Irq, sizeof(UINT32), &m_dwSysintrInput, sizeof(UINT32), NULL))
{
ERRORMSG(TRUE, (TEXT("HardwareContext::Init: Failed to obtain sysintr value for input interrupt.\r\n")));
return FALSE;
}
#if AC97
#if VRA
VRAEn = TRUE;
#else
VRAEn = FALSE;
#endif
// Init audio hardware
if(!audioHwInit(TRUE, // DMA enable
FALSE, // SSI interrupt disable
m_DmaTxBuffer[0], AUDIO_DMA_PAGE_SIZE,
m_DmaRxBuffer[0], AUDIO_DMA_PAGE_SIZE,
&m_DmaTxChannel, &m_DmaRxChannel, VRAEn))
{
DEBUGMSG(ZONE_ERROR, (TEXT("Audio HW init failed!\r\n")));
return FALSE;
}
#else
// Init audio hardware
if(!audioHwInit(TRUE, // DMA enable
FALSE, // SSI interrupt disable
m_DmaTxBuffer[0], AUDIO_DMA_PAGE_SIZE,
m_DmaRxBuffer[0], AUDIO_DMA_PAGE_SIZE,
&m_DmaTxChannel, &m_DmaRxChannel))
{
DEBUGMSG(ZONE_ERROR, (TEXT("Audio HW init failed!\r\n")));
return FALSE;
}
#endif
DEBUGMSG(ZONE_FUNCTION, (TEXT("-BSPAudioInit\r\n")));
return TRUE;
}
BOOL HardwareContext::BSPAudioDeinit()
{
DEBUGMSG(ZONE_FUNCTION, (TEXT("+BSPAudioDeinit\r\n")));
audioHwDeinit();
DEBUGMSG(ZONE_FUNCTION, (TEXT("-BSPAudioDeinit\r\n")));
return TRUE;
}
//------------------------------------------------------------------------------
//
// Function: BSPAudioInitCodec()
//
// Description: Initializes the audio codec chip.
//
// Notes: The audio codec chip is intialized for output mode
// but powered down. To conserve battery life, the chip
// is only powered up when the user starts playing a
// file.
//
// Specifically, the powerup/powerdown logic is done
// in the AudioMute() function. If either of the
// audio channels are unmuted, then the chip is powered
// up; otherwise the chip is powered own.
//
// Returns: Boolean indicating success
//
// ------------------------------------------------------------------------------
BOOL HardwareContext::BSPAudioInitCodec()
{
DEBUGMSG(ZONE_FUNCTION, (TEXT("+BSPAudioInitCodec\r\n")));
#if AC97
// Initialization for AC97 has been done in AudioHardwareinit
#else
g_Codec->InitRTCodecReg();
g_Codec->ChangeCodecPowerStatus(POWER_STATE_D2);
#endif
DEBUGMSG(ZONE_FUNCTION, (TEXT("-BSPAudioInitCodec\r\n")));
return TRUE;
}
//-----------------------------------------------------------------------------
//
// Function: BSPAudioStartOutput
//
// This function configures ssi to start audio playback.
//
// Parameters:
// [in] - enable SSI Transmit if TRUE
//
// Returns:
// TRUE for success
//
//-----------------------------------------------------------------------------
BOOL HardwareContext::BSPAudioStartOutput(BOOL enable)
{
DEBUGMSG(ZONE_FUNCTION, (TEXT("+BSPAudioStartOutput\r\n")));
g_Ssi->Transmit(enable);
DEBUGMSG(ZONE_FUNCTION, (TEXT("-BSPAudioStartOutput\r\n")));
return TRUE;
}
//-----------------------------------------------------------------------------
//
// Function: BSPAudioStartInput
//
// This function configures ssi to start audio record.
//
// Parameters:
// [in] - enable SSI receive if TRUE
//
// Returns:
// TRUE for success
//
//-----------------------------------------------------------------------------
BOOL HardwareContext::BSPAudioStartInput(BOOL enable)
{
DEBUGMSG(ZONE_FUNCTION, (TEXT("+BSPAudioStartInput\r\n")));
g_Ssi->Receive(enable);
DEBUGMSG(ZONE_FUNCTION, (TEXT("-BSPAudioStartInput\r\n")));
return TRUE;
}
//------------------------------------------------------------------------------
//
// FUNCTION: BSPAudioClearInterruptStatus
//
// 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:
// value of sisr
//
//------------------------------------------------------------------------------
UINT32 HardwareContext::BSPAudioClearInterruptStatus(SSI_TRANSFER_DIR dir, SSI_CHANNEL ch)
{
UINT32 ret;
DEBUGMSG(ZONE_FUNCTION, (TEXT("+BSPAudioClearInterruptStatus\r\n")));
ret = g_Ssi->ClearInterruptStatus(dir, ch);
DEBUGMSG(ZONE_FUNCTION, (TEXT("-BSPAudioClearInterruptStatus\r\n")));
return ret;
}
MMRESULT HardwareContext::BSPSetOutputGain (DWORD dwGain)
{
#if AC97
// m_dwOutputGain = dwGain & 0xffff; // save off so we can return this from GetGain - but only MONO
m_dwOutputGain = dwGain;
UINT32 ac97volL, ac97volR;
UINT32 volL = m_dwOutputGain & 0x0000FFFF ;
UINT32 volR = (m_dwOutputGain & 0xFFFF0000)>>16 ;
UINT16 usRegVal;
ac97volL = 0x1f -( volL*0x1f)/0xffff ;
ac97volR = 0x1f -( volR*0x1f)/0xffff ;
ac97volL = ac97volL << 8 ;
usRegVal = ac97volL | ac97volR ;
RETAILMSG(1, (TEXT("HardwareContext::SetOutputGain(%08x) => %04x\r\n"), m_dwOutputGain, usRegVal));
g_Codec->SetVol(usRegVal) ;
#else
m_dwOutputGain = dwGain;
if(dwGain==0)
{
g_Codec->AudioOutEnable(RT_WAVOUT_PATH_DAC,TRUE);
}
else
{
g_Codec->AudioOutEnable(RT_WAVOUT_PATH_DAC,FALSE);
}
g_Codec->SetAudioOutputGain(RT_WAVOUT_PATH_ALL,m_dwOutputGain);
#endif
return MMSYSERR_NOERROR;
}
MMRESULT HardwareContext::BSPSetOutputMute(BOOL fMute)
{
m_fOutputMute = fMute;
// Mute outputs
DEBUGMSG(ZONE_FUNCTION, (TEXT("+SetOutputMute\r\n")));
#if AC97
#else
// Mute lineout and headphone out.
g_Codec->AudioOutEnable(RT_WAVOUT_PATH_ALL,m_fOutputMute);
#endif
DEBUGMSG(ZONE_FUNCTION, (TEXT("+SetOutputMute\r\n")));
return MMSYSERR_NOERROR;
}
BOOL HardwareContext::BSPSetSwap(BOOL bSwap)
{
#if AC97
#else
// g_Codec->SetSwap(TRUE);
#endif
return TRUE;
}
BOOL HardwareContext::BSPSetSlotTag(DWORD Tag)
{
#if AC97
g_Ssi->SetAc97Tag(Tag);
#else
#endif
return TRUE;
}
//-----------------------------------------------------------------------------
//
// Function: BSPAudioSetPowerOnOff
//
// This function powers up or powers down the external audio chip,
// according to the third parameter.
//
// Parameters:
// [in] - bSetPlayback
// powers up or powers down the playback channel if TRUE
// [in] - bSetRecord
// powers up or powers down the record channel if TRUE
// [in] - bOff
// powers down if TRUE
// powers down if FALSE
//
// Returns:
// None.
//
//-----------------------------------------------------------------------------
void HardwareContext::BSPAudioSetPowerOnOff(BOOL bSetPlayback, BOOL bSetRecord, BOOL bOff)
{
audioSetPowerOnOff(bSetPlayback, bSetRecord, bOff);
}
DWORD HardwareContext::RT_AudioMessage(UINT uMsg,DWORD dwParam1,DWORD dwParam2)
{
if(g_Codec)
{
return g_Codec->ProcessAudioMessage(uMsg,dwParam1,dwParam2);
}
return(MMSYSERR_NOTSUPPORTED);
}
//-----------------------------------------------------------------------------
//
// Function: BSPAudioGetSampleRate
//
// This function gets the hardware sample rate of the codec
//
// Parameters:
// None.
//
// Returns:
// The hardware sample rate of the codec
//
//-----------------------------------------------------------------------------
UINT64 BSPAudioGetSampleRate( void )
{
return CODECSAMPLERATE;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -