📄 mmc_8c.html
字号:
<td><p>Do one MMC command and return the MMC SPI R1 response. <p>Returns 0xff in case of timeout (relies on weak pull-up on the MISO pin). Note that the parameter bytes are used for temporary storage after they are written out. <p>Definition at line <a class="el" href="mmc_8c-source.html#l00019">19</a> of file <a class="el" href="mmc_8c-source.html">mmc.c</a>.<p>References <a class="el" href="board_8h-source.html#l00159">MMC_NOT_SELECTED</a>, <a class="el" href="board_8h-source.html#l00150">MMC_OFF</a>, <a class="el" href="board_8h-source.html#l00156">MMC_SELECTED</a>, <a class="el" href="board_8h-source.html#l00153">MMC_XCS</a>, <a class="el" href="board_8h-source.html#l00147">NO</a>, <a class="el" href="board_8c-source.html#l00026">SPI8Clocks()</a>, <a class="el" href="board_8h-source.html#l00223">SPI_RESULT_BYTE</a>, <a class="el" href="board_8c-source.html#l00018">SPIGetChar()</a>, <a class="el" href="board_8h-source.html#l00217">SPIPutChar</a>, <a class="el" href="board_8h-source.html#l00220">SPIPutCharWithoutWaiting</a>, and <a class="el" href="board_8h-source.html#l00214">SPIWait</a>.<p>Referenced by <a class="el" href="mmc_8c-source.html#l00181">GetStorageInformation()</a>, <a class="el" href="mmc_8c-source.html#l00249">InitMMC()</a>, <a class="el" href="mmc_8c-source.html#l00221">RebootMMC()</a>, <a class="el" href="mmc_8c-source.html#l00431">SeekSector()</a>, and <a class="el" href="mmc_8c-source.html#l00502">WritePhysicalSector()</a>.<p><pre class="fragment"><div>00023 {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) && (c<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--)&&((c2=<a class="code" href="board_8c.html#a1">SPIGetChar</a>())&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--)&&((c2=<a class="code" href="board_8c.html#a1">SPIGetChar</a>())&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 }</div></pre><p>Here is the call graph for this function:<p><center><img src="mmc_8c_a0_cgraph.png" border="0" usemap="#mmc_8c_a0_cgraph_map" alt=""></center><map name="mmc_8c_a0_cgraph_map"><area href="board_8h.html#a48" shape="rect" coords="164,7,238,31" alt=""><area href="board_8c.html#a1" shape="rect" coords="162,54,240,78" alt=""></map> </td> </tr></table><a class="anchor" name="a2" doxytag="mmc.c::MmcGetData" ></a><p><table class="mdTable" width="100%" cellpadding="2" cellspacing="0"> <tr> <td class="mdRow"> <table cellpadding="0" cellspacing="0" border="0"> <tr> <td class="md" nowrap valign="top"> void MmcGetData </td> <td class="md" valign="top">( </td> <td class="md" nowrap valign="top">unsigned int </td> <td class="mdname1" valign="top" nowrap> <em>amountOctets</em> </td> <td class="md" valign="top"> ) </td> <td class="md" nowrap></td> </tr> </table> </td> </tr></table><table cellspacing=5 cellpadding=0 border=0> <tr> <td> </td> <td><p>Read a Data Block from MMC. <p>Use shared global pointer dataBufPtr declared in <a class="el" href="buffer_8h.html">buffer.h</a>. Does not affect MMC chip select signal. <dl compact><dt><b>Warning:</b></dt><dd>this is not the fastest way to read, use PerformBlockRead to read entire disk block. </dd></dl><p>Definition at line <a class="el" href="mmc_8c-source.html#l00169">169</a> of file <a class="el" href="mmc_8c-source.html">mmc.c</a>.<p>References <a class="el" href="buffer_8h-source.html#l00107">DiskBlock::Raw::buf</a>, <a class="el" href="buffer_8c-source.html#l00013">dataBufPtr</a>, <a class="el" href="buffer_8c-source.html#l00010">diskSect</a>, <a class="el" href="unionDiskBlock.html#o1">DiskBlock::raw</a>, and <a class="el" href="board_8c-source.html#l00018">SPIGetChar()</a>.<p>Referenced by <a class="el" href="mmc_8c-source.html#l00181">GetStorageInformation()</a>.<p><pre class="fragment"><div>00169 {00170 DebugMessage(<span class="stringliteral">"<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>"</span>);00177 }</div></pre><p>Here is the call graph for this function:<p><center><img src="mmc_8c_a2_cgraph.png" border="0" usemap="#mmc_8c_a2_cgraph_map" alt=""></center><map name="mmc_8c_a2_cgraph_map"><area href="board_8c.html#a1" shape="rect" coords="151,7,229,30" alt=""></map> </td> </tr></table><a class="anchor" name="a1" doxytag="mmc.c::MmcWaitForData" ></a><p><table class="mdTable" width="100%" cellpadding="2" cellspacing="0"> <tr> <td class="mdRow"> <table cellpadding="0" cellspacing="0" border="0"> <tr> <td class="md" nowrap valign="top"> unsigned char MmcWaitForData </td> <td class="md" valign="top">( </td> <td class="mdname1" valign="top" nowrap> </td> <td class="md" valign="top"> ) </td> <td class="md" nowrap></td> </tr> </table> </td> </tr></table><table cellspacing=5 cellpadding=0 border=0> <tr> <td> </td> <td><p>MMC Wait For Data start token 0xfe. <p>First any 0xFF's are read off the mmc. The first non-ff octet is examined. If it's the 0xfe data start token, everything is fine. If not, then some error has occurred. Since we're in an embedded system, it's unclear what we should do then. Current approach is to say all ok but make read block return 0xff's by dropping the MMC card offline. Before that we read "lots" of octets from the MMC to flush any pending data. Finally we return "ALL OK". It's not disasterous at least as long as we don't WRITE to MMC. <p>Definition at line <a class="el" href="mmc_8c-source.html#l00102">102</a> of file <a class="el" href="mmc_8c-source.html">mmc.c</a>.<p>References <a class="el" href="board_8h-source.html#l00159">MMC_NOT_SELECTED</a>, <a class="el" href="board_8h-source.html#l00153">MMC_XCS</a>, <a class="el" href="board_8c-source.html#l00026">SPI8Clocks()</a>, and <a class="el" href="board_8c-source.html#l00018">SPIGetChar()</a>.<p>Referenced by <a class="el" href="mmc_8c-source.html#l00181">GetStorageInformation()</a>, <a class="el" href="mmc_8c-source.html#l00477">ReadPhysicalSector()</a>, and <a class="el" href="mmc_8c-source.html#l00502">WritePhysicalSector()</a>.<p><pre class="fragment"><div>00102 {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">"<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)&&(--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>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -