?? sddriver.h
字號(hào):
#include <csl_stdinc.h>
/***********************************************************************/
typedef struct SD_STRUCT
{
Uint32 block_num; /* 卡中塊的數(shù)量 */
Uint32 block_len; /* 卡的塊長度(單位:字節(jié)) */
Uint32 erase_unit; /* 一次可擦除的塊個(gè)數(shù) */
Uint32 timeout_read; /* 讀塊超時(shí)時(shí)間(單位: 8 SPI clock) */
Uint32 timeout_write; /* 寫塊超時(shí)時(shí)間(單位: 8 SPI clock) */
Uint32 timeout_erase; /* 擦塊超時(shí)時(shí)間(單位: 8 SPI clock) */
}sd_struct;
extern sd_struct sds; /* SD卡信息結(jié)構(gòu)體變量 */
/*
*************************************************************
用戶API函數(shù): 讀, 寫, 擦 SD卡 API函數(shù)及錯(cuò)誤碼
*************************************************************
*/
/* 錯(cuò)誤碼 error code */
#define SD_NO_ERR 0x00 // 函數(shù)執(zhí)行成功
#define SD_ERR_NO_CARD 0x01 // SD卡沒有完全插入到卡座中
#define SD_ERR_USER_PARAM 0x02 // 用戶使用API函數(shù)時(shí),入口參數(shù)有錯(cuò)誤
#define SD_ERR_CARD_PARAM 0x03 // 卡中參數(shù)有錯(cuò)誤(與本模塊不兼容)
#define SD_ERR_VOL_NOTSUSP 0x04 // 卡不支持3.3V供電
#define SD_ERR_OVER_CARDRANGE 0x05 // 操作超出卡容量范圍
/* SD命令可能返回的錯(cuò)誤碼 */
#define SD_ERR_CMD_RESPTYPE 0x10 // 命令類型錯(cuò)誤
#define SD_ERR_CMD_TIMEOUT 0x11 // SD命令響應(yīng)超時(shí)
#define SD_ERR_CMD_RESP 0x12 // SD命令響應(yīng)錯(cuò)誤
/* 數(shù)據(jù)流錯(cuò)誤碼 */
#define SD_ERR_DATA_CRC16 0x20 // 數(shù)據(jù)流CRC16校驗(yàn)不通過
#define SD_ERR_DATA_START_TOK 0x21 // 讀單塊或多塊時(shí),數(shù)據(jù)開始令牌不正確
#define SD_ERR_DATA_RESP 0x22 // 寫單塊或多塊時(shí),SD卡數(shù)據(jù)響應(yīng)令牌不正確
/* 等待錯(cuò)誤碼 */
#define SD_ERR_TIMEOUT_WAIT 0x30 // 寫或擦操作時(shí),發(fā)生超時(shí)錯(cuò)誤
#define SD_ERR_TIMEOUT_READ 0x31 // 讀操作超時(shí)錯(cuò)誤
#define SD_ERR_TIMEOUT_WRITE 0x32 // 寫操作超時(shí)錯(cuò)誤
#define SD_ERR_TIMEOUT_ERASE 0x33 // 擦除操作超時(shí)錯(cuò)誤
#define SD_ERR_TIMEOUT_WAITIDLE 0x34 // 初始化SD卡時(shí),等待SD卡進(jìn)入空閑狀態(tài)超時(shí)錯(cuò)誤
/* 寫操作可能返回的錯(cuò)誤碼 */
#define SD_ERR_WRITE_BLK 0x40 // 寫塊數(shù)據(jù)錯(cuò)誤
#define SD_ERR_WRITE_BLKNUMS 0x41 // 寫多塊時(shí),想要寫入的塊與正確寫入的塊數(shù)不一致
#define SD_ERR_WRITE_PROTECT 0x42 // 卡外殼的寫保護(hù)開關(guān)打在寫保護(hù)位置
/* 初始化SD卡 initialize sd card */
extern Uint8 SD_Initialize(void);
/* 從SD卡中讀一個(gè)塊 read a single block from sd card */
extern Uint8 SD_ReadBlock(Uint32 blockaddr, Uint8 *recbuf);
/* 從SD卡中讀多個(gè)塊 read multi blocks from sd card */
extern Uint8 SD_ReadMultiBlock(Uint32 blockaddr, Uint32 blocknum, Uint8 *recbuf);
/* 向SD卡中寫入一個(gè)塊 write a block to sd card */
extern Uint8 SD_WriteBlock(Uint32 blockaddr, Uint8 *recbuf);
/* 向SD卡中寫入多個(gè)塊 write multi blocks to sd card */
extern Uint8 SD_WriteMultiBlock(Uint32 blockaddr, Uint32 blocknum, Uint8 *recbuf);
/* 擦除SD卡中的塊 Erase the block of sd card */
extern Uint8 SD_EraseBlock(Uint32 startaddr, Uint32 blocknum);
/* 得到SD卡信息 get information of sd card */
extern Uint8 SD_GetCardInfo(void);
/* 由CSD寄存器計(jì)算超時(shí)時(shí)間 calculate timeout from CSD register */
void SD_CalTimeout(Uint8 *csdbuf);
/* 激活SD卡內(nèi)部進(jìn)行初始化處理 active sd to initialize process */
Uint8 SD_ActiveInit(void);
/*
*************************************************************
下面為軟件包用到的與SD卡相關(guān)的宏定義
*************************************************************
*/
/* Mask off the bits in the OCR corresponding to voltage range 3.2V to
* 3.4V, OCR bits 20 and 21 */
#define MSK_OCR_33 0xC0
/* 定義在初始化階段,等待SD卡退出空閑狀態(tài)的重試次數(shù) */
/* Number of tries to wait for the card to go idle during initialization */
#define SD_IDLE_WAIT_MAX 1000
/* SD卡命令超時(shí)時(shí)間(單位 8clock)*/
/* timeout of command */
#define SD_CMD_TIMEOUT 100
/* 100ms 相當(dāng)?shù)腟PI時(shí)鐘數(shù)(單位 unit: 8 clocks) */
/* 100ms correspond to SPI clock(unit: 8 clocks)*/
#define READ_TIMEOUT_100MS 100 * SPI_CLOCK / 1000 / 8
/* 250ms 相當(dāng)?shù)腟PI時(shí)鐘數(shù)(單位 unit: 8 clocks) */
/* 250ms correspond to SPI clock(unit: 8 clocks)*/
#define WRITE_TIMEOUT_250MS 250 * SPI_CLOCK / 1000 / 8
/* CSD中一些域的字節(jié)位置(高字節(jié)在前) */
#define TAAC_POS 1 //TACC
#define NSAC_POS 2 //NSAC
#define READ_BL_LEN_POS 5 //READ_BL_LEN
#define C_SIZE_POS1 6 //C_SIZE upper 2-bit
#define C_SIZE_POS2 7 //C_SIZE middle 8-bit
#define C_SIZE_POS3 8 //C_SIZE lower 2-bit
#define C_SIZE_MULT_POS1 9 //C_SIZE_MULT upper 2-bit
#define C_SIZE_MULT_POS2 10 //C_SIZE_MULT lower 1-bit
#define SECTOR_SIZE_POS1 10 //SECTOR_SIZE upper 5-bit
#define SECTOR_SIZE_POS2 11 //SECTOR_SIZE lower 2-bit
#define R2WFACTOR_POS 12 //R2WFACTOR_POS
//CSD中一些域的掩碼
#define TAAC_MSK 0x07 //TACC 域掩碼
#define NSAC_MSK 0x78 //NSAC 域掩碼
#define READ_BL_LEN_MSK 0x0F //READ_BL_LEN 的掩碼
#define C_SIZE_MSK1 0x03 //C_SIZE 高2位掩碼
#define C_SIZE_MSK3 0xC0 //C_SIZE 低2位掩碼
#define C_SIZE_MULT_MSK1 0x03 //C_SIZE_MULT 的高2位掩碼
#define C_SIZE_MULT_MSK2 0x80 //C_SIZE_MULT 的低2位掩碼
#define R2WFACTOR_MSK 0x1C //R2WFACTOR 掩碼
#define SECTOR_SIZE_MSK1 0x3F //SECTOR_SIZE 的高5位
#define SECTOR_SIZE_MSK2 0x80 //SECTOR_SIZE 的低2位
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -