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

📄 mmc_8c-source.html

📁 MP3播放器源代码, VS1003B
💻 HTML
📖 第 1 页 / 共 3 页
字号:
00376     <a class="code" href="board_8h.html#a45">SPIPutCharWithoutWaiting</a>(0xff);00377     <a class="code" href="board_8h.html#a43">SPIWait</a>();00378     *<a class="code" href="buffer_8c.html#a1">dataBufPtr</a>++=<a class="code" href="board_8h.html#a46">SPI_RESULT_BYTE</a>;00379     <a class="code" href="board_8h.html#a45">SPIPutCharWithoutWaiting</a>(0xff);00380     <a class="code" href="board_8h.html#a43">SPIWait</a>();00381     *<a class="code" href="buffer_8c.html#a1">dataBufPtr</a>++=<a class="code" href="board_8h.html#a46">SPI_RESULT_BYTE</a>;00382     <a class="code" href="board_8h.html#a45">SPIPutCharWithoutWaiting</a>(0xff);00383     <a class="code" href="board_8h.html#a43">SPIWait</a>();00384     *<a class="code" href="buffer_8c.html#a1">dataBufPtr</a>++=<a class="code" href="board_8h.html#a46">SPI_RESULT_BYTE</a>;00385     <a class="code" href="board_8h.html#a45">SPIPutCharWithoutWaiting</a>(0xff);00386     <a class="code" href="board_8h.html#a43">SPIWait</a>();00387     *<a class="code" href="buffer_8c.html#a1">dataBufPtr</a>++=<a class="code" href="board_8h.html#a46">SPI_RESULT_BYTE</a>;00388   }00389 00390 <span class="preprocessor">#ifdef MMCDEBUG</span>00391 <span class="preprocessor"></span>    ConsoleWrite(<span class="stringliteral">"R&gt;"</span>);00392 <span class="preprocessor">#endif</span>00393 <span class="preprocessor"></span>00394 }00395 <a name="l00397"></a><a class="code" href="mmc_8c.html#a7">00397</a> <span class="keywordtype">void</span> <a class="code" href="mmc_8c.html#a7">ConsoleDecipherMMCResponse</a>(<span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> c){00398 00399     ConsoleWrite (<span class="stringliteral">"\rSeek failed, MMC returns "</span>);00400     ConsolePutHex8 (c);00401     ConsoleWrite (<span class="stringliteral">"h ("</span>);00402         00403     <span class="keywordflow">if</span> (c&amp;128) ConsoleWrite(<span class="stringliteral">"which is NOT an R1 response!!"</span>);00404     <span class="keywordflow">else</span>{00405       <span class="keywordflow">if</span> (c&amp;64) ConsoleWrite(<span class="stringliteral">"ParameterError "</span>);00406       <span class="keywordflow">if</span> (c&amp;32) ConsoleWrite(<span class="stringliteral">"AddressError "</span>);00407       <span class="keywordflow">if</span> (c&amp;16) ConsoleWrite(<span class="stringliteral">"EraseSequenceError "</span>);00408       <span class="keywordflow">if</span> (c&amp;8) ConsoleWrite(<span class="stringliteral">"CommandCrcError "</span>);00409       <span class="keywordflow">if</span> (c&amp;4) ConsoleWrite(<span class="stringliteral">"IllegalCommandCode "</span>);00410       <span class="keywordflow">if</span> (c&amp;2) ConsoleWrite(<span class="stringliteral">"EraseCancelled "</span>);00411       <span class="keywordflow">if</span> (c&amp;1) ConsoleWrite(<span class="stringliteral">"Idle "</span>);00412     }00413     00414     ConsoleWrite (<span class="stringliteral">") for sector "</span>);00415     ConsolePutUInt (<a class="code" href="buffer_8c.html#a2">sectorAddress</a>.<a class="code" href="unionAddress.html#o0">l</a>);00416     ConsoleWrite(<span class="stringliteral">".\rFurther reading data returns: \r"</span>);00417     <span class="keywordflow">for</span> (c=0; c&lt;255; c++){00418       ConsolePutHex8(<a class="code" href="board_8c.html#a1">SPIGetChar</a>());     00419     }00420     ConsolePutChar(13);00421     <span class="keywordflow">while</span> (!<a class="code" href="board_8h.html#a14">KEY_BUTTON</a>);00422 00423 00424 }00425 00426 00427 <a name="l00431"></a><a class="code" href="mmc_8h.html#a2">00431</a> <a class="code" href="board_8h.html#a47">Public</a> <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> <a class="code" href="mmc_8h.html#a2">SeekSector</a>(<span class="keywordtype">unsigned</span> <span class="keywordtype">long</span> sectorN){00432   <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> c, retries;00433 00434   retries = 0;00435   <span class="keywordflow">do</span>{00436     retries++;00437     <a class="code" href="buffer_8c.html#a2">sectorAddress</a>.<a class="code" href="unionAddress.html#o0">l</a> = sectorN * 2; <span class="comment">//convert to bytes (combined with 8bit shift)</span>00438     c=<a class="code" href="mmc_8c.html#a0">MmcCommand</a>(0x51,<a class="code" href="buffer_8c.html#a2">sectorAddress</a>.<a class="code" href="unionAddress.html#o1">b</a>.<a class="code" href="structAddress_1_1B.html#o2">b2</a>,<a class="code" href="buffer_8c.html#a2">sectorAddress</a>.<a class="code" href="unionAddress.html#o1">b</a>.<a class="code" href="structAddress_1_1B.html#o1">b1</a>,00439                  <a class="code" href="buffer_8c.html#a2">sectorAddress</a>.<a class="code" href="unionAddress.html#o1">b</a>.<a class="code" href="structAddress_1_1B.html#o0">b0</a>, 0);00440     <a class="code" href="buffer_8c.html#a2">sectorAddress</a>.<a class="code" href="unionAddress.html#o0">l</a> = <a class="code" href="buffer_8c.html#a2">sectorAddress</a>.<a class="code" href="unionAddress.html#o0">l</a> &gt;&gt; 1; <span class="comment">//convert back to blocks</span>00441 00442     <span class="comment">// If MMC works properly, it returns Busy (== Not idle) at this stage.    </span>00443     <span class="keywordflow">if</span> (c!=0x00){00444       <span class="keywordflow">if</span> (c != 0xff){ 00445         <span class="comment">//MMC returns something else than Busy or "Idle Bus", print what it is</span>00446         <a class="code" href="mmc_8c.html#a7">ConsoleDecipherMMCResponse</a>(c);00447       }00448       <span class="comment">// Something is wrong, take the standard action...</span>00449       <a class="code" href="mmc_8c.html#a4">RebootMMC</a>();00450       <span class="keywordflow">if</span> (retries &gt; 10){  00451         <span class="keywordflow">return</span> 7; <span class="comment">/* failed to execute mmc command */</span>00452       }00453     }00454   }<span class="keywordflow">while</span>(c!=0x00); <span class="comment">//repeat until we get busy signal from MMC.</span>00455     00456   <a class="code" href="board_8h.html#a33">MMCDeselect</a>();00457   00458   <span class="keywordflow">return</span> 0; <span class="comment">//ok return</span>00459 }00460 00461 00462 <span class="comment">/* Wait for data start token and read 512 bytes to global buffer */</span><a name="l00463"></a><a class="code" href="mmc_8h.html#a3">00463</a> <a class="code" href="board_8h.html#a47">Public</a> <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> <a class="code" href="mmc_8c.html#a9">ReadPhysicalSector</a>(){00464 00465   <span class="comment">// RED_LED = LED_ON; /* Disk Read LED on */</span>00466 00467   <a class="code" href="board_8h.html#a32">MMCSelect</a>();00468   <a class="code" href="mmc_8c.html#a1">MmcWaitForData</a>();00469   <a class="code" href="mmc_8c.html#a6">PerformBlockRead</a>();00470 00471   <span class="comment">/* generate SPI clock edges to finish up the command */</span>00472 00473   <a class="code" href="board_8h.html#a50">SPI8Clocks</a>(4); <span class="comment">//Send 8*4=32 clocks (4 ff's) to MMC to be nice.</span>00474   <a class="code" href="board_8h.html#a33">MMCDeselect</a>();00475   <a class="code" href="board_8h.html#a50">SPI8Clocks</a>(4); <span class="comment">//Again, give the poor MMC some clocks, it likes them.</span>00476 00477   <span class="comment">//RED_LED = LED_OFF; /* Disk Read LED off */</span>00478 00479   <span class="keywordflow">return</span> 0; <span class="comment">//ok return</span>00480 }00481 00482 <a name="l00484"></a><a class="code" href="mmc_8h.html#a4">00484</a> <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> <a class="code" href="mmc_8c.html#a10">WritePhysicalSector</a>(){00485   <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> c;  00486 00487 <span class="preprocessor">#ifdef MMCDEBUG</span>00488 <span class="preprocessor"></span>  ConsoleWrite(<span class="stringliteral">"&lt;W"</span>);00489 <span class="preprocessor">#endif  </span>00490 <span class="preprocessor"></span>00491 00492   <span class="comment">//RED_LED = LED_ON;</span>00493   <a class="code" href="buffer_8c.html#a2">sectorAddress</a>.<a class="code" href="unionAddress.html#o0">l</a> = <a class="code" href="buffer_8c.html#a2">sectorAddress</a>.<a class="code" href="unionAddress.html#o0">l</a> * 2; <span class="comment">//convert to bytes (combined with 8bit shift)</span>00494   c=<a class="code" href="mmc_8c.html#a0">MmcCommand</a>(0x40 | 24, <a class="code" href="buffer_8c.html#a2">sectorAddress</a>.<a class="code" href="unionAddress.html#o1">b</a>.<a class="code" href="structAddress_1_1B.html#o2">b2</a>, <a class="code" href="buffer_8c.html#a2">sectorAddress</a>.<a class="code" href="unionAddress.html#o1">b</a>.<a class="code" href="structAddress_1_1B.html#o1">b1</a>,00495                <a class="code" href="buffer_8c.html#a2">sectorAddress</a>.<a class="code" href="unionAddress.html#o1">b</a>.<a class="code" href="structAddress_1_1B.html#o0">b0</a>, 0);00496   <a class="code" href="buffer_8c.html#a2">sectorAddress</a>.<a class="code" href="unionAddress.html#o0">l</a> = <a class="code" href="buffer_8c.html#a2">sectorAddress</a>.<a class="code" href="unionAddress.html#o0">l</a> &gt;&gt; 1; <span class="comment">//convert back to blocks</span>00497 00498   <span class="comment">//ConsolePutChar('w');</span>00499   <span class="comment">//ConsolePutHex8(c);</span>00500   00501   <span class="keywordflow">if</span> (c!=0x00) <span class="keywordflow">return</span> (c); <span class="comment">//Error - MMC did not go to write mode</span>00502   00503 <span class="comment">/*</span>00504 <span class="comment">  while (c!=0x00) { //wait for BUSY token, if you get 0x01(idle), it's an ERROR!</span>00505 <span class="comment">    c = SPIGetChar();</span>00506 <span class="comment">    ConsolePutHex8(c);</span>00507 <span class="comment">  }      </span>00508 <span class="comment">*/</span>  00509   <a class="code" href="buffer_8c.html#a1">dataBufPtr</a> = <a class="code" href="buffer_8c.html#a0">diskSect</a>.<a class="code" href="unionDiskBlock.html#o1">raw</a>.<a class="code" href="structDiskBlock_1_1Raw.html#o0">buf</a>;00510   <a class="code" href="board_8h.html#a45">SPIPutCharWithoutWaiting</a>(0xFE);00511   <a class="code" href="board_8h.html#a43">SPIWait</a>();00512   00513   <span class="keywordflow">for</span> (c=0;c&lt;128;c++){00514     <a class="code" href="board_8h.html#a45">SPIPutCharWithoutWaiting</a>(*<a class="code" href="buffer_8c.html#a1">dataBufPtr</a>++);   00515     <a class="code" href="board_8h.html#a43">SPIWait</a>();00516     <a class="code" href="board_8h.html#a45">SPIPutCharWithoutWaiting</a>(*<a class="code" href="buffer_8c.html#a1">dataBufPtr</a>++);   00517     <a class="code" href="board_8h.html#a43">SPIWait</a>();00518     <a class="code" href="board_8h.html#a45">SPIPutCharWithoutWaiting</a>(*<a class="code" href="buffer_8c.html#a1">dataBufPtr</a>++);   00519     <a class="code" href="board_8h.html#a43">SPIWait</a>();00520     <a class="code" href="board_8h.html#a45">SPIPutCharWithoutWaiting</a>(*<a class="code" href="buffer_8c.html#a1">dataBufPtr</a>++);   00521     <a class="code" href="board_8h.html#a43">SPIWait</a>();00522   }00523   <span class="comment">//ConsolePutChar('-');</span>00524 00525   c = <a class="code" href="board_8c.html#a1">SPIGetChar</a>();  <span class="comment">//crc 1st byte (sends 0xff)</span>00526   c = <a class="code" href="board_8c.html#a1">SPIGetChar</a>(); <span class="comment">//crc 2nd byte (sends 0xff)</span>00527   c = <a class="code" href="board_8c.html#a1">SPIGetChar</a>();00528   <span class="comment">//ConsolePutHex8(c); //This prints xxx00101, (usually e5) when data ok</span>00529   00530 <span class="comment">//  while (SPIGetChar()!=0xff)      //busy wait moved to mmcCommand</span>00531 <span class="comment">//    ; // Wait until MMC not busy.     </span>00532 00533 <span class="preprocessor">#ifdef MMCDEBUG</span>00534 <span class="preprocessor"></span>  ConsoleWrite(<span class="stringliteral">"W&gt;"</span>);00535 <span class="preprocessor">#endif  </span>00536 <span class="preprocessor"></span>00537   00538   <a class="code" href="board_8h.html#a50">SPI8Clocks</a>(16);00539   <a class="code" href="board_8h.html#a33">MMCDeselect</a>();00540   <a class="code" href="board_8h.html#a50">SPI8Clocks</a>(16);00541 00542   <span class="comment">//RED_LED = LED_OFF;</span>00543 00544   <span class="keywordflow">return</span> 0;00545 }00546 00547 </div></pre><hr><FONT SIZE="-1">All software copyright 2000-2004 <a href="http://www.vlsi.fi/"> VLSI Solution OY.</a>Redistribution of these software modules are limited to promotional use onlyand only with the VS1011 / VS1002 / VS1003  MP3-Evakit evaluation boards. Free orcommercial use of these software modules in MP3 players is ok if theproduct includes MP3 decoder chip(s) from VLSI. You can request the complete(compilable) package from mp3@vlsi.fi</FONT>

⌨️ 快捷键说明

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