summaryrefslogtreecommitdiff
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
parent0660105af276058befa41311d50432dcf9453f47 (diff)
downloadrockbox-f5bdf6952c49ed6ab08020a93cbd2a07d4ea0901.tar.gz
rockbox-f5bdf6952c49ed6ab08020a93cbd2a07d4ea0901.zip
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
-rw-r--r--apps/debug_menu.c2
-rw-r--r--firmware/drivers/ata_mmc.c76
-rw-r--r--firmware/export/kernel.h4
3 files changed, 51 insertions, 31 deletions
diff --git a/apps/debug_menu.c b/apps/debug_menu.c
index ccf9f81888..02c4f096ae 100644
--- a/apps/debug_menu.c
+++ b/apps/debug_menu.c
@@ -1371,7 +1371,7 @@ bool dbg_mmc_info(void)
1371 1371
1372 lcd_update(); 1372 lcd_update();
1373 1373
1374 switch (button_get(true)) 1374 switch (button_get_w_tmo(HZ/2))
1375 { 1375 {
1376 case SETTINGS_OK: 1376 case SETTINGS_OK:
1377 case SETTINGS_CANCEL: 1377 case SETTINGS_CANCEL:
diff --git a/firmware/drivers/ata_mmc.c b/firmware/drivers/ata_mmc.c
index 487339292b..7b3b8d1ea8 100644
--- a/firmware/drivers/ata_mmc.c
+++ b/firmware/drivers/ata_mmc.c
@@ -31,7 +31,6 @@
31#include "string.h" 31#include "string.h"
32#include "hwcompat.h" 32#include "hwcompat.h"
33#include "adc.h" 33#include "adc.h"
34
35#include "bitswap.h" 34#include "bitswap.h"
36 35
37#define SECTOR_SIZE 512 36#define SECTOR_SIZE 512
@@ -90,9 +89,6 @@ long last_disk_activity = -1;
90 89
91static struct mutex mmc_mutex; 90static struct mutex mmc_mutex;
92 91
93static char mmc_stack[DEFAULT_STACK_SIZE];
94static const char mmc_thread_name[] = "mmc";
95static struct event_queue mmc_queue;
96static bool initialized = false; 92static bool initialized = false;
97static bool delayed_write = false; 93static bool delayed_write = false;
98static unsigned char delayed_sector[SECTOR_SIZE]; 94static unsigned char delayed_sector[SECTOR_SIZE];
@@ -115,6 +111,8 @@ static int current_buffer = 0;
115 111
116static tCardInfo card_info[2]; 112static tCardInfo card_info[2];
117static int current_card = 0; 113static int current_card = 0;
114static bool last_mmc_status = false;
115static int countdown; /* for mmc switch debouncing */
118 116
119/* private function declarations */ 117/* private function declarations */
120 118
@@ -137,6 +135,9 @@ static void swapcopy_sector(const unsigned char *buf);
137static int send_sector(const unsigned char *nextbuf, int timeout); 135static int send_sector(const unsigned char *nextbuf, int timeout);
138static int send_single_sector(const unsigned char *buf, int timeout); 136static int send_single_sector(const unsigned char *buf, int timeout);
139 137
138static bool mmc_detect(void);
139static void mmc_tick(void);
140
140/* implementation */ 141/* implementation */
141 142
142static int select_card(int card_no) 143static int select_card(int card_no)
@@ -475,10 +476,12 @@ tCardInfo *mmc_card_info(int card_no)
475{ 476{
476 tCardInfo *card = &card_info[card_no]; 477 tCardInfo *card = &card_info[card_no];
477 478
478 if (!card->initialized) 479 if (!card->initialized && ((card_no == 0) || mmc_detect()))
479 { 480 {
481 mutex_lock(&mmc_mutex);
480 select_card(card_no); 482 select_card(card_no);
481 deselect_card(); 483 deselect_card();
484 mutex_unlock(&mmc_mutex);
482 } 485 }
483 return card; 486 return card;
484} 487}
@@ -757,27 +760,42 @@ void ata_spin(void)
757{ 760{
758} 761}
759 762
760static void mmc_thread(void) 763static bool mmc_detect(void)
761{ 764{
762 struct event ev; 765 return adc_read(ADC_MMC_SWITCH) < 0x200 ? true : false;
766}
763 767
764 while (1) { 768static void mmc_tick(void)
765 while ( queue_empty( &mmc_queue ) ) { 769{
770 bool current_status;
766 771
767 sleep(HZ/4); 772 current_status = mmc_detect();
768 } 773
769 queue_wait(&mmc_queue, &ev); 774 /* Only report when the status has changed */
770 switch ( ev.id ) { 775 if (current_status != last_mmc_status)
771#ifndef USB_NONE 776 {
772 case SYS_USB_CONNECTED: 777 last_mmc_status = current_status;
773 /* Tell the USB thread that we are safe */ 778 countdown = 30;
774 DEBUGF("mmc_thread got SYS_USB_CONNECTED\n"); 779 }
775 usb_acknowledge(SYS_USB_CONNECTED_ACK); 780 else
776 781 {
777 /* Wait until the USB cable is extracted again */ 782 /* Count down until it gets negative */
778 usb_wait_for_disconnect(&mmc_queue); 783 if (countdown >= 0)
779 break; 784 countdown--;
780#endif 785
786 /* Report to the thread if we have had 3 identical status
787 readings in a row */
788 if (countdown == 0)
789 {
790 if (current_status)
791 {
792 queue_broadcast(SYS_MMC_INSERTED, NULL);
793 }
794 else
795 {
796 queue_broadcast(SYS_MMC_EXTRACTED, NULL);
797 card_info[1].initialized = false;
798 }
781 } 799 }
782 } 800 }
783} 801}
@@ -822,7 +840,8 @@ int ata_init(void)
822 PBIOR |= 0x2000; /* SCK1 output */ 840 PBIOR |= 0x2000; /* SCK1 output */
823 PBIOR &= ~0x0C00; /* TxD1, RxD1 input */ 841 PBIOR &= ~0x0C00; /* TxD1, RxD1 input */
824 842
825 if(adc_read(ADC_MMC_SWITCH) < 0x200) 843 last_mmc_status = mmc_detect();
844 if (last_mmc_status)
826 { /* MMC inserted */ 845 { /* MMC inserted */
827 current_card = 1; 846 current_card = 1;
828 } 847 }
@@ -833,12 +852,9 @@ int ata_init(void)
833 852
834 ata_enable(true); 853 ata_enable(true);
835 854
836 if ( !initialized ) { 855 if ( !initialized )
837 856 {
838 queue_init(&mmc_queue); 857 tick_add_task(mmc_tick);
839
840 create_thread(mmc_thread, mmc_stack,
841 sizeof(mmc_stack), mmc_thread_name);
842 initialized = true; 858 initialized = true;
843 } 859 }
844 860
diff --git a/firmware/export/kernel.h b/firmware/export/kernel.h
index 0e8797f98c..25e537dc55 100644
--- a/firmware/export/kernel.h
+++ b/firmware/export/kernel.h
@@ -39,6 +39,10 @@
39#define SYS_USB_DISCONNECTED_ACK -4 39#define SYS_USB_DISCONNECTED_ACK -4
40#define SYS_TIMEOUT -5 40#define SYS_TIMEOUT -5
41 41
42/* MMC based systems only */
43#define SYS_MMC_INSERTED -6
44#define SYS_MMC_EXTRACTED -7
45
42struct event 46struct event
43{ 47{
44 int id; 48 int id;