summaryrefslogtreecommitdiff
path: root/firmware
diff options
context:
space:
mode:
authorJens Arnold <amiconn@rockbox.org>2004-10-10 00:35:19 +0000
committerJens Arnold <amiconn@rockbox.org>2004-10-10 00:35:19 +0000
commitf5bdf6952c49ed6ab08020a93cbd2a07d4ea0901 (patch)
tree035b188d557584fb9055766a43da32e4085eb471 /firmware
parent0660105af276058befa41311d50432dcf9453f47 (diff)
downloadrockbox-f5bdf6952c49ed6ab08020a93cbd2a07d4ea0901.zip
rockbox-f5bdf6952c49ed6ab08020a93cbd2a07d4ea0901.tar.gz
rockbox-f5bdf6952c49ed6ab08020a93cbd2a07d4ea0901.tar.bz2
rockbox-f5bdf6952c49ed6ab08020a93cbd2a07d4ea0901.tar.xz
First part of MMC hotswap handling; removed unnecessary MMC thread
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@5241 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'firmware')
-rw-r--r--firmware/drivers/ata_mmc.c76
-rw-r--r--firmware/export/kernel.h4
2 files changed, 50 insertions, 30 deletions
diff --git a/firmware/drivers/ata_mmc.c b/firmware/drivers/ata_mmc.c
index 4873392..7b3b8d1 100644
--- a/firmware/drivers/ata_mmc.c
+++ b/firmware/drivers/ata_mmc.c
@@ -31,7 +31,6 @@
#include "string.h"
#include "hwcompat.h"
#include "adc.h"
-
#include "bitswap.h"
#define SECTOR_SIZE 512
@@ -90,9 +89,6 @@ long last_disk_activity = -1;
static struct mutex mmc_mutex;
-static char mmc_stack[DEFAULT_STACK_SIZE];
-static const char mmc_thread_name[] = "mmc";
-static struct event_queue mmc_queue;
static bool initialized = false;
static bool delayed_write = false;
static unsigned char delayed_sector[SECTOR_SIZE];
@@ -115,6 +111,8 @@ static int current_buffer = 0;
static tCardInfo card_info[2];
static int current_card = 0;
+static bool last_mmc_status = false;
+static int countdown; /* for mmc switch debouncing */
/* private function declarations */
@@ -137,6 +135,9 @@ static void swapcopy_sector(const unsigned char *buf);
static int send_sector(const unsigned char *nextbuf, int timeout);
static int send_single_sector(const unsigned char *buf, int timeout);
+static bool mmc_detect(void);
+static void mmc_tick(void);
+
/* implementation */
static int select_card(int card_no)
@@ -475,10 +476,12 @@ tCardInfo *mmc_card_info(int card_no)
{
tCardInfo *card = &card_info[card_no];
- if (!card->initialized)
+ if (!card->initialized && ((card_no == 0) || mmc_detect()))
{
+ mutex_lock(&mmc_mutex);
select_card(card_no);
deselect_card();
+ mutex_unlock(&mmc_mutex);
}
return card;
}
@@ -757,27 +760,42 @@ void ata_spin(void)
{
}
-static void mmc_thread(void)
+static bool mmc_detect(void)
{
- struct event ev;
+ return adc_read(ADC_MMC_SWITCH) < 0x200 ? true : false;
+}
- while (1) {
- while ( queue_empty( &mmc_queue ) ) {
+static void mmc_tick(void)
+{
+ bool current_status;
- sleep(HZ/4);
- }
- queue_wait(&mmc_queue, &ev);
- switch ( ev.id ) {
-#ifndef USB_NONE
- case SYS_USB_CONNECTED:
- /* Tell the USB thread that we are safe */
- DEBUGF("mmc_thread got SYS_USB_CONNECTED\n");
- usb_acknowledge(SYS_USB_CONNECTED_ACK);
-
- /* Wait until the USB cable is extracted again */
- usb_wait_for_disconnect(&mmc_queue);
- break;
-#endif
+ 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
+ {
+ /* Count down until it gets negative */
+ if (countdown >= 0)
+ countdown--;
+
+ /* Report to the thread if we have had 3 identical status
+ readings in a row */
+ if (countdown == 0)
+ {
+ if (current_status)
+ {
+ queue_broadcast(SYS_MMC_INSERTED, NULL);
+ }
+ else
+ {
+ queue_broadcast(SYS_MMC_EXTRACTED, NULL);
+ card_info[1].initialized = false;
+ }
}
}
}
@@ -822,7 +840,8 @@ int ata_init(void)
PBIOR |= 0x2000; /* SCK1 output */
PBIOR &= ~0x0C00; /* TxD1, RxD1 input */
- if(adc_read(ADC_MMC_SWITCH) < 0x200)
+ last_mmc_status = mmc_detect();
+ if (last_mmc_status)
{ /* MMC inserted */
current_card = 1;
}
@@ -833,12 +852,9 @@ int ata_init(void)
ata_enable(true);
- if ( !initialized ) {
-
- queue_init(&mmc_queue);
-
- create_thread(mmc_thread, mmc_stack,
- sizeof(mmc_stack), mmc_thread_name);
+ if ( !initialized )
+ {
+ tick_add_task(mmc_tick);
initialized = true;
}
diff --git a/firmware/export/kernel.h b/firmware/export/kernel.h
index 0e8797f..25e537d 100644
--- a/firmware/export/kernel.h
+++ b/firmware/export/kernel.h
@@ -39,6 +39,10 @@
#define SYS_USB_DISCONNECTED_ACK -4
#define SYS_TIMEOUT -5
+/* MMC based systems only */
+#define SYS_MMC_INSERTED -6
+#define SYS_MMC_EXTRACTED -7
+
struct event
{
int id;