標簽:WM8960IIS音頻驅動s3c2416裸機開發(fā)
2014-06-10 09:50853人閱讀評論(0)收藏舉報
分類:
s3c2416裸機開發(fā)(24)
版權聲明:本文為博主原創(chuàng)文章,未經博主允許不得轉載。
目錄(?)[+]
象棋小子 1048272975
IIS模塊實現IIS.c如下:
#include"s3c2416.h"
#include "IIS.h"
#include"Exception.h"
#include"UART0.h"
#defineDEBUG_IIS
#ifdef DEBUG_IIS
#defineDebug(x...) Uart0_Printf(x)
#else
#defineDebug(x...)
#endif
staticunsigned char TX_Channel; // 發(fā)送音頻的聲道數
staticunsigned char TX_BitLen; // 發(fā)送位長
staticunsigned char RX_Channel; // 接收音頻的聲道數
staticunsigned char RX_BitLen; // 接收位長
staticvolatile unsigned char TxBufferFlag;
staticvolatile unsigned char RxBufferFlag;
staticunsigned int TxCount; // 播放時記錄緩存中的寫位置
staticunsigned int RxCount; // 錄音時記錄緩存中的讀位置
// 插放與錄音均采用雙緩存,DMA傳輸的主存與cache會有數據一致性問題
// 音頻DMA緩存分配到不開啟cache的內存區(qū)域
staticunsigned int TxBuffer0[4*1024] __attribute__((section("No_Cache"),zero_init));
staticunsigned int TxBuffer1[4*1024] __attribute__((section("No_Cache"),zero_init));
staticunsigned int RxBuffer0[4*1024] __attribute__((section("No_Cache"),zero_init));
staticunsigned int RxBuffer1[4*1024] __attribute__((section("No_Cache"),zero_init));
static voidDMA_IRQ(void)
{
static unsigned char TxBufferChannel = 0;
static unsigned char RxBufferChannel = 0;
unsigned int DMA_Channel;
DMA_Channel = rSUBSRCPND;
if (DMA_Channel &(1< if (TxBufferChannel == 0) { rDISRC0 = ((unsigned int)TxBuffer1);// 開始使用Buffer1緩存 TxBufferFlag &= ~(1<<0);// 發(fā)送標志0位清空,說明Buffer0數據需填充 TxBufferChannel = 1; // 正在發(fā)送Buffer1緩存 } else { rDISRC0 = ((unsignedint)TxBuffer0);// 開始使用Buffer0緩存 TxBufferFlag &= ~(1<<1);// 發(fā)送標志1位清空,說明Buffer1數據需填充 TxBufferChannel = 0; // 正在發(fā)送Buffer0緩存 } rDCON0 = (rDCON0&(~0xfffff)) |(sizeof(TxBuffer0)/4); rDMASKTRIG0 = (1<<1); // IIS TX打開DMA0通道 rSUBSRCPND |= (1< } if (DMA_Channel &(1< if (RxBufferChannel == 0) { rDIDST1 = ((unsigned int)RxBuffer1);// DMA1目的地址 RxBufferFlag |= (1<<0); // 接收緩存0位置位,說明Buffer0數據準備好 RxBufferChannel = 1; // 下一次使用Buffer1 } else { rDIDST1 = ((unsigned int)RxBuffer0);// DMA1目的地址 RxBufferFlag |= (1<<1); // 接收緩存1位置位,說明Buffer1數據準備好 RxBufferChannel = 0; // 下一次使用Buffer0 } rDCON1 = (rDCON1&(~0xfffff)) |(sizeof(RxBuffer0)/4); rDMASKTRIG1 = (1<<1); // IIS RX打開DMA1通道 rSUBSRCPND |= (1< } rSRCPND1 |= (1 << INT_DMA); rINTPND1 |= (1 << INT_DMA); } unsignedint IIS_WriteBuffer(unsigned char *pData, unsigned int MaxLen) { unsigned int i; unsigned int nCount; // 能寫入buffer中數據長度(以字計,fifo 32位長) unsigned int *pBuffer; unsigned char *pTemp = pData; if (pTemp==0 || MaxLen==0) { return 0; // 參數錯誤,數據未寫入緩存 } if ((TxBufferFlag&0x3) == 0x3) { return 0; // Buffer0,Buffer1均已寫滿 } if (!(TxBufferFlag & (1<<0))) { //Buffer0需填充 pBuffer = &TxBuffer0[TxCount]; } else { // Buffer1需填充 pBuffer = &TxBuffer1[TxCount]; } nCount = (sizeof(TxBuffer0)/4) - TxCount; switch (TX_BitLen) { case 8: if (TX_Channel != 1) { // 雙聲道 if (MaxLen/2 == 0) {// 左右聲道fifo中有兩個8位有效音頻數據 pTemp += MaxLen; // 不足一個采樣2字節(jié)數據,丟棄寫入buffer中 } MaxLen = MaxLen/2; // 32位的fifo中有兩個8位有效音頻數據 if (MaxLen < nCount) { nCount = MaxLen; } for (i=0; i *pBuffer++ = (((unsignedint)pTemp[1]<<16)+ ((unsignedint)pTemp[0]<<0)); pTemp += 2; // 2個8位的聲道數據已寫入buffer中 } } else { // 單聲道 if (MaxLen < nCount) {// 32位的fifo中有一個8位有效音頻數據 nCount = MaxLen; } for (i=0; i *pBuffer++ = (unsignedint)pTemp[0]<<0; pTemp += 1; // 1個8位的聲道數據已寫入FIFO中 } } break; case 16: if (TX_Channel != 1) { // 雙聲道 if (MaxLen/4 == 0) {// 左右聲道fifo中有四個8位有效音頻數據 pTemp += MaxLen; // 不足一個采樣4字節(jié)數據,丟棄寫入buffer中 } MaxLen = MaxLen/4; // 32位的fifo中有四個8位有效音頻數據 if (MaxLen < nCount) { nCount = MaxLen; } for (i=0; i *pBuffer++ = (((unsignedint)pTemp[0]<<0) + ((unsignedint)pTemp[1]<<8)) +