?? hwctxt.cpp
字號:
DEBUGMSG(1,(TEXT("---InitOutputDMA\n")));
//open SP or HP amplifier!
//Lock();
/*if(gHP_flag)
{
//MAX_HeadphoneMuted(false);
MAX_AudioMuted(IIC_OUTPUT_CHANNEl,true);
}else
{
//MAX_HeadphoneMuted(true);
MAX_AudioMuted(IIC_OUTPUT_CHANNEl,false);
}*/
/*if((v_pIOPregs->rGPFDAT)&0x02)//HP
{
MAX_AudioMuted(IIC_OUTPUT_CHANNEl,true);
b_prolevel=true;
}else
{
MAX_AudioMuted(IIC_OUTPUT_CHANNEl,false);
b_prolevel=false;
}*/
//gb_changed=false;
//Unlock();
//RETAILMSG(1,(TEXT("-------InitOutputDMA----------!\r\n")));
Wr_MAXIIC(IIC_SLAVEADDRESS_WRITE,0x2,0x1e);
return TRUE;
}
BOOL HardwareContext::StartOutputDMA()
{
//RETAILMSG(1,(TEXT("+++StartOutputDMA\n")));
//RETAILMSG(1,(TEXT("-------StartOutputDMA----------!\r\n")));
if(!m_OutputDMARunning && (m_Dx == D0) )
// if(!m_OutputDMARunning)
{
//----- 1. Initialize our buffer counters -----
m_OutputDMARunning=TRUE;
m_OutBytes[OUT_BUFFER_A]=m_OutBytes[OUT_BUFFER_B]=0;
//----- 2. Prime the output buffer with sound data -----
//3 5 3(0)
m_OutputDMAStatus = (DMA_DONEA | DMA_DONEB) & ~DMA_BIU;
ULONG OutputTransferred = TransferOutputBuffers(m_OutputDMAStatus);
//----- 3. If we did transfer any data to the DMA buffers, go ahead and enable DMA -----
if(OutputTransferred)
{
//----- 4. Configure the DMA channel for playback -----
if(!InitOutputDMA())
{
DEBUGMSG(ZONE_ERROR, (TEXT("HardwareContext::StartOutputDMA() - Unable to initialize output DMA channel!\r\n")));
goto START_ERROR;
}
////////////////////////////////////////////////////////////////////////////////
// To correct left/right channel on ouput stream,
// You should reset IISCON[0] bit.
Lock();
v_pIISregs->rIISCON &= ~IIS_INTERFACE_ENABLE;//1 stop
v_pIISregs->rIISCON |= TRANSMIT_DMA_REQUEST_ENABLE; //5
v_pIISregs->rIISCON &= ~TRANSMIT_IDLE_CMD; //3 not idle
//23 13
v_pIISregs->rIISFCON |= ( TRANSMIT_FIFO_ACCESS_DMA | TRANSMIT_FIFO_ENABLE );//DMA FIFO enable
//7
v_pIISregs->rIISMOD |= IIS_TRANSMIT_MODE;//10 transmit mode
//1
v_pIISregs->rIISCON |= IIS_INTERFACE_ENABLE; //start!
Unlock();
////////////////////////////////////////////////////////////////////////////////
//----- 5. Make sure the audio isn't muted -----
//AudioMute( IIC_OUTPUT_CHANNEl,FALSE);
//open SP or HP amplifier!
//MAX_AudioMuted(IIC_OUTPUT_CHANNEl,gHP_flag);
//----- 6. Start the DMA controller -----
//AUDIO_RESET_PLAYBACK_POINTER();
ioPlaybackPointerLow = (AUDIO_DMA_BUFFER_PHYS);
ioPlaybackPointerHigh = (AUDIO_DMA_BUFFER_PHYS + AUDIO_DMA_PAGE_SIZE);
//SELECT_AUDIO_DMA_OUTPUT_BUFFER_A();
v_pDMAregs->rDISRC2 = (int)(AUDIO_DMA_BUFFER_PHYS);
//Codec_channel(); // Turn ON output channel
// charlie, start A buffer
//AUDIO_OUT_DMA_ENABLE();
v_pDMAregs->rDMASKTRIG2 &= ~STOP_DMA_TRANSFER; //2
v_pDMAregs->rDMASKTRIG2 |= ENABLE_DMA_CHANNEL; //1
// wait for DMA to start.
delay_count = 0;
while((v_pDMAregs->rDSTAT2&0xfffff)==0)
{
if( delay_count++ > DELAY_COUNT ) break;
}
// change the buffer pointer
//SELECT_AUDIO_DMA_OUTPUT_BUFFER_B();
v_pDMAregs->rDISRC2 = (int)(AUDIO_DMA_BUFFER_PHYS+AUDIO_DMA_PAGE_SIZE);
// Set DMA for B Buffer
}
else // We didn't transfer any data, so DMA wasn't enabled
{
m_OutputDMARunning=FALSE;
}
}
return TRUE;
START_ERROR:
return FALSE;
}
void HardwareContext::StopOutputDMA()
{
//----- 1. If the output DMA is running, stop it -----
//RETAILMSG(1,(TEXT("-------StopOutputDMA----------!\r\n")));
//MAX_ShotdownAmplifier();
//MAX_HeadphoneMuted(true);
//MAX_AudioMuted(IIC_OUTPUT_CHANNEl,true);
Wr_MAXIIC(IIC_SLAVEADDRESS_WRITE,0x2,0x9f);
if (m_OutputDMARunning)
{
m_OutputDMAStatus = DMA_CLEAR;
//AUDIO_OUT_DMA_DISABLE();
v_pDMAregs->rDMASKTRIG2 |= STOP_DMA_TRANSFER;
v_pDMAregs->rDMASKTRIG2 &= ~ENABLE_DMA_CHANNEL;
//AUDIO_OUT_CLEAR_INTERRUPTS();
v_pDMAregs->rDCON2 = v_pDMAregs->rDCON2;
v_pIISregs->rIISCON &= ~TRANSMIT_DMA_REQUEST_ENABLE;
v_pIISregs->rIISCON |= TRANSMIT_IDLE_CMD;//pause transimit
v_pIISregs->rIISFCON &= ~( TRANSMIT_FIFO_ACCESS_DMA | TRANSMIT_FIFO_ENABLE );
v_pIISregs->rIISMOD &= ~IIS_TRANSMIT_MODE;//00 no transmit
//AudioMute(IIC_OUTPUT_CHANNEl, TRUE);
}
m_OutputDMARunning = FALSE;
Codec_channel();
//RETAILMSG(1,(TEXT("-------StopOutputDMA----------!\r\n")));
//MAX_SpeakerMuted();//
}
BOOL HardwareContext::InitInputDMA()
{
//RETAILMSG(1,(TEXT(" --------------InitInputDMA----------------\r\n")));
//goto INIT_ERROR;
//DEBUGMSG(1,(TEXT("+++InitInputDMA\n")));
//============================ Configure DMA Channel 1 ===========================
//------ On platforms with the revsion of the Samsung SC2410 CPU with the IIS SLAVE bug fix, this -----
// code can be used to configure DMA channel 1 for input.
//----- 1. Initialize the DMA channel for input mode and use the first input DMA buffer -----
v_pDMAregs->rDISRC1 = (int)IISFIF_PHYS;
//apb fixed!
v_pDMAregs->rDISRCC1 = (SOURCE_PERIPHERAL_BUS | FIXED_SOURCE_ADDRESS); // Source is periperal bus, fixed addr
//----- 2. Initialize the DMA channel to receive data over the I2S bus -----
v_pDMAregs->rDIDST1 = (int)(AUDIO_DMA_BUFFER_PHYS);
//ahb increment!
v_pDMAregs->rDIDSTC1 &= ~(DESTINATION_PERIPHERAL_BUS | FIXED_DESTINATION_ADDRESS); // Destination is system bus, increment addr
//----- 3. Configure the DMA channel's transfer characteristics: handshake, sync PCLK, interrupt, -----
// (unit)single tx, single service, I2SSDI, I2S request, no(problem) auto-reload, half-word, tx count
//31 29, 25 23 20 1k
v_pDMAregs->rDCON1 = ( HANDSHAKE_MODE | GENERATE_INTERRUPT | I2SSDI_DMA1 | DMA_TRIGGERED_BY_HARDWARE
| TRANSFER_HALF_WORD | (AUDIO_DMA_PAGE_SIZE / 2) );
//MAX_AudioMuted(IIC_INPUT_CHANNEl, false);//MIC muted
RecordInit();
return TRUE;
}
BOOL HardwareContext::StartInputDMA()
{
//DEBUGMSG(1,(_T("StartInputDMA()++\r\n")));
//RETAILMSG(1,(TEXT(" --------------StartInputDMA----------------\r\n")));
if(!m_InputDMARunning)
{
//----- 1. Initialize our buffer counters -----
m_InputDMARunning=TRUE;
//Codec_channel(); // Turn On Input channel
m_InBytes[IN_BUFFER_A]=m_InBytes[IN_BUFFER_B]=0;
//----- 2. Prime the output buffer with sound data -----
m_InputDMAStatus = (DMA_DONEA | DMA_DONEB) & ~DMA_BIU;
//----- 3. Configure the DMA channel for record -----
if(!InitInputDMA())
{
DEBUGMSG(ZONE_ERROR, (TEXT("HardwareContext::StartInputDMA() - Unable to initialize input DMA channel!\r\n")));
goto START_ERROR;
}
v_pIISregs->rIISCON |= RECEIVE_DMA_REQUEST_ENABLE;
v_pIISregs->rIISCON &= ~RECEIVE_IDLE_CMD;
v_pIISregs->rIISFCON |= ( RECEIVE_FIFO_ACCESS_DMA | RECEIVE_FIFO_ENABLE);
v_pIISregs->rIISMOD |= IIS_RECEIVE_MODE;
//----- 4. Make sure the audio isn't muted -----
//AudioMute(IIC_INPUT_CHANNEl, FALSE);
//----- 5. Start the input DMA -----
//AUDIO_RESET_RECORD_POINTER();
ioRecordPointerLow = (RECORD_DMA_BUFFER_PHYS);
ioRecordPointerHigh = (RECORD_DMA_BUFFER_PHYS+ AUDIO_DMA_PAGE_SIZE);
//SELECT_AUDIO_DMA_INPUT_BUFFER_A();
v_pDMAregs->rDIDST1 = (int)(AUDIO_DMA_BUFFER_PHYS+2*AUDIO_DMA_PAGE_SIZE);
Codec_channel(); // Turn On Input channel
v_pDMAregs->rDMASKTRIG1 &= ~STOP_DMA_TRANSFER;
v_pDMAregs->rDMASKTRIG1 |= ENABLE_DMA_CHANNEL;
// wait for DMA to start.
delay_count = 0;
while((v_pDMAregs->rDSTAT2&0xfffff)==0){
if( delay_count++ > DELAY_COUNT ) break;
}
// change the buffer pointer
//SELECT_AUDIO_DMA_INPUT_BUFFER_B();
v_pDMAregs->rDIDST1 = (int)(AUDIO_DMA_BUFFER_PHYS+3*AUDIO_DMA_PAGE_SIZE);
}
//DEBUGMSG(1,(_T("StartInputDMA()--\r\n")));
return TRUE;
START_ERROR:
return FALSE;
}
void HardwareContext::StopInputDMA()
{
//RETAILMSG(1,(TEXT(" --------------StopInputDMA----------------\r\n")));
//------ On platforms with the revsion of the Samsung SC2410 CPU with the IIS SLAVE bug fix, this -----
// code can be used to configure DMA channel 1 for input.
//DEBUGMSG(1,(_T("StopInputDMA()++\r\n")));
//----- 1. If the output DMA is running, stop it -----
if (m_InputDMARunning)
{
m_InputDMAStatus = DMA_CLEAR;
v_pIISregs->rIISCON &= ~RECEIVE_DMA_REQUEST_ENABLE;
v_pIISregs->rIISCON |= RECEIVE_IDLE_CMD;
v_pIISregs->rIISFCON &= ~( RECEIVE_FIFO_ACCESS_DMA | RECEIVE_FIFO_ENABLE);
v_pIISregs->rIISMOD &= ~IIS_RECEIVE_MODE;
v_pDMAregs->rDMASKTRIG1 |= STOP_DMA_TRANSFER;
v_pDMAregs->rDMASKTRIG1 &= ~ENABLE_DMA_CHANNEL;
// AUDIO_IN_DMA_DISABLE();
// v_pIISregs->rIISCON &= ~RECEIVE_DMA_REQUEST_ENABLE;
// v_pIISregs->rIISFCON &= ~( RECEIVE_FIFO_ACCESS_DMA | RECEIVE_FIFO_ENABLE);
// v_pDMAregs->rDMASKTRIG1 |= STOP_DMA_TRANSFER;
//AUDIO_IN_CLEAR_INTERRUPTS();
v_pDMAregs->rDCON1 = v_pDMAregs->rDCON1;
//AudioMute(IIC_INPUT_CHANNEl, TRUE);
}
m_InputDMARunning = FALSE;
//Codec_channel();
//MAX_AudioMuted(IIC_INPUT_CHANNEl, true); //MIC muted!
Recordfinish();
//DEBUGMSG(1,(_T("StopInputDMA()--\r\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()
{
//v_pIOPregs->rGPFCON |= (0x2 << 2); //int1
//v_pIOPregs->rGPFUP &=0xfd; //pull-up
BOOL bSuccess;
//automaticly set event! initial stat is no-singal!
m_hAudioInterrupt = CreateEvent( NULL, FALSE, FALSE, NULL);
if (!m_hAudioInterrupt)
{
return FALSE;
}
bSuccess = InterruptInitialize(m_IntrAudio, m_hAudioInterrupt, NULL, 0);
m_hAudioInterruptThread = CreateThread((LPSECURITY_ATTRIBUTES)NULL,
0,
(LPTHREAD_START_ROUTINE)CallInterruptThread,
this,
0,
NULL);
if (!m_hAudioInterruptThread)
{
return FALSE;
}
//DWORD dwPriority= GetInterruptThreadPriority();
//RETAILMSG(1,(TEXT("------------------------- GetInterruptThreadPriority0x%x \r\n")), dwPriority);
//RETAILMSG(1,(TEXT("------------------------- GetInterruptThreadPriority0x%x \r\n"), GetInterruptThreadPriority()));
//CeSetThreadPriority(m_hAudioInterruptThread, GetInterruptThreadPriority());
CeSetThreadPriority(m_hAudioInterruptThread, 2);
/////////////////////////////////////
//SoundControlInit(); //volume control key button !
/*if (m_hVolumeIncrEvent == NULL)
{
// allocate the interrupt event
m_hVolumeIncrEvent = CreateEvent(NULL, FALSE, FALSE,NULL);
if (NULL == m_hVolumeIncrEvent)
{
RETAILMSG(1,(TEXT("sound increase event Error1\r\n")));
}
// initialize interrupt event
if (!InterruptInitialize (SYSINTR_INCVOLUME, m_hVolumeIncrEvent, NULL, 0))
{
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -