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 
00062 #include <sys/device.h>
00063 #include <sys/file.h>
00064 
00069 
00073 typedef struct _MMCIFC {
00075     int (*mmcifc_in) (void);
00077      uint8_t(*mmcifc_io) (uint8_t);
00079     int (*mmcifc_cs) (int);
00081     int (*mmcifc_cd) (void);
00083     int (*mmcifc_wp) (void);
00084 } MMCIFC;
00085 
00086 #define MMCMD_HOST                      0x40
00087 #define MMCMD_RESET_CRC                 0x95
00088 
00094 #define MMCMD_GO_IDLE_STATE             0
00095 
00097 #define MMCMD_SEND_OP_COND              1
00098 
00104 #define MMCMD_ALL_SEND_CID              2
00105 
00107 #define MMCMD_SEND_RELATIVE_ADDR        3
00108 
00110 #define MMCMD_SELECT_CARD               7
00111 
00113 #define MMCMD_SEND_CSD                  9
00114 
00116 #define MMCMD_SEND_CID                  10
00117 
00119 #define MMCMD_STOP_TRANSMISSION         12
00120 
00122 #define MMCMD_SEND_STATUS               13
00123 
00125 #define MMCMD_SET_BLOCKLEN              16
00126 
00128 #define MMCMD_READ_SINGLE_BLOCK         17
00129 
00131 #define MMCMD_READ_MULTIPLE_BLOCK       18
00132 
00134 #define MMCMD_WRITE_BLOCK               24
00135 
00137 #define MMCMD_WRITE_MULTIPLE_BLOCK      25
00138 
00140 #define MMCMD_PROGRAM_CSD               27
00141 
00143 #define MMCMD_SET_WRITE_PROTECT         28
00144 
00146 #define MMCMD_CLR_WRITE_PROTECT         29
00147 
00149 #define MMCMD_SEND_WRITE_PROTECT        30
00150 
00152 #define MMCMD_TAG_ERASE_GROUP_START     35
00153 
00155 #define MMCMD_TAG_ERASE_GROUP_END       36
00156 
00158 #define MMCMD_ERASE                     38
00159 
00161 #define MMCMD_SEND_APP_OP_COND          41
00162 
00164 #define MMCMD_LOCK_UNLOCK               42
00165 
00167 #define MMCMD_SEND_APP_CMD              55
00168 
00170 #define MMCMD_READ_OCR                  58
00171 
00176 #define MMCMD_CRC_ON_OFF                59
00177 
00179 #define MMR1_IDLE_STATE         0x00
00180 
00181 #define MMR1_NOT_IDLE           0x01
00182 
00183 #define MMR1_ERASE_RESET        0x02
00184 
00185 #define MMR1_ILLEGAL_COMMAND    0x04
00186 
00187 #define MMR1_COM_CRC_ERROR      0x08
00188 
00189 #define MMR1_ERASE_SEQ_ERROR    0x10
00190 
00191 #define MMR1_ADDRESS_ERROR      0x20
00192 
00193 #define MMR1_PARAMETER_ERROR    0x40
00194 
00195 
00197 #define MMR2_CARD_LOCKED        0x01
00198 
00199 #define MMR2_WP_ERASE_SKIP      0x02
00200 
00201 #define MMR2_ERROR              0x04
00202 
00203 #define MMR2_CC_ERROR           0x08
00204 
00205 #define MMR2_ECC_FAILED         0x10
00206 
00207 #define MMR2_WP_VIOLATION       0x20
00208 
00209 #define MMR2_ERASE_PARAMETER    0x40
00210 
00211 #define MMR2_OUT_OF_RANGE       0x80
00212 
00213 
00214 #define MMCSR_OUT_OF_RANGE      0x80000000
00215 #define MMCSR_ADDRESS_ERROR     0x40000000
00216 #define MMCSR_BLOCK_LEN_ERROR   0x20000000
00217 #define MMCSR_ERASE_SEQ_ERROR   0x10000000
00218 #define MMCSR_ERASE_PARAM       0x08000000
00219 #define MMCSR_WP_VIOLATION      0x04000000
00220 #define MMCSR_COM_CRC_ERROR     0x00800000
00221 #define MMCSR_ILLEGAL_COMMAND   0x00400000
00222 #define MMCSR_ERROR             0x00080000
00223 #define MMCSR_CIDCSD_OVERWRITE  0x00010000
00224 #define MMCSR_WP_ERASE_SKIP     0x00008000
00225 #define MMCSR_CARD_ECC_DISABLED 0x00004000
00226 #define MMCSR_ERASE_RESET       0x00002000
00227 #define MMCSR_STATE_MASK        0x00001E00
00228 #define MMCSR_READY_FOR_DATA    0x00000100
00229 
00230 #define MMCSR_IS_IDLE           0x00000000
00231 #define MMCSR_IS_READY          0x00000200
00232 #define MMCSR_IS_IDENT          0x00000400
00233 #define MMCSR_IS_STBY           0x00000600
00234 #define MMCSR_IS_TRAN           0x00000800
00235 #define MMCSR_IS_DATA           0x00000A00
00236 #define MMCSR_IS_RCV            0x00000C00
00237 #define MMCSR_IS_PRG            0x00000E00
00238 #define MMCSR_IS_DIS            0x00001000
00239 
00240 #define MMDR_ACCEPTED
00241 #define MMDR_CRC_ERROR
00242 #define MMDR_WRITE_ERROR
00243 
00244 #define MMCERR_TIMEOUT      0x00000001
00245 
00246 #define MMCOP_NBUSY         0x80000000
00247 
00249 #define MMCARD_CIDR_SIZE                16
00250 
00252 #define MMCARD_CSDR_SIZE                16
00253 
00255 #define MMCARD_OCR_SIZE                 32
00256 
00261 #define MMCARD_165_195V     0x00000080
00262 #define MMCARD_20_21V       0x00000100
00263 #define MMCARD_21_22V       0x00000200
00264 #define MMCARD_22_23V       0x00000400
00265 #define MMCARD_23_24V       0x00000800
00266 #define MMCARD_24_25V       0x00001000
00267 #define MMCARD_25_26V       0x00002000
00268 #define MMCARD_26_27V       0x00004000
00269 #define MMCARD_27_28V       0x00008000
00270 #define MMCARD_28_29V       0x00010000
00271 #define MMCARD_29_30V       0x00020000
00272 #define MMCARD_30_31V       0x00040000
00273 #define MMCARD_31_32V       0x00080000
00274 #define MMCARD_32_33V       0x00100000
00275 #define MMCARD_33_34V       0x00200000
00276 #define MMCARD_34_35V       0x00400000
00277 #define MMCARD_35_36V       0x00800000
00278 
00284 
00286 #define MMCARD_GETSTATUS    0x2001
00287 
00288 #define MMCARD_GETOCR       0x2002
00289 
00290 #define MMCARD_GETCID       0x2003
00291 
00292 #define MMCARD_GETCSD       0x2004
00293 
00299 typedef struct __attribute__ ((packed)) _MMC_CID {
00301     uint8_t mmcid_mid;
00303     uint16_t mmcid_oid;
00305     uint8_t mmcid_pnm[6];
00307     uint8_t mmcid_rev;
00309     uint32_t mmcid_psn;
00311     uint8_t mmcid_mdt;
00313     uint8_t mmcid_crc;
00314 } MMC_CID;
00315 
00319 typedef struct __attribute__ ((packed)) _MMC_CSD {
00321     uint8_t mmcsd_spec;
00323     uint8_t mmcsd_taac;
00325     uint8_t mmcsd_nsac;
00327     uint8_t mmcsd_speed;
00329     uint8_t mmcsd_ccc_bl[2];
00359     uint8_t mmcsd_rfld[8];
00361     uint8_t mmcsd_pfld;
00363     uint8_t mmcsd_crc;
00364 } MMC_CSD;
00365 
00368 __BEGIN_DECLS
00369 /* Prototypes */
00370 extern int MmCardDevInit(NUTDEVICE * dev);
00371 extern int MmCardIOCtl(NUTDEVICE * dev, int req, void *conf);
00372 extern int MmCardBlockRead(NUTFILE * nfp, void *buffer, int len);
00373 extern int MmCardBlockWrite(NUTFILE * nfp, CONST void *buffer, int len);
00374 #ifdef __HARVARD_ARCH__
00375 extern int MmCardBlockWrite_P(NUTFILE * nfp, PGM_P buffer, int len);
00376 #endif
00377 extern NUTFILE *MmCardMount(NUTDEVICE * dev, CONST char *name, int mode, int acc);
00378 extern int MmCardUnmount(NUTFILE * nfp);
00379 
00380 __END_DECLS
00381 /* End of prototypes */
00382 #endif

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