diff options
-rw-r--r-- | firmware/drivers/ata_mmc.c | 39 | ||||
-rw-r--r-- | firmware/export/kernel.h | 1 |
2 files changed, 40 insertions, 0 deletions
diff --git a/firmware/drivers/ata_mmc.c b/firmware/drivers/ata_mmc.c index a62f778cfd..293ccaf616 100644 --- a/firmware/drivers/ata_mmc.c +++ b/firmware/drivers/ata_mmc.c | |||
@@ -32,6 +32,7 @@ | |||
32 | #include "hwcompat.h" | 32 | #include "hwcompat.h" |
33 | #include "adc.h" | 33 | #include "adc.h" |
34 | #include "bitswap.h" | 34 | #include "bitswap.h" |
35 | #include "disk.h" /* for mount/unmount */ | ||
35 | 36 | ||
36 | #define SECTOR_SIZE 512 | 37 | #define SECTOR_SIZE 512 |
37 | 38 | ||
@@ -89,6 +90,11 @@ long last_disk_activity = -1; | |||
89 | 90 | ||
90 | static struct mutex mmc_mutex; | 91 | static struct mutex mmc_mutex; |
91 | 92 | ||
93 | #ifdef HAVE_HOTSWAP | ||
94 | static char mmc_stack[DEFAULT_STACK_SIZE]; | ||
95 | static const char mmc_thread_name[] = "mmc"; | ||
96 | static struct event_queue mmc_queue; | ||
97 | #endif | ||
92 | static bool initialized = false; | 98 | static bool initialized = false; |
93 | static bool delayed_write = false; | 99 | static bool delayed_write = false; |
94 | static unsigned char delayed_sector[SECTOR_SIZE]; | 100 | static unsigned char delayed_sector[SECTOR_SIZE]; |
@@ -786,6 +792,34 @@ void ata_spin(void) | |||
786 | { | 792 | { |
787 | } | 793 | } |
788 | 794 | ||
795 | #ifdef HAVE_HOTSWAP | ||
796 | static void mmc_thread(void) | ||
797 | { | ||
798 | struct event ev; | ||
799 | |||
800 | while (1) { | ||
801 | queue_wait(&mmc_queue, &ev); | ||
802 | switch ( ev.id ) { | ||
803 | case SYS_USB_CONNECTED: | ||
804 | usb_acknowledge(SYS_USB_CONNECTED_ACK); | ||
805 | /* Wait until the USB cable is extracted again */ | ||
806 | usb_wait_for_disconnect(&mmc_queue); | ||
807 | break; | ||
808 | |||
809 | case SYS_MMC_INSERTED: | ||
810 | disk_mount(1); /* mount MMC */ | ||
811 | queue_broadcast(SYS_FS_CHANGED, NULL); | ||
812 | break; | ||
813 | |||
814 | case SYS_MMC_EXTRACTED: | ||
815 | disk_unmount(1); /* release "by force" */ | ||
816 | queue_broadcast(SYS_FS_CHANGED, NULL); | ||
817 | break; | ||
818 | } | ||
819 | } | ||
820 | } | ||
821 | #endif /* #ifdef HAVE_HOTSWAP */ | ||
822 | |||
789 | bool mmc_detect(void) | 823 | bool mmc_detect(void) |
790 | { | 824 | { |
791 | return adc_read(ADC_MMC_SWITCH) < 0x200 ? true : false; | 825 | return adc_read(ADC_MMC_SWITCH) < 0x200 ? true : false; |
@@ -880,6 +914,11 @@ int ata_init(void) | |||
880 | 914 | ||
881 | if ( !initialized ) | 915 | if ( !initialized ) |
882 | { | 916 | { |
917 | #ifdef HAVE_HOTSWAP | ||
918 | queue_init(&mmc_queue); | ||
919 | create_thread(mmc_thread, mmc_stack, | ||
920 | sizeof(mmc_stack), mmc_thread_name); | ||
921 | #endif | ||
883 | tick_add_task(mmc_tick); | 922 | tick_add_task(mmc_tick); |
884 | initialized = true; | 923 | initialized = true; |
885 | } | 924 | } |
diff --git a/firmware/export/kernel.h b/firmware/export/kernel.h index 1a238a66af..3816d71340 100644 --- a/firmware/export/kernel.h +++ b/firmware/export/kernel.h | |||
@@ -42,6 +42,7 @@ | |||
42 | #define SYS_MMC_INSERTED ((SYS_EVENT | ((long)6 << 27))) | 42 | #define SYS_MMC_INSERTED ((SYS_EVENT | ((long)6 << 27))) |
43 | #define SYS_MMC_EXTRACTED ((SYS_EVENT | ((long)7 << 27))) | 43 | #define SYS_MMC_EXTRACTED ((SYS_EVENT | ((long)7 << 27))) |
44 | #define SYS_POWEROFF ((SYS_EVENT | ((long)8 << 27))) | 44 | #define SYS_POWEROFF ((SYS_EVENT | ((long)8 << 27))) |
45 | #define SYS_FS_CHANGED ((SYS_EVENT | ((long)9 << 27))) | ||
45 | 46 | ||
46 | struct event | 47 | struct event |
47 | { | 48 | { |