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

📄 libchain.lst

📁 威望公司MP3 + USB MCU 的参考软件
💻 LST
📖 第 1 页 / 共 4 页
字号:
                          result = 1;
                      }else{
                          result = 0; 
                          return result;         
                      }                  
                  }
              #endif
              
                  chain->Point += (1<<9); //Point go ahead 1 sector.
                  if(chain->Point > chain->Size){
C51 COMPILER V8.01   LIBCHAIN                                                              04/17/2008 09:45:56 PAGE 14  

                      chain->Point = chain->Size;
                      result = 0;     //No enought data, at least one sector
                  }   
              
                  return result;
              }
              #else
 802          BYTE ChainGet1Sector(DRIVE *drv, CHAIN *chain, BYTE offset)
 803          {
 804   1              DWORD result;
 805   1              DWORD current;
 806   1              DWORD sectoffset; // Sector offset in a Cluster 
 807   1              BYTE maxoffset; 
 808   1      
 809   1              result = 1;
 810   1              maxoffset = drv->bMaxOffset;//(1<<(drv->bBytesPerSectorExp - BLKSIZE_512_EXP)) - 1;
 811   1      
 812   1              sectoffset = ((chain->Point>>drv->bBytesPerSectorExp) & ((1<<drv->ClusterExp)-1)) + 1;  
 813   1              //The last sector and maxoffset in the current cluster, should update the chain->Current
 814   1              if((sectoffset>=drv->ClusterSize) && (offset==maxoffset)){ 
 815   2                      current = ReadFatxx(chain->Current);
 816   2      
 817   2                      if(current != 0xffffffff){
 818   3                              chain->Current = current;
 819   3                              result = 1;
 820   3                      }else{
 821   3                              result = 0;     
 822   3                              return result;     
 823   3                      }                  
 824   2              }
 825   1      
 826   1              //Only 512B can be got each time, no matter what is the true BytesPerSector (512B, 2048B).
 827   1              chain->Point += BLKSIZE_512;//(1<<drv->bBytesPerSectorExp); //Point go ahead 1 sector.
 828   1      #if 0   
                      if(chain->Point > chain->Size){
                              chain->Point = chain->Size;
                              result = 0;     //No enought data, at least one sector
                      }       
              #endif
 834   1              return result;
 835   1      }
 836          
 837          #endif
 838          
 839          
 840          DWORD ChainGetLba(CHAIN *chain)
 841          {
 842   1              DRIVE *drv = &Drive[0]; 
 843   1      
 844   1              return drv->DataStart + ((chain->Point >> drv->bBytesPerSectorExp) & (drv->ClusterSize - 1))
 845   1                 + ((chain->Current - 2) << drv->ClusterExp);
 846   1      }
 847          
 848          BYTE ChainGetOffset(CHAIN *chain)
 849          {
 850   1              DRIVE *drv = &Drive[0]; 
 851   1              
 852   1              return ((chain->Point>>BLKSIZE_512_EXP) & drv->bMaxOffset);
 853   1      }
 854          
 855          #if 0
              BYTE ChainReadMp3(DRIVE *drv, CHAIN *chain)
C51 COMPILER V8.01   LIBCHAIN                                                              04/17/2008 09:45:56 PAGE 15  

              {
                      DWORD lba;
              
                      lba = ChainGetLba(drv, chain);
              //      UartOutText("-I-: lba= ");UartOutValue(lba, 8);
              
                      if(ChainGet1Sector(drv, chain) == 0) return DRIVE_ACCESS_FAIL;
              
                      if(DriveReadMp3(drv, lba, 0) != FS_SUCCEED)     
                              return DRIVE_ACCESS_FAIL;               
                              
                      return FS_SUCCEED;
              }
              #else
 871          BYTE ChainReadMp3(CHAIN *chain)
 872          {
 873   1              DWORD lba;
 874   1              BYTE offset;
 875   1              DRIVE *drv = &Drive[0]; 
 876   1      
 877   1              lba = ChainGetLba(chain);
 878   1              offset = ChainGetOffset(chain);
 879   1              //offset = ((chain->Point>>BLKSIZE_512_EXP) & ((1<<(drv->bBytesPerSectorExp - BLKSIZE_512_EXP)) - 1));
 880   1              //UartOutText("-I-: lba= ");UartOutValue(lba, 8);
 881   1              //UartOutText("       offset= ");UartOutValue(offset, 8);
 882   1      
 883   1              if(DriveReadMp3(lba, (BYTE)offset) != FS_SUCCEED)       
 884   1                      return DRIVE_ACCESS_FAIL;               
 885   1                      
 886   1              if(ChainGet1Sector(drv, chain, offset) == 0) return DRIVE_ACCESS_FAIL;
 887   1                      
 888   1              return FS_SUCCEED;
 889   1      }
 890          #endif
 891          
 892          #if 0   
              // separate the read/write region into three segment,
              // use the sector grid to cut the region into separated segments, the first and last segments
              // may less or equal to a sector magnitude. If the first segment less then a sector, i.e., it
              // is not begin at the first byte of a sector. Then the it is the head-segment. The case of the
              // tail-segment is the same. The middle part between head-segment and tail-segment is the
              // body-segment.
              void ChainSeparate(CHAIN *chain, DWORD *head, DWORD *body, DWORD *tail, DWORD size)
                      {
                  *head = SECTOR_SIZE - (chain->Point & 0x000001ff);    // get the byte offset in head sector
                  *head = *head & 0x000001ff;                            // the byte offset cannot over sector boundary
                  *tail = 0;
                  *body = 0;
                  
                  if(*head < size)
                      {
                      *tail = (chain->Point + size) & 0x000001ff;    // get the byte offset in tail sector
                      if(*tail < size - *head)
                          *body = (size - *head - *tail) >> drv->bBytesPerSectorExp;            // get the body length i
             -n sector unit
                      else
                          *tail = size - *head;
                      }
                  else
                      *head = size;
                      }
              
C51 COMPILER V8.01   LIBCHAIN                                                              04/17/2008 09:45:56 PAGE 16  

              
              // get a continuous sector block from current sector point with its size not great
              // than the request sector count. After returning, the chain point will move to
              // the point right after this continuous block area
              // note that the service call will update the value of request to (repuest - result)
              DWORD ChainGetContinuity(DRIVE *drv, CHAIN *chain, DWORD *request)
                      {
                  DWORD addend, result;
                  DWORD previous, current;
                  
                  result = 0;
                  
                  // get the sector offset of the current point within the current cluster
                  addend = chain->Point << (32 - drv->ClusterExp - drv->bBytesPerSectorExp);
                  addend = addend >> (32 - drv->ClusterExp);
                  
                  addend = drv->ClusterSize - addend;
                  
                  do{        
                      previous = chain->Current;
              //        current = drv->FatRead(drv, chain->Current);        
                      current = ReadFatxx(drv, chain->Current);
              
                      if(current == 0xffffffff){
                          if(addend >= *request){
                            result += *request;
                            chain->Point += *request << drv->bBytesPerSectorExp;
                          }else{
                            result += addend;
                            chain->Point += addend << drv->bBytesPerSectorExp;
                          }
              
                          *request = 0;
                          break;
                      }
                          
                      if(*request >= addend){
                          result += addend;
                          chain->Point += addend << drv->bBytesPerSectorExp;
                          *request -= addend;
                      }else{
                          result += *request;
                          chain->Point += *request << drv->bBytesPerSectorExp;
                          *request = 0;
                          break;
                      }
                          
                      addend = drv->ClusterSize;
                      chain->Current = current;
              
                  } while(chain->Current == previous + 1);
              
                  return result;
              }
              
              
              BYTE ChainRead(DRIVE *drv, CHAIN *chain, BYTE *buffer, DWORD sector)
              {
                      DWORD count, lba, sectorCnt;
              
                      sectorCnt = sector;
                      while(sector)   {
C51 COMPILER V8.01   LIBCHAIN                                                              04/17/2008 09:45:56 PAGE 17  

                              lba = ChainGetLba(drv, chain);
                              count = ChainGetContinuity(drv, chain, &sector);
              
                              if(!count) return DRIVE_ACCESS_FAIL;
              
                              if(DriveRead(drv, buffer, lba) != FS_SUCCEED)   
                                      return DRIVE_ACCESS_FAIL;               
                              
                              buffer += count << drv->bBytesPerSectorExp;                     // increase the destination buffer point
                      }
                              
                      return FS_SUCCEED;
              }
              
              // value of 'size' must satify the condition that (size + (chain->Point & 0x1ff)) <= 512
              int ChainFragmentRead(DRIVE *drv, CHAIN *chain, BYTE *buffer, DWORD size)
                      {
                  BYTE *fragment;
                  DWORD lba;
                  
                  //fragment = (BYTE *)OsTempMemAllocate();
                      fragment = DBUF;
                  lba = ChainGetLba(drv, chain);
              
                  if(DriveRead(drv, fragment, lba) != FS_SUCCEED)
                      return DRIVE_ACCESS_FAIL;
                  memcpy(buffer, fragment + (chain->Point & 0x1ff), size);
                  
                      //OsTempMemRelease((DWORD)fragment);
                      
                  ChainSeekForward(drv, chain, size);
              
                  return FS_SUCCEED;
                      }
              
              BYTE ChainFragmentReadMp3(DRIVE *drv, CHAIN *chain, DWORD size)
              {
                  //BYTE *fragment;
                  DWORD lba;
                  
                  lba = ChainGetLba(drv, chain);
                  if(DriveReadMp3(drv, lba) != FS_SUCCEED)
                      return DRIVE_ACCESS_FAIL;
                      
                  ChainSeekForward(drv, chain, size);
              
                  return FS_SUCCEED;
              }
              #endif
1029          
1030          
1031          


MODULE INFORMATION:   STATIC OVERLAYABLE
   CODE SIZE        =   1304    ----
   CONSTANT SIZE    =   ----    ----
   XDATA SIZE       =   ----     102
   PDATA SIZE       =   ----    ----
   DATA SIZE        =   ----       6
   IDATA SIZE       =   ----    ----
   BIT SIZE         =   ----    ----
C51 COMPILER V8.01   LIBCHAIN                                                              04/17/2008 09:45:56 PAGE 18  

END OF MODULE INFORMATION.


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

⌨️ 快捷键说明

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