sd_raw.c File Reference

#include <string.h>
#include <avr/io.h>
#include "sd_raw.h"

Include dependency graph for sd_raw.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_SD_SEND_OP_COND   0x29
#define CMD_LOCK_UNLOCK   0x2a
#define CMD_APP   0x37
#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
#define SD_RAW_SPEC_1   0
#define SD_RAW_SPEC_2   1
#define SD_RAW_SPEC_SDHC   2

Functions

static void sd_raw_send_byte (uint8_t b)
static uint8_t sd_raw_rec_byte ()
static uint8_t sd_raw_send_command (uint8_t command, uint32_t arg)
uint8_t sd_raw_init ()
uint8_t sd_raw_available ()
uint8_t sd_raw_locked ()
uint8_t sd_raw_read (offset_t offset, uint8_t *buffer, uintptr_t length)
uint8_t sd_raw_read_interval (offset_t offset, uint8_t *buffer, uintptr_t interval, uintptr_t length, sd_raw_read_interval_handler_t callback, void *p)
uint8_t sd_raw_write (offset_t offset, const uint8_t *buffer, uintptr_t length)
uint8_t sd_raw_write_interval (offset_t offset, uint8_t *buffer, uintptr_t length, sd_raw_write_interval_handler_t callback, void *p)
uint8_t sd_raw_sync ()
uint8_t sd_raw_get_info (struct sd_raw_info *info)

Variables

static uint8_t raw_block [512]
static offset_t raw_block_address
static uint8_t raw_block_written
static uint8_t sd_raw_card_type


Detailed Description

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

Author:
Roland Riegel

Definition in file sd_raw.c.


Define Documentation

#define CMD_APP   0x37

Definition at line 94 of file sd_raw.c.

Referenced by sd_raw_init().

#define CMD_CLR_WRITE_PROT   0x1d

Definition at line 72 of file sd_raw.c.

#define CMD_CRC_ON_OFF   0x3b

Definition at line 98 of file sd_raw.c.

#define CMD_ERASE   0x26

Definition at line 88 of file sd_raw.c.

#define CMD_GO_IDLE_STATE   0x00

Definition at line 44 of file sd_raw.c.

Referenced by sd_raw_init(), and sd_raw_send_command().

#define CMD_LOCK_UNLOCK   0x2a

Definition at line 92 of file sd_raw.c.

#define CMD_PROGRAM_CSD   0x1b

Definition at line 68 of file sd_raw.c.

#define CMD_READ_MULTIPLE_BLOCK   0x12

Definition at line 62 of file sd_raw.c.

#define CMD_READ_OCR   0x3a

Definition at line 96 of file sd_raw.c.

Referenced by sd_raw_init().

#define CMD_READ_SINGLE_BLOCK   0x11

Definition at line 60 of file sd_raw.c.

Referenced by sd_raw_read(), and sd_raw_read_interval().

#define CMD_SD_SEND_OP_COND   0x29

Definition at line 90 of file sd_raw.c.

Referenced by sd_raw_init().

#define CMD_SEND_CID   0x0a

Definition at line 52 of file sd_raw.c.

Referenced by sd_raw_get_info().

#define CMD_SEND_CSD   0x09

Definition at line 50 of file sd_raw.c.

Referenced by sd_raw_get_info().

#define CMD_SEND_IF_COND   0x08

Definition at line 48 of file sd_raw.c.

Referenced by sd_raw_init(), and sd_raw_send_command().

#define CMD_SEND_OP_COND   0x01

Definition at line 46 of file sd_raw.c.

Referenced by sd_raw_init().

#define CMD_SEND_STATUS   0x0d

Definition at line 56 of file sd_raw.c.

#define CMD_SEND_WRITE_PROT   0x1e

Definition at line 74 of file sd_raw.c.

#define CMD_SET_BLOCKLEN   0x10

Definition at line 58 of file sd_raw.c.

Referenced by sd_raw_init().

#define CMD_SET_WRITE_PROT   0x1c

Definition at line 70 of file sd_raw.c.

#define CMD_STOP_TRANSMISSION   0x0c

Definition at line 54 of file sd_raw.c.

#define CMD_TAG_ERASE_GROUP_END   0x24

Definition at line 84 of file sd_raw.c.

#define CMD_TAG_ERASE_GROUP_START   0x23

Definition at line 82 of file sd_raw.c.

#define CMD_TAG_SECTOR_END   0x21

Definition at line 78 of file sd_raw.c.

#define CMD_TAG_SECTOR_START   0x20

Definition at line 76 of file sd_raw.c.

#define CMD_UNTAG_ERASE_GROUP   0x25

Definition at line 86 of file sd_raw.c.

#define CMD_UNTAG_SECTOR   0x22

Definition at line 80 of file sd_raw.c.

#define CMD_WRITE_MULTIPLE_BLOCK   0x19

Definition at line 66 of file sd_raw.c.

#define CMD_WRITE_SINGLE_BLOCK   0x18

Definition at line 64 of file sd_raw.c.

Referenced by sd_raw_write().

#define DR_STATUS_ACCEPTED   0x05

Definition at line 138 of file sd_raw.c.

#define DR_STATUS_CRC_ERR   0x0a

Definition at line 139 of file sd_raw.c.

#define DR_STATUS_MASK   0x0e

Definition at line 137 of file sd_raw.c.

#define DR_STATUS_WRITE_ERR   0x0c

Definition at line 140 of file sd_raw.c.

#define R1_ADDR_ERR   5

Definition at line 107 of file sd_raw.c.

#define R1_COM_CRC_ERR   3

Definition at line 105 of file sd_raw.c.

#define R1_ERASE_RESET   1

Definition at line 103 of file sd_raw.c.

#define R1_ERASE_SEQ_ERR   4

Definition at line 106 of file sd_raw.c.

#define R1_IDLE_STATE   0

Definition at line 102 of file sd_raw.c.

Referenced by sd_raw_init().

#define R1_ILL_COMMAND   2

Definition at line 104 of file sd_raw.c.

Referenced by sd_raw_init().

#define R1_PARAM_ERR   6

Definition at line 108 of file sd_raw.c.

#define R2_ADDR_ERR   (R1_ADDR_ERR + 8)

Definition at line 125 of file sd_raw.c.

#define R2_CARD_ECC_FAIL   4

Definition at line 115 of file sd_raw.c.

#define R2_CARD_ERR   3

Definition at line 114 of file sd_raw.c.

#define R2_CARD_LOCKED   0

Definition at line 111 of file sd_raw.c.

#define R2_COM_CRC_ERR   (R1_COM_CRC_ERR + 8)

Definition at line 123 of file sd_raw.c.

#define R2_CSD_OVERWRITE   7

Definition at line 119 of file sd_raw.c.

#define R2_ERASE_RESET   (R1_ERASE_RESET + 8)

Definition at line 121 of file sd_raw.c.

#define R2_ERASE_SEQ_ERR   (R1_ERASE_SEQ_ERR + 8)

Definition at line 124 of file sd_raw.c.

#define R2_ERR   2

Definition at line 113 of file sd_raw.c.

#define R2_IDLE_STATE   (R1_IDLE_STATE + 8)

Definition at line 120 of file sd_raw.c.

#define R2_ILL_COMMAND   (R1_ILL_COMMAND + 8)

Definition at line 122 of file sd_raw.c.

#define R2_INVAL_ERASE   6

Definition at line 117 of file sd_raw.c.

#define R2_OUT_OF_RANGE   7

Definition at line 118 of file sd_raw.c.

#define R2_PARAM_ERR   (R1_PARAM_ERR + 8)

Definition at line 126 of file sd_raw.c.

#define R2_WP_ERASE_SKIP   1

Definition at line 112 of file sd_raw.c.

#define R2_WP_VIOLATION   5

Definition at line 116 of file sd_raw.c.

#define R3_ADDR_ERR   (R1_ADDR_ERR + 32)

Definition at line 134 of file sd_raw.c.

#define R3_COM_CRC_ERR   (R1_COM_CRC_ERR + 32)

Definition at line 132 of file sd_raw.c.

#define R3_ERASE_RESET   (R1_ERASE_RESET + 32)

Definition at line 130 of file sd_raw.c.

#define R3_ERASE_SEQ_ERR   (R1_ERASE_SEQ_ERR + 32)

Definition at line 133 of file sd_raw.c.

#define R3_IDLE_STATE   (R1_IDLE_STATE + 32)

Definition at line 129 of file sd_raw.c.

#define R3_ILL_COMMAND   (R1_ILL_COMMAND + 32)

Definition at line 131 of file sd_raw.c.

#define R3_OCR_MASK   (0xffffffffUL)

Definition at line 128 of file sd_raw.c.

#define R3_PARAM_ERR   (R1_PARAM_ERR + 32)

Definition at line 135 of file sd_raw.c.

#define SD_RAW_SPEC_1   0

Definition at line 143 of file sd_raw.c.

Referenced by sd_raw_init().

#define SD_RAW_SPEC_2   1

Definition at line 144 of file sd_raw.c.

Referenced by sd_raw_get_info(), and sd_raw_init().

#define SD_RAW_SPEC_SDHC   2

Definition at line 145 of file sd_raw.c.

Referenced by sd_raw_init(), sd_raw_read(), sd_raw_read_interval(), and sd_raw_write().


Variable Documentation

uint8_t raw_block[512] [static]

Definition at line 149 of file sd_raw.c.

Referenced by sd_raw_init(), sd_raw_read(), sd_raw_sync(), and sd_raw_write().

Definition at line 151 of file sd_raw.c.

Referenced by sd_raw_init(), sd_raw_read(), sd_raw_sync(), and sd_raw_write().

uint8_t raw_block_written [static]

Definition at line 154 of file sd_raw.c.

Referenced by sd_raw_init(), sd_raw_sync(), and sd_raw_write().

uint8_t sd_raw_card_type [static]


Generated on Tue Jul 20 09:30:57 2010 for WaspmoteAPI by  doxygen 1.5.6