pl ack in tmtc

Dependencies:   FreescaleIAP SimpleDMA mbed-rtos mbed

Fork of COM_MNG_TMTC_SIMPLE_pl123 by shubham c

Revision:
92:bce22b38c440
Parent:
86:a26f5f22631d
Child:
96:4ca92f9775e0
diff -r 05cf9d71a665 -r bce22b38c440 cdms_sd.h
--- a/cdms_sd.h	Sat Jan 23 12:20:56 2016 +0000
+++ b/cdms_sd.h	Sat Jan 23 12:59:06 2016 +0000
@@ -38,7 +38,7 @@
 //void FCTN_CDMS_INIT_SD();
 //int FCTN_CDMS_WR_SD(const uint8_t *, uint64_t);
 //int FCTN_CDMS_RD_SD(uint8_t *, uint64_t);
-uint8_t FCTN_SD_MNGR(uint8_t);
+uint32_t FCTN_SD_MNGR(uint8_t);
 
 
 int cmd(int, int);
@@ -48,9 +48,9 @@
 int read(uint8_t*, uint32_t );
 int write(const uint8_t*, uint32_t );
 static uint32_t ext_bits(unsigned char *, int , int );
-int SD_WRITE(uint8_t*,uint8_t,uint8_t);
+int SD_WRITE(uint8_t*,uint32_t,uint8_t);
 void FCTN_CDMS_SD_INIT();
-int SD_READ(uint8_t*,uint8_t,uint8_t);
+int SD_READ(uint8_t*,uint32_t,uint8_t);
 #define SDCARD_FAIL 0
 #define SDCARD_V1   1
 #define SDCARD_V2   2
@@ -81,54 +81,68 @@
 
     
 
-uint8_t  FCTN_SD_MNGR(uint8_t sid)
+uint32_t  FCTN_SD_MNGR(uint8_t sid)
 
 {
-    
+   
     uint32_t SD_MNG_SECT=7000;
-    uint32_t block_number;
-    uint8_t fsc;
-    uint8_t *buffer;
-    uint32_t i=0;
-    disk_read(buffer, SD_MNG_SECT);
-   
+    
+    uint32_t fsc;
+    uint8_t buffer[512];
+    int b=disk_read(buffer, SD_MNG_SECT);
     if(sid==0x0)
     {
-        fsc=buffer[0];
-        buffer[0]++;
+        
+        fsc=(uint32_t)(buffer[0]<<24)+(uint32_t)(buffer[1]<<16)+(uint32_t)(buffer[2]<<8)+(uint32_t)buffer[3];
+        uint32_t next_fsc=fsc+1;
+        buffer[0]=(uint8_t) (next_fsc>>24 & 0xFF);
+        buffer[1]=(uint8_t) (next_fsc>>16 & 0xFF);
+        buffer[2]=(uint8_t) (next_fsc>>8 & 0xFF);
+        buffer[3]=(uint8_t) (next_fsc & 0xFF);
         buffer[511]+=2;
         disk_write(buffer,SD_MNG_SECT);
     }
     if(sid==0x1)
     {
-        fsc=buffer[1];
-        buffer[1]++;
+        fsc=(uint32_t)(buffer[4]<<24)+(uint32_t)(buffer[5]<<16)+(uint32_t)(buffer[6]<<8)+(uint32_t)buffer[7];
+        uint32_t next_fsc=fsc+1;
+        buffer[4]=(uint8_t) (next_fsc>>24 & 0xFF);
+        buffer[5]=(uint8_t) (next_fsc>>16 & 0xFF);
+        buffer[6]=(uint8_t) (next_fsc>>8 & 0xFF);
+        buffer[7]=(uint8_t) (next_fsc & 0xFF);
         buffer[511]+=2;
         disk_write(buffer,SD_MNG_SECT);
     }
     if(sid==0x2)
     {
-        fsc=buffer[2];
-        buffer[2]++;
+        fsc=(uint32_t)(buffer[8]<<24)+(uint32_t)(buffer[9]<<16)+(uint32_t)(buffer[10]<<8)+(uint32_t)buffer[11];
+        uint32_t next_fsc=fsc+1;
+        buffer[8]=(uint8_t) (next_fsc>>24 & 0xFF);
+        buffer[9]=(uint8_t) (next_fsc>>16 & 0xFF);
+        buffer[10]=(uint8_t) (next_fsc>>8 & 0xFF);
+        buffer[11]=(uint8_t) (next_fsc & 0xFF);
         buffer[511]+=2;
         disk_write(buffer,SD_MNG_SECT);
     }
      if(sid==0x3)
     {
-        fsc=buffer[30];
-        printf("Hey buffer[300] pre-increment is %d\r\n",buffer[300]);
-        buffer[300]+=1;
-        printf("Hey buffer[300] post-increment is %d\r\n",buffer[300]);
+        fsc=(uint32_t)(buffer[12]<<24)+(uint32_t)(buffer[13]<<16)+(uint32_t)(buffer[14]<<8)+(uint32_t)buffer[15];
+        uint32_t next_fsc=fsc+1;
+        buffer[12]=(uint8_t) (next_fsc>>24 & 0xFF);
+        buffer[13]=(uint8_t) (next_fsc>>16 & 0xFF);
+        buffer[14]=(uint8_t) (next_fsc>>8 & 0xFF);
+        buffer[15]=(uint8_t) (next_fsc & 0xFF);
         buffer[511]+=2;
         disk_write(buffer,SD_MNG_SECT);
-        disk_read(buffer, SD_MNG_SECT);
-        printf("Hey buffer[300] post writing is %d\r\n",buffer[300]);
-         printf("Hey buffer[511] post writing is %d\r\n",buffer[511]);
     }
      if(sid==0x4)
     {
-        fsc=buffer[4];
-        buffer[4]++;
+        fsc=(uint32_t)(buffer[16]<<24)+(uint32_t)(buffer[17]<<16)+(uint32_t)(buffer[18]<<8)+(uint32_t)buffer[19];
+        uint32_t next_fsc=fsc+1;
+        buffer[16]=(uint8_t) (next_fsc>>24 & 0xFF);
+        buffer[17]=(uint8_t) (next_fsc>>16 & 0xFF);
+        buffer[18]=(uint8_t) (next_fsc>>8 & 0xFF);
+        buffer[19]=(uint8_t) (next_fsc & 0xFF);
         buffer[511]+=2;
         disk_write(buffer,SD_MNG_SECT);
     }
@@ -136,7 +150,7 @@
 }
 
 
-int SD_WRITE(uint8_t* buffer,uint8_t fsc,uint8_t sid)
+int SD_WRITE(uint8_t* buffer,uint32_t fsc,uint8_t sid)
 {
    
     uint32_t SD_SCP_FIRST=1001;
@@ -154,7 +168,7 @@
     int result;
     if(sid==0x0)
     {
-        block_number=SD_SCP_FIRST+uint32_t(fsc);
+        block_number=SD_SCP_FIRST+fsc;
 //        printf("write_block_number=%d\r\n",block_number);
         result= disk_write(buffer,block_number);
         return result;
@@ -187,7 +201,7 @@
     return 1;
 }
 
-int SD_READ(uint8_t* buffer,uint8_t fsc,uint8_t sid)
+int SD_READ(uint8_t* buffer,uint32_t fsc,uint8_t sid)
 {
    
     uint32_t SD_SCP_FIRST=1001;
@@ -205,7 +219,7 @@
     int result;
     if(sid==0x0)
     {
-        block_number=SD_SCP_FIRST + uint32_t(fsc);
+        block_number=SD_SCP_FIRST + fsc;
 //        sd1.printf("read_block_number=%d\r\n",block_number);
         result= disk_read(buffer,block_number);
     }
@@ -595,4 +609,4 @@
     }
     
     return 0; //normal return
-}
+}
\ No newline at end of file