sd_mmc.c File Reference

#include <string.h>
#include <avr/io.h>
#include "sd_mmc.h"
#include "uart.h"
#include "spi.h"

Include dependency graph for sd_mmc.c:

Go to the source code of this file.

Defines

#define CMD_GO_IDLE_STATE   0x00
#define CMD_SEND_OP_COND   0x01
#define CMD_SEND_IF_COND   0x08
#define CMD_SEND_CSD   0x09
#define CMD_SEND_CID   0x0a
#define CMD_STOP_TRANSMISSION   0x0c
#define CMD_SEND_STATUS   0x0d
#define CMD_SET_BLOCKLEN   0x10
#define CMD_READ_SINGLE_BLOCK   0x11
#define CMD_READ_MULTIPLE_BLOCK   0x12
#define CMD_WRITE_SINGLE_BLOCK   0x18
#define CMD_WRITE_MULTIPLE_BLOCK   0x19
#define CMD_PROGRAM_CSD   0x1b
#define CMD_SET_WRITE_PROT   0x1c
#define CMD_CLR_WRITE_PROT   0x1d
#define CMD_SEND_WRITE_PROT   0x1e
#define CMD_TAG_SECTOR_START   0x20
#define CMD_TAG_SECTOR_END   0x21
#define CMD_UNTAG_SECTOR   0x22
#define CMD_TAG_ERASE_GROUP_START   0x23
#define CMD_TAG_ERASE_GROUP_END   0x24
#define CMD_UNTAG_ERASE_GROUP   0x25
#define CMD_ERASE   0x26
#define CMD_LOCK_UNLOCK   0x2a
#define CMD_READ_OCR   0x3a
#define CMD_CRC_ON_OFF   0x3b
#define R1_IDLE_STATE   0
#define R1_ERASE_RESET   1
#define R1_ILL_COMMAND   2
#define R1_COM_CRC_ERR   3
#define R1_ERASE_SEQ_ERR   4
#define R1_ADDR_ERR   5
#define R1_PARAM_ERR   6
#define R2_CARD_LOCKED   0
#define R2_WP_ERASE_SKIP   1
#define R2_ERR   2
#define R2_CARD_ERR   3
#define R2_CARD_ECC_FAIL   4
#define R2_WP_VIOLATION   5
#define R2_INVAL_ERASE   6
#define R2_OUT_OF_RANGE   7
#define R2_CSD_OVERWRITE   7
#define R2_IDLE_STATE   (R1_IDLE_STATE + 8)
#define R2_ERASE_RESET   (R1_ERASE_RESET + 8)
#define R2_ILL_COMMAND   (R1_ILL_COMMAND + 8)
#define R2_COM_CRC_ERR   (R1_COM_CRC_ERR + 8)
#define R2_ERASE_SEQ_ERR   (R1_ERASE_SEQ_ERR + 8)
#define R2_ADDR_ERR   (R1_ADDR_ERR + 8)
#define R2_PARAM_ERR   (R1_PARAM_ERR + 8)
#define R3_OCR_MASK   (0xffffffffUL)
#define R3_IDLE_STATE   (R1_IDLE_STATE + 32)
#define R3_ERASE_RESET   (R1_ERASE_RESET + 32)
#define R3_ILL_COMMAND   (R1_ILL_COMMAND + 32)
#define R3_COM_CRC_ERR   (R1_COM_CRC_ERR + 32)
#define R3_ERASE_SEQ_ERR   (R1_ERASE_SEQ_ERR + 32)
#define R3_ADDR_ERR   (R1_ADDR_ERR + 32)
#define R3_PARAM_ERR   (R1_PARAM_ERR + 32)
#define DR_STATUS_MASK   0x0e
#define DR_STATUS_ACCEPTED   0x05
#define DR_STATUS_CRC_ERR   0x0a
#define DR_STATUS_WRITE_ERR   0x0c

Functions

static uint8_t sd_send_command_r1 (uint8_t command, uint32_t arg)
static uint16_t sd_send_command_r2 (uint8_t command, uint32_t arg)
uint8_t sd_init ()
uint8_t sd_available ()
uint8_t sd_locked ()
uint8_t sd_read (uint32_t offset, uint8_t *buffer, uint16_t length)
uint8_t sd_read_interval (uint32_t offset, uint8_t *buffer, uint16_t interval, uint16_t length, sd_raw_read_interval_handler_t callback, void *p)
uint8_t sd_write (uint32_t offset, const uint8_t *buffer, uint16_t length)
uint8_t sd_write_interval (uint32_t offset, uint8_t *buffer, uint16_t length, sd_raw_write_interval_handler_t callback, void *p)
uint8_t sd_sync ()
uint8_t sd_get_info (struct sd_raw_info *info)

Variables

static uint8_t raw_block [512]
static uint32_t raw_block_address
static uint8_t raw_block_written


Detailed Description

MMC/SD access implementation (license: GPLv2 or LGPLv2.1)

Author:
Roland Riegel; adapted to SPI layer Dennis Dingeldein

Definition in file sd_mmc.c.


Define Documentation

#define CMD_CLR_WRITE_PROT   0x1d

Definition at line 81 of file sd_mmc.c.

#define CMD_CRC_ON_OFF   0x3b

Definition at line 103 of file sd_mmc.c.

#define CMD_ERASE   0x26

Definition at line 97 of file sd_mmc.c.

#define CMD_GO_IDLE_STATE   0x00

Definition at line 53 of file sd_mmc.c.

Referenced by sd_init(), sd_send_command_r1(), and sd_send_command_r2().

#define CMD_LOCK_UNLOCK   0x2a

Definition at line 99 of file sd_mmc.c.

#define CMD_PROGRAM_CSD   0x1b

Definition at line 77 of file sd_mmc.c.

#define CMD_READ_MULTIPLE_BLOCK   0x12

Definition at line 71 of file sd_mmc.c.

#define CMD_READ_OCR   0x3a

Definition at line 101 of file sd_mmc.c.

#define CMD_READ_SINGLE_BLOCK   0x11

Definition at line 69 of file sd_mmc.c.

Referenced by sd_read(), and sd_read_interval().

#define CMD_SEND_CID   0x0a

Definition at line 61 of file sd_mmc.c.

Referenced by sd_get_info().

#define CMD_SEND_CSD   0x09

Definition at line 59 of file sd_mmc.c.

Referenced by sd_get_info().

#define CMD_SEND_IF_COND   0x08

Definition at line 57 of file sd_mmc.c.

#define CMD_SEND_OP_COND   0x01

Definition at line 55 of file sd_mmc.c.

Referenced by sd_init().

#define CMD_SEND_STATUS   0x0d

Definition at line 65 of file sd_mmc.c.

#define CMD_SEND_WRITE_PROT   0x1e

Definition at line 83 of file sd_mmc.c.

#define CMD_SET_BLOCKLEN   0x10

Definition at line 67 of file sd_mmc.c.

Referenced by sd_init().

#define CMD_SET_WRITE_PROT   0x1c

Definition at line 79 of file sd_mmc.c.

#define CMD_STOP_TRANSMISSION   0x0c

Definition at line 63 of file sd_mmc.c.

#define CMD_TAG_ERASE_GROUP_END   0x24

Definition at line 93 of file sd_mmc.c.

#define CMD_TAG_ERASE_GROUP_START   0x23

Definition at line 91 of file sd_mmc.c.

#define CMD_TAG_SECTOR_END   0x21

Definition at line 87 of file sd_mmc.c.

#define CMD_TAG_SECTOR_START   0x20

Definition at line 85 of file sd_mmc.c.

#define CMD_UNTAG_ERASE_GROUP   0x25

Definition at line 95 of file sd_mmc.c.

#define CMD_UNTAG_SECTOR   0x22

Definition at line 89 of file sd_mmc.c.

#define CMD_WRITE_MULTIPLE_BLOCK   0x19

Definition at line 75 of file sd_mmc.c.

#define CMD_WRITE_SINGLE_BLOCK   0x18

Definition at line 73 of file sd_mmc.c.

Referenced by sd_write().

#define DR_STATUS_ACCEPTED   0x05

Definition at line 143 of file sd_mmc.c.

#define DR_STATUS_CRC_ERR   0x0a

Definition at line 144 of file sd_mmc.c.

#define DR_STATUS_MASK   0x0e

Definition at line 142 of file sd_mmc.c.

#define DR_STATUS_WRITE_ERR   0x0c

Definition at line 145 of file sd_mmc.c.

#define R1_ADDR_ERR   5

Definition at line 112 of file sd_mmc.c.

#define R1_COM_CRC_ERR   3

Definition at line 110 of file sd_mmc.c.

#define R1_ERASE_RESET   1

Definition at line 108 of file sd_mmc.c.

#define R1_ERASE_SEQ_ERR   4

Definition at line 111 of file sd_mmc.c.

#define R1_IDLE_STATE   0

Definition at line 107 of file sd_mmc.c.

Referenced by sd_init().

#define R1_ILL_COMMAND   2

Definition at line 109 of file sd_mmc.c.

#define R1_PARAM_ERR   6

Definition at line 113 of file sd_mmc.c.

#define R2_ADDR_ERR   (R1_ADDR_ERR + 8)

Definition at line 130 of file sd_mmc.c.

#define R2_CARD_ECC_FAIL   4

Definition at line 120 of file sd_mmc.c.

#define R2_CARD_ERR   3

Definition at line 119 of file sd_mmc.c.

#define R2_CARD_LOCKED   0

Definition at line 116 of file sd_mmc.c.

#define R2_COM_CRC_ERR   (R1_COM_CRC_ERR + 8)

Definition at line 128 of file sd_mmc.c.

#define R2_CSD_OVERWRITE   7

Definition at line 124 of file sd_mmc.c.

#define R2_ERASE_RESET   (R1_ERASE_RESET + 8)

Definition at line 126 of file sd_mmc.c.

#define R2_ERASE_SEQ_ERR   (R1_ERASE_SEQ_ERR + 8)

Definition at line 129 of file sd_mmc.c.

#define R2_ERR   2

Definition at line 118 of file sd_mmc.c.

#define R2_IDLE_STATE   (R1_IDLE_STATE + 8)

Definition at line 125 of file sd_mmc.c.

#define R2_ILL_COMMAND   (R1_ILL_COMMAND + 8)

Definition at line 127 of file sd_mmc.c.

#define R2_INVAL_ERASE   6

Definition at line 122 of file sd_mmc.c.

#define R2_OUT_OF_RANGE   7

Definition at line 123 of file sd_mmc.c.

#define R2_PARAM_ERR   (R1_PARAM_ERR + 8)

Definition at line 131 of file sd_mmc.c.

#define R2_WP_ERASE_SKIP   1

Definition at line 117 of file sd_mmc.c.

#define R2_WP_VIOLATION   5

Definition at line 121 of file sd_mmc.c.

#define R3_ADDR_ERR   (R1_ADDR_ERR + 32)

Definition at line 139 of file sd_mmc.c.

#define R3_COM_CRC_ERR   (R1_COM_CRC_ERR + 32)

Definition at line 137 of file sd_mmc.c.

#define R3_ERASE_RESET   (R1_ERASE_RESET + 32)

Definition at line 135 of file sd_mmc.c.

#define R3_ERASE_SEQ_ERR   (R1_ERASE_SEQ_ERR + 32)

Definition at line 138 of file sd_mmc.c.

#define R3_IDLE_STATE   (R1_IDLE_STATE + 32)

Definition at line 134 of file sd_mmc.c.

#define R3_ILL_COMMAND   (R1_ILL_COMMAND + 32)

Definition at line 136 of file sd_mmc.c.

#define R3_OCR_MASK   (0xffffffffUL)

Definition at line 133 of file sd_mmc.c.

#define R3_PARAM_ERR   (R1_PARAM_ERR + 32)

Definition at line 140 of file sd_mmc.c.


Variable Documentation

uint8_t raw_block[512] [static]

Definition at line 150 of file sd_mmc.c.

Referenced by sd_init(), sd_read(), sd_sync(), and sd_write().

uint32_t raw_block_address [static]

Definition at line 152 of file sd_mmc.c.

Referenced by sd_init(), sd_read(), sd_sync(), and sd_write().

uint8_t raw_block_written [static]

Definition at line 155 of file sd_mmc.c.

Referenced by sd_init(), sd_sync(), and sd_write().


Generated on Wed Sep 17 19:31:52 2008 for mptry by  doxygen 1.5.5