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

📄 cardmng.h

📁 好记星的控件,包括button,list,对文件操作
💻 H
字号:
/****************************************************************************/
/*                                                                          */
/*              Copyright (C) 2004 SHENZHEN MEIJIN CO.LTD                   */
/*                                                                          */
/* FILE NAME:   CardMng.H                                                   */
/* MODULE NAME: CARD MANAGER MODAL                                          */
/*                                                                          */
/****************************************************************************/
/*    DATE       AUTHOR       VERSION                   REMARKS             */
/* =========== ===========  =========  =====================================*/
/* 2004-07-30     Victor    Ver 1.00                                        */
/****************************************************************************/

#ifndef __CARDMNG_H__
#define __CARDMNG_H__


// timing valuees
#define INITIAL_TIMEOUT     5       //100 ,victor 
#define MIN_NCS     1           //0
#define MAX_NCS     -
#define MIN_NCR     1
#define MAX_NCR     8
#define MIN_NCX     0
#define MAX_NCX     8
#define MIN_NRC     1
#define MAX_NRC     -
#define MIN_NAC     1
#define MAX_NAC     spec. in the CSD
#define MIN_NWR     1
#define MAX_NWR     -
#define MIN_NEC     1           //0
#define MAX_NEC     -
#define MIN_NDS     0
#define MAX_NDS     -
#define MIN_NBR     1
#define MAX_NBR     1

// voltage range
#define MASTER_VDD_WIN  0x00300000      // 3.2V - 3.4V

// response format
#define R1_FORMAT              0
#define R1B_FORMAT             1
#define R2_FORMAT              2
#define R3_FORMAT              3
#define RDATA_FORMAT           4

// data token type
#define SINGLE_READ_START       0xfe
#define MULTIPLE_READ_START     0xfe
#define SINGLE_WRITE_START      0xfe
#define MULTIPLE_WRITE_START    0xfc
#define MULTIPLE_WRITE_STOP     0xfd

typedef struct tagCID
{
    UINT8   mid;                // Manufacturer ID
    UINT8   oid0;               // OEM/Application ID
    UINT8   oid1;               // OEM/Application ID
    UINT8   pnm[6];             // Product name
    UINT8   prv;                // Product revision
    UINT8   psn[4];             // Product serial number
    UINT8   mdt;                // Manufacturing date
    UINT8   crc;                // CRC7 checksum & '1'
    UINT16  dataCRC;            // data read CRC
}REG_CID;

typedef struct tagCardPartition
{
    UINT8   state;
    UINT8   beginHead;
    UINT8   beginSector;
    UINT16  beginCylinder;
    UINT8   type;
    UINT8   endHead;
    UINT8   endSector;
    UINT16  endCylinder;
    UINT32  firstSector;
    UINT32  totalSector;
}CARD_PARTITION;    

typedef struct tagCSD
{
    UINT8   CSD_STRUCTURE;                                        // CSD structure[127:126]
    UINT8   SPEC_VERS;                                            // System specification version[125:122]
    UINT8   TAAC;                                                 // data read access-time-1[119:112]
    UINT8   NSAC;                                                 // data read access-time-2 in CLK cycles(NSAC*100)[111:104]
    UINT8   TRAN_SPEED;                                           // max. data transfer rate[103:96]
    UINT16  CCC;                                                  // card command classes[95:84]
    UINT8   READ_BL_LEN;                                          // max. read data block length[83:80]
    UINT8   READ_BL_PARTIAL;                                      // partial blocks for read allowed[79:79]
    UINT8   WRITE_BLK_MISALIGN;                                   // write block misalignment[78:78]
    UINT8   READ_BLK_MISALIGN;                                    // read block misalignment[77:77]
    UINT8   DSR_IMP;                                              // DSR implemented[76:76]
    UINT16  C_SIZE;                                               // device size[73:62]
    UINT8   VDD_R_CURR_MIN;                                       // max. read current @VDD min[61:59]
    UINT8   VDD_R_CURR_MAX;                                       // max. read current @VDD max[58:56]
    UINT8   VDD_W_CURR_MIN;                                       // max. write current @VDD min[55:53]
    UINT8   VDD_W_CURR_MAX;                                       // max. write current @VDD max[52:50]
    UINT8   C_SIZE_MULT;                                          // device size multiplier[49:47]
    UINT8   ERASE_GRP_SIZE;                                       // erase group size[46:42]
    UINT8   ERASE_GRP_MULT;                                       // erase group size multiplier[41:37]
    UINT8   WP_GRP_SIZE;                                          // write protect group size[36:32]
    UINT8   WP_GRP_ENABLE;                                        // write protect group enable[31:31]
    UINT8   DEFAULT_ECC;                                          // manufacturer default ECC[30:29]
    UINT8   R2W_FACTOR;                                           // write speed factor[28:26]
    UINT8   WRITE_BL_LEN;                                         // max. write data block length[25:22]
    UINT8   WRTIT_BL_PARTIAL;                                     // partial blocks for write allowed[21:21]
    UINT8   FILE_FORMAT_GRP;                                      // File format group[15:15]
    UINT8   COPY;                                                 // copy flag(OTP)[14:14]
    UINT8   PERM_WRITE_PROTECT;                                   // permanent write protection[13:13]
    UINT8   TMP_WRITE_PROTECT;                                    // temporary write protection[12:12]
    UINT8   FILE_FORMAT;                                          // file format[11:10]
    UINT8   ECC;                                                  // ECC code[9:8]
    UINT8   CRC;                                                  // CRC7[7:1]
}REG_CSD;

#define OID(a)              (((UINT16)(a.oid0))<<8 + a.oid1)    // OEM/Application ID

#define CSD_STRUCTURE(a)    (a[0]>>6&0x03)                      // CSD structure[127:126]
#define SPEC_VERS(a)        (a[0]>>2&0x0f)                      // System specification version[125:122]
#define TAAC(a)             (a[1])                              // data read access-time-1[119:112]
#define NSAC(a)             (a[2])                              // data read access-time-2 in CLK cycles(NSAC*100)[111:104]
#define TRAN_SPEED(a)       (a[3])                              // max. data transfer rate[103:96]
#define CCC(a)              ((((UINT16)(a[4])<<8) + a[5])>>4)   // card command classes[95:84]
#define READ_BL_LEN(a)      (a[5]&0x0f)                         // max. read data block length[83:80]
#define READ_BL_PARTIAL(a)  (a[6]>>7)                           // partial blocks for read allowed[79:79]
#define WRITE_BLK_MISALIGN(a)((a[6]>>6)&0x01)                   // write block misalignment[78:78]
#define READ_BLK_MISALIGN(a)((a[6]>>5)&0x01)                    // read block misalignment[77:77]
#define DSR_IMP(a)          ((a[6]>>4)&0x01)                    // DSR implemented[76:76]
#define C_SIZE(a)           ((((UINT16)(a[6])<<10) + ((UINT16)(a[7])<<2) + (a[8]>>6))&0x0fff) // device size[73:62]
#define VDD_R_CURR_MIN(a)   ((a[8]>>3)&0x07)                    // max. read current @VDD min[61:59]
#define VDD_R_CURR_MAX(a)   (a[8]&0x07)                         // max. read current @VDD max[58:56]
#define VDD_W_CURR_MIN(a)   ((a[9]>>5)&0x07)                    // max. write current @VDD min[55:53]
#define VDD_W_CURR_MAX(a)   ((a[9]>>2)&0x07)                    // max. write current @VDD max[52:50]
#define C_SIZE_MULT(a)      (((a[9]<<1)&0x06)+((a[10]>>7)&0x01))// device size multiplier[49:47]
#define ERASE_GRP_SIZE(a)   ((a[10]>>2)&0x1f)                   // erase group size[46:42]
#define ERASE_GRP_MULT(a)   (((a[10]&0x03)<<3)+((a[11]>>5)&0x07)) // erase group size multiplier[41:37]
#define WP_GRP_SIZE(a)      (a[11]&0x1f)                        // write protect group size[36:32]
#define WP_GRP_ENABLE(a)    (a[12]>>7)                          // write protect group enable[31:31]
#define DEFAULT_ECC(a)      ((a[12]>>5)&0x03)                   // manufacturer default ECC[30:29]
#define R2W_FACTOR(a)       ((a[12]>>2)&0x07)                   // write speed factor[28:26]
#define WRITE_BL_LEN(a)     (((a[12]&0x03)<<2)+((a[13]>>6)&0x03)) // max. write data block length[25:22]
#define WRTIT_BL_PARTIAL(a) ((a[13]>>5)&0x01)                   // partial blocks for write allowed[21:21]
#define FILE_FORMAT_GRP(a)  ((a[14]>>7)&0x01)                   // File format group[15:15]
#define COPY(a)             ((a[14]>>6)&0x01)                   // copy flag(OTP)[14:14]
#define PERM_WRITE_PROTECT(a) ((a[14]>>5)&0x01)                 // permanent write protection[13:13]
#define TMP_WRITE_PROTECT(a) ((a[14]>>4)&0x01)                  // temporary write protection[12:12]
#define FILE_FORMAT(a)      ((a[14]>>2)&0x03)                   // file format[11:10]
#define ECC(a)              (a[14]&0x03)                        // ECC code[9:8]
#define CRC(a)              (a[15])                             // CRC7[7:1]

// error code
#define CARD_ERR_NO         0       //OK
#define CARD_ERR_TIMEOUT    -1      //time out
#define CARD_ERR_CMDILLEGAL -2      //command is illegal
#define CARD_ERR_BUSY       -3      //card is busy
#define CARD_ERR_VOLTAGE    -4      //card has incompatible voltage range
#define CARD_ERR_LOCKED     -5      //card be locked
#define CARD_ERR_WRITE      -6      //error due to CRC or write error
#define CARD_ERR_INEXISTENT -7      //card is not existent
#define CARD_ERR_FORMAT     -8      //file format is not supported
#define CARD_ERR_CRC        -9      //crc7 correct error

INT CardOpen(UINT16 driveno);
INT CardRawOpen(UINT16 driveno);
INT CardClose(UINT16 driveno);
INT CardIo(UINT16 driveno, UINT32 dwLogicalPage, VOID *buffer, UINT16 uPages, INT do_read);
INT CardIoCtrl(UINT16 driveno, UINT16 command, VOID *buffer);
INT CardCheck(UINT16 driveno);
BOOL CardSetupService(void);
BOOL IsCardExist(void);
BOOL IsCardLocked(void);

#endif  /* __CARDMNG_H__ */

⌨️ 快捷键说明

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