📄 iis_wav.c
字号:
/*********************************************************************************************
* File: iis.c
* Author: embest
* Desc: IIS sound circuit code
* History:
*********************************************************************************************/
#include "44b.h"
#include "44blib.h"
#include "option.h"
#include "def.h"
#include "iis.h"
/*------------------------------------------------------------------------------------------*/
/* constant define */
/*------------------------------------------------------------------------------------------*/
#define PLAY 0
#define RECORD 1
#define REC_LEN 0xF0000
/*------------------------------------------------------------------------------------------*/
/* extern variables */
/*------------------------------------------------------------------------------------------*/
extern const UINT8T g_ucWave[155760];
/*------------------------------------------------------------------------------------------*/
/* global variables */
/*------------------------------------------------------------------------------------------*/
int f_nDMADone;
/*********************************************************************************************
* name: iis_test
* func: Test IIS circuit
* para: none
* ret: none
* modify:
* comment:
*********************************************************************************************/
void iis_test(void)
{
UINT8T ucInput;
iis_init(); // initialize IIS
uart_printf("Menu(press digital to select):\n");
uart_printf("1: play wave file \n");
uart_printf("2: record and play\n");
do{
ucInput = uart_getch();
}while((ucInput != 0x31) && (ucInput != 0x32));
if(ucInput == 0x31)
iis_play_wave(1);
if(ucInput == 0x32)
iis_record();
iis_close(); // close IIS
}
/*********************************************************************************************
* name: iis_init
* func: Initialize IIS circuit
* para: none
* ret: none
* modify:
* comment:
*********************************************************************************************/
void iis_init(void)
{
rPCONE = (rPCONE&0xffff) | (2<<16); // PE8:CODECLK
#ifdef S3CEV40
rPCONC = (rPCONC&0xFFFFFF00) | (0xFF); // PC0:IISLRCLK PC1:IISSDO PC2:IISDI PC3:IISSCLK
rPCONF = (rPCONF&0x3ff);
#else
rPCONC = (rPCONC&0xFFFFFF00);
rPCONF = (rPCONF&0x3ff) | (0x249000); // PF5:IISLRCLK PF6:IISSDO PF7:IISDI PF8:IISSCLK
#endif
f_nDMADone = 0;
init_1341(PLAY); // initialize philips UDA1341 chip
}
/*********************************************************************************************
* name: iis_close
* func: Close IIS circuit
* para: none
* ret: none
* modify:
* comment:
*********************************************************************************************/
void iis_close()
{
rIISCON = 0x0; // IIS stop
cache_flush();
rINTMSK |= BIT_GLOBAL; // Mask interrupt
}
/*********************************************************************************************
* name: iis_play_wave
* func: play wave data
* para: nTimes -- input, play times
* ret: none
* modify:
* comment:
*********************************************************************************************/
void iis_play_wave(int nTimes)
{
unsigned char* pWavFile;
int nSoundLen;
int i;
// enable interrupt
rINTMOD = 0x0;
rINTCON = 0x1;
// execute command "download t.wav 0xc300000" before running
// pWavFile = (unsigned char*)0xC300000;
pWavFile = (unsigned char*)g_ucWave;
// initialize philips UDA1341 chip
init_1341(PLAY);
// set BDMA interrupt
pISR_BDMA0 = (unsigned)bdma0_done;
rINTMSK = ~(BIT_GLOBAL|BIT_BDMA0);
for(i=nTimes; i!=0; i--)
{
// initialize variables
f_nDMADone = 0;
nSoundLen= 155956;
rBDISRC0 = (1<<30)+(1<<28)+((int)(pWavFile)); // Half word,increment,pBufTmp
rBDIDES0 = (1<<30)+(3<<28)+((int)rIISFIF); // M2IO,Internel peripheral,IISFIF
rBDICNT0 = (1<<30)+(1<<26)+(3<<22)+(0<<21)+(1<<20)+nSoundLen; // IIS,Int,auto-reload,enable DMA
rBDCON0 = 0x0<<2;
// IIS Initialize
rIISCON = 0x22; // Tx DMA enable,Rx idle,prescaler enable
rIISMOD = 0xC9; // Master,Tx,L-ch=low,iis,16bit ch.,codeclk=256fs,lrck=32fs
rIISPSR = 0x22; // Prescaler_A/B enable, value=3
rIISFCON = 0xF00; // Tx/Rx DMA,Tx/Rx FIFO
rIISCON |= 0x1; // enable IIS
while( f_nDMADone == 0); // DMA end
rIISCON = 0x0; // IIS stop
}
}
/*********************************************************************************************
* name: iis_play_wave
* func: play wave data
* para: nTimes -- input, play times
* ret: none
* modify:
* comment:
*********************************************************************************************/
void iis_record(void)
{
unsigned char* pRecBuf;
int nSoundLen;
int i;
// enable interrupt
rINTMOD=0x0;
rINTCON=0x1;
//----------------------------------------------------------------//
// record //
//----------------------------------------------------------------//
uart_printf("Start recording....\n");
pRecBuf = (unsigned char *)0x0C400000; // for download
for(i= (UINT32T)pRecBuf; i<((UINT32T)pRecBuf+REC_LEN+0x20000); i+=4)
{
*((volatile unsigned int*)i)=0x0;
}
init_1341(RECORD);
// set BDMA interrupt
f_nDMADone = 0;
pISR_BDMA0 = (unsigned)bdma0_done;
rINTMSK = ~(BIT_GLOBAL|BIT_BDMA0);
// BDMA0 Initialize
rBDISRC0 = (1<<30)+(3<<28)+((int)rIISFIF); // Half word,inc,pBufTmp
rBDIDES0 = (2<<30)+(1<<28)+((int)pRecBuf); // M2IO,fix,IISFIF
rBDICNT0 = (1<<30)+(1<<26)+(3<<22)+(1<<21)+(1<<20)+REC_LEN;
rBDCON0 = 0x0<<2;
// IIS Initialize
rIISCON = 0x1a; // Rx DMA enable,Rx idle,prescaler enable
rIISMOD = 0x49; // Master,Tx,L-ch=low,iis,16bit ch.,codeclk=256fs,lrck=32fs
rIISPSR = 0x22; // Prescaler_A/B enable, value=3
rIISFCON= 0x500; // Tx/Rx DMA,Tx/Rx FIFO --> start piling....
rIISCON |=0x1; // Rx start
while(f_nDMADone == 0); // DMA end
rINTMSK |= BIT_BDMA0;
delay(10);
rIISCON = 0x0; // IIS stop
rBDICNT0= 0x0; // BDMA stop
uart_printf("End of record!!!\n");
uart_printf("Press any key to play record data!!!\n");
while(!uart_getch());
//----------------------------------------------------------------//
// play //
//----------------------------------------------------------------//
// initialize philips UDA1341 chip
init_1341(PLAY);
// set BDMA interrupt
pISR_BDMA0 = (unsigned)bdma0_done;
rINTMSK = ~(BIT_GLOBAL|BIT_BDMA0);
// initialize variables
f_nDMADone = 0;
nSoundLen= REC_LEN;
rBDISRC0 = (1<<30)+(1<<28)+((int)(pRecBuf)); // Half word,increment,pBufTmp
rBDIDES0 = (1<<30)+(3<<28)+((int)rIISFIF); // M2IO,Internel peripheral,IISFIF
rBDICNT0 = (1<<30)+(1<<26)+(3<<22)+(0<<21)+(1<<20)+nSoundLen; // IIS,Int,auto-reload,enable DMA
rBDCON0 = 0x0<<2;
// IIS Initialize
rIISCON = 0x22; // Tx DMA enable,Rx idle,prescaler enable
rIISMOD = 0xC9; // Master,Tx,L-ch=low,iis,16bit ch.,codeclk=256fs,lrck=32fs
rIISPSR = 0x22; // Prescaler_A/B enable, value=3
rIISFCON = 0xF00; // Tx/Rx DMA,Tx/Rx FIFO
rIISCON |= 0x1; // enable IIS
while(f_nDMADone == 0); // DMA end
rIISCON = 0x0; // IIS stop
uart_printf("Play end!!!\n");
}
/*********************************************************************************************
* name: bdma0_done
* func: BDMA0 interrupt handler
* para: none
* ret: none
* modify:
* comment:
*********************************************************************************************/
void bdma0_done(void)
{
rI_ISPC=BIT_BDMA0; // clear pending bit
f_nDMADone = 1;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -