Repository for CDMS code

Dependencies:   SimpleDMA mbed-rtos mbed eeprom

Fork of COM_MNG_TMTC_SIMPLE by Shreesha S

Files at this revision

API Documentation at this revision

Comitter:
ee12b079
Date:
Wed Jun 29 15:23:12 2016 +0000
Parent:
194:ab528911780d
Child:
196:c51bf4993f75
Commit message:
SDCard read code updated , to be tested;

Changed in this revision

Compression.h Show annotated file Show diff for this revision Revisions of this file
DefinitionsAndGlobals.h Show annotated file Show diff for this revision Revisions of this file
OBSRS.h Show annotated file Show diff for this revision Revisions of this file
cdms_sd.h Show annotated file Show diff for this revision Revisions of this file
--- a/Compression.h	Wed Jun 29 14:24:12 2016 +0000
+++ b/Compression.h	Wed Jun 29 15:23:12 2016 +0000
@@ -73,6 +73,15 @@
     sci_time = 0;
     gPC.puts("enter srp");
     
+    //Call FCTN_SD_MNGR for latest fsc
+    FCTN_SD_MNGR();
+    uint32_t FSC[6];
+    uint8_t sd_stat;
+    
+    for(int i =1; i<6;i++)
+    {
+        FSC[i] = FSC_CURRENT[i];
+    }
     for (int i = 0; i < 52 ; i++){
         scp_bin[i] = 0;
     }
@@ -284,8 +293,8 @@
                 if(id == 1){    //below thereshold
                     space = adjust(1,0,pointer,8);
                     space = adjust(4,3,pointer,space);
-                    //FSC_science = FCTN_SD_MNGR(3);
-                    gPC.printf("SID = 3, FSC = %02X\r\n", FSC_science);
+                    FSC[3]++;
+                    gPC.printf("SID = 3, FSC = %02X\r\n", FSC[3]);
                     frames[id][1] = (FSC_science>>24)&0xff;
                     frames[id][2] = (FSC_science>>16)&0xff;
                     frames[id][3] = (FSC_science>>8)&0xff;
@@ -299,8 +308,8 @@
                     space = adjust(1,0,pointer,8);
                     space = adjust(4,2,pointer,space);
                     //FSC_science = FCTN_SD_MNGR(2);
-                    
-                    gPC.printf("SID = 2, FSC = %02X\r\n", FSC_science);
+                    FSC[2]++;
+                    gPC.printf("SID = 2, FSC = %02X\r\n", FSC[2]);
                     frames[id][1] = (FSC_science>>16)&0xff;
                     frames[id][2] = (FSC_science>>8)&0xff;
                     frames[id][3] = FSC_science&0xff;
@@ -323,12 +332,16 @@
                 interleave(TM_convoluted_data+ 135,TM_interleave_data + 144);
                 
                 if(id == 1){
-                    SD_WRITE(TM_interleave_data,FSC_science,3);
+                    sd_stat = SD_WRITE(TM_interleave_data,FSC[3],3);
                    }
                 else if (id == 2){
-                    SD_WRITE(TM_interleave_data,FSC_science,2);
+                    sd_stat = SD_WRITE(TM_interleave_data,FSC[2],2);
                   }
-                FSC_science++;      //remove this after testing
+                if(sd_stat)
+                {
+                    gPC.puts("sd write failure");
+                    break;
+                    }
                 position_tm_frame[id] = position_tm_starting[id];
                 frames[id][6-id] = (length-1) - j;      // first head pointer.
                 
@@ -583,8 +596,8 @@
                 pointer = frames[id];
                 space = adjust(1,0,pointer,8);
                 space = adjust(4,1,pointer,space);
-                FSC_science = FCTN_SD_MNGR(1);
-                gPC.printf("SID = 1, FSC = %02X\r\n", FSC_science);
+                FSC[1]++;
+                gPC.printf("SID = 1, FSC = %02X\r\n", FSC[1]);
                 frames[id][1] = (FSC_science>>16)&0xff;
                 frames[id][2] = (FSC_science>>8)&0xff;
                 frames[id][3] = (FSC_science)&0xff;
@@ -603,7 +616,12 @@
                 convolution(frames[id]);
                 interleave(TM_convoluted_data,TM_interleave_data);
                 interleave(TM_convoluted_data+ 135,TM_interleave_data + 144);
-                SD_WRITE(TM_interleave_data,FSC_science,1);
+                sd_stat = SD_WRITE(TM_interleave_data,FSC[1],1);
+                if(sd_stat)
+                {
+                    gPC.puts("sd write failure");
+                    break;
+                }
                 position_tm_frame[id] = position_tm_starting[id];
                 frames[id][4] = (length-1) - j;
             }
--- a/DefinitionsAndGlobals.h	Wed Jun 29 14:24:12 2016 +0000
+++ b/DefinitionsAndGlobals.h	Wed Jun 29 15:23:12 2016 +0000
@@ -188,4 +188,5 @@
 
 //SD HK
 uint32_t FSC_CURRENT[6];
-uint32_t FSC_LAST[6];
\ No newline at end of file
+uint32_t FSC_LAST[6];
+uint8_t SD_SW_EN_DS;
\ No newline at end of file
--- a/OBSRS.h	Wed Jun 29 14:24:12 2016 +0000
+++ b/OBSRS.h	Wed Jun 29 15:23:12 2016 +0000
@@ -44,12 +44,12 @@
 uint8_t SID ;
 unsigned char buffer_112[112];
 uint32_t FSC;
-uint16_t read_success = false;
+uint8_t read_success = 0;
 uint16_t counter_buffer_112=0, counter_EoS=0,T_frames_sent=0;
 uint16_t counter_interleavedata=0;
 uint16_t counter_buffer_512=0;
 uint16_t max_segments  =  65415/(48+T_frames_in_segment*159);
-uint16_t ack_code = 0xA0;
+uint8_t ack_code = 0xA0;
 uint8_t segments_sent = 0;
 uint8_t counter_SCH40 = 0;
 uint8_t counter_FCCH80 = 0;
@@ -138,7 +138,7 @@
  enable_FCCH = false;\
  enable_DS = false;\
  half_buffer = 0;\
- read_success = false;\
+ read_success = 0;\
  counter_buffer_112=0;\
  counter_EoS=0;\
  T_frames_sent=0;\
@@ -580,7 +580,7 @@
 //                        }
                   int write_success = SD_WRITE(write_buffer,FSC + block_counter,SID);
 //                   wait_ms(8);
-                   read_success = SD_READ(buffer_512, FSC + block_counter,SID);
+                   ack_code = SD_READ(buffer_512, FSC + block_counter,SID);
                    for(int i = 0; i<512;i++)
                    if(write_buffer[i] != buffer_512[i])
                    gPC.printf("incorrect");
@@ -588,27 +588,29 @@
                    gPC.printf("read block %d \n\r",read_success);
              }
                else{
-                   read_success = SD_READ(buffer_512, list_of_FSC[block_counter],SID);
+                   ack_code = SD_READ(buffer_512, list_of_FSC[block_counter],SID);
                    }
                block_counter++;
                if(block_counter == no_of_frames){
                        last_block=true;
                }
                enable_read_block = false;
-               if(read_success == 0){
-//                   cout<<"read one block successfully"<<" ";
-                    ack_code = 0xA0;
+               if(ack_code == 0xA0){
+                   gPC.puts("read one block successfully");
                    enable_T_frame = true;
                    enable_SCH = true;
                 }
-                else if(read_success == 1){
-                    ack_code = 0x85;
+                else if(ack_code == 0x88 || ack_code == 0x89){
+
                     gPC.printf("Hardware failure");
                     enable_T_frame = false;
                 }
-                else if(read_success == 2){
-                    ack_code = 0x86;
-                    gPC.printf("Invalid FSC");
+                else if(ack_code == 0x02){
+                    gPC.printf("Invalid SID");
+                    enable_T_frame = false;
+                }
+                else if(ack_code == 0x86){
+                    gPC.printf("FSC outof bounds");
                     enable_T_frame = false;
                 }
                 else{
--- a/cdms_sd.h	Wed Jun 29 14:24:12 2016 +0000
+++ b/cdms_sd.h	Wed Jun 29 15:23:12 2016 +0000
@@ -57,7 +57,7 @@
 static uint32_t ext_bits(unsigned char *, int , int );
 int SD_WRITE(uint8_t*,uint32_t,uint8_t);
 int FCTN_CDMS_SD_INIT();
-int SD_READ(uint8_t*,uint32_t,uint8_t);
+uint8_t SD_READ(uint8_t*,uint32_t,uint8_t);
 #define SDCARD_FAIL 0
 #define SDCARD_V1   1
 #define SDCARD_V2   2
@@ -88,48 +88,37 @@
 
     
 
-uint32_t  FCTN_SD_MNGR(uint8_t sid)
+void FCTN_SD_MNGR(void)
 {
     uint32_t fsc;
     uint32_t start_fsc;
     uint8_t buffer[512];
     int b=disk_read(buffer, SD_MNG_SECT);
-    if(sid==0x01)
-    {
-        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];
-        FSC_CURRENT[1] = fsc;
-        FSC_LAST[1] = start_fsc;
-    }
-    if(sid==0x02)
-    {
-        fsc=(uint32_t)(buffer[8]<<24)+(uint32_t)(buffer[9]<<16)+(uint32_t)(buffer[10]<<8)+(uint32_t)buffer[11];
-        start_fsc=(uint32_t)(buffer[12]<<24)+(uint32_t)(buffer[13]<<16)+(uint32_t)(buffer[14]<<8)+(uint32_t)buffer[15];
-        FSC_CURRENT[2] = fsc;
-        FSC_LAST[2] = start_fsc;
-    }
-    if(sid==0x03)
-    {
-        fsc=(uint32_t)(buffer[16]<<24)+(uint32_t)(buffer[17]<<16)+(uint32_t)(buffer[18]<<8)+(uint32_t)buffer[19];
-        start_fsc=(uint32_t)(buffer[20]<<24)+(uint32_t)(buffer[21]<<16)+(uint32_t)(buffer[22]<<8)+(uint32_t)buffer[23];
-        FSC_CURRENT[3] = fsc;
-        FSC_LAST[3] = start_fsc;
-    }
-    if(sid==0x04)
-    {
-        fsc=(uint32_t)(buffer[24]<<24)+(uint32_t)(buffer[25]<<16)+(uint32_t)(buffer[26]<<8)+(uint32_t)buffer[27];
-        start_fsc=(uint32_t)(buffer[28]<<24)+(uint32_t)(buffer[29]<<16)+(uint32_t)(buffer[30]<<8)+(uint32_t)buffer[31];
-        FSC_CURRENT[4] = fsc;
-        FSC_LAST[4] = start_fsc;
-    }
-    if(sid==0x05)
-    {
-        fsc=(uint32_t)(buffer[32]<<24)+(uint32_t)(buffer[33]<<16)+(uint32_t)(buffer[34]<<8)+(uint32_t)buffer[35];
-        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;
-    }
-    return fsc;
+    
+    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];
+    FSC_CURRENT[1] = fsc;
+    FSC_LAST[1] = start_fsc;
+    
+    fsc=(uint32_t)(buffer[8]<<24)+(uint32_t)(buffer[9]<<16)+(uint32_t)(buffer[10]<<8)+(uint32_t)buffer[11];
+    start_fsc=(uint32_t)(buffer[12]<<24)+(uint32_t)(buffer[13]<<16)+(uint32_t)(buffer[14]<<8)+(uint32_t)buffer[15];
+    FSC_CURRENT[2] = fsc;
+    FSC_LAST[2] = start_fsc;
+
+    fsc=(uint32_t)(buffer[16]<<24)+(uint32_t)(buffer[17]<<16)+(uint32_t)(buffer[18]<<8)+(uint32_t)buffer[19];
+    start_fsc=(uint32_t)(buffer[20]<<24)+(uint32_t)(buffer[21]<<16)+(uint32_t)(buffer[22]<<8)+(uint32_t)buffer[23];
+    FSC_CURRENT[3] = fsc;
+    FSC_LAST[3] = start_fsc;
+    
+    fsc=(uint32_t)(buffer[24]<<24)+(uint32_t)(buffer[25]<<16)+(uint32_t)(buffer[26]<<8)+(uint32_t)buffer[27];
+    start_fsc=(uint32_t)(buffer[28]<<24)+(uint32_t)(buffer[29]<<16)+(uint32_t)(buffer[30]<<8)+(uint32_t)buffer[31];
+    FSC_CURRENT[4] = fsc;
+    FSC_LAST[4] = start_fsc;
+        
+    fsc=(uint32_t)(buffer[32]<<24)+(uint32_t)(buffer[33]<<16)+(uint32_t)(buffer[34]<<8)+(uint32_t)buffer[35];
+    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)
@@ -284,40 +273,61 @@
     return 1;
 }
 
-int SD_READ(uint8_t* buffer,uint32_t fsc,uint8_t sid)
+uint8_t SD_READ(uint8_t* buffer,uint32_t fsc,uint8_t sid)
 {
+    FCTN_SD_MNGR();
+    if(SD_SW_EN_DS == 1)
+        return 0x89;
     uint32_t block_number;
     int result;
     if(sid==0x01)
     {
+        if(!(FSC_LAST[1]<=fsc && fsc<=FSC_CURRENT[1])){
+            return 0x86;
+        }
         block_number=SD_SCP_FIRST + fsc;
         result= disk_read(buffer,block_number);
     }
    else if(sid==0x02)
     {
+        if(!(FSC_LAST[2]<=fsc && fsc<=FSC_CURRENT[2])){
+            return 0x86;
+        }
         block_number=SD_SFF_AT_FIRST + fsc;
         result= disk_read(buffer,block_number);
     }
     else if(sid==0x03)
     {
+        if(!(FSC_LAST[3]<=fsc && fsc<=FSC_CURRENT[3])){
+            return 0x86;
+        }
         block_number=SD_SFF_BT_FIRST + fsc;
         result= disk_read(buffer,block_number);
     }
     else if(sid==0x04)
     {
+        if(!(FSC_LAST[4]<=fsc && fsc<=FSC_CURRENT[4])){
+            return 0x86;
+        }
         block_number=SD_HK_ARCH_FIRST + fsc;
         result= disk_read(buffer,block_number);
     }
     else if(sid==0x05)
     {
+        if(!(FSC_LAST[5]<=fsc && fsc<=FSC_CURRENT[5])){
+            return 0x86;
+        }
         block_number=LOG_FIRST +fsc;
         result= disk_read(buffer,block_number);
     }
     else
     {
-        return 1;
+        return 0x02;
     }
-    return result;
+    if(result == 0)
+        return 0xA0;
+    else
+        return 0x88;
 }
 
 
@@ -576,11 +586,6 @@
     return bits;
 }
 
-int disk_initialize()
-{
-
-}
-
 int disk_write(const uint8_t *buffer, uint64_t block_number)
 
 {