⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sd.h

📁 linux 2.6下的sd卡驱动
💻 H
字号:
/****************************************************************************   File:    sd.h  -   Common definition for SD* *   The content of this file or document is CONFIDENTIAL and PROPRIETARY*   to Jade Technologies Co., Ltd.  It is subject to the terms of a*   License Agreement between Licensee and Jade Technologies Co., Ltd.*   restricting among other things, the use, reproduction, distribution*   and transfer.  Each of the embodiments, including this information *   and any derivative work shall retain this copyright notice.* *   Copyright (c) 2005 Jade Technologies Co., Ltd. *   All rights reserved.****************************************************************************/#ifndef SD_H#define SD_H#include "sd_datatype.h"//------------------------------------------------------------------------------// Global Macros//------------------------------------------------------------------------------// MSG definition, if 1, print correspond message.#define MSG_SYS		0#define MSG_DISK	0#define MSG_INFO	0#define MSG_PAP		0//PNP#define MSG_DATA	1#define MSG_DMA		1// Test definition,	if 1, card get into test mode.#define SD_TEST		0#define IF_WIDE_BUS	1// SD physic address#define PHYS_SD0_BASE  	0x20039000// SD sector size#define BYTES_PER_SECTOR_SH	0x9//SH:bit to shift#define BYTES_PER_SECTOR	(1<<BYTES_PER_SECTOR_SH)#define SECTORS_PER_BATCH	0x7F#define BYTES_FIFO		0x40// Card Status definition, used by variable "g_CardStatus". #define STATE_INITING		1#define STATE_OPENED		2#define STATE_CLOSED		3#define STATE_DEINITING		4#define STATE_DEAD		5#define STATE_TEST		6#define READY_FOR_DATA	(1 << 8)// Others#define MIN(__x,__y) ((__x)<(__y)?(__x):(__y)) #define apBIT_MASK_FIELD(__bw, __bs) ((unsigned long)((((__bw)==32)?0xFFFFFFFF:(unsigned long)((unsigned long)1U << (__bw)) - 1)) << (__bs))#define apBIT_GET_FIELD(__datum, __bw, __bs) ((unsigned long)(((__datum) & ((unsigned long) apBIT_MASK_FIELD(__bw,__bs))) >> (__bs)))//// map to SD PL180's register of system memory.//typedef volatile struct{	volatile unsigned long    sd_POWER    ;	volatile unsigned long    sd_CLOCK    ;	volatile unsigned long    sd_ARGUMENT ;	volatile unsigned long    sd_COMMAND  ;	volatile unsigned long    sd_RESPCMD  ;	volatile unsigned long    sd_RESP0    ;	volatile unsigned long    sd_RESP1    ;	volatile unsigned long    sd_RESP2    ;	volatile unsigned long    sd_RESP3    ;	volatile unsigned long    sd_DATATMR  ;	volatile unsigned long    sd_DATALEN  ;	volatile unsigned long    sd_DATACTRL ;	volatile unsigned long    sd_DATACNT  ;	volatile unsigned long    sd_STATUS   ;	volatile unsigned long    sd_CLEAR    ;	volatile unsigned long    sd_MASK0    ;	volatile unsigned long    sd_MASK1	  ;	volatile unsigned long    sd_SELECT   ;	volatile unsigned long    sd_FIFOCNT  ;	volatile unsigned long    RESERVED[0x0D];	volatile unsigned long    sd_FIFO		;    }SD_REG;//// structure to construct a command and for configuration.//typedef struct {	apMCI_eCommand		CmdIndex;				apMCI_eCmdResponse	Responsetype;			apMCI_eCmdTimer		CmdTimer;				unsigned long		Option;			//	indicate interrupt to ignore	unsigned long		InterruptMask;		//	indicate which interrupt to response.	unsigned long		WaitTime;}Command_Parameter;//// structure to store and control the whole operate flow//typedef volatile struct {	void 				*cmddone_data;	unsigned long		laststatus;	volatile int		*SysDetect;	SD_REG*				Registers;	apMCI_sDecodedCSD	CardCSD;	apMCI_sDecodedCID	CardCID;//	diskinfo		diskinfo;//sd card's infomation,however,is scattered in the file! 	int					ifDMA;	int 				irq_request_sign;	spinlock_t			lock;	spinlock_t			queue_lock;	spinlock_t			cmd_lock;	struct request_queue 	*queue;	struct gendisk		*gd;	struct completion	thread_complete;	wait_queue_head_t	thread_wq;	struct semaphore	thread_sem;	unsigned int		flags;	struct request		*req;	struct timer_list	timer;	struct tasklet_struct	card_tasklet;}SD_controller;//// command parameters, used by function "SDI_SendCmd"//static Command_Parameter CommandParameters[] = {#define GO_IDLE_STATE 			0	{	MCI_CMD0_GO_IDLE_STATE,		apMCI_CMDRESP_NONE,	apMCI_CMD_TIMEOUT,	MCI_CMDOPT_IMMEDIATE,	MCI_STATUS_CMD_INT_MASK	, 1},#define SEND_OP_COND 			1	{	MCI_CMD41_SEND_OP_COND_SD,	apMCI_CMDRESP_SHORT,	apMCI_CMD_TIMEOUT,	MCI_CMDOPT_IMMEDIATE|MCI_CMDOPT_IGNORE_CRC,	MCI_STATUS_CMD_INT_MASK&(~MCI_STATUS_CMDCRCFAIL), 1 },#define ALL_SEND_CID 			2	{	MCI_CMD2_ALL_SEND_CID,		apMCI_CMDRESP_LONG,	apMCI_CMD_TIMEOUT,	MCI_CMDOPT_IMMEDIATE|MCI_CMDOPT_IGNORE_CRC,	MCI_STATUS_CMD_INT_MASK&(~MCI_STATUS_CMDCRCFAIL), 1	},#define SET_RELATIVE_ADDR 		3	{	MCI_CMD3_SET_RELATIVE_ADDR,	apMCI_CMDRESP_SHORT,	apMCI_CMD_TIMEOUT,	MCI_CMDOPT_IMMEDIATE,	MCI_STATUS_CMD_INT_MASK	, 1},#define SET_BUS_WIDTH			4	{	MCI_CMD6_SET_BUS_WIDTH,		apMCI_CMDRESP_SHORT,	apMCI_CMD_TIMEOUT,	MCI_CMDOPT_IMMEDIATE,	MCI_STATUS_CMD_INT_MASK	, 1},#define SELECT_CARD 			5	{	MCI_CMD7_SELECT_CARD,		apMCI_CMDRESP_SHORT,	apMCI_CMD_TIMEOUT,	MCI_CMDOPT_IMMEDIATE,	MCI_STATUS_CMD_INT_MASK, 1	},#define SEND_CSD 			6	{	MCI_CMD9_SEND_CSD,		apMCI_CMDRESP_LONG,	apMCI_CMD_TIMEOUT,	MCI_CMDOPT_IMMEDIATE,	MCI_STATUS_CMD_INT_MASK, 1	},#define SEND_CID 			7	{	MCI_CMD10_SEND_CID,		apMCI_CMDRESP_LONG,	apMCI_CMD_TIMEOUT,	MCI_CMDOPT_IMMEDIATE,	MCI_STATUS_CMD_INT_MASK, 1	},#define READ_DAT_UNTIL_STOP		8		{	MCI_CMD11_READ_DAT_UNTIL_STOP,	apMCI_CMDRESP_SHORT,	apMCI_CMD_TIMEOUT,	MCI_CMDOPT_IMMEDIATE,	MCI_STATUS_CMD_INT_MASK, 1	},#define STOP_TRANSMISSION 		9	{	MCI_CMD12_STOP_TRANSMISSION,	apMCI_CMDRESP_SHORT,	apMCI_CMD_TIMEOUT,	MCI_CMDOPT_IMMEDIATE|MCI_CMDOPT_IGNORE_TIMEOUT,	MCI_STATUS_CMD_INT_MASK&(~MCI_STATUS_CMDTIMEOUT), 1	},#define SEND_STATUS 			10	{	MCI_CMD13_SEND_STATUS,		apMCI_CMDRESP_SHORT,	apMCI_CMD_TIMEOUT,	MCI_CMDOPT_IMMEDIATE,	MCI_STATUS_CMD_INT_MASK	, 1},#define SET_BLOCKLEN 			11	{	MCI_CMD16_SET_BLOCKLEN,		apMCI_CMDRESP_SHORT,	apMCI_CMD_TIMEOUT,	MCI_CMDOPT_IMMEDIATE,	MCI_STATUS_CMD_INT_MASK	, 1},#define READ_SINGLE_BLOCK 		12	{	MCI_CMD17_READ_SINGLE_BLOCK,	apMCI_CMDRESP_SHORT,	apMCI_CMD_TIMEOUT,	MCI_CMDOPT_IMMEDIATE,	MCI_STATUS_CMD_INT_MASK	, 1},#define READ_MULTIPLE_BLOCK		13		{	MCI_CMD18_READ_MULTIPLE_BLOCK,	apMCI_CMDRESP_SHORT,	apMCI_CMD_TIMEOUT,	MCI_CMDOPT_IMMEDIATE,	MCI_STATUS_CMD_INT_MASK	, 1},#define WRITE_DAT_UNTIL_STOP		14 		{	MCI_CMD20_WRITE_DAT_UNTIL_STOP,	apMCI_CMDRESP_SHORT,	apMCI_CMD_TIMEOUT,	MCI_CMDOPT_IMMEDIATE,	MCI_STATUS_CMD_INT_MASK	, 1},#define WRITE_BLOCK 			15	{	MCI_CMD24_WRITE_BLOCK,		apMCI_CMDRESP_SHORT,	apMCI_CMD_TIMEOUT,	MCI_CMDOPT_IMMEDIATE,	MCI_STATUS_CMD_INT_MASK	, 1},#define WRITE_MULTIPLE_BLOCK		16	{	MCI_CMD25_WRITE_MULTIPLE_BLOCK,	apMCI_CMDRESP_SHORT,	apMCI_CMD_TIMEOUT,	MCI_CMDOPT_IMMEDIATE,	MCI_STATUS_CMD_INT_MASK	, 1},#define APP_CMD				17	{	MCI_CMD55_APP_CMD,		apMCI_CMDRESP_SHORT,	apMCI_CMD_TIMEOUT, MCI_CMDOPT_IMMEDIATE, MCI_STATUS_CMD_INT_MASK, 1},};typedef enum CARD_STAT{	ST_IDLE = 0x0,	ST_READY,	ST_IDENT,	ST_STBY,	ST_TRAN,	ST_DATA,	ST_RCV,	ST_PRG,	ST_DIS,	ST_RESERVD}MCI_CARD_STAT;// Card internal state//------------------------------------------------------------------------------//// Functions ////------------------------------------------------------------------------------#ifdef __cplusplusextern "C"{#endif// Functions in SD_INFO.C		/*int SDI_GetDeviceInfo(	LPWSTR ActivePath, 	PSTORAGEDEVICEINFO pInfo	);int SDI_GetFolderName(	LPWSTR ActivePath, 	LPWSTR FolderName, 	unsigned long cBytes, 	unsigned long* pcBytes	);HKEY SDI_OpenDriverKey(	LPTSTR ActiveKey	);*/// Functions in SD_DISK.CSD_controller* SDI_InitInterface(	SD_controller* controller, 	unsigned long* errorcode	);int SDI_StartUpCard(	SD_controller* controller, 	unsigned long* errorcode	);int SDI_ReStartUpCard(	SD_controller* controller, 	unsigned long* errorcode	);int SDI_ResetInterface(	SD_controller* controller, 	unsigned long* errorcode	);int SDI_DeinitInterface(	SD_controller*, 	unsigned long* errorcode	);int SDI_SendCmd(	SD_controller*controller, 	const Command_Parameter*param, 	unsigned long arg, 	apMCI_sResponse* response, 	unsigned long* errorcode	);unsigned long SDI_PrvLongResponseDecode(	apMCI_sResponse* pLongResponse, 	unsigned long LowestBit, 	unsigned long BitWidth	);int SDI_GetCID(	SD_controller* controller, 	apMCI_sDecodedCID* pDecodedResponse, 	unsigned long* errorcode	);int SDI_GetCSD(	SD_controller* controller, 	apMCI_sDecodedCSD* pDecodedResponse, 	unsigned long RCA,	unsigned long* errorcode	);// Functions in SD_DATA.Cint SDI_BatchRead_DMA(	SD_controller* controller, 	unsigned long SectorNum, 	unsigned long SectorCnt, 	unsigned char* buffer, 	unsigned long* errorcode	);int SDI_BatchWrite_DMA(	SD_controller* controller, 	unsigned long SectorNum, 	unsigned long SectorCnt, 	unsigned char* buffer, 	unsigned long* errorcode	);int SDI_SafeRead(	SD_controller*controller, 	unsigned long SectorNum, 	unsigned long SectorCnt, 	unsigned char* buffer, 	unsigned long* errorcode	);int SDI_SafeWrite(	SD_controller*controller, 	unsigned long SectorNum, 	unsigned long SectorCnt, 	unsigned char* buffer, 	unsigned long* errorcode	);int SDI_BlockRead(	SD_controller* controller, 	unsigned long SectorNum, 	unsigned long SectorCnt, 	unsigned char* buffer, 	unsigned long* errorcode	);int SDI_BlockWrite(	SD_controller* controller, 	unsigned long SectorNum, 	unsigned long SectorCnt, 	unsigned char* buffer, 	unsigned long* errorcode	);// Functions in SD_PAP.Cvoid SDI_DetectInsert(void);void SDI_DetectRemove(void);unsigned long SDI_DetectStatus(	void * controller	);int SDI_IsCardIn(	SD_controller* controller, 	unsigned long * errorcode	);// Functions in SD_DMA.Cint SDI_AllocateDMA(void);int SDI_InitDMA(	unsigned long Opcode	);int SDI_StartDMA(	unsigned long Opcode, 	unsigned long FIFOAddr, 	unsigned char* buf,	unsigned long size	);int SDI_WaitDMA(	unsigned long Opcode, 	unsigned long FIFOAddr, 	unsigned char* buf,	unsigned long size	);int SDI_ReleaseDMA(void);int sd_request_dma(void);#ifdef __cplusplus	}#endif#endif

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -