📄 audioinit.c
字号:
break; } /* For playback, we map AC97 slot 3 and 4(Left & Right PCM playback) to DMA Channel 0. Set the fifo to be 15 bytes at offset zero. */ ac97_slotid = 0x01000f00; writel(ac97_slotid, CS4281_pBA0 + BA0_FCR0); writel(ac97_slotid | FCRn_FEN, CS4281_pBA0 + BA0_FCR0); /* Map the Playback SRC to the same AC97 slots(3 & 4-- --Playback left & right)as DMA channel 0. Map the record SRC to the same AC97 slots(10 & 11-- -- Record left & right) as DMA channel 1. */ ac97_slotid = 0x0b0a0100; writel(ac97_slotid, CS4281_pBA0 + BA0_SRCSA); /* Set 'Half Terminal Count Interrupt Enable' and 'Terminal Count Interrupt Enable' in DMA Control Registers 0 & 1. Set 'MSK' flag to 1 to keep the DMA engines paused. */ temp1 = (DCRn_HTCIE | DCRn_TCIE | DCRn_MSK); writel(temp1, CS4281_pBA0 + BA0_DCR0); /* Set 'Auto-Initialize Control' to 'enabled'; For playback, set 'Transfer Type Control'(TR[1:0]) to 'read transfer', for record, set Transfer Type Control to 'write transfer'. All other bits set to zero; Some will be changed @ transfer start. */ temp1 = (DMRn_DMA | DMRn_AUTO | DMRn_TR_READ); writel(temp1, CS4281_pBA0 + BA0_DMR0); /* Enable DMA interrupts generally, and DMA0 & DMA1 interrupts specifically. */ temp1 = readl(CS4281_pBA0 + BA0_HIMR) & 0xfffbfcff; writel(temp1, CS4281_pBA0+BA0_HIMR); printf("\nCS4281 Hardware Initialization Complete!!\n"); return 0;} /*------------------------- Start DAC / Stop DAC ------------------------*/void start_dac(void){ UINT32 temp1; int lockkey; lockkey = intLock(); /* enable DMA0 */ temp1 = readl(CS4281_pBA0+BA0_DCR0); writel(temp1 & ~DCRn_MSK, CS4281_pBA0+BA0_DCR0); /* enable Interrupt */ writel(HICR_IEV | HICR_CHGM, CS4281_pBA0+BA0_HICR); writel(0, CS4281_pBA0+BA0_PPRVC); writel(0, CS4281_pBA0+BA0_PPLVC); intUnlock(lockkey);}/*------------------------- set DMAcntl, SampleRate, <8bits unsigned mono> ------------------------*/int prog_codec(void){ UINT32 format; int lockkey; lockkey = intLock(); /* Program record/playback sampling rate -- 11025 */ /* DAC */ format = DMRn_DMA | DMRn_AUTO |DMRn_TR_READ|DMRn_USIGN|DMRn_SIZE8|DMRn_MONO; writel(format, CS4281_pBA0+BA0_DMR0); writel(0x04, CS4281_pBA0+BA0_DACSR); intUnlock(lockkey); return 0;}/*------------------------------------* * Interrupt Service Routine * for * DMA0, DMA1 *------------------------------------*/void cs4281_interrupt(int param){ UINT32 temp1; int lockkey; /*logMsg("\nCW:cs4281-->");*/ /* if it's not DMA interrupts, jump out */ temp1 = readl(CS4281_pBA0+BA0_HISR); if(!(temp1 &(HISR_DMA0 | HISR_DMA1))) { writel(HICR_IEV| HICR_CHGM, CS4281_pBA0+BA0_HICR); return; } /* playback DMA0 */ if(temp1 & HISR_DMA0) { semGive(SEM_DMA_Playback); CNT_DMA_Playback++; if(0x00010000 & readl(CS4281_pBA0+BA0_HDSR0)) { /*DMA Terminal Count */ DTC_DMA_Playback = 1; /*logMsg("playbkDMA0:TC");*/ } else { DTC_DMA_Playback = 0; /*logMsg("playbkDMA0:Half_TC");*/ } } /*logMsg("\n");*/ writel(HICR_IEV| HICR_CHGM, CS4281_pBA0+BA0_HICR);} /********************************************************* * Install the cs4281/ac97 driver: * -bring up the hardware * -allocate and set DMA buffer/DMA engine * -connect ISR to IRQ * -start_adc/dac ********************************************************/ int probe1(){ unsigned int pciBusNo, pciDevNo, pciFuncNo; unsigned char byte; UINT32 s_pBA0, s_pBA1; /* To ensure that taskDelay(1) is 1ms delay */ sysClkRateSet(1000); if (pciConfigLibInit (PCI_MECHANISM_1, 0xCF8, 0xCFC, 0) != OK) { printf("PCI lib config error\n"); return 1; } /**************************** * Find SoundCard * Set BaseAddr0, BaseAddr1 ****************************/ if(!(pciFindDevice(PCI_VENDOR_ID_CIRRUS,PCI_DEVICE_ID_CRYSTAL_CS4281, 0, &pciBusNo, &pciDevNo, &pciFuncNo)==OK)) { printf("\n CS4281 sound card NOT FOUND!!! \n"); return 1; } printf("\n FIND CS4281 sound card, configuring BA0,BA1... \n"); pciConfigOutLong( pciBusNo, pciDevNo, pciFuncNo, PCI_CFG_BASE_ADDRESS_0, CS4281_pBA0); /* pciConfigOutLong( pciBusNo, pciDevNo, pciFuncNo, PCI_CFG_BASE_ADDRESS_1, CS4281_pBA1); */ pciConfigInLong( pciBusNo, pciDevNo, pciFuncNo, PCI_CFG_BASE_ADDRESS_0, &s_pBA0); pciConfigInLong( pciBusNo, pciDevNo, pciFuncNo, PCI_CFG_BASE_ADDRESS_1, &s_pBA1 ); printf ("\npBusNo pDeviceNo pFuncNo pBA0 pBA1\n\n"); printf ("%.8x %.8x %.8x %.8x %.8x \n", pciBusNo, pciDevNo, pciFuncNo, s_pBA0,s_pBA1); /******************************** * Config PCI Device Capability * DMA Master * MEM mapped ********************************/ /* Set the INTA vector */ pciConfigInByte(pciBusNo, pciDevNo, pciFuncNo, PCI_CFG_DEV_INT_LINE, &cs4281_irq); printf("\nFound CS4281 configured for IRQ %d\n", cs4281_irq); pciConfigInByte(pciBusNo, pciDevNo, pciFuncNo, PCI_CFG_DEV_INT_PIN, &byte); printf("\tINT_PIN=%.8x\n", byte); /* Enable the device's capabilities as specified * Bus Master Enable/ Mem Space Enable */ pciConfigOutWord(pciBusNo, pciDevNo, pciFuncNo, PCI_CFG_COMMAND, (unsigned short)0x0006); /*************************** * BringUp Hardware ***************************/ if(cs4281_hw_init()) return 1; /**************************** * Allocate ADC_BUFFER * Allocate DAC_BUFFER * * Hook cs4281_interrupt * * Program CoDec ****************************/ if((DAC_BUFFER=valloc(DAC_BUFFER_SIZE))==NULL) { printf("\n DAC_BUFFER valloc failed!\n"); return 1; } writel((UINT32)DAC_BUFFER+8,CS4281_pBA0 + BA0_DBA0); writel(DAC_BUFFER_SIZE-16, CS4281_pBA0 + BA0_DBC0); /* connect interrupt */ printf("\n Hook cs4281_interrupt to vector %d\n", (INUM_TO_IVEC (cs4281_irq+INT_NUM_IRQ0))); pciIntConnect((INUM_TO_IVEC (cs4281_irq+INT_NUM_IRQ0)), (VOIDFUNCPTR)cs4281_interrupt, 0); sysIntEnablePIC(cs4281_irq); SEM_DMA_Playback = semBCreate(SEM_Q_FIFO,SEM_EMPTY); CNT_DMA_Playback = CNT_DMA_Record = 0; /* program coDec */ printf("\n Program CoDec (sample rate, DMA...)\n"); prog_codec(); /********************************************* * start dac, interrupt is comming... *********************************************/ printf("\n\n>>>Start DAC !!!!!!!!!!\n"); start_dac(); return 0;}VOID tcpRecvTask( int sockfd/* server's socket fd */ ){ logMsg("before the readbuffer.\n"); loadBuffer(adNauseam); logMsg("after the read buffer.\n"); while(1) { logMsg("Before semTake, in loop.\n"); semTake(SEM_DMA_Playback, WAIT_FOREVER); logMsg("After semTake, in loop.\n"); if(DTC_DMA_Playback) memmove(DAC_BUFFER+DAC_BUFFER_SIZE/2,adNauseam, DAC_BUFFER_SIZE/2); else memmove(DAC_BUFFER,adNauseam, DAC_BUFFER_SIZE/2); logMsg("Now sending sound data.\n"); }}void loadBuffer(char b[MAX_LINE]){ int i; for(i=0;i<MAX_LINE;i++) { b[i] = pbdata[i]; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -