Go to the documentation of this file.00001 #ifndef _DEV_MMCARD_H_
00002 #define _DEV_MMCARD_H_
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00062 #include <sys/device.h>
00063 #include <sys/file.h>
00064
00069
00070 #define NUTMC_SF_CD 0x01
00071 #define NUTMC_SF_WP 0x02
00072
00073 #define NUTMC_IND_OFF 0
00074 #define NUTMC_IND_READ 1
00075 #define NUTMC_IND_WRITE 2
00076 #define NUTMC_IND_ERROR 4
00077
00081 typedef struct _MEMCARDSUPP {
00083 uint8_t mcs_cf;
00085 uint8_t mcs_sf;
00087 int (*mcs_reset) (NUTDEVICE *);
00089 void (*mcs_act) (int);
00091 int (*mcs_power) (int);
00092 } MEMCARDSUPP;
00093
00097 typedef struct _MMCIFC {
00099 int (*mmcifc_in) (void);
00101 uint8_t(*mmcifc_io) (uint8_t);
00103 int (*mmcifc_cs) (int);
00105 int (*mmcifc_cd) (void);
00107 int (*mmcifc_wp) (void);
00108 } MMCIFC;
00109
00110 #define MMCMD_HOST 0x40
00111 #define MMCMD_RESET_CRC 0x95
00112
00118 #define MMCMD_GO_IDLE_STATE 0
00119
00121 #define MMCMD_SEND_OP_COND 1
00122
00128 #define MMCMD_ALL_SEND_CID 2
00129
00131 #define MMCMD_SEND_RELATIVE_ADDR 3
00132
00134 #define MMCMD_SELECT_CARD 7
00135
00137 #define MMCMD_SEND_EXTCSD 8
00138
00140 #define MMCMD_SEND_CSD 9
00141
00143 #define MMCMD_SEND_CID 10
00144
00146 #define MMCMD_STOP_TRANSMISSION 12
00147
00149 #define MMCMD_SEND_STATUS 13
00150
00152 #define MMCMD_SET_BLOCKLEN 16
00153
00155 #define MMCMD_READ_SINGLE_BLOCK 17
00156
00158 #define MMCMD_READ_MULTIPLE_BLOCK 18
00159
00161 #define MMCMD_WRITE_BLOCK 24
00162
00164 #define MMCMD_WRITE_MULTIPLE_BLOCK 25
00165
00167 #define MMCMD_PROGRAM_CSD 27
00168
00170 #define MMCMD_SET_WRITE_PROTECT 28
00171
00173 #define MMCMD_CLR_WRITE_PROTECT 29
00174
00176 #define MMCMD_SEND_WRITE_PROTECT 30
00177
00179 #define MMCMD_TAG_ERASE_GROUP_START 35
00180
00182 #define MMCMD_TAG_ERASE_GROUP_END 36
00183
00185 #define MMCMD_ERASE 38
00186
00188 #define MMCMD_SEND_APP_OP_COND 41
00189
00191 #define MMCMD_LOCK_UNLOCK 42
00192
00194 #define MMCMD_SEND_APP_CMD 55
00195
00197 #define MMCMD_READ_OCR 58
00198
00203 #define MMCMD_CRC_ON_OFF 59
00204
00206 #define MMR1_IDLE_STATE 0x00
00207
00208 #define MMR1_NOT_IDLE 0x01
00209
00210 #define MMR1_ERASE_RESET 0x02
00211
00212 #define MMR1_ILLEGAL_COMMAND 0x04
00213
00214 #define MMR1_COM_CRC_ERROR 0x08
00215
00216 #define MMR1_ERASE_SEQ_ERROR 0x10
00217
00218 #define MMR1_ADDRESS_ERROR 0x20
00219
00220 #define MMR1_PARAMETER_ERROR 0x40
00221
00222
00224 #define MMR2_CARD_LOCKED 0x01
00225
00226 #define MMR2_WP_ERASE_SKIP 0x02
00227
00228 #define MMR2_ERROR 0x04
00229
00230 #define MMR2_CC_ERROR 0x08
00231
00232 #define MMR2_ECC_FAILED 0x10
00233
00234 #define MMR2_WP_VIOLATION 0x20
00235
00236 #define MMR2_ERASE_PARAMETER 0x40
00237
00238 #define MMR2_OUT_OF_RANGE 0x80
00239
00240
00241 #define MMCSR_OUT_OF_RANGE 0x80000000
00242 #define MMCSR_ADDRESS_ERROR 0x40000000
00243 #define MMCSR_BLOCK_LEN_ERROR 0x20000000
00244 #define MMCSR_ERASE_SEQ_ERROR 0x10000000
00245 #define MMCSR_ERASE_PARAM 0x08000000
00246 #define MMCSR_WP_VIOLATION 0x04000000
00247 #define MMCSR_COM_CRC_ERROR 0x00800000
00248 #define MMCSR_ILLEGAL_COMMAND 0x00400000
00249 #define MMCSR_ERROR 0x00080000
00250 #define MMCSR_CIDCSD_OVERWRITE 0x00010000
00251 #define MMCSR_WP_ERASE_SKIP 0x00008000
00252 #define MMCSR_CARD_ECC_DISABLED 0x00004000
00253 #define MMCSR_ERASE_RESET 0x00002000
00254 #define MMCSR_STATE_MASK 0x00001E00
00255 #define MMCSR_READY_FOR_DATA 0x00000100
00256
00257 #define MMCSR_IS_IDLE 0x00000000
00258 #define MMCSR_IS_READY 0x00000200
00259 #define MMCSR_IS_IDENT 0x00000400
00260 #define MMCSR_IS_STBY 0x00000600
00261 #define MMCSR_IS_TRAN 0x00000800
00262 #define MMCSR_IS_DATA 0x00000A00
00263 #define MMCSR_IS_RCV 0x00000C00
00264 #define MMCSR_IS_PRG 0x00000E00
00265 #define MMCSR_IS_DIS 0x00001000
00266
00267 #define MMDR_ACCEPTED
00268 #define MMDR_CRC_ERROR
00269 #define MMDR_WRITE_ERROR
00270
00271 #define MMCERR_TIMEOUT 0x00000001
00272
00273 #define MMCOP_NBUSY 0x80000000
00274
00276 #define MMCARD_CIDR_SIZE 16
00277
00279 #define MMCARD_CSDR_SIZE 16
00280
00282 #define MMCARD_OCR_SIZE 32
00283
00288 #define MMCARD_165_195V 0x00000080
00289 #define MMCARD_20_21V 0x00000100
00290 #define MMCARD_21_22V 0x00000200
00291 #define MMCARD_22_23V 0x00000400
00292 #define MMCARD_23_24V 0x00000800
00293 #define MMCARD_24_25V 0x00001000
00294 #define MMCARD_25_26V 0x00002000
00295 #define MMCARD_26_27V 0x00004000
00296 #define MMCARD_27_28V 0x00008000
00297 #define MMCARD_28_29V 0x00010000
00298 #define MMCARD_29_30V 0x00020000
00299 #define MMCARD_30_31V 0x00040000
00300 #define MMCARD_31_32V 0x00080000
00301 #define MMCARD_32_33V 0x00100000
00302 #define MMCARD_33_34V 0x00200000
00303 #define MMCARD_34_35V 0x00400000
00304 #define MMCARD_35_36V 0x00800000
00305
00311
00313 #define MMCARD_GETSTATUS 0x2001
00314
00315 #define MMCARD_GETOCR 0x2002
00316
00317 #define MMCARD_GETCID 0x2003
00318
00319 #define MMCARD_GETCSD 0x2004
00320
00321 #define MMCARD_GETEXTCSD 0x2005
00322
00328 typedef struct __attribute__ ((packed)) _MMC_CID {
00330 uint8_t mmcid_mid;
00332 uint16_t mmcid_oid;
00334 uint8_t mmcid_pnm[6];
00336 uint8_t mmcid_rev;
00338 uint32_t mmcid_psn;
00340 uint8_t mmcid_mdt;
00342 uint8_t mmcid_crc;
00343 } MMC_CID;
00344
00348 typedef struct __attribute__ ((packed)) _MMC_CSD {
00350 uint8_t mmcsd_spec;
00352 uint8_t mmcsd_taac;
00354 uint8_t mmcsd_nsac;
00356 uint8_t mmcsd_speed;
00358 uint8_t mmcsd_ccc_bl[2];
00388 uint8_t mmcsd_rfld[8];
00390 uint8_t mmcsd_pfld;
00392 uint8_t mmcsd_crc;
00393 } MMC_CSD;
00394
00397 __BEGIN_DECLS
00398
00399 extern int MmCardDevInit(NUTDEVICE * dev);
00400 extern int MmCardIOCtl(NUTDEVICE * dev, int req, void *conf);
00401 extern int MmCardBlockRead(NUTFILE * nfp, void *buffer, int len);
00402 extern int MmCardBlockWrite(NUTFILE * nfp, CONST void *buffer, int len);
00403 #ifdef __HARVARD_ARCH__
00404 extern int MmCardBlockWrite_P(NUTFILE * nfp, PGM_P buffer, int len);
00405 #endif
00406 extern NUTFILE *MmCardMount(NUTDEVICE * dev, CONST char *name, int mode, int acc);
00407 extern int MmCardUnmount(NUTFILE * nfp);
00408
00409 extern int SpiMmcInit(NUTDEVICE * dev);
00410 extern int SpiMmcIOCtl(NUTDEVICE * dev, int req, void *conf);
00411 extern int SpiMmcBlockRead(NUTFILE * nfp, void *buffer, int num);
00412 extern int SpiMmcBlockWrite(NUTFILE * nfp, CONST void *buffer, int num);
00413 #ifdef __HARVARD_ARCH__
00414 extern int SpiMmcBlockWrite_P(NUTFILE * nfp, PGM_P buffer, int len);
00415 #endif
00416 extern NUTFILE *SpiMmcMount(NUTDEVICE * dev, CONST char *name, int mode, int acc);
00417 extern int SpiMmcUnmount(NUTFILE * nfp);
00418
00419 __END_DECLS
00420
00421 #endif