⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 libdrive.lst

📁 威望公司MP3 + USB MCU 的参考软件
💻 LST
📖 第 1 页 / 共 4 页
字号:
 678   1              BYTE bRet;
 679   1              DRIVE *drv = &Drive[0]; 
 680   1              //static BYTE bDledCnt = 0;
 681   1              //drv = drv; //buffer = buffer; lba = lba; len = len;
 682   1      DISABLE_INTERRUPTS;
 683   1              //NOTE: buffer is just 512byte!!!!!!!!!?????????????
 684   1      //      WDT = 0X1F;
 685   1      
 686   1              //halT0Reset(); 
 687   1      #ifdef ENABLE_SD_CARD   
 688   1              if(drv->DevID == SD_DISK){
 689   2                      //UartOutText("\rDriveRead(), before halSDReadSector()\r\n");
 690   2                      bRet = halSDRead(buffer, lba);
 691   2              }
 692   1              else
 693   1      #endif
 694   1                      {
 695   2                      //RBC_ReadOneSec(lba, buffer, RBC_READ_BUF, offset);    
 696   2                      bRet =halUsbRead(lba, buffer, offset);
 697   2              }       
 698   1              //UartOutText("-I-: Read Time 0X");UartOutValue(halT0Read(), 4);
 699   1      
 700   1      #if 0
                      bDledCnt++;
                      if(bDledCnt >= 5){
                              halDLEDISR();
                              bDledCnt = 0;
                      }
              #endif
 707   1              
 708   1      ENABLE_INTERRUPTS;
 709   1      
 710   1              if(bRet == FALSE)
 711   1                      return DRIVE_ACCESS_FAIL ;
 712   1              else
 713   1                      return FS_SUCCEED;      
 714   1      }
 715          
 716          #ifdef WRITE_ENABLE_FLAG
              //This function will startup a write operation at address lba, only one sector each time 
              BYTE DriveWrite(DRIVE *drv, BYTE* buffer, UDWORD lba)
              {
C51 COMPILER V8.01   LIBDRIVE                                                              04/17/2008 09:46:00 PAGE 13  

                      BYTE ret;
                      
                      //drv = drv; //buffer = buffer; lba = lba; len = len;
                      DISABLE_INTERRUPTS;
                      //NOTE: buffer is just 512byte!!!!!!!!!?????????????
                      if(drv->DevID == SD_DISK)
                              ret = halSDWriteSector(buffer, lba);
                      else
                              ret = RBC_WriteOneSec(lba, buffer);     
                      ENABLE_INTERRUPTS;
              
                      return FS_SUCCEED;
              }
              #endif
 734          
 735          //This function will startup a read operation at address lba, and continuous len sectiors will be read.  
 736          BYTE DriveReadMp3(UDWORD lba, BYTE offset)
 737          {
 738   1              DRIVE *drv = &Drive[0]; 
 739   1              BYTE ret;
 740   1              //drv = drv; //buffer = buffer; lba = lba; len = len;
 741   1              //halSDReadMp3(lba);
 742   1      #ifdef ENABLE_SD_CARD
 743   1              if(drv->DevID == SD_DISK)
 744   1                      ret = halSDReadMp3(lba);
 745   1              else
 746   1      #endif          
 747   1              ret = halUsbReadMp3(lba, offset);
 748   1                      //RBC_ReadOneSec(lba, NULL, RBC_READ_MP3, offset);      //ret = RBC_ReadMp3(lba); //USB data -> mp3 dec buffe
             -r
 749   1      
 750   1              if(ret != TRUE)
 751   1                      return DRIVE_ACCESS_FAIL;
 752   1              else
 753   1                      return FS_SUCCEED;
 754   1      }
 755          
 756          
 757          ///
 758          ///@ingroup     DRIVE
 759          ///@brief       Initial all the data structure and operation variables for file system
 760          ///
 761          ///@param       NONE
 762          ///
 763          ///@return NONE
 764          ///
 765          void FileSystemInit()
 766          {
 767   1              DriveInit();
 768   1              StreamInit();
 769   1      //      DriveCounter = 0;
 770   1      //      CurrDrive = 0;
 771   1      
 772   1              return;
 773   1      }
 774          
 775          ///
 776          ///@ingroup     DRIVE
 777          ///@brief       Scan the file system of specific device, and add to Drive buffer
 778          ///
 779          ///@param       BYTE dev  The device ID to scan
 780          ///
C51 COMPILER V8.01   LIBDRIVE                                                              04/17/2008 09:46:00 PAGE 14  

 781          ///@return      Number of drive added
 782          ///
 783          ///@remark      The function call only add formatted device to drive buffer. If the device is 
 784          ///         not formatted, it will return 0 and add no drive to drive buffer. The drive ID 
 785          ///         is the same as device ID.
 786          ///         Note that, only HD support multiple partition.
 787          ///
 788          BYTE DriveAdd(BYTE devID)
 789          {
 790   1              BYTE data ret;//, count;
 791   1              BYTE data blkexp;
 792   1              DRIVE   *drv;
 793   1      
 794   1              // At current stage, only 2 drive is supported.
 795   1              //if(devID > 1 ){ return 0;}    
 796   1      
 797   1              //drv         = &Drive[devID];
 798   1              drv         = &Drive[0];
 799   1              drv->DevID    = devID;
 800   1      
 801   1              //This should be done before PartitionScan.
 802   1              if(drv->DevID == USB_DISK){
 803   2                      blkexp = halUsbInfo();
 804   2              }else{  //SD_DISK
 805   2      #ifdef ENABLE_SD_CARD
 806   2                      blkexp = halSDInfo();
 807   2      #endif  
 808   2                      }
 809   1              drv->bBytesPerSectorExp         = blkexp;
 810   1              drv->wBytesPerSector            = (1<<blkexp);
 811   1              drv->bMaxOffset                 = ((1<<(blkexp - BLKSIZE_512_EXP))-1);  
 812   1      
 813   1              // scan the partition table of current drive
 814   1              if(!(ret = PartitionScan(drv))){             // 0 mean no partition table exist
 815   2      #if 1
 816   2      
 817   2              UartOutText("\rDriveAdd,  if(!(ret = PartitionScan(drv)))\r\n");
 818   2                  if(FloppyCheck(drv) != FS_SUCCEED) {
 819   3                      UartOutText("\rDriveAdd,  !(ret = PartitionScan(drv)) (FloppyCheck(drv) != FS_SUCCEED)\r\n");   
 820   3                      return 0;                           
 821   3      
 822   3                      }               
 823   2                  else
 824   2                      ret = 1;
 825   2      #else
                          UartOutText("PartitionScan() Fail \r\n");   
                          return 0;   
              
              #endif          
 830   2              }
 831   1      
 832   1      #if 0
                      count = ret;
                      while(count > 0){
                              // if this device contain more than one partition// then let these partitions number from 1, not from 0
                          drv->Partition ++;                          
                              //drv ++;               //?????drv++ will point to the next DRIVE structure.
                          count --;
                      }
              #else
 841   1              //drv->Partition ++;
 842   1      #endif
C51 COMPILER V8.01   LIBDRIVE                                                              04/17/2008 09:46:00 PAGE 15  

 843   1      
 844   1              return ret;     
 845   1      }
 846          
 847          ///
 848          ///@ingroup     DRIVE
 849          ///@brief       Change current drive to specific drive 
 850          ///
 851          ///@param       BYTE drive_id  The drive ID 
 852          ///
 853          ///@return      Start address of the drive structure if success, NULL if the drive_id is invalid.       
 854          ///
 855          DRIVE *DriveGet(void)
 856          {
 857   1      #if 0   
                      //check validity of drive_id    
                      if(drive_id >= FS_MAX_DRIVE)
                      {
                              return NULL;            
                      }
              
                      CurrDrive = drive_id;
                      return &Drive[CurrDrive];
              #else
 867   1      //      drive_id = drive_id;
 868   1              return &Drive[0];       //Only one drive is available.
 869   1      #endif
 870   1      }
 871          
 872          #if 0
              void DrivePhyBlkSize(WORD size, BYTE exp, BYTE offset)
              {
                      Drive[0].bBytesPerSectorExp     = exp;
                      Drive[0].wBytesPerSector                = size;
                      Drive[0].bMaxOffset                     = offset;       
                      
                      return;
              }
              #endif
 882          
 883          BYTE DriveFlush(BOOL bSkip)
 884          {
 885   1              BYTE byRet = TRUE;
 886   1              DRIVE *drv = &Drive[0]; 
 887   1      
 888   1              if(drv->DevID == USB_DISK){
 889   2                      byRet = RBC_ReadFlush(bSkip);
 890   2              }       
 891   1                      
 892   1              return byRet;
 893   1      }
 894          


MODULE INFORMATION:   STATIC OVERLAYABLE
   CODE SIZE        =   1854    ----
   CONSTANT SIZE    =     18    ----
   XDATA SIZE       =   1324      67
   PDATA SIZE       =   ----    ----
   DATA SIZE        =   ----      21
   IDATA SIZE       =   ----    ----
   BIT SIZE         =   ----    ----
C51 COMPILER V8.01   LIBDRIVE                                                              04/17/2008 09:46:00 PAGE 16  

END OF MODULE INFORMATION.


C51 COMPILATION COMPLETE.  0 WARNING(S),  0 ERROR(S)

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -