📄 aic23b_8c-source.html
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html><head><meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1"><title>Procyon ARMlib-LPC2100: aic23b.c Source File</title><link href="dox.css" rel="stylesheet" type="text/css"></head><body><!-- Generated by Doxygen 1.3.6 --><div class="qindex"><a class="qindex" href="main.html">Main Page</a> | <a class="qindex" href="files.html">File List</a> | <a class="qindex" href="globals.html">Globals</a></div><h1>aic23b.c</h1><a href="aic23b_8c.html">Go to the documentation of this file.</a><div class="fragment"><pre>00001 <span class="comment">/*! \file aic23b.c \brief TI TLV320AIC23B Audio Codec Driver. */</span>00002 <span class="comment">//*****************************************************************************</span>00003 <span class="comment">//</span>00004 <span class="comment">// File Name : 'aic23b.c'</span>00005 <span class="comment">// Title : TI TLV320AIC23B Audio Codec Driver</span>00006 <span class="comment">// Author : Pascal Stang - Copyright (C) 2004</span>00007 <span class="comment">// Created : 2004.05.05</span>00008 <span class="comment">// Revised : 2004.07.12</span>00009 <span class="comment">// Version : 0.1</span>00010 <span class="comment">// Target MCU : ARM processors</span>00011 <span class="comment">// Editor Tabs : 4</span>00012 <span class="comment">//</span>00013 <span class="comment">// NOTE: This code is currently below version 1.0, and therefore is considered</span>00014 <span class="comment">// to be lacking in some functionality or documentation, or may not be fully</span>00015 <span class="comment">// tested. Nonetheless, you can expect most functions to work.</span>00016 <span class="comment">//</span>00017 <span class="comment">// This code is distributed under the GNU Public License</span>00018 <span class="comment">// which can be found at http://www.gnu.org/licenses/gpl.txt</span>00019 <span class="comment">//</span>00020 <span class="comment">//*****************************************************************************</span>00021 00022 <span class="preprocessor">#include "<a class="code" href="global_8h.html">global.h</a>"</span>00023 <span class="preprocessor">#include "config.h"</span>00024 <span class="preprocessor">#include "<a class="code" href="i2c_8h.html">i2c.h</a>"</span>00025 <span class="preprocessor">#include "<a class="code" href="spi_8h.html">spi.h</a>"</span>00026 <span class="preprocessor">#include "lpc210x.h"</span>00027 <span class="preprocessor">#include "armVIC.h"</span>00028 <span class="preprocessor">#include "<a class="code" href="aic23b_8h.html">aic23b.h</a>"</span>00029 00030 <span class="keyword">volatile</span> u32 AicSpiCount = 0;00031 <span class="keyword">volatile</span> u32 *SpiDataPtr;00032 <span class="keyword">volatile</span> u32 SpiData = 0;00033 <span class="keyword">volatile</span> u08 SpiDatab[6];00034 <span class="keyword">volatile</span> u32 SpiCount = 0;00035 00036 <span class="comment">// Sin wave table (256 steps, 16-bit output)</span>00037 <span class="keywordtype">signed</span> <span class="keywordtype">short</span> SinTable256_16[] = {00038 0, 804, 1608, 2410, 3212, 4011, 4808, 5602, 00039 6393, 7179, 7962, 8739, 9512, 10278, 11039, 11793, 00040 12539, 13279, 14010, 14732, 15446, 16151, 16846, 17530, 00041 18204, 18868, 19519, 20159, 20787, 21403, 22005, 22594, 00042 23170, 23731, 24279, 24811, 25329, 25832, 26319, 26790, 00043 27245, 27683, 28105, 28510, 28898, 29268, 29621, 29956, 00044 30273, 30571, 30852, 31113, 31356, 31580, 31785, 31971, 00045 32137, 32285, 32412, 32521, 32609, 32678, 32728, 32757, 00046 32767, 32757, 32728, 32678, 32609, 32521, 32412, 32285, 00047 32137, 31971, 31785, 31580, 31356, 31113, 30852, 30571, 00048 30273, 29956, 29621, 29268, 28898, 28510, 28105, 27683, 00049 27245, 26790, 26319, 25832, 25329, 24811, 24279, 23731, 00050 23170, 22594, 22005, 21403, 20787, 20159, 19519, 18868, 00051 18204, 17530, 16846, 16151, 15446, 14732, 14010, 13279, 00052 12539, 11793, 11039, 10278, 9512, 8739, 7962, 7179, 00053 6393, 5602, 4808, 4011, 3212, 2410, 1608, 804, 00054 0, -804, -1608, -2410, -3212, -4011, -4808, -5602, 00055 -6393, -7179, -7962, -8739, -9512, -10278, -11039, -11793, 00056 -12539, -13279, -14010, -14732, -15446, -16151, -16846, -17530, 00057 -18204, -18868, -19519, -20159, -20787, -21403, -22005, -22594, 00058 -23170, -23731, -24279, -24811, -25329, -25832, -26319, -26790, 00059 -27245, -27683, -28105, -28510, -28898, -29268, -29621, -29956, 00060 -30273, -30571, -30852, -31113, -31356, -31580, -31785, -31971, 00061 -32137, -32285, -32412, -32521, -32609, -32678, -32728, -32757, 00062 -32767, -32757, -32728, -32678, -32609, -32521, -32412, -32285, 00063 -32137, -31971, -31785, -31580, -31356, -31113, -30852, -30571, 00064 -30273, -29956, -29621, -29268, -28898, -28510, -28105, -27683, 00065 -27245, -26790, -26319, -25832, -25329, -24811, -24279, -23731, 00066 -23170, -22594, -22005, -21403, -20787, -20159, -19519, -18868, 00067 -18204, -17530, -16846, -16151, -15446, -14732, -14010, -13279, 00068 -12539, -11793, -11039, -10278, -9512, -8739, -7962, -7179, 00069 -6393, -5602, -4808, -4011, -3212, -2410, -1608, -804, 00070 };00071 00072 00073 <span class="keywordtype">void</span> aicInit(<span class="keywordtype">void</span>)00074 {00075 <a class="code" href="i2c_8c.html#a0">i2cInit</a>();00076 00077 aicWriteReg(AIC_REG_RESET);00078 aicWriteReg(AIC_REG_POWERDOWN | BIT(AIC_PD_MIC));00079 aicWriteReg(AIC_REG_ANALOG_PATH | BIT(AIC_AP_DAC));00080 aicWriteReg(AIC_REG_DIGITAL_PATH | BIT(AIC_DP_DEEMP1));00081 00082 <span class="comment">// preset volume</span>00083 aicSetVolumeHp(5);00084 }00085 00086 <span class="keywordtype">int</span> aicWriteReg(u16 regdata)00087 {00088 u08 packet[2];00089 packet[0] = regdata>>8;00090 packet[1] = regdata;00091 <span class="keywordflow">if</span>(<a class="code" href="i2c_8h.html#a53">i2cMasterSendNI</a>(AIC_I2C_ADDR, 2, packet) == I2C_OK)00092 <span class="keywordflow">return</span> TRUE;00093 <span class="keywordflow">else</span>00094 <span class="keywordflow">return</span> FALSE;00095 }00096 00097 <span class="keywordtype">void</span> aicSetVolumeLineIn(u08 volume)00098 {00099 <span class="comment">// limit and bitmask</span>00100 volume = MIN(volume,31);00101 volume &= 0x001F;00102 <span class="comment">// write to left and right channel</span>00103 aicWriteReg(AIC_REG_VOL_LINEIN_LEFT |00104 volume | BIT(AIC_VLIL_LIM) | BIT(AIC_VLIL_LRS));00105 }00106 00107 <span class="keywordtype">void</span> aicSetVolumeHp(u08 volume)00108 {00109 <span class="comment">// add mute offset</span>00110 volume += 0x30;00111 <span class="comment">// limit and bitmask</span>00112 volume = MIN(volume,127);00113 volume &= 0x007F;00114 <span class="comment">// write to left and right channel</span>00115 aicWriteReg(AIC_REG_VOL_HP_LEFT |00116 volume | BIT(AIC_VHPL_LZC) | BIT(AIC_VHPL_LRS));00117 }00118 00119 <span class="keywordtype">void</span> aicDigitalEnable(<span class="keywordtype">void</span>)00120 {00121 <span class="comment">// setup digital data format</span>00122 aicWriteReg(AIC_REG_INTERFACE_FORMAT | BIT(AIC_IF_MS)00123 | AIC_IF_24BIT | AIC_IF_DSP);00124 00125 <span class="comment">// set sample rate</span>00126 aicWriteReg(AIC_REG_SAMPLE_RATE |00127 BIT(AIC_SR_CLKIN) | BIT(AIC_SR_CLKOUT) | AIC_SR_18432_48KHZ);00128 00129 <span class="comment">// activate digital interface</span>00130 aicWriteReg(AIC_REG_DIGITAL_IF_ACT | 0x01);00131 }00132 00133 <span class="keywordtype">void</span> aicSpiInit(<span class="keywordtype">void</span>)00134 {00135 spiInit();00136 00137 <span class="comment">// switch to slave mode</span>00138 SPCR &= BIT(SPCR_MSTR);00139 <span class="comment">// enable the SPI interrupt</span>00140 SPCR |= BIT(SPCR_SPIE);00141 00142 <span class="comment">// initialize the interrupt vector</span>00143 VICIntSelect &= ~VIC_BIT(VIC_SPI); <span class="comment">// SPI selected as IRQ</span>00144 VICVectCntl1 = VIC_ENABLE | VIC_SPI; <span class="comment">// SPI on VIC vector 1</span>00145 VICVectAddr1 = (uint32_t)aicSpiService; <span class="comment">// address of the ISR</span>00146 VICIntEnable = VIC_BIT(VIC_SPI); <span class="comment">// SPI interrupt enabled</span>00147 <span class="comment">/*</span>00148 <span class="comment"> // initialize the FIQ vector</span>00149 <span class="comment"> VICIntSelect |= VIC_BIT(VIC_SPI); // SPI selected as FIQ</span>00150 <span class="comment"> VICIntEnable = VIC_BIT(VIC_SPI); // SPI interrupt enabled</span>00151 <span class="comment">*/</span>00152 <span class="comment">// initialize the interrupt vector</span>00153 VICIntSelect &= ~VIC_BIT(VIC_TIMER1); <span class="comment">// TIMER1 selected as IRQ</span>00154 VICVectCntl0 = VIC_ENABLE | VIC_TIMER1; <span class="comment">// TIMER1 on VIC vector 0</span>00155 VICVectAddr0 = (uint32_t)aicLRCService; <span class="comment">// address of the ISR</span>00156 VICIntEnable = VIC_BIT(VIC_TIMER1); <span class="comment">// TIMER1 interrupt enabled</span>00157 00158 <span class="comment">// setup timer1</span>00159 <span class="comment">// set pinselect</span>00160 PINSEL0 &= ~(1<<20);00161 PINSEL0 |= (1<<21);00162 <span class="comment">// start timer</span>00163 T1TCR = TCR_ENABLE;00164 <span class="comment">// enable timer1 interrupt on CR0 rising edge</span>00165 T1CCR = TCCR_CR0_I | TCCR_CR0_R;00166 00167 <span class="comment">// initialize SPI SS driver</span>00168 IODIR |= BIT(12);00169 <span class="comment">// assert address</span>00170 IOCLR = BIT(12);00171 IOSET = BIT(12);00172 00173 AicSpiCount = 0;00174 SpiData = 0;00175 SpiCount = 3;00176 SpiDataPtr = &SpiData;00177 }00178 00179 u32 aicGetSampleCount(<span class="keywordtype">void</span>)00180 {00181 <span class="keywordflow">return</span> AicSpiCount;00182 }00183 00184 <span class="keywordtype">void</span> aicClearSampleCount(<span class="keywordtype">void</span>)00185 {00186 AicSpiCount = 0;00187 }00188 00189 <span class="keywordtype">void</span> fast_interrupt_exception(<span class="keywordtype">void</span>)00190 {00191 <span class="comment">// perform proper ISR entry so thumb-interwork works properly</span>00192 ISR_ENTRY();00193 <span class="comment">// recover registers and return</span>00194 ISR_EXIT();00195 }00196 00197 <span class="keywordtype">void</span> aicLRCService(<span class="keywordtype">void</span>)00198 {00199 ISR_ENTRY();00200 <span class="comment">// clear CR0 Interrupt</span>00201 T1IR |= TIR_CR0I;00202 VICSoftIntClear = (1<<VIC_TIMER1);00203 00204 <span class="comment">//VICIntEnable = VIC_BIT(VIC_SPI); // SPI interrupt enabled</span>00205 IOCLR = BIT(12);00206 SpiCount=3;00207 SpiData = (AicSpiCount>>8) | ((AicSpiCount<<8) & 0xFF00);00208 <span class="comment">//SpiDataPtr = &SpiData;</span>00209 AicSpiCount++;00210 00211 VICVectAddr = 0x00000000; <span class="comment">// clear this interrupt from the VIC</span>00212 ISR_EXIT(); <span class="comment">// recover registers and return</span>00213 }00214 00215 <span class="keywordtype">void</span> aicSpiService(<span class="keywordtype">void</span>)00216 {00217 u32 data;00218 00219 <span class="comment">// perform proper ISR entry so thumb-interwork works properly</span>00220 ISR_ENTRY();00221 <span class="comment">// clear SPI interrupt</span>00222 SPINT = 0x01;00223 <span class="comment">//VICSoftIntClear = VIC_BIT(VIC_SPI);</span>00224 00225 data = SPSR;00226 00227 <span class="comment">// if(SPSR & BIT(SPSR_SPIF))</span>00228 <span class="comment">// {</span>00229 <span class="comment">// }</span>00230 00231 <span class="comment">// read the data</span>00232 <span class="comment">//data = SPDR;</span>00233 <span class="comment">// write the data</span>00234 SPDR = SpiDatab[0];00235 <span class="comment">//SPDR = SpiData;</span>00236 SpiData = SpiData>>8;00237 SpiCount--;00238 <span class="keywordflow">if</span>(!SpiCount)00239 {00240 <span class="comment">//VICIntEnClear = VIC_BIT(VIC_SPI); // SPI interrupt disabled</span>00241 IOSET = BIT(12);00242 }00243 00244 <span class="comment">// AicSpiCount++;</span>00245 00246 <span class="comment">// clear this interrupt from the VIC</span>00247 VICVectAddr = 0x00000000;00248 <span class="comment">// recover registers and return</span>00249 ISR_EXIT();00250 }</pre></div><hr size="1"><address style="align: right;"><small>Generated on Tue Jul 13 03:38:11 2004 for Procyon ARMlib-LPC2100 by<a href="http://www.doxygen.org/index.html"><img src="doxygen.png" alt="doxygen" align="middle" border=0 > </a>1.3.6 </small></address></body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -