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

📄 mmc_8c-source.html

📁 MP3 Player Source Code
💻 HTML
📖 第 1 页 / 共 3 页
字号:
<!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>mmc.c</h1><a href="mmc_8c.html">Go to the documentation of this file.</a><pre class="fragment"><div>00001 00006 <span class="preprocessor">#include "<a class="code" href="mmc_8h.html">mmc.h</a>"</span>00007 <span class="preprocessor">#include "<a class="code" href="board_8h.html">board.h</a>"</span>00008 <span class="preprocessor">#include "console.h"</span>00009 <span class="preprocessor">#include "<a class="code" href="buffer_8h.html">buffer.h</a>"</span>00010 00011 <span class="comment">//#define MMCDEBUG</span>00012 <span class="comment">//#define MMCLONGDEBUG</span>00013 00014 <a name="l00019"></a><a class="code" href="mmc_8c.html#a0">00019</a> <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> <a class="code" href="mmc_8c.html#a0">MmcCommand</a>(<span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> c1, 00020                          <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> c2, 00021                          <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> c3, 00022                          <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> c4, 00023                          <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> c5){00024 00025 00026   xdata <span class="keywordtype">char</span> c;00027 00028   <span class="comment">/* Note: c1, c2 are used for temporary variables after use! */</span>  00029 00030   <a class="code" href="board_8h.html#a28">MMC_OFF</a> = <a class="code" href="board_8h.html#a27">NO</a>; <span class="comment">//MMC should be powered, but switch power on just-in-case</span>00031   <a class="code" href="board_8h.html#a29">MMC_XCS</a> = <a class="code" href="board_8h.html#a31">MMC_NOT_SELECTED</a>; <span class="comment">//put MMC on-line.</span>00032 00033   <span class="comment">// Provide clock edges before and after asserting MMC CS</span>00034   <a class="code" href="board_8h.html#a48">SPI8Clocks</a>(8); 00035   <a class="code" href="board_8h.html#a29">MMC_XCS</a> = <a class="code" href="board_8h.html#a30">MMC_SELECTED</a>;00036   <a class="code" href="board_8h.html#a48">SPI8Clocks</a>(8); 00037 00038   c=0;00039   <span class="comment">// If card still seems to be busy, give it some time...</span>00040   <span class="keywordflow">while</span> ((<a class="code" href="board_8c.html#a1">SPIGetChar</a>()!=0xff) &amp;&amp; (c&lt;100)){00041     ConsolePutChar(<span class="charliteral">'.'</span>);00042     c++;00043   }00044 00045 00046   <span class="comment">// The bus should be stable high now</span>00047   <span class="keywordflow">if</span> (<a class="code" href="board_8h.html#a44">SPI_RESULT_BYTE</a> != 0xff){00048     ConsoleWrite(<span class="stringliteral">"\rUnexpected busy signal from MMC. "</span>);00049     <a class="code" href="board_8h.html#a29">MMC_XCS</a> = <a class="code" href="board_8h.html#a31">MMC_NOT_SELECTED</a>; <span class="comment">//drop MMC offline.</span>00050     <span class="keywordflow">return</span> 0x81; <span class="comment">//MMC unexpectedly Busy</span>00051   }00052 00053 <span class="preprocessor">#ifdef MMCDEBUG</span>00054 <span class="preprocessor"></span>  DebugMessage(<span class="stringliteral">" \x1b[7m"</span>);00055   ConsolePutChar(<span class="charliteral">'C'</span>); ConsolePutHex8(c1); ConsolePutHex8(c2); ConsolePutHex8(c3);00056   ConsolePutHex8(c4); ConsolePutHex8(c5); ConsolePutChar(<span class="charliteral">'|'</span>);00057 <span class="preprocessor">#endif</span>00058 <span class="preprocessor"></span>00059   <span class="comment">// Send the MMC command</span>00060   <a class="code" href="board_8h.html#a43">SPIPutCharWithoutWaiting</a>(c1);00061   <a class="code" href="board_8h.html#a42">SPIPutChar</a>(c2);00062   <a class="code" href="board_8h.html#a42">SPIPutChar</a>(c3);00063   <a class="code" href="board_8h.html#a42">SPIPutChar</a>(c4);00064   <a class="code" href="board_8h.html#a42">SPIPutChar</a>(c5);00065   <a class="code" href="board_8h.html#a42">SPIPutChar</a>(0x95);     <span class="comment">/* Valid CRC for init, then don't care */</span>00066   <a class="code" href="board_8h.html#a41">SPIWait</a>();00067   <span class="comment">/* Now ok to use c1..c5 as temporaries (dirty but kool) */</span>00068 00069   <span class="comment">// Wait for R1 style response (bit 7 low) from MMC</span>00070 <span class="preprocessor">#ifdef MMCDEBUG </span>00071 <span class="preprocessor"></span>  {00072     c1=100; <span class="comment">/* try max. 100 times */</span>00073     <span class="keywordflow">while</span>((c1--)&amp;&amp;((c2=<a class="code" href="board_8c.html#a1">SPIGetChar</a>())&amp;0x80)){ <span class="comment">//wait for R1 or timeout</span>00074       <span class="comment">// R1 response not detected, if it's not 0xff, print it for debugging.</span>00075       <span class="keywordflow">if</span> (c2!=0xff){ConsolePutHex8(c2);ConsolePutChar(<span class="charliteral">'|'</span>);}00076     }00077     ConsolePutHex8(c2);00078     DebugMessage(<span class="stringliteral">"\x1b[0m "</span>);00079   }00080 <span class="preprocessor">#else </span>00081 <span class="preprocessor"></span>  {00082     c1=100;00083     <span class="keywordflow">while</span>((c1--)&amp;&amp;((c2=<a class="code" href="board_8c.html#a1">SPIGetChar</a>())&amp;0x80)) <span class="comment">//wait for R1 or timeout</span>00084       ;00085   }00086 <span class="preprocessor">#endif</span>00087 <span class="preprocessor"></span>00088   <span class="keywordflow">return</span> c2; <span class="comment">//return the R1 response</span>00089 }00090 00091 <a name="l00102"></a><a class="code" href="mmc_8c.html#a1">00102</a> <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> <a class="code" href="mmc_8c.html#a1">MmcWaitForData</a>(){00103 00104   <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> c;00105   <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> i = 32000;00106   00107   DebugMessage(<span class="stringliteral">"&lt;t:"</span>); <span class="comment">//Token Wait</span>00108  00109 00110   <span class="comment">// Wait until something else than 0xff is read from the bus</span>00111   <span class="keywordflow">do</span> {00112     c=<a class="code" href="board_8c.html#a1">SPIGetChar</a>();00113 <span class="preprocessor">#ifdef MMCDEBUG    </span>00114 <span class="preprocessor"></span>    <span class="keywordflow">if</span> (c!=0xFF) ConsolePutHex8(c); <span class="comment">//0xfe token or some erroneus byte</span>00115 <span class="preprocessor">#endif</span>00116 <span class="preprocessor"></span>  } <span class="keywordflow">while</span> ((c == 0xff)&amp;&amp;(--i));00117 00118 00119   <span class="keywordflow">if</span> (!i){ <span class="comment">//timeout }</span>00120     00121     ConsoleWrite(<span class="stringliteral">"\rTimeout while waiting for block.\r"</span>);00122     <a class="code" href="board_8h.html#a29">MMC_XCS</a> = <a class="code" href="board_8h.html#a31">MMC_NOT_SELECTED</a>;00123     <span class="keywordflow">return</span> 5; <span class="comment">//return error</span>00124 00125   }00126 00127   <span class="comment">// Something was received from the bus? Might it actually be te </span>00128   <span class="comment">// desired 0xFE data start token? </span>00129   <span class="keywordflow">if</span> (c != 0xfe){00130     <span class="comment">// No data start token, read fail. In an OS an error message would display.</span>00131     <span class="comment">// Since we're in an embedded system, it's unclear what we should do now.</span>00132     <span class="comment">// Current approach is to say all ok but make read block return 0xff's.</span>00133     <span class="comment">// It's not disasterous at least as long as we don't WRITE to MMC.</span>00134 00135     <span class="comment">// Flush any data that might be pending from the MMC.</span>00136 <span class="preprocessor">#ifdef MMCLONGDEBUG    </span>00137 <span class="preprocessor"></span>    {00138       <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> i;00139       ConsoleWrite(<span class="stringliteral">"\rMMCWaitForData failed. "</span>);00140       ConsoleWrite(<span class="stringliteral">"Expected 0xFE token, received: "</span>);00141       <span class="keywordflow">for</span> (i=0;i&lt;550;i++){00142         ConsolePutHex8(c);00143         c=<a class="code" href="board_8c.html#a1">SPIGetChar</a>();00144       }00145     }00146 <span class="preprocessor">#else</span>00147 <span class="preprocessor"></span>    <a class="code" href="board_8h.html#a48">SPI8Clocks</a>(200); <span class="comment">/* Flush MMC by sending lots of FF's to it */</span>00148     <a class="code" href="board_8h.html#a48">SPI8Clocks</a>(200);00149     <a class="code" href="board_8h.html#a48">SPI8Clocks</a>(200);00150 <span class="preprocessor">#endif</span>00151 <span class="preprocessor"></span>00152     <a class="code" href="board_8h.html#a29">MMC_XCS</a> = <a class="code" href="board_8h.html#a31">MMC_NOT_SELECTED</a>; <span class="comment">//Drop MMC offline now.</span>00153     DebugMessage(<span class="stringliteral">"!t&gt;"</span>);00154     <span class="keywordflow">return</span> 5; <span class="comment">//Return error</span>00155 00156   }00157 00158   DebugMessage(<span class="stringliteral">"t&gt;"</span>); <span class="comment">//Exit Token Wait</span>00159   <span class="keywordflow">return</span> 0;00160 00161 }00162 00163 <a name="l00169"></a><a class="code" href="mmc_8c.html#a2">00169</a> <span class="keywordtype">void</span> <a class="code" href="mmc_8c.html#a2">MmcGetData</a>(<span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> amountOctets){00170   DebugMessage(<span class="stringliteral">"&lt;G"</span>);00171 00172   <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>;00173   <span class="keywordflow">while</span> (amountOctets--){00174     *<a class="code" href="buffer_8c.html#a1">dataBufPtr</a>++=<a class="code" href="board_8c.html#a1">SPIGetChar</a>();00175   }00176   DebugMessage(<span class="stringliteral">"G&gt;"</span>);00177 }00178 00179 <a name="l00181"></a><a class="code" href="mmc_8c.html#a3">00181</a> <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> <a class="code" href="mmc_8c.html#a3">GetStorageInformation</a>(){00182   <span class="keywordflow">if</span> (<a class="code" href="mmc_8c.html#a0">MmcCommand</a>(0x4a,0,0,0,0)&amp;0xfe)00183     <span class="keywordflow">return</span> 4; <span class="comment">/* no storage info */</span>00184   <a class="code" href="mmc_8c.html#a1">MmcWaitForData</a>();00185   <a class="code" href="mmc_8c.html#a2">MmcGetData</a>(30);00186 00187   ConsoleWrite(<span class="stringliteral">"\rMMC Manufacturer#: "</span>);00188   ConsolePutUInt(<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>[0]);00189   ConsoleWrite(<span class="stringliteral">"Product Name: "</span>);00190   ConsolePutChar(<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>[3]);00191   ConsolePutChar(<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>[4]);00192   ConsolePutChar(<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>[5]);00193   ConsolePutChar(<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>[6]);

⌨️ 快捷键说明

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