HPI32.LST
资源名称:51-SD.rar [点击查看]
上传用户:jcsy2001
上传日期:2013-11-29
资源大小:201k
文件大小:54k
源码类别:
嵌入式/单片机编程
开发平台:
C/C++
- C51 COMPILER V8.02 HPI32 04/29/2007 12:48:53 PAGE 1
- C51 COMPILER V8.02, COMPILATION OF MODULE HPI32
- OBJECT MODULE PLACED IN HPI32.OBJ
- COMPILER INVOKED BY: D:KeilC51BINC51.EXE HPI32.C BROWSE DEBUG OBJECTEXTEND
- line level source
- 1 #include "common.h"
- 2 #include "DEVICE.H"
- 3 #include "HPI.H"
- 4 #include "HAL.H"
- 5 #include "Fat.h"
- 6 #include "Fat32.h"
- 7 #include "HPI32.H"
- 8
- 9 extern FLAGS bdata bFlags;
- 10 extern unsigned char xdata DBUF[BUFFER_LENGTH];
- 11 //////////////////////////////////////////
- 12 extern unsigned char xdata UARTBUF[UARTBUF_LENGTH];
- 13 extern SYS_INFO_BLOCK xdata DeviceInfo;
- 14 extern FILE_INFO xdata ThisFile;
- 15
- 16 extern Command_Def xdata Command;
- 17 extern Response_Def xdata Response;
- 18
- 19 unsigned long xdata DirStartCluster32,NowCluster32;
- 20 extern unsigned long xdata NowSector;
- 21 extern ShowFileName_Def xdata ShowFileName[MaxLFNum]; //long file struct
- 22 /////////////////////////////////////////////
- 23
- 24 unsigned char UartHandler32(void)
- 25 {
- 26 1 Response.Result=0;Response.len=0;
- 27 1 switch(Command.CLass)
- 28 1 {
- 29 2 case 0x00: //List
- 30 2 Response.Result=List32();
- 31 2 break;
- 32 2 case 0x01: //Open File
- 33 2 Response.Result=OpenFile32(Command.Parameter);
- 34 2 break;
- 35 2 case 0x02: //Read File
- 36 2 Response.Result=ReadFile32(Command.len,UARTBUF);
- 37 2 break;
- 38 2 case 0x03: //Set Pointer
- 39 2 Response.Result=SetFilePointer32(Command.len);
- 40 2 break;
- 41 2 case 0x04: //Great File
- 42 2 Response.Result=OpenFile32(Command.Parameter);
- 43 2 if(Response.Result)
- 44 2 {
- 45 3 Response.Result=SetFilePointer32(ThisFile.LengthInByte);
- 46 3 }
- 47 2 else
- 48 2 Response.Result=CreateFile32(Command.len,Command.Parameter,UARTBUF);
- 49 2 break;
- 50 2 case 0x05: //Write File
- 51 2 Response.Result=WriteFile32(Command.len,UARTBUF);
- 52 2 break;
- 53 2 case 0x06: //Remove File
- 54 2 ThisFile.bFileOpen=0;
- 55 2 Response.Result=RemoveFile32(Command.Parameter);
- C51 COMPILER V8.02 HPI32 04/29/2007 12:48:53 PAGE 2
- 56 2 break;
- 57 2 case 0x07: //Get Space
- 58 2 Response.Result=GetCapacity32();
- 59 2 break;
- 60 2 case 0x08: //DetectDisk
- 61 2 if(bFlags.bits.SLAVE_IS_ATTACHED)
- 62 2 Response.Result=1;
- 63 2 break;
- 64 2 case 0x09: //Great Dir
- 65 2 Response.Result=DownDir32(Command.Parameter);
- 66 2 if(!Response.Result)
- 67 2 Response.Result=CreateDir32(Command.len,Command.Parameter,UARTBUF);
- 68 2 break;
- 69 2 case 0x0a: //Down Dir
- 70 2 Response.Result=DownDir32(Command.Parameter);
- 71 2 break;
- 72 2 case 0x0b: //Up Dir
- 73 2 Response.Result=UpDir32();
- 74 2 break;
- 75 2 case 0x0c: //Up RootDir
- 76 2 Response.Result=UpRootDir32();
- 77 2 break;
- 78 2 }
- 79 1
- 80 1 UartSendRsp();
- 81 1 ///////////////////////////////
- 82 1 return TRUE;
- 83 1 }
- 84
- 85 unsigned char List32(void)
- 86 {
- 87 1 unsigned int item,i;
- 88 1 unsigned char k,bstop,sector;
- 89 1 unsigned char Lcount,Ncount,base;
- 90 1
- 91 1 if(!bFlags.bits.SLAVE_IS_ATTACHED)
- 92 1 return FALSE;
- 93 1 item=0;
- 94 1 bstop=0;
- 95 1 ////////////////////////////////////
- 96 1 Lcount=0;
- 97 1 for(i=0;i<MaxLFNum;i++)
- 98 1 {
- 99 2 ShowFileName[i].LongName[0]=0x00;
- 100 2 ShowFileName[i].LongName[1]=0x00;
- 101 2 }
- 102 1 //////////////////////////////////////////////////////////////////
- 103 1 NowCluster32=DirStartCluster32;
- 104 1 do
- 105 1 {
- 106 2 NowSector=FirstSectorofCluster32(NowCluster32);
- 107 2 for(sector=0;sector<DeviceInfo.BPB_SecPerClus;sector++)
- 108 2 {
- 109 3 if(!SdReadSector(NowSector+sector,1,DBUF))
- 110 3 return FALSE;
- 111 3 for(i=0;i<DeviceInfo.BPB_BytesPerSec;i=i+32)
- 112 3 {
- 113 4 if(DBUF[i]==0x00)
- 114 4 {bstop=1;break;}
- 115 4 else if(DBUF[i]==0xE5)
- 116 4 continue;
- 117 4 else
- C51 COMPILER V8.02 HPI32 04/29/2007 12:48:53 PAGE 3
- 118 4 {
- 119 5 for(k=0;k<32;k++)
- 120 5 UARTBUF[item*32+k]=DBUF[i+k];
- 121 5 item=item+1;
- 122 5 if(item>=(UARTBUF_LENGTH/32)) {bstop=1;break;} //串口缓冲 只能有512项目录,强行结束
- 123 5 /////////////////////////////////
- 124 5 if(Lcount<MaxLFNum)
- 125 5 {
- 126 6 if(DBUF[i+11]==0x0F)
- 127 6 {
- 128 7 base=((DBUF[i]&0x1F)-1)*26;
- 129 7 if(base<=224)
- 130 7 {
- 131 8 Ncount=0;
- 132 8 for(k=1;k<11;k++)
- 133 8 {
- 134 9 ShowFileName[Lcount].LongName[base+Ncount]=DBUF[i+k];
- 135 9 Ncount++;
- 136 9 }
- 137 8 for(k=14;k<26;k++)
- 138 8 {
- 139 9 ShowFileName[Lcount].LongName[base+Ncount]=DBUF[i+k];
- 140 9 Ncount++;
- 141 9 }
- 142 8 for(k=28;k<32;k++)
- 143 8 {
- 144 9 ShowFileName[Lcount].LongName[base+Ncount]=DBUF[i+k];
- 145 9 Ncount++;
- 146 9 }
- 147 8 }
- 148 7 }
- 149 6 else
- 150 6 {
- 151 7 for(k=0;k<32;k++)
- 152 7 ShowFileName[Lcount].item[k]=DBUF[i+k];
- 153 7 Lcount++;
- 154 7 }
- 155 6 }
- 156 5 /////////////////////////////////
- 157 5 }
- 158 4 }
- 159 3 if(bstop==1)break;
- 160 3 }
- 161 2 if(bstop==1)break;
- 162 2
- 163 2 NowCluster32=GetNextClusterNum32(NowCluster32);
- 164 2
- 165 2 }while(NowCluster32<=DeviceInfo.TotCluster);
- 166 1
- 167 1 Response.len=item*32;
- 168 1 return TRUE;
- 169 1 }
- 170
- 171 unsigned char OpenFile32(unsigned char *pBuffer)
- 172 {
- 173 1 unsigned int i;
- 174 1 unsigned char j,bstop,sector;
- 175 1
- 176 1 if(!bFlags.bits.SLAVE_IS_ATTACHED)
- 177 1 return FALSE;
- 178 1 ThisFile.bFileOpen=0;
- 179 1 NowCluster32=DirStartCluster32;
- C51 COMPILER V8.02 HPI32 04/29/2007 12:48:53 PAGE 4
- 180 1 do
- 181 1 {
- 182 2 NowSector=FirstSectorofCluster32(NowCluster32);
- 183 2 for(sector=0;sector<DeviceInfo.BPB_SecPerClus;sector++)
- 184 2 {
- 185 3 if(!SdReadSector(NowSector+sector,1,DBUF))
- 186 3 return FALSE;
- 187 3 for(i=0;i<DeviceInfo.BPB_BytesPerSec;i=i+32)
- 188 3 {
- 189 4 if(DBUF[i]==0x00)
- 190 4 return FALSE;
- 191 4 j=0;
- 192 4 while(DBUF[i+j]==*(pBuffer+j))
- 193 4 {
- 194 5 j=j+1;
- 195 5 if(j>10)
- 196 5 break;
- 197 5 }
- 198 4 if(j>10&&(DBUF[i+11]&0x10)!=0x10)
- 199 4 {
- 200 5 for(j=0;j<32;j++)
- 201 5 UARTBUF[j]=DBUF[i+j];
- 202 5 bstop=1;
- 203 5 break;
- 204 5 }
- 205 4 }
- 206 3 if(bstop==1)break;
- 207 3 }
- 208 2 if(bstop==1)break;
- 209 2 NowCluster32=GetNextClusterNum32(NowCluster32);
- 210 2 }while(NowCluster32<=DeviceInfo.TotCluster);
- 211 1
- 212 1 if(NowCluster32>DeviceInfo.TotCluster)
- 213 1 return FALSE;
- 214 1
- 215 1 ThisFile.bFileOpen=1;
- 216 1 ThisFile.StartCluster=LSwapINT32(UARTBUF[26],UARTBUF[27],UARTBUF[20],UARTBUF[21]);
- 217 1 ThisFile.LengthInByte=LSwapINT32(UARTBUF[28],UARTBUF[29],UARTBUF[30],UARTBUF[31]);
- 218 1 ThisFile.ClusterPointer=ThisFile.StartCluster;
- 219 1 ThisFile.SectorPointer=FirstSectorofCluster32(ThisFile.StartCluster);
- 220 1 ThisFile.OffsetofSector=0;
- 221 1 ThisFile.SectorofCluster=0;
- 222 1 ThisFile.FatSectorPointer=0;
- 223 1 ThisFile.pointer=0;
- 224 1
- 225 1 Response.len=32;
- 226 1 return TRUE;
- 227 1 }
- 228
- 229
- 230 unsigned char ReadFile32(unsigned long readLength,unsigned char *pBuffer)
- 231 {
- 232 1
- 233 1 unsigned int len,i;
- 234 1 unsigned int tlen;
- 235 1 unsigned long blen;
- 236 1
- 237 1 if(!bFlags.bits.SLAVE_IS_ATTACHED)
- 238 1 return FALSE;
- 239 1 if(!ThisFile.bFileOpen)
- 240 1 return FALSE;
- 241 1
- C51 COMPILER V8.02 HPI32 04/29/2007 12:48:53 PAGE 5
- 242 1 blen=readLength;
- 243 1 tlen=0;
- 244 1 if(readLength>MAX_READ_LENGTH)
- 245 1 return FALSE;
- 246 1
- 247 1 if(readLength+ThisFile.pointer>ThisFile.LengthInByte)
- 248 1 return FALSE;
- 249 1
- 250 1 ////////////////////////////////////////////
- 251 1 while(readLength>0)
- 252 1 {
- 253 2 if(readLength+ThisFile.OffsetofSector>DeviceInfo.BPB_BytesPerSec)
- 254 2 len=DeviceInfo.BPB_BytesPerSec;
- 255 2 else
- 256 2 len=readLength+ThisFile.OffsetofSector;
- 257 2
- 258 2 //////////////////////////////////////////////////////
- 259 2 if(ThisFile.OffsetofSector>0)
- 260 2 {
- 261 3 if(SdReadSector(ThisFile.SectorPointer,1,DBUF))
- 262 3 {
- 263 4
- 264 4 len=len-ThisFile.OffsetofSector;
- 265 4 for(i=0;i<len;i++)
- 266 4
- 267 4 *(pBuffer+i)=DBUF[ThisFile.OffsetofSector+i];
- 268 4 ThisFile.OffsetofSector=ThisFile.OffsetofSector+len;
- 269 4 }
- 270 3 else
- 271 3 return FALSE;
- 272 3 }
- 273 2 else
- 274 2 {
- 275 3 if(!SdReadSector(ThisFile.SectorPointer,1,pBuffer+tlen))
- 276 3 return FALSE;
- 277 3 ThisFile.OffsetofSector=len;
- 278 3 }
- 279 2 ////////////////////////////////////////////////////////////
- 280 2 readLength-=len;
- 281 2 tlen+=len;
- 282 2
- 283 2 /////////////////////////////////////////////////////////
- 284 2 if(ThisFile.OffsetofSector>DeviceInfo.BPB_BytesPerSec-1)
- 285 2 {
- 286 3 ThisFile.OffsetofSector-=DeviceInfo.BPB_BytesPerSec;
- 287 3 ThisFile.SectorofCluster+=1;
- 288 3 if(ThisFile.SectorofCluster>DeviceInfo.BPB_SecPerClus-1)
- 289 3 {
- 290 4 ThisFile.SectorofCluster=0;
- 291 4 ThisFile.ClusterPointer=GetNextClusterNum32(ThisFile.ClusterPointer);
- 292 4 if(ThisFile.ClusterPointer>DeviceInfo.TotCluster)
- 293 4 return FALSE;
- 294 4 ThisFile.SectorPointer=FirstSectorofCluster32(ThisFile.ClusterPointer);
- 295 4 }
- 296 3 else
- 297 3 ThisFile.SectorPointer=ThisFile.SectorPointer+1;
- 298 3 }
- 299 2 //////////////////////////////////////////////////////////////////
- 300 2 }//end while
- 301 1
- 302 1 ThisFile.bFileOpen=1;
- 303 1 ThisFile.pointer+=tlen;
- C51 COMPILER V8.02 HPI32 04/29/2007 12:48:53 PAGE 6
- 304 1 //////////////////////////////////////////////
- 305 1 Response.len=blen;
- 306 1
- 307 1 return TRUE;
- 308 1 }
- 309
- 310 unsigned char SetFilePointer32(unsigned long pointer)
- 311 {
- 312 1 if(!bFlags.bits.SLAVE_IS_ATTACHED)
- 313 1 return FALSE;
- 314 1 if(!ThisFile.bFileOpen)
- 315 1 return FALSE;
- 316 1 ///////////////////////////////////////////////////////////
- 317 1 ThisFile.pointer=pointer;
- 318 1 if(ThisFile.pointer>ThisFile.LengthInByte)
- 319 1 return FALSE;
- 320 1
- 321 1 if(!GoToPointer32(ThisFile.pointer))
- 322 1 {
- 323 2 ThisFile.bFileOpen=0;
- 324 2 return FALSE;
- 325 2 }
- 326 1 //////////////////////////////////////////////
- 327 1 return TRUE;
- 328 1 }
- 329
- 330 unsigned char CreateFile32(unsigned long len,unsigned char *pBuffer,unsigned char *pName)
- 331 {
- 332 1 unsigned int sector,i,j,DirCount;
- 333 1 unsigned long cnum;
- 334 1 unsigned char xdata bstop,InByte,bwrite;
- 335 1 unsigned long ClusterPointer;
- 336 1
- 337 1 if(!bFlags.bits.SLAVE_IS_ATTACHED)
- 338 1 return FALSE;
- 339 1 if((len%32)!=0)
- 340 1 return FALSE;
- 341 1 if((len+32)>DeviceInfo.BPB_BytesPerSec)
- 342 1 return FALSE;
- 343 1
- 344 1 ThisFile.bFileOpen=0;
- 345 1
- 346 1 cnum=GetFreeCusterNum32();
- 347 1 if(cnum<0x02)
- 348 1 return FALSE;
- 349 1
- 350 1 pBuffer[21]=(unsigned char)(cnum>>24);
- 351 1 pBuffer[20]=(unsigned char)(cnum>>16);
- 352 1 pBuffer[27]=(unsigned char)(cnum>>8);
- 353 1 pBuffer[26]=(unsigned char)(cnum);
- 354 1
- 355 1 pBuffer[28]=0;pBuffer[29]=0;pBuffer[30]=0;pBuffer[31]=0;
- 356 1 bstop=0;
- 357 1
- 358 1 NowCluster32=DirStartCluster32;
- 359 1 do
- 360 1 {
- 361 2 NowSector=FirstSectorofCluster32(NowCluster32);
- 362 2 ClusterPointer=NowCluster32;
- 363 2 for(sector=0;sector<DeviceInfo.BPB_SecPerClus;sector++)
- 364 2 {
- 365 3 if(!SdReadSector(NowSector+sector,1,DBUF))
- C51 COMPILER V8.02 HPI32 04/29/2007 12:48:53 PAGE 7
- 366 3 return FALSE;
- 367 3 DirCount=0;bwrite=0;
- 368 3
- 369 3 for(i=0;i<DeviceInfo.BPB_BytesPerSec;i=i+32)
- 370 3 {
- 371 4 if(len==0)
- 372 4 {
- 373 5 if((DBUF[i]==0x00)||(DBUF[i]==0xE5))
- 374 5 {
- 375 6 for(j=0;j<32;j++)
- 376 6 DBUF[i+j]=*(pBuffer+j);
- 377 6 if(!SdWriteSector(NowSector+sector,1,DBUF))
- 378 6 return FALSE;
- 379 6 bstop=1;
- 380 6 break;
- 381 6 }
- 382 5 }
- 383 4 else
- 384 4 {
- 385 5 if(DirCount==0)
- 386 5 InByte=i;
- 387 5 if(DBUF[i]==0xE5)
- 388 5 DirCount++;
- 389 5 else if(DBUF[i]==0x00)
- 390 5 {
- 391 6 DirCount++;
- 392 6 DBUF[i]=0xE5;
- 393 6 bwrite=1;
- 394 6 }
- 395 5 else
- 396 5 DirCount=0;
- 397 5
- 398 5 if((DirCount*32)>=(len+32))
- 399 5 {
- 400 6 for(j=0;j<len;j++)
- 401 6 DBUF[InByte+j]=*(pName+j);
- 402 6 for(j=0;j<32;j++)
- 403 6 DBUF[InByte+len+j]=*(pBuffer+j);
- 404 6 if(!SdWriteSector(NowSector+sector,1,DBUF))
- 405 6 return FALSE;
- 406 6 bstop=1;
- 407 6 break;
- 408 6 }
- 409 5 }
- 410 4 }
- 411 3 if(bstop==1)break;
- 412 3
- 413 3 if((len!=0)&&(bwrite==1))
- 414 3 {
- 415 4 if(!SdWriteSector(NowSector+sector,1,DBUF))
- 416 4 return FALSE;
- 417 4 }
- 418 3 }
- 419 2 if(bstop==1)break;
- 420 2
- 421 2 NowCluster32=GetNextClusterNum32(NowCluster32);
- 422 2 if(NowCluster32>DeviceInfo.TotCluster)
- 423 2 {
- 424 3 NowCluster32=CreateClusterLink32(ClusterPointer);
- 425 3 if(NowCluster32==0x00)
- 426 3 return FALSE;
- 427 3 NowSector=FirstSectorofCluster32(NowCluster32);
- C51 COMPILER V8.02 HPI32 04/29/2007 12:48:53 PAGE 8
- 428 3 for(i=0;i<DeviceInfo.BPB_BytesPerSec;i++) DBUF[i]=0x00;
- 429 3 for(sector=0;sector<DeviceInfo.BPB_SecPerClus;sector++)
- 430 3 {
- 431 4 if(!SdWriteSector(NowSector+sector,1,DBUF))
- 432 4 return FALSE;
- 433 4 }
- 434 3 }
- 435 2 }while(NowCluster32<=DeviceInfo.TotCluster);
- 436 1 ////////////////////////////////////////////////////////////////
- 437 1
- 438 1 ThisFile.StartCluster=cnum;
- 439 1 ThisFile.LengthInByte=0;
- 440 1 ThisFile.ClusterPointer=ThisFile.StartCluster;
- 441 1 ThisFile.SectorPointer=FirstSectorofCluster32(ThisFile.StartCluster);
- 442 1 ThisFile.OffsetofSector=0;
- 443 1 ThisFile.SectorofCluster=0;
- 444 1 ThisFile.bFileOpen=1;
- 445 1 ThisFile.pointer=0;
- 446 1 ThisFile.FatSectorPointer=0;
- 447 1
- 448 1 return TRUE;
- 449 1 }
- 450
- 451
- 452 unsigned char WriteFile32(unsigned long writeLength,unsigned char *pBuffer)
- 453 {
- 454 1 unsigned long cnum;
- 455 1 unsigned int len,sector,i,tlen;
- 456 1 unsigned char bSuccess,bStop;
- 457 1
- 458 1 if(!bFlags.bits.SLAVE_IS_ATTACHED)
- 459 1 return FALSE;
- 460 1 if(!ThisFile.bFileOpen)
- 461 1 return FALSE;
- 462 1 ThisFile.bFileOpen=0;
- 463 1 bSuccess=1;
- 464 1 bStop=0;
- 465 1 tlen=0;
- 466 1
- 467 1 while(writeLength>0)
- 468 1 {
- 469 2 if(writeLength+ThisFile.OffsetofSector>DeviceInfo.BPB_BytesPerSec)
- 470 2 len=DeviceInfo.BPB_BytesPerSec;
- 471 2 else
- 472 2 len=writeLength+ThisFile.OffsetofSector;
- 473 2
- 474 2 //////////////////////////////////////////////////////
- 475 2 if(ThisFile.OffsetofSector>0)
- 476 2 {
- 477 3 if(SdReadSector(ThisFile.SectorPointer,1,DBUF))
- 478 3 {
- 479 4
- 480 4 len=len-ThisFile.OffsetofSector;
- 481 4 for(i=0;i<len;i++)
- 482 4 DBUF[ThisFile.OffsetofSector+i]=*(pBuffer+i);
- 483 4 if(!SdWriteSector(ThisFile.SectorPointer,1,DBUF))
- 484 4 return FALSE;
- 485 4 ThisFile.OffsetofSector=ThisFile.OffsetofSector+len;
- 486 4 }
- 487 3 else
- 488 3 return FALSE;
- 489 3 }
- C51 COMPILER V8.02 HPI32 04/29/2007 12:48:53 PAGE 9
- 490 2 else
- 491 2 {
- 492 3 if(!SdWriteSector(ThisFile.SectorPointer,1,pBuffer+tlen))
- 493 3 return FALSE;
- 494 3 ThisFile.OffsetofSector=len;
- 495 3 }
- 496 2 /////////////////////////////////////////////////////
- 497 2 writeLength-=len;
- 498 2 tlen+=len;
- 499 2 /////////////更新文件指针 //////////////////////////////
- 500 2 if(ThisFile.OffsetofSector>DeviceInfo.BPB_BytesPerSec-1)
- 501 2 {
- 502 3 ThisFile.OffsetofSector-=DeviceInfo.BPB_BytesPerSec;
- 503 3 ThisFile.SectorofCluster+=1;
- 504 3 if(ThisFile.SectorofCluster>DeviceInfo.BPB_SecPerClus-1)
- 505 3 {
- 506 4 ThisFile.SectorofCluster=0;
- 507 4 ThisFile.ClusterPointer=CreateClusterLink32(ThisFile.ClusterPointer);
- 508 4 if(ThisFile.ClusterPointer==0x00)
- 509 4 return FALSE;
- 510 4 ThisFile.SectorPointer=FirstSectorofCluster32(ThisFile.ClusterPointer);
- 511 4 }
- 512 3 else
- 513 3 ThisFile.SectorPointer=ThisFile.SectorPointer+1;
- 514 3 }
- 515 2
- 516 2
- 517 2 }//end while
- 518 1 ThisFile.pointer+=tlen;
- 519 1 ///////////更新文件目录信息/////////////////////////////
- 520 1 if(bSuccess==1)
- 521 1 {
- 522 2 NowCluster32=DirStartCluster32;
- 523 2 do
- 524 2 {
- 525 3 NowSector=FirstSectorofCluster32(NowCluster32);
- 526 3 for(sector=0;sector<DeviceInfo.BPB_SecPerClus;sector++)
- 527 3 {
- 528 4 if(!SdReadSector(NowSector+sector,1,DBUF))
- 529 4 return FALSE;
- 530 4 for(i=0;i<DeviceInfo.BPB_BytesPerSec;i=i+32)
- 531 4 {
- 532 5 cnum=LSwapINT32(DBUF[i+26],DBUF[i+27],DBUF[i+20],DBUF[i+21]);
- 533 5 if((cnum==ThisFile.StartCluster)&&(DBUF[i]!=0xe5))
- 534 5 {
- 535 6 if(ThisFile.pointer>ThisFile.LengthInByte)
- 536 6 ThisFile.LengthInByte=ThisFile.pointer;
- 537 6 DBUF[i+28]=(unsigned char)(ThisFile.LengthInByte&0xff);
- 538 6 DBUF[i+29]=(unsigned char)((ThisFile.LengthInByte>>8)&0xff);
- 539 6 DBUF[i+30]=(unsigned char)((ThisFile.LengthInByte>>16)&0xff);
- 540 6 DBUF[i+31]=(unsigned char)((ThisFile.LengthInByte>>24)&0xff);
- 541 6 if(!SdWriteSector(NowSector+sector,1,DBUF))
- 542 6 return FALSE;
- 543 6 bStop=1;
- 544 6 break;
- 545 6 }
- 546 5 }
- 547 4 if(bStop==1)break;
- 548 4 }
- 549 3 if(bStop==1)break;
- 550 3 NowCluster32=GetNextClusterNum32(NowCluster32);
- 551 3 }while(NowCluster32<=DeviceInfo.TotCluster);
- C51 COMPILER V8.02 HPI32 04/29/2007 12:48:53 PAGE 10
- 552 2
- 553 2 if(NowCluster32>DeviceInfo.TotCluster)
- 554 2 return FALSE;
- 555 2 }
- 556 1
- 557 1 ThisFile.bFileOpen=1;
- 558 1 //////////////////////////////////////////////
- 559 1 return TRUE;
- 560 1 }
- 561
- 562
- 563 unsigned char RemoveFile32(unsigned char *pBuffer)
- 564 {
- 565 1 unsigned int sector,i;
- 566 1 unsigned char bStop,j;
- 567 1 int k;
- 568 1
- 569 1 if(!bFlags.bits.SLAVE_IS_ATTACHED)
- 570 1 return FALSE;
- 571 1 ////////////// 清除目录/////////////////////////////////////
- 572 1 NowCluster32=DirStartCluster32;
- 573 1 do
- 574 1 {
- 575 2 NowSector=FirstSectorofCluster32(NowCluster32);
- 576 2 for(sector=0;sector<DeviceInfo.BPB_SecPerClus;sector++)
- 577 2 {
- 578 3 if(!SdReadSector(NowSector+sector,1,DBUF))
- 579 3 return FALSE;
- 580 3 for(i=0;i<DeviceInfo.BPB_BytesPerSec;i=i+32)
- 581 3 {
- 582 4 if(DBUF[i]==0x00)
- 583 4 return FALSE;
- 584 4 j=0;
- 585 4 while(DBUF[i+j]==*(pBuffer+j))
- 586 4 {
- 587 5 j=j+1;
- 588 5 if(j>10)
- 589 5 break;
- 590 5 }
- 591 4 if(j>10)
- 592 4 {
- 593 5 DBUF[i]=0xE5;
- 594 5 ThisFile.StartCluster=LSwapINT32(DBUF[i+26],DBUF[i+27],DBUF[i+20],DBUF[i+21]);
- 595 5 for(k=(i-32);k>=0;k=k-32)
- 596 5 {
- 597 6 if(DBUF[k+11]==0x0F)
- 598 6 DBUF[k]=0xE5;
- 599 6 else
- 600 6 break;
- 601 6 }
- 602 5 DelayMs(15);
- 603 5 if(!SdWriteSector(NowSector+sector,1,DBUF))
- 604 5 return FALSE;
- 605 5 //////////////////// 清除FAT中的纪录////////////////////////
- 606 5 DelayMs(10);
- 607 5 if(!DeleteClusterLink32(ThisFile.StartCluster))
- 608 5 return FALSE;
- 609 5 bStop=1;
- 610 5 break;
- 611 5 }
- 612 4 }
- 613 3 if(bStop==1)break;
- C51 COMPILER V8.02 HPI32 04/29/2007 12:48:53 PAGE 11
- 614 3 }
- 615 2 if(bStop==1)break;
- 616 2 NowCluster32=GetNextClusterNum32(NowCluster32);
- 617 2 }while(NowCluster32<=DeviceInfo.TotCluster);
- 618 1
- 619 1 if(NowCluster32>DeviceInfo.TotCluster)
- 620 1 return FALSE;
- 621 1
- 622 1 return TRUE;
- 623 1 }
- 624
- 625
- 626 unsigned char GetCapacity32(void)
- 627 {
- 628 1 unsigned int sectorNum,i;
- 629 1 unsigned long FreeSize,Freesectorcnt;
- 630 1
- 631 1 if(!bFlags.bits.SLAVE_IS_ATTACHED)
- 632 1 return FALSE;
- 633 1
- 634 1 ////////////////////////////////////////////////////////////////////////
- 635 1 sectorNum=DeviceInfo.FatStartSector;
- 636 1 Freesectorcnt=0;
- 637 1 while(sectorNum<DeviceInfo.BPB_FATSz32+DeviceInfo.FatStartSector)
- 638 1 {
- 639 2
- 640 2 if(SdReadSector(sectorNum,1,DBUF))
- 641 2 {
- 642 3 for(i=0;i<DeviceInfo.BPB_BytesPerSec;i=i+4)
- 643 3 {
- 644 4 if((DBUF[i]||DBUF[i+1]||DBUF[i+2]||DBUF[i+3])==0x00)
- 645 4 {
- 646 5 Freesectorcnt++;
- 647 5 }
- 648 4 }
- 649 3 }
- 650 2 else
- 651 2 return FALSE;
- 652 2 sectorNum++;
- 653 2 }
- 654 1
- 655 1 ////////////////////////////////////////////////////////////////////////
- 656 1 FreeSize=DeviceInfo.BPB_BytesPerSec*DeviceInfo.BPB_SecPerClus;
- 657 1 FreeSize=Freesectorcnt*FreeSize;
- 658 1
- 659 1 UARTBUF[0]=(unsigned char)((FreeSize>>24)&0xff);
- 660 1 UARTBUF[1]=(unsigned char)((FreeSize>>16)&0xff);
- 661 1 UARTBUF[2]=(unsigned char)((FreeSize>>8)&0xff);
- 662 1 UARTBUF[3]=(unsigned char)(FreeSize&0xff);
- 663 1 Response.len=4;
- 664 1 return TRUE;
- 665 1 }
- 666
- 667
- 668 unsigned char CreateDir32(unsigned long len,unsigned char *pBuffer,unsigned char *pName)
- 669 {
- 670 1 unsigned int sector,i,j,DirCount;
- 671 1 unsigned long cnum;
- 672 1 unsigned char xdata bstop,InByte,bwrite;
- 673 1 unsigned long ClusterPointer;
- 674 1
- 675 1 if(!bFlags.bits.SLAVE_IS_ATTACHED)
- C51 COMPILER V8.02 HPI32 04/29/2007 12:48:53 PAGE 12
- 676 1 return FALSE;
- 677 1 if((len%32)!=0)
- 678 1 return FALSE;
- 679 1 if((len+32)>DeviceInfo.BPB_BytesPerSec)
- 680 1 return FALSE;
- 681 1
- 682 1 ThisFile.bFileOpen=0;
- 683 1 ThisFile.FatSectorPointer=0;
- 684 1
- 685 1 cnum=GetFreeCusterNum32();
- 686 1 if(cnum<0x02)
- 687 1 return FALSE;
- 688 1
- 689 1 pBuffer[11]=0x10;
- 690 1 pBuffer[21]=(unsigned char)(cnum>>24);
- 691 1 pBuffer[20]=(unsigned char)(cnum>>16);
- 692 1 pBuffer[27]=(unsigned char)(cnum>>8);
- 693 1 pBuffer[26]=(unsigned char)(cnum);
- 694 1 pBuffer[28]=0;pBuffer[29]=0;pBuffer[30]=0;pBuffer[31]=0;
- 695 1 bstop=0;
- 696 1
- 697 1 NowCluster32=DirStartCluster32;
- 698 1 do
- 699 1 {
- 700 2 NowSector=FirstSectorofCluster32(NowCluster32);
- 701 2 ClusterPointer=NowCluster32;
- 702 2 for(sector=0;sector<DeviceInfo.BPB_SecPerClus;sector++)
- 703 2 {
- 704 3 if(!SdReadSector(NowSector+sector,1,DBUF))
- 705 3 return FALSE;
- 706 3 DirCount=0;bwrite=0;
- 707 3 for(i=0;i<DeviceInfo.BPB_BytesPerSec;i=i+32)
- 708 3 {
- 709 4 if(len==0)
- 710 4 {
- 711 5 if((DBUF[i]==0x00)||(DBUF[i]==0xE5))
- 712 5 {
- 713 6 for(j=0;j<32;j++)
- 714 6 DBUF[i+j]=*(pBuffer+j);
- 715 6 if(!SdWriteSector(NowSector+sector,1,DBUF))
- 716 6 return FALSE;
- 717 6 bstop=1;
- 718 6 break;
- 719 6 }
- 720 5 }
- 721 4 else
- 722 4 {
- 723 5 if(DirCount==0)
- 724 5 InByte=i;
- 725 5 if(DBUF[i]==0xE5)
- 726 5 DirCount++;
- 727 5 else if(DBUF[i]==0x00)
- 728 5 {
- 729 6 DirCount++;
- 730 6 DBUF[i]=0xE5;
- 731 6 bwrite=1;
- 732 6 }
- 733 5 else
- 734 5 DirCount=0;
- 735 5
- 736 5 if((DirCount*32)>=(len+32))
- 737 5 {
- C51 COMPILER V8.02 HPI32 04/29/2007 12:48:53 PAGE 13
- 738 6 for(j=0;j<len;j++)
- 739 6 DBUF[InByte+j]=*(pName+j);
- 740 6 for(j=0;j<32;j++)
- 741 6 DBUF[InByte+len+j]=*(pBuffer+j);
- 742 6 if(!SdWriteSector(NowSector+sector,1,DBUF))
- 743 6 return FALSE;
- 744 6 bstop=1;
- 745 6 break;
- 746 6 }
- 747 5 }
- 748 4 }
- 749 3 if(bstop==1)break;
- 750 3 if((len!=0)&&(bwrite==1))
- 751 3 {
- 752 4 if(!SdWriteSector(NowSector+sector,1,DBUF))
- 753 4 return FALSE;
- 754 4 }
- 755 3 }
- 756 2 if(bstop==1)break;
- 757 2
- 758 2 NowCluster32=GetNextClusterNum32(NowCluster32);
- 759 2 if(NowCluster32>DeviceInfo.TotCluster)
- 760 2 {
- 761 3 NowCluster32=CreateClusterLink32(ClusterPointer);
- 762 3 if(NowCluster32==0x00)
- 763 3 return FALSE;
- 764 3 NowSector=FirstSectorofCluster32(NowCluster32);
- 765 3 for(i=0;i<DeviceInfo.BPB_BytesPerSec;i++) DBUF[i]=0x00;
- 766 3 for(sector=0;sector<DeviceInfo.BPB_SecPerClus;sector++)
- 767 3 {
- 768 4 if(!SdWriteSector(NowSector+sector,1,DBUF))
- 769 4 return FALSE;
- 770 4 }
- 771 3 }
- 772 2 }while(NowCluster32<=DeviceInfo.TotCluster);
- 773 1
- 774 1 if(NowCluster32>DeviceInfo.TotCluster)
- 775 1 return FALSE;
- 776 1 ////////////////////////////////////////////////////////////////
- 777 1 for(i=64;i<DeviceInfo.BPB_BytesPerSec;i++) DBUF[i]=0x00;
- 778 1
- 779 1 for(i=0;i<43;i++) DBUF[i]=0x20;
- 780 1
- 781 1 DBUF[0]=0x2e;
- 782 1 for(i=11;i<32;i++) DBUF[i]=pBuffer[i];
- 783 1
- 784 1 DBUF[32]=0x2e;DBUF[33]=0x2e;
- 785 1 for(i=43;i<64;i++) DBUF[i]=pBuffer[i-32];
- 786 1
- 787 1 if(DirStartCluster32==DeviceInfo.RootStartCluster) //Root Dir
- 788 1 {
- 789 2 DBUF[53]=0;DBUF[52]=0;DBUF[59]=0;DBUF[58]=0;
- 790 2 }
- 791 1 else
- 792 1 {
- 793 2 DBUF[53]=(unsigned char)(DirStartCluster32>>24);
- 794 2 DBUF[52]=(unsigned char)(DirStartCluster32>>16);
- 795 2 DBUF[59]=(unsigned char)(DirStartCluster32>>8);
- 796 2 DBUF[58]=(unsigned char)(DirStartCluster32);
- 797 2 }
- 798 1
- 799 1 NowSector=FirstSectorofCluster32(cnum);
- C51 COMPILER V8.02 HPI32 04/29/2007 12:48:53 PAGE 14
- 800 1 if(!SdWriteSector(NowSector,1,DBUF))
- 801 1 return FALSE;
- 802 1
- 803 1 DirStartCluster32=cnum;
- 804 1 // ThisFile.ClusterPointer=DirStartCluster32;
- 805 1 ThisFile.ClusterPointer=0;
- 806 1 return TRUE;
- 807 1 }
- 808
- 809 unsigned char DownDir32(unsigned char *pBuffer)
- 810 {
- 811 1 unsigned int i;
- 812 1 unsigned char j,bstop,sector;
- 813 1
- 814 1 if(!bFlags.bits.SLAVE_IS_ATTACHED)
- 815 1 return FALSE;
- 816 1
- 817 1 ThisFile.bFileOpen=0;
- 818 1 bstop=0;
- 819 1
- 820 1 NowCluster32=DirStartCluster32;
- 821 1 do
- 822 1 {
- 823 2 NowSector=FirstSectorofCluster32(NowCluster32);
- 824 2 for(sector=0;sector<DeviceInfo.BPB_SecPerClus;sector++)
- 825 2 {
- 826 3 if(!SdReadSector(NowSector+sector,1,DBUF))
- 827 3 return FALSE;
- 828 3 for(i=0;i<DeviceInfo.BPB_BytesPerSec;i=i+32)
- 829 3 {
- 830 4 if(DBUF[i]==0x00)
- 831 4 return FALSE;
- 832 4 j=0;
- 833 4 while(DBUF[i+j]==*(pBuffer+j))
- 834 4 {
- 835 5 j=j+1;
- 836 5 if(j>10)
- 837 5 break;
- 838 5 }
- 839 4 if(j>10&&(DBUF[i+11]&0x10))
- 840 4 {bstop=1;break;}
- 841 4 }
- 842 3 if(bstop==1)break;
- 843 3 }
- 844 2 if(bstop==1)break;
- 845 2 NowCluster32=GetNextClusterNum32(NowCluster32);
- 846 2 }while(NowCluster32<=DeviceInfo.TotCluster);
- 847 1
- 848 1 if(NowCluster32>DeviceInfo.TotCluster)
- 849 1 return FALSE;
- 850 1
- 851 1 DirStartCluster32=LSwapINT32(DBUF[i+26],DBUF[i+27],DBUF[i+20],DBUF[i+21]);
- 852 1 // ThisFile.ClusterPointer=DirStartCluster32;
- 853 1 ThisFile.ClusterPointer=0;
- 854 1 return TRUE;
- 855 1 }
- 856
- 857 unsigned char UpDir32()
- 858 {
- 859 1 if(!bFlags.bits.SLAVE_IS_ATTACHED)
- 860 1 return FALSE;
- 861 1 if(DirStartCluster32==DeviceInfo.RootStartCluster) //Root Dir
- C51 COMPILER V8.02 HPI32 04/29/2007 12:48:53 PAGE 15
- 862 1 return TRUE;
- 863 1
- 864 1 ThisFile.bFileOpen=0;
- 865 1
- 866 1 NowSector=FirstSectorofCluster32(DirStartCluster32);
- 867 1 if(!SdReadSector(NowSector,1,DBUF))
- 868 1 return FALSE;
- 869 1 if(DBUF[32]!=0x2e&&DBUF[33]!=0x2e) //..
- 870 1 return FALSE;
- 871 1
- 872 1 DirStartCluster32=LSwapINT32(DBUF[58],DBUF[59],DBUF[52],DBUF[53]);
- 873 1 if(DirStartCluster32==0) //Root Dir
- 874 1 DirStartCluster32=DeviceInfo.RootStartCluster;
- 875 1 // ThisFile.ClusterPointer=DirStartCluster32;
- 876 1 ThisFile.ClusterPointer=0;
- 877 1 return TRUE;
- 878 1 }
- 879
- 880 unsigned char UpRootDir32()
- 881 {
- 882 1 if(!bFlags.bits.SLAVE_IS_ATTACHED)
- 883 1 return FALSE;
- 884 1
- 885 1 ThisFile.bFileOpen=0;
- 886 1 DirStartCluster32=DeviceInfo.RootStartCluster; //Root Dir
- 887 1
- 888 1 return TRUE;
- 889 1 }
- 890
- MODULE INFORMATION: STATIC OVERLAYABLE
- CODE SIZE = 8682 ----
- CONSTANT SIZE = ---- ----
- XDATA SIZE = 8 6
- PDATA SIZE = ---- ----
- DATA SIZE = ---- 136
- IDATA SIZE = ---- ----
- BIT SIZE = ---- ----
- END OF MODULE INFORMATION.
- C51 COMPILATION COMPLETE. 0 WARNING(S), 0 ERROR(S)