?? sddriver.h
字號:
/******************************************************************************************************
** Descriptions: sd 卡驅動軟件包: 用戶API函數(頭文件)
********************************************************************************************************/
#ifndef __sddriver_h
#define __sddriver_h
/* SD卡信息結構體定義 */
/* the information structure variable of SD Card*/
typedef struct SD_STRUCT
{
uint8 block_num; /* 卡中塊的數量 */
uint8 block_len; /* 卡的塊長度(單位:字節) */
uint8 erase_unit; /* 一次可擦除的塊個數 */
uint8 timeout_read; /* 讀塊超時時間(單位: 8 SPI clock) */
uint8 timeout_write; /* 寫塊超時時間(單位: 8 SPI clock) */
uint8 timeout_erase; /* 擦塊超時時間(單位: 8 SPI clock) */
}sd_struct;
extern sd_struct sds; /* SD卡信息結構體變量 */
/*
*************************************************************
用戶API函數: 讀, 寫, 擦 SD卡 API函數及錯誤碼
*************************************************************
*/
/* 錯誤碼 error code */
#define SD_NO_ERR 0x00 // 函數執行成功
#define SD_ERR_NO_CARD 0x01 // SD卡沒有完全插入到卡座中
#define SD_ERR_USER_PARAM 0x02 // 用戶使用API函數時,入口參數有錯誤
#define SD_ERR_CARD_PARAM 0x03 // 卡中參數有錯誤(與本模塊不兼容)
#define SD_ERR_VOL_NOTSUSP 0x04 // 卡不支持3.3V供電
#define SD_ERR_OVER_CARDRANGE 0x05 // 操作超出卡容量范圍
/* SD命令可能返回的錯誤碼 */
#define SD_ERR_CMD_RESPTYPE 0x10 // 命令類型錯誤
#define SD_ERR_CMD_TIMEOUT 0x11 // SD命令響應超時
#define SD_ERR_CMD_RESP 0x12 // SD命令響應錯誤
/* 數據流錯誤碼 */
#define SD_ERR_DATA_CRC16 0x20 // 數據流CRC16校驗不通過
#define SD_ERR_DATA_START_TOK 0x21 // 讀單塊或多塊時,數據開始令牌不正確
#define SD_ERR_DATA_RESP 0x22 // 寫單塊或多塊時,SD卡數據響應令牌不正確
/* 等待錯誤碼 */
#define SD_ERR_TIMEOUT_WAIT 0x30 // 寫或擦操作時,發生超時錯誤
#define SD_ERR_TIMEOUT_READ 0x31 // 讀操作超時錯誤
#define SD_ERR_TIMEOUT_WRITE 0x32 // 寫操作超時錯誤
#define SD_ERR_TIMEOUT_ERASE 0x33 // 擦除操作超時錯誤
#define SD_ERR_TIMEOUT_WAITIDLE 0x34 // 初始化SD卡時,等待SD卡進入空閑狀態超時錯誤
/* 寫操作可能返回的錯誤碼 */
#define SD_ERR_WRITE_BLK 0x40 // 寫塊數據錯誤
#define SD_ERR_WRITE_BLKNUMS 0x41 // 寫多塊時,想要寫入的塊與正確寫入的塊數不一致
#define SD_ERR_WRITE_PROTECT 0x42 // 卡外殼的寫保護開關打在寫保護位置
/* 初始化SD卡 initialize sd card */
extern uint8 SD_Initialize(void);
/* 從SD卡中讀一個塊 read a single block from sd card */
extern uint8 SD_ReadBlock(uint32 blockaddr, uint8 *recbuf);
/* 從SD卡中讀多個塊 read multi blocks from sd card */
extern uint8 SD_ReadMultiBlock(uint32 blockaddr, uint32 blocknum, uint8 *recbuf);
/* 向SD卡中寫入一個塊 write a block to sd card */
extern uint8 SD_WriteBlock(uint32 blockaddr, uint8 *recbuf);
/* 向SD卡中寫入多個塊 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寄存器計算超時時間 calculate timeout from CSD register */
extern void SD_CalTimeout(uint8 *csdbuf);
/* 激活SD卡內部進行初始化處理 active sd to initialize process */
uint8 SD_ActiveInit(void);
/*
*************************************************************
下面為軟件包用到的與SD卡相關的宏定義
*************************************************************
*/
/* 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 //1100 0000B
/* 定義在初始化階段,等待SD卡退出空閑狀態的重試次數 */
/* Number of tries to wait for the card to go idle during initialization */
#define SD_IDLE_WAIT_MAX 1000
/* SD卡命令超時時間(單位 8clock)*/
/* timeout of command */
#define SD_CMD_TIMEOUT 100
/* 100ms 相當的SPI時鐘數(單位 unit: 8 clocks) */
/* 100ms correspond to SPI clock(unit: 8 clocks)*/
#define READ_TIMEOUT_100MS 100 * SPI_CLOCK / 1000 / 8
/* 250ms 相當的SPI時鐘數(單位 unit: 8 clocks) */
/* 250ms correspond to SPI clock(unit: 8 clocks)*/
#define WRITE_TIMEOUT_250MS 250 * SPI_CLOCK / 1000 / 8
/* CSD中一些域的字節位置(高字節在前) */
#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位
#endif
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -