diff options
author | Frank Gevaerts <frank@gevaerts.be> | 2010-06-06 13:20:47 +0000 |
---|---|---|
committer | Frank Gevaerts <frank@gevaerts.be> | 2010-06-06 13:20:47 +0000 |
commit | 9c43b2ce17cbc1f88b825ab8a5021575cee46dd7 (patch) | |
tree | 8d96e95861b3b0df1a7efa6b660395c317ecb475 /firmware/drivers/ata_mmc.c | |
parent | 4a2cab6aa1008a4f5ac05dac44c99b7f1a05e8f4 (diff) | |
download | rockbox-9c43b2ce17cbc1f88b825ab8a5021575cee46dd7.tar.gz rockbox-9c43b2ce17cbc1f88b825ab8a5021575cee46dd7.zip |
Remove card_enable_monitoring() and use a mutex instead. The card_enable_monitoring() method actually didn't eliminate the possible race conditions it was meant to fix.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@26627 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'firmware/drivers/ata_mmc.c')
-rw-r--r-- | firmware/drivers/ata_mmc.c | 60 |
1 files changed, 24 insertions, 36 deletions
diff --git a/firmware/drivers/ata_mmc.c b/firmware/drivers/ata_mmc.c index 5da0b44292..c27c3b5d05 100644 --- a/firmware/drivers/ata_mmc.c +++ b/firmware/drivers/ata_mmc.c | |||
@@ -93,7 +93,6 @@ static long last_disk_activity = -1; | |||
93 | static struct mutex mmc_mutex; | 93 | static struct mutex mmc_mutex; |
94 | 94 | ||
95 | #ifdef HAVE_HOTSWAP | 95 | #ifdef HAVE_HOTSWAP |
96 | static bool mmc_monitor_enabled = true; | ||
97 | static long mmc_stack[((DEFAULT_STACK_SIZE*2) + 0x800)/sizeof(long)]; | 96 | static long mmc_stack[((DEFAULT_STACK_SIZE*2) + 0x800)/sizeof(long)]; |
98 | #else | 97 | #else |
99 | static long mmc_stack[(DEFAULT_STACK_SIZE*2)/sizeof(long)]; | 98 | static long mmc_stack[(DEFAULT_STACK_SIZE*2)/sizeof(long)]; |
@@ -130,7 +129,9 @@ static tCardInfo card_info[2]; | |||
130 | static int current_card = 0; | 129 | static int current_card = 0; |
131 | #endif | 130 | #endif |
132 | static bool last_mmc_status = false; | 131 | static bool last_mmc_status = false; |
133 | static int countdown = HZ/3; /* for mmc switch debouncing */ | 132 | static int countdown = -1; /* for mmc switch debouncing. -1 because the |
133 | countdown should not happen if the card | ||
134 | is inserted at boot */ | ||
134 | static bool usb_activity; /* monitoring the USB bridge */ | 135 | static bool usb_activity; /* monitoring the USB bridge */ |
135 | static long last_usb_activity; | 136 | static long last_usb_activity; |
136 | 137 | ||
@@ -807,13 +808,6 @@ static void mmc_thread(void) | |||
807 | } | 808 | } |
808 | } | 809 | } |
809 | 810 | ||
810 | #ifdef HAVE_HOTSWAP | ||
811 | void mmc_enable_monitoring(bool on) | ||
812 | { | ||
813 | mmc_monitor_enabled = on; | ||
814 | } | ||
815 | #endif | ||
816 | |||
817 | bool mmc_detect(void) | 811 | bool mmc_detect(void) |
818 | { | 812 | { |
819 | return (adc_read(ADC_MMC_SWITCH) < 0x200); | 813 | return (adc_read(ADC_MMC_SWITCH) < 0x200); |
@@ -846,9 +840,6 @@ bool mmc_usb_active(int delayticks) | |||
846 | static void mmc_tick(void) | 840 | static void mmc_tick(void) |
847 | { | 841 | { |
848 | bool current_status; | 842 | bool current_status; |
849 | #ifndef HAVE_HOTSWAP | ||
850 | const bool mmc_monitor_enabled = true; | ||
851 | #endif | ||
852 | 843 | ||
853 | if (new_mmc_circuit) | 844 | if (new_mmc_circuit) |
854 | /* USB bridge activity is 0 on idle, ~527 on active */ | 845 | /* USB bridge activity is 0 on idle, ~527 on active */ |
@@ -860,33 +851,30 @@ static void mmc_tick(void) | |||
860 | last_usb_activity = current_tick; | 851 | last_usb_activity = current_tick; |
861 | usb_activity = current_status; | 852 | usb_activity = current_status; |
862 | 853 | ||
863 | if (mmc_monitor_enabled) | 854 | current_status = mmc_detect(); |
855 | /* Only report when the status has changed */ | ||
856 | if (current_status != last_mmc_status) | ||
864 | { | 857 | { |
865 | current_status = mmc_detect(); | 858 | last_mmc_status = current_status; |
866 | /* Only report when the status has changed */ | 859 | countdown = HZ/3; |
867 | if (current_status != last_mmc_status) | 860 | } |
868 | { | 861 | else |
869 | last_mmc_status = current_status; | 862 | { |
870 | countdown = HZ/3; | 863 | /* Count down until it gets negative */ |
871 | } | 864 | if (countdown >= 0) |
872 | else | 865 | countdown--; |
873 | { | ||
874 | /* Count down until it gets negative */ | ||
875 | if (countdown >= 0) | ||
876 | countdown--; | ||
877 | 866 | ||
878 | if (countdown == 0) | 867 | if (countdown == 0) |
868 | { | ||
869 | if (current_status) | ||
879 | { | 870 | { |
880 | if (current_status) | 871 | queue_broadcast(SYS_HOTSWAP_INSERTED, 0); |
881 | { | 872 | } |
882 | queue_broadcast(SYS_HOTSWAP_INSERTED, 0); | 873 | else |
883 | } | 874 | { |
884 | else | 875 | queue_broadcast(SYS_HOTSWAP_EXTRACTED, 0); |
885 | { | 876 | mmc_status = MMC_UNTOUCHED; |
886 | queue_broadcast(SYS_HOTSWAP_EXTRACTED, 0); | 877 | card_info[1].initialized = false; |
887 | mmc_status = MMC_UNTOUCHED; | ||
888 | card_info[1].initialized = false; | ||
889 | } | ||
890 | } | 878 | } |
891 | } | 879 | } |
892 | } | 880 | } |