From ba68f2dedd8714d5a6f75dabc5396cb81d7900de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafa=C3=ABl=20Carr=C3=A9?= Date: Mon, 15 Mar 2010 02:36:16 +0000 Subject: sd-as3525v2: add card hotswap to sd_thread MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Clip+: add (disabled) configuration for µSD slot git-svn-id: svn://svn.rockbox.org/rockbox/trunk@25194 a1c6a512-1295-4272-9138-f99709370657 --- firmware/export/config/sansaclipplus.h | 8 ++++++ firmware/target/arm/as3525/sd-as3525v2.c | 48 ++++++++++++++++++++++++++++++++ 2 files changed, 56 insertions(+) (limited to 'firmware') diff --git a/firmware/export/config/sansaclipplus.h b/firmware/export/config/sansaclipplus.h index c297d74dfb..cc9f09fe86 100644 --- a/firmware/export/config/sansaclipplus.h +++ b/firmware/export/config/sansaclipplus.h @@ -9,6 +9,14 @@ #define FIRMWARE_OFFSET_FILE_DATA 8 #define FIRMWARE_OFFSET_FILE_CRC 0 +#if 0 /* TODO */ +#ifndef BOOTLOADER +#define HAVE_MULTIDRIVE +#define NUM_DRIVES 2 +#define HAVE_HOTSWAP +#endif +#endif + #if 0 /* disabled since there is no driver (yet) */ #define HW_SAMPR_CAPS (SAMPR_CAP_44) diff --git a/firmware/target/arm/as3525/sd-as3525v2.c b/firmware/target/arm/as3525/sd-as3525v2.c index 4b62fa9339..862479d57a 100644 --- a/firmware/target/arm/as3525/sd-as3525v2.c +++ b/firmware/target/arm/as3525/sd-as3525v2.c @@ -39,6 +39,10 @@ #include "ata_idle_notify.h" #include "sd.h" +#ifdef HAVE_HOTSWAP +#include "disk.h" +#endif + #include "lcd.h" #include #include "sysfont.h" @@ -484,6 +488,50 @@ static void sd_thread(void) switch ( ev.id ) { +#ifdef HAVE_HOTSWAP + case SYS_HOTSWAP_INSERTED: + case SYS_HOTSWAP_EXTRACTED: + { + int microsd_init = 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 */ + /* 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; + + if (ev.id == SYS_HOTSWAP_INSERTED) + { + sd_enable(true); + microsd_init = sd_init_card(SD_SLOT_AS3525); + if (microsd_init < 0) /* initialisation failed */ + panicf("microSD init failed : %d", microsd_init); + + microsd_init = 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 (microsd_init) + queue_broadcast(SYS_FS_CHANGED, 0); + /* Access is now safe */ + mutex_unlock(&sd_mtx); + fat_unlock(); + sd_enable(false); + } + break; +#endif case SYS_TIMEOUT: if (TIME_BEFORE(current_tick, last_disk_activity+(3*HZ))) { -- cgit v1.2.3