⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 iis.c

📁 基于2410的一个iis总线测试程序 声音控制芯片是飞利浦的UTS1341 可通过xmodem发送声音文件(WAV)到内存
💻 C
📖 第 1 页 / 共 2 页
字号:
//Version:
//parm:
//		0|char|play mode
//		1|char|record mode
//return:none
//===================================
void iisInitDMA(char argMode){
	
	if(argMode == PLAY_MODE){//in the play mode,RAM -> IISFIFO
		//first setting up the initial source 
		rDISRC2 = (unsigned)(PLAY_BUFFER + 0x2c);//we remove the wav header 
		rDISRCC2 &= ~((0x1 << 1)|(0x1 << 0));//source is AHB,address increment 
		//then setting up the initial destination
		rDIDST2 = (unsigned)(0x55000010);//the destination is IISFIFO
		rDIDSTC2 |=	((0x1 << 1)|(0x1 << 0));//destination is APB ,address fix
		//then we configure the DMA controller
		//handshake,sync to APB,interrupt enable,unit transfer
		//single service,I2SSDO,hardware DMA,auto relaod,16bit transfer
		rDCON2 |= ((0x1 << 31)|(0x1 << 29)|(0x1 << 23)|(0x1 << 20));
		//at last we turn on the DMA channel
		rDMASKTRIG2 |= (0x1 << 1);//DMA channel is on,waitting for DMA requset
		//install the interrupt handle
		pISR_DMA2 = (unsigned int)iisDMA2PlayISR;
	}else{//in the record mode,IISFIFO -> RAM
		//first setting up the initial source 
		rDISRC2 = (unsigned)(0x55000010);//the source is IIS FIFO 
		rDISRCC2 |= ((0x1 << 1)|(0x1 << 0));//source is APB,address fix 
		//then setting up the initial destination
		rDIDST2 = (unsigned)(PLAY_BUFFER + 0x2c);//reserve room for the header
		rDIDSTC2 &=	~((0x1 << 1)|(0x1 << 0));//destination is AHB,address increment
		//then we configure the DMA controller
		//handshake,sync to APB,interrupt enable,unit transfer
		//single service,I2SSDI,hardware DMA,auto relaod,16bit transfer
		rDCON2 |= ((0x1 << 31)|(0x1 << 24)|(0x1 << 29)|(0x1 << 23)|(0x1 << 20));
		//install the interrupt handler
		pISR_DMA2 = (unsigned int)iisDMA2RecordISR;
	}
}

//===========[iisloadDMA]============
//Discription:load the counter vaule into DMA counter
//Author:Decell.Zhou
//Version;
//parm:
//		counterValue|int|the value which is going to be loaded into the DMA
//return:
//===================================
void iisLoadDMA(int counterValue){
	rDCON2 &= ~(0xfffff << 0);//clear the counter bit
	rDCON2 |= (counterValue & 0xfffff);
	Uart_Printf("DMA Load: 0x %x\n",counterValue);
	
}

//===========[iisInit]===============
//Description:make preparasion for the iis test
//				1.configure the port
//				2.configure the DMA
//				3.install the isr for the eint
//				4.configre the EINT
//			  this method must be call as soon as the system starting up
//Author:Decell.Zhou
//Version:
//parm:none
//return:none
//==================================
void iisInit(void){
	
	//first setting up the port
	iisInitPort();
	//then install the ISR for the EINT0
	pISR_EINT0 = (unsigned int)iisEint0ISR + 0x30000000;
	//configure the eint0 interrupt
	rINTMOD &= ~(0x1 << 0);//the eint0 is set to irq mode
	//rEXTINT0 |= (0x4 << 0);//rising edge trigged
	//third initial the gobal variable
	gMute = 0;
	gbDMAStop = 0;
	gCompletedSize = 0;
}

//==========[iisPlayStart]============
//Discription:start playing the wav file
//				1.enable all the interrupts
//				2.start DMA
//				3.configure the IIS interface accroding to the argument
//				4.start the IIS
//Author:Decell.Zhou
//Version:
//parm:
//		argMode|char|0|play mode
//		argMode|char|1|record mode
//		argFs|int|sample rate
//return:none
void iisStart(char argMode,unsigned int argFs){
	//enable all interrupts
	rINTMSK &= ~((0x1 << 0)|(0x1 << 19));//enable the eint0,enable the DMA2
	//start DMA
	rDMASKTRIG2 |= (0x1 << 1);//DMA channel is on,waitting for DMA requset
	
	if(argMode == PLAY_MODE){
		//make IIS into Tx mode
		//enable transmit DMA,pause Rx,enale prescale
		rIISCON |= ((0x1 << 5)|(0x1 << 2)|(0x1 << 1));
		//master mode,transmit mode,low for left channel,IIS format,16 bit,
		//master clock 256fs,serial bit clock 32fs
		rIISMOD |= ((0x2 << 6)|(0x1 << 3)|(0x1 << 0));
		//configure the prescaler
		if(argFs == 44100){//FCLK = 135428572Hz,PCLK = 33857143Hz,fs=44100
			rIISPSR = (0x2<<5)|(0x2 << 0);// 33857143/(2+1) = 11285714 = 256*44100
		}else{//FCLK = 135428572Hz,PCLK = 33857143Hz,fs=22050
			rIISPSR = (0x5<<5)|(0x5 << 0);
			Uart_SendString("IIS Started!\n");
		}
		//configure the IIS FIFO
		//transmit FIFO assess by DMA,enable transmit FIFO 
		rIISFCON |= ((0x1 << 15)|(0x1 << 13));
		//start the IIS Tx
		rIISCON |= (0x1 << 0);
		

	}else{
		//make IIS into Rx mode
		//enable receive DMA,pause Tx,enale prescale
		rIISCON |= ((0x1 << 4)|(0x1 << 3)|(0x1 << 1));
		//master mode,receicve mode,low for left channel,IIS format,16 bit,
		//master clock 256fs,serial bit clock 32fs
		rIISMOD |= ((0x1 << 6)|(0x1 << 3)|(0x1 << 0));
		//configure the prescaler
		if(argFs == 44100){//FCLK = 135428572Hz,PCLK = 33857143Hz,fs=44100
			rIISPSR = (0x2<<5)|(0x2 <<0);// 33857143/(2+1) = 11285714 = 256*44100
		}else{//FCLK = 135428572Hz,PCLK = 33857143Hz,fs=22050
			rIISPSR = (0x5<<5)|(0x5 <<0);
		}
		//configure the IIS FIFO
		//receive FIFO assess by DMA,enable receive FIFO 
		rIISFCON |= ((0x1 << 14)|(0x1 << 12));
		//start the IIS Rx
		rIISCON |= (0x1 << 0);	
	}
}

//==========[iisPlayStop]============
//Discription:stop playing the wav file
//			  1.disable all interrputs
//			  2.stop DMA
//			  3.stop IIS
//Author:Decell.Zhou
//Version:
//parm:none
//return:none
void iisStop(void){
	rSRCPND |= ((0x1 << 0)|(0x1 << 19));//clear the pending bit
	rINTPND |= ((0x1 << 0)|(0x1 << 19));
	rINTMSK |= ((0x1 << 0)|(0x1 << 19));//disable the eint0,enable the DMA2
	
	rDMASKTRIG2 |= (0x1 << 2);//stop the DMA immediatly
	//stop the IIS interface
	rIISCON &= ~(0x1 << 0);
}


//===========[iisFileCheck]==========
//Description:check the wav file,the file must be in wav-uncompress format
//Author:
//Version:
//parm:none
//return:
//		0|char|check ok
//		1|char|check failed
//==================================
char iisFileCheck(void){
	return 0;
}


//===========[iisDownloadFile]==========
//Discription:download a file through the serial port
//Author:Decell.Zhou
//Version:
//parm: none
//return:
//		DOWNLOADSUCCESS|char|download file complete successfully
//		DOWNLOADFILED|char|download file failed
//=====================================
char iisDownloadFile(void){
	
	Uart_SendString("Starting the download operation...\n");
	Uart_SendString("The file must be not large than 16MB!\n");
	if(xmodemTransmit((unsigned int)PLAY_BUFFER) == 0){//if download completed successfully
		return DOWNLOADSUCCESS;
	}else{
		return DOWNLOADFAILED;
	}
}


//=========[iisRecord]================
//Discription:record a sound file through the mic
//Author:Decell.Zhou
//Version:
//pram: none
//return:
//		RECORDSUCCESS|char|record a file successfully
//		RECORDFAILED|char|record a file failed
//======================================
char iisRecord(void){}

//=============[iisPlay]=================
//Discription:play the sound file
//Author:Decell.Zhou
//Version:
//parm:
//return:
//======================================
void iisPlay(void){
	unsigned long fileSize;//the sample size, read form the wav header
	unsigned long DMACycle;//the DMA cycles in total
	unsigned int  sampleRate;//the sample rate for the wav file
	unsigned char *fileHead;//the starting point of the file
	
	int i;
	
	fileHead = (unsigned char *)PLAY_BUFFER;//let the fileHead points to the starting point of the play buffer
	
	fileSize = ((*(fileHead + 0x2b))<<24)|((*(fileHead + 0x2a))<<16)|((*(fileHead + 0x29))<<8)|((*(fileHead + 0x28))<<0);
	sampleRate = ((*(fileHead + 0x1b))<<24)|((*(fileHead + 0x1a))<<16)|((*(fileHead + 0x19))<<8)|((*(fileHead + 0x18))<<0);
	DMACycle = fileSize / 2;
	gDMACounter = DMACycle;
	
	if(iisFileCheck() == 1){
		Uart_SendString("The format of the file is not valid!,please down load again\n");
	}else{
	
		Uart_Printf("\n|File size = %d Bytes\n",fileSize);
		Uart_Printf("|Sample rate = %d Hz\n",sampleRate);
		Uart_SendString("|Playing Sound....\n");
		Uart_SendString("Press any key to stop...\n");
		
		for(;Uart_GetKey() == 0;){
			
			iisInitDMA(PLAY_MODE);
			iis1341SetMode(PLAY_MODE);
			gbDMAStop = 0;
			
			if(DMACycle < 0x10000 ){//if the file size is smaller than 128kB
				iisLoadDMA((DMACycle -1) & 0xfffff);//load the dma vaule into the dma counter directly
				iisStart(PLAY_MODE,sampleRate);
			}else{
				iisLoadDMA(0xffff);
				iisStart(PLAY_MODE,sampleRate);
			}
			
			for(;gbDMAStop == 0;){
				Uart_Printf("DMA source: 0x%x\n",rDCSRC2);
				Uart_Printf("DMA destinnation: 0x%x\n",rDIDST2);
				for(i = 0;i <= 100000; i++);
				rGPFDAT &= ~((0x1 << 7)|(0x1 << 4));//set the out put the low, turn on the LED
			}//the DMA transfer is not complete yet;
		
		}
		iisStop();
		Uart_SendString("Stop playing the sound....\n");
	
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -