summaryrefslogtreecommitdiff
path: root/firmware
diff options
context:
space:
mode:
authorRafaël Carré <rafael.carre@gmail.com>2010-03-15 02:36:16 +0000
committerRafaël Carré <rafael.carre@gmail.com>2010-03-15 02:36:16 +0000
commitba68f2dedd8714d5a6f75dabc5396cb81d7900de (patch)
treeeaabcd0e9d76f0b9625ca59e44280566c522b4b5 /firmware
parent72e0bf3381601e24f83b28815c6dcb4cfb586aaa (diff)
sd-as3525v2: add card hotswap to sd_thread
Clip+: add (disabled) configuration for µSD slot git-svn-id: svn://svn.rockbox.org/rockbox/trunk@25194 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'firmware')
-rw-r--r--firmware/export/config/sansaclipplus.h8
-rw-r--r--firmware/target/arm/as3525/sd-as3525v2.c48
2 files changed, 56 insertions, 0 deletions
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 <stdarg.h>
#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)))
{