📄 mmc_8c-source.html
字号:
<!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 Page</a> | <a class="qindex" href="annotated.html">Class List</a> | <a class="qindex" href="files.html">File List</a> | <a class="qindex" href="functions.html">Class Members</a> | <a class="qindex" href="globals.html">File Members</a> | <a class="qindex" href="pages.html">Related 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 00005 <span class="preprocessor">#include "<a class="code" href="mmc_8h.html">mmc.h</a>"</span>00006 <span class="preprocessor">#include "<a class="code" href="board_8h.html">board.h</a>"</span>00007 <span class="preprocessor">#include "<a class="code" href="storage_8h.html">storage.h</a>"</span> <span class="comment">//for reporting back the serial number</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 <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) && (++i<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--)&&((c2=<a class="code" href="board_8c.html#a1">SPIGetChar</a>())&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--)&&((c2=<a class="code" href="board_8c.html#a1">SPIGetChar</a>())&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 }00092 00093 <a name="l00105"></a><a class="code" href="mmc_8c.html#a1">00105</a> <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> <a class="code" href="mmc_8c.html#a1">MmcWaitForData</a>(){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">"<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) && (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 00127 <span class="comment">// Flush any data that might be pending from the MMC.</span>00128 <span class="preprocessor">#ifdef MMCLONGDEBUG </span>00129 <span class="preprocessor"></span> {00130 <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> i;00131 ConsoleWrite(<span class="stringliteral">"\rMMCWaitForData failed. "</span>);00132 ConsoleWrite(<span class="stringliteral">"Expected 0xFE token, received: "</span>);00133 <span class="keywordflow">for</span> (i=0;i<550;i++){00134 ConsolePutHex8(c);00135 c=<a class="code" href="board_8c.html#a1">SPIGetChar</a>();00136 }00137 }00138 <span class="preprocessor">#else</span>00139 <span class="preprocessor"></span> ConsoleWrite(<span class="stringliteral">" NoData "</span>);00140 <a class="code" href="board_8h.html#a50">SPI8Clocks</a>(200); <span class="comment">/* Flush MMC by sending lots of FF's to it */</span>00141 <a class="code" href="board_8h.html#a50">SPI8Clocks</a>(200);00142 <a class="code" href="board_8h.html#a50">SPI8Clocks</a>(200);00143 <span class="preprocessor">#endif</span>00144 <span class="preprocessor"></span>00145 <a class="code" href="board_8h.html#a33">MMCDeselect</a>();00146 DebugMessage(<span class="stringliteral">"!t>"</span>);00147 <span class="keywordflow">return</span> 5; <span class="comment">//Return error</span>00148 }00149 DebugMessage(<span class="stringliteral">"t>"</span>); <span class="comment">//Exit Token Wait</span>00150 <span class="keywordflow">return</span> 0;00151 }00152 00153 <a name="l00159"></a><a class="code" href="mmc_8c.html#a2">00159</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){00160 DebugMessage(<span class="stringliteral">"<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>"</span>);00167 }00168 00169 <a name="l00171"></a><a class="code" href="mmc_8c.html#a3">00171</a> <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> <a class="code" href="mmc_8c.html#a3">GetStorageInformation</a>(){00172 <span class="keywordflow">if</span> (<a class="code" href="mmc_8c.html#a0">MmcCommand</a>(0x4a,0,0,0,0)&0xfe)00173 <span class="keywordflow">return</span> 4; <span class="comment">/* no storage info */</span>00174 <a class="code" href="mmc_8c.html#a1">MmcWaitForData</a>();00175 <a class="code" href="mmc_8c.html#a2">MmcGetData</a>(30);00176 00177 ConsoleWrite(<span class="stringliteral">"\rMMC Manufacturer#: "</span>);00178 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]);00179 ConsoleWrite(<span class="stringliteral">"Product Name: "</span>);00180 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]);00181 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]);00182 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]);00183 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]);00184 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>[7]);00185 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>[8]);00186 ConsoleWrite(<span class="stringliteral">" Production date: "</span>);00187 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>[14]>>4);00188 ConsoleWrite(<span class="stringliteral">"/ "</span>);00189 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>[14]&0x0f)+1997);00190 ConsolePutChar(<span class="charliteral">'\r'</span>);00191 ConsoleWrite(<span class="stringliteral">"Media serial number: "</span>);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -