keil_examples/USBHostLite/UsbHost/Fat/usbhost_fat.c
/*
**************************************************************************************************************
*                                              GET NEXT CLUSTER
*
* Description: This function returns next cluster of the current cluster in the cluster chain. If the current
*              cluster is the last cluster then this function returns 0
*
* Arguments  : clus_no    The cluster number for which the next cluster to be found
*
* Returns    : next_clus  if the current cluster is not the last cluster
*              0          if the current cluster is the last cluster
*                         Note: In practical cluster number 0 doesn't exist
*
**************************************************************************************************************
*/
GET NEXT CLUSTER
Description: This function returns next cluster of the current cluster in the cluster chain. If the current
cluster is the last cluster then this function returns 0

Arguments  : clus_no    The cluster number for which the next cluster to be found

Returns    : next_clus  if the current cluster is not the last cluster
0          if the current cluster is the last cluster
Note: In practical cluster number 0 doesn't exist
GET NEXT CLUSTER Description : This function returns next cluster of the current cluster in the cluster chain . If the current cluster is the last cluster then this function returns 0 Arguments : clus_no The cluster number for which the next cluster to be found Returns : next_clus if the current cluster is not the last cluster 0 if the current cluster is the last cluster Note : In practical cluster number 0 doesn ' t exist
uint16_t  FAT_GetNextClus (uint16_t  clus_no)
{
    uint32_t  sec_num;
    uint32_t  ent_offset;
    uint16_t  next_clus;
    sec_num = FAT_BootSec.RsvdSecCnt + ((clus_no * 2) / FAT_BootSec.BytsPerSec);
    ent_offset = (clus_no * 2) % FAT_BootSec.BytsPerSec; 
    MS_BulkRecv(sec_num, 1, FATBuffer);                          
    next_clus = ReadLE16U(&FATBuffer[ent_offset]);               
    if (next_clus >= 0xFFF8 && next_clus <= 0xFFFF) {       
        next_clus = 0;                                     
    }
    return (next_clus);
}
uint16_t FAT_GetNextClus ( uint16_t clus_no ) { uint32_t sec_num ; uint32_t ent_offset ; uint16_t next_clus ; sec_num = FAT_BootSec . RsvdSecCnt + ( ( clus_no * 2 ) / FAT_BootSec . BytsPerSec ) ; ent_offset = ( clus_no * 2 ) % FAT_BootSec . BytsPerSec ; MS_BulkRecv ( sec_num , 1 , FATBuffer ) ; next_clus = ReadLE16U ( & FATBuffer [ ent_offset ] ) ; if ( next_clus >= 0xFFF8 && next_clus <= 0xFFFF ) { next_clus = 0 ; } return ( next_clus ) ; }
GET NEXT CLUSTER
Description: This function returns next cluster of the current cluster in the cluster chain.
GET NEXT CLUSTER Description : This function returns next cluster of the current cluster in the cluster chain .
/* Get the sector number in the FAT that contains current cluster */ /* Get the sector offset in the FAT where the current cluster is located */ /* Read that sector                        */ /* Read the next cluster                   */ /* If that value is in between 0xFFF8 and 0xFFFF */ /* Current cluster is the end cluster            */