Multimedia Card Driver
[Device Driver API.Block Devices]

Collaboration diagram for Multimedia Card Driver:


Detailed Description

Block device driver for MM/SD Cards.


Data Structures

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...

Control Codes

#define MMCARD_GETSTATUS
 Retrieve card status.
#define MMCARD_GETOCR
 Retrieve operation condition register.
#define MMCARD_GETCID
 Retrieve card identification.
#define MMCARD_GETCSD
 Retrieve card specific data.

Defines

#define MMCMD_HOST
#define MMCMD_RESET_CRC
#define MMCMD_GO_IDLE_STATE
 Reset card to idle state.
#define MMCMD_SEND_OP_COND
 Activate card's initialization process.
#define MMCMD_SEND_CSD
 Query card's CSD.
#define MMCMD_SEND_CID
 Query card's CID.
#define MMCMD_STOP_TRANSMISSION
 Stop multiple block transmission.
#define MMCMD_SEND_STATUS
 Query card's status register.
#define MMCMD_SET_BLOCKLEN
 Select block length for following read/write commands.
#define MMCMD_READ_SINGLE_BLOCK
 Initiate single block read.
#define MMCMD_READ_MULTIPLE_BLOCK
 Initiate continuous block read.
#define MMCMD_WRITE_BLOCK
 Initiate single block write.
#define MMCMD_WRITE_MULTIPLE_BLOCK
 Initiate continuous block write.
#define MMCMD_PROGRAM_CSD
 Initiate programming of programmable CSD bits.
#define MMCMD_SET_WRITE_PROTECT
 Enable card's optional write protection.
#define MMCMD_CLR_WRITE_PROTECT
 Disable card's write protection.
#define MMCMD_SEND_WRITE_PROTECT
 Query card's write protect status.
#define MMCMD_TAG_ERASE_GROUP_START
 Set address of the first erase group.
#define MMCMD_TAG_ERASE_GROUP_END
 Set address of the last erase group.
#define MMCMD_ERASE
 Erase previously selected sectors.
#define MMCMD_LOCK_UNLOCK
 Set/clear password or lock/unlock the card.
#define MMCMD_READ_OCR
 Query card's operating condition register.
#define MMCMD_CRC_ON_OFF
 Enable or disable CRC mode.
#define MMR1_IDLE_STATE
 Card is idle.
#define MMR1_NOT_IDLE
 Card is busy.
#define MMR1_ERASE_RESET
 Erase sequence was cleared before execution.
#define MMR1_ILLEGAL_COMMAND
 Illegal command code detected.
#define MMR1_COM_CRC_ERROR
 Bad command CRC detected.
#define MMR1_ERASE_SEQ_ERROR
 Bad erase sequence.
#define MMR1_ADDRESS_ERROR
 Misaligned address did not match block length.
#define MMR1_PARAMETER_ERROR
 Command parameter is out of range.
#define MMR2_CARD_LOCKED
 Card is locked.
#define MMR2_WP_ERASE_SKIP
 Erasing write protected sector or password error.
#define MMR2_ERROR
 General or unknown error occured.
#define MMR2_CC_ERROR
 Internal card controller error.
#define MMR2_ECC_FAILED
 Bad internal ECC.
#define MMR2_WP_VIOLATION
 Failed to write to protected block.
#define MMR2_ERASE_PARAMETER
 Invalid erase parameter.
#define MMR2_OUT_OF_RANGE
 Command parameter is out of range.
#define MMCSR_OUT_OF_RANGE
#define MMCSR_ADDRESS_ERROR
#define MMCSR_BLOCK_LEN_ERROR
#define MMCSR_ERASE_SEQ_ERROR
#define MMCSR_ERASE_PARAM
#define MMCSR_WP_VIOLATION
#define MMCSR_COM_CRC_ERROR
#define MMCSR_ILLEGAL_COMMAND
#define MMCSR_ERROR
#define MMCSR_CIDCSD_OVERWRITE
#define MMCSR_WP_ERASE_SKIP
#define MMCSR_CARD_ECC_DISABLED
#define MMCSR_ERASE_RESET
#define MMCSR_STATE_MASK
#define MMCSR_READY_FOR_DATA
#define MMCSR_IS_IDLE
#define MMCSR_IS_READY
#define MMCSR_IS_IDENT
#define MMCSR_IS_STBY
#define MMCSR_IS_TRAN
#define MMCSR_IS_DATA
#define MMCSR_IS_RCV
#define MMCSR_IS_PRG
#define MMCSR_IS_DIS
#define MMDR_ACCEPTED
#define MMDR_CRC_ERROR
#define MMDR_WRITE_ERROR
#define MMCARD_CIDR_SIZE
 Number of bytes in the CID register.
#define MMCARD_CSDR_SIZE
 Number of bytes in the CSD register.
#define MMCARD_OCR_SIZE
 Number of bytes in the operating condition register.
#define MMC_BLOCK_SIZE

Typedefs

typedef _MMCIFC MMCIFC
 Low level access information structure.
typedef _MMC_CID MMC_CID
 Multimedia card identification register.
typedef _MMC_CSD MMC_CSD
 Multimedia card identification register.
typedef _MMCFCB MMCFCB
 Local multimedia card mount information.

Functions

int MmCardDevInit (NUTDEVICE *dev)
 Initialize high level MMC driver.
int MmCardIOCtl (NUTDEVICE *dev, int req, void *conf)
 Perform MMC control 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.
NUTFILEMmCardMount (NUTDEVICE *dev, CONST char *name, int mode, int acc)
 Mount a partition.
int MmCardUnmount (NUTFILE *nfp)
 Unmount a previously mounted partition.

Variables

u_char(* _MMCIFC::mmcifc_io )(u_char)
int(* _MMCIFC::mmcifc_cs )(int)
int(* _MMCIFC::mmcifc_cd )(void)
int(* _MMCIFC::mmcifc_wp )(void)
u_short _MMC_CID::mmcid_oid
 OEM/Application identifier.
u_char _MMC_CID::mmcid_pnm [6]
 Product name.
u_char _MMC_CID::mmcid_rev
 Product revision.
u_long _MMC_CID::mmcid_psn
 Serial number.
u_char _MMC_CID::mmcid_mdt
 Manufacturing date code.
u_char _MMC_CID::mmcid_crc
 CRC7 checksum.
u_char _MMC_CSD::mmcsd_taac
 Data read access time.
u_char _MMC_CSD::mmcsd_nsac
 Data read access time 2.
u_char _MMC_CSD::mmcsd_speed
 Maximum data transfer rate.
u_char _MMC_CSD::mmcsd_ccc_bl [2]
 Card command classes and max. read block length.
u_char _MMC_CSD::mmcsd_rfld [8]
 Read-only fields.
u_char _MMC_CSD::mmcsd_pfld
 Programmable field.
u_char _MMC_CSD::mmcsd_crc
 


Define Documentation

#define MMCMD_CRC_ON_OFF
 

Enable or disable CRC mode.

In SPI mode CRC is disabled by default.

#define MMCMD_GO_IDLE_STATE
 

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.


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:
nfp Pointer to a NUTFILE structure, obtained by a previous call to MmCardMount().
buffer Pointer to the data buffer to fill.
num Maximum 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.

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:
nfp Pointer to a NUTFILE structure, obtained by a previous call to MmCardMount().
buffer Pointer to the data to be written.
num Maximum 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.

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:
dev Identifies the device to initialize.
Returns:
Always zero.

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:
dev Identifies the device that receives the device-control function.
req Requested control function. May be set to one of the following constants:
conf Points 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.

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:
dev Pointer to the MMC device.
name Partition 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.
mode Opening mode. Currently ignored, but should be used for compatibility with future enhancements.
acc File attributes, ignored.
Returns:
Pointer to a newly created file pointer to the mounted partition or NUTFILE_EOF in case of any error.

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.


Variable Documentation

int(* _MMCIFC::mmcifc_cd)(void) [inherited]
 

Query write protect.

int(* _MMCIFC::mmcifc_cs)(int) [inherited]
 

Query card detect.

u_char(* _MMCIFC::mmcifc_io)(u_char) [inherited]
 

Select or deselect the card.

u_char _MMC_CSD::mmcsd_rfld[8] [inherited]
 

Read-only fields.

  • [0] 0..1 Device size bits 10..11.
  • [0] 2..3 Reserved.
  • [0] 4 DSR implemented.
  • [0] 5 Read block misalignment.
  • [0] 6 Write block misalignment.
  • [0] 7 Partial blocks for read allowed.
  • [1] 0..7 Device size bits 2..9.
  • [2] 0..2 Max. read current at VDD max.
  • [2] 3..5 Max. read current at VDD min.
  • [2] 6..7 Device size bits 0..1.
  • [3] 0..1 Device size multiplier bits 1..2.
  • [3] 2..4 Max. write current at VDD max.
  • [3] 5..7 Max. write current at VDD min.
  • [4] 0..1 Erase group size multiplier bits 3..4.
  • [4] 2..6 Erase group size.
  • [4] 7 Device size multiplier bit 0.
  • [5] 0..4 Write protect group size.
  • [5] 5..7 Erase group size multiplier bits 0..2.
  • [6] 0..1 Max. write data block length bits 2..3.
  • [6] 2..4 Read to write speed factor.
  • [6] 5..6 Reserved.
  • [6] 7 Write protect group enable.
  • [7] 0 Content protection application.
  • [7] 1..4 Reserved.
  • [7] 5 Partial blocks for write allowed.
  • [7] 6..7 Max. write data block length bits 0..1.


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