?? sddriver.h
字號(hào):
/****************************************Copyright (c)**************************************************
** Co.,LTD.
**
** http://
**
**--------------File Info-------------------------------------------------------------------------------
** File name: sddriver.c
** Last modified Date: 2007-10-15
** Last Version: V1.0
** Descriptions: SD/MMC卡讀寫(xiě)模塊: 物理層 用戶(hù)API函數(shù)(頭文件)
** Soft Packet of SD Card: user API funciton (header file)
**
**------------------------------------------------------------------------------------------------------
** Created by: lhlzjut@hotmail.com
** Created date: 2007-10-15
** Version: V1.0
** Descriptions: The original version
**
**------------------------------------------------------------------------------------------------------
********************************************************************************************************/
#ifndef __SDDRIVER_H__
#define __SDDRIVER_H__
#include "sdconfig.h"
/* SD卡信息結(jié)構(gòu)體定義 */
/* the information structure variable of SD Card*/
typedef struct SD_STRUCT
{
INT8U card_type;
INT32U block_num; /* 卡中塊的數(shù)量 */
INT32U block_len; /* 卡的塊長(zhǎng)度(單位:字節(jié)) */
INT32U erase_unit; /* 一次可擦除的塊個(gè)數(shù) */
INT32U timeout_read; /* 讀塊超時(shí)時(shí)間(單位: 8 SPI clock) */
INT32U timeout_write; /* 寫(xiě)塊超時(shí)時(shí)間(單位: 8 SPI clock) */
INT32U timeout_erase; /* 擦塊超時(shí)時(shí)間(單位: 8 SPI clock) */
}sd_struct;
extern sd_struct sds; /* SD卡信息結(jié)構(gòu)體變量 */
/*
*************************************************************
用戶(hù)API函數(shù): 讀, 寫(xiě), 擦 SD卡 API函數(shù)及錯(cuò)誤碼
*************************************************************
*/
/* 錯(cuò)誤碼 error code */
#define SD_NO_ERR 0x00 // 函數(shù)執(zhí)行成功
#define SD_ERR_NO_CARD 0x01 // 卡沒(méi)有完全插入到卡座中
#define SD_ERR_USER_PARAM 0x02 // 用戶(hù)使用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 // 操作超出卡容量范圍
#define SD_ERR_UNKNOWN_CARD 0x06 // 無(wú)法識(shí)別卡型
/* SD命令可能返回的錯(cuò)誤碼 */
#define SD_ERR_CMD_RESPTYPE 0x10 // 命令類(lèi)型錯(cuò)誤
#define SD_ERR_CMD_TIMEOUT 0x11 // 卡命令響應(yīng)超時(shí)
#define SD_ERR_CMD_RESP 0x12 // 卡命令響應(yīng)錯(cuò)誤
/* 數(shù)據(jù)流錯(cuò)誤碼 */
#define SD_ERR_DATA_CRC16 0x20 // 數(shù)據(jù)流CRC16校驗(yàn)不通過(guò)
#define SD_ERR_DATA_START_TOK 0x21 // 讀單塊或多塊時(shí),數(shù)據(jù)開(kāi)始令牌不正確
#define SD_ERR_DATA_RESP 0x22 // 寫(xiě)單塊或多塊時(shí),卡數(shù)據(jù)響應(yīng)令牌不正確
/* 等待錯(cuò)誤碼 */
#define SD_ERR_TIMEOUT_WAIT 0x30 // 寫(xiě)或擦操作時(shí),發(fā)生超時(shí)錯(cuò)誤
#define SD_ERR_TIMEOUT_READ 0x31 // 讀操作超時(shí)錯(cuò)誤
#define SD_ERR_TIMEOUT_WRITE 0x32 // 寫(xiě)操作超時(shí)錯(cuò)誤
#define SD_ERR_TIMEOUT_ERASE 0x33 // 擦除操作超時(shí)錯(cuò)誤
#define SD_ERR_TIMEOUT_WAITIDLE 0x34 // 初始化卡時(shí),等待卡退出空閑狀態(tài)超時(shí)錯(cuò)誤
/* 寫(xiě)操作可能返回的錯(cuò)誤碼 */
#define SD_ERR_WRITE_BLK 0x40 // 寫(xiě)塊數(shù)據(jù)錯(cuò)誤
#define SD_ERR_WRITE_BLKNUMS 0x41 // 寫(xiě)多塊時(shí),想要寫(xiě)入的塊與正確寫(xiě)入的塊數(shù)不一致
#define SD_ERR_WRITE_PROTECT 0x42 // 卡外殼的寫(xiě)保護(hù)開(kāi)關(guān)打在寫(xiě)保護(hù)位置
/* 使用UCOS-II時(shí)可能出現(xiàn)的錯(cuò)誤 */
#define SD_ERR_CREATE_SEMSD 0xA0 // 創(chuàng)建SD/MMC卡訪問(wèn)信號(hào)量失敗
/**************************************************
其它宏定義
***************************************************/
#define CARDTYPE_SD 0x00 // 卡型為SD 卡
#define CARDTYPE_MMC 0x01 // 卡型為MMC 卡
#define SD_UCOSII_SMALLWAIT 256 // 運(yùn)行于UCOS-II時(shí)的小等待時(shí)間
#define SD_READREG_TIMEOUT 8 // 讀寄存器的超時(shí)時(shí)間
/* 初始化SD卡 initialize sd card */
extern INT8U SD_Initialize(void);
/* 從SD卡中讀一個(gè)塊 read a single block from sd card */
extern INT8U SD_ReadBlock(INT32U blockaddr,INT32U len, INT8U *recbuf);
/* 從SD卡中讀多個(gè)塊 read multi blocks from sd card */
extern INT8U SD_ReadMultiBlock(INT32U blockaddr, INT32U blocknum, INT8U *recbuf);
/* 向SD卡中寫(xiě)入一個(gè)塊 write a block to sd card */
extern INT8U SD_WriteBlock(INT32U blockaddr, INT32U len, INT8U *sendbuf);
/* 向SD卡中寫(xiě)入多個(gè)塊 write multi blocks to sd card */
extern INT8U SD_WriteMultiBlock(INT32U blockaddr, INT32U blocknum, INT8U *recbuf);
/* 擦除SD卡中的塊 Erase the block of sd card */
extern INT8U SD_EraseBlock(INT32U startaddr, INT32U blocknum);
/* 得到SD卡信息 get information of sd card */
extern INT8U SD_GetCardInfo(void);
/* 由CSD寄存器計(jì)算超時(shí)時(shí)間 calculate timeout from CSD register */
extern INT8U SD_CalTimeout(INT8U *csdbuf);
/* 激活SD卡內(nèi)部進(jìn)行初始化處理 active sd to initialize process */
extern INT8U SD_ActiveInit(void);
/* 向OS申請(qǐng)?jiān)L問(wèn)卡的信號(hào)量 request semaphore accessed card to OS */
extern void SD_StartSD(void);
/* 將訪問(wèn)卡的信號(hào)量還給OS return semaphore accessed card to OS */
extern void SD_EndSD(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 0x30
/* 定義在初始化階段,等待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
/**/
#define ERASE_GRP_SIZE_POS 10 //MMC卡 ERASE_GRP_SIZE 5-bit
#define ERASE_GRP_MULTI_POS1 10 //MMC卡 ERASE_GRP_MULTI 2-bit
#define ERASE_GRP_MULTI_POS2 11 //MMC卡 ERASE_GRP_MULTI 3-bit
//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位
#define ERASE_GRP_SIZE_MSK 0x7C //MMC卡 ERASE_GRP_SIZE 掩碼
#define ERASE_GRP_MULTI_MSK1 0x03 //MMC卡 ERASE_GRP_MULTI 高2位掩碼
#define ERASE_GRP_MULTI_MSK2 0xE0 //MMC卡 ERASE_GRP_NULTI 低3位掩碼
#endif
//****************************************END OF FILE**********************************/
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -