From 15d7077c3ad2b7e3bcacf61a04428784b11e418c Mon Sep 17 00:00:00 2001 From: Jens Arnold Date: Mon, 16 May 2005 13:25:02 +0000 Subject: Hotswap: Avoid mount race at startup and after returning from USB mode. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@6479 a1c6a512-1295-4272-9138-f99709370657 --- apps/main.c | 3 +++ firmware/drivers/ata_mmc.c | 52 ++++++++++++++++++++++++++++------------------ firmware/export/ata_mmc.h | 3 +++ firmware/usb.c | 6 ++++++ 4 files changed, 44 insertions(+), 20 deletions(-) diff --git a/apps/main.c b/apps/main.c index 25bc9296e5..edcff92995 100644 --- a/apps/main.c +++ b/apps/main.c @@ -233,6 +233,9 @@ void init(void) usb_screen(); system_reboot(); } +#if defined(HAVE_MMC) && defined(HAVE_HOTSWAP) + mmc_enable_monitoring(true); +#endif settings_calc_config_sector(); settings_load(SETTINGS_ALL); diff --git a/firmware/drivers/ata_mmc.c b/firmware/drivers/ata_mmc.c index 5afb6ca8a1..aa333dba32 100644 --- a/firmware/drivers/ata_mmc.c +++ b/firmware/drivers/ata_mmc.c @@ -94,6 +94,7 @@ static struct mutex mmc_mutex; static long mmc_stack[(DEFAULT_STACK_SIZE + 0x800)/sizeof(long)]; static const char mmc_thread_name[] = "mmc"; static struct event_queue mmc_queue; +static bool mmc_monitor_enabled = false; #endif static bool initialized = false; static bool new_mmc_circuit; @@ -1033,6 +1034,11 @@ static void mmc_thread(void) } } } + +void mmc_enable_monitoring(bool on) +{ + mmc_monitor_enabled = on; +} #endif /* #ifdef HAVE_HOTSWAP */ bool mmc_detect(void) @@ -1050,6 +1056,9 @@ bool mmc_usb_active(int delayticks) static void mmc_tick(void) { bool current_status; +#ifndef HAVE_HOTSWAP + const bool mmc_monitor_enabled = true; +#endif if (new_mmc_circuit) /* USB bridge activity is 0 on idle, ~527 on active */ @@ -1061,29 +1070,32 @@ static void mmc_tick(void) last_usb_activity = current_tick; usb_activity = current_status; - current_status = mmc_detect(); - /* Only report when the status has changed */ - if (current_status != last_mmc_status) - { - last_mmc_status = current_status; - countdown = 30; - } - else + if (mmc_monitor_enabled) { - /* Count down until it gets negative */ - if (countdown >= 0) - countdown--; - - if (countdown == 0) + current_status = mmc_detect(); + /* Only report when the status has changed */ + if (current_status != last_mmc_status) { - if (current_status) - { - queue_broadcast(SYS_MMC_INSERTED, NULL); - } - else + last_mmc_status = current_status; + countdown = 30; + } + else + { + /* Count down until it gets negative */ + if (countdown >= 0) + countdown--; + + if (countdown == 0) { - queue_broadcast(SYS_MMC_EXTRACTED, NULL); - card_info[1].initialized = false; + if (current_status) + { + queue_broadcast(SYS_MMC_INSERTED, NULL); + } + else + { + queue_broadcast(SYS_MMC_EXTRACTED, NULL); + card_info[1].initialized = false; + } } } } diff --git a/firmware/export/ata_mmc.h b/firmware/export/ata_mmc.h index 8b5056bbd8..6f7fb2bdb5 100644 --- a/firmware/export/ata_mmc.h +++ b/firmware/export/ata_mmc.h @@ -45,5 +45,8 @@ unsigned long mmc_extract_bits(const unsigned long *p, unsigned int start, unsigned int size); tCardInfo *mmc_card_info(int card_no); bool mmc_usb_active(int delayticks); +#ifdef HAVE_HOTSWAP +void mmc_enable_monitoring(bool on); +#endif #endif diff --git a/firmware/usb.c b/firmware/usb.c index 6095bcd65e..4b76fe60be 100644 --- a/firmware/usb.c +++ b/firmware/usb.c @@ -194,7 +194,13 @@ static void usb_slave_mode(bool on) panicf("ata: %d",rc); } +#if defined(HAVE_MMC) && defined(HAVE_HOTSWAP) + mmc_enable_monitoring(false); rc = disk_mount_all(); + mmc_enable_monitoring(true); +#else + rc = disk_mount_all(); +#endif if (rc <= 0) /* no partition */ panicf("mount: %d",rc); -- cgit v1.2.3