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 
00059 #include <sys/device.h>
00060 #include <sys/file.h>
00061 
00066 
00070 typedef struct _MMCIFC {
00072     int (*mmcifc_in) (void);
00074      uint8_t(*mmcifc_io) (uint8_t);
00076     int (*mmcifc_cs) (int);
00078     int (*mmcifc_cd) (void);
00080     int (*mmcifc_wp) (void);
00081 } MMCIFC;
00082 
00083 #define MMCMD_HOST                      0x40
00084 #define MMCMD_RESET_CRC                 0x95
00085 
00091 #define MMCMD_GO_IDLE_STATE             0
00092 
00094 #define MMCMD_SEND_OP_COND              1
00095 
00101 #define MMCMD_ALL_SEND_CID              2
00102 
00104 #define MMCMD_SEND_RELATIVE_ADDR        3
00105 
00107 #define MMCMD_SELECT_CARD               7
00108 
00110 #define MMCMD_SEND_CSD                  9
00111 
00113 #define MMCMD_SEND_CID                  10
00114 
00116 #define MMCMD_STOP_TRANSMISSION         12
00117 
00119 #define MMCMD_SEND_STATUS               13
00120 
00122 #define MMCMD_SET_BLOCKLEN              16
00123 
00125 #define MMCMD_READ_SINGLE_BLOCK         17
00126 
00128 #define MMCMD_READ_MULTIPLE_BLOCK       18
00129 
00131 #define MMCMD_WRITE_BLOCK               24
00132 
00134 #define MMCMD_WRITE_MULTIPLE_BLOCK      25
00135 
00137 #define MMCMD_PROGRAM_CSD               27
00138 
00140 #define MMCMD_SET_WRITE_PROTECT         28
00141 
00143 #define MMCMD_CLR_WRITE_PROTECT         29
00144 
00146 #define MMCMD_SEND_WRITE_PROTECT        30
00147 
00149 #define MMCMD_TAG_ERASE_GROUP_START     35
00150 
00152 #define MMCMD_TAG_ERASE_GROUP_END       36
00153 
00155 #define MMCMD_ERASE                     38
00156 
00158 #define MMCMD_LOCK_UNLOCK               42
00159 
00161 #define MMCMD_READ_OCR                  58
00162 
00167 #define MMCMD_CRC_ON_OFF                59
00168 
00170 #define MMR1_IDLE_STATE         0x00
00171 
00172 #define MMR1_NOT_IDLE           0x01
00173 
00174 #define MMR1_ERASE_RESET        0x02
00175 
00176 #define MMR1_ILLEGAL_COMMAND    0x04
00177 
00178 #define MMR1_COM_CRC_ERROR      0x08
00179 
00180 #define MMR1_ERASE_SEQ_ERROR    0x10
00181 
00182 #define MMR1_ADDRESS_ERROR      0x20
00183 
00184 #define MMR1_PARAMETER_ERROR    0x40
00185 
00186 
00188 #define MMR2_CARD_LOCKED        0x01
00189 
00190 #define MMR2_WP_ERASE_SKIP      0x02
00191 
00192 #define MMR2_ERROR              0x04
00193 
00194 #define MMR2_CC_ERROR           0x08
00195 
00196 #define MMR2_ECC_FAILED         0x10
00197 
00198 #define MMR2_WP_VIOLATION       0x20
00199 
00200 #define MMR2_ERASE_PARAMETER    0x40
00201 
00202 #define MMR2_OUT_OF_RANGE       0x80
00203 
00204 
00205 #define MMCSR_OUT_OF_RANGE      0x80000000
00206 #define MMCSR_ADDRESS_ERROR     0x40000000
00207 #define MMCSR_BLOCK_LEN_ERROR   0x20000000
00208 #define MMCSR_ERASE_SEQ_ERROR   0x10000000
00209 #define MMCSR_ERASE_PARAM       0x08000000
00210 #define MMCSR_WP_VIOLATION      0x04000000
00211 #define MMCSR_COM_CRC_ERROR     0x00800000
00212 #define MMCSR_ILLEGAL_COMMAND   0x00400000
00213 #define MMCSR_ERROR             0x00080000
00214 #define MMCSR_CIDCSD_OVERWRITE  0x00010000
00215 #define MMCSR_WP_ERASE_SKIP     0x00008000
00216 #define MMCSR_CARD_ECC_DISABLED 0x00004000
00217 #define MMCSR_ERASE_RESET       0x00002000
00218 #define MMCSR_STATE_MASK        0x00001E00
00219 #define MMCSR_READY_FOR_DATA    0x00000100
00220 
00221 #define MMCSR_IS_IDLE           0x00000000
00222 #define MMCSR_IS_READY          0x00000200
00223 #define MMCSR_IS_IDENT          0x00000400
00224 #define MMCSR_IS_STBY           0x00000600
00225 #define MMCSR_IS_TRAN           0x00000800
00226 #define MMCSR_IS_DATA           0x00000A00
00227 #define MMCSR_IS_RCV            0x00000C00
00228 #define MMCSR_IS_PRG            0x00000E00
00229 #define MMCSR_IS_DIS            0x00001000
00230 
00231 #define MMDR_ACCEPTED
00232 #define MMDR_CRC_ERROR
00233 #define MMDR_WRITE_ERROR
00234 
00235 #define MMCERR_TIMEOUT      0x00000001
00236 
00237 #define MMCOP_NBUSY         0x80000000
00238 
00240 #define MMCARD_CIDR_SIZE                16
00241 
00243 #define MMCARD_CSDR_SIZE                16
00244 
00246 #define MMCARD_OCR_SIZE                 32
00247 
00252 
00254 #define MMCARD_GETSTATUS    0x2001
00255 
00256 #define MMCARD_GETOCR       0x2002
00257 
00258 #define MMCARD_GETCID       0x2003
00259 
00260 #define MMCARD_GETCSD       0x2004
00261 
00267 typedef struct __attribute__ ((packed)) _MMC_CID {
00269     uint8_t mmcid_mid;
00271     uint16_t mmcid_oid;
00273     uint8_t mmcid_pnm[6];
00275     uint8_t mmcid_rev;
00277     uint32_t mmcid_psn;
00279     uint8_t mmcid_mdt;
00281     uint8_t mmcid_crc;
00282 } MMC_CID;
00283 
00287 typedef struct __attribute__ ((packed)) _MMC_CSD {
00289     uint8_t mmcsd_spec;
00291     uint8_t mmcsd_taac;
00293     uint8_t mmcsd_nsac;
00295     uint8_t mmcsd_speed;
00297     uint8_t mmcsd_ccc_bl[2];
00327     uint8_t mmcsd_rfld[8];
00329     uint8_t mmcsd_pfld;
00331     uint8_t mmcsd_crc;
00332 } MMC_CSD;
00333 
00336 __BEGIN_DECLS
00337 /* Prototypes */
00338 extern int MmCardDevInit(NUTDEVICE * dev);
00339 extern int MmCardIOCtl(NUTDEVICE * dev, int req, void *conf);
00340 extern int MmCardBlockRead(NUTFILE * nfp, void *buffer, int len);
00341 extern int MmCardBlockWrite(NUTFILE * nfp, CONST void *buffer, int len);
00342 #ifdef __HARVARD_ARCH__
00343 extern int MmCardBlockWrite_P(NUTFILE * nfp, PGM_P buffer, int len);
00344 #endif
00345 extern NUTFILE *MmCardMount(NUTDEVICE * dev, CONST char *name, int mode, int acc);
00346 extern int MmCardUnmount(NUTFILE * nfp);
00347 
00348 __END_DECLS
00349 /* End of prototypes */
00350 #endif

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