?lang_form? ?lang_select? ?lang_submit? ?lang_endform?
{HEADER END}
{FILE START}

library

?curdirlinks? - Rev 6

?prevdifflink? - Blame - ?getfile?

<!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>Procyon AVRlib: mmc.h Source File</title>
<link href="dox.css" rel="stylesheet" type="text/css">
</head><body>
<!-- Generated by Doxygen 1.4.2 -->
<div class="qindex"><a class="qindex" href="main.html">Main&nbsp;Page</a> | <a class="qindex" href="modules.html">Modules</a> | <a class="qindex" href="annotated.html">Data&nbsp;Structures</a> | <a class="qindex" href="dirs.html">Directories</a> | <a class="qindex" href="files.html">File&nbsp;List</a> | <a class="qindex" href="functions.html">Data&nbsp;Fields</a> | <a class="qindex" href="globals.html">Globals</a> | <a class="qindex" href="pages.html">Related&nbsp;Pages</a></div>
<h1>mmc.h</h1><a href="mmc_8h.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment">00001 <span class="comment">/*! \file mmc.h \brief MultiMedia and SD Flash Card Interface. */</span>
00002 <span class="comment">//*****************************************************************************</span>
00003 <span class="comment">//</span>
00004 <span class="comment">// File Name    : 'mmc.h'</span>
00005 <span class="comment">// Title        : MultiMedia and SD Flash Card Interface</span>
00006 <span class="comment">// Author       : Pascal Stang - Copyright (C) 2004</span>
00007 <span class="comment">// Created      : 2004.09.22</span>
00008 <span class="comment">// Revised      : 2004.09.22</span>
00009 <span class="comment">// Version      : 0.1</span>
00010 <span class="comment">// Target MCU   : Atmel AVR Series</span>
00011 <span class="comment">// Editor Tabs  : 4</span>
00012 <span class="comment">//</span><span class="comment"></span>
00013 <span class="comment">/// \ingroup driver_hw</span>
00014 <span class="comment">/// \defgroup mmc MultiMedia and SD Flash Card Interface (mmc.c)</span>
00015 <span class="comment">/// \code #include "mmc.h" \endcode</span>
00016 <span class="comment">/// \par Description</span>
00017 <span class="comment">///     This library offers some simple functions which can be used</span>
00018 <span class="comment">///     to read and write data on a MultiMedia or SecureDigital (SD) Flash</span>
00019 <span class="comment">///     Card.  Although MM and SD Cards are designed to operate with their own</span>
00020 <span class="comment">///     special bus wiring and protocols, both types of cards also provide a</span>
00021 <span class="comment">///     simple SPI-like interface mode which is exceptionally useful when </span>
00022 <span class="comment">///     attempting to use the cards in embedded systems.</span>
00023 <span class="comment">///</span>
00024 <span class="comment">/// \par Wiring</span>
00025 <span class="comment">///     To work with this library, the card must be wired to the SPI port of</span>
00026 <span class="comment">///     the Atmel microcontroller as described below.  Typical cards can</span>
00027 <span class="comment">///     operate at up to 25MHz maximum SPI clock rate (thus faster than most</span>
00028 <span class="comment">///     AVR's maximum SPI clock rate).</span>
00029 <span class="comment">/// &lt;pre&gt;</span>
00030 <span class="comment">///       _________________</span>
00031 <span class="comment">///      /  1 2 3 4 5 6 78 |    &lt;- view of MMC/SD card looking at contacts</span>
00032 <span class="comment">///     / 9                |    Pins 8 and 9 are present only on SD cards</span>
00033 <span class="comment">///     |    MMC/SD Card   |</span>
00034 <span class="comment">///     |                  |</span>
00035 <span class="comment">///     /\/\/\/\/\/\/\/\/\/\</span>
00036 <span class="comment">///     1 - CS   (chip select)          - wire to any available I/O pin(*)</span>
00037 <span class="comment">///     2 - DIN  (data in, card&lt;-host)  - wire to SPI MOSI pin</span>
00038 <span class="comment">///     3 - VSS  (ground)               - wire to ground</span>
00039 <span class="comment">///     4 - VDD  (power, 3.3V only?)    - wire to power (MIGHT BE 3.3V ONLY!)</span>
00040 <span class="comment">///     5 - SCLK (data clock)           - wire to SPI SCK pin</span>
00041 <span class="comment">///     6 - VSS  (ground)               - wire to ground</span>
00042 <span class="comment">///     7 - DOUT (data out, card-&gt;host) - wire to SPI MISO pin</span>
00043 <span class="comment">///</span>
00044 <span class="comment">///     (*) you must define this chip select I/O pin in mmcconf.h</span>
00045 <span class="comment">/// &lt;/pre&gt;</span>
00046 <span class="comment">/// \note This code is currently below version 1.0, and therefore is considered</span>
00047 <span class="comment">/// to be lacking in some functionality or documentation, or may not be fully</span>
00048 <span class="comment">/// tested.  Nonetheless, you can expect most functions to work.</span>
00049 <span class="comment"></span><span class="comment">//</span>
00050 <span class="comment">// This code is distributed under the GNU Public License</span>
00051 <span class="comment">//      which can be found at http://www.gnu.org/licenses/gpl.txt</span>
00052 <span class="comment">//</span>
00053 <span class="comment">//*****************************************************************************</span><span class="comment"></span>
00054 <span class="comment">//@{</span>
00055 <span class="comment"></span>
00056 <span class="preprocessor">#ifndef MMC_H</span>
00057 <span class="preprocessor"></span><span class="preprocessor">#define MMC_H</span>
00058 <span class="preprocessor"></span>
00059 <span class="preprocessor">#include "<a class="code" href="global_8h.html">global.h</a>"</span>
00060 
00061 <span class="comment">// constants/macros/typdefs</span>
00062 <span class="comment">// MMC commands (taken from sandisk MMC reference)</span>
<a name="l00063"></a><a class="code" href="group__mmc.html#ga6">00063</a> <span class="preprocessor">#define MMC_GO_IDLE_STATE           0       </span><span class="comment">///&lt; initialize card to SPI-type access</span>
<a name="l00064"></a><a class="code" href="group__mmc.html#ga7">00064</a> <span class="comment"></span>#define MMC_SEND_OP_COND            1       <span class="comment">///&lt; set card operational mode</span>
<a name="l00065"></a><a class="code" href="group__mmc.html#ga8">00065</a> <span class="comment"></span>#define MMC_SEND_CSD                9       <span class="comment">///&lt; get card's CSD</span>
<a name="l00066"></a><a class="code" href="group__mmc.html#ga9">00066</a> <span class="comment"></span>#define MMC_SEND_CID                10      <span class="comment">///&lt; get card's CID</span>
00067 <span class="comment"></span>#define MMC_SEND_STATUS             13
<a name="l00068"></a><a class="code" href="group__mmc.html#ga11">00068</a> <span class="preprocessor">#define MMC_SET_BLOCKLEN            16      </span><span class="comment">///&lt; Set number of bytes to transfer per block</span>
<a name="l00069"></a><a class="code" href="group__mmc.html#ga12">00069</a> <span class="comment"></span>#define MMC_READ_SINGLE_BLOCK       17      <span class="comment">///&lt; read a block</span>
<a name="l00070"></a><a class="code" href="group__mmc.html#ga13">00070</a> <span class="comment"></span>#define MMC_WRITE_BLOCK             24      <span class="comment">///&lt; write a block</span>
00071 <span class="comment"></span>#define MMC_PROGRAM_CSD             27
00072 <span class="preprocessor">#define MMC_SET_WRITE_PROT          28</span>
00073 <span class="preprocessor"></span><span class="preprocessor">#define MMC_CLR_WRITE_PROT          29</span>
00074 <span class="preprocessor"></span><span class="preprocessor">#define MMC_SEND_WRITE_PROT         30</span>
00075 <span class="preprocessor"></span><span class="preprocessor">#define MMC_TAG_SECTOR_START        32</span>
00076 <span class="preprocessor"></span><span class="preprocessor">#define MMC_TAG_SECTOR_END          33</span>
00077 <span class="preprocessor"></span><span class="preprocessor">#define MMC_UNTAG_SECTOR            34</span>
<a name="l00078"></a><a class="code" href="group__mmc.html#ga21">00078</a> <span class="preprocessor"></span><span class="preprocessor">#define MMC_TAG_ERASE_GROUP_START   35      </span><span class="comment">///&lt; Sets beginning of erase group (mass erase)</span>
<a name="l00079"></a><a class="code" href="group__mmc.html#ga22">00079</a> <span class="comment"></span>#define MMC_TAG_ERARE_GROUP_END     36      <span class="comment">///&lt; Sets end of erase group (mass erase)</span>
<a name="l00080"></a><a class="code" href="group__mmc.html#ga23">00080</a> <span class="comment"></span>#define MMC_UNTAG_ERASE_GROUP       37      <span class="comment">///&lt; Untag (unset) erase group (mass erase)</span>
<a name="l00081"></a><a class="code" href="group__mmc.html#ga24">00081</a> <span class="comment"></span>#define MMC_ERASE                   38      <span class="comment">///&lt; Perform block/mass erase</span>
<a name="l00082"></a><a class="code" href="group__mmc.html#ga25">00082</a> <span class="comment"></span>#define MMC_CRC_ON_OFF              59      <span class="comment">///&lt; Turns CRC check on/off</span>
00083 <span class="comment"></span>// R1 Response bit-defines
<a name="l00084"></a><a class="code" href="group__mmc.html#ga26">00084</a> <span class="preprocessor">#define MMC_R1_BUSY                 0x80    </span><span class="comment">///&lt; R1 response: bit indicates card is busy</span>
00085 <span class="comment"></span>#define MMC_R1_PARAMETER            0x40
00086 <span class="preprocessor">#define MMC_R1_ADDRESS              0x20</span>
00087 <span class="preprocessor"></span><span class="preprocessor">#define MMC_R1_ERASE_SEQ            0x10</span>
00088 <span class="preprocessor"></span><span class="preprocessor">#define MMC_R1_COM_CRC              0x08</span>
00089 <span class="preprocessor"></span><span class="preprocessor">#define MMC_R1_ILLEGAL_COM          0x04</span>
00090 <span class="preprocessor"></span><span class="preprocessor">#define MMC_R1_ERASE_RESET          0x02</span>
00091 <span class="preprocessor"></span><span class="preprocessor">#define MMC_R1_IDLE_STATE           0x01</span>
00092 <span class="preprocessor"></span><span class="comment">// Data Start tokens</span>
<a name="l00093"></a><a class="code" href="group__mmc.html#ga34">00093</a> <span class="preprocessor">#define MMC_STARTBLOCK_READ         0xFE    </span><span class="comment">///&lt; when received from card, indicates that a block of data will follow</span>
<a name="l00094"></a><a class="code" href="group__mmc.html#ga35">00094</a> <span class="comment"></span>#define MMC_STARTBLOCK_WRITE        0xFE    <span class="comment">///&lt; when sent to card, indicates that a block of data will follow</span>
00095 <span class="comment"></span>#define MMC_STARTBLOCK_MWRITE       0xFC
00096 <span class="comment">// Data Stop tokens</span>
00097 <span class="preprocessor">#define MMC_STOPTRAN_WRITE          0xFD</span>
00098 <span class="preprocessor"></span><span class="comment">// Data Error Token values</span>
00099 <span class="preprocessor">#define MMC_DE_MASK                 0x1F</span>
00100 <span class="preprocessor"></span><span class="preprocessor">#define MMC_DE_ERROR                0x01</span>
00101 <span class="preprocessor"></span><span class="preprocessor">#define MMC_DE_CC_ERROR             0x02</span>
00102 <span class="preprocessor"></span><span class="preprocessor">#define MMC_DE_ECC_FAIL             0x04</span>
00103 <span class="preprocessor"></span><span class="preprocessor">#define MMC_DE_OUT_OF_RANGE         0x04</span>
00104 <span class="preprocessor"></span><span class="preprocessor">#define MMC_DE_CARD_LOCKED          0x04</span>
00105 <span class="preprocessor"></span><span class="comment">// Data Response Token values</span>
00106 <span class="preprocessor">#define MMC_DR_MASK                 0x1F</span>
00107 <span class="preprocessor"></span><span class="preprocessor">#define MMC_DR_ACCEPT               0x05</span>
00108 <span class="preprocessor"></span><span class="preprocessor">#define MMC_DR_REJECT_CRC           0x0B</span>
00109 <span class="preprocessor"></span><span class="preprocessor">#define MMC_DR_REJECT_WRITE_ERROR   0x0D</span>
00110 <span class="preprocessor"></span>
00111 <span class="comment">// functions</span>
00112 <span class="comment"></span>
00113 <span class="comment">//! Initialize AVR&lt;-&gt;MMC hardware interface.</span>
00114 <span class="comment">/// Prepares hardware for MMC access.</span>
00115 <span class="comment"></span><span class="keywordtype">void</span> <a class="code" href="group__mmc.html#ga0">mmcInit</a>(<span class="keywordtype">void</span>);
00116 <span class="comment"></span>
00117 <span class="comment">//! Initialize the card and prepare it for use.</span>
00118 <span class="comment">/// Returns zero if successful.</span>
00119 <span class="comment"></span>u08 <a class="code" href="group__mmc.html#ga1">mmcReset</a>(<span class="keywordtype">void</span>);
00120 <span class="comment"></span>
00121 <span class="comment">//! Send card an MMC command.</span>
00122 <span class="comment">/// Returns R1 result code.</span>
00123 <span class="comment"></span>u08 <a class="code" href="group__mmc.html#ga2">mmcSendCommand</a>(u08 cmd, u32 arg);
00124 <span class="comment"></span>
00125 <span class="comment">//! Read 512-byte sector from card to buffer</span>
00126 <span class="comment">/// Returns zero if successful.</span>
00127 <span class="comment"></span>u08 <a class="code" href="group__mmc.html#ga3">mmcRead</a>(u32 sector, u08* buffer);
00128 <span class="comment"></span>
00129 <span class="comment">//! Write 512-byte sector from buffer to card</span>
00130 <span class="comment">/// Returns zero if successful.</span>
00131 <span class="comment"></span>u08 <a class="code" href="group__mmc.html#ga4">mmcWrite</a>(u32 sector, u08* buffer);
00132 <span class="comment"></span>
00133 <span class="comment">//! Internal command function.</span>
00134 <span class="comment">/// Issues a generic MMC command as specified by cmd and arg.</span>
00135 <span class="comment"></span>u08 <a class="code" href="group__mmc.html#ga5">mmcCommand</a>(u08 cmd, u32 arg);
00136 
00137 <span class="preprocessor">#endif</span>
00138 <span class="preprocessor"></span><span class="comment">//@}</span>
</span></pre></div><hr size="1"><address style="align: right;"><small>Generated on Sun Oct 29 03:41:07 2006 for Procyon AVRlib by&nbsp;
<a href="http://www.doxygen.org/index.html">
<img src="doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.4.2 </small></address>
</body>
</html>
{FILE END}
{FOOTER START}

Powered by WebSVN v2.8.3