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

📄 tpbulk.lst

📁 USB U 盘 开发的源代码
💻 LST
字号:
C51 COMPILER V7.06   TPBULK                                                                09/18/2004 01:30:02 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          #include "HPI32.H"
   7          
   8          //////////////////////////////////
   9          extern unsigned char xdata DBUF[BUFFER_LENGTH];
  10          extern SYS_INFO_BLOCK xdata DeviceInfo;
  11          extern FILE_INFO xdata ThisFile;
  12          extern unsigned int xdata DirStartCluster;
  13          extern unsigned long xdata DirStartCluster32;
  14                  
  15          unsigned char idata out[0x20];
  16          ///////////////////////////////////////////////////////////////////////////
  17          unsigned char EnumMassDev(void)
  18          {
  19   1              unsigned int ReservedSectorsNum;
  20   1      
  21   1              if(!SPC_Inquiry())
  22   1                      return FALSE;
  23   1              if(!SPC_TestUnit())
  24   1                      return FALSE;
  25   1              if(!SPC_LockMedia())
  26   1                      return FALSE;
  27   1              if(!SPC_RequestSense())
  28   1                      return FALSE;
  29   1              if(!SPC_TestUnit())
  30   1                      return FALSE;
  31   1              if(!RBC_ReadCapacity())
  32   1                      return FALSE;
  33   1      
  34   1              ////////////////////////////////////////////////////
  35   1              DeviceInfo.BPB_BytesPerSec=512; //暂假设为512
  36   1              
  37   1              if(!SPC_RequestSense())
  38   1                      return FALSE;
  39   1              if(!SPC_TestUnit())
  40   1                      return FALSE;
  41   1              if(!RBC_ReadCapacity())
  42   1                      return FALSE;
  43   1              ////////////////////////////////////////////////////
  44   1              if(!RBC_Read(0x0,1,DBUF))
  45   1                      return FALSE;
  46   1              //////////////////////////////////
  47   1              if(DBUF[0]==0xeb||DBUF[0]==0xe9)
  48   1                      {
  49   2                      DeviceInfo.StartSector=0;
  50   2                      }
  51   1              else
  52   1                      {
  53   2                      DeviceInfo.StartSector=LSwapINT32(DBUF[454],DBUF[455],DBUF[456],DBUF[457]);
  54   2                      }
  55   1              ///////////////////////////////////////////////////////
C51 COMPILER V7.06   TPBULK                                                                09/18/2004 01:30:02 PAGE 2   

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

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

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

 239   1              /////////////////////////////////////
 240   1              out[15]=RBC_CMD_WRITE10;        
 241   1              out[16]=0x00;
 242   1              out[17]=(unsigned char)((lba>>24)&0xff);
 243   1              out[18]=(unsigned char)((lba>>16)&0xff);
 244   1              out[19]=(unsigned char)((lba>>8)&0xff);
 245   1              out[20]=(unsigned char)(lba&0xff);
 246   1              out[21]=0x00;
 247   1              out[22]=(unsigned char)((len>>8)&0xff);
 248   1              out[23]=(unsigned char)(len&0xff);      
 249   1              out[24]=0x00;
 250   1              //////////////////////////////////////
 251   1              if(!epBulkSend(out,0x1f))       
 252   1                      return FALSE;
 253   1              DelayMs(15);
 254   1              if(!epBulkSend(pBuffer,DeviceInfo.BPB_BytesPerSec))
 255   1                      return FALSE;
 256   1              DelayMs(10);    
 257   1              if(!epBulkRcv(out,13))
 258   1                      return FALSE;
 259   1              return TRUE;
 260   1      }


MODULE INFORMATION:   STATIC OVERLAYABLE
   CODE SIZE        =   2091    ----
   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 + -