?? sdcmd.h
字號(hào):
/*********************************************************************************
SD/MMC 卡 SPI 總線模式命令及響應(yīng)
**********************************************************************************/
#if (!SDBUS_MODE_EN)
/* R1和R2高字節(jié)錯(cuò)誤碼 R1 and upper byte of R2 error code */
#define MSK_IDLE 0x01
#define MSK_ERASE_RST 0x02
#define MSK_ILL_CMD 0x04
#define MSK_CRC_ERR 0x08
#define MSK_ERASE_SEQ_ERR 0x10
#define MSK_ADDR_ERR 0x20
#define MSK_PARAM_ERR 0x40
/* R2低字節(jié)錯(cuò)誤碼 lower byte of R2 error code */
#define MSK_TOK_ERROR 0x01
#define MSK_TOK_CC_ERROR 0x02
#define MSK_TOK_ECC_FAILED 0x04
#define MSK_TOK_CC_OUTOFRANGE 0x08
#define MSK_TOK_CC_LOCKED 0x10
/* 數(shù)據(jù)令牌 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
/* 數(shù)據(jù)響應(yīng)令牌 Data Response Tokens */
#define SD_RESP_DATA_MSK 0x0F //數(shù)據(jù)響應(yīng)掩碼
#define SD_RESP_DATA_ACCETPTED 0x05 //數(shù)據(jù)被接受
#define SD_RESP_DATA_REJECT_CRC 0x0B //由于CRC錯(cuò)誤而被拒絕
#define SD_RESP_DATA_REJECT_WRITE 0x0D //由于寫(xiě)錯(cuò)誤而被拒絕
/* 等待類(lèi)型 Wait Type */
#define SD_WAIT_READ 0x00 //讀等待
#define SD_WAIT_WRITE 0x01 //寫(xiě)等待
#define SD_WAIT_ERASE 0x02 //擦除等待
/* 命令響應(yīng)定義 define command's response */
#define R1 1
#define R1B 2
#define R2 3
#define R3 4
/*
*********************************************
SD/MMC卡SPI模式下命令集
*********************************************
*/
/******************************** 基本命令集 Basic command set **************************/
/* 復(fù)位SD 卡 Reset cards to idle state */
#define CMD0 0
#define CMD0_R R1
/* 讀OCR寄存器 Read the OCR (MMC mode, do not use for SD cards) */
#define CMD1 1
#define CMD1_R R1
/* 讀CSD寄存器 Card sends the CSD */
#define CMD9 9
#define CMD9_R R1
/* 讀CID寄存器 Card sends CID */
#define CMD10 10
#define CMD10_R R1
/* 停止讀多塊時(shí)的數(shù)據(jù)傳輸 Stop a multiple block (stream) read/write operation */
#define CMD12 12
#define CMD12_R R1B
/* 讀 Card_Status 寄存器 Get the addressed card's status register */
#define CMD13 13
#define CMD13_R R2
/***************************** 塊讀命令集 Block read commands **************************/
/* 設(shè)置塊的長(zhǎng)度 Set the block length */
#define CMD16 16
#define CMD16_R R1
/* 讀單塊 Read a single block */
#define CMD17 17
#define CMD17_R R1
/* 讀多塊,直至主機(jī)發(fā)送CMD12為止 Read multiple blocks until a CMD12 */
#define CMD18 18
#define CMD18_R R1
/***************************** 塊寫(xiě)命令集 Block write commands *************************/
/* 寫(xiě)單塊 Write a block of the size selected with CMD16 */
#define CMD24 24
#define CMD24_R R1
/* 寫(xiě)多塊 Multiple block write until a CMD12 */
#define CMD25 25
#define CMD25_R R1
/* 寫(xiě)CSD寄存器 Program the programmable bits of the CSD */
#define CMD27 27
#define CMD27_R R1
/***************************** 寫(xiě)保護(hù) Write protection *****************************/
/* Set the write protection bit of the addressed group */
#define CMD28 28
#define CMD28_R R1B
/* Clear the write protection bit of the addressed group */
#define CMD29 29
#define CMD29_R R1B
/* Ask the card for the status of the write protection bits */
#define CMD30 30
#define CMD30_R R1
/***************************** 擦除命令 Erase commands *******************************/
/* 設(shè)置擦除塊的起始地址(只用于SD卡) Set the address of the first write block to be erased(only for SD) */
#define CMD32 32
#define CMD32_R R1
/* 設(shè)置擦除塊的終止地址(只用于SD卡) Set the address of the last write block to be erased(only for SD) */
#define CMD33 33
#define CMD33_R R1
/* 設(shè)置擦除塊的起始地址(只用于MMC卡) Set the address of the first write block to be erased(only for MMC) */
#define CMD35 35
#define CMD35_R R1
/* 設(shè)置擦除塊的終止地址(只用于MMC卡) Set the address of the last write block to be erased(only for MMC) */
#define CMD36 36
#define CMD36_R R1
/* 擦除所選擇的塊 Erase the selected write blocks */
#define CMD38 38
#define CMD38_R R1B
/***************************** 鎖卡命令 Lock Card commands ***************************/
/* 設(shè)置/復(fù)位密碼或上鎖/解鎖卡 Set/reset the password or lock/unlock the card */
#define CMD42 42
#define CMD42_R R1B
/* Commands from 42 to 54, not defined here */
/***************************** 應(yīng)用命令 Application-specific commands ****************/
/* 禁止下一個(gè)命令為應(yīng)用命令 Flag that the next command is application-specific */
#define CMD55 55
#define CMD55_R R1
/* 應(yīng)用命令的通用I/O General purpose I/O for application-specific commands */
#define CMD56 56
#define CMD56_R R1
/* 讀OCR寄存器 Read the OCR (SPI mode only) */
#define CMD58 58
#define CMD58_R R3
/* 使能或禁止 CRC Turn CRC on or off */
#define CMD59 59
#define CMD59_R R1
/***************************** 應(yīng)用命令 Application-specific commands ***************/
/* 獲取 SD Status寄存器 Get the SD card's status */
#define ACMD13 13
#define ACMD13_R R2
/* 得到已寫(xiě)入卡中的塊的個(gè)數(shù) Get the number of written write blocks (Minus errors ) */
#define ACMD22 22
#define ACMD22_R R1
/* 在寫(xiě)之前,設(shè)置預(yù)先擦除的塊的個(gè)數(shù) Set the number of write blocks to be pre-erased before writing */
#define ACMD23 23
#define ACMD23_R R1
/* 讀取OCR寄存器 Get the card's OCR (SD mode) */
#define ACMD41 41
#define ACMD41_R R1
/* 連接/斷開(kāi)CD/DATA[3]引腳上的上拉電阻 Connect or disconnect the 50kOhm internal pull-up on CD/DAT[3] */
#define ACMD42 42
#define ACMD42_R R1
/* 讀取SCR寄存器 Get the SD configuration register */
#define ACMD51 51
#define ACMD51_R R1
extern INT8U SdSpi_SendCmd(sd_struct *sds, INT8U cmd, INT8U *param, INT8U resptype, INT8U *resp);
extern void SdSpi_PackParam(INT8U *parameter, INT32U value); // 封裝參數(shù)
extern INT8U SdSpi_BlockCommand(sd_struct *sds, INT8U cmd, INT8U resptype, INT32U parameter);
// 塊命令
extern INT8U SpiCmd_Go_Idle_State(sd_struct *sds); // 復(fù)位SD卡
extern INT8U SpiCmd_Send_OP_Cond(sd_struct *sds);
extern INT8U SpiCmd_Send_CSD(sd_struct *sds, INT8U csdlen, INT8U *recbuf); // 讀CSD
extern INT8U SpiCmd_Send_CID(sd_struct *sds, INT8U cidlen, INT8U *recbuf); // 讀CID
extern INT8U SpiCmd_Stop_Transmission(sd_struct *sds); // 停止傳輸
extern INT8U SpiCmd_Send_Status(sd_struct *sds, INT8U len, INT8U *buffer); // 讀Card Status
extern INT8U SpiCmd_Set_BlockLen(sd_struct *sds, INT32U length); // 設(shè)置塊長(zhǎng)度
extern INT8U SpiCmd_Read_Single_Block(sd_struct *sds, INT32U blockaddr); // 讀單塊
extern INT8U SpiCmd_Read_Multiple_Block(sd_struct *sds, INT32U blockaddr); // 讀多塊
extern INT8U SpiCmd_Write_Single_Block(sd_struct *sds, INT32U blockaddr); // 寫(xiě)單塊
extern INT8U SpiCmd_Write_Multiple_Block(sd_struct *sds, INT32U blockaddr); // 寫(xiě)多塊
extern INT8U SpiCmd_Program_CSD(sd_struct *sds, INT8U len, INT8U *buff); // 寫(xiě)CSD寄存器
extern INT8U SdCmd_Erase_Wr_Blk_Start(sd_struct *sds, INT32U startblock); // 擦塊起始地址
extern INT8U SdCmd_Erase_Wr_Blk_End(sd_struct *sds, INT32U endblock); // 擦塊終止地址
extern INT8U SdCmd_Erase(sd_struct *sds); // 擦除所選的塊
extern INT8U SpiCmd_ReadOCR(sd_struct *sds, INT32U *ocrbuf); // 讀OCR
extern INT8U SpiCmd_CRC_ON_OFF(sd_struct *sds, INT8U bEnable); // 使能CRC校驗(yàn)
// 特殊應(yīng)用命令
extern INT8U SpiCmd_ReadSD_Status(sd_struct *sds, INT8U sdslen, INT8U *recbuf); // 讀SD_Status
extern INT8U SpiCmd_Send_SCR(sd_struct *sds, INT8U scrlen, INT8U *recbuf); // 讀SCR
extern INT8U SpiCmd_Send_Num_WR_Blcoks(sd_struct *sds, INT32U *blocknum); // 得到正確寫(xiě)入塊數(shù)
// 數(shù)據(jù)流函數(shù)
extern INT8U SdSpi_ReadRegister(sd_struct *sds, INT32U len, INT8U *recbuf); // 讀寄存器
extern INT8U SdSpi_ReadBlockData(sd_struct *sds, INT32U len, INT8U *recbuf); // 讀塊數(shù)據(jù)
extern INT8U SdSpi_WriteBlockData(sd_struct *sds, INT8U bmulti, INT32U len, INT8U *sendbuf); // 寫(xiě)塊數(shù)據(jù)
// 其它函數(shù)
extern void SdSpi_StopMultiToken(sd_struct *sds); // 停止多塊寫(xiě)令牌
extern INT8U SdSpi_WaitBusy(sd_struct *sds, INT8U waittype); // 忙
extern void SdSpi_Delay(sd_struct *sds, INT8U value); // 發(fā)生SPI時(shí)鐘
#endif // end of !SDBUS_MODE_EN
#endif // end of __SDCMD_H__
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -