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

📄 vs10xx_8c-source.html

📁 MP3播放器源代码, VS1003B
💻 HTML
📖 第 1 页 / 共 2 页
字号:
<!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>VLSI Solution Oy Evaluation MP3 Player Source Code Documentation</title><link href="doxygen.css" rel="stylesheet" type="text/css"><img src="vlsi_small.gif" hspace="20" bordercolor="#ffffff"  alt="VLSI Solution Oy"><b>VLSI Solution Oy Evaluation MP3 Player Source Code Documentation</b><p></p></head><body><!-- Generated by Doxygen 1.3.7 --><div class="qindex"><a class="qindex" href="index.html">Main&nbsp;Page</a> | <a class="qindex" href="annotated.html">Class&nbsp;List</a> | <a class="qindex" href="files.html">File&nbsp;List</a> | <a class="qindex" href="functions.html">Class&nbsp;Members</a> | <a class="qindex" href="globals.html">File&nbsp;Members</a> | <a class="qindex" href="pages.html">Related&nbsp;Pages</a></div><h1>vs10xx.c</h1><a href="vs10xx_8c.html">Go to the documentation of this file.</a><pre class="fragment"><div>00001 00007 <span class="preprocessor">#include "<a class="code" href="vs10xx_8h.html">vs10xx.h</a>"</span>00008 <span class="preprocessor">#include "<a class="code" href="lcd_8h.html">lcd.h</a>"</span>00009 <span class="preprocessor">#include "<a class="code" href="filesys_8h.html">filesys.h</a>"</span>00010 <span class="preprocessor">#include "<a class="code" href="storage_8h.html">storage.h</a>"</span>00011 <span class="preprocessor">#include "<a class="code" href="ui_8h.html">ui.h</a>"</span>00012 00013 00014 00015 <a name="l00017"></a><a class="code" href="vs10xx_8h.html#a38">00017</a> <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> <a class="code" href="vs10xx_8h.html#a38">Mp3ReadRegister</a> (<span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> addressbyte){00018   <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> resultvalue = 0;00019 00020   <a class="code" href="board_8h.html#a4">Mp3SelectControl</a>();00021   <a class="code" href="board_8h.html#a45">SPIPutCharWithoutWaiting</a>(<a class="code" href="vs10xx_8h.html#a1">VS_READ_COMMAND</a>);00022   <a class="code" href="board_8h.html#a44">SPIPutChar</a>((addressbyte));00023   <a class="code" href="board_8h.html#a44">SPIPutChar</a>(0xff);00024   <a class="code" href="board_8h.html#a43">SPIWait</a>();00025   resultvalue = (<a class="code" href="board_8h.html#a46">SPI_RESULT_BYTE</a>) &lt;&lt; 8;00026   <a class="code" href="board_8h.html#a45">SPIPutCharWithoutWaiting</a>(0xff);00027   <a class="code" href="board_8h.html#a43">SPIWait</a>();00028   resultvalue |= (<a class="code" href="board_8h.html#a46">SPI_RESULT_BYTE</a>);00029   <a class="code" href="board_8h.html#a5">Mp3DeselectControl</a>();00030   <span class="keywordflow">return</span> resultvalue;00031 }00032   00033 <a name="l00035"></a><a class="code" href="vs10xx_8h.html#a37">00035</a> <span class="keywordtype">void</span> <a class="code" href="vs10xx_8c.html#a2">Mp3SoftReset</a>(){00036 00037   <span class="comment">/* Soft Reset of VS10xx */</span>00038   <a class="code" href="vs10xx_8h.html#a32">Mp3WriteRegister</a> (<a class="code" href="vs10xx_8h.html#a2">SPI_MODE</a>, 0x08, 0x04); <span class="comment">/* Newmode, Reset, No L1-2 */</span>00039 00040   <a class="code" href="board_8h.html#a51">Delay</a>(1); <span class="comment">/* One millisecond delay */</span>00041   <span class="keywordflow">while</span> (!<a class="code" href="board_8h.html#a9">MP3_DREQ</a>) <span class="comment">/* wait for startup */</span>00042     ;00043   00044   <span class="comment">/* Set clock register, doubler etc. */</span>00045 <span class="preprocessor">#ifdef VS1003</span>00046 <span class="preprocessor"></span>  <a class="code" href="vs10xx_8h.html#a32">Mp3WriteRegister</a>(<a class="code" href="vs10xx_8h.html#a5">SPI_CLOCKF</a>, 0xa6, 0x96);00047 <span class="preprocessor">#else</span>00048 <span class="preprocessor"></span>  <a class="code" href="vs10xx_8h.html#a32">Mp3WriteRegister</a>(<a class="code" href="vs10xx_8h.html#a5">SPI_CLOCKF</a>, 156, 204);00049 <span class="preprocessor">#endif</span>00050 <span class="preprocessor"></span>  00051   <a class="code" href="board_8h.html#a51">Delay</a>(1); <span class="comment">/* One millisecond delay */</span>00052 00053  00054   <span class="comment">/* Send null bytes to data interface */</span>00055   <a class="code" href="board_8h.html#a7">Mp3SelectData</a>();00056   <a class="code" href="board_8h.html#a45">SPIPutCharWithoutWaiting</a>(0);00057   <a class="code" href="board_8h.html#a44">SPIPutChar</a>(0);00058   <a class="code" href="board_8h.html#a44">SPIPutChar</a>(0);00059   <a class="code" href="board_8h.html#a44">SPIPutChar</a>(0);00060   <a class="code" href="board_8h.html#a43">SPIWait</a>();00061   <a class="code" href="board_8h.html#a8">Mp3DeselectData</a>();00062 00063 }00064 00065 00066 00067 <a name="l00069"></a><a class="code" href="vs10xx_8h.html#a36">00069</a> <span class="keywordtype">void</span> <a class="code" href="vs10xx_8c.html#a3">Mp3Reset</a>(){00070 00071   <a class="code" href="board_8h.html#a1">Mp3PutInReset</a>();00072   <a class="code" href="board_8h.html#a51">Delay</a>(1);00073 00074   <span class="comment">/* Send dummy SPI byte to initialize SPI */</span>00075   <a class="code" href="board_8h.html#a45">SPIPutCharWithoutWaiting</a>(0xFF);00076 00077   <span class="comment">/* Un-reset MP3 chip */</span>00078   <a class="code" href="board_8h.html#a5">Mp3DeselectControl</a>();00079   <a class="code" href="board_8h.html#a8">Mp3DeselectData</a>();00080   <a class="code" href="board_8h.html#a2">Mp3ReleaseFromReset</a>();00081   <a class="code" href="vs10xx_8h.html#a33">Mp3SetVolume</a>(0xff,0xff);00082   00083   <span class="comment">/* Set clock register, doubler etc. */</span>00084 <span class="preprocessor">#ifdef VS1003</span>00085 <span class="preprocessor"></span>  <a class="code" href="vs10xx_8h.html#a32">Mp3WriteRegister</a>(<a class="code" href="vs10xx_8h.html#a5">SPI_CLOCKF</a>, 0xa6, 0x96); <span class="comment">//oli 0xa66c</span>00086 <span class="preprocessor">#else</span>00087 <span class="preprocessor"></span>  <a class="code" href="vs10xx_8h.html#a32">Mp3WriteRegister</a>(<a class="code" href="vs10xx_8h.html#a5">SPI_CLOCKF</a>, 156, 204);00088 <span class="preprocessor">#endif</span>00089 <span class="preprocessor"></span>  00090   <span class="comment">/* Wait for DREQ */</span>00091   <span class="keywordflow">while</span> (!<a class="code" href="board_8h.html#a9">MP3_DREQ</a>)00092     ;00093   00094   <span class="comment">/* Slow sample rate for slow analog part startup */</span>00095   <a class="code" href="vs10xx_8h.html#a32">Mp3WriteRegister</a>(<a class="code" href="vs10xx_8h.html#a7">SPI_AUDATA</a>, 0, 10); <span class="comment">/* 10 Hz */</span>00096   <a class="code" href="board_8h.html#a51">Delay</a>(100);00097 00098   <span class="comment">/* Switch on the analog parts */</span>00099   <a class="code" href="vs10xx_8h.html#a33">Mp3SetVolume</a>(0xfe,0xfe);00100   <a class="code" href="vs10xx_8h.html#a32">Mp3WriteRegister</a> (<a class="code" href="vs10xx_8h.html#a7">SPI_AUDATA</a>, 31, 64); <span class="comment">/* 8kHz */</span>00101   <a class="code" href="vs10xx_8h.html#a33">Mp3SetVolume</a>(20,20);00102   <a class="code" href="vs10xx_8c.html#a2">Mp3SoftReset</a>();00103   <a class="code" href="board_8h.html#a42">SPISetFastClock</a>();00104   00105 00106   ConsoleWrite (<span class="stringliteral">"Init: VS10XX\r"</span>);00107 00108 }00109 00110 <a name="l00112"></a><a class="code" href="vs10xx_8h.html#a35">00112</a> <span class="keywordtype">void</span> <a class="code" href="vs10xx_8c.html#a4">VsSineTest</a>(){00113 00114   <span class="comment">/* Reset MP3 chip */</span>00115   <a class="code" href="board_8h.html#a1">Mp3PutInReset</a>();       <span class="comment">/* Pull xRESET low -&gt; hardware reset */</span>00116   <a class="code" href="board_8h.html#a51">Delay</a>(100);            <span class="comment">/* 100 ms delay */</span>00117 00118   <span class="comment">/* Send dummy SPI byte to initialize SPI of Atmel microcontroller */</span>00119   <a class="code" href="board_8h.html#a45">SPIPutCharWithoutWaiting</a>(0xFF);00120 00121   <span class="comment">/* Un-reset MP3 chip */</span>00122   <a class="code" href="board_8h.html#a5">Mp3DeselectControl</a>();  <span class="comment">/* Pull xCS high    */</span>00123   <a class="code" href="board_8h.html#a8">Mp3DeselectData</a>();     <span class="comment">/* Pull xDCS high   */</span>00124   <a class="code" href="board_8h.html#a2">Mp3ReleaseFromReset</a>(); <span class="comment">/* Pull xRESET high */</span>00125   <a class="code" href="board_8h.html#a51">Delay</a>(100);            <span class="comment">/* 100 ms delay     */</span>00126 00127   <a class="code" href="board_8h.html#a11">GREEN_LED</a> = <a class="code" href="board_8h.html#a12">LED_ON</a>;00128   <a class="code" href="board_8h.html#a10">RED_LED</a> = <a class="code" href="board_8h.html#a12">LED_ON</a>;00129 00130   <span class="comment">/* VS10xx Application Notes, chapter 4.8 ---------------------------------*/</span>00131   <span class="comment">/* As an example, let's write value 0x0820 to register 00 byte by byte    */</span>00132   <a class="code" href="board_8h.html#a4">Mp3SelectControl</a>();    <span class="comment">/* Now SPI writes go to SCI port                   */</span>00133   <a class="code" href="board_8h.html#a44">SPIPutChar</a>(0x02);      <span class="comment">/* Send SPI Byte, then wait for byte to be sent.   */</span>00134   <a class="code" href="board_8h.html#a44">SPIPutChar</a>(0x00);      <span class="comment">/* 0x02 was WRITE command, 0x00 is register number */</span>00135   <a class="code" href="board_8h.html#a44">SPIPutChar</a>(0x08);      <span class="comment">/* This byte goes to MSB                           */</span>00136   <a class="code" href="board_8h.html#a44">SPIPutChar</a>(0x20);      <span class="comment">/* ..and this is LSB. (0x20=Allow Test Mode)       */</span>00137   <a class="code" href="board_8h.html#a43">SPIWait</a>();             <span class="comment">/* Wait until Atmel MCU signals SPI write complete */</span>00138   <a class="code" href="board_8h.html#a5">Mp3DeselectControl</a>();  <span class="comment">/* Now SPI writes don't go to SCI port             */</span>00139 00140   <span class="keywordflow">while</span> (!<a class="code" href="board_8h.html#a9">MP3_DREQ</a>)      <span class="comment">/* Wait for DREQ = 1                               */</span>00141     ;                    <span class="comment">/* Do nothing while waiting for DREQ = 1           */</span>00142 00143   <span class="comment">/* Send a Sine Test Header to Data port                                   */</span>00144   <a class="code" href="board_8h.html#a7">Mp3SelectData</a>();       <span class="comment">/* Now SPI writes go to SDI port                   */</span>00145 00146   <a class="code" href="board_8h.html#a44">SPIPutChar</a>(0x53);      <span class="comment">/* - This is a special VLSI Solution test header - */</span>00147   <a class="code" href="board_8h.html#a44">SPIPutChar</a>(0xef);      <span class="comment">/* - that starts a sine sound. It's good for     - */</span>00148   <a class="code" href="board_8h.html#a44">SPIPutChar</a>(0x6e);      <span class="comment">/* - testing your code, the chip and also for    - */</span>00149   <a class="code" href="board_8h.html#a44">SPIPutChar</a>(0x44);      <span class="comment">/* - seeing if your MP3 decoder was manufactured - */</span>00150   <a class="code" href="board_8h.html#a44">SPIPutChar</a>(0x00);      <span class="comment">/* - by VLSI Solution oy. ------------------------ */</span>00151   <a class="code" href="board_8h.html#a44">SPIPutChar</a>(0x00);00152   <a class="code" href="board_8h.html#a44">SPIPutChar</a>(0x00);00153   <a class="code" href="board_8h.html#a44">SPIPutChar</a>(0x00);00154   <a class="code" href="board_8h.html#a43">SPIWait</a>();00155   <a class="code" href="board_8h.html#a8">Mp3DeselectData</a>();00156   00157   <a class="code" href="board_8h.html#a10">RED_LED</a> = <a class="code" href="board_8h.html#a13">LED_OFF</a>;00158   <a class="code" href="board_8h.html#a51">Delay</a> (500);           <span class="comment">/* 500 ms delay */</span>00159   <a class="code" href="board_8h.html#a11">GREEN_LED</a> = <a class="code" href="board_8h.html#a13">LED_OFF</a>;00160 00161   <span class="comment">/* Stop the sine test sound */</span>00162   <a class="code" href="board_8h.html#a7">Mp3SelectData</a>();00163   <a class="code" href="board_8h.html#a44">SPIPutChar</a>(0x45);00164   <a class="code" href="board_8h.html#a44">SPIPutChar</a>(0x78);00165   <a class="code" href="board_8h.html#a44">SPIPutChar</a>(0x69);00166   <a class="code" href="board_8h.html#a44">SPIPutChar</a>(0x74);00167   <a class="code" href="board_8h.html#a44">SPIPutChar</a>(0x00);00168   <a class="code" href="board_8h.html#a44">SPIPutChar</a>(0x00);00169   <a class="code" href="board_8h.html#a44">SPIPutChar</a>(0x00);00170   <a class="code" href="board_8h.html#a44">SPIPutChar</a>(0x00);00171   <a class="code" href="board_8h.html#a43">SPIWait</a>();00172   <a class="code" href="board_8h.html#a8">Mp3DeselectData</a>();00173 00174   <a class="code" href="board_8h.html#a51">Delay</a>(500);            <span class="comment">/* 500 ms delay */</span>00175 }  00176 <a name="l00178"></a><a class="code" href="vs10xx_8h.html#a39">00178</a> <span class="keywordtype">void</span> <a class="code" href="vs10xx_8c.html#a5">SendZerosToVS10xx</a>(){00179   <a class="code" href="board_8h.html#a7">Mp3SelectData</a>();00180   <a class="code" href="board_8h.html#a45">SPIPutCharWithoutWaiting</a>(0);00181   <span class="keywordflow">for</span> (<a class="code" href="board_8c.html#a0">temp</a>.<a class="code" href="unionTemp.html#o1">i</a>=0; <a class="code" href="board_8c.html#a0">temp</a>.<a class="code" href="unionTemp.html#o1">i</a>&lt;1048; <a class="code" href="board_8c.html#a0">temp</a>.<a class="code" href="unionTemp.html#o1">i</a>++){ <span class="comment">/* TESTING 1048 TESTING */</span>00182     <span class="keywordflow">while</span> (!<a class="code" href="board_8h.html#a9">MP3_DREQ</a>)00183       ;00184     <a class="code" href="board_8h.html#a44">SPIPutChar</a>(0);00185   }

⌨️ 快捷键说明

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