CDMS_CODE_samp_23SEP_DMA_flag

Dependencies:   FreescaleIAP SimpleDMA mbed-rtos mbed

Fork of CDMS_CODE_samp_23SEP_DMA by iitm sat

Files at this revision

API Documentation at this revision

Comitter:
chaithanyarss
Date:
Sun Aug 07 10:36:59 2016 +0000
Parent:
289:9bd62b69874c
Child:
291:912da006918b
Child:
292:61aa2169ea1c
Commit message:
testing in indo mim. DMA not working;

Changed in this revision

CDMS_HK.h Show annotated file Show diff for this revision Revisions of this file
COM_MNG_TMTC.h Show annotated file Show diff for this revision Revisions of this file
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
TEST_PL.h Show annotated file Show diff for this revision Revisions of this file
ThreadsAndFunctions.h Show annotated file Show diff for this revision Revisions of this file
i2c.h Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/CDMS_HK.h	Sat Aug 06 06:34:38 2016 +0000
+++ b/CDMS_HK.h	Sun Aug 07 10:36:59 2016 +0000
@@ -135,7 +135,7 @@
     if(sd_stat)
     {
         gPC.puts("sd write failure");
-        break;
+       // break;
         }
     gPC.printf("Completed CDMS HK\t");
 
@@ -172,7 +172,7 @@
             if(sd_stat)
     {
         gPC.puts("sd write failure");
-        break;
+        //break;
         }
         }
         
@@ -197,7 +197,7 @@
     beacon_array[7] = SD_FAULTCOUNT;
     beacon_array[8] = RTC_FAULTCOUNT >> 8;
     beacon_array[9] = RTC_FAULTCOUNT;
-    beacon_array[10] = (((SD_STATUS == DEVICE_DISABLED || SD_STATUS == DEVICE_OC_FAULT)?1:0)<<7)|(RTC_STATUS <<6)|(COM_RX_STATUS<<3)|(V_C_PGOOD<<2)|(COMRX_OC_FAULT<<1)|(COMTX_OC_FAULT);
+    beacon_array[10] = (((SD_STATUS == DEVICE_DISABLED || SD_STATUS == DEVICE_OC_FAULT)?1:0)<<7)|(RTC_STATUS <<6)|(COM_RX_STATUS<<3)|(V_C_PGOOD<<2)|(COMRX_OC_FAULT<<1)|(COM_TX_OC_FAULT);
     beacon_array[11] = (COM_RX_CNTRL <<7)|(COM_TX_CNTRL);
     beacon_array[12] = CDMS_HK_MAIN_COUNTER >>8;
     beacon_array[13] = CDMS_HK_MAIN_COUNTER;
@@ -335,7 +335,7 @@
     //COMRX_OC_FAULT //$
     GPIO_STATUS=(COMRX_OC_FAULT)?(GPIO_STATUS)||((uint16_t)(0x1<<11)):(GPIO_STATUS)&(~((uint16_t)(0x1<<11)));
     // COMTX_OC_FAULT //$
-    GPIO_STATUS=(COMTX_OC_FAULT)?(GPIO_STATUS)||((uint16_t)(0x1<<10)):(GPIO_STATUS)&(~((uint16_t)(0x1<<10)));
+    GPIO_STATUS=(COM_TX_OC_FAULT)?(GPIO_STATUS)||((uint16_t)(0x1<<10)):(GPIO_STATUS)&(~((uint16_t)(0x1<<10)));
     //BAE_OC_FAULT //$
     GPIO_STATUS=(BAE_OC_FAULT)?(GPIO_STATUS)||((uint16_t)(0x1<<9)):(GPIO_STATUS)&(~((uint16_t)(0x1<<9)));
     //PL_GPIO_1_STATUS //$
@@ -361,7 +361,7 @@
     if(COMRX_OC_FAULT==0 && RSSI_volatge > 0.4) {
         COMRX_STATUS = COMRX_ALIVE;
     } else {
-        RESET_COMRX();
+        //RESET_COMRX();
         COMRX_RESET_COUNTER++;
         if(COMRX_OC_FAULT==0 && RSSI_volatge > 0.4)
             COMRX_STATUS = COMRX_ALIVE;
@@ -381,7 +381,7 @@
         response = spi.write(0x00);
         CDMS_RTC_BL = (response & 0x10) >>4;
         if(response & 0x04 == 0x04) {
-            RESET_RTC();
+            //RESET_RTC();
             RTC_STATUS = 0x01;
             RTC_FAULTCOUNT++;
         }
@@ -498,7 +498,7 @@
 
 void COLLECT_CDMS_RAM()
 {
-    CDMS_RAM[0] = ((PL_INIT_STATUS<<7)&0x80)|((PL_MAIN_STATUS<<6)&0x40)|((PL_LOW_POWER<<5)&0x20)|((PL_STATE<<3)&0x18)|(PL_STATUS&0x07);
+    CDMS_RAM[0] = ((PL_INIT_STATUS<<7)&0x80)|((PL_MAIN_status<<6)&0x40)|((PL_LOW_POWER<<5)&0x20)|((PL_STATE<<3)&0x18)|(PL_STATUS&0x07);
     CDMS_RAM[1] = ((PL_RCV_SC_DATA_STATUS<<7)&0x80)|((COM_SESSION<<6)&0x40)|((COM_RX<<5)&0x20)|((RF_SW_STATUS<<4)&0x10)|((COM_TX<<3)&0x08)|((COM_TX_STATUS<<2)&0x04)|((COM_MNG_TMTC<<1)&0x02)|(EN_CDMS_HK&0x01);
     CDMS_RAM[2] = ((EN_PL<<7)&0x80)|((EN_RCV_SC<<6)&0x40)|((CDMS_INIT_STATUS<<5)&0x20)|((CDMS_HK_MAIN_STATUS<<4)&0x10)|((CDMS_HK_STATUS<<2)&0x0C)|((COM_RX_STATUS<<1)&0x02)|(CDMS_RTC_BL&0x01);
     CDMS_RAM[3] = CDMS_I2C_ERR_SPEED_COUNTER >> 8;
--- a/COM_MNG_TMTC.h	Sat Aug 06 06:34:38 2016 +0000
+++ b/COM_MNG_TMTC.h	Sun Aug 07 10:36:59 2016 +0000
@@ -371,9 +371,9 @@
                 gPC.printf("Write success\r\n");
                 //wait(0.2);
                 int poll=0;
-                while(poll<20000 && BAE_I2C_GPIO==0)
+                while(poll<3000 && BAE_I2C_GPIO==0)
                 {
-                    wait_us(10);
+                    wait_ms(1);
                     poll+=1;
                 }
                 if(BAE_I2C_GPIO == 1)
@@ -1124,9 +1124,12 @@
                 }    
             if(PL_I2C_Intr == 1)
                 {
-                    gPC.printf("PL_I2C_Intr is high\r\n");
+                    gPC.printf("\n\rPL_I2C_Intr is high");
                     Base_tm *tm_ptr = new Long_tm;
                     y=FCTN_I2C_READ_PL((char*)tm_ptr->TM_string,TM_LONG_SIZE);
+                    gPC.printf("\n\r");
+                    for(int i = 0;i<134;i++)
+                    gPC.printf("%X",(int)(tm_ptr->TM_string[i]));
                     if(y==0)
                     {
                         tm_ptr->next_TM=NULL;
@@ -1134,16 +1137,17 @@
                     }
                     else if(y==1)
                     {
+                        gPC.printf("\n\rPL_TM read failure");
                         delete tm_ptr;
                         Base_tm *tm_ptr_short = new Short_tm;
-                        ACK_L234(tm_ptr_short,0x85,GETpacket_seq_count(tc_ptr));                
-                        //gPC.printf("\n\rPTE->PDIR = 0x%08X",PTE->PDIR);
+                        ACK_L234(tm_ptr_short,0x85,GETpacket_seq_count(tc_ptr));              
+                        gPC.printf("\n\r0x85");
                         return tm_ptr_short;
                     }
                 }
                 else if(PL_I2C_Intr == 0)                                       //name to be changed later
                 {
-                    gPC.printf("PL_I2C_Intr is not high\r\n");                    
+                    gPC.printf("\n\rPL_I2C_Intr is not high");                    
                     Base_tm *tm_ptr_short = new Short_tm;
                     ACK_L234(tm_ptr_short,0x84,GETpacket_seq_count(tc_ptr));
                     return tm_ptr_short;
@@ -1152,7 +1156,7 @@
         }
         default:    //invalid TC
         {
-            gPC.printf("INVALID TC\r\n");
+            gPC.printf("\n\rINVALID TC");
             Base_tm *tm_ptr_short = new Short_tm;
             ACK_L234(tm_ptr_short,0x02,GETpacket_seq_count(tc_ptr));
             return tm_ptr_short;
--- a/Compression.h	Sat Aug 06 06:34:38 2016 +0000
+++ b/Compression.h	Sun Aug 07 10:36:59 2016 +0000
@@ -16,9 +16,30 @@
 //reading functions 2byte, 4byte
 #define srpz 0
 #define scpz 0
-#define scp_last 0
-#define srp_last 0
+#define scpz_last 0
+#define srpz_last 0
+#define debug_fsc 0
+#define debug_time 0
+#define debug_dma 0
 
+#if debug_dma
+uint16_t read_2byte(uint8_t* ptr)
+{
+    uint16_t output = (((uint16_t )(*(ptr+1)))<<8);
+    output += (((uint16_t)(*ptr)));
+    return output;
+}
+
+uint32_t read_4byte(uint8_t* ptr)
+{
+    uint32_t output = (uint32_t)(*(ptr+3))<<24;
+    output += (uint32_t)(*(ptr+2)<<16);
+    output += (uint32_t)(*(ptr+1)<<8);
+    output += (uint32_t)(*(ptr));
+    return output;
+}
+#endif
+#if !debug_dma
 uint16_t read_2byte(uint8_t* ptr)
 {
     uint16_t output = (uint8_t ) *(ptr+1);
@@ -34,7 +55,7 @@
     output += (uint32_t)(*(ptr)<<24);
     return output;
 }
-
+#endif
 uint8_t adjust(uint8_t size, uint8_t data, uint8_t* ptr , uint8_t space)
 {
     space = space&0x0f;
@@ -96,6 +117,11 @@
 uint32_t attitude = 0;
 uint32_t beacon_threshold[9] = {114688,245760,245760,245760,245760,114688,114688,65472,65472};
 
+/*----------------------------temporary counters used for testing purposes---------------------------*/
+uint32_t test_fsc[4]={1,1,1,1};
+/*---------------------------------------------------------------------------------------------------*/
+
+
 Convolution ConvObj;
 void convolution (uint8_t * ptr){
     ConvObj.convolutionEncode(ptr, TM_convoluted_data);
@@ -106,9 +132,12 @@
 void srp(uint8_t * head)
 {
     uint8_t sd_stat = 0;
-    gPC.printf("\n\rEntered srp function");
+    gPC.printf("\n\rEntered SRP function");
     debug_cntr = 0;
     sci_time = FCTN_CDMS_RD_RTC();
+    #if debug_time
+    sci_time = 0x0000000021000000;
+    #endif
     if(time_prev_scp==0){
         time_prev_scp = sci_time;
     }    
@@ -122,14 +151,14 @@
     for(uint8_t counter = 0 ; counter < 60 ; counter++)
     {       
         #if srpz
-        //gPC.printf("\n\n\rSRP count:%d",counter+1);
+        gPC.printf("\n\n\rSRP count:%d",counter+1);
         #endif
         /*-------------------- ------------populating sfp_bin and scp_bin[] starts here(also tag AT or BT)-----------------------*/
         at = 0;     pzf = 1;    ezf = 1;
         if(srp_mode == 0)                                   //calibrated mode 
         {
             #if srpz
-            //gPC.printf("\n\rSRP - Calibrated Mode");
+            gPC.printf("\n\rSRP - Calibrated Mode");
             #endif
             for(int i=0; i<48 ; i++)                        //first 48 bins or SRP are of 16 bits size
             {
@@ -164,7 +193,7 @@
         else if(srp_mode == 1)                              //scattered mode
         {
             #if srpz
-            //gPC.printf("\n\rSRP - Scatter Plot Mode");
+            gPC.printf("\n\rSRP - Scatter Plot Mode");
             #endif
             for(int i = 0; i <48; i++)                      //first 48 bins of SRP are of 16 bit size
             {
@@ -178,7 +207,6 @@
             }
             for(int i = 0; i < 4 ; i++)                     //next 4 bins are of 32 bit size
             {
-                ///sfp_bin[i+48] = read_4byte( (ptr+64) + 4*i );
                 sfp_bin[i+48] = read_4byte( (ptr+96) + 4*i );
                 scp_bin[i+48] += sfp_bin[i+48];
                 if(sfp_bin[i+48] > sfp_threshold_m1[i+48]){
@@ -201,7 +229,7 @@
             if(at == 0)
             {
                 #if srpz
-                //gPC.printf("\n\rSFP Below Threshold");
+                gPC.printf("\n\rSFP Below Threshold");
                 #endif
                 pointer = sfp; debug_cntr = 0;
                 space = adjust(4, attitude,pointer,8);      pointer += space>>4;    debug_cntr += space>>4;
@@ -241,7 +269,7 @@
             }                                                                                           //below thershold ends here.
             if(at == 1){
                 #if srpz
-                //gPC.printf("\n\rSFP Above Threshold");
+                gPC.printf("\n\rSFP Above Threshold");
                 #endif
                 pointer = sfp + 6; debug_cntr = 6;space = 8;
                 sfp[0] = (sci_time>>27)&0xff;   sfp[1] = (sci_time>>19)&0xff;   sfp[2] = (sci_time>>11)&0xff;   sfp[3] = (sci_time>>3)&0xff;
@@ -271,7 +299,7 @@
                 if(pzf == 0){
                     //cout<<"proton bins ";
                     #if srpz
-                    //gPC.printf("\n\rProton bins present in SRP");
+                    gPC.printf("\n\rProton bins present in SRP");
                     #endif
                     for(uint8_t i = 0; i<17 ; i++){
                         space = adjust(2, ((compress(sfp_bin[i],8,2))>>8) ,pointer,space);      pointer += space>>4;    debug_cntr += space>>4;
@@ -282,7 +310,7 @@
                 if(ezf == 0){
                     //cout<<"electron bins ";
                     #if srpz
-                    //gPC.printf("\n\rElectron bins present in SRP");
+                    gPC.printf("\n\rElectron bins present in SRP");
                     #endif
                     for(int i = 0; i<5 ; i++){
                         space = adjust(2,((compress(sfp_bin[18+i],8,2))>>8),pointer,space);     pointer += space>>4;    debug_cntr += space>>4;
@@ -313,7 +341,7 @@
             if(at == 0)
             {
                 #if srpz
-                //gPC.printf("\n\rSFP below threshold");
+                gPC.printf("\n\rSFP below threshold");
                 #endif
                 pointer = sfp; debug_cntr = 0;  space = 8;
                 space = adjust(4, attitude,pointer,8);      pointer += space>>4;    debug_cntr += space>>4;
@@ -333,7 +361,7 @@
             {
                 
                 #if srpz                
-                //gPC.printf("\n\rSFP below threshold");
+                gPC.printf("\n\rSFP below threshold");
                 #endif
                 pointer = sfp; debug_cntr = 0;  space = 8;
                 space = adjust(3, sci_time>>32 ,pointer,space); pointer += space>>4;    debug_cntr += space>>4;
@@ -366,7 +394,7 @@
         }
         length = (length%8==0)?(length/8):(length/8)+1;                         //converting length to mulitple of 8
         #if srpz
-        //gPC.printf("\n\rLength of SFP packet in bytes = %d",length);
+        gPC.printf("\n\rLength of SFP packet in bytes = %d",length);
         #endif
         /*----------------------------------------forming a science packet ends here-----------------------------------------------*/
 
@@ -374,7 +402,7 @@
         if(id==1){
             if(position_tm_frame[id]>130){
                 #if srpz
-                //gPC.printf("\n\rSkipping the current frame.Inserting sfp packet into the next frame.");
+                gPC.printf("\n\rSkipping the current frame.Inserting sfp packet into the next frame.");
                 #endif
                 while(position_tm_frame[id]<132){
                     frames[id][position_tm_frame[id]] = 0;
@@ -385,7 +413,7 @@
         else if(id==2){
             if(position_tm_frame[id]>126){
                 #if srpz
-                //gPC.printf("\n\rSkipping the current frame.Inserting sfp packet into the next frame.");
+                gPC.printf("\n\rSkipping the current frame.Inserting sfp packet into the next frame.");
                 #endif
                 while(position_tm_frame[id]<132){
                     frames[id][position_tm_frame[id]] = 0;
@@ -401,7 +429,7 @@
             if(position_tm_frame[id]==frames[id][6-id]){
                 if(id==1){
                     #if srpz
-                    //gPC.printf("\n\rAdding Time to TM frame");
+                    gPC.printf("\n\rAdding Time to TM frame");
                     #endif
                     frames[id][6]  = (uint8_t)((sci_time>>32)&0x07);
                     frames[id][7]  = (uint8_t)((sci_time>>24)&0xff);
@@ -419,30 +447,48 @@
             {
                 /*-----------the current frame is completely filled and we fill frame header to write into SD card---------*/
                 #if srpz
-                //gPC.printf("\n\rSFP_TM frame full. Length of current packet = %d",j);
-                //gPC.printf("\n\rFrame Header: %d",frames[id][6-id]);
-                //gPC.printf("\n\rFirst head pointer contents: 0x%02X",frames[id][frames[id][6-id]]);
+                gPC.printf("\n\rSFP_TM frame full. Length of current packet = %d",j);
+                gPC.printf("\n\rFirst Header pointer: %d",frames[id][6-id]);
+                gPC.printf("\n\rFirst head pointer contents: 0x%02X",frames[id][frames[id][6-id]]);
                 #endif
                 pointer = frames[id];
                 if(id == 1){    //below threshold
                     space = adjust(1,0,pointer,8);
                     space = adjust(4,3,pointer,space);
                     FSC_science = FSC_CURRENT[3];                               ///to be used as this, but FSC_CURRENT[] is 32 bit 
-                    gPC.printf("3 = 0x%X",FSC_science);                   
+
+                    //gPC.printf("3 = 0x%X",FSC_science);                   
+                    #if debug_fsc
+                    frames[id][1] = (test_fsc[3]>>24)&0xff;
+                    frames[id][2] = (test_fsc[3]>>16)&0xff;
+                    frames[id][3] = (test_fsc[3]>>8)&0xff;
+                    frames[id][4] = test_fsc[3]&0xff;                    
+                    test_fsc[3]++;
+                    #endif                    
+                    #if !debug_fsc
                     frames[id][1] = (FSC_science>>24)&0xff;
                     frames[id][2] = (FSC_science>>16)&0xff;
                     frames[id][3] = (FSC_science>>8)&0xff;
                     frames[id][4] = FSC_science&0xff;                    
+                    #endif
                 }
                 else if(id == 2)    //above threshold
                 {
                     space = adjust(1,0,pointer,8);
                     space = adjust(4,2,pointer,space);                    
                     FSC_science = FSC_CURRENT[2];                                               ///to be used as this
-                    gPC.printf("2 = 0x%X",FSC_science);
+                    //gPC.printf("2 = 0x%X",FSC_science);
+                    #if debug_fsc
+                    frames[id][1] = (test_fsc[2]>>16)&0xff;
+                    frames[id][2] = (test_fsc[2]>>8)&0xff;
+                    frames[id][3] = test_fsc[2]&0xff;
+                    test_fsc[2]++;
+                    #endif
+                    #if !debug_fsc
                     frames[id][1] = (FSC_science>>16)&0xff;
                     frames[id][2] = (FSC_science>>8)&0xff;
                     frames[id][3] = FSC_science&0xff;
+                    #endif
                 }
                 temp_crc = crc16_gen(frames[id],132);
                 frames[id][132] = temp_crc>>8;
@@ -450,8 +496,9 @@
                 
                 #if srpz
                 gPC.printf("\n\rPrinting SFP_TM\n\r{");                
+                //gPC.printf("\n\r{");
                 for(uint8_t z=0;z<134;z++){
-                    gPC.printf("0x%02X,",frames[id][z]);
+                    gPC.printf("%02X",frames[id][z]);
                 }
                 gPC.printf("}\n\r");
                 #endif
@@ -472,7 +519,7 @@
                 if(sd_stat)
                 {
                     gPC.puts("sd write fail");
-                    }
+                }
                 position_tm_frame[id] = position_tm_starting[id];
                 frames[id][6-id] = (length - j)+position_tm_starting[id];
             }
@@ -493,29 +540,48 @@
             space = adjust(1,0,pointer,8);
             space = adjust(4,3,pointer,space);
             FSC_science = FSC_CURRENT[3];                               ///to be used as this, but FSC_CURRENT[] is 32 bit                    
+            #if debug_fsc
+            frames[id][1] = (FSC_science>>24)&0xff;
+            frames[id][2] = (FSC_science>>16)&0xff;
+            frames[id][3] = (FSC_science>>8)&0xff;
+            frames[id][4] = FSC_science&0xff;
+            test_fsc[3]++;
+            #endif
+            #if !debug_fsc
             frames[id][1] = (FSC_science>>24)&0xff;
             frames[id][2] = (FSC_science>>16)&0xff;
             frames[id][3] = (FSC_science>>8)&0xff;
             frames[id][4] = FSC_science&0xff;                    
+            #endif
         }
         else if(id == 2)    //above threshold
         {
             space = adjust(1,0,pointer,8);
             space = adjust(4,2,pointer,space);                    
             FSC_science = FSC_CURRENT[2];                                               ///to be used as this
+            #if debug_fsc
+            frames[id][1] = (test_fsc[2]>>16)&0xff;
+            frames[id][2] = (test_fsc[2]>>8)&0xff;
+            frames[id][3] = test_fsc[2]&0xff;
+            test_fsc[2]++;
+            #endif
+            #if !debug_fsc
             frames[id][1] = (FSC_science>>16)&0xff;
             frames[id][2] = (FSC_science>>8)&0xff;
             frames[id][3] = FSC_science&0xff;
+            #endif
         }
         temp_crc = crc16_gen(frames[id],132);
         frames[id][132] = temp_crc>>8;
         frames[id][133] = temp_crc & 0xff;        
         
-        gPC.printf("\n\rPrinting SFP_TM\n\r{");
+        //gPC.printf("\n\rPrinting SFP_TM\n\r{");
+        gPC.printf("\n\r{");
         for(uint8_t z=0;z<134;z++){
-            gPC.printf("0x%02X,",frames[id][z]);
+            gPC.printf("%02X",frames[id][z]);
         }
         gPC.printf("}\n\r");
+        position_tm_frame[id] = position_tm_starting[id];
     }
     #endif
     at = 0;     pzf = 1;    ezf = 1;
@@ -774,7 +840,7 @@
     beacon_cntr++;
     /*--------------------------------------------------beacon packet ends here--------------------------------------------------------*/
 
-    //gPC.printf("\n\rSCP count: %d");
+    //gPC.printf("\n\n\rSCP");
     uint8_t packet_pp,time_diff;
     /*------------------------------------------Forming a science packet(scp) starts here----------------------------------------------*/
 
@@ -809,13 +875,13 @@
     }
     if(srp_mode == 0 && compression_option == 0){       //normal callibrated mode
         #if scpz
-        //gPC.printf("\n\rSCP - Normal calibrated mode");
+        gPC.printf("\n\rSCP - Normal calibrated mode");
         #endif
         space = adjust(1, pzf,pointer,space);                       pointer += space>>4;    debug_cntr += space>>4;
         space = adjust(1, ezf,pointer,space);                       pointer += space>>4;    debug_cntr += space>>4;
         if(at == 0 ){
             #if scpz
-            //gPC.printf("\n\rBelow threshold");
+            gPC.printf("\n\rBelow threshold");
             #endif
             for(int i = 0; i<8 ;i++){
                 space = adjust(7,compress(scp_bin[24+i],4,3) ,pointer,space);       pointer += space>>4;    debug_cntr += space>>4;
@@ -849,7 +915,7 @@
         }// below threshold ends here
         if(at == 1){
             #if scpz
-            //gPC.printf("\n\rAbove threshold");
+            gPC.printf("\n\rAbove threshold");
             #endif
             for(int i = 0; i<8 ;i++){
                 space = adjust(7,compress(scp_bin[24+i],4,3) ,pointer,space);       pointer += space>>4;    debug_cntr += space>>4;
@@ -884,11 +950,11 @@
     }   //srp_mode == 0 ends
     if(srp_mode == 1){
         #if scpz
-        //gPC.printf("\n\rSCP - Scatter plot mode");
+        gPC.printf("\n\rSCP - Scatter plot mode");
         #endif
         if(at == 0){
             #if scpz
-            //gPC.printf("\n\rBelow Threshold");
+            gPC.printf("\n\rBelow Threshold");
             #endif
             for(int i=0; i<48; i++){
                 space = adjust(6, ((compress(scp_bin[i],3,3))&0xff) ,pointer,space);    pointer += space>>4;    debug_cntr += space>>4;
@@ -899,7 +965,7 @@
         }
         if(at == 1){
             #if scpz
-            //gPC.printf("\n\rAbove threshold");
+            gPC.printf("\n\rAbove threshold");
             #endif
             for(int i=0; i<48; i++){
                 space = adjust(7, (compress((scp_bin[i]/2),4,3))>>8 ,pointer,space);    pointer += space>>4;    debug_cntr += space>>4;
@@ -912,13 +978,13 @@
     }// scp mode 1 end
     if( srp_mode == 0 && compression_option == 1 ){ //scp data conservation mode
         #if scpz
-        //gPC.printf("\n\rSCP - Calibrated data conservation mode");
+        gPC.printf("\n\rSCP - Calibrated data conservation mode");
         #endif
         space = adjust(1, pzf,pointer,space);       pointer += space>>4;    debug_cntr += space>>4;
         space = adjust(1, ezf,pointer,space);       pointer += space>>4;    debug_cntr += space>>4;
         if(at == 0){
             #if scpz
-            //gPC.printf("\n\rBelow threshold");
+            gPC.printf("\n\rBelow threshold");
             #endif
             space = adjust(6, (compress(scp_bin[44],3,3)) ,pointer,space);              pointer += space>>4;    debug_cntr += space>>4;
             for(int i=0; i<4; i++){
@@ -936,7 +1002,7 @@
             }
         }else if(at == 1){
             #if scpz
-            //gPC.printf("\n\rAbove threshold");
+            gPC.printf("\n\rAbove threshold");
             #endif
             space = adjust(1, (compress(scp_bin[44],6,3))>>8 ,pointer,space);           pointer += space>>4;    debug_cntr += space>>4;
             space = adjust(8, (compress(scp_bin[44],6,3)) ,pointer,space);              pointer += space>>4;    debug_cntr += space>>4;
@@ -963,13 +1029,13 @@
         if(srp_mode==0)
         {
             #if scpz
-            //gPC.printf("\n\rSCP - calibrated extreme data conservation mode");
+            gPC.printf("\n\rSCP - calibrated extreme data conservation mode");
             #endif
             space = adjust(1, pzf,pointer,space);       pointer += space>>4;    debug_cntr += space>>4;
             space = adjust(1, ezf,pointer,space);       pointer += space>>4;    debug_cntr += space>>4;
             if(at==0){
                 #if scpz
-                //gPC.printf("\n\rBelow threshold");
+                gPC.printf("\n\rBelow threshold");
                 #endif
                 space = adjust(7, (compress(scp_bin[50],4,3)) ,pointer,space);              pointer += space>>4;    debug_cntr += space>>4;
                 if(pzf==0){
@@ -982,7 +1048,7 @@
                 }
             }else if(at==1){
                 #if scpz
-                //gPC.printf("\n\rAbove threshold");
+                gPC.printf("\n\rAbove threshold");
                 #endif
                 space = adjust(4, (compress(scp_bin[50],9,3))>>8 ,pointer,space);           pointer += space>>4;    debug_cntr += space>>4;
                 space = adjust(8, (compress(scp_bin[50],9,3)) ,pointer,space);              pointer += space>>4;    debug_cntr += space>>4;
@@ -999,14 +1065,14 @@
         else if(srp_mode==1)
         {
             #if scpz
-            //gPC.printf("\n\rSCP - Scatter plot, extreme data conservation mode");
+            gPC.printf("\n\rSCP - Scatter plot, extreme data conservation mode");
             #endif
             pzf = 0;    ezf = 0;    //because proton energy bins are not available in scatter plot mode and hence in the packet we send dummy data(which is nothng but the maximum value which fits into that particular compression scheme)
             space = adjust(1, pzf,pointer,space);       pointer += space>>4;    debug_cntr += space>>4;
             space = adjust(1, ezf,pointer,space);       pointer += space>>4;    debug_cntr += space>>4;
             if(at==0){
                 #if scpz
-                //gPC.printf("\n\rBelow threshold");
+                gPC.printf("\n\rBelow threshold");
                 #endif
                 space = adjust(7, (compress(scp_bin[50],4,3)) ,pointer,space);      pointer += space>>4;    debug_cntr += space>>4;
                 // below 4 lines - filling the proton ane electron energy bins with zeros(junk value) since they're not available in srp
@@ -1017,7 +1083,7 @@
             }
             else if(at==1){
                 #if scpz
-                //gPC.printf("\n\rAbove threshold");
+                gPC.printf("\n\rAbove threshold");
                 #endif
                 space = adjust(4, (compress(scp_bin[50],9,3))>>8 ,pointer,space);       pointer += space>>4;    debug_cntr += space>>4;
                 space = adjust(8, (compress(scp_bin[50],9,3)) ,pointer,space);          pointer += space>>4;    debug_cntr += space>>4;
@@ -1084,12 +1150,12 @@
     }
     length = (length%8==0)?(length/8):(length/8)+1;
     #if scpz
-    //gPC.printf("\n\rSCP packet length = %d",length);
+    gPC.printf("\n\rSCP packet length = %d",length);
     #endif
     if(position_tm_frame[id]>129){        
         #if scpz
-        //gPC.printf("\n\rSkipping the current TM frame. Inserting SCP into the next frame");
-        //gPC.printf("\n\rposition_tm_frame = %d",position_tm_frame[id]);
+        gPC.printf("\n\rSkipping the current TM frame. Inserting SCP into the next frame");
+        gPC.printf("\n\rposition_tm_frame = %d",position_tm_frame[id]);
         #endif
         while(position_tm_frame[id]<132){
             frames[id][position_tm_frame[id]] = 0;
@@ -1103,7 +1169,7 @@
     {        
         if(position_tm_frame[id]==frames[id][4]){
             #if scpz
-            //gPC.printf("\n\rInserting Time into SCP_TM");
+            gPC.printf("\n\rInserting Time into SCP_TM");
             #endif
             frames[id][5] = (uint8_t)((sci_time>>29)&0x3f);
             frames[id][6] = (uint8_t)((sci_time>>21)&0xff);
@@ -1117,24 +1183,35 @@
         if(position_tm_frame[id] == 132)                                                //space full in the frame bro
         {
             #if scpz
-            //gPC.printf("\n\rSCP_TM frame full. Length of current SCP packet = %d",j);
+            gPC.printf("\n\rSCP_TM frame full. Length of current SCP packet = %d",j);
             #endif
             pointer = frames[id];
             space = adjust(1,0,pointer,8);
             space = adjust(4,1,pointer,space);
             FSC_science = FSC_CURRENT[1];
-            gPC.printf("1 = 0x%X",FSC_science);
+            //gPC.printf("1 = 0x%X",FSC_science);
+            
+            #if debug_fsc
             frames[id][1] = (FSC_science>>16)&0xff;
             frames[id][2] = (FSC_science>>8)&0xff;
             frames[id][3] = (FSC_science)&0xff;
+            test_fsc[1]++;
+            #endif
+            #if !debug_fsc
+            frames[id][1] = (FSC_science>>16)&0xff;
+            frames[id][2] = (FSC_science>>8)&0xff;
+            frames[id][3] = (FSC_science)&0xff;
+            #endif
+
             temp_crc = crc16_gen(frames[id],132);
             frames[id][132] = temp_crc>>8;
             frames[id][133] = temp_crc & 0xff;
             #if scpz
             //gPC.printf("\n\rFirst head pointer contents: 0x%02X",frames[id][frames[id][4]]);
-            gPC.printf("\n\rPrinting SCP_TM\n\r{");
+            //gPC.printf("\n\rPrinting SCP_TM\n\r{");
+            gPC.printf("\n\r{");
             for(uint8_t z=0;z<134;z++){
-                gPC.printf("0x%02X,",frames[id][z]);
+                gPC.printf("%02X",frames[id][z]);
             }
             gPC.printf("}\n\r");
             #endif
@@ -1145,52 +1222,53 @@
 
             sd_stat = SD_WRITE(TM_interleave_data,FSC_science+1,1);         //sd_write returns ack, for now not included
             if(sd_stat)
-                {
-                    gPC.puts("sd write fail");
-                    }
-            
+            {
+                gPC.puts("sd write fail");
+            }
             position_tm_frame[id] = position_tm_starting[id];
             frames[id][4] = (length - j)+position_tm_starting[id];
         }
     }
     #if scpz_last
-    //gPC.printf("\n\rPrinting the last SFP_TM frame");
+    //gPC.printf("\n\rPrinting the last SCP_TM frame");
     //gPC.printf("\n\n\rPosition of tm_pointer: %d",position_tm_frame[id]);
     while(position_tm_frame[id]<132){
         frames[id][position_tm_frame[id]] = 0;
         position_tm_frame[id]++;
     }
-    if(position_tm_frame[id]==132){
-        //gPC.printf("\n\rFirst head pointer contents: 0x%02X",frames[id][frames[id][4]]);
+    if(position_tm_frame[id] == 132)                                                //space full in the frame bro
+    {
+        //gPC.printf("\n\rSCP_TM frame full. Length of current SCP packet = %d",j);
         pointer = frames[id];
-        if(id == 1){    //below threshold
-            space = adjust(1,0,pointer,8);
-            space = adjust(4,3,pointer,space);
-            FSC_science = FSC_CURRENT[1];                               ///to be used as this, but FSC_CURRENT[] is 32 bit                    
-            frames[id][1] = (FSC_science>>24)&0xff;
-            frames[id][2] = (FSC_science>>16)&0xff;
-            frames[id][3] = (FSC_science>>8)&0xff;
-            frames[id][4] = FSC_science&0xff;                    
-        }
-        else if(id == 2)    //above threshold
-        {
-            space = adjust(1,0,pointer,8);
-            space = adjust(4,2,pointer,space);                    
-            FSC_science = FSC_CURRENT[2];                                               ///to be used as this
-            frames[id][1] = (FSC_science>>16)&0xff;
-            frames[id][2] = (FSC_science>>8)&0xff;
-            frames[id][3] = FSC_science&0xff;
-        }
+        space = adjust(1,0,pointer,8);
+        space = adjust(4,1,pointer,space);
+        FSC_science = FSC_CURRENT[1];
+        //gPC.printf("1 = 0x%X",FSC_science);
+        
+        #if debug_fsc
+        frames[id][1] = (FSC_science>>16)&0xff;
+        frames[id][2] = (FSC_science>>8)&0xff;
+        frames[id][3] = (FSC_science)&0xff;
+        test_fsc[1]++;
+        #endif
+        #if !debug_fsc
+        frames[id][1] = (FSC_science>>16)&0xff;
+        frames[id][2] = (FSC_science>>8)&0xff;
+        frames[id][3] = (FSC_science)&0xff;
+        #endif
+
         temp_crc = crc16_gen(frames[id],132);
         frames[id][132] = temp_crc>>8;
         frames[id][133] = temp_crc & 0xff;
-        
-        
-        gPC.printf("\n\rPrinting SCP_TM\n\r{");
+        //gPC.printf("\n\rFirst head pointer contents: 0x%02X",frames[id][frames[id][4]]);
+        //gPC.printf("\n\rPrinting SCP_TM\n\r{");
+        gPC.printf("\n\r{");
         for(uint8_t z=0;z<134;z++){
-            gPC.printf("0x%02X,",frames[id][z]);
+            gPC.printf("%02X",frames[id][z]);
         }
         gPC.printf("}\n\r");
+        position_tm_frame[id] = position_tm_starting[id];
     }
-    #endif    
+    #endif   
+    gPC.printf("\n\rExiting SRP"); 
 }
\ No newline at end of file
--- a/DefinitionsAndGlobals.h	Sat Aug 06 06:34:38 2016 +0000
+++ b/DefinitionsAndGlobals.h	Sun Aug 07 10:36:59 2016 +0000
@@ -279,7 +279,7 @@
 DigitalIn V_B_PGOOD_2 (PIN7);
 DigitalIn V_C_PGOOD (PIN54);
 DigitalIn COMRX_OC_FAULT (PIN68);
-DigitalIn COMTX_OC_FAULT (PIN69);
+//DigitalIn COMTX_OC_FAULT (PIN69);
 DigitalIn BAE_OC_FAULT (PIN92);
 DigitalOut PL_GPIO_1_STATUS (PIN71); // PYLD EPS CNTRL Signal1 / PYLD_EPS_CNTRL_SIG1
 DigitalOut PL_GPIO_2_STATUS (PIN81);//PYLD EPS CNTRL 2 / PYLD_EPS_CNTRL_2
@@ -320,30 +320,30 @@
 uint32_t TIME_LATEST_SPI_SPEED;
 
 //Counter's
-uint16_t CDMS_I2C_ERR_SPEED_COUNTER;
-uint16_t CDMS_I2C_ERR_BAE_COUNTER;
-uint16_t CDMS_HK_MAIN_COUNTER;
-uint16_t COMRX_RESET_COUNTER;
-uint16_t PL_MAIN_COUNTER;
-uint16_t PL_RCV_SC_DATA_COUNTER;
-uint16_t CDMS_WR_SD_FAULT_COUNTER;
+uint16_t CDMS_I2C_ERR_SPEED_COUNTER = 0;
+uint16_t CDMS_I2C_ERR_BAE_COUNTER = 0;
+uint16_t CDMS_HK_MAIN_COUNTER = 0;
+uint16_t COMRX_RESET_COUNTER = 0;
+uint16_t PL_MAIN_COUNTER = 0;
+uint16_t PL_RCV_SC_DATA_COUNTER = 0;
+uint16_t CDMS_WR_SD_FAULT_COUNTER = 0;
 uint16_t SD_LIB_WRITES = 0;
 
 //CDMS RAM parameters
-uint8_t PL_INIT_STATUS;
-uint8_t PL_MAIN_STATUS;
+uint8_t PL_INIT_STATUS = 0;
+uint8_t PL_MAIN_status;
 uint8_t PL_LOW_POWER;
 uint8_t PL_STATE;
-uint8_t PL_RCV_SC_DATA_STATUS;
+uint8_t PL_RCV_SC_DATA_STATUS = 0;
 uint8_t COM_SESSION;
 uint8_t COM_RX;
 uint8_t RF_SW_STATUS;
 uint8_t COM_TX;
 uint8_t COM_TX_STATUS;
 uint8_t COM_MNG_TMTC;
-uint8_t EN_CDMS_HK = 0x01;
-uint8_t EN_PL = 0x01;
-uint8_t EN_RCV_SC = 0x01;
+uint8_t EN_CDMS_HK = 1;
+uint8_t EN_PL = 1;
+uint8_t EN_RCV_SC = 1;
 uint8_t CDMS_INIT_STATUS;
 uint8_t CDMS_HK_STATUS;
 uint8_t COM_RX_STATUS;
--- a/TEST_PL.h	Sat Aug 06 06:34:38 2016 +0000
+++ b/TEST_PL.h	Sun Aug 07 10:36:59 2016 +0000
@@ -498,9 +498,9 @@
         
     //testing TC = 0x1,0x2...0x6
     int w =1;
-    for(uint8_t v=1;w<1000;w++)
+    for(uint8_t v=1;v<7;v++)
     {        
-        /*switch(v)
+        switch(v)
         {
             case 1: test_schedule_1(test_tm_ptr);
                     break;
@@ -514,8 +514,8 @@
                     break;
             case 6: test_schedule_6(test_tm_ptr);
                     break;
-        }*/
-        gPC.printf("\n\rIndex:%d",w);
+        }
+        //gPC.printf("\n\rIndex:%d",w);
         if(v==1)
         {
             test_schedule_1(test_tm_ptr);
@@ -569,7 +569,7 @@
         verify_extracted(v);
         for(z=0;z<192;z++)
             temp_pl_block[z] = pl_block[z];
-        //wait(1);
+        wait(1);
     }
     gPC.printf("\n\rTesting TC_TM block processing complete");
 }
\ No newline at end of file
--- a/ThreadsAndFunctions.h	Sat Aug 06 06:34:38 2016 +0000
+++ b/ThreadsAndFunctions.h	Sun Aug 07 10:36:59 2016 +0000
@@ -12,22 +12,31 @@
     gPAY_SPI = new dmaSPISlave(PAY_SPI_MOSI, PAY_SPI_MISO, PAY_SPI_CLK, PAY_SPI_CS);
     gPAY_SPI->frequency(1000000);
     gPAY_SPI->format(8,0);
+    gPC.printf("\n\rTest...........................");
     gPAY_SPI->bulkRead_init(gPAYLOAD_BUFFER, PAYLOAD_BUFFER_LENGTH, &payload_isr_fun);
     gPAY_SPI->bulkRead_start();
-    //gPAY_SPI->bulkRead_pause();
-    //gPAY_SPI->bulkRead_resume(&payload_isr_fun);
+    gPAY_SPI->bulkRead_pause();
+    gPAY_SPI->bulkRead_resume(&payload_isr_fun);
     while(true){
         gPC.puts("entering sci\r\n");
         gSCIENCE_THREAD->signal_wait(SCIENCE_SIGNAL);
         gMutex.lock();
+        PL_RCV_SC_DATA_STATUS = 1;
         gPC.puts("sig_set\r\n");
         //for(int i =0; i<PAYLOAD_BUFFER_LENGTH; i++)
         //if (gPAYLOAD_BUFFER[i] != 0) gPC.printf("not zero");  
+        //gPAY_SPI->bulkRead_start();
         srp(gPAYLOAD_BUFFER);//skip one apcket when cdms resets
         gPC.puts("exit_srp\r\n");
         wait(2);/*timeout to be decided*/
         if(dma)
-        gPAY_SPI->bulkRead_start();
+        {
+            gPAY_SPI->bulkRead_start();
+            gPAY_SPI->bulkRead_pause();
+            gPAY_SPI->bulkRead_resume(&payload_isr_fun);
+        }
+        /*else
+        gPC.printf("\n\rDMA error");*/
         gMutex.unlock();
     }
 }
@@ -161,7 +170,7 @@
         }
         else if( gFLAGS & NEW_TC_RECEIVED ){
             gPC.puts("NEW TC RECEIVED\r\n");
-            //Thread::wait(10000);
+            Thread::wait(2000);
             gFLAGS = gFLAGS & (~NEW_TC_RECEIVED);
             gFLAGS = gFLAGS | COM_MNG_TMTC_RUNNING_FLAG;
 
@@ -178,7 +187,7 @@
             gFLAGS = gFLAGS & (~COM_RX_FLAG);
             
             //Mutex
-            gMutex.lock();
+            //gMutex.lock();
             
             if( gTOTAL_VALID_TC > 0 ){
                 gPC.printf("valid TC rx: %u\r\n", gTOTAL_VALID_TC);
--- a/i2c.h	Sat Aug 06 06:34:38 2016 +0000
+++ b/i2c.h	Sun Aug 07 10:36:59 2016 +0000
@@ -45,7 +45,7 @@
         }
         if(((pdirr1 & 0x03000000)==0x03000000))//if SCL and SDA are both high
         {    
-            gPC.printf("\n\rData received from BAE");
+            gPC.printf("\n\rData received from PL");
         }
         else 
         {            
--- a/main.cpp	Sat Aug 06 06:34:38 2016 +0000
+++ b/main.cpp	Sun Aug 07 10:36:59 2016 +0000
@@ -114,8 +114,8 @@
     sys_reset_cdms_timer = new RtosTimer(sys_pwr_reset, osTimerPeriodic, (void * )NULL);
     sys_reset_cdms_timer->start(cdms_reset_timeout);
 
-    /*PL_wo_dma = new RtosTimer(payload_isr_fun_dma, osTimerPeriodic,(void * )NULL);
-    PL_wo_dma->start(6000);*/
+    //PL_wo_dma = new RtosTimer(payload_isr_fun_dma, osTimerPeriodic,(void * )NULL);
+    //PL_wo_dma->start(6000);
     //gSCIENCE_THREAD->signal_set(SCIENCE_SIGNAL);
     
     /*Timeout flipper;
@@ -129,7 +129,7 @@
     wait(1);
     }
     gPC.printf("PL_TC sent");*/
-    
+    //test_pl_main();
     while(true){
         Thread::wait(osWaitForever);
          gLEDG = !gLEDG;