📄 hpi.lst
字号:
432 2 {
433 3
434 3 UartRspBlock.errcode=ERC_DEVICEERR;
435 3 return FALSE;
436 3 }
437 2 ///////////////////////////////////////////////////
438 2 for(i=0;i<DeviceInfo.BPB_BytesPerSec;i=i+32)
439 2 {
440 3 if((DBUF[i]==0x00)||(DBUF[i]==0xE5))
441 3 {
442 4 for(j=0;j<32;j++)
443 4 //DBUF[i+j]=UartCmdBlock.CmdBlock.Cmd_CreateFile.item[j];
444 4 DBUF[i+j]=*(pBuffer+j);
445 4 if(!RBC_Write(DeviceInfo.RootStartSector+sector,1,DBUF))
446 4 {
447 5 UartRspBlock.errcode=ERC_DEVICEERR;
448 5 return FALSE;
449 5 }
450 4 bstop=1;
451 4 break;
452 4 }
453 3 }
454 2 ///////////////////////////////////////////////////////
455 2 if(bstop==1)break;
456 2
457 2 }
458 1 /////////////////////////////////////////////
459 1 //pDirInfo=(PDIR_INFO)RspBlockOpenFile.item;
460 1 //ThisFile.FatSectorPointer=ThisFatSecNum(ThisFile.StartCluster);
461 1 ThisFile.StartCluster=SwapINT16(pDirInfo->startCluster);
462 1 ThisFile.LengthInByte=0;
463 1 ThisFile.ClusterPointer=ThisFile.StartCluster;
464 1 ThisFile.SectorPointer=FirstSectorofCluster(ThisFile.StartCluster);
465 1 ThisFile.OffsetofSector=0;
466 1 ThisFile.SectorofCluster=0;
467 1 ThisFile.bFileOpen=1;
468 1 ThisFile.pointer=0;
469 1 ThisFile.FatSectorPointer=0;
470 1 //////////////////////////////////////////////
471 1 FreeFat.SectorNum=DeviceInfo.FatStartSector;
472 1 FreeFat.OldSectorNum=DeviceInfo.FatStartSector;
473 1 FreeFat.OffsetofSector=2;
474 1
475 1 return TRUE;
476 1 #undef RspBlockCreateFile
477 1 }
478
479 unsigned char WriteFile(unsigned int writeLength,unsigned char *pBuffer)
480 {
481 1 #define RspBlockWriteFile UartRspBlock.RspBlock.Rsp_WriteFile
482 1 unsigned int len,sector,i;
483 1 PDIR_INFO pDirInfo;
484 1 unsigned char bSuccess,bStop,step;
485 1
486 1 if(!bXXGFlags.bits.SLAVE_IS_ATTACHED) //U盘是否已经连接
487 1 {
488 2 UartRspBlock.errcode=ERC_NODEVICE;
489 2 return FALSE;
C51 COMPILER V6.21 HPI 06/13/2005 16:14:56 PAGE 9
490 2 }
491 1 if(!ThisFile.bFileOpen) //文件是否已经打开
492 1 {
493 2 UartRspBlock.errcode=ERC_FILENOTOPENED;
494 2 return FALSE;
495 2 }
496 1 ///////////////////////////////////////////////////////////
497 1 //if(UartCmdBlock.CmdBlock.Cmd_WriteFile.writeLength>0)
498 1 // {
499 1 // for(i=UartCmdBlock.CmdBlock.Cmd_WriteFile.writeLength;i<MAX_WRITE_LENGTH;i++)
500 1 // UARTBUF[i]=0;
501 1 // }
502 1
503 1 ///////////////////////////////////////////////////////////
504 1 ThisFile.bFileOpen=0;
505 1 bSuccess=1;
506 1 bStop=0;
507 1
508 1 UartRspBlock.len=0;
509 1 //if(UartCmdBlock.CmdBlock.Cmd_WriteFile.writeLength)
510 1 while(writeLength>0)
511 1 {
512 2 //////////////////////////////////////////////////////
513 2 if(ThisFile.OffsetofSector>0)
514 2 {
515 3 if(writeLength+ThisFile.OffsetofSector>DeviceInfo.BPB_BytesPerSec)
516 3 len=DeviceInfo.BPB_BytesPerSec;
517 3 else
518 3 len=writeLength+ThisFile.OffsetofSector;
519 3 //////////////////////////////////////////////////
520 3 if(!RBC_Read(ThisFile.SectorPointer,1,DBUF))
521 3 {
522 4 UartRspBlock.errcode=ERC_DEVICEERR;
523 4 return FALSE;
524 4 }
525 3 //ThisFile.OffsetofSector=len;
526 3 len=len-ThisFile.OffsetofSector;
527 3 for(i=0;i<len;i++)
528 3 //DBUF[ThisFile.OffsetofSector+i]=UARTBUF[i];
529 3 DBUF[ThisFile.OffsetofSector+i]=*(pBuffer+i);
530 3 if(!RBC_Write(ThisFile.SectorPointer,1,DBUF))
531 3 {
532 4 UartRspBlock.errcode=ERC_DEVICEERR;
533 4 return FALSE;
534 4 }
535 3 ThisFile.OffsetofSector=ThisFile.OffsetofSector+len;
536 3 }
537 2 else
538 2 {
539 3 if(writeLength>DeviceInfo.BPB_BytesPerSec)
540 3 {
541 4 step=writeLength/DeviceInfo.BPB_BytesPerSec;
542 4 //step=step-ThisFile.SectorofCluster;
543 4 if(step>DeviceInfo.BPB_SecPerClus)
544 4 {
545 5 step=DeviceInfo.BPB_SecPerClus-ThisFile.SectorofCluster;
546 5 len=step*DeviceInfo.BPB_BytesPerSec;
547 5 }
548 4 else
549 4 {
550 5 step=step-ThisFile.SectorofCluster;
551 5 len=step*DeviceInfo.BPB_BytesPerSec;
C51 COMPILER V6.21 HPI 06/13/2005 16:14:56 PAGE 10
552 5 }
553 4 }
554 3 else
555 3 {
556 4 step=1;
557 4 len=writeLength;
558 4 }
559 3 ////////////////////////////////////////////
560 3 if(!RBC_Write(ThisFile.SectorPointer,step,pBuffer+UartRspBlock.len))
561 3 {
562 4 UartRspBlock.errcode=ERC_DEVICEERR;
563 4 return FALSE;
564 4 }
565 3 ThisFile.OffsetofSector=len;
566 3 }
567 2 /////////////////////////////////////////////////////
568 2 //if(ThisFile.OffsetofSector>DeviceInfo.BPB_BytesPerSec-1)
569 2 // ThisFile.OffsetofSector-=DeviceInfo.BPB_BytesPerSec;
570 2 writeLength-=len;
571 2 UartRspBlock.len+=len;
572 2 //ThisFile.LengthInByte+=len;
573 2 /////////////更新文件指针 //////////////////////////////
574 2 //改变参数:OffsetofSector,SectorofCluster,SectorPointer,ClusterPointer
575 2 step=ThisFile.OffsetofSector/DeviceInfo.BPB_BytesPerSec;
576 2
577 2 if(step>0)
578 2 {
579 3 ThisFile.OffsetofSector-=step*DeviceInfo.BPB_BytesPerSec;
580 3 ThisFile.SectorofCluster+=step;
581 3 if(ThisFile.SectorofCluster>DeviceInfo.BPB_SecPerClus-1)
582 3 {
583 4 ThisFile.SectorofCluster=0;
584 4 if(ThisFile.pointer+UartRspBlock.len<ThisFile.LengthInByte)
585 4 ThisFile.ClusterPointer=GetNextClusterNum(ThisFile.ClusterPointer);
586 4 else
587 4 ThisFile.ClusterPointer=CreateClusterLink(ThisFile.ClusterPointer);//GetNextClusterNum(ThisFile.Clu
-sterPointer);
588 4 if(ThisFile.ClusterPointer==0x00)
589 4 {
590 5 // RspBlockReadFile.errcode=ERC_REACHEND;
591 5 // RspBlockReadFile.result=0x0;
592 5 UartRspBlock.errcode=ERC_DEVICEERR;
593 5 return FALSE;
594 5 }
595 4 ThisFile.SectorPointer=FirstSectorofCluster(ThisFile.ClusterPointer);
596 4 }
597 3 else
598 3 ThisFile.SectorPointer=ThisFile.SectorPointer+step;
599 3 }
600 2
601 2
602 2 }//end while
603 1 ThisFile.pointer+=UartRspBlock.len;
604 1
605 1 UpdateFat(FreeFat.SectorNum);
606 1 ///////////更新文件目录信息/////////////////////////////
607 1 if(bSuccess==1)
608 1 {
609 2
610 2 for(sector=0;sector<DeviceInfo.BPB_RootEntCnt;sector++)
611 2 {
612 3 //////////////////////////////////////////////////
C51 COMPILER V6.21 HPI 06/13/2005 16:14:56 PAGE 11
613 3 if(!RBC_Read(DeviceInfo.RootStartSector+sector,1,DBUF))
614 3 {
615 4 UartRspBlock.errcode=ERC_DEVICEERR;
616 4 return FALSE;
617 4 }
618 3 ///////////////////////////////////////////////////
619 3 for(i=0;i<DeviceInfo.BPB_BytesPerSec;i=i+32)
620 3 {
621 4 pDirInfo=(PDIR_INFO)(DBUF+i);
622 4
623 4 if(pDirInfo->startCluster==SwapINT16(ThisFile.StartCluster))
624 4 {
625 5 if(ThisFile.pointer>ThisFile.LengthInByte)
626 5 ThisFile.LengthInByte=ThisFile.pointer;
627 5 //else
628 5 // ThisFile.pointer=;
629 5
630 5 pDirInfo->length=SwapINT32(ThisFile.LengthInByte);
631 5 if(!RBC_Write(DeviceInfo.RootStartSector+sector,1,DBUF))
632 5 {
633 6 UartRspBlock.errcode=ERC_DEVICEERR;
634 6 return FALSE;
635 6 }
636 5 bStop=1;
637 5 break;
638 5 }
639 4 }
640 3 if(bStop==1)
641 3 break;
642 3 ////////////////////////////////////////////////////
643 3 }
644 2
645 2 }
646 1 /*
647 1 if(bSuccess==0)
648 1 {
649 1 RspBlockWriteFile.errcode=ERC_DEVICEERR;
650 1 RspBlockWriteFile.result=0x0;
651 1 }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -