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

📄 mmc_8c.html

📁 MP3播放器源代码, VS1003B
💻 HTML
📖 第 1 页 / 共 5 页
字号:
  <tr>    <td>      &nbsp;    </td>    <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_8c-source.html#l00036">Delay()</a>, <a class="el" href="board_8h-source.html#l00178">MMCDeselect</a>, <a class="el" href="board_8h-source.html#l00175">MMCSelect</a>, <a class="el" href="board_8c-source.html#l00026">SPI8Clocks()</a>, <a class="el" href="board_8h-source.html#l00241">SPI_RESULT_BYTE</a>, <a class="el" href="board_8c-source.html#l00018">SPIGetChar()</a>, <a class="el" href="board_8h-source.html#l00235">SPIPutChar</a>, <a class="el" href="board_8h-source.html#l00238">SPIPutCharWithoutWaiting</a>, and <a class="el" href="board_8h-source.html#l00232">SPIWait</a>.<p>Referenced by <a class="el" href="mmc_8c-source.html#l00171">GetStorageInformation()</a>, <a class="el" href="mmc_8c-source.html#l00246">InitMMC()</a>, <a class="el" href="mmc_8c-source.html#l00217">RebootMMC()</a>, <a class="el" href="mmc_8c-source.html#l00431">SeekSector()</a>, and <a class="el" href="mmc_8c-source.html#l00484">WritePhysicalSector()</a>.<p><pre class="fragment"><div>00023                                           {00024 00025 00026   <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> i;00027 00028 00029   <span class="comment">/* Note: c1, c2 are used for temporary variables after use! */</span>  00030 00031   <span class="comment">// MMC_OFF = NO; //MMC should be powered, but switch power on just-in-case</span>00032   <span class="comment">// MMCDeselect(); //put MMC on-line.</span>00033   <span class="comment">// Provide clock edges before and after asserting MMC CS</span>00034 00035   <a class="code" href="board_8h.html#a33">MMCDeselect</a>();00036   <a class="code" href="board_8h.html#a50">SPI8Clocks</a>(8); 00037   <a class="code" href="board_8h.html#a32">MMCSelect</a>();00038   <a class="code" href="board_8h.html#a50">SPI8Clocks</a>(8); 00039 00040   i=0;00041   <span class="comment">// If card still seems to be busy, give it some time... </span>00042   <span class="comment">// changed 12/2005 to give quite a lot of time.</span>00043   <span class="keywordflow">while</span> ((<a class="code" href="board_8c.html#a1">SPIGetChar</a>()!=0xff) &amp;&amp; (++i&lt;60000));00044     ; 00045  00046   <span class="comment">// The bus should be stable high now</span>00047   <span class="keywordflow">if</span> ((i=<a class="code" href="board_8h.html#a46">SPI_RESULT_BYTE</a>) != 0xff){00048     ConsoleWrite(<span class="stringliteral">"\rUnexpected busy signal from MMC. "</span>);00049     ConsolePutHex16(i);00050     <a class="code" href="board_8h.html#a33">MMCDeselect</a>();00051     <a class="code" href="board_8h.html#a51">Delay</a>(1000);00052     <span class="keywordflow">return</span> 0x81; <span class="comment">//MMC unexpectedly Busy</span>00053   }00054 00055 <span class="preprocessor">#ifdef MMCDEBUG</span>00056 <span class="preprocessor"></span>  DebugMessage(<span class="stringliteral">" \x1b[7m"</span>);00057   ConsolePutChar(<span class="charliteral">'C'</span>); ConsolePutHex8(c1); ConsolePutHex8(c2); ConsolePutHex8(c3);00058   ConsolePutHex8(c4); ConsolePutHex8(c5); ConsolePutChar(<span class="charliteral">'|'</span>);00059 <span class="preprocessor">#endif</span>00060 <span class="preprocessor"></span>00061   <span class="comment">// Send the MMC command</span>00062   <a class="code" href="board_8h.html#a45">SPIPutCharWithoutWaiting</a>(c1);00063   <a class="code" href="board_8h.html#a44">SPIPutChar</a>(c2);00064   <a class="code" href="board_8h.html#a44">SPIPutChar</a>(c3);00065   <a class="code" href="board_8h.html#a44">SPIPutChar</a>(c4);00066   <a class="code" href="board_8h.html#a44">SPIPutChar</a>(c5);00067   <a class="code" href="board_8h.html#a44">SPIPutChar</a>(0x95);     <span class="comment">/* Valid CRC for init, then don't care */</span>00068   <a class="code" href="board_8h.html#a43">SPIWait</a>();00069   <span class="comment">/* Now ok to use c1..c5 as temporaries (dirty but kool) */</span>00070 00071   <span class="comment">// Wait for R1 style response (bit 7 low) from MMC</span>00072 <span class="preprocessor">#ifdef MMCDEBUG </span>00073 <span class="preprocessor"></span>  {00074     c1=100; <span class="comment">/* try max. 100 times */</span>00075     <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>00076       <span class="comment">// R1 response not detected, if it's not 0xff, print it for debugging.</span>00077       <span class="keywordflow">if</span> (c2!=0xff){ConsolePutHex8(c2);ConsolePutChar(<span class="charliteral">'|'</span>);}00078     }00079     ConsolePutHex8(c2);00080     DebugMessage(<span class="stringliteral">"\x1b[0m "</span>);00081   }00082 <span class="preprocessor">#else </span>00083 <span class="preprocessor"></span>  {00084     c1=100;00085     <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>00086       ;00087   }00088 <span class="preprocessor">#endif</span>00089 <span class="preprocessor"></span>00090   <span class="keywordflow">return</span> c2; <span class="comment">//return the R1 response</span>00091 }</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#a51" shape="rect" coords="181,7,221,31" alt=""><area href="board_8h.html#a50" shape="rect" coords="164,55,238,78" alt=""><area href="board_8c.html#a1" shape="rect" coords="162,102,240,126" 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">(&nbsp;</td>          <td class="md" nowrap valign="top">unsigned int&nbsp;</td>          <td class="mdname1" valign="top" nowrap> <em>amountOctets</em>          </td>          <td class="md" valign="top">&nbsp;)&nbsp;</td>          <td class="md" nowrap></td>        </tr>      </table>    </td>  </tr></table><table cellspacing=5 cellpadding=0 border=0>  <tr>    <td>      &nbsp;    </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#l00159">159</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#l00171">GetStorageInformation()</a>.<p><pre class="fragment"><div>00159                                           {00160   DebugMessage(<span class="stringliteral">"&lt;G"</span>);00161 00162   <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>;00163   <span class="keywordflow">while</span> (amountOctets--){00164     *<a class="code" href="buffer_8c.html#a1">dataBufPtr</a>++=<a class="code" href="board_8c.html#a1">SPIGetChar</a>();00165   }00166   DebugMessage(<span class="stringliteral">"G&gt;"</span>);00167 }</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">(&nbsp;</td>          <td class="mdname1" valign="top" nowrap>          </td>          <td class="md" valign="top">&nbsp;)&nbsp;</td>          <td class="md" nowrap></td>        </tr>      </table>    </td>  </tr></table><table cellspacing=5 cellpadding=0 border=0>  <tr>    <td>      &nbsp;    </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. 12/2005: Well, now we do write to mmc... <p>Definition at line <a class="el" href="mmc_8c-source.html#l00105">105</a> of file <a class="el" href="mmc_8c-source.html">mmc.c</a>.<p>References <a class="el" href="board_8h-source.html#l00178">MMCDeselect</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#l00171">GetStorageInformation()</a>, and <a class="el" href="mmc_8c-source.html#l00463">ReadPhysicalSector()</a>.<p><pre class="fragment"><div>00105                               {00106 00107   <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> c;00108   <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> i; 00109   00110   DebugMessage(<span class="stringliteral">"&lt;t:"</span>); <span class="comment">//Token Wait</span>00111 00112   i = 60000; <span class="comment">//try max. 60000 bus cycles</span>00113   <span class="comment">// Wait until something else than 0xff is read from the bus</span>00114   <span class="keywordflow">do</span> {00115     c=<a class="code" href="board_8c.html#a1">SPIGetChar</a>();00116     --i;00117   } <span class="keywordflow">while</span> ((c == 0xff) &amp;&amp; (i));00118 00119   <span class="comment">// Something was received from the bus? Might it actually be te </span>00120   <span class="comment">// desired 0xFE data start token? </span>00121   <span class="keywordflow">if</span> (c != 0xfe){00122     <span class="comment">// No data start token, read fail. In an OS an error message would display.</span>00123     <span class="comment">// Since we're in an embedded system, it's unclear what we should do now.</span>00124     <span class="comment">// Current approach is to say all ok but make read block return 0xff's.</span>00125     <span class="comment">// It's not disasterous at least as long as we don't WRITE to MMC.</span>00126 

⌨️ 快捷键说明

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