📄 sd_cmd.h
字号:
/************************************************************************************/
/* */
/* Copyright (C) 2004 Medeli Electric Industry Co., LTD. */
/* */
/* System Name : IC-1000 */
/* File Name : sd_cmd.h */
/* Revision : 1.00 */
/* Date : 2006/4/10 */
/* Initial version */
/* Joe's work */
/************************************************************************************/
#ifndef SD_CMD_H
#define SD_CMD_H
#ifdef __cplusplus
extern "C" {
#endif
/********************************Includs***************************************/
/*******************************Constants**************************************/
/********************************************************/
/* SD 卡的相关命令与响应宏定义 */
/********************************************************/
typedef enum
{/* 命令响应定义 define command's response */
R1,
R1B,
R2,
R3,
SD_ALL_RESPONSES
}SD_RESPONSE_TYPES;
typedef enum
{/* R1和R2高字节错误码 R1 and upper byte of R2 error code */
B_MSK_IDLE =0x01,
B_MSK_ERASE_RST =0x02,
B_MSK_ILL_CMD =0x04,
B_MSK_CRC_ERR =0x08,
B_MSK_ERASE_SEQ_ERR =0x10,
B_MSK_ADDR_ERR =0x20,
B_MSK_PARAM_ERR =0x40
}SD_R1_R2_HI_ERR_BIT;
typedef enum
{/* R2低字节错误码 lower byte of R2 error code */
B_MSK_TOK_ERROR =0x01,
B_MSK_TOK_CC_ERROR =0x02,
B_MSK_TOK_ECC_FAILED =0x04,
B_MSK_TOK_CC_OUTOFRANGE =0x08,
B_MSK_TOK_CC_LOCKED =0x10
}SD_R2_LOW_ERR_BIT;
/* 数据令牌 Data Tokens */
#define SD_TOK_READ_STARTBLOCK (0xFE)
#define SD_TOK_WRITE_STARTBLOCK (0xFE)
#define SD_TOK_READ_STARTBLOCK_M (0xFE)
#define SD_TOK_WRITE_STARTBLOCK_M (0xFC)
#define SD_TOK_STOP_MULTI (0xFD)
/* 数据响应令牌 Data Response Tokens */
#define SD_RESP_DATA_MSK (0x0F) /* data response mask 数据响应掩码 */
#define SD_RESP_DATA_ACCETPTED (0x05) /* data accepted 数据被接受 */
#define SD_RESP_DATA_REJECT_CRC (0x0B) /* data rejected due to a CRC error由于CRC错误而被拒绝 */
#define SD_RESP_DATA_REJECT_WRITE (0x0D) /* data rejected due to a write error 由于写错误而被拒绝 */
/* 等待类型 Wait Type */
#define SD_WAIT_READ (0x00) /* 读等待 */
#define SD_WAIT_WRITE (0x01) /* 写等待 */
#define SD_WAIT_ERASE (0x02) /* 擦除等待 */
#define SD_READREG_TIMEOUT (8)
/********************************************************/
/* SD 卡的相关命令与响应宏定义 */
/********************************************************/
typedef enum
{
/****************************************************************************************/
/* 基本命令集 Basic command set */
/****************************************************************************************/
CMD0 /*=0*/, /* 复位SD 卡 Reset cards to idle state */
CMD1 /*=1*/, /* 读OCR寄存器 Read the OCR (MMC mode, do not use for SD cards) */
CMD9 /*=9*/, /* 读CSD寄存器 Card sends the CSD */
CMD10 /*=10*/, /* 读CID寄存器 Card sends CID */
CMD12 /*=12*/, /* 停止读多块时的数据传输 Stop a multiple block (stream) read/write operation */
CMD13 /*=13*/, /* 读 Card_Status 寄存器 Get the addressed card's status register */
/****************************************************************************************/
/* 块读命令集 Block read commands */
/****************************************************************************************/
CMD16 /*=16*/, /* 设置块的长度 Set the block length */
CMD17 /*=17*/, /* 读单块 Read a single block */
CMD18 /*=18*/, /* 读多块,直至主机发送CMD12为止 Read multiple blocks until a CMD12 */
/****************************************************************************************/
/* 块写命令集 Block write commands */
/****************************************************************************************/
CMD24 /*=24*/, /* 写单块 Write a block of the size selected with CMD16 */
CMD25 /*=25*/, /* 写多块 Multiple block write until a CMD12 */
CMD27 /*=27*/, /* 写CSD寄存器 Program the programmable bits of the CSD */
/****************************************************************************************/
/* 写保护 Write protection */
/****************************************************************************************/
CMD28 /*=28*/, /* Set the write protection bit of the addressed group */
CMD29 /*=29*/, /* Clear the write protection bit of the addressed group */
CMD30 /*=30*/, /* Ask the card for the status of the write protection bits */
/****************************************************************************************/
/* 擦除命令 Erase commands */
/****************************************************************************************/
CMD32 /*=32*/, /* 设置擦除块的起始地址 Set the address of the first write block to be erased */
CMD33 /*=33*/, /* 设置擦除块的终止地址 Set the address of the last write block to be erased */
CMD38 /*=38*/, /* 擦除所选择的块 Erase the selected write blocks */
/****************************************************************************************/
/* 锁卡命令 Lock Card commands */
/****************************************************************************************/
CMD42 /*=42*/, /* 设置/复位密码或上锁/解锁卡 Set/reset the password or lock/unlock the card */
/****************************************************************************************/
/* 应用命令 Application-specific commands */
/****************************************************************************************/
CMD55 /*=55*/, /* 标志下一个命令为应用命令 Flag that the next command is application-specific */
CMD56 /*=56*/, /* 应用命令的通用I/O General purpose I/O for application-specific commands */
CMD58 /*=58*/, /* 读OCR寄存器 Read the OCR (SPI mode only) */
CMD59 /*=59*/, /* 使能或禁止 CRC Turn CRC on or off */
SD_SPI_ALL_GEN_CMD
}SD_SPI_COMMAND;
typedef struct
{
UBYTE com;
SD_RESPONSE_TYPES rsp;
}SD_COMMAND_STRUCT;
/****************************************************************************************/
/* 应用命令 Application-specific command */
/****************************************************************************************/
typedef enum
{
ACMD13 /*=13*/, /* 获取 SD Status寄存器 Get the SD card's status */
ACMD22 /*=22*/, /* 得到已写入卡中的块的个数 Get the number of written write blocks (Minus errors ) */
ACMD23 /*=23*/, /* 在写之前,设置预先擦除的块的个数 Set the number of write blocks to be pre-erased before writing */
ACMD41 /*=41*/, /* 读取OCR寄存器 Get the card's OCR (SD mode) */
ACMD42 /*=42*/, /* 连接/断开CD/DATA[3]引脚上的上拉电阻 Connect or disconnect the 50kOhm internal pull-up on CD/DAT[3] */
ACMD51 /*=51*/, /* 读取SCR寄存器 Get the SD configuration register */
SD_SPI_ALL_APP_CMD
}SD_SPI_APP_COMMAND;
/*********************************Enums****************************************/
/********************************Marcros***************************************/
/*******************************Structures*************************************/
/********************************Specials**************************************/
/**************************Variable Declaration********************************/
/**************************Function Declaration********************************/
/**************************End of sd_command.h*********************************/
#ifdef __cplusplus
}; /* End of 'extern "C"' */
#endif
#endif /* End of sd_command.h */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -