keil_examples/USBHostLite/UsbHost/Fat/usbhost_fat.c
/*
**************************************************************************************************************
*                                               GET FREE CLUSTER
*
* Description: This function returns the free cluster if available
*
* Arguments  : None
*
* Returns    : free_clus    if available
*              0            if not available(means the disk is full)
*
**************************************************************************************************************
*/
GET FREE CLUSTER
Description: This function returns the free cluster if available

Arguments  : None

Returns    : free_clus    if available
0            if not available(means the disk is full)
GET FREE CLUSTER Description : This function returns the free cluster if available Arguments : None Returns : free_clus if available 0 if not available ( means the disk is full )
uint16_t  FAT_GetFreeClus (void)
{
    uint32_t  num_sec;
    uint32_t  cnt;
    uint32_t  sec_num;
    uint16_t  free_clus;
    sec_num = FAT_BootSec.RsvdSecCnt;
    num_sec = FAT_BootSec.FATSz16;
    while (sec_num < (FAT_BootSec.RsvdSecCnt + num_sec)) {
        MS_BulkRecv(sec_num, 1, FATBuffer);
        for (cnt = 0; cnt < FAT_BootSec.BytsPerSec; cnt += 2) {
            if (ReadLE16U(&FATBuffer[cnt]) == 0) {
                free_clus = (((sec_num - FAT_BootSec.RsvdSecCnt) * FAT_BootSec.BytsPerSec) + cnt) / 2;
                return (free_clus);
            }
        }
        sec_num++;
    }
    return (0);
}
uint16_t FAT_GetFreeClus ( void ) { uint32_t num_sec ; uint32_t cnt ; uint32_t sec_num ; uint16_t free_clus ; sec_num = FAT_BootSec . RsvdSecCnt ; num_sec = FAT_BootSec . FATSz16 ; while ( sec_num < ( FAT_BootSec . RsvdSecCnt + num_sec ) ) { MS_BulkRecv ( sec_num , 1 , FATBuffer ) ; for ( cnt = 0 ; cnt < FAT_BootSec . BytsPerSec ; cnt += 2 ) { if ( ReadLE16U ( & FATBuffer [ cnt ] ) == 0 ) { free_clus = ( ( ( sec_num - FAT_BootSec . RsvdSecCnt ) * FAT_BootSec . BytsPerSec ) + cnt ) / 2 ; return ( free_clus ) ; } } sec_num ++ ; } return ( 0 ) ; }
GET FREE CLUSTER
Description: This function returns the free cluster if available
GET FREE CLUSTER Description : This function returns the free cluster if available