📄 fat32.lst
字号:
642 =2 typedef struct _TEST_UNIT_SPC {
643 =2 UINT8 OperationCode; // 00H
644 =2 UINT8 Reserved[4];
645 =2 UINT8 Control;
646 =2 } TEST_UNIT_SPC, *pTEST_UNIT_SPC;
647 =2
648 =2 /*
649 =2 // Write Buffer
650 =2 */
651 =2
652 =2 typedef struct _WRITE_BUFFER_SPC {
653 =2 UINT8 OperationCode;
654 =2 UINT8 Mod:4 ;
655 =2 UINT8 Reserved0:4 ;
656 =2 UINT8 BufferID;
657 =2 UINT8 BufferOff_2;
658 =2 UINT8 BufferOff_1;
659 =2 UINT8 BufferOff_0;
660 =2 UINT8 ParameterLen_2;
661 =2 UINT8 ParameterLen_1;
662 =2 UINT8 ParameterLen_0;
663 =2 UINT8 Control;
664 =2 } WRITE_BUFFER_SPC, *pWRITE_BUFFER_SPC;
665 =2
666 =2 typedef union _CDB_RBC {
667 =2 GENERIC_CDB Cdb_Generic;
668 =2
669 =2 // RBC commands
670 =2 GENERIC_RBC RbcCdb_Generic;
671 =2
672 =2 FORMAT_RBC RbcCdb_Format;
673 =2 READ_RBC RbcCdb_Read;
674 =2 READ_CAPACITY_RBC RbcCdb_ReadCapacity;
675 =2 START_STOP_RBC RbcCdb_OnOffUnit;
676 =2 SYNCHRONIZE_CACHE_RBC RbcCdb_SyncCache;
677 =2 VERIFY_RBC RbcCdb_Verify;
678 =2 WRITE_RBC RbcCdb_Write;
679 =2
680 =2
681 =2 // SPC-2 commands
682 =2
683 =2 INQUIRY_SPC SpcCdb_Inquiry;
684 =2 MODE_SELECT_SPC SpcCdb_ModeSelect;
685 =2 MODE_SENSE_SPC SpcCdb_ModeSense;
686 =2 MEDIA_REMOVAL_SPC SpcCdb_Remove;
687 =2 REQUEST_SENSE_SPC SpcCdb_RequestSense;
688 =2 TEST_UNIT_SPC SpcCdb_TestUnit;
689 =2 WRITE_BUFFER_SPC SpcCdb_WriteBuffer;
690 =2
691 =2 // ATAPI Commands
692 =2 READ_10 CmdRead10;
693 =2 WRITE_10 CmdWrite10;
694 =2 MODE_SELECT_10 CmdModeSel10;
695 =2 MODE_SENSE_10 CmdModeSen10;
696 =2 //////////////////////////////////////
697 =2 READ_LONG_CMD SpcCdb_ReadLong;
C51 COMPILER V8.02 FAT32 09/19/2006 15:01:23 PAGE 21
698 =2
699 =2 } CDB_RBC, *pCDB_RBC;
700 =2
701 =2
2 =1 ///////////////////////////////////
3 =1 #define CBW_SIGNATURE 0x55534243
4 =1 #define CSW_SIGNATURE 0x55534253
5 =1
6 =1 #define TPBulk_CBW TPBulk_Block.TPBulk_CommandBlock
7 =1 #define CBW_wXferLen TPBulk_CBW.dCBW_DataXferLen
8 =1 #define RBC_CDB TPBulk_CBW.cdbRBC
9 =1 #define RBC_LUN TPBulk_CBW.bCBW_LUN
10 =1 #define TPBulk_CSW TPBulk_Block.TPBulk_CommandStatus
11 =1
12 =1 typedef struct _COMMAND_BLOCK_WRAPPER{
13 =1 UINT32 dCBW_Signature;
14 =1 UINT32 dCBW_Tag;
15 =1 UINT32 dCBW_DataXferLen;
16 =1 UINT8 bCBW_Flag;
17 =1 UINT8 bCBW_LUN;
18 =1 UINT8 bCBW_CDBLen;
19 =1 CDB_RBC cdbRBC;
20 =1 } CBW, *pCBW;
21 =1
22 =1 typedef struct _COMMAND_STATUS_WRAPPER{
23 =1 UINT32 dCSW_Signature;
24 =1 UINT32 dCSW_Tag;
25 =1 UINT32 dCSW_DataResidue;
26 =1 UINT8 bCSW_Status;
27 =1 } CSW, *pCSW;
28 =1
29 =1 typedef union _TPBULK_STRUC {
30 =1 CBW TPBulk_CommandBlock;
31 =1 CSW TPBulk_CommandStatus;
32 =1
33 =1 }TPB_STRUC, *pTPB_STRUC;
34 =1 ///////////////////////////////////
35 =1 unsigned char EnumMassDev(void);
36 =1 unsigned char TPBulk_GetMaxLUN(void);
37 =1 unsigned char SPC_Inquiry(void);
38 =1 unsigned char SPC_READLONG(void);
39 =1 unsigned char SPC_RequestSense(void);
40 =1 unsigned char SPC_TestUnit(void);
41 =1 unsigned char SPC_LockMedia(void);
42 =1 unsigned char RBC_ReadCapacity(void);
43 =1 unsigned char RBC_ReadOneSec(unsigned long lba, unsigned char *pBuffer);
44 =1 unsigned char RBC_Write(unsigned long lba,unsigned char len,unsigned char *pBuffer);
45 =1
46 =1
7 #include "HAL.H"
1 =1 ///////////////////////////hal.h//////////////////////////
2 =1 #include "AT89X52.H"
1 =2 /*--------------------------------------------------------------------------
2 =2 AT89X52.H
3 =2
4 =2 Header file for the low voltage Flash Atmel AT89C52 and AT89LV52.
5 =2 Copyright (c) 1995-1996 Keil Software, Inc. All rights reserved.
6 =2 --------------------------------------------------------------------------*/
7 =2
8 =2 #ifndef AT89X52_HEADER_FILE
9 =2 #define AT89X52_HEADER_FILE 1
10 =2
C51 COMPILER V8.02 FAT32 09/19/2006 15:01:23 PAGE 22
11 =2 /*------------------------------------------------
12 =2 Byte Registers
13 =2 ----------------------
14 =2 Interrupt Vectors:
15 =2 Interrupt Address = (Number * 8) + 3
16 =2 ------------------------------------------------*/
17 =2 #define IE0_VECTOR 0 /* 0x03 External Interrupt 0 */
18 =2 #define TF0_VECTOR 1 /* 0x0B Timer 0 */
19 =2 #define IE1_VECTOR 2 /* 0x13 External Interrupt 1 */
20 =2 #define TF1_VECTOR 3 /* 0x1B Timer 1 */
21 =2 #define SIO_VECTOR 4 /* 0x23 Serial port */
22 =2
23 =2 #define TF2_VECTOR 5 /* 0x2B Timer 2 */
24 =2 #define EX2_VECTOR 5 /* 0x2B External Interrupt 2 */
25 =2
26 =2 /*------------------------------------------------
27 =2 ------------------------------------------------*/
28 =2 #endif
29 =2
30 =2
3 =1
4 =1 sbit MCU_LED1=P1^0;
5 =1 sbit MCU_LED2=P1^1;
6 =1 sbit MCU_LED3=P1^2;
7 =1 sbit MCU_LED4=P1^3;
8 =1
9 =1 sbit SWM1=P1^4;
10 =1 sbit SWM2=P1^5;
11 =1 sbit SWM3=P1^6;
12 =1 sbit SWM4=P1^7;
13 =1
14 =1
15 =1 sbit SL811_RST=P3^5;
16 =1 sbit SL811_CS=P3^4;
17 =1
18 =1 #define SL811_ADDR_PORT 0x08000
19 =1 #define SL811_DATA_PORT 0x08001
20 =1
21 =1
22 =1 unsigned char SL811Read(unsigned char a);
23 =1 void SL811Write(unsigned char a, unsigned char d);
24 =1 void SL811BufRead(unsigned char addr, unsigned char *s, unsigned char c);
25 =1 void SL811BufWrite(unsigned char addr, unsigned char *s, unsigned char c);
26 =1 unsigned short WordSwap(unsigned short input);
27 =1 void DelayMs(unsigned int nFactor);
28 =1 unsigned long SwapINT32(unsigned long dData);
29 =1 void ComSendByte(unsigned char c);
30 =1
31 =1 unsigned int LSwapINT16(unsigned short dData1,unsigned short dData2);
32 =1 unsigned long LSwapINT32(unsigned long dData1,unsigned long dData2,unsigned long dData3,unsigned long dDat
-a4);
33 =1 unsigned long SwapINT32(unsigned long dData);
8
9
10 ////////////////////////////////////////
11 extern SYS_INFO_BLOCK xdata DeviceInfo;
12 extern UINT8 xdata DBUF[BUFFER_LENGTH];
13 extern UINT8 xdata FATBUF[512];
14 extern int FatSectorPointer;
15 ////////////////////////////////////////
16
17
C51 COMPILER V8.02 FAT32 09/19/2006 15:01:23 PAGE 23
18 #ifdef FAT32_ACCESS
unsigned long FirstSectorofCluster32(unsigned long clusterNum)
{
unsigned long temp;
temp=clusterNum-2;
temp=temp*DeviceInfo.BPB_SecPerClus;
temp=temp+DeviceInfo.FirstDataSector;
return temp;
}
unsigned long ThisFatSecNum32(unsigned long clusterNum)
{
unsigned long temp;
temp=clusterNum*4;
temp=temp/DeviceInfo.BPB_BytesPerSec;
temp=temp+DeviceInfo.FatStartSector;
return temp;
}
unsigned long ThisFatEntOffset32(unsigned long clusterNum)
{
unsigned long temp1,temp2;
temp1=4*clusterNum;
temp2=temp1/DeviceInfo.BPB_BytesPerSec;
temp1=temp1-temp2*DeviceInfo.BPB_BytesPerSec;
return temp1;
}
unsigned long GetNextClusterNum32(unsigned long clusterNum )
{
unsigned long FatSecNum,FatEntOffset;
FatSecNum=ThisFatSecNum32(clusterNum);
FatEntOffset=ThisFatEntOffset32(clusterNum);
if(FatSectorPointer!=FatSecNum)
{
if(!RBC_ReadOneSec(FatSecNum, FATBUF))
return 0xFFFFFFFF;
FatSectorPointer=FatSecNum;
}
///////////////////////////////////////////////////
//clusterNum=LSwapINT32(FATBUF[FatEntOffset],FATBUF[FatEntOffset+1],FATBUF[FatEntOffset+2],FATBUF[FatEntO
-ffset+3]);
clusterNum = SwapINT32 ( (unsigned long *)(&FATBUF[FatEntOffset]) );
return clusterNum;
}
/*
unsigned char GoToPointer32(unsigned long pointer)
{
unsigned int clusterSize;
clusterSize=DeviceInfo.BPB_SecPerClus*DeviceInfo.BPB_BytesPerSec;
ThisFile.ClusterPointer=ThisFile.StartCluster;
while(pointer>clusterSize)
{
pointer-=clusterSize;
ThisFile.ClusterPointer=GetNextClusterNum32(ThisFile.ClusterPointer);
if(ThisFile.ClusterPointer==0xffffffff)
C51 COMPILER V8.02 FAT32 09/19/2006 15:01:23 PAGE 24
{
return FALSE;
}
}
ThisFile.SectorofCluster=pointer/DeviceInfo.BPB_BytesPerSec;
ThisFile.SectorPointer=FirstSectorofCluster32(ThisFile.ClusterPointer)+ThisFile.SectorofCluster;
ThisFile.OffsetofSector=pointer-ThisFile.SectorofCluster*DeviceInfo.BPB_BytesPerSec;
ThisFile.FatSectorPointer=0;
return TRUE;
}
unsigned char DeleteClusterLink32(unsigned long clusterNum)
{
unsigned long FatSecNum,FatEntOffset;
unsigned char i;
while((clusterNum>1)&&(clusterNum<DeviceInfo.TotCluster))
{
FatSecNum=ThisFatSecNum32(clusterNum);
FatEntOffset=ThisFatEntOffset32(clusterNum);
if(RBC_ReadOneSec(FatSecNum, DBUF))
clusterNum=LSwapINT32(DBUF[FatEntOffset],DBUF[FatEntOffset+1],DBUF[FatEntOffset+2],DBUF[FatEntOffset+3])
-;
else
return FALSE;
DBUF[FatEntOffset]=0x00;DBUF[FatEntOffset+1]=0x00;DBUF[FatEntOffset+2]=0x00;DBUF[FatEntOffset+3]=0x00;
for(i=0;i<DeviceInfo.BPB_NumFATs;i++)
{
DelayMs(5);
if(!RBC_Write(FatSecNum+i*DeviceInfo.BPB_FATSz32,1,DBUF))
return FALSE;
}
}
return TRUE;
}
unsigned long GetFreeCusterNum32(void)
{
unsigned long xdata clusterNum,i;
unsigned long xdata sectorNum;
unsigned char xdata j;
clusterNum=0;
sectorNum=DeviceInfo.FatStartSector;
while(sectorNum<DeviceInfo.BPB_FATSz32+DeviceInfo.FatStartSector)
{
if(!RBC_ReadOneSec(sectorNum, DBUF))
return 0x0;
for(i=0;i<DeviceInfo.BPB_BytesPerSec;i=i+4)
{
if((DBUF[i]==0)&&(DBUF[i+1]==0)&&(DBUF[i+2]==0)&&(DBUF[i+3]==0))
{
DBUF[i]=0xff;DBUF[i+1]=0xff;DBUF[i+2]=0xff;DBUF[i+
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -