📄 hwctxt.cpp
字号:
SELECT_AUDIO_DMA_INPUT_BUFFER_A();
Codec_channel(); // Turn On Input channel
//v_pDMAregs->DMASKTRIG2 |= ENABLE_DMA_CHANNEL;
AUDIO_IN_DMA_ENABLE();
#if DMA_FLAG
// wait for DMA to start.
delay_count = 0;
while((v_pDMAregs->DSTAT2&0xfffff)==0){
#if WAIT_DMA_END
Sleep(1);
#else
if( delay_count++ > DELAY_COUNT ) break;
#endif
}
// change the buffer pointer
SELECT_AUDIO_DMA_INPUT_BUFFER_B();
#endif
}
DEBUGMSG(ZONE_FUNCTION,(TEXT("---StartInputDMA\n")));
RETAILMSG(AC97_DEBUG1,(TEXT("---StartInputDMA 0x%X\n"),v_pAC97regs->AC_GLBCTRL));
return(TRUE);
START_ERROR:
return(FALSE);
}
/*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Function: StopInputDMA()
Description: Stops any DMA activity on the input channel.
Notes: ***** NOT IMPLEMENTED *****
The following routine is not implemented due to a
hardware bug in the revision of the Samsung SC2450
CPU this driver was developed on. See the header
at the top of this file for details.
Returns: Boolean indicating success
-------------------------------------------------------------------*/
void HardwareContext::StopInputDMA()
{
//----- 1. If the output DMA is running, stop it -----
RETAILMSG(AC97_DEBUG1,(TEXT("+++StopInputDMA\n")));
if (m_InputDMARunning)
{
AUDIO_IN_DMA_DISABLE(); // jylee
AUDIO_IN_CLEAR_INTERRUPTS();
m_InputDMAStatus = DMA_CLEAR;
// Kingfish2 AC97
#if AC97_RECORD_MICIN
v_pAC97regs->AC_GLBCTRL = (v_pAC97regs->AC_GLBCTRL & ~(0x3<<8)) | (0x0<<8); // 0x0 = DMA OFF
#else
v_pAC97regs->AC_GLBCTRL = (v_pAC97regs->AC_GLBCTRL & ~(0x3<<10)) | (0x0<<10); // 0x0 = DMA OFF
#endif
#if (BSP_TYPE == BSP_SMDK2443)
AudioMute(DMA_CH_MIC, TRUE);
#elif (BSP_TYPE == BSP_SMDK2450)
#endif
}
m_InputDMARunning = FALSE;
#if (BSP_TYPE == BSP_SMDK2443)
#elif (BSP_TYPE == BSP_SMDK2450)
AudioMute(DMA_CH_MIC, TRUE);
#endif
Codec_channel();
RETAILMSG(AC97_DEBUG1,(TEXT("---StopInputDMA\n")));
}
DWORD HardwareContext::GetInterruptThreadPriority()
{
HKEY hDevKey;
DWORD dwValType;
DWORD dwValLen;
DWORD dwPrio = 249; // Default priority
hDevKey = OpenDeviceKey((LPWSTR)m_DriverIndex);
if (hDevKey)
{
dwValLen = sizeof(DWORD);
RegQueryValueEx(
hDevKey,
TEXT("Priority256"),
NULL,
&dwValType,
(PUCHAR)&dwPrio,
&dwValLen);
RegCloseKey(hDevKey);
}
return dwPrio;
}
/////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
// SetForceSpeaker is called from the device context to update the state of the
// m_bForceSpeaker variable.
/////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
DWORD HardwareContext::ForceSpeaker( BOOL bForceSpeaker )
{
// If m_NumForcedSpeaker is non-zero, audio should be routed to an
// external speaker (if hw permits).
if (bForceSpeaker)
{
m_NumForcedSpeaker++;
if (m_NumForcedSpeaker==1)
{
RecalcSpeakerEnable();
}
}
else
{
m_NumForcedSpeaker--;
if (m_NumForcedSpeaker==0)
{
RecalcSpeakerEnable();
}
}
return MMSYSERR_NOERROR;
}
// Control the hardware speaker enable
void HardwareContext::SetSpeakerEnable(BOOL bEnable)
{
// Code to turn speaker on/off here
return;
}
/////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
// RecalcSpeakerEnable decides whether to enable the speaker or not.
// For now, it only looks at the m_bForceSpeaker variable, but it could
// also look at whether the headset is plugged in
// and/or whether we're in a voice call. Some mechanism would
// need to be implemented to inform the wave driver of changes in the state of
// these variables however.
/////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
void HardwareContext::RecalcSpeakerEnable()
{
SetSpeakerEnable(m_NumForcedSpeaker);
}
/*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Function: InitInterruptThread()
Description: Initializes the IST for handling DMA interrupts.
Returns: Boolean indicating success
-------------------------------------------------------------------*/
BOOL HardwareContext::InitInterruptThread()
{
m_hAudioInterruptInput = CreateEvent(NULL, FALSE, FALSE, NULL);
if (!m_hAudioInterruptInput)
{
ERRMSG("Unable to create interrupt event");
return(FALSE);
}
m_hAudioInterruptOutput = CreateEvent(NULL, FALSE, FALSE, NULL);
if (!m_hAudioInterruptOutput)
{
ERRMSG("Unable to create interrupt event");
return(FALSE);
}
if (! InterruptInitialize(m_dwSysintrOutput, m_hAudioInterruptOutput, NULL, 0)) {
ERRMSG("Unable to initialize output interrupt");
return FALSE;
}
if (! InterruptInitialize(m_dwSysintrInput, m_hAudioInterruptInput, NULL, 0)) {
ERRMSG("Unable to initialize input interrupt");
return FALSE;
}
m_hAudioInterruptThreadInput = CreateThread((LPSECURITY_ATTRIBUTES)NULL,
0,
(LPTHREAD_START_ROUTINE)CallInterruptThreadInput,
this,
0,
NULL);
if (!m_hAudioInterruptThreadInput)
{
ERRMSG("Unable to create interrupt thread");
return FALSE;
}
m_hAudioInterruptThreadOutput = CreateThread((LPSECURITY_ATTRIBUTES)NULL,
0,
(LPTHREAD_START_ROUTINE)CallInterruptThreadOutput,
this,
0,
NULL);
if (!m_hAudioInterruptThreadOutput)
{
ERRMSG("Unable to create interrupt thread");
return FALSE;
}
// Bump up the priority since the interrupt must be serviced immediately.
CeSetThreadPriority(m_hAudioInterruptThreadInput, GetInterruptThreadPriority()-1);
CeSetThreadPriority(m_hAudioInterruptThreadOutput, GetInterruptThreadPriority());
return(TRUE);
}
/*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Function: PowerUp()
Description: Powers up the audio codec chip.
Notes: Currently, this function is unimplemented because
the audio codec chip is ONLY powered up when the
user wishes to play or record. The AudioMute() function
handles the powerup sequence.
Returns: Boolean indicating success
-------------------------------------------------------------------*/
void HardwareContext::PowerUp()
{
AC97MSG((TEXT("AC97 Power UP \r\n")));
AC97_Init(); // Kingfish2
InitCodec();
#if (BSP_TYPE == BSP_SMDK2443)
//AudioMute((DMA_CH_OUT | DMA_CH_MIC), TRUE);
AudioMute((DMA_CH_OUT), FALSE); //2005.7.1 junkim
#elif (BSP_TYPE == BSP_SMDK2450)
AudioMute((DMA_CH_OUT | DMA_CH_MIC), TRUE);
#endif
}
/*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Function: PowerDown()
Description: Powers down the audio codec chip.
Notes: Even if the input/output channels are muted, this
function powers down the audio codec chip in order
to conserve battery power.
Returns: Boolean indicating success
-------------------------------------------------------------------*/
void HardwareContext::PowerDown()
{
AC97MSG((TEXT("AC97:PowerDown\r\n")));
/*
StopOutputDMA();
AudioMute((DMA_CH_OUT | DMA_CH_MIC), TRUE);
*/
#if (BSP_TYPE == BSP_SMDK2443)
m_OutputDMAStatus = DMA_CLEAR;
#elif (BSP_TYPE == BSP_SMDK2450)
AudioMute((DMA_CH_OUT | DMA_CH_MIC), TRUE);
Codec_channel();
#endif
AUDIO_OUT_DMA_DISABLE();
AUDIO_OUT_CLEAR_INTERRUPTS();
v_pAC97regs->AC_GLBCTRL = ( v_pAC97regs->AC_GLBCTRL & ~(0x3<<12)) | (0x0 << 12);
#if (BSP_TYPE == BSP_SMDK2443)
m_OutputDMARunning = FALSE;
m_InputDMARunning = FALSE;
AudioMute((DMA_CH_OUT | DMA_CH_MIC), TRUE);
#elif (BSP_TYPE == BSP_SMDK2450)
#endif
}
//############################################ Helper Functions #############################################
/*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Function: TransferOutputBuffer()
Description: Retrieves the next "mixed" audio buffer of data to
DMA into the output channel.
Returns: Number of bytes needing to be transferred.
-------------------------------------------------------------------*/
ULONG HardwareContext::TransferOutputBuffer(ULONG NumBuf)
{
ULONG BytesTransferred = 0;
PBYTE pBufferStart = m_Output_pbDMA_PAGES[NumBuf];
PBYTE pBufferEnd = pBufferStart + AUDIO_DMA_PAGE_SIZE;
PBYTE pBufferLast;
RETAILMSG(AC97_DEBUG2,(_T("TransferOutputBuffer:%d\r\n"),NumBuf));
__try
{
pBufferLast = m_OutputDeviceContext.TransferBuffer(pBufferStart, pBufferEnd,NULL);
BytesTransferred = m_OutBytes[NumBuf] = pBufferLast-pBufferStart;
// Enable if you need to clear the rest of the DMA buffer
StreamContext::ClearBuffer(pBufferLast,pBufferEnd);
if(NumBuf == OUT_BUFFER_A) // Output Buffer A
{
m_OutputDMAStatus &= ~DMA_DONEA;
m_OutputDMAStatus |= DMA_STRTA;
}
else // Output Buffer B
{
m_OutputDMAStatus &= ~DMA_DONEB;
m_OutputDMAStatus |= DMA_STRTB;
}
}
__except(EXCEPTION_EXECUTE_HANDLER)
{
DEBUGMSG(ZONE_ERROR, (TEXT("WAVDEV2.DLL:TransferOutputBuffer() - EXCEPTION: %d"), GetExceptionCode()));
}
return BytesTransferred;
}
/*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Function: TransferOutputBuffers()
Description: Determines which output buffer (A or B) needs to
be filled with sound data. The correct buffer is
then populated with data and ready to DMA to the
output channel.
Returns: Boolean indicating success
-------------------------------------------------------------------*/
ULONG HardwareContext::TransferOutputBuffers(DWORD dwDCSR)
{
ULONG BytesTransferred = 0;
ULONG BytesTotal;
DWORD Bits = dwDCSR & (DMA_DONEA|DMA_DONEB|DMA_BIU);
RETAILMSG(AC97_DEBUG2,(_T("TransferOutputBuffers:%d\r\n"),Bits));
switch (Bits)
{
case 0:
case DMA_BIU:
// No done bits set- must not be my interrupt
return 0;
case DMA_DONEA|DMA_DONEB|DMA_BIU:
// Load B, then A
BytesTransferred = TransferOutputBuffer(OUT_BUFFER_B);
// fall through
case DMA_DONEA: // This should never happen!
case DMA_DONEA|DMA_BIU:
BytesTransferred += TransferOutputBuffer(OUT_BUFFER_A); // charlie, A => B
break;
case DMA_DONEA|DMA_DONEB:
// Load A, then B
BytesTransferred = TransferOutputBuffer(OUT_BUFFER_A);
// charlie
BytesTransferred += TransferOutputBuffer(OUT_BUFFER_B);
break; // charlie
// fall through
case DMA_DONEB|DMA_BIU: // This should never happen!
case DMA_DONEB:
// Load B
BytesTransferred += TransferOutputBuffer(OUT_BUFFER_B); // charlie, B => A
break;
}
// If it was our interrupt, but we weren't able to transfer any bytes
// (e.g. no full buffers ready to be emptied)
// and all the output DMA buffers are now empty, then stop the output DMA
BytesTotal = m_OutBytes[OUT_BUFFER_A]+m_OutBytes[OUT_BUFFER_B];
if (BytesTotal==0)
{
StopOutputDMA();
}
#if (BSP_TYPE == BSP_SMDK2443)
#elif (BSP_TYPE == BSP_SMDK2450)
else
{
StartOutputDMA(); // for DMA resume when wake up
}
#endif
return BytesTransferred;
}
/*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Function: TransferInputBuffer()
Description: Retrieves the chunk of recorded sound data and inputs
it into an audio buffer for potential "mixing".
Returns: Number of bytes needing to be transferred.
-------------------------------------------------------------------*/
ULONG HardwareContext::TransferInputBuffer(ULONG NumBuf)
{
ULONG BytesTransferred = 0;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -