Skip to content

Library not fully initialized when card is inserted #1

@markregel

Description

@markregel

The global variables need to be initialized whenever a new SD card is initialized. To accomplish this task I added the function below and call it whenever a card needs to be initialized. Without doing this a bad card can leave the library in a non-functional state even after a new card is inserted.

//*******************************************************
//*******************************************************
//********** RESET NEW MMC / SD CARD ****************
//*******************************************************
//*******************************************************
//call this function to reset the library
BYTE ffs_reset(void)
{
BYTE b_temp;

ffs_card_ok = 0; //Flag that card not OK

sm_ffs_process = FFS_PROCESS_NO_CARD;
file_system_information_sector = 0;
ffs_no_of_heads = 0;
ffs_no_of_sectors_per_track = 0;
ffs_no_of_partition_sectors = 0;
card_is_high_capacity = 0;
chk_cmd_response_data = 0;

number_of_root_directory_sectors = 0; //Only used by FAT16, 0 for FAT32
ffs_buffer_needs_writing_to_card = 0;
ffs_buffer_contains_lba = 0xffffffff;
fat1_start_sector = 0;
root_directory_start_sector_cluster = 0; //Start sector for FAT16, start clustor for FAT32
data_area_start_sector = 0;
disk_is_fat_32 = 0;
sectors_per_cluster = 0;
last_found_free_cluster = 0;
sectors_per_fat = 0;
active_fat_table_flags = 0;
read_write_directory_last_lba = 0;
read_write_directory_last_entry = 0;
ffs_card_write_protected = 0;

//Reset all file handlers
for (b_temp = 0; b_temp < FFS_FOPEN_MAX; b_temp++)
ffs_file[b_temp].flags.bits.file_is_open = 0;

return 1;
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions