S3C2410 IIS總線sample code 分析
{
本文引用地址:http://butianyuan.cn/article/201611/316667.htmif((RecStatus.handle!=hwi)||(RecStatus.Status!=DEVICE_REC))
returnMMSYSERR_INVALHANDLE;
rIISCON=0x0;//IISInterfacestop
rIISFCON=0x0;//ForFIFOflush
rCLKCON&=~0x20000;//disableIIScolock
//rMPLLCON=save_MPLLCON;//restoreMPLLCONvalue
SetSysFclk(save_MPLLCON);
RecStatus.Status=DEVICE_FREE;
ReleaseDMA(RecStatus.DevReq);
if((RecStatus.DevReq&0xff)==0x12)
DisableIrq(BIT_DMA1);
if((RecStatus.DevReq&0xff)==0x21)
DisableIrq(BIT_DMA2);
returnMMSYSERR_NOERROR;
}
MMRESULTwaveInStart(HWAVEINhwi)
{
if((RecStatus.handle!=hwi)||(RecStatus.Status!=DEVICE_REC))
returnMMSYSERR_INVALHANDLE;
if(!RecTotBlks)
returnMMSYSERR_NOMEM;
SetRecDma();
//{48000,(123<<12)|(6<<4)|0,(3<<5)|3,0}};
rIISPSR=CodecPara[RecStatus.FsIdx].PreScaler;
rIISCON=(0<<5)+(1<<4)+(1<<3)+(0<<2)+(1<<1);//TxDMAdisable,RxDMAenable,Txidle,Rxnotidle,prescalerenable,stop
rIISMOD=(0<<8)+(1<<6)+(0<<5)+(1<<4)+((RecStatus.wBitsPerSample>>4)<<3)+(CodecPara[RecStatus.FsIdx].ofs<<2)+(1<<0);
//Mastermode[8],Rxmode[7:6],LowforLeftChannel[5],IISformat[4],16/8bit[3],256/384fs[2],IISCLK32fs[1:0]
rIISFCON=(1<<14)+(1<<12);//RxDMA,RxFIFO-->startpiling....
rIISCON|=0x1;//startIIS
returnMMSYSERR_NOERROR;
}
MMRESULTwaveInStop(HWAVEINhwi)
{
if((RecStatus.handle!=hwi)||(RecStatus.Status!=DEVICE_REC))
returnMMSYSERR_INVALHANDLE;
rIISCON=0x0;//IISInterfacestop
rIISFCON=0x0;//ForFIFOflush
StopDMA(RecStatus.DevReq);
returnMMSYSERR_NOERROR;
}
MMRESULTwaveInPrepareHeader(HWAVEINhwi,LPWAVEHDRpwh,UINTcbwh)
{
if((RecStatus.handle!=hwi)||(RecStatus.Status!=DEVICE_REC))
returnMMSYSERR_INVALHANDLE;
pwh->lpNext=0;
pwh->dwBytesRecorded=0;
pwh->dwUser=0;
pwh->dwFlags=0;
returnMMSYSERR_NOERROR;
}
MMRESULTwaveInUnprepareHeader(HWAVEINhwi,LPWAVEHDRpwh,UINTcbwh)
{
if((RecStatus.handle!=hwi)||(RecStatus.Status!=DEVICE_REC))
returnMMSYSERR_INVALHANDLE;
returnMMSYSERR_NOERROR;
}
//每次循環(huán)指針pwh值都不一樣他們是個(gè)連續(xù)的數(shù)組,這個(gè)函數(shù)的作用就是將數(shù)組中的數(shù)據(jù)組成一個(gè)鏈表
MMRESULTwaveInAddBuffer(HWAVEINhwi,LPWAVEHDRpwh,UINTcbwh)
{
if((RecStatus.handle!=hwi)||(RecStatus.Status!=DEVICE_REC))
returnMMSYSERR_INVALHANDLE;
if(!RecTotBlks)
{
lpRecFstBlk=pwh;
lpRecCurBlk=lpRecFstBlk;//最開始播放的數(shù)據(jù)
}
else
{
lpRecLstBlk->lpNext=pwh;
}
lpRecLstBlk=pwh;
pwh->lpNext=0;
RecTotBlks++;
returnMMSYSERR_NOERROR;
}
MMRESULTwaveInReset(HWAVEOUThwi)
{
returnMMSYSERR_NOERROR;
}
/*************************ControlFunction*********************/
staticvoidIIS_PortSetting(void)
{
//----------------------------------------------------------
//PORTBGROUP
//Ports:GPB4GPB3GPB2
//Signal:L3CLOCKL3DATAL3MODE
//Setting:OUTPUTOUTPUTOUTPUT
//[9:8][7:6}[5:4]
//Binary:01,0101
//----------------------------------------------------------
rGPBUP=rGPBUP&~(0x7<<2)|(0x7<<2);//ThepullupfunctionisdisabledGPB[4:2]11100
rGPBCON=rGPBCON&~(0x3f<<4)|(0x15<<4);//GPB[4:2]=Output(L3CLOCK):Output(L3DATA):Output(L3MODE)
//----------------------------------------------------------
//PORTEGROUP
//Ports:GPE4GPE3GPE2GPE1GPE0
//Signal:I2SSDOI2SSDICDCLKI2SSCLKI2SLRCK
//Binary:10,1010,1010
//----------------------------------------------------------
rGPEUP=rGPEUP&~(0x1f)|0x1f;//ThepullupfunctionisdisabledGPE[4:0]11111
rGPECON=rGPECON&~(0x3ff)|0x2aa;//GPE[4:0]=I2SSDO:I2SSDI:CDCLK:I2SSCLK:I2SLRCK
}
//==========================================================
#defineL3C(1<<4)//GPB4=L3CLOCK
#defineL3D(1<<3)//GPB3=L3DATA
#defineL3M(1<<2)//GPB2=L3MODE
staticvoid_WrL3Addr(U8data)
{
S32i,j;
rGPBDAT=rGPBDAT&~(L3D|L3M|L3C)|L3C;//L3D=L,L3M=L(inaddressmode),L3C=H
for(j=0;j<4;j++);//tsu(L3)>190ns
//GPB[4:2]=L3C3D3M
for(i=0;i<8;i++)//LSBfirst
{
if(data&0x1)//IfdatasLSBisH
{
rGPBDAT&=~L3C;//L3C=L
rGPBDAT|=L3D;//L3D=H
for(j=0;j<4;j++);//tcy(L3)>500ns
rGPBDAT|=L3C;//L3C=H
rGPBDAT|=L3D;//L3D=H
for(j=0;j<4;j++);//tcy(L3)>500ns
}
else//IfdatasLSBisL
{
rGPBDAT&=~L3C;//L3C=L
rGPBDAT&=~L3D;//L3D=L
for(j=0;j<4;j++);//tcy(L3)>500ns
rGPBDAT|=L3C;//L3C=H
rGPBDAT&=~L3D;//L3D=L
for(j=0;j<4;j++);//tcy(L3)>500ns
}
data>>=1;
}
rGPBDAT=rGPBDAT&~(L3D|L3M|L3C)|(L3C|L3M);//L3M=H,L3C=H
}
//==========================================================
staticvoid_WrL3Data(U8data,inthalt)
{
S32i,j;
if(halt)
{
rGPBDAT=rGPBDAT&~(L3D|L3M|L3C)|L3C;//L3C=H(whiletstp,L3interfacehaltcondition)
for(j=0;j<4;j++);//tstp(L3)>190ns
}
rGPBDAT=rGPBDAT&~(L3D|L3M|L3C)|(L3C|L3M);//L3M=H(indatatransfermode)
for(j=0;j<4;j++);//tsu(L3)D>190ns
//GPB[4:2]=L3C3D3M
for(i=0;i<8;i++)
{
if(data&0x1)//ifdatasLSBisH
{
rGPBDAT&=~L3C;//L3C=L
rGPBDAT|=L3D;//L3D=H
for(j=0;j<4;j++);//tcy(L3)>500ns
rGPBDAT|=(L3C|L3D);//L3C=H,L3D=H
for(j=0;j<4;j++);//tcy(L3)>500ns
}
else//IfdatasLSBisL
{
rGPBDAT&=~L3C;//L3C=L
rGPBDAT&=~L3D;//L3D=L
for(j=0;j<4;j++);//tcy(L3)>500ns
rGPBDAT|=L3C;//L3C=H
rGPBDAT&=~L3D;//L3D=L
for(j=0;j<4;j++);//tcy(L3)>500ns
}
data>>=1;//Forchecknextbit
}
rGPBDAT=rGPBDAT&~(L3D|L3M|L3C)|(L3C|L3M);//L3M=H,L3C=H
}
//==========================================================
staticvoidInit1341(charmode)
{
U16FsIdx;
//PortInitialize
//----------------------------------------------------------
//PORTBGROUP
//Ports:GPB4GPB3GPB2
//Signal:L3CLOCKL3DATAL3MODE
//Setting:OUTPUTOUTPUTOUTPUT
//[9:8][7:6}[5:4]
//Binary:01,0101
//----------------------------------------------------------
rGPBDAT=rGPBDAT&~(L3M|L3C|L3D)|(L3M|L3C);//Startcondition:L3M=H,L3C=H
rGPBUP=rGPBUP&~(0x7<<2)|(0x7<<2);//ThepullupfunctionisdisabledGPB[4:2]11100
rGPBCON=rGPBCON&~(0x3f<<4)|(0x15<<4);//GPB[4:2]=Output(L3CLOCK):Output(L3DATA):Output(L3MODE)
//L3Interface
_WrL3Addr(0x14+2);//STATUS(000101xx+10)
_WrL3Data(0x60,0);//0,1,10,000,0:Status0,Reset,256fs,IIS-bus,noDC-filtering
_WrL3Addr(0x14+2);//STATUS(000101xx+10)
FsIdx=mode?RecStatus.FsIdxlayStatus.FsIdx;
if(CodecPara[FsIdx].ofs)
_WrL3Data(0x18,0);//0,0,01,000,0:Status0,Noreset,384fs,IIS-bus,noDC-filtering
else
_WrL3Data(0x28,0);//0,0,10,000,0:Status0,Noreset,256fs,IIS-bus,noDC-filtering
_WrL3Addr(0x14+2);//STATUS(000101xx+10)
_WrL3Data(0xc1,0);//1,0,0,0,0,0,01
//Status1,GainofDAC6dB,GainofADC0dB,ADCnon-inverting,DACnon-inverting
//,Singlespeedplayback,ADC-OffDAC-On
//Record
if(mode){
_WrL3Addr(0x14+2);//STATUS(000101xx+10)
//_WrL3Data(0xa2,0);//1,0,1,0,0,0,10
//Status1,GainofDAC0dB,GainofADC6dB,ADCnon-inverting,DACnon-inverting
//,Singlespeedplayback,ADC-OnDAC-Off
_WrL3Data(0xe3,0);//1,1,1,0,0,0,11
//Status1,GainofDAC6dB,GainofADC6dB,ADCnon-inverting,DACnon-inverting
//,Singlespeedplayback,ADC-OnDAC-On,DAC打開使錄音時(shí)可從耳機(jī)聽到聲音
//_WrL3Addr(0x14+0);//DATA0(000101xx+00)
//_WrL3Data(0x3f,0);//00,111111:Volumecontrol(6bits)
//_WrL3Data(0x00,0);//00,000000:Volumecontrol(6bits)0dB
_WrL3Addr(0x14+0);//DATA0(000101xx+00)
_WrL3Data(0x7b,0);//01,1110,11:Data0,BassBoost18~24dB,Treble6dB
//_WrL3Addr(0x14+0);//DATA0(000101xx+00)
_WrL3Data(0xc4,0);//11000,100:Extendedaddr(3bits),100
//_WrL3Data(0x90,0);//100,100,00:DATA0,EnableAGC,00,inputamplifiergainchannel2(2bits)
_WrL3Data(0xf0,0);//111,100,00:DATA0,EnableAGC,00,inputamplifiergainchannel2(2bits)
//_WrL3Addr(0x14+0);//DATA0(000101xx+00)
_WrL3Data(0xc0,0);//11000,000:Extendedaddr(3bits),000
_WrL3Data(0xe4,0);//111,00000:MA=0dB
_WrL3Data(0xc1,0);//11000,001:Extendedaddr(3bits),001
_WrL3Data(0xe4,0);//111,00000:MB=0dB
//_WrL3Addr(0x14+0);//DATA0(000101xx+00)
_WrL3Data(0xc2,0);//11000,010:Extendedaddr(3bits),010
//_WrL3Data(0x59,0);//010,110,01:DATA0,MICAmplifierGain27dB,inputchannel1select(inputchannel2off)
_WrL3Data(0xf9,0);//111,110,11:DATA0,MICAmplifierGain27dB,input1XMA+input2XMB
}
}
//==========================================================
staticvoidPlayPause(U8mode)
{
if(mode)
rIISCON&=~1;//stopiis
else
rIISCON|=1;//startiis
}
#defineMAX_VOLUME61
staticvoidAdjVolume(U16volume)
{
rGPBDAT=rGPBDAT&~(L3M|L3C|L3D)|(L3M|L3C);//Startcondition:L3M=H,L3C=H
rGPBUP=rGPBUP&~(0x7<<2)|(0x7<<2);//ThepullupfunctionisdisabledGPB[4:2]11100
rGPBCON=rGPBCON&~(0x3f<<4)|(0x15<<4);//GPB[4:2]=Output(L3CLOCK):Output(L3DATA):Output(L3MODE)
volume=(volume*MAX_VOLUME)/0xffff;
_WrL3Addr(0x14+0);//DATA0(000101xx+00)
_WrL3Data(MAX_VOLUME-volume,0);
}
/*
staticvoidMuting(void)
{
if(mute)//Mute
{
_WrL3Addr(0x14+0);//DATA0(000101xx+00)
_WrL3Data(0xa4,0);//10,1,00,1,00:after,node-emp,mute,flat
mute=0;
}
else//Nomute
{
_WrL3Addr(0x14+0);//DATA0(000101xx+00)
_WrL3Data(0xa0,0);//10,1,00,0,00:after,node-emp,nomute,flat
mute=1;
}
}
*/
評論