diff options
author | Jens Arnold <amiconn@rockbox.org> | 2004-10-10 00:35:19 +0000 |
---|---|---|
committer | Jens Arnold <amiconn@rockbox.org> | 2004-10-10 00:35:19 +0000 |
commit | f5bdf6952c49ed6ab08020a93cbd2a07d4ea0901 (patch) | |
tree | 035b188d557584fb9055766a43da32e4085eb471 /firmware | |
parent | 0660105af276058befa41311d50432dcf9453f47 (diff) | |
download | rockbox-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
Diffstat (limited to 'firmware')
-rw-r--r-- | firmware/drivers/ata_mmc.c | 76 | ||||
-rw-r--r-- | firmware/export/kernel.h | 4 |
2 files changed, 50 insertions, 30 deletions
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 | ||
91 | static struct mutex mmc_mutex; | 90 | static struct mutex mmc_mutex; |
92 | 91 | ||
93 | static char mmc_stack[DEFAULT_STACK_SIZE]; | ||
94 | static const char mmc_thread_name[] = "mmc"; | ||
95 | static struct event_queue mmc_queue; | ||
96 | static bool initialized = false; | 92 | static bool initialized = false; |
97 | static bool delayed_write = false; | 93 | static bool delayed_write = false; |
98 | static unsigned char delayed_sector[SECTOR_SIZE]; | 94 | static unsigned char delayed_sector[SECTOR_SIZE]; |
@@ -115,6 +111,8 @@ static int current_buffer = 0; | |||
115 | 111 | ||
116 | static tCardInfo card_info[2]; | 112 | static tCardInfo card_info[2]; |
117 | static int current_card = 0; | 113 | static int current_card = 0; |
114 | static bool last_mmc_status = false; | ||
115 | static 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); | |||
137 | static int send_sector(const unsigned char *nextbuf, int timeout); | 135 | static int send_sector(const unsigned char *nextbuf, int timeout); |
138 | static int send_single_sector(const unsigned char *buf, int timeout); | 136 | static int send_single_sector(const unsigned char *buf, int timeout); |
139 | 137 | ||
138 | static bool mmc_detect(void); | ||
139 | static void mmc_tick(void); | ||
140 | |||
140 | /* implementation */ | 141 | /* implementation */ |
141 | 142 | ||
142 | static int select_card(int card_no) | 143 | static 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 | ||
760 | static void mmc_thread(void) | 763 | static 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) { | 768 | static 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 | |||
42 | struct event | 46 | struct event |
43 | { | 47 | { |
44 | int id; | 48 | int id; |