CDMS_CODE_samp_23SEP_DMA_flag

Dependencies:   FreescaleIAP SimpleDMA mbed-rtos mbed

Fork of CDMS_CODE_samp_23SEP_DMA by iitm sat

Revision:
261:1e54415b34d3
Parent:
257:7d404e9dc9e2
Child:
283:5ea9ea429b55
Child:
295:699801854b71
--- a/cdms_sd.h	Tue Jul 12 17:54:30 2016 +0000
+++ b/cdms_sd.h	Thu Jul 14 13:07:30 2016 +0000
@@ -4,7 +4,7 @@
 //Serial sd1(USBTX,USBRX);
 
 
-#define SD_COMMAND_TIMEOUT 5000
+#define SD_COMMAND_TIMEOUT 325
 
 #define SD_DBG             0
 
@@ -56,7 +56,7 @@
 int SD_WRITE(uint8_t*,uint32_t,uint8_t);
 int FCTN_CDMS_SD_INIT();
 uint8_t SD_READ(uint8_t*,uint32_t,uint8_t);
-#define SDCARD_FAIL 0
+#define SDCARD_FAIL 4
 #define SDCARD_V1   1
 #define SDCARD_V2   2
 #define SDCARD_V2HC 3
@@ -68,6 +68,8 @@
 int FCTN_CDMS_SD_INIT()
 {   
     int i = initialise_card();
+    if( i == 4)
+    return 4;
     debug_if(SD_DBG, "init card = %d\n", i);
     sectors = sd_sectors();
 
@@ -78,7 +80,7 @@
     } else {
     //printf("\rDisk initialization successfull\r\n");
     }
-
+    SD_STATUS = DEVICE_POWERED;
     spi.frequency(1000000); // Set to 1MHz for data transfer
     return 0;
 }
@@ -88,7 +90,9 @@
     uint32_t fsc;
     uint32_t start_fsc;
     uint8_t buffer[512];
-    int b=disk_read(buffer, SD_MNG_SECT);
+    int b;
+    if(SD_STATUS == DEVICE_POWERED){
+    b=disk_read(buffer, SD_MNG_SECT);
     
     fsc=(uint32_t)(buffer[0]<<24)+(uint32_t)(buffer[1]<<16)+(uint32_t)(buffer[2]<<8)+(uint32_t)buffer[3];
     start_fsc=(uint32_t)(buffer[4]<<24)+(uint32_t)(buffer[5]<<16)+(uint32_t)(buffer[6]<<8)+(uint32_t)buffer[7];
@@ -114,6 +118,7 @@
     start_fsc=(uint32_t)(buffer[36]<<24)+(uint32_t)(buffer[37]<<16)+(uint32_t)(buffer[38]<<8)+(uint32_t)buffer[39];
     FSC_CURRENT[5] = fsc;
     FSC_LAST[5] = start_fsc;
+    }
 }
 
 int INCREMENT_SD_LIB(uint8_t sid)
@@ -259,6 +264,7 @@
 {
     uint32_t block_number;
     int result = 10;
+    if(SD_STATUS == DEVICE_POWERED){
     if(sid==0x01)
     {
         //block_number=SD_SCP_FIRST+(fsc%(SD_SCP_LAST-SD_SCP_FIRST+1))-1;
@@ -319,6 +325,7 @@
         }
         return result;
     }
+    }
     return 1;
 }