📄 sdraw.h
字号:
#ifndef __SDRAW_H__
#define __SDRAW_H__
//#include "config.h"
//-------------------------------------------------------------------//
//
// SD/MMC Card Layout
//
//-------------------------------------------------------------------//
#define SD_RAW_FORMAT_HARDDISK 0
#define SD_RAW_FORMAT_SUPERFLOPPY 1
#define SD_RAW_FORMAT_UNIVERSAL 2
#define SD_RAW_FORMAT_UNKNOWN 3
//-------------------------------------------------------------------//
//
// Structure for Getting SD/MMC Card Manufacture Info
//
//-------------------------------------------------------------------//
struct sdraw_info
{
/**
* A manufacturer code globally assigned by the SD card organization.
*/
uint8_t manufacturer;
/**
* A string describing the card's OEM or content, globally assigned by the SD card organization.
*/
uint8_t oem[3];
/**
* A product name.
*/
uint8_t product[6];
/**
* The card's revision, coded in packed BCD.
*
* For example, the revision value \c 0x32 means "3.2".
*/
uint8_t revision;
/**
* A serial number assigned by the manufacturer.
*/
uint32_t serial;
/**
* The year of manufacturing.
*
* A value of zero means year 2000.
*/
uint8_t manufacturing_year;
/**
* The month of manufacturing.
*/
uint8_t manufacturing_month;
/**
* The card's total capacity in bytes.
*/
uint32_t capacity;
/**
* Defines wether the card's content is original or copied.
*
* A value of \c 0 means original, \c 1 means copied.
*/
uint8_t flag_copy;
/**
* Defines wether the card's content is write-protected.
*
* \note This is an internal flag and does not represent the
* state of the card's mechanical write-protect switch.
*/
uint8_t flag_write_protect;
/**
* Defines wether the card's content is temporarily write-protected.
*
* \note This is an internal flag and does not represent the
* state of the card's mechanical write-protect switch.
*/
uint8_t flag_write_protect_temp;
/**
* The card's data layout.
*
* See the \c SD_RAW_FORMAT_* constants for details.
*
* \note This value is not guaranteed to match reality.
*/
uint8_t format;
};
//-------------------------------------------------------------------//
//
// Commands Table available in SPI mode
//
//-------------------------------------------------------------------//
#define CMD_GO_IDLE_STATE 0x00 /* CMD0: response R1 */
#define CMD_SEND_OP_COND 0x01 /* CMD1: response R1 */
#define CMD_SEND_CSD 0x09 /* CMD9: response R1 */
#define CMD_SEND_CID 0x0A /* CMD10: response R1 */
#define CMD_STOP_TRANSMISSION 0x0C /* CMD12: response R1 */
#define CMD_SEND_STATUS 0x0D /* CMD13: response R2 */
#define CMD_SET_BLOCKLEN 0x10 /* CMD16: arg0[31:0]: block length, response R1 */
#define CMD_READ_SINGLE_BLOCK 0x11 /* CMD17: arg0[31:0]: data address, response R1 */
#define CMD_READ_MULTIPLE_BLOCK 0x12 /* CMD18: arg0[31:0]: data address, response R1 */
#define CMD_WRITE_SINGLE_BLOCK 0x18 /* CMD24: arg0[31:0]: data address, response R1 */
#define CMD_WRITE_MULTIPLE_BLOCK 0x19 /* CMD25: arg0[31:0]: data address, response R1 */
#define CMD_PROGRAM_CSD 0x1B /* CMD27: response R1 */
#define CMD_SET_WRITE_PROT 0x1C /* CMD28: arg0[31:0]: data address, response R1b */
#define CMD_CLR_WRITE_PROT 0x1D /* CMD29: arg0[31:0]: data address, response R1b */
#define CMD_SEND_WRITE_PROT 0x1E /* CMD30: arg0[31:0]: write protect data address, response R1 */
#define CMD_TAG_SECTOR_START 0x20 /* CMD32: arg0[31:0]: data address, response R1 */
#define CMD_TAG_SECTOR_END 0x21 /* CMD33: arg0[31:0]: data address, response R1 */
#define CMD_UNTAG_SECTOR 0x22 /* CMD34: arg0[31:0]: data address, response R1 */
#define CMD_TAG_ERASE_GROUP_START 0x23 /* CMD35: arg0[31:0]: data address, response R1 */
#define CMD_TAG_ERASE_GROUP_END 0x24 /* CMD36: arg0[31:0]: data address, response R1 */
#define CMD_UNTAG_ERASE_GROUP 0x25 /* CMD37: arg0[31:0]: data address, response R1 */
#define CMD_ERASE 0x26 /* CMD38: arg0[31:0]: stuff bits, response R1b */
#define CMD_LOCK_UNLOCK 0x2A /* CMD42: arg0[31:0]: stuff bits, response R1b */
#define CMD_READ_OCR 0x3A /* CMD58: response R3 */
#define CMD_CRC_ON_OFF 0x3B /* CMD59: arg0[31:1]: stuff bits, arg0[0:0]: crc option, response R1 */
//-------------------------------------------------------------------//
//
// Command Responses
//
//-------------------------------------------------------------------//
/* R1: size 1 byte */
#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
/* R1b: equals R1, additional busy bytes */
/* R2: size 2 bytes */
#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)
/* R3: size 5 bytes */
#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)
/* Data Response: size 1 byte */
#define DR_STATUS_MASK 0x0E
#define DR_STATUS_ACCEPTED 0x05
#define DR_STATUS_CRC_ERR 0x0A
#define DR_STATUS_WRITE_ERR 0x0C
extern uint8_t sdraw_send_command_r1(uint8_t command, uint32_t arg);
extern uint8_t sdraw_sync();
extern uint8_t sdraw_read(uint32_t offset, uint8_t* buffer, uint16_t length);
extern uint8_t sdraw_write(uint32_t offset, const uint8_t* buffer, uint16_t length);
extern uint8_t sdraw_init();
extern uint8_t sdraw_get_info(struct sdraw_info* info);
#endif /* __SDRAW_H__ */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -