📄 datatype.h
字号:
#ifndef __DATA_TYPE_H
#define __DATA_TYPE_H
#define NULL 0
#define STATUS_ERR 1
#define STATUS_OK 0
#define TRUE 1
#define FALSE 0
typedef void (* PrVoid)(void);
typedef PrVoid (*PrPrVoid)(void);
/***********************************************************/
//
/***********************************************************/
#define ENTER_KEY 0x0d
#define BACK_KEY 0x08
#define ESC_KEY 0x1b
#define MAX_CMD_LEN 128
#define MAX_ARGS MAX_CMD_LEN/4
/*********************************************************************************/
//
/*********************************************************************************/
//typedef unsigned char U8;
//typedef unsigned short U16;
//typedef unsigned int U32;
//typedef signed char S8;
//typedef signed short S16;
//typedef signed int S32;
#ifndef U8
#define U8 unsigned char
#endif
#ifndef U16
#define U16 unsigned short
#endif
#ifndef U32
#define U32 unsigned int
#endif
#ifndef S8
#define S8 signed char
#endif
#ifndef S16
#define S16 short int
#endif
#ifndef S32
#define S32 int
#endif
typedef unsigned char BYTE;
typedef unsigned short WORD;
typedef unsigned int DWORD;
/*********************************************************************************/
/*********************************************************************************/
typedef struct{
U16 year;
U8 month;
U8 day;
U8 weekday;
U8 hour;
U8 min;
U8 sec;
}TIME_STRUC;
/*********************************************************************************/
//
/*********************************************************************************/
typedef struct _TJH_FLAGS
{
U8 bTimeout;
U8 UDiskOK;
U8 SLAVE_ONLINE;
U8 TIMEOUT_ERR;
U8 DATA_STOP;
U8 bData1;
U8 bIsFat32;
///////////////////////////////////////////
U8 bMassDevice;
U8 bFatChanged;
} TJHFLAGS;
/*********************************************************************************/
// USB Device Definition
/*********************************************************************************/
#define MAX_EP 0x05 // maximum number of endpoints (Ep0 + max of 4 data endpoints)
typedef struct
{
U16 wVID, wPID;
U8 bClass; //
U8 bNumOfEPs;
U8 iMfg;
U8 iPdt;
U8 bId1;
U8 bId2;
U8 bEPAddr[MAX_EP];
U8 bAttr[MAX_EP];
U16 wPayLoad[MAX_EP];
U16 bInterval[MAX_EP];
U8 bData1[MAX_EP];
} pUSBDEV, *PUSBDEV;
// USB specific request
typedef struct
{
U8 bmRequest;
U8 bRequest;
U16 wValue;
U16 wIndex;
U16 wLength;
} SetupPKG, *pSetupPKG;
typedef struct
{
U8 usbaddr;
U8 endpoint;
U8 pid;
U8 wPayload;
U16 wLen;
U8 *buffer;
SetupPKG setup;
U8 epbulkin;
U8 epbulkout;
} TJHPKG, *pTJHPKG;
// Standard Device Descriptor
typedef struct
{ U8 bLength;
U8 bDescriptorType;
U16 bcdUSB;
U8 bDeviceClass;
U8 bDeviceSubClass;
U8 bDeviceProtocol;
U8 bMaxPacketSize0;
U16 idVendor;
U16 idProduct;
U16 bcdDevice;
U8 iManufacturer;
U8 iProduct;
U8 iSerialNumber;
U8 bNumConfigurations;
} sDevDesc, *pDevDesc;
// Standard Configuration Descriptor
typedef struct
{
U8 bLength;
U8 bType;
U16 wLength;
U8 bNumIntf;
U8 bCV;
U8 bIndex;
U8 bAttr;
U8 bMaxPower;
} sCfgDesc, *pCfgDesc;
// Standard Interface Descriptor
typedef struct
{ U8 bLength;
U8 bType;
U8 iNum;
U8 iAltString;
U8 bEndPoints;
U8 iClass;
U8 iSub;
U8 iProto;
U8 iIndex;
} sIntfDesc, *pIntfDesc;
// Standard EndPoint Descriptor
typedef struct
{ U8 bLength;
U8 bType;
U8 bEPAdd;
U8 bAttr;
U16 wPayLoad;
U8 bInterval;
} sEPDesc, *pEPDesc;
// Standard String Descriptor
typedef struct
{ U8 bLength;
U8 bType;
U16 wLang;
} sStrDesc, *pStrDesc;
/*********************************************************************************/
//
/*********************************************************************************/
#define RBC_CMD_FORMAT 0x04
#define RBC_CMD_READ10 0x28
#define RBC_CMD_READCAPACITY 0x25
#define RBC_CMD_STARTSTOPUNIT 0x1B
#define RBC_CMD_SYNCCACHE 0x35
#define RBC_CMD_VERIFY10 0x2F
#define RBC_CMD_WRITE10 0x2A
#define SPC_CMD_INQUIRY 0x12
#define SPC_CMD_MODESELECT6 0x15
#define SPC_CMD_MODESENSE6 0x1A
#define SPC_CMD_PERSISTANTRESERVIN 0x5E
#define SPC_CMD_PERSISTANTRESERVOUT 0x5F
#define SPC_CMD_PRVENTALLOWMEDIUMREMOVAL 0x1E
#define SPC_CMD_RELEASE6 0x17
#define SPC_CMD_REQUESTSENSE 0x03
#define SPC_CMD_RESERVE6 0x16
#define SPC_CMD_TESTUNITREADY 0x00
#define SPC_CMD_WRITEBUFFER 0x3B
#define SPC_CMD_READLONG 0x23
// Generic
typedef struct _GENERIC_CDB {
U8 OperationCode;
U8 Reserved[15];
} GENERIC_CDB,*PGENERIC_CDB;
typedef struct _GENERIC_RBC {
U8 OperationCode;
U8 Reserved[8];
U8 Control;
} GENERIC_RBC,*PGENERIC_RBC;
// Read Command
typedef struct _READ_RBC {
//U8 OperationCode; /* 10H */
U8 VendorSpecific;
U8 LBA_3;
U8 LBA_2;
U8 LBA_1;
U8 LBA_0;
U8 Reserved;
U16 XferLength;
U8 Control;
} READ_RBC, *PREAD_RBC;
// Read Capacity Data - returned in Big Endian format
typedef struct _READ_CAPACITY_DATA {
U8 LBA_3;
U8 LBA_2;
U8 LBA_1;
U8 LBA_0;
U8 BlockLen_3;
U8 BlockLen_2;
U8 BlockLen_1;
U8 BlockLen_0;
} READ_CAPACITY_DATA, *PREAD_CAPACITY_DATA;
//////////////////////////////////////////////////
// Read Capacity command
typedef struct _READ_CAPACITY_RBC {
//U8 OperationCode; // 10H /
union {
//FLEXI_INT32 l0[2];
U32 l[2];
READ_CAPACITY_DATA CapData; /* Reserved area, here is used as temp*/
} tmpVar;
U8 Control;
} READ_CAPACITY_RBC, *PREAD_CAPACITY_RBC;
typedef struct _READ_CAPACITY_RSP {
U32 LastLBA;
U32 BlockSize;
} READ_CAPACITY_RSP, *PREAD_CAPACITY_RSP;
// Write Command
typedef struct _WRITE_RBC {
U8 VendorSpecific;
U8 LBA_3;
U8 LBA_2;
U8 LBA_1;
U8 LBA_0;
U8 Reserved2;
U16 XferLength;
U8 Control;
} WRITE_RBC, *PWRITE_RBC;
// VERIFY Command
typedef struct _VERIFY_RBC {
U8 OperationCode; /* 2FH */
U8 Reserved0;
U8 LBA_3; /* Big Endian */
U8 LBA_2;
U8 LBA_1;
U8 LBA_0;
U8 Reserved1;
U8 VerifyLength_1; /* Big Endian */
U8 VerifyLength_0;
U8 Control;
} VERIFY_RBC, *PVERIFY_RBC;
// INQUIRY Command
typedef struct _INQUIRY_SPC {
U8 Reserved0;
U8 PageCode;
U8 Reserved1;
U8 AllocationLen;
U8 Control;
} INQUIRY_SPC, *PINQUIRY_SPC;
typedef struct _BPB_BLOCK {
U8 BS_jmpBoo[3];
U8 BS_OEMName[8];
U16 BPB_BytesPerSec; // bytes number of every sector
U8 BPB_SecPerClus; // sector per clus FAT16:2; FAT32:1
U16 BPB_RsvdSecCn;
U8 BPB_NumFATs;
U16 BPB_RootEntCnt;
U16 BPB_TotSec16;
U8 BPB_Media;
U16 BPB_FATSz16;
U16 BPB_SecPerTrk;
U16 BPB_NumHeads;
U32 BPB_HiddSec;
U32 BPB_TotSec32;
union{
struct{
U8 BS_DrvNum; // offset: 36
U8 BS_Reserved1;
U8 BS_BootSig;
U8 BS_VolID[4];
U8 BS_VolLab[11];
U8 BS_FilSysType[8]; // offset: 54
}fat16; // length:26
struct{
U32 BPB_FATSz32;
U16 BPB_ExtFlags;
U16 BPB_FSVer;
U32 BPB_RootClus;
U16 BPB_FSInfo;
U16 BPB_BkBootSec;
U8 res[12];
U8 BS_DrvNum;
U8 res1;
U8 BS_BootSig;
U8 BS_VoilD[4];
U8 BS_VoilLab[11];
U8 BS_FilSysType[8];
}fat32;
}fat16_32;
U8 ExecutableCode[410];
U8 Marker[2];
} BPB_BLOCK,* PBPB_BLOCK;
/**********************************
the attributes of Diretory and File
*********************************/
#define ATTR_READ_ONLY 0x01
#define ATTR_HIDDEN 0x02
#define ATTR_SYSTEM 0x04
#define ATTR_VOLUME_ID 0x08
#define ATTR_DIRECTORY 0x10
#define ATTR_ARCHIVE 0x20
#define ATTR_LONG_NAME 0x0f
/****************
****************/
typedef struct _SYS_INFO_BLOCK{
U16 BPB_BytesPerSec;
U8 BPB_SecPerClus;
U16 BPB_RootEntCnt;
U32 FATSz;
U32 FatStartSector;
U32 RootStartSector;
U32 RootClusterNum;
U32 FSI_Free_Count;
U32 FSI_Nxt_Free;
U32 FirstDataSector;
} SYS_INFO_BLOCK,* PSYS_INFO_BLOCK;
/*****************************
*** Directory information ***
******************************/
typedef struct{
U8 DIR_Name[11];
U8 DIR_Attr;
U8 DIR_NTRes;
U8 DIR_CrtTimeTenth;
U16 DIR_CrtTime;
U16 DIR_CrtDate;
U16 DIR_LstAccDate;
U16 DIR_FstClusHI;
U16 DIR_WrtTime;
U16 DIR_WrtDate;
U16 DIR_FstClusLO;
U32 DIR_FileSize;
}DIR_STRUC, * PDIR_STRUC;
typedef struct _FILE_INFO{
U8 bFileOpen;
U32 StartCluster;
U32 LengthInByte;
U32 ClusterPointer;
U32 SectorPointer;
U16 OffsetofSector;
U8 SectorofCluster;
U32 pointer;
U32 FatSectorPointer;
U8 FileName[11];
} FILE_INFO, * PFILE_INFO;
#define MAXDIRDEPTH 10
typedef struct _DIR_INFO{
U32 Link[MAXDIRDEPTH];
U32 StartSector;
U32 StartCluster;
U32 ParentStartCluster;
U8 DepthIndex;
U8 bRootDir;
} DIR_INFO,* PDIR_INFO;
typedef struct _FSINFO_BLOCK{
U8 res1[488];
U32 FSI_Free_Count;
U32 FSI_Nxt_Free;
}FSINFO_BLOCK, *PFSINFO_BLOCK;
// prevent/allow medium removal
typedef struct _MEDIA_REMOVAL_SPC {
//U8 OperationCode; // 1EH /
U8 Reserved0[3];
U8 Prevent;
} MEDIA_REMOVAL_SPC, *PMEDIA_REMOVAL_SPC;
// Request Sense
typedef struct _REQUEST_SENSE_SPC {
//U8 OperationCode; // 03H /
U8 Reserved[3];
U8 AllocationLen;
U8 Control;
} REQUEST_SENSE_SPC, *PREQUEST_SENSE_SPC;
// Test Unit Ready
typedef struct _TEST_UNIT_SPC {
//U8 OperationCode; /* 00H */
U8 Reserved[4];
U8 Control;
} TEST_UNIT_SPC, *PTEST_UNIT_SPC;
typedef union _CDB_RBC {
GENERIC_CDB Cdb_Generic;
// RBC commands
GENERIC_RBC RbcCdb_Generic;
//FORMAT_RBC RbcCdb_Format;
READ_RBC RbcCdb_Read;
READ_CAPACITY_RBC RbcCdb_ReadCapacity;
VERIFY_RBC RbcCdb_Verify;
WRITE_RBC RbcCdb_Write;
// SPC-2 commands
INQUIRY_SPC SpcCdb_Inquiry;
MEDIA_REMOVAL_SPC SpcCdb_Remove;
REQUEST_SENSE_SPC SpcCdb_RequestSense;
TEST_UNIT_SPC SpcCdb_TestUnit;
// ATAPI Commands
} CDB_RBC, *PCDB_RBC;
/*********************************************************************************/
//
/*********************************************************************************/
///////////////////////////////////
#define CBW_SIGNATURE 0x43425355
#define CSW_SIGNATURE 0x53425355
typedef struct _COMMAND_BLOCK_WRAPPER{
U32 dCBW_Signature;
U32 dCBW_Tag;
U32 dCBW_DataXferLen;
U8 bCBW_Flag;
U8 bCBW_LUN;
U8 bCBW_CDBLen;
U8 OperationCode;
CDB_RBC cdbRBC;
} CBW, *PCBW;
typedef struct _COMMAND_STATUS_WRAPPER{
U32 dCSW_Signature;
U32 dCSW_Tag;
U32 dCSW_DataResidue;
U8 bCSW_Status;
} CSW, *PCSW;
typedef union _TPBULK_STRUC {
CBW TPBulk_CommandBlock;
CSW TPBulk_CommandStatus;
}TPBLK_STRUC, * PTPBLK_STRUC;
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -