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

📄 tpbulk.lst

📁 用SL811USB接口芯片读写U盘FAT16固化程序(C51源代码)
💻 LST
字号:
C51 COMPILER V7.06   TPBULK                                                                09/18/2004 01:20:11 PAGE 1   


C51 COMPILER V7.06, COMPILATION OF MODULE TPBULK
OBJECT MODULE PLACED IN TPBULK.OBJ
COMPILER INVOKED BY: C:\Keil\C51\BIN\C51.EXE TPBULK.C BROWSE DEBUG OBJECTEXTEND

stmt level    source

   1          #include "common.h"
   2          #include "SL811.H"
   3          #include "TPBULK.H"
   4          #include "HAL.H"
   5          #include "HPI.H"
   6          
   7          //////////////////////////////////
   8          extern unsigned char xdata DBUF[BUFFER_LENGTH];
   9          extern SYS_INFO_BLOCK xdata DeviceInfo;
  10          extern FILE_INFO xdata ThisFile;
  11          
  12          unsigned char idata out[0x20];
  13          ///////////////////////////////////////////////////////////////////////////
  14          unsigned char EnumMassDev(void)
  15          {
  16   1              unsigned int ReservedSectorsNum;
  17   1      
  18   1              if(!SPC_Inquiry())
  19   1                      return FALSE;
  20   1              if(!SPC_TestUnit())
  21   1                      return FALSE;
  22   1              if(!SPC_LockMedia())
  23   1                      return FALSE;
  24   1              if(!SPC_RequestSense())
  25   1                      return FALSE;
  26   1              if(!SPC_TestUnit())
  27   1                      return FALSE;
  28   1              if(!RBC_ReadCapacity())
  29   1                      return FALSE;
  30   1      
  31   1              ////////////////////////////////////////////////////
  32   1              DeviceInfo.BPB_BytesPerSec=512; //暂假设为512
  33   1              
  34   1              if(!SPC_RequestSense())
  35   1                      return FALSE;
  36   1              if(!SPC_TestUnit())
  37   1                      return FALSE;
  38   1              if(!RBC_ReadCapacity())
  39   1                      return FALSE;
  40   1              ////////////////////////////////////////////////////
  41   1              if(!RBC_Read(0x0,1,DBUF))
  42   1                      return FALSE;
  43   1              //////////////////////////////////
  44   1              if(DBUF[0]==0xeb||DBUF[0]==0xe9)
  45   1                      {
  46   2                      DeviceInfo.StartSector=0;
  47   2                      }
  48   1              else
  49   1                      {
  50   2                      DeviceInfo.StartSector=LSwapINT32(DBUF[454],DBUF[455],DBUF[456],DBUF[457]);
  51   2                      }
  52   1              ///////////////////////////////////////////////////////
  53   1              if(!RBC_Read(DeviceInfo.StartSector,1,DBUF))
  54   1                      return FALSE;
  55   1              DeviceInfo.BPB_BytesPerSec=LSwapINT16(DBUF[11],DBUF[12]);
C51 COMPILER V7.06   TPBULK                                                                09/18/2004 01:20:11 PAGE 2   

  56   1              DeviceInfo.BPB_SecPerClus=DBUF[13];
  57   1              DeviceInfo.BPB_NumFATs=DBUF[16];
  58   1              DeviceInfo.BPB_RootEntCnt=LSwapINT16(DBUF[17],DBUF[18]);
  59   1              DeviceInfo.BPB_RootEntCnt=(DeviceInfo.BPB_RootEntCnt)*32/DeviceInfo.BPB_BytesPerSec;    
  60   1              DeviceInfo.BPB_TotSec16=LSwapINT16(DBUF[19],DBUF[20]);  
  61   1              DeviceInfo.BPB_FATSz16=LSwapINT16(DBUF[22],DBUF[23]);   
  62   1              DeviceInfo.BPB_TotSec32=LSwapINT32(DBUF[32],DBUF[33],DBUF[34],DBUF[35]);
  63   1              ReservedSectorsNum=LSwapINT16(DBUF[14],DBUF[15]);
  64   1              DeviceInfo.FatStartSector=DeviceInfo.StartSector+ReservedSectorsNum;
  65   1              DeviceInfo.RootStartSector=DeviceInfo.StartSector+DeviceInfo.BPB_NumFATs*DeviceInfo.BPB_FATSz16+ReservedS
             -ectorsNum;        
  66   1              DeviceInfo.FirstDataSector=DeviceInfo.FatStartSector+DeviceInfo.BPB_NumFATs*DeviceInfo.BPB_FATSz16+Device
             -Info.BPB_RootEntCnt;
  67   1              ///////////////////////////////////////////////////////
  68   1              ThisFile.bFileOpen=0;   
  69   1              ///////////////////////////////////////////////////////
  70   1              return TRUE;
  71   1      }
  72          
  73          unsigned char SPC_Inquiry(void)
  74          {
  75   1              out[0]=0x55;out[1]=0x53;out[2]=0x42;out[3]=0x43;
  76   1              out[4]=0x60;out[5]=0xa6;out[6]=0x24;out[7]=0xde;
  77   1              out[8]=0x24;out[9]=0x00;out[10]=0x00;out[11]=0x00;
  78   1              out[12]=0x80;out[13]=0x00;out[14]=06;   
  79   1              out[15]=SPC_CMD_INQUIRY;out[16]=0x00;out[17]=0x00;
  80   1              out[18]=0x00;out[19]=0x24;out[20]=0x00; 
  81   1              ////////////////////////////////
  82   1              if(!epBulkSend(out,0x1f))       
  83   1                      return FALSE;
  84   1              DelayMs(150);
  85   1              if(!epBulkRcv(DBUF,38))
  86   1                      return FALSE;   
  87   1              if(!epBulkRcv(out,13))
  88   1                      return FALSE;
  89   1              ////////////////////////////////
  90   1              return TRUE;    
  91   1      }
  92          
  93          unsigned char SPC_RequestSense(void)
  94          {
  95   1              out[0]=0x55;out[1]=0x53;out[2]=0x42;out[3]=0x43;        
  96   1              out[4]=0x60;out[5]=0xa6;out[6]=0x24;out[7]=0xde;
  97   1              out[8]=0x0e;out[9]=0x00;out[10]=0x00;out[11]=0x00;
  98   1              out[12]=0x80;out[13]=0x00;out[14]=6;
  99   1              out[15]=SPC_CMD_REQUESTSENSE;out[16]=0x00;out[17]=0x00;
 100   1              out[18]=0x00;out[19]=0x0e;out[20]=0x00;         
 101   1              //////////////////////////////////////
 102   1              if(!epBulkSend(out,0x1f))       
 103   1                      return FALSE;
 104   1              DelayMs(5);
 105   1              if(!epBulkRcv(out,18))
 106   1                      return FALSE;   
 107   1              //delay_dsp
 108   1              if(!epBulkRcv(out,13))
 109   1                      return FALSE;
 110   1      /////////////////////////////
 111   1              return TRUE;
 112   1      }
 113          
 114          unsigned char SPC_TestUnit(void)
 115          {
C51 COMPILER V7.06   TPBULK                                                                09/18/2004 01:20:11 PAGE 3   

 116   1              out[0]=0x55;out[1]=0x53;out[2]=0x42;out[3]=0x43;        
 117   1              out[4]=0x60;out[5]=0xa6;out[6]=0x24;out[7]=0xde;        
 118   1              out[8]=0x00;out[9]=0x00;out[10]=0x00;out[11]=0x00;
 119   1              out[12]=0x00;out[13]=0x00;out[14]=6;
 120   1              /////////////////////////////////////   
 121   1              out[15]=SPC_CMD_TESTUNITREADY;
 122   1              out[16]=0;out[17]=0;out[18]=0;out[19]=0;out[20]=0;
 123   1              //////////////////////////////////////
 124   1              if(!epBulkSend(out,0x1f))       
 125   1                      return FALSE;
 126   1              DelayMs(5);
 127   1              if(!epBulkRcv(out,13))
 128   1                      return FALSE;
 129   1              return TRUE;
 130   1      }
 131          
 132          unsigned char SPC_LockMedia(void)
 133          {
 134   1              out[0]=0x55;out[1]=0x53;out[2]=0x42;out[3]=0x43;
 135   1              out[4]=0x60;out[5]=0xa6;out[6]=0x24;out[7]=0xde;        
 136   1              out[8]=0x00;out[9]=0x00;out[10]=0x00;out[11]=0x00;
 137   1              out[12]=0x00;out[13]=0x00;out[14]=5;
 138   1              ///////////////////////////////////////////
 139   1              out[15]=SPC_CMD_PRVENTALLOWMEDIUMREMOVAL;
 140   1              out[16]=0;out[17]=0;out[18]=0;out[19]=1;
 141   1              ///////////////////////////////////////////
 142   1              if(!epBulkSend(out,0x1f))       
 143   1                      return FALSE;
 144   1              DelayMs(5);
 145   1      
 146   1              if(!epBulkRcv(out,13))
 147   1                      return FALSE;
 148   1      
 149   1      /////////////////////////////
 150   1              return TRUE;
 151   1      }
 152          
 153          unsigned char RBC_ReadCapacity(void)
 154          {
 155   1              out[0]=0x55;out[1]=0x53;out[2]=0x42;out[3]=0x43;        
 156   1              out[4]=0x60;out[5]=0xa6;out[6]=0x24;out[7]=0xde;        
 157   1              out[8]=0x08;out[9]=0x00;out[10]=0x00;out[11]=0x00;      
 158   1              out[12]=0x80;out[13]=0x00;out[14]=10;
 159   1              /////////////////////////////////////
 160   1              out[15]=RBC_CMD_READCAPACITY;
 161   1              out[16]=0;out[17]=0;out[18]=0;out[19]=0;
 162   1              out[20]=0;out[21]=0;out[22]=0;out[23]=0;
 163   1              out[24]=0;
 164   1              /////////////////////////////////////
 165   1              if(!epBulkSend(out,0x1f))       
 166   1                      return FALSE;
 167   1              DelayMs(10);
 168   1              if(!epBulkRcv(DBUF,8))
 169   1                      return FALSE;
 170   1              if(!epBulkRcv(out,13))
 171   1                      return FALSE;
 172   1              /////////////////////////////
 173   1              return TRUE;
 174   1      }
 175          
 176          unsigned char RBC_Read(unsigned long lba,unsigned char len,unsigned char *pBuffer)
 177          {
C51 COMPILER V7.06   TPBULK                                                                09/18/2004 01:20:11 PAGE 4   

 178   1              unsigned long lout;     
 179   1              out[0]=0x55;out[1]=0x53;out[2]=0x42;out[3]=0x43;        
 180   1              out[4]=0x60;out[5]=0xa6;out[6]=0x24;out[7]=0xde;        
 181   1              lout=len*DeviceInfo.BPB_BytesPerSec;
 182   1              out[8]=(unsigned char)(lout&0xff);
 183   1              out[9]=(unsigned char)((lout>>8)&0xff);
 184   1              out[10]=(unsigned char)((lout>>16)&0xff);
 185   1              out[11]=(unsigned char)((lout>>24)&0xff);       
 186   1              out[12]=0x80;out[13]=0x00;out[14]=10;
 187   1              /////////////////////////////////////
 188   1              out[15]=RBC_CMD_READ10;out[16]=0x00;
 189   1              out[17]=(unsigned char)((lba>>24)&0xff);
 190   1              out[18]=(unsigned char)((lba>>16)&0xff);
 191   1              out[19]=(unsigned char)((lba>>8)&0xff);
 192   1              out[20]=(unsigned char)(lba&0xff);      
 193   1              out[21]=0x00;
 194   1              out[22]=(unsigned char)((len>>8)&0xff);
 195   1              out[23]=(unsigned char)(len&0xff);      
 196   1              out[24]=0x00;
 197   1              //////////////////////////////////////  
 198   1              if(!epBulkSend(out,0x1f))       
 199   1                      return FALSE;
 200   1              DelayMs(5);
 201   1              if(!epBulkRcv(pBuffer,len*DeviceInfo.BPB_BytesPerSec))
 202   1                      return FALSE;
 203   1              if(!epBulkRcv(out,13))
 204   1                      return FALSE;           
 205   1              /////////////////////////////
 206   1              return TRUE;
 207   1      }
 208          
 209          unsigned char RBC_Write(unsigned long lba,unsigned char len,unsigned char *pBuffer)
 210          {
 211   1              unsigned long lout;
 212   1              out[0]=0x55;out[1]=0x53;out[2]=0x42;out[3]=0x43;
 213   1              out[4]=0xb4;out[5]=0xd9;out[6]=0x77;out[7]=0xc1;        
 214   1              lout=len*DeviceInfo.BPB_BytesPerSec;
 215   1              out[8]=(unsigned char)(lout&0xff);
 216   1              out[9]=(unsigned char)((lout>>8)&0xff);
 217   1              out[10]=(unsigned char)((lout>>16)&0xff);
 218   1              out[11]=(unsigned char)((lout>>24)&0xff);       
 219   1              out[12]=0x00;out[13]=0x00;out[14]=10;
 220   1              /////////////////////////////////////
 221   1              out[15]=RBC_CMD_WRITE10;        
 222   1              out[16]=0x00;
 223   1              out[17]=(unsigned char)((lba>>24)&0xff);
 224   1              out[18]=(unsigned char)((lba>>16)&0xff);
 225   1              out[19]=(unsigned char)((lba>>8)&0xff);
 226   1              out[20]=(unsigned char)(lba&0xff);
 227   1              out[21]=0x00;
 228   1              out[22]=(unsigned char)((len>>8)&0xff);
 229   1              out[23]=(unsigned char)(len&0xff);      
 230   1              out[24]=0x00;
 231   1              //////////////////////////////////////
 232   1              if(!epBulkSend(out,0x1f))       
 233   1                      return FALSE;
 234   1              DelayMs(15);
 235   1              if(!epBulkSend(pBuffer,DeviceInfo.BPB_BytesPerSec))
 236   1                      return FALSE;
 237   1              DelayMs(10);    
 238   1              if(!epBulkRcv(out,13))
 239   1                      return FALSE;
C51 COMPILER V7.06   TPBULK                                                                09/18/2004 01:20:11 PAGE 5   

 240   1              return TRUE;
 241   1      }


MODULE INFORMATION:   STATIC OVERLAYABLE
   CODE SIZE        =   1714    ----
   CONSTANT SIZE    =   ----    ----
   XDATA SIZE       =   ----    ----
   PDATA SIZE       =   ----    ----
   DATA SIZE        =   ----      26
   IDATA SIZE       =     32    ----
   BIT SIZE         =   ----    ----
END OF MODULE INFORMATION.


C51 COMPILATION COMPLETE.  0 WARNING(S),  0 ERROR(S)

⌨️ 快捷键说明

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