diff options
Diffstat (limited to 'firmware/target/arm/as3525/sd-as3525v2.c')
-rw-r--r-- | firmware/target/arm/as3525/sd-as3525v2.c | 41 |
1 files changed, 17 insertions, 24 deletions
diff --git a/firmware/target/arm/as3525/sd-as3525v2.c b/firmware/target/arm/as3525/sd-as3525v2.c index ae3dde4495..b4ac40152b 100644 --- a/firmware/target/arm/as3525/sd-as3525v2.c +++ b/firmware/target/arm/as3525/sd-as3525v2.c @@ -598,21 +598,13 @@ static void sd_thread(void) { #ifdef HAVE_HOTSWAP case SYS_HOTSWAP_INSERTED: - case SYS_HOTSWAP_EXTRACTED: - { - int changed = 1; - fat_lock(); /* lock-out FAT activity first - - prevent deadlocking via disk_mount that - would cause a reverse-order attempt with - another thread */ - mutex_lock(&sd_mtx); /* lock-out card activity - direct calls - into driver that bypass the fat cache */ - - /* We now have exclusive control of fat cache and ata */ - - disk_unmount(SD_SLOT_AS3525); /* release "by force", ensure file - descriptors aren't leaked and any busy - ones are invalid if mounting */ + case SYS_HOTSWAP_EXTRACTED:; + int success = 1; + + disk_unmount(SD_SLOT_AS3525); /* release "by force" */ + + mutex_lock(&sd_mtx); /* lock-out card activity */ + /* Force card init for new card, re-init for re-inserted one or * clear if the last attempt to init failed with an error. */ card_info[SD_SLOT_AS3525].initialized = 0; @@ -620,24 +612,25 @@ static void sd_thread(void) if (ev.id == SYS_HOTSWAP_INSERTED) { sd_enable(true); - changed = (sd_init_card(SD_SLOT_AS3525) == 0) && disk_mount(SD_SLOT_AS3525); /* 0 if fail */ + success = sd_init_card(SD_SLOT_AS3525) == 0 ? 2 : 0; + sd_enable(false); } + mutex_unlock(&sd_mtx); + + if (success > 1) + success = disk_mount(SD_SLOT_AS3525); /* 0 if fail */ + /* * Mount succeeded, or this was an EXTRACTED event, * in both cases notify the system about the changed filesystems */ - if (changed) + if (success) queue_broadcast(SYS_FS_CHANGED, 0); - sd_enable(false); - - /* Access is now safe */ - mutex_unlock(&sd_mtx); - fat_unlock(); - } break; -#endif +#endif /* HAVE_HOTSWAP */ + case SYS_TIMEOUT: if (TIME_BEFORE(current_tick, last_disk_activity+(3*HZ))) { |