mmcard.h

Go to the documentation of this file.
00001 #ifndef _DEV_MMCARD_H_
00002 #define _DEV_MMCARD_H_
00003 
00004 /*
00005  * Copyright (C) 2005 by egnite Software GmbH. All rights reserved.
00006  *
00007  * Redistribution and use in source and binary forms, with or without
00008  * modification, are permitted provided that the following conditions
00009  * are met:
00010  *
00011  * 1. Redistributions of source code must retain the above copyright
00012  *    notice, this list of conditions and the following disclaimer.
00013  * 2. Redistributions in binary form must reproduce the above copyright
00014  *    notice, this list of conditions and the following disclaimer in the
00015  *    documentation and/or other materials provided with the distribution.
00016  * 3. Neither the name of the copyright holders nor the names of
00017  *    contributors may be used to endorse or promote products derived
00018  *    from this software without specific prior written permission.
00019  *
00020  * THIS SOFTWARE IS PROVIDED BY EGNITE SOFTWARE GMBH AND CONTRIBUTORS
00021  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00022  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
00023  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL EGNITE
00024  * SOFTWARE GMBH OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
00025  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
00026  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
00027  * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
00028  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
00029  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
00030  * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
00031  * SUCH DAMAGE.
00032  *
00033  * For additional information see http://www.ethernut.de/
00034  */
00035 
00056 #include <sys/device.h>
00057 #include <sys/file.h>
00058 
00063 
00067 typedef struct _MMCIFC {
00069     int (*mmcifc_in) (void);
00071      u_char(*mmcifc_io) (u_char);
00073     int (*mmcifc_cs) (int);
00075     int (*mmcifc_cd) (void);
00077     int (*mmcifc_wp) (void);
00078 } MMCIFC;
00079 
00080 #define MMCMD_HOST                      0x40
00081 #define MMCMD_RESET_CRC                 0x95
00082 
00088 #define MMCMD_GO_IDLE_STATE             0
00089 
00091 #define MMCMD_SEND_OP_COND              1
00092 
00098 #define MMCMD_ALL_SEND_CID              2
00099 
00101 #define MMCMD_SEND_RELATIVE_ADDR        3
00102 
00104 #define MMCMD_SELECT_CARD               7
00105 
00107 #define MMCMD_SEND_CSD                  9
00108 
00110 #define MMCMD_SEND_CID                  10
00111 
00113 #define MMCMD_STOP_TRANSMISSION         12
00114 
00116 #define MMCMD_SEND_STATUS               13
00117 
00119 #define MMCMD_SET_BLOCKLEN              16
00120 
00122 #define MMCMD_READ_SINGLE_BLOCK         17
00123 
00125 #define MMCMD_READ_MULTIPLE_BLOCK       18
00126 
00128 #define MMCMD_WRITE_BLOCK               24
00129 
00131 #define MMCMD_WRITE_MULTIPLE_BLOCK      25
00132 
00134 #define MMCMD_PROGRAM_CSD               27
00135 
00137 #define MMCMD_SET_WRITE_PROTECT         28
00138 
00140 #define MMCMD_CLR_WRITE_PROTECT         29
00141 
00143 #define MMCMD_SEND_WRITE_PROTECT        30
00144 
00146 #define MMCMD_TAG_ERASE_GROUP_START     35
00147 
00149 #define MMCMD_TAG_ERASE_GROUP_END       36
00150 
00152 #define MMCMD_ERASE                     38
00153 
00155 #define MMCMD_LOCK_UNLOCK               42
00156 
00158 #define MMCMD_READ_OCR                  58
00159 
00164 #define MMCMD_CRC_ON_OFF                59
00165 
00167 #define MMR1_IDLE_STATE         0x00
00168 
00169 #define MMR1_NOT_IDLE           0x01
00170 
00171 #define MMR1_ERASE_RESET        0x02
00172 
00173 #define MMR1_ILLEGAL_COMMAND    0x04
00174 
00175 #define MMR1_COM_CRC_ERROR      0x08
00176 
00177 #define MMR1_ERASE_SEQ_ERROR    0x10
00178 
00179 #define MMR1_ADDRESS_ERROR      0x20
00180 
00181 #define MMR1_PARAMETER_ERROR    0x40
00182 
00183 
00185 #define MMR2_CARD_LOCKED        0x01
00186 
00187 #define MMR2_WP_ERASE_SKIP      0x02
00188 
00189 #define MMR2_ERROR              0x04
00190 
00191 #define MMR2_CC_ERROR           0x08
00192 
00193 #define MMR2_ECC_FAILED         0x10
00194 
00195 #define MMR2_WP_VIOLATION       0x20
00196 
00197 #define MMR2_ERASE_PARAMETER    0x40
00198 
00199 #define MMR2_OUT_OF_RANGE       0x80
00200 
00201 
00202 #define MMCSR_OUT_OF_RANGE      0x80000000
00203 #define MMCSR_ADDRESS_ERROR     0x40000000
00204 #define MMCSR_BLOCK_LEN_ERROR   0x20000000
00205 #define MMCSR_ERASE_SEQ_ERROR   0x10000000
00206 #define MMCSR_ERASE_PARAM       0x08000000
00207 #define MMCSR_WP_VIOLATION      0x04000000
00208 #define MMCSR_COM_CRC_ERROR     0x00800000
00209 #define MMCSR_ILLEGAL_COMMAND   0x00400000
00210 #define MMCSR_ERROR             0x00080000
00211 #define MMCSR_CIDCSD_OVERWRITE  0x00010000
00212 #define MMCSR_WP_ERASE_SKIP     0x00008000
00213 #define MMCSR_CARD_ECC_DISABLED 0x00004000
00214 #define MMCSR_ERASE_RESET       0x00002000
00215 #define MMCSR_STATE_MASK        0x00001E00
00216 #define MMCSR_READY_FOR_DATA    0x00000100
00217 
00218 #define MMCSR_IS_IDLE           0x00000000
00219 #define MMCSR_IS_READY          0x00000200
00220 #define MMCSR_IS_IDENT          0x00000400
00221 #define MMCSR_IS_STBY           0x00000600
00222 #define MMCSR_IS_TRAN           0x00000800
00223 #define MMCSR_IS_DATA           0x00000A00
00224 #define MMCSR_IS_RCV            0x00000C00
00225 #define MMCSR_IS_PRG            0x00000E00
00226 #define MMCSR_IS_DIS            0x00001000
00227 
00228 #define MMDR_ACCEPTED
00229 #define MMDR_CRC_ERROR
00230 #define MMDR_WRITE_ERROR
00231 
00232 #define MMCERR_TIMEOUT      0x00000001
00233 
00234 #define MMCOP_NBUSY         0x80000000
00235 
00237 #define MMCARD_CIDR_SIZE                16
00238 
00240 #define MMCARD_CSDR_SIZE                16
00241 
00243 #define MMCARD_OCR_SIZE                 32
00244 
00249 
00251 #define MMCARD_GETSTATUS    0x2001
00252 
00253 #define MMCARD_GETOCR       0x2002
00254 
00255 #define MMCARD_GETCID       0x2003
00256 
00257 #define MMCARD_GETCSD       0x2004
00258 
00264 typedef struct __attribute__ ((packed)) _MMC_CID {
00266     u_char mmcid_mid;
00268     u_short mmcid_oid;
00270     u_char mmcid_pnm[6];
00272     u_char mmcid_rev;
00274     u_long mmcid_psn;
00276     u_char mmcid_mdt;
00278     u_char mmcid_crc;
00279 } MMC_CID;
00280 
00284 typedef struct __attribute__ ((packed)) _MMC_CSD {
00286     u_char mmcsd_spec;
00288     u_char mmcsd_taac;
00290     u_char mmcsd_nsac;
00292     u_char mmcsd_speed;
00294     u_char mmcsd_ccc_bl[2];
00324     u_char mmcsd_rfld[8];
00326     u_char mmcsd_pfld;
00328     u_char mmcsd_crc;
00329 } MMC_CSD;
00330 
00333 __BEGIN_DECLS
00334 /* Prototypes */
00335 extern int MmCardDevInit(NUTDEVICE * dev);
00336 extern int MmCardIOCtl(NUTDEVICE * dev, int req, void *conf);
00337 extern int MmCardBlockRead(NUTFILE * nfp, void *buffer, int len);
00338 extern int MmCardBlockWrite(NUTFILE * nfp, CONST void *buffer, int len);
00339 #ifdef __HARVARD_ARCH__
00340 extern int MmCardBlockWrite_P(NUTFILE * nfp, PGM_P buffer, int len);
00341 #endif
00342 extern NUTFILE *MmCardMount(NUTDEVICE * dev, CONST char *name, int mode, int acc);
00343 extern int MmCardUnmount(NUTFILE * nfp);
00344 
00345 __END_DECLS
00346 /* End of prototypes */
00347 #endif

© 2000-2007 by egnite Software GmbH - visit http://www.ethernut.de/