keil_examples/USBHostLite/UsbHost/Fat/usbhost_fat.c
/*
**************************************************************************************************************
*                                                GET GREE ENTRY
*
* Description: This function searches for a free entry in the root directory. If a free entry is found, the
*              sector number and sector offset where the entry is located will be stored
*
* Arguments  : entry    Pointer to FILE_ENTRY structure
*
* Returns    : OK       If a free entry is found
*              ERROR    If no free entry is found
*
**************************************************************************************************************
*/
GET GREE ENTRY
Description: This function searches for a free entry in the root directory. If a free entry is found, the
sector number and sector offset where the entry is located will be stored

Arguments  : entry    Pointer to FILE_ENTRY structure

Returns    : OK       If a free entry is found
ERROR    If no free entry is found
GET GREE ENTRY Description : This function searches for a free entry in the root directory . If a free entry is found the sector number and sector offset where the entry is located will be stored Arguments : entry Pointer to FILE_ENTRY structure Returns : OK If a free entry is found ERROR If no free entry is found
int32_t  FAT_GetFreeEntry (FILE_ENTRY  *entry)
{
              uint32_t   sec_num;
    volatile  uint8_t  *buf;
              uint8_t   ent_type;
    for (sec_num = FAT_BootSec.RootDirStartSec; 
         sec_num < (FAT_BootSec.RootDirStartSec + FAT_BootSec.RootDirSec);
         sec_num++) {
        MS_BulkRecv(sec_num, 1, FATBuffer);
        buf = FATBuffer;
        while (buf < (FATBuffer + FAT_BootSec.BytsPerSec)) {
            ent_type = FAT_ChkEntType(buf);
            if (ent_type == FREE_ENTRY) {
                entry->EntrySec       = sec_num;
                entry->EntrySecOffset = buf - FATBuffer;
                return (OK);
            }
            if (ent_type == LAST_ENTRY) {
                return (ERR_ROOT_DIR_FULL);
            } else {
                buf += 32;
            }
        }
    }
    return (ERR_ROOT_DIR_FULL);
}
int32_t FAT_GetFreeEntry ( FILE_ENTRY * entry ) { uint32_t sec_num ; volatile uint8_t * buf ; uint8_t ent_type ; for ( sec_num = FAT_BootSec . RootDirStartSec ; sec_num < ( FAT_BootSec . RootDirStartSec + FAT_BootSec . RootDirSec ) ; sec_num ++ ) { MS_BulkRecv ( sec_num , 1 , FATBuffer ) ; buf = FATBuffer ; while ( buf < ( FATBuffer + FAT_BootSec . BytsPerSec ) ) { ent_type = FAT_ChkEntType ( buf ) ; if ( ent_type == FREE_ENTRY ) { entry -> EntrySec = sec_num ; entry -> EntrySecOffset = buf - FATBuffer ; return ( OK ) ; } if ( ent_type == LAST_ENTRY ) { return ( ERR_ROOT_DIR_FULL ) ; } else { buf += 32 ; } } } return ( ERR_ROOT_DIR_FULL ) ; }
GET GREE ENTRY
Description: This function searches for a free entry in the root directory.
GET GREE ENTRY Description : This function searches for a free entry in the root directory .