Nut/OS  4.10.3
API Reference
Multimedia Card Driver

Block device driver for MM/SD Cards. More...

Collaboration diagram for Multimedia Card Driver:

Data Structures

struct  _MEMCARDSUPP
 Memory card support structure. More...
struct  _MMCIFC
 Low level access information structure. More...
struct  _MMC_CID
 Multimedia card identification register. More...
struct  _MMC_CSD
 Multimedia card identification register. More...
struct  _MMCFCB
 Local multimedia card mount information. More...

Defines

#define NUTMC_SF_CD   0x01
#define NUTMC_SF_WP   0x02
#define NUTMC_IND_OFF   0
#define NUTMC_IND_READ   1
#define NUTMC_IND_WRITE   2
#define NUTMC_IND_ERROR   4
#define MMCMD_HOST   0x40
#define MMCMD_RESET_CRC   0x95
#define MMCMD_GO_IDLE_STATE   0
 Reset card to idle state.
#define MMCMD_SEND_OP_COND   1
 Activate card's initialization process.
#define MMCMD_ALL_SEND_CID   2
 Send operation condition register.
#define MMCMD_SEND_RELATIVE_ADDR   3
 Assign relative card address.
#define MMCMD_SELECT_CARD   7
 Assign relative card address.
#define MMCMD_SEND_EXTCSD   8
 Query card's extended CSD.
#define MMCMD_SEND_CSD   9
 Query card's CSD.
#define MMCMD_SEND_CID   10
 Query card's CID.
#define MMCMD_STOP_TRANSMISSION   12
 Stop multiple block transmission.
#define MMCMD_SEND_STATUS   13
 Query card's status register.
#define MMCMD_SET_BLOCKLEN   16
 Select block length for following read/write commands.
#define MMCMD_READ_SINGLE_BLOCK   17
 Initiate single block read.
#define MMCMD_READ_MULTIPLE_BLOCK   18
 Initiate continuous block read.
#define MMCMD_WRITE_BLOCK   24
 Initiate single block write.
#define MMCMD_WRITE_MULTIPLE_BLOCK   25
 Initiate continuous block write.
#define MMCMD_PROGRAM_CSD   27
 Initiate programming of programmable CSD bits.
#define MMCMD_SET_WRITE_PROTECT   28
 Enable card's optional write protection.
#define MMCMD_CLR_WRITE_PROTECT   29
 Disable card's write protection.
#define MMCMD_SEND_WRITE_PROTECT   30
 Query card's write protect status.
#define MMCMD_TAG_ERASE_GROUP_START   35
 Set address of the first erase group.
#define MMCMD_TAG_ERASE_GROUP_END   36
 Set address of the last erase group.
#define MMCMD_ERASE   38
 Erase previously selected sectors.
#define MMCMD_SEND_APP_OP_COND   41
 Activate SD card's initialization process.
#define MMCMD_LOCK_UNLOCK   42
 Set/clear password or lock/unlock the card.
#define MMCMD_SEND_APP_CMD   55
 Application command follows.
#define MMCMD_READ_OCR   58
 Query card's operating condition register.
#define MMCMD_CRC_ON_OFF   59
 Enable or disable CRC mode.
#define MMR1_IDLE_STATE   0x00
 Card is idle.
#define MMR1_NOT_IDLE   0x01
 Card is busy.
#define MMR1_ERASE_RESET   0x02
 Erase sequence was cleared before execution.
#define MMR1_ILLEGAL_COMMAND   0x04
 Illegal command code detected.
#define MMR1_COM_CRC_ERROR   0x08
 Bad command CRC detected.
#define MMR1_ERASE_SEQ_ERROR   0x10
 Bad erase sequence.
#define MMR1_ADDRESS_ERROR   0x20
 Misaligned address did not match block length.
#define MMR1_PARAMETER_ERROR   0x40
 Command parameter is out of range.
#define MMR2_CARD_LOCKED   0x01
 Card is locked.
#define MMR2_WP_ERASE_SKIP   0x02
 Erasing write protected sector or password error.
#define MMR2_ERROR   0x04
 General or unknown error occured.
#define MMR2_CC_ERROR   0x08
 Internal card controller error.
#define MMR2_ECC_FAILED   0x10
 Bad internal ECC.
#define MMR2_WP_VIOLATION   0x20
 Failed to write to protected block.
#define MMR2_ERASE_PARAMETER   0x40
 Invalid erase parameter.
#define MMR2_OUT_OF_RANGE   0x80
 Command parameter is out of range.
#define MMCSR_OUT_OF_RANGE   0x80000000
#define MMCSR_ADDRESS_ERROR   0x40000000
#define MMCSR_BLOCK_LEN_ERROR   0x20000000
#define MMCSR_ERASE_SEQ_ERROR   0x10000000
#define MMCSR_ERASE_PARAM   0x08000000
#define MMCSR_WP_VIOLATION   0x04000000
#define MMCSR_COM_CRC_ERROR   0x00800000
#define MMCSR_ILLEGAL_COMMAND   0x00400000
#define MMCSR_ERROR   0x00080000
#define MMCSR_CIDCSD_OVERWRITE   0x00010000
#define MMCSR_WP_ERASE_SKIP   0x00008000
#define MMCSR_CARD_ECC_DISABLED   0x00004000
#define MMCSR_ERASE_RESET   0x00002000
#define MMCSR_STATE_MASK   0x00001E00
#define MMCSR_READY_FOR_DATA   0x00000100
#define MMCSR_IS_IDLE   0x00000000
#define MMCSR_IS_READY   0x00000200
#define MMCSR_IS_IDENT   0x00000400
#define MMCSR_IS_STBY   0x00000600
#define MMCSR_IS_TRAN   0x00000800
#define MMCSR_IS_DATA   0x00000A00
#define MMCSR_IS_RCV   0x00000C00
#define MMCSR_IS_PRG   0x00000E00
#define MMCSR_IS_DIS   0x00001000
#define MMDR_ACCEPTED
#define MMDR_CRC_ERROR
#define MMDR_WRITE_ERROR
#define MMCERR_TIMEOUT   0x00000001
#define MMCOP_NBUSY   0x80000000
#define MMCARD_CIDR_SIZE   16
 Number of bytes in the CID register.
#define MMCARD_CSDR_SIZE   16
 Number of bytes in the CSD register.
#define MMCARD_OCR_SIZE   32
 Number of bytes in the operating condition register.
#define MMC_BLOCK_SIZE   512
 Block size.
#define MMC_MAX_INIT_POLLS   512
 Card init timeout.
#define MMC_MAX_RESET_POLLS   255
 Card reset timeout.
#define MMC_MAX_WRITE_POLLS   1024
 Card write timeout.
#define MMC_MAX_WRITE_RETRIES   32
 Card write retries.
#define MMC_MAX_READ_RETRIES   8
 Card read retries.
#define MMC_MAX_REG_POLLS   512
 Register read timeout.
#define MMC_MAX_CMDACK_POLLS   1024
 Command acknowledge timeout.
#define MMC_MAX_R1_POLLS   1024
 R1 response timeout.
#define MMC_BLOCK_SIZE   512
 Block size.
#define MMC_MAX_INIT_POLLS   512
 Card init timeout.
#define MMC_MAX_RESET_RETRIES   2
 Card reset timeout.
#define MMC_MAX_WRITE_RETRIES   2
 Card write retries.
#define MMC_MAX_READ_RETRIES   MMC_MAX_WRITE_RETRIES
 Card read retries.
#define MMC_MAX_CMDACK_POLLS   1024
 Command acknowledge timeout.
#define MMC_MAX_READY_POLLS   800
 Card busy timeout.

Typedefs

typedef struct _MEMCARDSUPP MEMCARDSUPP
 Memory card support structure.
typedef struct _MMCIFC MMCIFC
 Low level access information structure.
typedef struct _MMC_CID MMC_CID
 Multimedia card identification register.
typedef struct _MMC_CSD MMC_CSD
 Multimedia card identification register.
typedef struct _MMCFCB MMCFCB
 Local multimedia card mount information.
typedef struct _MMCFCB MMCFCB
 Local multimedia card status information.

Functions

int MmCardBlockRead (NUTFILE *nfp, void *buffer, int num)
 Read data blocks from a mounted partition.
int MmCardBlockWrite (NUTFILE *nfp, CONST void *buffer, int num)
 Write data blocks to a mounted partition.
int MmCardBlockWrite_P (NUTFILE *nfp, PGM_P buffer, int num)
 Write data blocks from program space to a mounted partition.
NUTFILEMmCardMount (NUTDEVICE *dev, CONST char *name, int mode, int acc)
 Mount a partition.
int MmCardUnmount (NUTFILE *nfp)
 Unmount a previously mounted partition.
int MmCardIOCtl (NUTDEVICE *dev, int req, void *conf)
 Perform MMC control functions.
int MmCardDevInit (NUTDEVICE *dev)
 Initialize high level MMC driver.
int SpiMmcBlockRead (NUTFILE *nfp, void *buffer, int num)
 Read data blocks from a mounted partition.
int SpiMmcBlockWrite (NUTFILE *nfp, CONST void *buffer, int num)
 Write data blocks to a mounted partition.
int SpiMmcBlockWrite_P (NUTFILE *nfp, PGM_P buffer, int num)
 Write data blocks from program space to a mounted partition.
int SpiMmcUnmount (NUTFILE *nfp)
 Unmount a previously mounted partition.
NUTFILESpiMmcMount (NUTDEVICE *dev, CONST char *name, int mode, int acc)
 Mount a partition.
int SpiMmcIOCtl (NUTDEVICE *dev, int req, void *conf)
 Perform MMC control functions.
int SpiMmcInit (NUTDEVICE *dev)
 Initialize MMC driver.

Voltage Ranges

#define MMCARD_165_195V   0x00000080
#define MMCARD_20_21V   0x00000100
#define MMCARD_21_22V   0x00000200
#define MMCARD_22_23V   0x00000400
#define MMCARD_23_24V   0x00000800
#define MMCARD_24_25V   0x00001000
#define MMCARD_25_26V   0x00002000
#define MMCARD_26_27V   0x00004000
#define MMCARD_27_28V   0x00008000
#define MMCARD_28_29V   0x00010000
#define MMCARD_29_30V   0x00020000
#define MMCARD_30_31V   0x00040000
#define MMCARD_31_32V   0x00080000
#define MMCARD_32_33V   0x00100000
#define MMCARD_33_34V   0x00200000
#define MMCARD_34_35V   0x00400000
#define MMCARD_35_36V   0x00800000

Control Codes

#define MMCARD_GETSTATUS   0x2001
 Retrieve card status.
#define MMCARD_GETOCR   0x2002
 Retrieve operation condition register.
#define MMCARD_GETCID   0x2003
 Retrieve card identification.
#define MMCARD_GETCSD   0x2004
 Retrieve card specific data.
#define MMCARD_GETEXTCSD   0x2005
 Retrieve extended card specific data.

Detailed Description

Block device driver for MM/SD Cards.

Basic SPI bus block device driver for multimedia cards.

Basic block device driver for multimedia cards.

The driver uses SPI mode, but doesn't include any low level hardware access. This must be provided by some additional routines.

 *
 * $Log$
 * Revision 1.15  2009/02/13 14:52:05  haraldkipp
 * Include memdebug.h for heap management debugging support.
 *
 * Revision 1.14  2009/02/06 15:40:29  haraldkipp
 * Using newly available strdup() and calloc().
 * Replaced NutHeap routines by standard malloc/free.
 * Replaced pointer value 0 by NULL.
 *
 * Revision 1.13  2009/01/17 11:26:46  haraldkipp
 * Getting rid of two remaining BSD types in favor of stdint.
 * Replaced 'u_int' by 'unsinged int' and 'uptr_t' by 'uintptr_t'.
 *
 * Revision 1.12  2008/08/11 06:59:42  haraldkipp
 * BSD types replaced by stdint types (feature request #1282721).
 *
 * Revision 1.11  2008/07/14 13:09:30  haraldkipp
 * Allow small MultiMedia Cards without partition table.
 *
 * Revision 1.10  2007/08/30 12:15:06  haraldkipp
 * Configurable MMC timings.
 *
 * Revision 1.9  2006/10/08 16:48:09  haraldkipp
 * Documentation fixed
 *
 * Revision 1.8  2006/07/05 08:03:12  haraldkipp
 * Bugfix. Trailing slash in mount path not properly handled.
 * Thanks to Michael Fischer.
 *
 * Revision 1.7  2006/06/18 16:34:46  haraldkipp
 * Mutex deadlock fixed.
 *
 * Revision 1.6  2006/05/25 09:34:21  haraldkipp
 * Added mutual exclusion lock for multithreaded access.
 *
 * Revision 1.5  2006/04/07 12:29:03  haraldkipp
 * Number of read retries increased. Memory hole fixed.
 * Added ioctl(NUTBLKDEV_MEDIAAVAIL).
 * Card change ioctl() will also return 1 if no card is available.
 *
 * Revision 1.4  2006/02/23 15:43:56  haraldkipp
 * Timeout value increased. Some cards have long write latencies.
 *
 * Revision 1.3  2006/01/22 17:36:31  haraldkipp
 * Some cards need more time to enter idle state.
 * Card access now returns an error after card change detection.
 *
 * Revision 1.2  2006/01/19 18:40:08  haraldkipp
 * Timeouts increased and long time sleeps decreased for better performance.
 *
 * Revision 1.1  2006/01/05 16:30:49  haraldkipp
 * First check-in.
 *
 *
 * 

The driver provides generic memory card access, but doesn't include low level hardware support like card detection. This must be provided by a hardware specific support module.

 *
 * $Id$
 *
 * 

Define Documentation

#define NUTMC_SF_CD   0x01

Definition at line 70 of file mmcard.h.

Referenced by SpiMmcIOCtl(), and SpiMmcMount().

#define NUTMC_SF_WP   0x02

Definition at line 71 of file mmcard.h.

#define NUTMC_IND_OFF   0

Definition at line 73 of file mmcard.h.

Referenced by SpiMmcBlockRead(), and SpiMmcBlockWrite().

#define NUTMC_IND_READ   1

Definition at line 74 of file mmcard.h.

Referenced by SpiMmcBlockRead().

#define NUTMC_IND_WRITE   2

Definition at line 75 of file mmcard.h.

Referenced by SpiMmcBlockWrite().

#define NUTMC_IND_ERROR   4

Definition at line 76 of file mmcard.h.

Referenced by SpiMmcBlockRead(), and SpiMmcBlockWrite().

#define MMCMD_HOST   0x40

Definition at line 110 of file mmcard.h.

#define MMCMD_RESET_CRC   0x95

Definition at line 111 of file mmcard.h.

#define MMCMD_GO_IDLE_STATE   0

Reset card to idle state.

In idle state the card will not accept any other commands than MMCMD_SEND_OP_COND or MMCMD_READ_OCR.

Definition at line 118 of file mmcard.h.

#define MMCMD_SEND_OP_COND   1

Activate card's initialization process.

Definition at line 121 of file mmcard.h.

#define MMCMD_ALL_SEND_CID   2

Send operation condition register.

Queries the operation condition register content from all cards, which are in idle state.

Definition at line 128 of file mmcard.h.

#define MMCMD_SEND_RELATIVE_ADDR   3

Assign relative card address.

Definition at line 131 of file mmcard.h.

#define MMCMD_SELECT_CARD   7

Assign relative card address.

Definition at line 134 of file mmcard.h.

#define MMCMD_SEND_EXTCSD   8

Query card's extended CSD.

Definition at line 137 of file mmcard.h.

Referenced by SpiMmcIOCtl().

#define MMCMD_SEND_CSD   9

Query card's CSD.

Definition at line 140 of file mmcard.h.

Referenced by MmCardIOCtl(), and SpiMmcIOCtl().

#define MMCMD_SEND_CID   10

Query card's CID.

Definition at line 143 of file mmcard.h.

Referenced by MmCardIOCtl(), and SpiMmcIOCtl().

#define MMCMD_STOP_TRANSMISSION   12

Stop multiple block transmission.

Definition at line 146 of file mmcard.h.

#define MMCMD_SEND_STATUS   13

Query card's status register.

Definition at line 149 of file mmcard.h.

Referenced by MmCardIOCtl(), and SpiMmcIOCtl().

#define MMCMD_SET_BLOCKLEN   16

Select block length for following read/write commands.

Definition at line 152 of file mmcard.h.

#define MMCMD_READ_SINGLE_BLOCK   17

Initiate single block read.

Definition at line 155 of file mmcard.h.

Referenced by SpiMmcBlockRead(), and SpiMmcMount().

#define MMCMD_READ_MULTIPLE_BLOCK   18

Initiate continuous block read.

Definition at line 158 of file mmcard.h.

#define MMCMD_WRITE_BLOCK   24

Initiate single block write.

Definition at line 161 of file mmcard.h.

Referenced by SpiMmcBlockWrite().

#define MMCMD_WRITE_MULTIPLE_BLOCK   25

Initiate continuous block write.

Definition at line 164 of file mmcard.h.

#define MMCMD_PROGRAM_CSD   27

Initiate programming of programmable CSD bits.

Definition at line 167 of file mmcard.h.

#define MMCMD_SET_WRITE_PROTECT   28

Enable card's optional write protection.

Definition at line 170 of file mmcard.h.

#define MMCMD_CLR_WRITE_PROTECT   29

Disable card's write protection.

Definition at line 173 of file mmcard.h.

#define MMCMD_SEND_WRITE_PROTECT   30

Query card's write protect status.

Definition at line 176 of file mmcard.h.

#define MMCMD_TAG_ERASE_GROUP_START   35

Set address of the first erase group.

Definition at line 179 of file mmcard.h.

#define MMCMD_TAG_ERASE_GROUP_END   36

Set address of the last erase group.

Definition at line 182 of file mmcard.h.

#define MMCMD_ERASE   38

Erase previously selected sectors.

Definition at line 185 of file mmcard.h.

#define MMCMD_SEND_APP_OP_COND   41

Activate SD card's initialization process.

Definition at line 188 of file mmcard.h.

#define MMCMD_LOCK_UNLOCK   42

Set/clear password or lock/unlock the card.

Definition at line 191 of file mmcard.h.

#define MMCMD_SEND_APP_CMD   55

Application command follows.

Definition at line 194 of file mmcard.h.

#define MMCMD_READ_OCR   58

Query card's operating condition register.

Definition at line 197 of file mmcard.h.

Referenced by MmCardIOCtl(), and SpiMmcIOCtl().

#define MMCMD_CRC_ON_OFF   59

Enable or disable CRC mode.

In SPI mode CRC is disabled by default.

Definition at line 203 of file mmcard.h.

#define MMR1_IDLE_STATE   0x00

Card is idle.

Definition at line 206 of file mmcard.h.

Referenced by MmCardIOCtl(), and SpiMmcIOCtl().

#define MMR1_NOT_IDLE   0x01

Card is busy.

Definition at line 208 of file mmcard.h.

#define MMR1_ERASE_RESET   0x02

Erase sequence was cleared before execution.

Definition at line 210 of file mmcard.h.

#define MMR1_ILLEGAL_COMMAND   0x04

Illegal command code detected.

Definition at line 212 of file mmcard.h.

#define MMR1_COM_CRC_ERROR   0x08

Bad command CRC detected.

Definition at line 214 of file mmcard.h.

#define MMR1_ERASE_SEQ_ERROR   0x10

Bad erase sequence.

Definition at line 216 of file mmcard.h.

#define MMR1_ADDRESS_ERROR   0x20

Misaligned address did not match block length.

Definition at line 218 of file mmcard.h.

#define MMR1_PARAMETER_ERROR   0x40

Command parameter is out of range.

Definition at line 220 of file mmcard.h.

#define MMR2_CARD_LOCKED   0x01

Card is locked.

Definition at line 224 of file mmcard.h.

#define MMR2_WP_ERASE_SKIP   0x02

Erasing write protected sector or password error.

Definition at line 226 of file mmcard.h.

#define MMR2_ERROR   0x04

General or unknown error occured.

Definition at line 228 of file mmcard.h.

#define MMR2_CC_ERROR   0x08

Internal card controller error.

Definition at line 230 of file mmcard.h.

#define MMR2_ECC_FAILED   0x10

Bad internal ECC.

Definition at line 232 of file mmcard.h.

#define MMR2_WP_VIOLATION   0x20

Failed to write to protected block.

Definition at line 234 of file mmcard.h.

#define MMR2_ERASE_PARAMETER   0x40

Invalid erase parameter.

Definition at line 236 of file mmcard.h.

#define MMR2_OUT_OF_RANGE   0x80

Command parameter is out of range.

Definition at line 238 of file mmcard.h.

#define MMCSR_OUT_OF_RANGE   0x80000000

Definition at line 241 of file mmcard.h.

#define MMCSR_ADDRESS_ERROR   0x40000000

Definition at line 242 of file mmcard.h.

#define MMCSR_BLOCK_LEN_ERROR   0x20000000

Definition at line 243 of file mmcard.h.

#define MMCSR_ERASE_SEQ_ERROR   0x10000000

Definition at line 244 of file mmcard.h.

#define MMCSR_ERASE_PARAM   0x08000000

Definition at line 245 of file mmcard.h.

#define MMCSR_WP_VIOLATION   0x04000000

Definition at line 246 of file mmcard.h.

#define MMCSR_COM_CRC_ERROR   0x00800000

Definition at line 247 of file mmcard.h.

#define MMCSR_ILLEGAL_COMMAND   0x00400000

Definition at line 248 of file mmcard.h.

#define MMCSR_ERROR   0x00080000

Definition at line 249 of file mmcard.h.

#define MMCSR_CIDCSD_OVERWRITE   0x00010000

Definition at line 250 of file mmcard.h.

#define MMCSR_WP_ERASE_SKIP   0x00008000

Definition at line 251 of file mmcard.h.

#define MMCSR_CARD_ECC_DISABLED   0x00004000

Definition at line 252 of file mmcard.h.

#define MMCSR_ERASE_RESET   0x00002000

Definition at line 253 of file mmcard.h.

#define MMCSR_STATE_MASK   0x00001E00

Definition at line 254 of file mmcard.h.

#define MMCSR_READY_FOR_DATA   0x00000100

Definition at line 255 of file mmcard.h.

#define MMCSR_IS_IDLE   0x00000000

Definition at line 257 of file mmcard.h.

#define MMCSR_IS_READY   0x00000200

Definition at line 258 of file mmcard.h.

#define MMCSR_IS_IDENT   0x00000400

Definition at line 259 of file mmcard.h.

#define MMCSR_IS_STBY   0x00000600

Definition at line 260 of file mmcard.h.

#define MMCSR_IS_TRAN   0x00000800

Definition at line 261 of file mmcard.h.

#define MMCSR_IS_DATA   0x00000A00

Definition at line 262 of file mmcard.h.

#define MMCSR_IS_RCV   0x00000C00

Definition at line 263 of file mmcard.h.

#define MMCSR_IS_PRG   0x00000E00

Definition at line 264 of file mmcard.h.

#define MMCSR_IS_DIS   0x00001000

Definition at line 265 of file mmcard.h.

#define MMDR_ACCEPTED

Definition at line 267 of file mmcard.h.

#define MMDR_CRC_ERROR

Definition at line 268 of file mmcard.h.

#define MMDR_WRITE_ERROR

Definition at line 269 of file mmcard.h.

#define MMCERR_TIMEOUT   0x00000001

Definition at line 271 of file mmcard.h.

#define MMCOP_NBUSY   0x80000000

Definition at line 273 of file mmcard.h.

#define MMCARD_CIDR_SIZE   16

Number of bytes in the CID register.

Definition at line 276 of file mmcard.h.

#define MMCARD_CSDR_SIZE   16

Number of bytes in the CSD register.

Definition at line 279 of file mmcard.h.

#define MMCARD_OCR_SIZE   32

Number of bytes in the operating condition register.

Definition at line 282 of file mmcard.h.

#define MMCARD_165_195V   0x00000080

Definition at line 288 of file mmcard.h.

#define MMCARD_20_21V   0x00000100

Definition at line 289 of file mmcard.h.

#define MMCARD_21_22V   0x00000200

Definition at line 290 of file mmcard.h.

#define MMCARD_22_23V   0x00000400

Definition at line 291 of file mmcard.h.

#define MMCARD_23_24V   0x00000800

Definition at line 292 of file mmcard.h.

#define MMCARD_24_25V   0x00001000

Definition at line 293 of file mmcard.h.

#define MMCARD_25_26V   0x00002000

Definition at line 294 of file mmcard.h.

#define MMCARD_26_27V   0x00004000

Definition at line 295 of file mmcard.h.

#define MMCARD_27_28V   0x00008000

Definition at line 296 of file mmcard.h.

#define MMCARD_28_29V   0x00010000

Definition at line 297 of file mmcard.h.

#define MMCARD_29_30V   0x00020000

Definition at line 298 of file mmcard.h.

#define MMCARD_30_31V   0x00040000

Definition at line 299 of file mmcard.h.

#define MMCARD_31_32V   0x00080000

Definition at line 300 of file mmcard.h.

#define MMCARD_32_33V   0x00100000

Definition at line 301 of file mmcard.h.

#define MMCARD_33_34V   0x00200000

Definition at line 302 of file mmcard.h.

#define MMCARD_34_35V   0x00400000

Definition at line 303 of file mmcard.h.

#define MMCARD_35_36V   0x00800000

Definition at line 304 of file mmcard.h.

#define MMCARD_GETSTATUS   0x2001

Retrieve card status.

Definition at line 313 of file mmcard.h.

Referenced by MmCardIOCtl(), and SpiMmcIOCtl().

#define MMCARD_GETOCR   0x2002

Retrieve operation condition register.

Definition at line 315 of file mmcard.h.

Referenced by MmCardIOCtl(), and SpiMmcIOCtl().

#define MMCARD_GETCID   0x2003

Retrieve card identification.

Definition at line 317 of file mmcard.h.

Referenced by MmCardIOCtl(), and SpiMmcIOCtl().

#define MMCARD_GETCSD   0x2004

Retrieve card specific data.

Definition at line 319 of file mmcard.h.

Referenced by MmCardIOCtl(), and SpiMmcIOCtl().

#define MMCARD_GETEXTCSD   0x2005

Retrieve extended card specific data.

Definition at line 321 of file mmcard.h.

Referenced by SpiMmcIOCtl().

#define MMC_BLOCK_SIZE   512

Block size.

Block size in bytes. Do not change unless you are sure that both, the file system and the hardware support it.

Definition at line 132 of file mmcard.c.

#define MMC_MAX_INIT_POLLS   512

Card init timeout.

Max. number of loops waiting for card's idle mode after initialization. An additional delay of 1 ms is added to each loop after one quarter of this value elapsed.

Definition at line 143 of file mmcard.c.

#define MMC_MAX_RESET_POLLS   255

Card reset timeout.

Max. number of loops waiting for card's idle mode after resetting it.

Definition at line 152 of file mmcard.c.

#define MMC_MAX_WRITE_POLLS   1024

Card write timeout.

Max. number of loops waiting for card's idle mode after resetting it. An additional delay of 1 ms is added to each loop after 31/32 of this value elapsed.

Definition at line 163 of file mmcard.c.

#define MMC_MAX_WRITE_RETRIES   32

Card write retries.

Max. number of retries while writing.

Definition at line 172 of file mmcard.c.

#define MMC_MAX_READ_RETRIES   8

Card read retries.

Max. number of retries while reading.

Definition at line 181 of file mmcard.c.

Referenced by MmCardBlockRead(), and MmCardBlockWrite().

#define MMC_MAX_REG_POLLS   512

Register read timeout.

Max. number of loops while reading a card's register.

Definition at line 190 of file mmcard.c.

#define MMC_MAX_CMDACK_POLLS   1024

Command acknowledge timeout.

Max. number of loops waiting for card's acknowledge of a command. An additional delay of 1 ms is added to each loop after three quarter of this value elapsed.

Definition at line 201 of file mmcard.c.

#define MMC_MAX_R1_POLLS   1024

R1 response timeout.

Max. number of loops waiting for card's R1 response.

Definition at line 210 of file mmcard.c.

#define MMC_BLOCK_SIZE   512

Block size.

Block size in bytes. Do not change unless you are sure that both, the file system and the hardware support it.

Definition at line 85 of file spi_mmc.c.

Referenced by SpiMmcBlockRead(), SpiMmcBlockWrite(), SpiMmcInit(), SpiMmcIOCtl(), and SpiMmcMount().

#define MMC_MAX_INIT_POLLS   512

Card init timeout.

Max. number of loops waiting for card's idle mode after initialization. An additional delay of 1 ms is added to each loop after one quarter of this value elapsed.

Definition at line 96 of file spi_mmc.c.

#define MMC_MAX_RESET_RETRIES   2

Card reset timeout.

Max. number of loops waiting for card's idle mode after resetting it.

Definition at line 105 of file spi_mmc.c.

#define MMC_MAX_WRITE_RETRIES   2

Card write retries.

Max. number of retries while writing.

Definition at line 114 of file spi_mmc.c.

#define MMC_MAX_READ_RETRIES   MMC_MAX_WRITE_RETRIES

Card read retries.

Max. number of retries while reading.

Definition at line 123 of file spi_mmc.c.

#define MMC_MAX_CMDACK_POLLS   1024

Command acknowledge timeout.

Max. number of loops waiting for card's acknowledge of a command. An additional delay of 1 ms is added to each loop after three quarter of this value elapsed.

Definition at line 134 of file spi_mmc.c.

#define MMC_MAX_READY_POLLS   800

Card busy timeout.

Max. number of loops waiting for card's ready state. An additional delay of 1 ms is added to each loop after one quarter of this value elapsed.

Definition at line 145 of file spi_mmc.c.


Typedef Documentation

typedef struct _MEMCARDSUPP MEMCARDSUPP

Memory card support structure.

typedef struct _MMCIFC MMCIFC

Low level access information structure.

typedef struct _MMC_CID MMC_CID

Multimedia card identification register.

typedef struct _MMC_CSD MMC_CSD

Multimedia card identification register.

typedef struct _MMCFCB MMCFCB

Local multimedia card mount information.

typedef struct _MMCFCB MMCFCB

Local multimedia card status information.


Function Documentation

int MmCardBlockRead ( NUTFILE nfp,
void *  buffer,
int  num 
)

Read data blocks from a mounted partition.

Applications should not call this function directly, but use the stdio interface.

Parameters:
nfpPointer to a NUTFILE structure, obtained by a previous call to MmCardMount().
bufferPointer to the data buffer to fill.
numMaximum number of blocks to read. However, reading multiple blocks is not yet supported by this driver.
Returns:
The number of blocks actually read. A return value of -1 indicates an error.

Definition at line 596 of file mmcard.c.

References _MMCFCB::fcb_blkbuf, _MMCFCB::fcb_blknum, _MMCFCB::fcb_part, MMC_MAX_READ_RETRIES, _MMCIFC::mmcifc_cd, _NUTFILE::nf_dev, _NUTFILE::nf_fcb, and _DOSPART::part_sect_offs.

int MmCardBlockWrite ( NUTFILE nfp,
CONST void *  buffer,
int  num 
)

Write data blocks to a mounted partition.

Applications should not call this function directly, but use the stdio interface.

Parameters:
nfpPointer to a NUTFILE structure, obtained by a previous call to MmCardMount().
bufferPointer to the data to be written.
numMaximum number of blocks to write. However, writing multiple blocks is not yet supported by this driver.
Returns:
The number of blocks written. A return value of -1 indicates an error.

Definition at line 649 of file mmcard.c.

References _MMCFCB::fcb_blkbuf, _MMCFCB::fcb_blknum, _MMCFCB::fcb_part, MMC_MAX_READ_RETRIES, _MMCIFC::mmcifc_cd, _NUTFILE::nf_dev, _NUTFILE::nf_fcb, and _DOSPART::part_sect_offs.

int MmCardBlockWrite_P ( NUTFILE nfp,
PGM_P  buffer,
int  num 
)

Write data blocks from program space to a mounted partition.

This function is not yet implemented and will always return -1.

Similar to MmCardBlockWrite() except that the data is located in program memory.

Applications should not call this function directly, but use the stdio interface.

Parameters:
nfpFile pointer to a previously opened device.
bufferPointer to the data bytes in program space to be written.
numMaximum number of blocks to write. However, writing multiple blocks is not yet supported by this driver.
Returns:
The number of blocks written. A return value of -1 indicates an error.

Definition at line 707 of file mmcard.c.

NUTFILE* MmCardMount ( NUTDEVICE dev,
CONST char *  name,
int  mode,
int  acc 
)

Mount a partition.

Nut/OS doesn't provide specific routines for mounting. Instead routines for opening files are used.

Applications should not directly call this function, but use the high level stdio routines for opening a file.

Parameters:
devPointer to the MMC device.
namePartition number followed by a slash followed by a name of the file system device. Both items are optional. If no file system driver name is given, the first file system driver found in the list of registered devices will be used. If no partition number is specified or if partition zero is given, the first active primary partition will be used.
modeOpening mode. Currently ignored, but should be used for compatibility with future enhancements.
accFile attributes, ignored.
Returns:
Pointer to a newly created file pointer to the mounted partition or NUTFILE_EOF in case of any error.

Definition at line 738 of file mmcard.c.

References atoi(), calloc, _NUTDEVICE::dev_icb, _NUTDEVICE::dev_ioctl, _NUTDEVICE::dev_name, _NUTDEVICE::dev_next, _NUTDEVICE::dev_type, DOSPART_MAGICPOS, DOSPART_SECTORPOS, DOSPART_TYPEPOS, ENODEV, ENOMEM, errno, _MMCFCB::fcb_blkbuf, _MMCFCB::fcb_fsdev, _MMCFCB::fcb_part, free(), FS_VOL_MOUNT, IFTYP_FS, MmCardUnmount(), _MMCIFC::mmcifc_cd, _NUTFILE::nf_dev, _NUTFILE::nf_fcb, _NUTFILE::nf_next, nutDeviceList, NUTFILE_EOF, NutHeapAlloc, _DOSPART::part_sect_offs, _DOSPART::part_sects, _DOSPART::part_state, _DOSPART::part_type, printf, PTYPE_EMPTY, PTYPE_FAT12, and strcmp().

Here is the call graph for this function:

int MmCardUnmount ( NUTFILE nfp)

Unmount a previously mounted partition.

Applications should not directly call this function, but use the high level stdio routines for closing a previously opened file.

Returns:
0 on success, -1 otherwise.

Definition at line 874 of file mmcard.c.

References _NUTDEVICE::dev_icb, _NUTDEVICE::dev_ioctl, _MMCFCB::fcb_fsdev, free(), FS_VOL_UNMOUNT, _MMCIFC::mmcifc_cd, _NUTFILE::nf_dev, and _NUTFILE::nf_fcb.

Referenced by MmCardMount().

Here is the call graph for this function:

int MmCardIOCtl ( NUTDEVICE dev,
int  req,
void *  conf 
)

Perform MMC control functions.

This function is called by the ioctl() function of the C runtime library. Applications should not directly call this function.

Todo:
Card change detection should verify the serial card number.
Parameters:
devIdentifies the device that receives the device-control function.
reqRequested control function. May be set to one of the following constants:
confPoints to a buffer that contains any data required for the given control function or receives data from that function.
Returns:
0 on success, -1 otherwise.

Definition at line 968 of file mmcard.c.

References _NUTDEVICE::dev_icb, _MMCFCB::fcb_blkbuf, _MMCFCB::fcb_blknum, _MMCFCB::fcb_part, MMCARD_GETCID, MMCARD_GETCSD, MMCARD_GETOCR, MMCARD_GETSTATUS, _MMCIFC::mmcifc_cd, MMCMD_READ_OCR, MMCMD_SEND_CID, MMCMD_SEND_CSD, MMCMD_SEND_STATUS, MMR1_IDLE_STATE, _NUTFILE::nf_fcb, NUTBLKDEV_INFO, NUTBLKDEV_MEDIAAVAIL, NUTBLKDEV_MEDIACHANGE, NUTBLKDEV_SEEK, NutEventPost(), NutEventWait(), _BLKPAR_INFO::par_blkbp, _BLKPAR_SEEK::par_blknum, _BLKPAR_INFO::par_blksz, _BLKPAR_INFO::par_nblks, _BLKPAR_SEEK::par_nfp, _BLKPAR_INFO::par_nfp, and _DOSPART::part_sects.

Here is the call graph for this function:

int MmCardDevInit ( NUTDEVICE dev)

Initialize high level MMC driver.

Applications should not directly call this function. It is automatically executed during during device registration by NutRegisterDevice().

Parameters:
devIdentifies the device to initialize.
Returns:
Always zero.

Definition at line 1058 of file mmcard.c.

int SpiMmcBlockRead ( NUTFILE nfp,
void *  buffer,
int  num 
)

Read data blocks from a mounted partition.

Applications should not call this function directly, but use the stdio interface.

Parameters:
nfpPointer to a NUTFILE structure, obtained by a previous call to SpiMmcMount().
bufferPointer to the data buffer to fill.
numMaximum number of blocks to read. However, reading multiple blocks is not yet supported by this driver.
Returns:
The number of blocks actually read. A return value of -1 indicates an error.

Definition at line 500 of file spi_mmc.c.

References _NUTDEVICE::dev_dcb, _NUTDEVICE::dev_icb, _MMCFCB::fcb_address, _MMCFCB::fcb_blkbuf, _MEMCARDSUPP::mcs_act, _MEMCARDSUPP::mcs_cf, MMC_BLOCK_SIZE, MMCMD_READ_SINGLE_BLOCK, _NUTFILE::nf_dev, _NUTFILE::nf_fcb, NUTASSERT, NUTMC_IND_ERROR, NUTMC_IND_OFF, and NUTMC_IND_READ.

int SpiMmcBlockWrite ( NUTFILE nfp,
CONST void *  buffer,
int  num 
)

Write data blocks to a mounted partition.

Applications should not call this function directly, but use the stdio interface.

Parameters:
nfpPointer to a NUTFILE structure, obtained by a previous call to SpiMmcMount().
bufferPointer to the data to be written. However, writing multiple blocks is not yet supported by this driver.
numNumber of blocks to write.
Returns:
The number of blocks written. A return value of -1 indicates an error.

Definition at line 553 of file spi_mmc.c.

References _NUTDEVICE::dev_dcb, _NUTDEVICE::dev_icb, _MMCFCB::fcb_address, _MMCFCB::fcb_blkbuf, _MEMCARDSUPP::mcs_act, _MEMCARDSUPP::mcs_cf, MMC_BLOCK_SIZE, MMCMD_WRITE_BLOCK, _NUTFILE::nf_dev, _NUTFILE::nf_fcb, NUTASSERT, NUTMC_IND_ERROR, NUTMC_IND_OFF, and NUTMC_IND_WRITE.

int SpiMmcBlockWrite_P ( NUTFILE nfp,
PGM_P  buffer,
int  num 
)

Write data blocks from program space to a mounted partition.

This function is not yet implemented and will always return -1.

Similar to SpiMmcBlockWrite() except that the data is located in program memory.

Applications should not call this function directly, but use the stdio interface.

Parameters:
nfpFile pointer to a previously opened device.
bufferPointer to the data bytes in program space to be written.
numMaximum number of blocks to write. However, writing multiple blocks is not yet supported by this driver.
Returns:
The number of blocks written. A return value of -1 indicates an error.

Definition at line 608 of file spi_mmc.c.

int SpiMmcUnmount ( NUTFILE nfp)

Unmount a previously mounted partition.

Applications should not directly call this function, but use the high level stdio routines for closing a previously opened volume.

Parameters:
nfpPointer to a NUTFILE structure, obtained by a previous call to SpiMmcMount().
Returns:
0 on success, -1 otherwise.

Definition at line 793 of file spi_mmc.c.

References _NUTDEVICE::dev_ioctl, _MMCFCB::fcb_fsdev, free(), FS_VOL_UNMOUNT, _NUTFILE::nf_fcb, and NUTASSERT.

Referenced by SpiMmcMount().

Here is the call graph for this function:

NUTFILE* SpiMmcMount ( NUTDEVICE dev,
CONST char *  name,
int  mode,
int  acc 
)

Mount a partition.

Nut/OS doesn't provide specific routines for mounting. Instead routines for opening files are used.

Applications should not directly call this function, but use the high level stdio routines for opening a file.

Parameters:
devPointer to the MMC device.
namePartition number followed by a slash followed by a name of the file system device. Both items are optional. If no file system driver name is given, the first file system driver found in the list of registered devices will be used. If no partition number is specified or if partition zero is given, the first active primary partition will be used.
modeOpening mode. Currently ignored, but should be used for compatibility with future enhancements.
accFile attributes, ignored.
Returns:
Pointer to a newly created file pointer to the mounted partition or NUTFILE_EOF in case of any error.

Definition at line 641 of file spi_mmc.c.

References atoi(), calloc, _NUTDEVICE::dev_dcb, _NUTDEVICE::dev_icb, _NUTDEVICE::dev_ioctl, _NUTDEVICE::dev_name, _NUTDEVICE::dev_next, _NUTDEVICE::dev_type, DOSPART_MAGICPOS, DOSPART_SECTORPOS, DOSPART_TYPEPOS, ENODEV, ENOMEM, errno, _MMCFCB::fcb_blkbuf, _MMCFCB::fcb_fsdev, _MMCFCB::fcb_part, free(), FS_VOL_MOUNT, IFTYP_FS, _MEMCARDSUPP::mcs_cf, _MEMCARDSUPP::mcs_sf, MMC_BLOCK_SIZE, MMCMD_READ_SINGLE_BLOCK, _NUTFILE::nf_dev, _NUTFILE::nf_fcb, _NUTFILE::nf_next, nutDeviceList, NUTFILE_EOF, NutHeapAlloc, NUTMC_SF_CD, _DOSPART::part_sect_offs, _DOSPART::part_sects, _DOSPART::part_state, _DOSPART::part_type, printf, PTYPE_EMPTY, PTYPE_FAT12, SpiMmcUnmount(), and strcmp().

Here is the call graph for this function:

int SpiMmcIOCtl ( NUTDEVICE dev,
int  req,
void *  conf 
)

Perform MMC control functions.

This function is called by the ioctl() function of the C runtime library. Applications should not directly call this function.

Todo:
Card change detection should verify the serial card number.
Parameters:
devIdentifies the device that receives the device-control function.
reqRequested control function. May be set to one of the following constants:
confPoints to a buffer that contains any data required for the given control function or receives data from that function.
Returns:
0 on success, -1 otherwise.

Definition at line 835 of file spi_mmc.c.

References _NUTSPIBUS::bus_release, _NUTSPIBUS::bus_transfer, _NUTDEVICE::dev_dcb, _NUTDEVICE::dev_icb, _MMCFCB::fcb_address, _MMCFCB::fcb_blkbuf, _MMCFCB::fcb_part, MMC_BLOCK_SIZE, MMCARD_GETCID, MMCARD_GETCSD, MMCARD_GETEXTCSD, MMCARD_GETOCR, MMCARD_GETSTATUS, MMCMD_READ_OCR, MMCMD_SEND_CID, MMCMD_SEND_CSD, MMCMD_SEND_EXTCSD, MMCMD_SEND_STATUS, MMR1_IDLE_STATE, _NUTFILE::nf_fcb, _NUTSPINODE::node_bus, NUTBLKDEV_INFO, NUTBLKDEV_MEDIAAVAIL, NUTBLKDEV_MEDIACHANGE, NUTBLKDEV_SEEK, NUTMC_SF_CD, _BLKPAR_INFO::par_blkbp, _BLKPAR_SEEK::par_blknum, _BLKPAR_INFO::par_blksz, _BLKPAR_INFO::par_nblks, _BLKPAR_SEEK::par_nfp, _BLKPAR_INFO::par_nfp, _DOSPART::part_sect_offs, and _DOSPART::part_sects.

int SpiMmcInit ( NUTDEVICE dev)

Initialize MMC driver.

Applications should not directly call this function. It is automatically executed during during device registration by NutRegisterDevice().

Parameters:
devIdentifies the device to initialize.
Returns:
Always zero.

Definition at line 928 of file spi_mmc.c.

References memset(), and MMC_BLOCK_SIZE.

Here is the call graph for this function: