📄 hpi32.lst
字号:
449 {
450 1 unsigned int len,sector,i,tlen;
451 1 unsigned char bSuccess,bStop;
452 1 unsigned long cnum;
453 1
454 1 if(!bFlags.bits.SLAVE_IS_ATTACHED)
455 1 return FALSE;
456 1 if(!ThisFile.bFileOpen)
457 1 return FALSE;
458 1 ThisFile.bFileOpen=0;
459 1 bSuccess=1;
460 1 bStop=0;
461 1 tlen=0;
462 1
463 1 while(writeLength>0)
464 1 {
465 2 if(writeLength+ThisFile.OffsetofSector>DeviceInfo.BPB_BytesPerSec)
466 2 len=DeviceInfo.BPB_BytesPerSec;
467 2 else
468 2 len=writeLength+ThisFile.OffsetofSector;
469 2
470 2 //////////////////////////////////////////////////////
471 2 if(ThisFile.OffsetofSector>0)
472 2 {
473 3 if(RBC_Read(ThisFile.SectorPointer,1,DBUF))
474 3 {
475 4
476 4 len=len-ThisFile.OffsetofSector;
477 4 for(i=0;i<len;i++)
478 4 DBUF[ThisFile.OffsetofSector+i]=*(pBuffer+i);
479 4 if(!RBC_Write(ThisFile.SectorPointer,1,DBUF))
480 4 return FALSE;
481 4 ThisFile.OffsetofSector=ThisFile.OffsetofSector+len;
482 4 }
483 3 else
484 3 return FALSE;
485 3 }
486 2 else
487 2 {
488 3 if(!RBC_Write(ThisFile.SectorPointer,1,pBuffer+tlen))
C51 COMPILER V7.06 HPI32 08/10/2005 23:36:35 PAGE 9
489 3 return FALSE;
490 3 ThisFile.OffsetofSector=len;
491 3 }
492 2 /////////////////////////////////////////////////////
493 2 writeLength-=len;
494 2 tlen+=len;
495 2 /////////////更新文件指针 ////////////////////////////
496 2 if(ThisFile.OffsetofSector>DeviceInfo.BPB_BytesPerSec-1)
497 2 {
498 3 ThisFile.OffsetofSector-=DeviceInfo.BPB_BytesPerSec;
499 3 ThisFile.SectorofCluster+=1;
500 3 if(ThisFile.SectorofCluster>DeviceInfo.BPB_SecPerClus-1)
501 3 {
502 4 ThisFile.SectorofCluster=0;
503 4 ThisFile.ClusterPointer=CreateClusterLink32(ThisFile.ClusterPointer);
504 4 if(ThisFile.ClusterPointer==0x00)
505 4 return FALSE;
506 4 ThisFile.SectorPointer=FirstSectorofCluster32(ThisFile.ClusterPointer);
507 4 }
508 3 else
509 3 ThisFile.SectorPointer=ThisFile.SectorPointer+1;
510 3 }
511 2
512 2
513 2 }//end while
514 1 ThisFile.pointer+=tlen;
515 1 ///////////更新文件目录信息/////////////////////////////
516 1 if(bSuccess==1)
517 1 {
518 2 NowCluster32=DirStartCluster32;
519 2 do
520 2 {
521 3 NowSector=FirstSectorofCluster32(NowCluster32);
522 3 for(sector=0;sector<DeviceInfo.BPB_SecPerClus;sector++)
523 3 {
524 4 if(!RBC_Read(NowSector+sector,1,DBUF))
525 4 return FALSE;
526 4 for(i=0;i<DeviceInfo.BPB_BytesPerSec;i=i+32)
527 4 {
528 5 cnum=LSwapINT32(DBUF[i+26],DBUF[i+27],DBUF[i+20],DBUF[i+21]);
529 5 if((cnum==ThisFile.StartCluster)&&(DBUF[i]!=0xe5))
530 5 {
531 6 if(ThisFile.pointer>ThisFile.LengthInByte)
532 6 ThisFile.LengthInByte=ThisFile.pointer;
533 6 DBUF[i+28]=(unsigned char)(ThisFile.LengthInByte&0xff);
534 6 DBUF[i+29]=(unsigned char)((ThisFile.LengthInByte>>8)&0xff);
535 6 DBUF[i+30]=(unsigned char)((ThisFile.LengthInByte>>16)&0xff);
536 6 DBUF[i+31]=(unsigned char)((ThisFile.LengthInByte>>24)&0xff);
537 6 if(!RBC_Write(NowSector+sector,1,DBUF))
538 6 return FALSE;
539 6 bStop=1;
540 6 break;
541 6 }
542 5 }
543 4 if(bStop==1)
544 4 break;
545 4 }
546 3 if(bStop==1)
547 3 break;
548 3
549 3 NowCluster32=GetNextClusterNum32(NowCluster32);
550 3 }while(NowCluster32<=DeviceInfo.TotCluster);
C51 COMPILER V7.06 HPI32 08/10/2005 23:36:35 PAGE 10
551 2
552 2 if(NowCluster32>DeviceInfo.TotCluster)
553 2 return FALSE;
554 2 }
555 1
556 1 ThisFile.bFileOpen=1;
557 1 //////////////////////////////////////////////
558 1 return TRUE;
559 1 }
560
561
562 unsigned char RemoveFile32(unsigned char *pBuffer)
563 {
564 1 unsigned int sector,i;
565 1 unsigned char bStop,j;
566 1 int k;
567 1
568 1 if(!bFlags.bits.SLAVE_IS_ATTACHED)
569 1 return FALSE;
570 1 ////////////// 清除目录/////////////////////////////////////
571 1 NowCluster32=DirStartCluster32;
572 1 do
573 1 {
574 2 NowSector=FirstSectorofCluster32(NowCluster32);
575 2 for(sector=0;sector<DeviceInfo.BPB_SecPerClus;sector++)
576 2 {
577 3 if(!RBC_Read(NowSector+sector,1,DBUF))
578 3 return FALSE;
579 3 for(i=0;i<DeviceInfo.BPB_BytesPerSec;i=i+32)
580 3 {
581 4 if(DBUF[i]==0x00)
582 4 return FALSE;
583 4 j=0;
584 4 while(DBUF[i+j]==*(pBuffer+j))
585 4 {
586 5 j=j+1;
587 5 if(j>10)
588 5 break;
589 5 }
590 4 if(j>10)
591 4 {
592 5 DBUF[i]=0xE5;
593 5 ThisFile.StartCluster=LSwapINT32(DBUF[i+26],DBUF[i+27],DBUF[i+20],DBUF[i+21]);
594 5 for(k=(i-32);k>=0;k=k-32)
595 5 {
596 6 if(DBUF[k+11]==0x0F)
597 6 DBUF[k]=0xE5;
598 6 else
599 6 break;
600 6 }
601 5 DelayMs(15);
602 5 if(!RBC_Write(NowSector+sector,1,DBUF))
603 5 return FALSE;
604 5 //////////////////// 清除FAT中的纪录////////////////////////
605 5 DelayMs(10);
606 5 if(!DeleteClusterLink32(ThisFile.StartCluster))
607 5 return FALSE;
608 5 bStop=1;
609 5 break;
610 5 }
611 4 }
612 3 if(bStop==1)break;
C51 COMPILER V7.06 HPI32 08/10/2005 23:36:35 PAGE 11
613 3 }
614 2 if(bStop==1)break;
615 2 NowCluster32=GetNextClusterNum32(NowCluster32);
616 2 }while(NowCluster32<=DeviceInfo.TotCluster);
617 1
618 1 if(NowCluster32>DeviceInfo.TotCluster)
619 1 return FALSE;
620 1
621 1 return TRUE;
622 1 }
623
624
625 unsigned char GetCapacity32(void)
626 {
627 1 unsigned int sectorNum,i;
628 1 unsigned long FreeSize,Freesectorcnt;
629 1
630 1 if(!bFlags.bits.SLAVE_IS_ATTACHED)
631 1 return FALSE;
632 1
633 1 ////////////////////////////////////////////////////////////////////////
634 1 sectorNum=DeviceInfo.FatStartSector;
635 1 Freesectorcnt=0;
636 1 while(sectorNum<DeviceInfo.BPB_FATSz32+DeviceInfo.FatStartSector)
637 1 {
638 2
639 2 if(RBC_Read(sectorNum,1,DBUF))
640 2 {
641 3 for(i=0;i<DeviceInfo.BPB_BytesPerSec;i=i+4)
642 3 {
643 4 if((DBUF[i]||DBUF[i+1]||DBUF[i+2]||DBUF[i+3])==0x00)
644 4 {
645 5 Freesectorcnt++;
646 5 }
647 4 }
648 3 }
649 2 else
650 2 return FALSE;
651 2 sectorNum++;
652 2 }
653 1
654 1 ////////////////////////////////////////////////////////////////////////
655 1 FreeSize=DeviceInfo.BPB_BytesPerSec*DeviceInfo.BPB_SecPerClus;
656 1 FreeSize=Freesectorcnt*FreeSize;
657 1
658 1 UARTBUF[0]=(unsigned char)((FreeSize>>24)&0xff);
659 1 UARTBUF[1]=(unsigned char)((FreeSize>>16)&0xff);
660 1 UARTBUF[2]=(unsigned char)((FreeSize>>8)&0xff);
661 1 UARTBUF[3]=(unsigned char)(FreeSize&0xff);
662 1 Response.len=4;
663 1 return TRUE;
664 1 }
665
666
667 unsigned char CreateDir32(unsigned long len,unsigned char *pBuffer,unsigned char *pName)
668 {
669 1 unsigned int sector,i,j,DirCount;
670 1 unsigned long cnum;
671 1 unsigned char xdata bstop,InByte,bwrite;
672 1 unsigned long ClusterPointer;
673 1
674 1 if(!bFlags.bits.SLAVE_IS_ATTACHED)
C51 COMPILER V7.06 HPI32 08/10/2005 23:36:35 PAGE 12
675 1 return FALSE;
676 1 if((len%32)!=0)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -