summaryrefslogtreecommitdiff
path: root/firmware/drivers
diff options
context:
space:
mode:
Diffstat (limited to 'firmware/drivers')
-rw-r--r--firmware/drivers/ata_mmc.c39
1 files changed, 39 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
90static struct mutex mmc_mutex; 91static struct mutex mmc_mutex;
91 92
93#ifdef HAVE_HOTSWAP
94static char mmc_stack[DEFAULT_STACK_SIZE];
95static const char mmc_thread_name[] = "mmc";
96static struct event_queue mmc_queue;
97#endif
92static bool initialized = false; 98static bool initialized = false;
93static bool delayed_write = false; 99static bool delayed_write = false;
94static unsigned char delayed_sector[SECTOR_SIZE]; 100static unsigned char delayed_sector[SECTOR_SIZE];
@@ -786,6 +792,34 @@ void ata_spin(void)
786{ 792{
787} 793}
788 794
795#ifdef HAVE_HOTSWAP
796static 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
789bool mmc_detect(void) 823bool 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 }