📄 hwctxt.cpp
字号:
return TRUE;
}
/*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Function: UnmapRegisters()
Description: Unmaps the config registers used by both the SPI and
I2S controllers.
Notes: The SPI and I2S controllers both use the GPIO config
registers, so these MUST be deinitialized LAST.
Returns: Boolean indicating success
-------------------------------------------------------------------*/
BOOL HardwareContext::UnmapRegisters()
{
//----- 1. Free the fast driver-->driver calling mechanism object -----
if(g_hUTLObject)
{
CloseHandle(g_hUTLObject);
}
return TRUE;
}
/*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Function: MapDMABuffers()
Description: Maps the DMA buffers used for audio input/output
on the I2S bus.
Returns: Boolean indicating success
-------------------------------------------------------------------*/
BOOL HardwareContext::MapDMABuffers()
{
BOOL bSuccess=FALSE;
PBYTE pTemp;
//----- 1. Allocate a block of virtual memory big enough to hold the DMA buffers -----
if(!(pTemp = (PBYTE)VirtualAlloc(0, AUDIO_DMA_PAGE_SIZE * 4, MEM_RESERVE, PAGE_NOACCESS)))
{
DEBUGMSG(ZONE_ERROR, (TEXT("WAVEDEV.DLL:HardwareContext::MapDMABuffers() - Unable to allocate memory for DMA buffers!\r\n")));
goto MAP_ERROR;
}
//----- 2. Map the physical DMA buffer to the virtual address we just allocated -----
if(!VirtualCopy((LPVOID)pTemp, (LPVOID)AUDIO_DMA_BUFFER_BASE, (AUDIO_DMA_PAGE_SIZE * 4),
PAGE_READWRITE | PAGE_NOCACHE))
{
DEBUGMSG(ZONE_ERROR, (TEXT("WAVEDEV.DLL:HardwareContext::MapDMABuffers() - VirtualCopy() failed when binding DMA buffers.\r\n")));
goto MAP_ERROR;
}
//----- 3. 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] = pTemp;
m_Output_pbDMA_PAGES[1] = pTemp + AUDIO_DMA_PAGE_SIZE;
m_Input_pbDMA_PAGES[0] = pTemp + 2*AUDIO_DMA_PAGE_SIZE;
m_Input_pbDMA_PAGES[1] = pTemp + 3*AUDIO_DMA_PAGE_SIZE;
return TRUE;
MAP_ERROR:
if(pTemp)
VirtualFree(pTemp, 0, MEM_RELEASE);
return FALSE;
}
/*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Function: UnmapDMABuffers()
Description: Unmaps the DMA buffers used for audio input/output
on the I2S bus.
Returns: Boolean indicating success
-------------------------------------------------------------------*/
BOOL HardwareContext::UnmapDMABuffers()
{
if(m_Output_pbDMA_PAGES[0])
{
VirtualFree((PVOID)m_Output_pbDMA_PAGES[0], 0, MEM_RELEASE);
}
return TRUE;
}
BOOL HardwareContext::Codec_channel()
{
//****** Port B Initialize *****
v_pIOPregs->rGPBDAT |= L3M|L3C; //start condition : L3M=H, L3C=H
v_pIOPregs->rGPBUP |= 0x1c; //pull-up disable
v_pIOPregs->rGPBCON = ((v_pIOPregs->rGPBCON & 0x3ffc0f) | 0x000150);
_WrL3Addr(0x14+2); //STATUS (000101xx+10)
if( m_InputDMARunning & m_OutputDMARunning )
_WrL3Data(0xa3,0); //1,0,0,0,0,0,01 : OGS=0,IGS=0,ADC_NI,DAC_NI,sngl speed,AoffDon
else if( m_InputDMARunning )
_WrL3Data(0xa2,0); //1,0,0,0,0,0,01 : OGS=0,IGS=0,ADC_NI,DAC_NI,sngl speed,AoffDon
else if( m_OutputDMARunning )
_WrL3Data(0xa1,0); //1,0,0,0,0,0,01 : OGS=0,IGS=0,ADC_NI,DAC_NI,sngl speed,AoffDon
else
_WrL3Data(0xa0,0); //1,0,0,0,0,0,01 : OGS=0,IGS=0,ADC_NI,DAC_NI,sngl speed,AoffDon
return TRUE;
}
/*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Function: InitCodec()
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::InitCodec()
{
int i;
// int mode =0; // play
DEBUGMSG(1,(TEXT("+++InitCodec\n")));
//****** Port B Initialize *****
v_pIOPregs->rGPBDAT |= L3M|L3C; //start condition : L3M=H, L3C=H
v_pIOPregs->rGPBUP |= 0x1c; //pull-up disable
v_pIOPregs->rGPBCON = ((v_pIOPregs->rGPBCON & 0x3ffc0f) | 0x000150);
/****** L3 Interface ******/
#if (AUDIO_CODEC_CLOCK == 256) // test value
RETAILMSG(1,(TEXT("256 clock\n")));
_WrL3Addr(0x14+2); //STATUS (000101xx+10)
_WrL3Data(0x60,0); //0,1,10,000,0 : reset,256fs,no DCfilter,iis
_WrL3Addr(0x14+2); //STATUS (000101xx+10)
_WrL3Data(0x20,0); //0,0,10,000,0 : no reset,256fs,no DCfilter,iis
_WrL3Addr(0x14+2); //STATUS (000101xx+10)
_WrL3Data(0xa1,0); //1,0,0,0,0,0,01 : OGS=0,IGS=0,ADC_NI,DAC_NI,sngl speed,AoffDon
#else
RETAILMSG(1,(TEXT("384 clock\n")));
_WrL3Addr(0x14+2); //STATUS (000101xx+10)
_WrL3Data(0x50,0); //0,1,01,000,0 : reset,384fs,no DCfilter,iis
_WrL3Addr(0x14+2); //STATUS (000101xx+10)
_WrL3Data(0x10,0); //0,0,01,000,0 : no reset,384fs,no DCfilter,iis
_WrL3Addr(0x14+2); //STATUS (000101xx+10)
_WrL3Data(0xa1,0); ///1,0,0,0,0,0,01 : OGS=0,IGS=0,ADC_NI,DAC_NI,sngl speed,AoffDon
#endif
_WrL3Addr(0x14 + 0); //DATA0 (000101xx+00)
_WrL3Data(0xc2,0); //11000,010 : DATA0, Extended addr(010)
_WrL3Data(0x4d,0); //010,011,01 : DATA0, MS=9dB, Ch1=on Ch2=off,
return TRUE;
}
/*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Function: InitOutputDMA()
Description: Initializes the DMA channel for output.
Notes: DMA Channel 2 is used for transmitting output sound
data from system memory to the I2S controller.
Returns: Boolean indicating success
-------------------------------------------------------------------*/
BOOL HardwareContext::InitOutputDMA()
{
int tmp;
//----- 1. Initialize the DMA channel for output mode and use the first output DMA buffer -----
v_pDMAregs->rDISRC2 = (int)(AUDIO_DMA_BUFFER_PHYS);
v_pDMAregs->rDISRCC2 &= ~(SOURCE_PERIPHERAL_BUS | FIXED_SOURCE_ADDRESS); // Source is system bus, increment addr
//----- 2. Initialize the DMA channel to send data over the I2S bus -----
v_pDMAregs->rDIDST2 = (int)IISFIF_PHYS;
v_pDMAregs->rDIDSTC2 |= (DESTINATION_PERIPHERAL_BUS | FIXED_DESTINATION_ADDRESS); // Dest is periperal bus, fixed addr
//----- 3. Configure the DMA channel's transfer characteristics: handshake, sync PCLK, interrupt, -----
// single tx, single service, I2SSDO, I2S request, no auto-reload, half-word, tx count
v_pDMAregs->rDCON2 = ( HANDSHAKE_MODE | GENERATE_INTERRUPT | I2SSDO_DMA2 | DMA_TRIGGERED_BY_HARDWARE
| TRANSFER_HALF_WORD | (AUDIO_DMA_PAGE_SIZE / 2 ) );
//----- 4. Reset the playback pointers -----
//AUDIO_RESET_PLAYBACK_POINTER();
ioPlaybackPointerLow = (AUDIO_DMA_BUFFER_PHYS);
ioPlaybackPointerHigh = (AUDIO_DMA_BUFFER_PHYS + AUDIO_DMA_PAGE_SIZE);
DEBUGMSG(1,(TEXT("---InitOutputDMA\n")));
return TRUE;
}
/*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Function: StartOutputDMA()
Description: Starts outputting the sound data to the audio codec
chip via DMA.
Notes: Currently, both playback and record share the same
DMA channel. Consequently, we can only start this
operation if the input channel isn't using DMA.
Returns: Boolean indicating success
-------------------------------------------------------------------*/
BOOL HardwareContext::StartOutputDMA()
{
//RETAILMSG(1,(TEXT("+++StartOutputDMA\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 -----
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;
v_pIISregs->rIISCON |= TRANSMIT_DMA_REQUEST_ENABLE;
v_pIISregs->rIISCON &= ~TRANSMIT_IDLE_CMD;
v_pIISregs->rIISFCON |= ( TRANSMIT_FIFO_ACCESS_DMA | TRANSMIT_FIFO_ENABLE );
v_pIISregs->rIISMOD |= IIS_TRANSMIT_MODE;
v_pIISregs->rIISCON |= IIS_INTERFACE_ENABLE;
Unlock();
////////////////////////////////////////////////////////////////////////////////
//----- 5. Make sure the audio isn't muted -----
AudioMute(DMA_CH_OUT, FALSE);
//----- 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;
v_pDMAregs->rDMASKTRIG2 |= 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_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;
}
}
DEBUGMSG(1,(TEXT("---StartOutputDMA\n")));
return TRUE;
START_ERROR:
return FALSE;
}
/*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Function: StopOutputDMA()
Description: Stops any DMA activity on the output channel.
Returns: Boolean indicating success
-------------------------------------------------------------------*/
void HardwareContext::StopOutputDMA()
{
//----- 1. If the output DMA is running, stop it -----
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;
v_pIISregs->rIISFCON &= ~( TRANSMIT_FIFO_ACCESS_DMA | TRANSMIT_FIFO_ENABLE );
v_pIISregs->rIISMOD &= ~IIS_TRANSMIT_MODE;
AudioMute(DMA_CH_OUT, TRUE);
}
m_OutputDMARunning = FALSE;
Codec_channel();
}
/*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Function: InitInputDMA()
Description: Initializes the DMA channel for input.
Notes: ***** NOT IMPLEMENTED *****
The following routine is not implemented due to a
hardware bug in the revision of the Samsung SC2410
CPU this driver was developed on. See the header
at the top of this file for details.
Returns: Boolean indicating success
-------------------------------------------------------------------*/
BOOL HardwareContext::InitInputDMA()
{
//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;
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);
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, -----
// single tx, single service, I2SSDI, I2S request, no auto-reload, half-word, tx count
v_pDMAregs->rDCON1 = ( HANDSHAKE_MODE | GENERATE_INTERRUPT | I2SSDI_DMA1 | DMA_TRIGGERED_BY_HARDWARE
| TRANSFER_HALF_WORD | (AUDIO_DMA_PAGE_SIZE / 2) );
return TRUE;
INIT_ERROR:
return FALSE;
}
/*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Function: StartInputDMA()
Description: Starts inputting the recorded sound data from the
audio codec chip via DMA.
Notes: ***** NOT IMPLEMENTED *****
The following routine is not implemented due to a
hardware bug in the revision of the Samsung SC2410
CPU this driver was developed on. See the header
at the top of this file for details.
Returns: Boolean indicating success
-------------------------------------------------------------------*/
BOOL HardwareContext::StartInputDMA()
{
int tmp;
//goto START_ERROR;
//------ 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("StartInputDMA()++\r\n")));
if(!m_InputDMARunning)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -