📄 hpi.lst
字号:
414 1 {
415 2 UartRspBlock.errcode=ERC_NODEVICE;
416 2 return FALSE;
417 2 }
418 1 pDirInfo->length=0;
419 1 /////// Search a free space in the root dir space and build the item ///
420 1 ThisFile.bFileOpen=0;
421 1 bstop=0;
422 1 for(sector=0;sector<DeviceInfo.BPB_RootEntCnt;sector++)
423 1 {
424 2 //////////////////////////////////////////////////
425 2 if(!RBC_Read(DeviceInfo.RootStartSector+sector,1,DBUF))
426 2 {
427 3
C51 COMPILER V7.50 HPI 11/02/2007 09:31:21 PAGE 8
428 3 UartRspBlock.errcode=ERC_DEVICEERR;
429 3 return FALSE;
430 3 }
431 2 ///////////////////////////////////////////////////
432 2 for(i=0;i<DeviceInfo.BPB_BytesPerSec;i=i+32)
433 2 {
434 3 if((DBUF[i]==0x00)||(DBUF[i]==0xE5))
435 3 {
436 4 for(j=0;j<32;j++)
437 4 //DBUF[i+j]=UartCmdBlock.CmdBlock.Cmd_CreateFile.item[j];
438 4 DBUF[i+j]=*(pBuffer+j);
439 4 if(!RBC_Write(DeviceInfo.RootStartSector+sector,1,DBUF))
440 4 {
441 5 UartRspBlock.errcode=ERC_DEVICEERR;
442 5 return FALSE;
443 5 }
444 4 bstop=1;
445 4 break;
446 4 }
447 3 }
448 2 ///////////////////////////////////////////////////////
449 2 if(bstop==1)break;
450 2
451 2 }
452 1 /////////////////////////////////////////////
453 1 //pDirInfo=(PDIR_INFO)RspBlockOpenFile.item;
454 1 //ThisFile.FatSectorPointer=ThisFatSecNum(ThisFile.StartCluster);
455 1 ThisFile.StartCluster=SwapINT16(pDirInfo->startCluster);
456 1 ThisFile.LengthInByte=0;
457 1 ThisFile.ClusterPointer=ThisFile.StartCluster;
458 1 ThisFile.SectorPointer=FirstSectorofCluster(ThisFile.StartCluster);
459 1 ThisFile.OffsetofSector=0;
460 1 ThisFile.SectorofCluster=0;
461 1 ThisFile.bFileOpen=1;
462 1 ThisFile.pointer=0;
463 1 ThisFile.FatSectorPointer=0;
464 1 //////////////////////////////////////////////
465 1 return TRUE;
466 1 #undef RspBlockCreateFile
467 1 }
468
469 unsigned char WriteFile(unsigned int writeLength,unsigned char *pBuffer)
470 {
471 1 #define RspBlockWriteFile UartRspBlock.RspBlock.Rsp_WriteFile
472 1 unsigned int len,sector,i;
473 1 PDIR_INFO pDirInfo;
474 1 unsigned char bSuccess,bStop;
475 1
476 1 if(!bXXGFlags.bits.SLAVE_IS_ATTACHED)
477 1 {
478 2 UartRspBlock.errcode=ERC_NODEVICE;
479 2 return FALSE;
480 2 }
481 1 if(!ThisFile.bFileOpen)
482 1 {
483 2 UartRspBlock.errcode=ERC_FILENOTOPENED;
484 2 return FALSE;
485 2 }
486 1 ///////////////////////////////////////////////////////////
487 1 //if(UartCmdBlock.CmdBlock.Cmd_WriteFile.writeLength>0)
488 1 // {
489 1 // for(i=UartCmdBlock.CmdBlock.Cmd_WriteFile.writeLength;i<MAX_WRITE_LENGTH;i++)
C51 COMPILER V7.50 HPI 11/02/2007 09:31:21 PAGE 9
490 1 // UARTBUF[i]=0;
491 1 // }
492 1 ///////////////////////////////////////////////////////////
493 1 ThisFile.bFileOpen=0;
494 1 bSuccess=1;
495 1 bStop=0;
496 1
497 1 UartRspBlock.len=0;
498 1 //if(UartCmdBlock.CmdBlock.Cmd_WriteFile.writeLength)
499 1 while(writeLength>0)
500 1 {
501 2 if(writeLength+ThisFile.OffsetofSector>DeviceInfo.BPB_BytesPerSec)
502 2 len=DeviceInfo.BPB_BytesPerSec;
503 2 else
504 2 len=writeLength+ThisFile.OffsetofSector;
505 2
506 2 //////////////////////////////////////////////////////
507 2 if(ThisFile.OffsetofSector>0)
508 2 {
509 3 if(RBC_Read(ThisFile.SectorPointer,1,DBUF))
510 3 {
511 4 //ThisFile.OffsetofSector=len;
512 4 len=len-ThisFile.OffsetofSector;
513 4 for(i=0;i<len;i++)
514 4 //DBUF[ThisFile.OffsetofSector+i]=UARTBUF[i];
515 4 DBUF[ThisFile.OffsetofSector+i]=*(pBuffer+i);
516 4 if(!RBC_Write(ThisFile.SectorPointer,1,DBUF))
517 4 {
518 5 UartRspBlock.errcode=ERC_DEVICEERR;
519 5 return FALSE;
520 5 }
521 4 ThisFile.OffsetofSector=ThisFile.OffsetofSector+len;
522 4 }
523 3 else
524 3 {
525 4 UartRspBlock.errcode=ERC_DEVICEERR;
526 4 return FALSE;
527 4 }
528 3 }
529 2 else
530 2 {
531 3 if(!RBC_Write(ThisFile.SectorPointer,1,pBuffer+UartRspBlock.len))
532 3 {
533 4 UartRspBlock.errcode=ERC_DEVICEERR;
534 4 return FALSE;
535 4 }
536 3 ThisFile.OffsetofSector=len;
537 3 }
538 2 /////////////////////////////////////////////////////
539 2 //if(ThisFile.OffsetofSector>DeviceInfo.BPB_BytesPerSec-1)
540 2 // ThisFile.OffsetofSector-=DeviceInfo.BPB_BytesPerSec;
541 2 writeLength-=len;
542 2 UartRspBlock.len+=len;
543 2 //ThisFile.LengthInByte+=len;
544 2 /////////////更新文件指针 //////////////////////////////
545 2 if(ThisFile.OffsetofSector>DeviceInfo.BPB_BytesPerSec-1)
546 2 {
547 3 ThisFile.OffsetofSector-=DeviceInfo.BPB_BytesPerSec;
548 3 ThisFile.SectorofCluster+=1;
549 3 if(ThisFile.SectorofCluster>DeviceInfo.BPB_SecPerClus-1)
550 3 {
551 4 ThisFile.SectorofCluster=0;
C51 COMPILER V7.50 HPI 11/02/2007 09:31:21 PAGE 10
552 4 ThisFile.ClusterPointer=CreateClusterLink(ThisFile.ClusterPointer);//GetNextClusterNum(ThisFile.Clus
-terPointer);
553 4 if(ThisFile.ClusterPointer==0x00)
554 4 {
555 5 // RspBlockReadFile.errcode=ERC_REACHEND;
556 5 // RspBlockReadFile.result=0x0;
557 5 UartRspBlock.errcode=ERC_DEVICEERR;
558 5 return FALSE;
559 5 }
560 4 ThisFile.SectorPointer=FirstSectorofCluster(ThisFile.ClusterPointer);
561 4 }
562 3 else
563 3 ThisFile.SectorPointer=ThisFile.SectorPointer+1;
564 3 }
565 2
566 2
567 2 }//end while
568 1 ThisFile.pointer+=UartRspBlock.len;
569 1 ///////////更新文件目录信息/////////////////////////////
570 1 if(bSuccess==1)
571 1 {
572 2
573 2 for(sector=0;sector<DeviceInfo.BPB_RootEntCnt;sector++)
574 2 {
575 3 //////////////////////////////////////////////////
576 3 if(!RBC_Read(DeviceInfo.RootStartSector+sector,1,DBUF))
577 3 {
578 4 UartRspBlock.errcode=ERC_DEVICEERR;
579 4 return FALSE;
580 4 }
581 3 ///////////////////////////////////////////////////
582 3 for(i=0;i<DeviceInfo.BPB_BytesPerSec;i=i+32)
583 3 {
584 4 pDirInfo=(PDIR_INFO)(DBUF+i);
585 4
586 4 if(pDirInfo->startCluster==SwapINT16(ThisFile.StartCluster))
587 4 {
588 5 if(ThisFile.pointer>ThisFile.LengthInByte)
589 5 ThisFile.LengthInByte=ThisFile.pointer;
590 5 //else
591 5 // ThisFile.pointer=;
592 5
593 5 pDirInfo->length=SwapINT32(ThisFile.LengthInByte);
594 5 if(!RBC_Write(DeviceInfo.RootStartSector+sector,1,DBUF))
595 5 {
596 6 UartRspBlock.errcode=ERC_DEVICEERR;
597 6 return FALSE;
598 6 }
599 5 bStop=1;
600 5 break;
601 5 }
602 4 }
603 3 if(bStop==1)
604 3 break;
605 3 ////////////////////////////////////////////////////
606 3 }
607 2
608 2 }
609 1 /*
610 1 if(bSuccess==0)
611 1 {
612 1 RspBlockWriteFile.errcode=ERC_DEVICEERR;
C51 COMPILER V7.50 HPI 11/02/2007 09:31:21 PAGE 11
613 1 RspBlockWriteFile.result=0x0;
614 1 }
615 1 */
616 1 UartRspBlock.len=0;
617 1 ThisFile.bFileOpen=1;
618 1 //////////////////////////////////////////////
619 1 return TRUE;
620 1 #undef RspBlockWriteFile
621 1 }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -