All pastes #496857 Raw Edit

Unnamed

public text v1 · immutable
#496857 ·published 2007-05-19 14:12 UTC
rendered paste body
@@ -467,21 +511,37 @@
     unsigned int dummy;
     unsigned int response;
     unsigned int i;
-    tSDCardInfo *card = &card_info[current_card];
-
+    tSDCardInfo *card;
+    
     /* TODO: Add DMA support. */
 
-#ifdef HAVE_MULTIVOLUME
-    (void)drive; /* unused for now */
-#endif
     mutex_lock(&sd_mtx);
 
+    ata_enable(true);
+    ata_led(true);
+
+    if(drive && (GPIOA_INPUT_VAL & 0x80)) /* no external sd-card inserted */
+    {
+        ret = -9;
+        goto error;
+    }
+
+    if((drive != current_card) || !card_info[drive].initialized)
+    {
+        current_card = drive;
+        sd_init_device(drive);
+    }
+
+    card = &card_info[current_card];
+    if (!card->initialized)
+    {
+        ret = -9;
+        goto error;
+    }
+    
     last_disk_activity = current_tick;
     spinup_start = current_tick;
 
-    ata_enable(true);
-    ata_led(true);
-
     timeout = current_tick + READ_TIMEOUT;
 
     /* TODO: Select device */
@@ -529,6 +589,9 @@
         sd_wait_for_state(card, TRAN);
         break;
     }
+
+  error:
+
     ata_led(false);
     ata_enable(false);
 
@@ -551,11 +614,35 @@
     int ret = 0;
     unsigned int i;
     long timeout;
-    tSDCardInfo *card = &card_info[current_card];
+    tSDCardInfo *card;
 
     mutex_lock(&sd_mtx);
+
     ata_enable(true);
     ata_led(true);
+
+    if(drive && (GPIOA_INPUT_VAL & 0x80)) /* no external sd-card inserted */
+    {
+        ret = -9;
+        goto error;
+    }
+
+    if((drive != current_card) || !card_info[drive].initialized)
+    {
+        current_card = drive;
+        sd_init_device(drive);
+    }
+
+    card = &card_info[current_card];
+    if (!card->initialized)
+    {
+        ret = -9;
+        goto error;
+    }
+    
+
+    card = &card_info[current_card];
+
     if(current_card == 0)
     {
         if(start < BLOCKS_PER_BANK)