HPI.LST
资源名称:51-SD.rar [点击查看]
上传用户:jcsy2001
上传日期:2013-11-29
资源大小:201k
文件大小:76k
源码类别:
嵌入式/单片机编程
开发平台:
C/C++
- C51 COMPILER V8.02 HPI 04/29/2007 12:48:53 PAGE 1
- C51 COMPILER V8.02, COMPILATION OF MODULE HPI
- OBJECT MODULE PLACED IN HPI.OBJ
- COMPILER INVOKED BY: D:KeilC51BINC51.EXE HPI.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 unsigned char xdata UARTBUF[UARTBUF_LENGTH];
- 13 SYS_INFO_BLOCK xdata DeviceInfo;
- 14 FILE_INFO xdata ThisFile;
- 15
- 16 Command_Def xdata Command;
- 17 Response_Def xdata Response;
- 18
- 19 unsigned int xdata DirStartCluster,NowCluster;
- 20 unsigned long xdata NowSector;
- 21 ShowFileName_Def xdata ShowFileName[MaxLFNum]; //long file struct
- 22 /////////////////////////////////////////////
- 23
- 24 void UartSendRsp(void)
- 25 {
- 26 1 unsigned int i;
- 27 1 unsigned char *pBuf=(unsigned char *)&Response;
- 28 1 MCU_LED4=0;
- 29 1 for(i=0;i<5;i++)
- 30 1 ComSendByte(*(pBuf+i));
- 31 1
- 32 1 if(Response.len!=0)
- 33 1 {
- 34 2 for(i=0;i<Response.len;i++)
- 35 2 ComSendByte(UARTBUF[i]);
- 36 2 }
- 37 1 MCU_LED4=1;
- 38 1 }
- 39
- 40 unsigned char UartHandler(void)
- 41 {
- 42 1 Response.Result=0;Response.len=0;
- 43 1 switch(Command.CLass)
- 44 1 {
- 45 2 case 0x00: //List
- 46 2 Response.Result=List();
- 47 2 break;
- 48 2 case 0x01: //Open File
- 49 2 Response.Result=OpenFile(Command.Parameter);
- 50 2 break;
- 51 2 case 0x02: //Read File
- 52 2 Response.Result=ReadFile(Command.len,UARTBUF);
- 53 2 break;
- 54 2 case 0x03: //Set Pointer
- 55 2 Response.Result=SetFilePointer(Command.len);
- C51 COMPILER V8.02 HPI 04/29/2007 12:48:53 PAGE 2
- 56 2 break;
- 57 2 case 0x04: //Great File
- 58 2 Response.Result=OpenFile(Command.Parameter);
- 59 2 if(Response.Result)
- 60 2 {
- 61 3 Response.Result=SetFilePointer(ThisFile.LengthInByte);
- 62 3 }
- 63 2 else
- 64 2 Response.Result=CreateFile(Command.len,Command.Parameter,UARTBUF);
- 65 2 break;
- 66 2 case 0x05: //Write File
- 67 2 Response.Result=WriteFile(Command.len,UARTBUF);
- 68 2 break;
- 69 2 case 0x06: //Remove File
- 70 2 ThisFile.bFileOpen=0;
- 71 2 Response.Result=RemoveFile(Command.Parameter);
- 72 2 break;
- 73 2 case 0x07: //Get Space
- 74 2 Response.Result=GetCapacity();
- 75 2 break;
- 76 2 case 0x08: //DetectDisk
- 77 2 if(bFlags.bits.SLAVE_IS_ATTACHED)
- 78 2 Response.Result=1;
- 79 2 break;
- 80 2 case 0x09: //Great Dir
- 81 2 Response.Result=DownDir(Command.Parameter);
- 82 2 if(!Response.Result)
- 83 2 Response.Result=CreateDir(Command.len,Command.Parameter,UARTBUF);
- 84 2 break;
- 85 2 case 0x0a: //Down Dir
- 86 2 Response.Result=DownDir(Command.Parameter);
- 87 2 break;
- 88 2 case 0x0b: //Up Dir
- 89 2 Response.Result=UpDir();
- 90 2 break;
- 91 2 case 0x0c: //Up RootDir
- 92 2 Response.Result=UpRootDir();
- 93 2 break;
- 94 2 }
- 95 1
- 96 1 UartSendRsp();
- 97 1 ///////////////////////////////
- 98 1 return TRUE;
- 99 1 }
- 100
- 101 unsigned char List(void)
- 102 {
- 103 1 unsigned int item,i;
- 104 1 unsigned char k,bstop,sector;
- 105 1 unsigned char Lcount,Ncount,base;
- 106 1
- 107 1 if(!bFlags.bits.SLAVE_IS_ATTACHED)
- 108 1 return FALSE;
- 109 1 item=0;
- 110 1 bstop=0;
- 111 1 ////////////////////////////////////
- 112 1 Lcount=0;
- 113 1 for(i=0;i<MaxLFNum;i++)
- 114 1 {
- 115 2 ShowFileName[i].LongName[0]=0x00;
- 116 2 ShowFileName[i].LongName[1]=0x00;
- 117 2 }
- C51 COMPILER V8.02 HPI 04/29/2007 12:48:53 PAGE 3
- 118 1 /////////////////////////////////////
- 119 1
- 120 1 if(DirStartCluster==0) //Root Dir
- 121 1 {
- 122 2 for(sector=0;sector<DeviceInfo.BPB_RootEntCnt;sector++)
- 123 2 {
- 124 3 if(!SdReadSector(DeviceInfo.RootStartSector+sector,1,DBUF))
- 125 3 return FALSE;
- 126 3 for(i=0;i<DeviceInfo.BPB_BytesPerSec;i=i+32)
- 127 3 {
- 128 4 if(DBUF[i]==0x00)
- 129 4 {bstop=1;
- 130 5 break;}
- 131 4 else if(DBUF[i]==0xE5)
- 132 4 continue;
- 133 4 else
- 134 4 {
- 135 5 for(k=0;k<32;k++)
- 136 5 UARTBUF[item*32+k]=DBUF[i+k];
- 137 5 item=item+1;
- 138 5 if(item>=(UARTBUF_LENGTH/32)) {bstop=1;break;} //串口缓冲 只能有512项目录,强行结束
- 139 5 /////////////////////////////////
- 140 5 if(Lcount<MaxLFNum)
- 141 5 {
- 142 6 if(DBUF[i+11]==0x0F)
- 143 6 {
- 144 7 base=((DBUF[i]&0x1F)-1)*26;
- 145 7 if(base<=224)
- 146 7 {
- 147 8 Ncount=0;
- 148 8 for(k=1;k<11;k++)
- 149 8 {
- 150 9 ShowFileName[Lcount].LongName[base+Ncount]=DBUF[i+k];
- 151 9 Ncount++;
- 152 9 }
- 153 8 for(k=14;k<26;k++)
- 154 8 {
- 155 9 ShowFileName[Lcount].LongName[base+Ncount]=DBUF[i+k];
- 156 9 Ncount++;
- 157 9 }
- 158 8 for(k=28;k<32;k++)
- 159 8 {
- 160 9 ShowFileName[Lcount].LongName[base+Ncount]=DBUF[i+k];
- 161 9 Ncount++;
- 162 9 }
- 163 8 }
- 164 7 }
- 165 6 else
- 166 6 {
- 167 7 for(k=0;k<32;k++)
- 168 7 ShowFileName[Lcount].item[k]=DBUF[i+k];
- 169 7 Lcount++;
- 170 7 }
- 171 6 }//if(Lcount<MaxLFNum)
- 172 5 /////////////////////////////////
- 173 5 }
- 174 4 }
- 175 3
- 176 3 if(bstop==1)break;
- 177 3 }
- 178 2 Response.len=item*32;
- 179 2 return TRUE;
- C51 COMPILER V8.02 HPI 04/29/2007 12:48:53 PAGE 4
- 180 2 }
- 181 1 //////////////////////////////////////////////////////////////////
- 182 1 else //Son Dir
- 183 1 {
- 184 2 NowCluster=DirStartCluster;
- 185 2 do
- 186 2 {
- 187 3 NowSector=FirstSectorofCluster(NowCluster);
- 188 3 for(sector=0;sector<DeviceInfo.BPB_SecPerClus;sector++)
- 189 3 {
- 190 4 if(!SdReadSector(NowSector+sector,1,DBUF))
- 191 4 return FALSE;
- 192 4 for(i=0;i<DeviceInfo.BPB_BytesPerSec;i=i+32)
- 193 4 {
- 194 5 if(DBUF[i]==0x00)
- 195 5 {bstop=1;break;}
- 196 5 else if(DBUF[i]==0xE5)
- 197 5 continue;
- 198 5 else
- 199 5 {
- 200 6 for(k=0;k<32;k++)
- 201 6 UARTBUF[item*32+k]=DBUF[i+k];
- 202 6 item=item+1;
- 203 6 /////////////////////////////////
- 204 6 if(DBUF[i+11]==0x0F)
- 205 6 {
- 206 7 base=((DBUF[i]&0x1F)-1)*26;
- 207 7 if(base<=224)
- 208 7 {
- 209 8 Ncount=0;
- 210 8 for(k=1;k<11;k++)
- 211 8 {
- 212 9 ShowFileName[Lcount].LongName[base+Ncount]=DBUF[i+k];
- 213 9 Ncount++;
- 214 9 }
- 215 8 for(k=14;k<26;k++)
- 216 8 {
- 217 9 ShowFileName[Lcount].LongName[base+Ncount]=DBUF[i+k];
- 218 9 Ncount++;
- 219 9 }
- 220 8 for(k=28;k<32;k++)
- 221 8 {
- 222 9 ShowFileName[Lcount].LongName[base+Ncount]=DBUF[i+k];
- 223 9 Ncount++;
- 224 9 }
- 225 8 }
- 226 7 }
- 227 6 else
- 228 6 {
- 229 7 for(k=0;k<32;k++)
- 230 7 ShowFileName[Lcount].item[k]=DBUF[i+k];
- 231 7 Lcount++;
- 232 7 }
- 233 6 /////////////////////////////////
- 234 6 }
- 235 5 }
- 236 4 if(bstop==1)break;
- 237 4 }
- 238 3
- 239 3 if(bstop==1)break;
- 240 3
- 241 3 NowCluster=GetNextClusterNum(NowCluster);
- C51 COMPILER V8.02 HPI 04/29/2007 12:48:53 PAGE 5
- 242 3
- 243 3 }while(NowCluster<=0xffef);
- 244 2
- 245 2 Response.len=item*32;
- 246 2 return TRUE;
- 247 2 }
- 248 1 }
- 249
- 250 unsigned char OpenFile(unsigned char *pBuffer)
- 251 {
- 252 1 unsigned int i;
- 253 1 unsigned char j,bstop,sector;
- 254 1
- 255 1 if(!bFlags.bits.SLAVE_IS_ATTACHED)
- 256 1 return FALSE;
- 257 1 ThisFile.bFileOpen=0;
- 258 1
- 259 1 if(DirStartCluster==0) //Root Dir
- 260 1 {
- 261 2 for(sector=0;sector<DeviceInfo.BPB_RootEntCnt;sector++)
- 262 2 {
- 263 3 if(!SdReadSector(DeviceInfo.RootStartSector+sector,1,DBUF))
- 264 3 return FALSE;
- 265 3 for(i=0;i<DeviceInfo.BPB_BytesPerSec;i=i+32)
- 266 3 {
- 267 4 if(DBUF[i]==0x00)
- 268 4 return FALSE;
- 269 4 j=0;
- 270 4 while(DBUF[i+j]==*(pBuffer+j))
- 271 4 {
- 272 5 j=j+1;
- 273 5 if(j>10)
- 274 5 break;
- 275 5 }
- 276 4
- 277 4 if(j>10&&(DBUF[i+11]&0x10)!=0x10)
- 278 4 {
- 279 5 for(j=0;j<32;j++)
- 280 5 UARTBUF[j]=DBUF[i+j];
- 281 5 bstop=1;
- 282 5 break;}
- 283 4
- 284 4 }
- 285 3 if(bstop==1)break;
- 286 3 }
- 287 2
- 288 2 if(sector>=DeviceInfo.BPB_RootEntCnt)
- 289 2 return FALSE;
- 290 2 }
- 291 1 ///////////////////////////////////////////////////////////////////////////////////////
- 292 1 else
- 293 1 {
- 294 2 NowCluster=DirStartCluster;
- 295 2 do
- 296 2 {
- 297 3 NowSector=FirstSectorofCluster(NowCluster);
- 298 3 for(sector=0;sector<DeviceInfo.BPB_SecPerClus;sector++)
- 299 3 {
- 300 4 if(!SdReadSector(NowSector+sector,1,DBUF))
- 301 4 return FALSE;
- 302 4 for(i=0;i<DeviceInfo.BPB_BytesPerSec;i=i+32)
- 303 4 {
- C51 COMPILER V8.02 HPI 04/29/2007 12:48:53 PAGE 6
- 304 5 if(DBUF[i]==0x00)
- 305 5 return FALSE;
- 306 5 j=0;
- 307 5 while(DBUF[i+j]==*(pBuffer+j))
- 308 5 {
- 309 6 j=j+1;
- 310 6 if(j>10)
- 311 6 break;
- 312 6 }
- 313 5 if(j>10&&(DBUF[i+11]&0x10)!=0x10)
- 314 5 {
- 315 6 for(j=0;j<32;j++)
- 316 6 UARTBUF[j]=DBUF[i+j];
- 317 6 bstop=1;
- 318 6 break;
- 319 6 }
- 320 5 }
- 321 4 if(bstop==1)break;
- 322 4 }
- 323 3 if(bstop==1)break;
- 324 3 NowCluster=GetNextClusterNum(NowCluster);
- 325 3 }while(NowCluster<=0xffef);
- 326 2
- 327 2 if(NowCluster>0xffef)
- 328 2 return FALSE;
- 329 2 }
- 330 1
- 331 1 ThisFile.bFileOpen=1;
- 332 1 ThisFile.StartCluster=LSwapINT16(UARTBUF[26],UARTBUF[27]);
- 333 1 ThisFile.LengthInByte=LSwapINT32(UARTBUF[28],UARTBUF[29],UARTBUF[30],UARTBUF[31]);
- 334 1 ThisFile.ClusterPointer=ThisFile.StartCluster;
- 335 1 ThisFile.SectorPointer=FirstSectorofCluster(ThisFile.StartCluster);
- 336 1 ThisFile.OffsetofSector=0;
- 337 1 ThisFile.SectorofCluster=0;
- 338 1 ThisFile.FatSectorPointer=0;
- 339 1 ThisFile.pointer=0;
- 340 1
- 341 1 Response.len=32;
- 342 1 return TRUE;
- 343 1 }
- 344
- 345 unsigned char ReadFile(unsigned long readLength,unsigned char *pBuffer)
- 346 {
- 347 1
- 348 1 unsigned int len,i;
- 349 1 unsigned int tlen;
- 350 1 unsigned long blen;
- 351 1
- 352 1 if(!bFlags.bits.SLAVE_IS_ATTACHED)
- 353 1 return FALSE;
- 354 1 if(!ThisFile.bFileOpen)
- 355 1 return FALSE;
- 356 1
- 357 1 blen=readLength;
- 358 1
- 359 1 tlen=0;
- 360 1 if(readLength>MAX_READ_LENGTH)
- 361 1 return FALSE;
- 362 1
- 363 1 if(readLength+ThisFile.pointer>ThisFile.LengthInByte)
- 364 1 return FALSE;
- 365 1
- C51 COMPILER V8.02 HPI 04/29/2007 12:48:53 PAGE 7
- 366 1 ////////////////////////////////////////////
- 367 1 while(readLength>0)
- 368 1 {
- 369 2 if(readLength+ThisFile.OffsetofSector>DeviceInfo.BPB_BytesPerSec)
- 370 2 len=DeviceInfo.BPB_BytesPerSec;
- 371 2 else
- 372 2 len=readLength+ThisFile.OffsetofSector;
- 373 2
- 374 2 //////////////////////////////////////////////////////
- 375 2 if(ThisFile.OffsetofSector>0)
- 376 2 {
- 377 3 if(SdReadSector(ThisFile.SectorPointer,1,DBUF))
- 378 3 {
- 379 4
- 380 4 len=len-ThisFile.OffsetofSector;
- 381 4 for(i=0;i<len;i++)
- 382 4
- 383 4 *(pBuffer+i)=DBUF[ThisFile.OffsetofSector+i];
- 384 4 ThisFile.OffsetofSector=ThisFile.OffsetofSector+len;
- 385 4 }
- 386 3 else
- 387 3 return FALSE;
- 388 3 }
- 389 2 else
- 390 2 {
- 391 3 if(!SdReadSector(ThisFile.SectorPointer,1,pBuffer+tlen))
- 392 3 return FALSE;
- 393 3 ThisFile.OffsetofSector=len;
- 394 3 }
- 395 2 ////////////////////////////////////////////////////////////
- 396 2 readLength-=len;
- 397 2 tlen+=len;
- 398 2
- 399 2 /////////////////////////////////////////////////////////
- 400 2 if(ThisFile.OffsetofSector>DeviceInfo.BPB_BytesPerSec-1)
- 401 2 {
- 402 3 ThisFile.OffsetofSector-=DeviceInfo.BPB_BytesPerSec;
- 403 3 ThisFile.SectorofCluster+=1;
- 404 3 if(ThisFile.SectorofCluster>DeviceInfo.BPB_SecPerClus-1)
- 405 3 {
- 406 4 ThisFile.SectorofCluster=0;
- 407 4 ThisFile.ClusterPointer=GetNextClusterNum(ThisFile.ClusterPointer);
- 408 4 if(ThisFile.ClusterPointer>0xffef)
- 409 4 return FALSE;
- 410 4 ThisFile.SectorPointer=FirstSectorofCluster(ThisFile.ClusterPointer);
- 411 4 }
- 412 3 else
- 413 3 ThisFile.SectorPointer=ThisFile.SectorPointer+1;
- 414 3 }
- 415 2 //////////////////////////////////////////////////////////////////
- 416 2 }//end while
- 417 1
- 418 1 ThisFile.bFileOpen=1;
- 419 1 ThisFile.pointer+=tlen;
- 420 1 //////////////////////////////////////////////
- 421 1 Response.len=blen;
- 422 1
- 423 1 return TRUE;
- 424 1 }
- 425
- 426 unsigned char SetFilePointer(unsigned long pointer)
- 427 {
- C51 COMPILER V8.02 HPI 04/29/2007 12:48:53 PAGE 8
- 428 1 if(!bFlags.bits.SLAVE_IS_ATTACHED)
- 429 1 return FALSE;
- 430 1 if(!ThisFile.bFileOpen)
- 431 1 return FALSE;
- 432 1 ///////////////////////////////////////////////////////////
- 433 1 ThisFile.pointer=pointer;
- 434 1 if(ThisFile.pointer>ThisFile.LengthInByte)
- 435 1 return FALSE;
- 436 1
- 437 1 if(!GoToPointer(ThisFile.pointer))
- 438 1 {
- 439 2 ThisFile.bFileOpen=0;
- 440 2 return FALSE;
- 441 2 }
- 442 1 //////////////////////////////////////////////
- 443 1 return TRUE;
- 444 1 }
- 445
- 446 unsigned char CreateFile(unsigned long len,unsigned char *pBuffer,unsigned char *pName)
- 447 {
- 448 1 unsigned int sector,i,j,DirCount;
- 449 1 unsigned int cnum,ClusterPointer;
- 450 1 unsigned char xdata bstop,InByte,bwrite;
- 451 1
- 452 1 if(!bFlags.bits.SLAVE_IS_ATTACHED)
- 453 1 return FALSE;
- 454 1 if((len%32)!=0)
- 455 1 return FALSE;
- 456 1 if((len+32)>DeviceInfo.BPB_BytesPerSec)
- 457 1 return FALSE;
- 458 1
- 459 1 ThisFile.bFileOpen=0;
- 460 1
- 461 1 cnum=GetFreeCusterNum();
- 462 1 if(cnum<0x02)
- 463 1 return FALSE;
- 464 1
- 465 1 pBuffer[26]=(unsigned char)(cnum);
- 466 1 pBuffer[27]=(unsigned char)(cnum>>8);
- 467 1 pBuffer[28]=0;pBuffer[29]=0;pBuffer[30]=0;pBuffer[31]=0;
- 468 1 bstop=0;
- 469 1
- 470 1 if(DirStartCluster==0)
- 471 1 {
- 472 2 /////// Search a free space in the root dir space and build the item ///
- 473 2 for(sector=0;sector<DeviceInfo.BPB_RootEntCnt;sector++)
- 474 2 {
- 475 3 if(!SdReadSector(DeviceInfo.RootStartSector+sector,1,DBUF))
- 476 3 return FALSE;
- 477 3 DirCount=0;bwrite=0;
- 478 3 for(i=0;i<DeviceInfo.BPB_BytesPerSec;i=i+32)
- 479 3 {
- 480 4 if(len==0)
- 481 4 {
- 482 5 if((DBUF[i]==0x00)||(DBUF[i]==0xE5))
- 483 5 {
- 484 6 for(j=0;j<32;j++)
- 485 6 DBUF[i+j]=*(pBuffer+j);
- 486 6 if(!SdWriteSector(DeviceInfo.RootStartSector+sector,1,DBUF))
- 487 6 return FALSE;
- 488 6 bstop=1;
- 489 6 break;
- C51 COMPILER V8.02 HPI 04/29/2007 12:48:53 PAGE 9
- 490 6 }
- 491 5 }
- 492 4 else
- 493 4 {
- 494 5 if(DirCount==0)
- 495 5 InByte=i;
- 496 5 if(DBUF[i]==0xE5)
- 497 5 DirCount++;
- 498 5 else if(DBUF[i]==0x00)
- 499 5 {
- 500 6 DirCount++;
- 501 6 DBUF[i]=0xE5;
- 502 6 bwrite=1;
- 503 6 }
- 504 5 else
- 505 5 DirCount=0;
- 506 5
- 507 5 if((DirCount*32)>=(len+32))
- 508 5 {
- 509 6 for(j=0;j<len;j++)
- 510 6 DBUF[InByte+j]=*(pName+j);
- 511 6
- 512 6 for(j=0;j<32;j++)
- 513 6 DBUF[InByte+len+j]=*(pBuffer+j);
- 514 6
- 515 6 if(!SdWriteSector(DeviceInfo.RootStartSector+sector,1,DBUF))
- 516 6 return FALSE;
- 517 6 bstop=1;
- 518 6 break;
- 519 6 }
- 520 5 }
- 521 4 }
- 522 3 if(bstop==1)break;
- 523 3
- 524 3 if((len!=0)&&(bwrite==1))
- 525 3 {
- 526 4 if(!SdWriteSector(DeviceInfo.RootStartSector+sector,1,DBUF))
- 527 4 return FALSE;
- 528 4 }
- 529 3 }
- 530 2
- 531 2 if(sector>=DeviceInfo.BPB_RootEntCnt)
- 532 2 return FALSE;
- 533 2 }
- 534 1 ////////////////////////////////////////////////////////////
- 535 1 else
- 536 1 {
- 537 2 NowCluster=DirStartCluster;
- 538 2 do
- 539 2 {
- 540 3 NowSector=FirstSectorofCluster(NowCluster);
- 541 3 ClusterPointer=NowCluster;
- 542 3 for(sector=0;sector<DeviceInfo.BPB_SecPerClus;sector++)
- 543 3 {
- 544 4 if(!SdReadSector(NowSector+sector,1,DBUF))
- 545 4 return FALSE;
- 546 4 DirCount=0;bwrite=0;
- 547 4
- 548 4 for(i=0;i<DeviceInfo.BPB_BytesPerSec;i=i+32)
- 549 4 {
- 550 5 if(len==0)
- 551 5 {
- C51 COMPILER V8.02 HPI 04/29/2007 12:48:53 PAGE 10
- 552 6 if((DBUF[i]==0x00)||(DBUF[i]==0xE5))
- 553 6 {
- 554 7 for(j=0;j<32;j++)
- 555 7 DBUF[i+j]=*(pBuffer+j);
- 556 7 if(!SdWriteSector(NowSector+sector,1,DBUF))
- 557 7 return FALSE;
- 558 7 bstop=1;
- 559 7 break;
- 560 7 }
- 561 6 }
- 562 5 else
- 563 5 {
- 564 6 if(DirCount==0)
- 565 6 InByte=i;
- 566 6 if(DBUF[i]==0xE5)
- 567 6 DirCount++;
- 568 6 else if(DBUF[i]==0x00)
- 569 6 {
- 570 7 DirCount++;
- 571 7 DBUF[i]=0xE5;
- 572 7 bwrite=1;
- 573 7 }
- 574 6 else
- 575 6 DirCount=0;
- 576 6
- 577 6 if((DirCount*32)>=(len+32))
- 578 6 {
- 579 7 for(j=0;j<len;j++)
- 580 7 DBUF[InByte+j]=*(pName+j);
- 581 7 for(j=0;j<32;j++)
- 582 7 DBUF[InByte+len+j]=*(pBuffer+j);
- 583 7 if(!SdWriteSector(NowSector+sector,1,DBUF))
- 584 7 return FALSE;
- 585 7 bstop=1;
- 586 7 break;
- 587 7 }
- 588 6 }
- 589 5 }
- 590 4 if(bstop==1)break;
- 591 4
- 592 4 if((len!=0)&&(bwrite==1))
- 593 4 {
- 594 5 if(!SdWriteSector(NowSector+sector,1,DBUF))
- 595 5 return FALSE;
- 596 5 }
- 597 4 }
- 598 3 if(bstop==1)break;
- 599 3
- 600 3 NowCluster=GetNextClusterNum(NowCluster);
- 601 3 if(NowCluster>0xffef)
- 602 3 {
- 603 4 NowCluster=CreateClusterLink(ClusterPointer);
- 604 4 if(NowCluster==0x00)
- 605 4 return FALSE;
- 606 4 NowSector=FirstSectorofCluster(NowCluster);
- 607 4 for(i=0;i<DeviceInfo.BPB_BytesPerSec;i++) DBUF[i]=0x00;
- 608 4 for(sector=0;sector<DeviceInfo.BPB_SecPerClus;sector++)
- 609 4 {
- 610 5 if(!SdWriteSector(NowSector+sector,1,DBUF))
- 611 5 return FALSE;
- 612 5 }
- 613 4 }
- C51 COMPILER V8.02 HPI 04/29/2007 12:48:53 PAGE 11
- 614 3 }while(NowCluster<=0xffef);
- 615 2
- 616 2
- 617 2 if(NowCluster>0xffef)
- 618 2 return FALSE;
- 619 2 }
- 620 1 ////////////////////////////////////////////////////////////////
- 621 1
- 622 1 ThisFile.StartCluster=cnum;
- 623 1 ThisFile.LengthInByte=0;
- 624 1 ThisFile.ClusterPointer=ThisFile.StartCluster;
- 625 1 ThisFile.SectorPointer=FirstSectorofCluster(ThisFile.StartCluster);
- 626 1 ThisFile.OffsetofSector=0;
- 627 1 ThisFile.SectorofCluster=0;
- 628 1 ThisFile.bFileOpen=1;
- 629 1 ThisFile.pointer=0;
- 630 1 ThisFile.FatSectorPointer=0;
- 631 1
- 632 1 return TRUE;
- 633 1 }
- 634
- 635 unsigned char WriteFile(unsigned long writeLength,unsigned char *pBuffer)
- 636 {
- 637 1 unsigned int len,sector,i,cnum,tlen;
- 638 1 unsigned char bSuccess,bStop;
- 639 1
- 640 1 if(!bFlags.bits.SLAVE_IS_ATTACHED)
- 641 1 return FALSE;
- 642 1 if(!ThisFile.bFileOpen)
- 643 1 return FALSE;
- 644 1 ThisFile.bFileOpen=0;
- 645 1 bSuccess=1;
- 646 1 bStop=0;
- 647 1 tlen=0;
- 648 1
- 649 1 while(writeLength>0)
- 650 1 {
- 651 2 if(writeLength+ThisFile.OffsetofSector>DeviceInfo.BPB_BytesPerSec)
- 652 2 len=DeviceInfo.BPB_BytesPerSec;
- 653 2 else
- 654 2 len=writeLength+ThisFile.OffsetofSector;
- 655 2
- 656 2 //////////////////////////////////////////////////////
- 657 2 if(ThisFile.OffsetofSector>0)
- 658 2 {
- 659 3 if(SdReadSector(ThisFile.SectorPointer,1,DBUF))
- 660 3 {
- 661 4
- 662 4 len=len-ThisFile.OffsetofSector;
- 663 4 for(i=0;i<len;i++)
- 664 4
- 665 4 DBUF[ThisFile.OffsetofSector+i]=*(pBuffer+i);
- 666 4 if(!SdWriteSector(ThisFile.SectorPointer,1,DBUF))
- 667 4 return FALSE;
- 668 4 ThisFile.OffsetofSector=ThisFile.OffsetofSector+len;
- 669 4 }
- 670 3 else
- 671 3 return FALSE;
- 672 3 }
- 673 2 else
- 674 2 {
- 675 3 if(!SdWriteSector(ThisFile.SectorPointer,1,pBuffer+tlen))
- C51 COMPILER V8.02 HPI 04/29/2007 12:48:53 PAGE 12
- 676 3 return FALSE;
- 677 3 ThisFile.OffsetofSector=len;
- 678 3 }
- 679 2 /////////////////////////////////////////////////////
- 680 2 writeLength-=len;
- 681 2 tlen+=len;
- 682 2 /////////////更新文件指针 //////////////////////////////
- 683 2 if(ThisFile.OffsetofSector>DeviceInfo.BPB_BytesPerSec-1)
- 684 2 {
- 685 3 ThisFile.OffsetofSector-=DeviceInfo.BPB_BytesPerSec;
- 686 3 ThisFile.SectorofCluster+=1;
- 687 3 if(ThisFile.SectorofCluster>DeviceInfo.BPB_SecPerClus-1)
- 688 3 {
- 689 4 ThisFile.SectorofCluster=0;
- 690 4 ThisFile.ClusterPointer=CreateClusterLink(ThisFile.ClusterPointer);
- 691 4 if(ThisFile.ClusterPointer==0x00)
- 692 4 return FALSE;
- 693 4 ThisFile.SectorPointer=FirstSectorofCluster(ThisFile.ClusterPointer);
- 694 4 }
- 695 3 else
- 696 3 ThisFile.SectorPointer=ThisFile.SectorPointer+1;
- 697 3 }
- 698 2
- 699 2
- 700 2 }//end while
- 701 1 ThisFile.pointer+=tlen;
- 702 1 DelayMs(200);
- 703 1 ///////////更新文件目录信息/////////////////////////////
- 704 1 if(bSuccess==1)
- 705 1 {
- 706 2 if(DirStartCluster==0)
- 707 2 {
- 708 3 for(sector=0;sector<DeviceInfo.BPB_RootEntCnt;sector++)
- 709 3 {
- 710 4 //////////////////////////////////////////////////
- 711 4 if(!SdReadSector(DeviceInfo.RootStartSector+sector,1,DBUF))
- 712 4 return FALSE;
- 713 4 ///////////////////////////////////////////////////
- 714 4 for(i=0;i<DeviceInfo.BPB_BytesPerSec;i=i+32)
- 715 4 {
- 716 5 cnum=LSwapINT16(DBUF[i+26],DBUF[i+27]);
- 717 5 if((cnum==ThisFile.StartCluster)&&(DBUF[i]!=0xe5))
- 718 5 {
- 719 6 if(ThisFile.pointer>ThisFile.LengthInByte)
- 720 6 ThisFile.LengthInByte=ThisFile.pointer;
- 721 6 DBUF[i+28]=(unsigned char)(ThisFile.LengthInByte&0xff);
- 722 6 DBUF[i+29]=(unsigned char)((ThisFile.LengthInByte>>8)&0xff);
- 723 6 DBUF[i+30]=(unsigned char)((ThisFile.LengthInByte>>16)&0xff);
- 724 6 DBUF[i+31]=(unsigned char)((ThisFile.LengthInByte>>24)&0xff);
- 725 6 if(!SdWriteSector(DeviceInfo.RootStartSector+sector,1,DBUF))
- 726 6 return FALSE;
- 727 6 bStop=1;
- 728 6 break;
- 729 6 }
- 730 5 }
- 731 4 if(bStop==1)
- 732 4 break;
- 733 4 }
- 734 3 }
- 735 2 //////////////////////////////////////////////////////////////////////////////
- 736 2 else
- 737 2 {
- C51 COMPILER V8.02 HPI 04/29/2007 12:48:53 PAGE 13
- 738 3 NowCluster=DirStartCluster;
- 739 3 do
- 740 3 {
- 741 4 NowSector=FirstSectorofCluster(NowCluster);
- 742 4 for(sector=0;sector<DeviceInfo.BPB_SecPerClus;sector++)
- 743 4 {
- 744 5 if(!SdReadSector(NowSector+sector,1,DBUF))
- 745 5 return FALSE;
- 746 5 for(i=0;i<DeviceInfo.BPB_BytesPerSec;i=i+32)
- 747 5 {
- 748 6 cnum=LSwapINT16(DBUF[i+26],DBUF[i+27]);
- 749 6 if((cnum==ThisFile.StartCluster)&&(DBUF[i]!=0xe5))
- 750 6 {
- 751 7 if(ThisFile.pointer>ThisFile.LengthInByte)
- 752 7 ThisFile.LengthInByte=ThisFile.pointer;
- 753 7 DBUF[i+28]=(unsigned char)(ThisFile.LengthInByte&0xff);
- 754 7 DBUF[i+29]=(unsigned char)((ThisFile.LengthInByte>>8)&0xff);
- 755 7 DBUF[i+30]=(unsigned char)((ThisFile.LengthInByte>>16)&0xff);
- 756 7 DBUF[i+31]=(unsigned char)((ThisFile.LengthInByte>>24)&0xff);
- 757 7 if(!SdWriteSector(NowSector+sector,1,DBUF))
- 758 7 return FALSE;
- 759 7 bStop=1;
- 760 7 break;
- 761 7 }
- 762 6 }
- 763 5 if(bStop==1)break;
- 764 5 }
- 765 4 if(bStop==1)break;
- 766 4 NowCluster=GetNextClusterNum(NowCluster);
- 767 4 }while(NowCluster<=0xffef);
- 768 3
- 769 3 if(NowCluster>0xffef)
- 770 3 return FALSE;
- 771 3 }
- 772 2 }
- 773 1
- 774 1 ThisFile.bFileOpen=1;
- 775 1 //////////////////////////////////////////////
- 776 1 return TRUE;
- 777 1 }
- 778
- 779 unsigned char RemoveFile(unsigned char *pBuffer)
- 780 {
- 781 1 unsigned int sector,i;
- 782 1 unsigned char bStop,j;
- 783 1 int k;
- 784 1
- 785 1 if(!bFlags.bits.SLAVE_IS_ATTACHED)
- 786 1 return FALSE;
- 787 1 if(DirStartCluster==0)
- 788 1 {
- 789 2 ////////////// 清除目录/////////////////////////////////////
- 790 2 for(sector=0;sector<DeviceInfo.BPB_RootEntCnt;sector++)
- 791 2 {
- 792 3 //////////////////////////////////////////////////
- 793 3 if(!SdReadSector(DeviceInfo.RootStartSector+sector,1,DBUF))
- 794 3 return FALSE;
- 795 3 ///////////////////////////////////////////////////
- 796 3 for(i=0;i<DeviceInfo.BPB_BytesPerSec;i=i+32)
- 797 3 {
- 798 4 if(DBUF[i]==0x00)
- 799 4 return FALSE;
- C51 COMPILER V8.02 HPI 04/29/2007 12:48:53 PAGE 14
- 800 4 ///////////////////////////////////////////
- 801 4 j=0;
- 802 4 while(DBUF[i+j]==*(pBuffer+j))
- 803 4 {
- 804 5 j=j+1;
- 805 5 if(j>10) break;
- 806 5 }
- 807 4
- 808 4 if(j>10)
- 809 4 {
- 810 5 DBUF[i]=0xE5;
- 811 5 ThisFile.StartCluster=LSwapINT16(DBUF[i+26],DBUF[i+27]);
- 812 5
- 813 5 for(k=(i-32);k>=0;k=k-32)
- 814 5 {
- 815 6 if(DBUF[k+11]==0x0F)
- 816 6 DBUF[k]=0xE5;
- 817 6 else
- 818 6 break;
- 819 6 }
- 820 5 DelayMs(15);
- 821 5 if(!SdWriteSector(DeviceInfo.RootStartSector+sector,1,DBUF))
- 822 5 return FALSE;
- 823 5 /*
- 824 5 k=sector-1;
- 825 5 if(k>=0)
- 826 5 {
- 827 5 if(!SdReadSector(DeviceInfo.RootStartSector+k,1,DBUF))
- 828 5 return FALSE;
- 829 5 for(k=DeviceInfo.BPB_BytesPerSec;k>=0;k=k-32)
- 830 5 {
- 831 5 if(DBUF[k+11]==0x0F)
- 832 5 DBUF[k]=0xE5;
- 833 5 else
- 834 5 break;
- 835 5 }
- 836 5 // DelayMs(15);
- 837 5 if(!SdWriteSector(DeviceInfo.RootStartSector+sector-1,1,DBUF))
- 838 5 return FALSE;
- 839 5 }
- 840 5 */
- 841 5 //////////////////// 清除FAT中的纪录////////////////////////
- 842 5 DelayMs(10);
- 843 5 if(!DeleteClusterLink(ThisFile.StartCluster))
- 844 5 return FALSE;
- 845 5 bStop=1;
- 846 5 break;
- 847 5 }
- 848 4
- 849 4 }//end for
- 850 3 if(bStop==1)
- 851 3 break;
- 852 3
- 853 3 }//end search
- 854 2 if(sector>=DeviceInfo.BPB_RootEntCnt)
- 855 2 return FALSE;
- 856 2 }
- 857 1 else
- 858 1 {
- 859 2 NowCluster=DirStartCluster;
- 860 2 do
- 861 2 {
- C51 COMPILER V8.02 HPI 04/29/2007 12:48:53 PAGE 15
- 862 3 NowSector=FirstSectorofCluster(NowCluster);
- 863 3 for(sector=0;sector<DeviceInfo.BPB_SecPerClus;sector++)
- 864 3 {
- 865 4 if(!SdReadSector(NowSector+sector,1,DBUF))
- 866 4 return FALSE;
- 867 4 for(i=0;i<DeviceInfo.BPB_BytesPerSec;i=i+32)
- 868 4 {
- 869 5 if(DBUF[i]==0x00)
- 870 5 return FALSE;
- 871 5 j=0;
- 872 5 while(DBUF[i+j]==*(pBuffer+j))
- 873 5 {
- 874 6 j=j+1;
- 875 6 if(j>10)
- 876 6 break;
- 877 6 }
- 878 5 if(j>10)
- 879 5 {
- 880 6 DBUF[i]=0xE5;
- 881 6 ThisFile.StartCluster=LSwapINT16(DBUF[i+26],DBUF[i+27]);
- 882 6 for(k=(i-32);k>=0;k=k-32)
- 883 6 {
- 884 7 if(DBUF[k+11]==0x0F)
- 885 7 DBUF[k]=0xE5;
- 886 7 else
- 887 7 break;
- 888 7 }
- 889 6 DelayMs(15);
- 890 6 if(!SdWriteSector(NowSector+sector,1,DBUF))
- 891 6 return FALSE;
- 892 6 //////////////////// 清除FAT中的纪录////////////////////////
- 893 6 DelayMs(10);
- 894 6 if(!DeleteClusterLink(ThisFile.StartCluster))
- 895 6 return FALSE;
- 896 6 bStop=1;
- 897 6 break;
- 898 6 }
- 899 5 }
- 900 4 if(bStop==1)break;
- 901 4 }
- 902 3 if(bStop==1)break;
- 903 3 NowCluster=GetNextClusterNum(NowCluster);
- 904 3 }while(NowCluster<=0xffef);
- 905 2
- 906 2 if(NowCluster>0xffef)
- 907 2 return FALSE;
- 908 2 }
- 909 1 return TRUE;
- 910 1 }
- 911
- 912 unsigned char GetCapacity(void)
- 913 {
- 914 1 unsigned int sectorNum,i;
- 915 1 unsigned long FreeSize,Freesectorcnt;
- 916 1
- 917 1 if(!bFlags.bits.SLAVE_IS_ATTACHED)
- 918 1 return FALSE;
- 919 1
- 920 1 ////////////////////////////////////////////////////////////////////////
- 921 1 sectorNum=DeviceInfo.FatStartSector;
- 922 1 Freesectorcnt=0;
- 923 1 while(sectorNum<DeviceInfo.BPB_FATSz16+DeviceInfo.FatStartSector)
- C51 COMPILER V8.02 HPI 04/29/2007 12:48:53 PAGE 16
- 924 1 {
- 925 2
- 926 2 if(SdReadSector(sectorNum,1,DBUF))
- 927 2 {
- 928 3 for(i=0;i<DeviceInfo.BPB_BytesPerSec;i=i+2)
- 929 3 {
- 930 4 if((DBUF[i]==0x00)&&(DBUF[i+1]==0x00))
- 931 4 {
- 932 5 Freesectorcnt++;
- 933 5 }
- 934 4 }
- 935 3 }
- 936 2 else
- 937 2 return FALSE;
- 938 2 sectorNum++;
- 939 2 }
- 940 1
- 941 1 ////////////////////////////////////////////////////////////////////////
- 942 1 FreeSize=DeviceInfo.BPB_BytesPerSec*DeviceInfo.BPB_SecPerClus;
- 943 1 FreeSize=Freesectorcnt*FreeSize;
- 944 1
- 945 1 UARTBUF[0]=(unsigned char)((FreeSize>>24)&0xff);
- 946 1 UARTBUF[1]=(unsigned char)((FreeSize>>16)&0xff);
- 947 1 UARTBUF[2]=(unsigned char)((FreeSize>>8)&0xff);
- 948 1 UARTBUF[3]=(unsigned char)(FreeSize&0xff);
- 949 1 Response.len=4;
- 950 1 return TRUE;
- 951 1 }
- 952
- 953 unsigned char CreateDir(unsigned long len,unsigned char *pBuffer,unsigned char *pName)
- 954 {
- 955 1 unsigned int sector,i,j,DirCount;
- 956 1 unsigned int cnum,ClusterPointer;
- 957 1 unsigned char xdata bstop,InByte,bwrite;
- 958 1
- 959 1 if(!bFlags.bits.SLAVE_IS_ATTACHED)
- 960 1 return FALSE;
- 961 1 if((len%32)!=0)
- 962 1 return FALSE;
- 963 1 if((len+32)>DeviceInfo.BPB_BytesPerSec)
- 964 1 return FALSE;
- 965 1
- 966 1 ThisFile.bFileOpen=0;
- 967 1 ThisFile.FatSectorPointer=0;
- 968 1
- 969 1 cnum=GetFreeCusterNum();
- 970 1 if(cnum<0x02)
- 971 1 return FALSE;
- 972 1
- 973 1 pBuffer[11]=0x10;
- 974 1 pBuffer[26]=(unsigned char)(cnum);
- 975 1 pBuffer[27]=(unsigned char)(cnum>>8);
- 976 1 pBuffer[28]=0;pBuffer[29]=0;pBuffer[30]=0;pBuffer[31]=0;
- 977 1 bstop=0;
- 978 1
- 979 1 if(DirStartCluster==0)
- 980 1 {
- 981 2 /////// Search a free space in the root dir space and build the item ///
- 982 2 for(sector=0;sector<DeviceInfo.BPB_RootEntCnt;sector++)
- 983 2 {
- 984 3 if(!SdReadSector(DeviceInfo.RootStartSector+sector,1,DBUF))
- 985 3 return FALSE;
- C51 COMPILER V8.02 HPI 04/29/2007 12:48:53 PAGE 17
- 986 3 DirCount=0;bwrite=0;
- 987 3 for(i=0;i<DeviceInfo.BPB_BytesPerSec;i=i+32)
- 988 3 {
- 989 4 if(len==0)
- 990 4 {
- 991 5 if((DBUF[i]==0x00)||(DBUF[i]==0xE5))
- 992 5 {
- 993 6 for(j=0;j<32;j++)
- 994 6 DBUF[i+j]=*(pBuffer+j);
- 995 6 if(!SdWriteSector(DeviceInfo.RootStartSector+sector,1,DBUF))
- 996 6 return FALSE;
- 997 6 bstop=1;
- 998 6 break;
- 999 6 }
- 1000 5 }
- 1001 4 else
- 1002 4 {
- 1003 5 if(DirCount==0)
- 1004 5 InByte=i;
- 1005 5 if(DBUF[i]==0xE5)
- 1006 5 DirCount++;
- 1007 5 else if(DBUF[i]==0x00)
- 1008 5 {
- 1009 6 DirCount++;
- 1010 6 DBUF[i]=0xE5;
- 1011 6 bwrite=1;
- 1012 6 }
- 1013 5 else
- 1014 5 DirCount=0;
- 1015 5
- 1016 5 if((DirCount*32)>=(len+32))
- 1017 5 {
- 1018 6 for(j=0;j<len;j++)
- 1019 6 DBUF[InByte+j]=*(pName+j);
- 1020 6
- 1021 6 for(j=0;j<32;j++)
- 1022 6 DBUF[InByte+len+j]=*(pBuffer+j);
- 1023 6
- 1024 6 if(!SdWriteSector(DeviceInfo.RootStartSector+sector,1,DBUF))
- 1025 6 return FALSE;
- 1026 6 bstop=1;
- 1027 6 break;
- 1028 6 }
- 1029 5 }
- 1030 4 }
- 1031 3 if(bstop==1)break;
- 1032 3
- 1033 3 if((len!=0)&&(bwrite==1))
- 1034 3 {
- 1035 4 if(!SdWriteSector(DeviceInfo.RootStartSector+sector,1,DBUF))
- 1036 4 return FALSE;
- 1037 4 }
- 1038 3 }
- 1039 2
- 1040 2 if(sector>=DeviceInfo.BPB_RootEntCnt)
- 1041 2 return FALSE;
- 1042 2 }
- 1043 1 ////////////////////////////////////////////////////////////
- 1044 1 else
- 1045 1 {
- 1046 2 NowCluster=DirStartCluster;
- 1047 2 do
- C51 COMPILER V8.02 HPI 04/29/2007 12:48:53 PAGE 18
- 1048 2 {
- 1049 3 NowSector=FirstSectorofCluster(NowCluster);
- 1050 3 ClusterPointer=NowCluster;
- 1051 3 for(sector=0;sector<DeviceInfo.BPB_SecPerClus;sector++)
- 1052 3 {
- 1053 4 if(!SdReadSector(NowSector+sector,1,DBUF))
- 1054 4 return FALSE;
- 1055 4 DirCount=0;bwrite=0;
- 1056 4 for(i=0;i<DeviceInfo.BPB_BytesPerSec;i=i+32)
- 1057 4 {
- 1058 5 if(len==0)
- 1059 5 {
- 1060 6 if((DBUF[i]==0x00)||(DBUF[i]==0xE5))
- 1061 6 {
- 1062 7 for(j=0;j<32;j++)
- 1063 7 DBUF[i+j]=*(pBuffer+j);
- 1064 7 if(!SdWriteSector(NowSector+sector,1,DBUF))
- 1065 7 return FALSE;
- 1066 7 bstop=1;
- 1067 7 break;
- 1068 7 }
- 1069 6 }
- 1070 5 else
- 1071 5 {
- 1072 6 if(DirCount==0)
- 1073 6 InByte=i;
- 1074 6 if(DBUF[i]==0xE5)
- 1075 6 DirCount++;
- 1076 6 else if(DBUF[i]==0x00)
- 1077 6 {
- 1078 7 DirCount++;
- 1079 7 DBUF[i]=0xE5;
- 1080 7 bwrite=1;
- 1081 7 }
- 1082 6 else
- 1083 6 DirCount=0;
- 1084 6
- 1085 6 if((DirCount*32)>=(len+32))
- 1086 6 {
- 1087 7 for(j=0;j<len;j++)
- 1088 7 DBUF[InByte+j]=*(pName+j);
- 1089 7 for(j=0;j<32;j++)
- 1090 7 DBUF[InByte+len+j]=*(pBuffer+j);
- 1091 7 if(!SdWriteSector(NowSector+sector,1,DBUF))
- 1092 7 return FALSE;
- 1093 7 bstop=1;
- 1094 7 break;
- 1095 7 }
- 1096 6 }
- 1097 5 }
- 1098 4 if(bstop==1)break;
- 1099 4 if((len!=0)&&(bwrite==1))
- 1100 4 {
- 1101 5 if(!SdWriteSector(NowSector+sector,1,DBUF))
- 1102 5 return FALSE;
- 1103 5 }
- 1104 4 }
- 1105 3 if(bstop==1)break;
- 1106 3
- 1107 3 NowCluster=GetNextClusterNum(NowCluster);
- 1108 3 if(NowCluster>0xffef)
- 1109 3 {
- C51 COMPILER V8.02 HPI 04/29/2007 12:48:53 PAGE 19
- 1110 4 NowCluster=CreateClusterLink(ClusterPointer);
- 1111 4 if(NowCluster==0x00)
- 1112 4 return FALSE;
- 1113 4 NowSector=FirstSectorofCluster(NowCluster);
- 1114 4 for(i=0;i<DeviceInfo.BPB_BytesPerSec;i++) DBUF[i]=0x00;
- 1115 4 for(sector=0;sector<DeviceInfo.BPB_SecPerClus;sector++)
- 1116 4 {
- 1117 5 if(!SdWriteSector(NowSector+sector,1,DBUF))
- 1118 5 return FALSE;
- 1119 5 }
- 1120 4 }
- 1121 3 }while(NowCluster<=0xffef);
- 1122 2
- 1123 2 if(NowCluster>0xffef)
- 1124 2 return FALSE;
- 1125 2 }
- 1126 1 ////////////////////////////////////////////////////////////////
- 1127 1 for(i=64;i<DeviceInfo.BPB_BytesPerSec;i++) DBUF[i]=0x00;
- 1128 1
- 1129 1 for(i=0;i<43;i++) DBUF[i]=0x20;
- 1130 1
- 1131 1 DBUF[0]=0x2e;
- 1132 1 for(i=11;i<32;i++) DBUF[i]=pBuffer[i];
- 1133 1
- 1134 1 DBUF[32]=0x2e;DBUF[33]=0x2e;
- 1135 1 for(i=43;i<64;i++) DBUF[i]=pBuffer[i-32];
- 1136 1 DBUF[58]=(unsigned char)(DirStartCluster);
- 1137 1 DBUF[59]=(unsigned char)(DirStartCluster>>8);
- 1138 1
- 1139 1 NowSector=FirstSectorofCluster(cnum);
- 1140 1 if(!SdWriteSector(NowSector,1,DBUF))
- 1141 1 return FALSE;
- 1142 1
- 1143 1 DirStartCluster=cnum;
- 1144 1 // ThisFile.ClusterPointer=DirStartCluster;
- 1145 1 ThisFile.ClusterPointer=0;
- 1146 1 return TRUE;
- 1147 1 }
- 1148
- 1149 unsigned char DownDir(unsigned char *pBuffer)
- 1150 {
- 1151 1 unsigned int i;
- 1152 1 unsigned char j,bstop,sector;
- 1153 1
- 1154 1 if(!bFlags.bits.SLAVE_IS_ATTACHED)
- 1155 1 return FALSE;
- 1156 1
- 1157 1 ThisFile.bFileOpen=0;
- 1158 1 bstop=0;
- 1159 1
- 1160 1 if(DirStartCluster==0) //Root Dir
- 1161 1 {
- 1162 2 for(sector=0;sector<DeviceInfo.BPB_RootEntCnt;sector++)
- 1163 2 {
- 1164 3 if(!SdReadSector(DeviceInfo.RootStartSector+sector,1,DBUF))
- 1165 3 return FALSE;
- 1166 3 for(i=0;i<DeviceInfo.BPB_BytesPerSec;i=i+32)
- 1167 3 {
- 1168 4 if(DBUF[i]==0x00)
- 1169 4 return FALSE;
- 1170 4 j=0;
- 1171 4 while(DBUF[i+j]==*(pBuffer+j))
- C51 COMPILER V8.02 HPI 04/29/2007 12:48:53 PAGE 20
- 1172 4 {
- 1173 5 j=j+1;
- 1174 5 if(j>10)
- 1175 5 break;
- 1176 5 }
- 1177 4
- 1178 4 if(j>10&&(DBUF[i+11]&0x10))
- 1179 4 {
- 1180 5 bstop=1;
- 1181 5 break;}
- 1182 4
- 1183 4 }
- 1184 3 if(bstop==1)break;
- 1185 3 }
- 1186 2
- 1187 2 if(sector>=DeviceInfo.BPB_RootEntCnt)
- 1188 2 return FALSE;
- 1189 2
- 1190 2 DirStartCluster=LSwapINT16(DBUF[i+26],DBUF[i+27]);
- 1191 2 // ThisFile.ClusterPointer=DirStartCluster;
- 1192 2 ThisFile.ClusterPointer=0;
- 1193 2 return TRUE;
- 1194 2 }
- 1195 1 ////////////////////////////////////////////
- 1196 1 else
- 1197 1 {
- 1198 2 NowCluster=DirStartCluster;
- 1199 2 do
- 1200 2 {
- 1201 3 NowSector=FirstSectorofCluster(NowCluster);
- 1202 3 for(sector=0;sector<DeviceInfo.BPB_SecPerClus;sector++)
- 1203 3 {
- 1204 4 if(!SdReadSector(NowSector+sector,1,DBUF))
- 1205 4 return FALSE;
- 1206 4 for(i=0;i<DeviceInfo.BPB_BytesPerSec;i=i+32)
- 1207 4 {
- 1208 5 if(DBUF[i]==0x00)
- 1209 5 return FALSE;
- 1210 5 j=0;
- 1211 5 while(DBUF[i+j]==*(pBuffer+j))
- 1212 5 {
- 1213 6 j=j+1;
- 1214 6 if(j>10)
- 1215 6 break;
- 1216 6 }
- 1217 5 if(j>10&&(DBUF[i+11]&0x10))
- 1218 5 {bstop=1;break;}
- 1219 5 }
- 1220 4 if(bstop==1)break;
- 1221 4 }
- 1222 3 if(bstop==1)break;
- 1223 3 NowCluster=GetNextClusterNum(NowCluster);
- 1224 3 }while(NowCluster<=0xffef);
- 1225 2
- 1226 2 if(NowCluster>0xffef)
- 1227 2 return FALSE;
- 1228 2
- 1229 2 DirStartCluster=LSwapINT16(DBUF[i+26],DBUF[i+27]);
- 1230 2 // ThisFile.ClusterPointer=DirStartCluster;
- 1231 2 ThisFile.ClusterPointer=0;
- 1232 2 return TRUE;
- 1233 2 }
- C51 COMPILER V8.02 HPI 04/29/2007 12:48:53 PAGE 21
- 1234 1 }
- 1235
- 1236 unsigned char UpDir()
- 1237 {
- 1238 1 if(!bFlags.bits.SLAVE_IS_ATTACHED)
- 1239 1 return FALSE;
- 1240 1 if(DirStartCluster==0) //Root Dir
- 1241 1 return TRUE;
- 1242 1
- 1243 1 ThisFile.bFileOpen=0;
- 1244 1
- 1245 1 NowSector=FirstSectorofCluster(DirStartCluster);
- 1246 1 if(!SdReadSector(NowSector,1,DBUF))
- 1247 1 return FALSE;
- 1248 1 if(DBUF[32]!=0x2e&&DBUF[33]!=0x2e) //..
- 1249 1 return FALSE;
- 1250 1
- 1251 1 DirStartCluster=LSwapINT16(DBUF[58],DBUF[59]);
- 1252 1 // ThisFile.ClusterPointer=DirStartCluster;
- 1253 1 ThisFile.ClusterPointer=0;
- 1254 1 return TRUE;
- 1255 1 }
- 1256
- 1257 unsigned char UpRootDir()
- 1258 {
- 1259 1 if(!bFlags.bits.SLAVE_IS_ATTACHED)
- 1260 1 return FALSE;
- 1261 1
- 1262 1 ThisFile.bFileOpen=0;
- 1263 1 DirStartCluster=0; //Root Dir
- 1264 1
- 1265 1 return TRUE;
- 1266 1 }
- MODULE INFORMATION: STATIC OVERLAYABLE
- CODE SIZE = 11226 ----
- CONSTANT SIZE = ---- ----
- XDATA SIZE = 22283 6
- PDATA SIZE = ---- ----
- DATA SIZE = ---- 134
- IDATA SIZE = ---- ----
- BIT SIZE = ---- ----
- END OF MODULE INFORMATION.
- C51 COMPILATION COMPLETE. 0 WARNING(S), 0 ERROR(S)