📄 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 <platform.h> // hardware information of arm 926 board
#include <windows.h>
#include <ceddk.h>
#include <types.h>
#include <excpt.h>
#include <tchar.h>
#include <devload.h>
#include <diskio.h>
#include <storemgr.h>
#include <pkfuncs.h>
#include <dma.h>
#include "OalIntr.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
#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
#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
// Card internal state
#define ST_TRAN 0x04 // State - Tran
// 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
{
DWORD sd_POWER ;
DWORD sd_CLOCK ;
DWORD sd_ARGUMENT ;
DWORD sd_COMMAND ;
DWORD sd_RESPCMD ;
DWORD sd_RESP0 ;
DWORD sd_RESP1 ;
DWORD sd_RESP2 ;
DWORD sd_RESP3 ;
DWORD sd_DATATMR ;
DWORD sd_DATALEN ;
DWORD sd_DATACTRL ;
DWORD sd_DATACNT ;
DWORD sd_STATUS ;
DWORD sd_CLEAR ;
DWORD sd_MASK0 ;
DWORD sd_MASK1 ;
DWORD sd_SELECT ;
DWORD sd_FIFOCNT ;
DWORD RESERVED[0x0D];
DWORD 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 struct
{
volatile int* SysDetect;
SD_REG* Registers;
HANDLE InterruptEvent;
apMCI_sDecodedCSD CardCSD;
apMCI_sDecodedCID CardCID;
BOOL ifDMA;
}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},
};
//------------------------------------------------------------------------------
//
// Functions
//
//------------------------------------------------------------------------------
#ifdef __cplusplus
extern "C"
{
#endif
// Functions in SD_INFO.C
BOOL
SDI_GetDeviceInfo(
LPWSTR ActivePath,
PSTORAGEDEVICEINFO pInfo
);
BOOL
SDI_GetFolderName(
LPWSTR ActivePath,
LPWSTR FolderName,
unsigned long cBytes,
unsigned long* pcBytes
);
HKEY
SDI_OpenDriverKey(
LPTSTR ActiveKey
);
// Functions in SD_DISK.C
SD_controller*
SDI_InitInterface(
SD_controller* controller,
unsigned long* errorcode
);
BOOL
SDI_StartUpCard(
SD_controller* controller,
unsigned long* errorcode
);
BOOL
SDI_ReStartUpCard(
SD_controller* controller,
unsigned long* errorcode
);
BOOL
SDI_ResetInterface(
SD_controller* controller,
unsigned long* errorcode
);
BOOL
SDI_DeinitInterface(
SD_controller*,
unsigned long* errorcode
);
BOOL
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
);
BOOL
SDI_GetCID(
SD_controller* controller,
apMCI_sDecodedCID* pDecodedResponse,
unsigned long* errorcode
);
BOOL
SDI_GetCSD(
SD_controller* controller,
apMCI_sDecodedCSD* pDecodedResponse,
unsigned long RCA,
unsigned long* errorcode
);
// Functions in SD_DATA.C
BOOL
SDI_BatchRead_DMA(
SD_controller* controller,
unsigned long SectorNum,
unsigned long SectorCnt,
unsigned char* buffer,
unsigned long* errorcode
);
BOOL
SDI_BatchWrite_DMA(
SD_controller* controller,
unsigned long SectorNum,
unsigned long SectorCnt,
unsigned char* buffer,
unsigned long* errorcode
);
BOOL
SDI_SafeRead(
SD_controller*controller,
unsigned long SectorNum,
unsigned long SectorCnt,
unsigned char* buffer,
unsigned long* errorcode
);
BOOL
SDI_SafeWrite(
SD_controller*controller,
unsigned long SectorNum,
unsigned long SectorCnt,
unsigned char* buffer,
unsigned long* errorcode
);
BOOL
SDI_BlockRead(
SD_controller* controller,
unsigned long SectorNum,
unsigned long SectorCnt,
unsigned char* buffer,
unsigned long* errorcode
);
BOOL
SDI_BlockWrite(
SD_controller* controller,
unsigned long SectorNum,
unsigned long SectorCnt,
unsigned char* buffer,
unsigned long* errorcode
);
// Functions in SD_PAP.C
void
SDI_DetectInsert(void);
void
SDI_DetectRemove(void);
unsigned long
WINAPI SDI_DetectStatus(
LPVOID controller
);
BOOL
SDI_IsCardIn(
SD_controller* controller,
DWORD* errorcode
);
// Functions in SD_DMA.C
BOOL
SDI_AllocateDMA(void);
BOOL
SDI_InitDMA(
unsigned long Opcode
);
BOOL
SDI_StartDMA(
unsigned long Opcode,
unsigned long FIFOAddr,
unsigned char* buf,
unsigned long size
);
BOOL
SDI_WaitDMA(
unsigned long Opcode,
unsigned long FIFOAddr,
unsigned char* buf,
unsigned long size
);
BOOL
SDI_ReleaseDMA(void);
#ifdef __cplusplus
}
#endif
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -