Latest FM Code with EEPROM

Dependencies:   FreescaleIAP SimpleDMA eeprom mbed-rtos mbed

Fork of CDMS_QM_03MAR2017_Flash_with_obsrs by Team Fox

Revision:
261:1e54415b34d3
Parent:
260:65e1ace927fd
Child:
262:752c8689944a
diff -r 65e1ace927fd -r 1e54415b34d3 COM_MNG_TMTC.h
--- a/COM_MNG_TMTC.h	Tue Jul 12 17:54:30 2016 +0000
+++ b/COM_MNG_TMTC.h	Thu Jul 14 13:07:30 2016 +0000
@@ -16,25 +16,6 @@
 //DigitalIn tm_status_4m_pl(PIN61); //I2C interrupt to CDMS from PL
 #define RESET_CDMS NVIC_SystemReset()
 
-#define BAE_TC{\
-    tc_ptr->next_TC = NULL;\
-    PUTshort_or_long(tc_ptr,SHORT_TC_CODE);\
-    PUTcrc_pass(tc_ptr,0x1);\
-    PUTexec_status(tc_ptr,0);\
-    tc_ptr->TC_string[0] = 0x01;\
-    tc_ptr->TC_string[1] = 0x60;\
-    tc_ptr->TC_string[2] = 0x81;\
-    tc_ptr->TC_string[3] = 0x21;\
-    tc_ptr->TC_string[4] = 0x00;\
-    tc_ptr->TC_string[5] = 0;\
-    tc_ptr->TC_string[6] = 0;\
-    tc_ptr->TC_string[7] = 0;\
-    tc_ptr->TC_string[8] = 0;\
-    uint16_t crc16 = crc16_gen(tc_ptr->TC_string, 9);\
-    tc_ptr->TC_string[9]  = (crc16 & 0xFF00)>>8;\
-    tc_ptr->TC_string[10] = (crc16 & 0x00FF);\
-}
-
 
 uint8_t received = 0;
 uint16_t mid1;
@@ -50,7 +31,7 @@
 uint8_t ACK_CODE;
 
 void TM_PMS_PL_SCHEDULE(Base_tm* tm_pointer1,uint8_t psc);
-void ACK_L234(Base_tm* tm_pointer1,uint8_t ackCode,uint8_t psc);
+void ACK_L234(Base_tm* tm_pointer_short1,uint8_t ackCode,uint8_t psc);
 
 #define delete_TC(tc_ptr) {\
     if(tc_ptr == gHEAD_NODE_TCL){\
@@ -220,19 +201,19 @@
 /*tm_ptr is the next_TM of a linked list, and should have the value NULL, i.e. tm_ptr should be the next_TM pointer of thte last node */
 
 // CDMS TEAM CODE START
-void ACK_L234(Base_tm* tm_pointer1,uint8_t ackCode,uint8_t psc)
+void ACK_L234(Base_tm* tm_pointer_short1,uint8_t ackCode,uint8_t psc)
 {
-    tm_pointer1->TM_string[0] = 0xB0; 
-    tm_pointer1->TM_string[1] = psc;
-    tm_pointer1->TM_string[2] = ackCode;
-    tm_pointer1->TM_string[3] = 0x00;
-    tm_pointer1->TM_string[4] = 0x00;
+    tm_pointer_short1->TM_string[0] = 0xB0; 
+    tm_pointer_short1->TM_string[1] = psc;
+    tm_pointer_short1->TM_string[2] = ackCode;
+    tm_pointer_short1->TM_string[3] = 0x00;
+    tm_pointer_short1->TM_string[4] = 0x00;
     for(uint8_t i=0;i<6;i++)
-        tm_pointer1->TM_string[i+5] = 0;
-    crc16 = crc16_gen(tm_pointer1->TM_string,11);
-    tm_pointer1->TM_string[11] = (uint8_t)((crc16&0xFF00)>>8);
-    tm_pointer1->TM_string[12] = (uint8_t)(crc16&0x00FF);
-    tm_pointer1->next_TM = NULL;                                                 
+        tm_pointer_short1->TM_string[i+5] = 0;
+    crc16 = crc16_gen(tm_pointer_short1->TM_string,11);
+    tm_pointer_short1->TM_string[11] = (uint8_t)((crc16&0xFF00)>>8);
+    tm_pointer_short1->TM_string[12] = (uint8_t)(crc16&0x00FF);
+    tm_pointer_short1->next_TM = NULL;                                                 
 }
 void TM_PMS_PL_SCHEDULE(Base_tm *tm_pointer1,uint8_t psc)
 {
@@ -367,23 +348,26 @@
     //uint8_t ACKCODE = 0xB0;
     bool y;
     //gPC.printf("\rTC execution in progress\r\n");
-    Base_tm *tm_pointer = new Base_tm;
+    Base_tm *tm_pointer = new Long_tm;
     Base_tm *tm_ptr = tm_pointer;
+    //Base_tm *tm_ptr = new Long_tm;
+    Base_tm *tm_pointer_short = new Short_tm;
+    Base_tm *tm_ptr_short = tm_pointer_short;
     received = 0;
     switch(GETapid(tc_ptr))             //checking APID's
     {
         case 1: //apid=01 implies it corresponds to bae
         {
             BAE_I2C_mutex.lock();
-            BAE_TC;
+            //BAE_TC;
             gPC.printf("Telecommand is for BAE\r\n");
             gPC.printf("Sending TC to BAE...\r\n"); //interrupt to be sent to the bae
             y = FCTN_I2C_WRITE((char*)tc_ptr->TC_string,TC_LONG_SIZE);                         // Check for SHORT and LONG TC and then send
                 
             if(y==1)                                                            
             {                                                                               
-                ACK_L234(tm_pointer,0x03,GETpacket_seq_count(tc_ptr));
-                return tm_ptr;
+                ACK_L234(tm_ptr_short,0x03,GETpacket_seq_count(tc_ptr));
+                return tm_ptr_short;
             }                                  
             else if(y==0)
             {
@@ -406,17 +390,17 @@
                     }
                     else if(y==1)
                     {
-                        ACK_L234(tm_pointer,0x85,GETpacket_seq_count(tc_ptr));                
+                        ACK_L234(tm_ptr_short,0x85,GETpacket_seq_count(tc_ptr));                
                         //gPC.printf("\n\rPTE->PDIR = 0x%08X",PTE->PDIR);
-                        return tm_ptr;
+                        return tm_ptr_short;
                         break;  
                     }
                 }
                 else if(BAE_I2C_GPIO == 0)                                       //name to be changed later
                 {
                     gPC.printf("BAE_I2C_GPIO is not high\r\n");                    
-                    ACK_L234(tm_pointer,0x84,GETpacket_seq_count(tc_ptr));
-                    return tm_ptr;
+                    ACK_L234(tm_ptr_short,0x84,GETpacket_seq_count(tc_ptr));
+                    return tm_ptr_short;
                 }
             }
             BAE_I2C_mutex.unlock();
@@ -438,17 +422,15 @@
                             mid=((uint16_t)(tc_ptr->TC_string[3]<<4))+((uint16_t)(tc_ptr->TC_string[4]));                                                       
                             if(mid!=0x0000 && mid!=0x0001)
                             {
-                                ACK_L234(tm_pointer,0x02,GETpacket_seq_count(tc_ptr));
-                                return tm_ptr;
+                                ACK_L234(tm_ptr_short,0x02,GETpacket_seq_count(tc_ptr));
+                                return tm_ptr_short;
                             }
 
                             tm_pointer->TM_string[0] = 0x30;
                             tm_pointer->TM_string[1] = GETpacket_seq_count(tc_ptr);
                             tm_pointer->TM_string[2] = 0xA0;
                             tm_pointer->TM_string[3] = 0x00;                            //spare bits
-                            
                             FCTN_CDMS_RD_L_RAM(tm_pointer);
-                            
                             crc16 = crc16_gen(tm_ptr->TM_string,132);
                             tm_pointer->TM_string[132] = (uint8_t)((crc16&0xFF00)>>8);
                             tm_pointer->TM_string[133] = (uint8_t)(crc16&0x00FF);
@@ -461,43 +443,169 @@
                             mid=(uint16_t)(tc_ptr->TC_string[3]<<4)+(uint16_t)(tc_ptr->TC_string[4]);
                             //32 bits at a time           
 
-                            if(mid<0 || mid>16)                                  //allowable MID values?
+                            if(mid == 0x0101 || mid==0x0102 || mid == 0x0103 || mid == 0x0100)                                  //allowable MID values?
                             {
-                                ACK_L234(tm_pointer,0x02,GETpacket_seq_count(tc_ptr));
-                                return tm_ptr;
+                                ACK_L234(tm_ptr_short,0x02,GETpacket_seq_count(tc_ptr));
+                                return tm_ptr_short;
                             }                                                        
-                            
-                            FCTN_CDMS_WR_FLASH(mid,(uint32_t)(tc_ptr->TC_string[5]<<24)+(uint32_t)(tc_ptr->TC_string[6]<<16)+(uint32_t)(tc_ptr->TC_string[7]<<8)+(uint32_t)(tc_ptr->TC_string[8]));                          
+
+                            FCTN_CDMS_WR_S_FLASH(mid,(uint32_t)(tc_ptr->TC_string[5]<<24)+(uint32_t)(tc_ptr->TC_string[6]<<16)+(uint32_t)(tc_ptr->TC_string[7]<<8)+(uint32_t)(tc_ptr->TC_string[8]));                                                     
 
-                            ACK_L234(tm_pointer,0xA0,GETpacket_seq_count(tc_ptr));                     //ackCode = ? for success
+                            ACK_L234(tm_ptr_short,0xA0,GETpacket_seq_count(tc_ptr));              
 
-                            return tm_ptr;
+                            return tm_ptr_short;
                         }
-                        case 0x6:
+                        case 0x6:   //service subtye = WR_L_FLASH
                         {
-                            //gPC.printf("WRITE ON LONG_FLASH_MEMORY\r\n");                          
-                            mid=(uint16_t)(tc_ptr->TC_string[3]<<4)+(uint16_t)(tc_ptr->TC_string[4]);           
-                            //1024 bits at a time
-
-                            if(mid<0x0002 || mid>0x000A)                                  //allowable MID values?
+                            mid=((uint16_t)(tc_ptr->TC_string[3]<<8))+((uint16_t)(tc_ptr->TC_string[4]));
+                            if(mid == 0x0002)
+                            {
+                                for(uint8_t z=0;z<24;z++)
+                                    scp_threshold_m0[z] = tc_ptr->TC_string[z+5];
+                                for(uint8_t z=24;z<32;z++)
+                                    scp_threshold_m0[z+8] = tc_ptr->TC_string[z+5];                            
+                                //int strt_add = flash_size() - (11*SECTOR_SIZE);
+                                //uint32_t flasharray[32] = {0};
+                                for(uint8_t z=0;z<24;z++)
+                                    flasharray_thres[z] = scp_threshold_m0[z];
+                                for(uint8_t z=24;z<32;z++)
+                                    flasharray_thres[z] = scp_threshold_m0[z+8];
+                                erase_sector(strt_add_thres);
+                                program_flash(strt_add_thres, (char*)flasharray_thres,32);
+                                ACK_L234(tm_ptr_short,0xA0,GETpacket_seq_count(tc_ptr));
+                                return tm_ptr_short;
+                            }
+                            else if(mid == 0x0003)
+                            {
+                                for(uint8_t z=0;z<12;z++)
+                                    scp_threshold_m0[z+40] = tc_ptr->TC_string[z+5];
+                                //int strt_add = flash_size() - (10*SECTOR_SIZE);
+                                //uint32_t flasharray[32] = {0};
+                                for(uint8_t z=0;z<12;z++)
+                                    flasharray_thres[z] = scp_threshold_m0[z+40];
+                                erase_sector(strt_add_thres+SECTOR_SIZE);
+                                program_flash(strt_add_thres+SECTOR_SIZE, (char*)flasharray_thres,32);
+                                ACK_L234(tm_ptr_short,0xA0,GETpacket_seq_count(tc_ptr));
+                                return tm_ptr_short;
+                            }
+                            else if(mid == 0x0004)
+                            {
+                                for(uint8_t z=0;z<32;z++)
+                                    scp_threshold_m1[z] = tc_ptr->TC_string[z+5];
+                                //int strt_add = flash_size() - (9*SECTOR_SIZE);
+                                //uint32_t flasharray[32] = {0};
+                                for(uint8_t z=0;z<32;z++)
+                                    flasharray_thres[z] = scp_threshold_m1[z];
+                                erase_sector(strt_add_thres+(2*SECTOR_SIZE));
+                                program_flash(strt_add_thres+(2*SECTOR_SIZE), (char*)flasharray_thres,32);
+                                ACK_L234(tm_ptr_short,0xA0,GETpacket_seq_count(tc_ptr));
+                                return tm_ptr_short;
+                            }
+                            else if(mid == 0x0005)
+                            {
+                                for(uint8_t z=0;z<20;z++)
+                                    scp_threshold_m1[z+32] = tc_ptr->TC_string[z+5];
+                                //int strt_add = flash_size() - (8*SECTOR_SIZE);
+                                //uint32_t flasharray[32] = {0};
+                                for(uint8_t z=0;z<20;z++)
+                                    flasharray_thres[z] = scp_threshold_m1[z+32];
+                                erase_sector(strt_add_thres+(3*SECTOR_SIZE));
+                                program_flash(strt_add_thres+(3*SECTOR_SIZE), (char*)flasharray_thres,32);
+                                ACK_L234(tm_ptr_short,0xA0,GETpacket_seq_count(tc_ptr));
+                                return tm_ptr_short;
+                            }
+                            else if(mid == 0x0006)
                             {
-                                ACK_L234(tm_pointer,0x02,GETpacket_seq_count(tc_ptr));                     //ackCode = ? for invalid mid
-                                return tm_ptr;
-                            }    
-
-                            //Send TM for success after writing onto flash
-                            //FCTN_CDMS_WR_L_FLASH(mid);
-
-                            return tm_ptr;
-                        }                                                    
+                                scp_threshold_m0_1[7] = tc_ptr->TC_string[5];
+                                scp_threshold_m0_1[5] = tc_ptr->TC_string[6];
+                                scp_threshold_m0_1[8] = tc_ptr->TC_string[7];
+                                scp_threshold_m0_1[6] = tc_ptr->TC_string[8];
+                                for(uint8_t z=0;z<5;z++)
+                                    scp_threshold_m0_1[z] = tc_ptr->TC_string[z+9];
+                                //scp_sfp_threshold_m0_2[0] = tc_ptr->TC_string[14];
+                                //scp_sfp_threshold_m0_2[1] = tc_ptr->TC_string[15];
+                                //scp_sfp_threshold_m0_2[2] = tc_ptr->TC_string[16];
+                                //int strt_add = flash_size() - (7*SECTOR_SIZE);
+                                //uint32_t flasharray[32] = {0};
+                                flasharray_thres[0] = scp_threshold_m0_1[7];
+                                flasharray_thres[1] = scp_threshold_m0_1[5];
+                                flasharray_thres[2] = scp_threshold_m0_1[8];
+                                flasharray_thres[3] = scp_threshold_m0_1[6];
+                                for(uint8_t z=0;z<5;z++)
+                                    flasharray_thres[z+4] = scp_threshold_m0_1[z];
+                                //flasharray_thres[9]  = scp_sfp_threshold_m0_2[0];
+                                //flasharray_thres[10] = scp_sfp_threshold_m0_2[1];
+                                //flasharray_thres[11] = scp_sfp_threshold_m0_2[2];
+                                erase_sector(strt_add_thres+(4*SECTOR_SIZE));
+                                program_flash(strt_add_thres+(4*SECTOR_SIZE), (char*)flasharray_thres,32);
+                                ACK_L234(tm_ptr_short,0xA0,GETpacket_seq_count(tc_ptr));
+                                return tm_ptr_short;
+                            }
+                            else if(mid == 0x0007)
+                            {
+                                for(uint8_t z=0;z<24;z++)
+                                    sfp_threshold_m0[z] = tc_ptr->TC_string[z+5];
+                                for(uint8_t z=24;z<32;z++)
+                                    sfp_threshold_m0[z+8] = tc_ptr->TC_string[z+5];
+                                //int strt_add_thres = flash_size() - (6*SECTOR_SIZE);
+                                //uint32_t flasharray_thres[32] = {0};
+                                for(uint8_t z=0;z<24;z++)
+                                    flasharray_thres[z] = sfp_threshold_m0[z];
+                                for(uint8_t z=24;z<32;z++)
+                                    flasharray_thres[z] = sfp_threshold_m0[z+8];
+                                erase_sector(strt_add_thres+(5*SECTOR_SIZE));
+                                program_flash(strt_add_thres+(5*SECTOR_SIZE), (char*)flasharray_thres,32);
+                                ACK_L234(tm_ptr_short,0xA0,GETpacket_seq_count(tc_ptr));
+                                return tm_ptr_short;
+                            }
+                            else if(mid == 0x0008)
+                            {
+                                for(uint8_t z=0;z<12;z++)
+                                    sfp_threshold_m0[z+40] = tc_ptr->TC_string[z+5];
+                                //int strt_add_thres = flash_size() - (5*SECTOR_SIZE);
+                                //uint32_t flasharray_thres[32] = {0};
+                                for(uint8_t z=0;z<12;z++)
+                                    flasharray_thres[z] = sfp_threshold_m0[z+40];
+                                erase_sector(strt_add_thres+(6*SECTOR_SIZE));
+                                program_flash(strt_add_thres+(6*SECTOR_SIZE), (char*)flasharray_thres,32);
+                                ACK_L234(tm_ptr_short,0xA0,GETpacket_seq_count(tc_ptr));
+                                return tm_ptr_short;
+                            }
+                            else if(mid == 0x0009)
+                            {
+                                for(uint8_t z=0;z<32;z++)
+                                    sfp_threshold_m1[z] = tc_ptr->TC_string[z+5];
+                                //int strt_add_thres = flash_size() - (4*SECTOR_SIZE);
+                                //uint32_t flasharray_thres[32] = {0};
+                                for(uint8_t z=0;z<32;z++)
+                                    flasharray_thres[z] = sfp_threshold_m1[z];
+                                erase_sector(strt_add_thres+(7*SECTOR_SIZE));
+                                program_flash(strt_add_thres+(7*SECTOR_SIZE), (char*)flasharray_thres,32);
+                                ACK_L234(tm_ptr_short,0xA0,GETpacket_seq_count(tc_ptr));
+                                return tm_ptr_short;
+                            }
+                            else if(mid == 0x000A)
+                            {
+                                for(uint8_t z=0;z<20;z++)
+                                    sfp_threshold_m1[z+32] = tc_ptr->TC_string[z+5];
+                                //int strt_add_thres = flash_size() - (3*SECTOR_SIZE);
+                                //uint32_t flasharray_thres[32] = {0};
+                                for(uint8_t z=0;z<20;z++)
+                                    flasharray_thres[z] = sfp_threshold_m1[z+32];
+                                erase_sector(strt_add_thres+(8*SECTOR_SIZE));
+                                program_flash(strt_add_thres+(8*SECTOR_SIZE), (char*)flasharray_thres,32);
+                                ACK_L234(tm_ptr_short,0xA0,GETpacket_seq_count(tc_ptr));
+                                return tm_ptr_short;
+                            }                        
+                        }
                         default:
                         {
                             gPC.printf("INVALID SERVICE SUBTYPE\r\n");
-                            ACK_L234(tm_pointer,0x02,GETpacket_seq_count(tc_ptr));
-                            return tm_ptr;
+                            ACK_L234(tm_ptr_short,0x02,GETpacket_seq_count(tc_ptr));
+                            return tm_ptr_short;
                         }
                     } 
-                }                                                                
+                }                                                                   
                 case 0x80:
                 {
                     gPC.printf("service:FUNCTION MANAGEMENT SERVICE\r\n"); 
@@ -511,13 +619,13 @@
                                 
                                 P_PL_INIT();
 
-                                ACK_L234(tm_pointer,0xA0,GETpacket_seq_count(tc_ptr));
-                                return tm_ptr;
+                                ACK_L234(tm_ptr_short,0xA0,GETpacket_seq_count(tc_ptr));
+                                return tm_ptr_short;
                             }                
                             else if(CDMS_STANDBY==0)
                             {
-                                ACK_L234(tm_pointer,0x87,GETpacket_seq_count(tc_ptr));                        //TC cannot be processed now
-                                return tm_ptr;
+                                ACK_L234(tm_ptr_short,0x87,GETpacket_seq_count(tc_ptr));                        //TC cannot be processed now
+                                return tm_ptr_short;
                             }
                         }                                
                         else if(GETpid(tc_ptr)==0x02)
@@ -528,13 +636,13 @@
                                 
                                 P_PL_MAIN();
 
-                                ACK_L234(tm_pointer,0xA0,GETpacket_seq_count(tc_ptr));
-                                return tm_ptr;
+                                ACK_L234(tm_ptr_short,0xA0,GETpacket_seq_count(tc_ptr));
+                                return tm_ptr_short;
                             }                
                             else if(CDMS_STANDBY==0)
                             {
-                                ACK_L234(tm_pointer,0x87,GETpacket_seq_count(tc_ptr));                        //TC cannot be processed now
-                                return tm_ptr;
+                                ACK_L234(tm_ptr_short,0x87,GETpacket_seq_count(tc_ptr));                        //TC cannot be processed now
+                                return tm_ptr_short;
                             }
                         }
                         else if(GETpid(tc_ptr)==0x03)
@@ -545,13 +653,13 @@
                                 
                                 P_COM_INIT();
 
-                                ACK_L234(tm_pointer,0xA0,GETpacket_seq_count(tc_ptr));
-                                return tm_ptr;
+                                ACK_L234(tm_ptr_short,0xA0,GETpacket_seq_count(tc_ptr));
+                                return tm_ptr_short;
                             }                
                             else if(CDMS_STANDBY==0)
                             {
-                                ACK_L234(tm_pointer,0x87,GETpacket_seq_count(tc_ptr));                        //TC cannot be processed now
-                                return tm_ptr;
+                                ACK_L234(tm_ptr_short,0x87,GETpacket_seq_count(tc_ptr));                        //TC cannot be processed now
+                                return tm_ptr_short;
                             }
                         }
                         else if(GETpid(tc_ptr)==0x04)
@@ -560,15 +668,15 @@
                             {   
                                 //gPC.printf("TC_P_CDMS_HK_MAIN\r\n"); // call PWR_SWCH_ON function
                                 
-                                P_CDMS_HK_MAIN();
+                                //gHK_THREAD->signal_set(HK_SIGNAL);
 
-                                ACK_L234(tm_pointer,0xA0,GETpacket_seq_count(tc_ptr));
-                                return tm_ptr;
+                                ACK_L234(tm_ptr_short,0xA0,GETpacket_seq_count(tc_ptr));
+                                return tm_ptr_short;
                             }                
                             else if(CDMS_STANDBY==0)
                             {
-                                ACK_L234(tm_pointer,0x87,GETpacket_seq_count(tc_ptr));                        //TC cannot be processed now
-                                return tm_ptr;
+                                ACK_L234(tm_ptr_short,0x87,GETpacket_seq_count(tc_ptr));                        //TC cannot be processed now
+                                return tm_ptr_short;
                             }
                         }
                         else if(GETpid(tc_ptr)==0x05)
@@ -579,13 +687,13 @@
                                 
                                 P_PL_RCV_SC_DATA();
 
-                                ACK_L234(tm_pointer,0xA0,GETpacket_seq_count(tc_ptr));
-                                return tm_ptr;
+                                ACK_L234(tm_ptr_short,0xA0,GETpacket_seq_count(tc_ptr));
+                                return tm_ptr_short;
                             }                
                             else if(CDMS_STANDBY==0)
                             {
-                                ACK_L234(tm_pointer,0x87,GETpacket_seq_count(tc_ptr));                        //TC cannot be processed now
-                                return tm_ptr;
+                                ACK_L234(tm_ptr_short,0x87,GETpacket_seq_count(tc_ptr));                        //TC cannot be processed now
+                                return tm_ptr_short;
                             }
                         }
                         else if(GETpid(tc_ptr)==0x06)
@@ -593,16 +701,16 @@
                             if(CDMS_STANDBY==1)
                             {   
                                 //gPC.printf("TC_SW_ON_RTC\r\n"); // call PWR_SWCH_ON function
-                                
+                                gPC.printf("SD _INIT\r\n");
                                 P_CDMS_INIT_SD();
 
-                                ACK_L234(tm_pointer,0xA0,GETpacket_seq_count(tc_ptr));
-                                return tm_ptr;
+                                ACK_L234(tm_ptr_short,0xA0,GETpacket_seq_count(tc_ptr));
+                                return tm_ptr_short;
                             }                
                             else if(CDMS_STANDBY==0)
                             {
-                                ACK_L234(tm_pointer,0x87,GETpacket_seq_count(tc_ptr));                        //TC cannot be processed now
-                                return tm_ptr;
+                                ACK_L234(tm_ptr_short,0x87,GETpacket_seq_count(tc_ptr));                        //TC cannot be processed now
+                                return tm_ptr_short;
                             }    
                         }
                         else if(GETpid(tc_ptr)==0x11)
@@ -611,8 +719,8 @@
                             
                             CDMS_SD_SW_ON();
 
-                            ACK_L234(tm_pointer,0xA0,GETpacket_seq_count(tc_ptr));
-                            return tm_ptr;                                                       
+                            ACK_L234(tm_ptr_short,0xA0,GETpacket_seq_count(tc_ptr));
+                            return tm_ptr_short;                                                       
                         }
                         else if(GETpid(tc_ptr)==0x21)
                         {       
@@ -620,8 +728,8 @@
                             
                             CDMS_SD_SW_OFF();
 
-                            ACK_L234(tm_pointer,0xA0,GETpacket_seq_count(tc_ptr));
-                            return tm_ptr;     
+                            ACK_L234(tm_ptr_short,0xA0,GETpacket_seq_count(tc_ptr));
+                            return tm_ptr_short;     
                         }
                         else if(GETpid(tc_ptr)==0x12)
                         {       
@@ -629,8 +737,8 @@
                             
                             CDMS_RTC_ON();
 
-                            ACK_L234(tm_pointer,0xA0,GETpacket_seq_count(tc_ptr));
-                            return tm_ptr;                                                       
+                            ACK_L234(tm_ptr_short,0xA0,GETpacket_seq_count(tc_ptr));
+                            return tm_ptr_short;                                                       
                         }
                         else if(GETpid(tc_ptr)==0x22)
                         {       
@@ -638,17 +746,17 @@
                             
                             CDMS_RTC_OFF();
 
-                            ACK_L234(tm_pointer,0xA0,GETpacket_seq_count(tc_ptr));
-                            return tm_ptr;                                                       
-                        }
+                            ACK_L234(tm_ptr_short,0xA0,GETpacket_seq_count(tc_ptr));
+                            return tm_ptr_short;
+                        } 
                         else if(GETpid(tc_ptr)==0x13)
                         {                           
                             //gPC.printf("TC_SW_ON_BAE\r\n"); // call PWR_SWCH_ON function
                             
                             SW_ON_BAE();
 
-                            ACK_L234(tm_pointer,0xA0,GETpacket_seq_count(tc_ptr));
-                            return tm_ptr;                            
+                            ACK_L234(tm_ptr_short,0xA0,GETpacket_seq_count(tc_ptr));
+                            return tm_ptr_short;                            
                         }
                         else if(GETpid(tc_ptr)==0x23)
                         {                           
@@ -656,8 +764,8 @@
                             
                             SW_OFF_BAE();
 
-                            ACK_L234(tm_pointer,0xA0,GETpacket_seq_count(tc_ptr));
-                            return tm_ptr;                                                        
+                            ACK_L234(tm_ptr_short,0xA0,GETpacket_seq_count(tc_ptr));
+                            return tm_ptr_short;                                                        
                         }
                         else if(GETpid(tc_ptr)==0x14)
                         {                            
@@ -665,8 +773,8 @@
                             
                             SW_ON_PL_BEE();
 
-                            ACK_L234(tm_pointer,0xA0,GETpacket_seq_count(tc_ptr));
-                            return tm_ptr;                                                        
+                            ACK_L234(tm_ptr_short,0xA0,GETpacket_seq_count(tc_ptr));
+                            return tm_ptr_short;                                                        
                         }
                         else if(GETpid(tc_ptr)==0x24)
                         {                   
@@ -674,8 +782,8 @@
                             
                             SW_OFF_PL_BEE();
 
-                            ACK_L234(tm_pointer,0xA0,GETpacket_seq_count(tc_ptr));
-                            return tm_ptr;    
+                            ACK_L234(tm_ptr_short,0xA0,GETpacket_seq_count(tc_ptr));
+                            return tm_ptr_short;    
                         }
                         else if(GETpid(tc_ptr)==0x15)
                         {                            
@@ -683,8 +791,8 @@
                             
                             SW_ON_PL_EPS();
 
-                            ACK_L234(tm_pointer,0xA0,GETpacket_seq_count(tc_ptr));     
-                            return tm_ptr;                            
+                            ACK_L234(tm_ptr_short,0xA0,GETpacket_seq_count(tc_ptr));     
+                            return tm_ptr_short;                            
                         }
                         else if(GETpid(tc_ptr)==0x25)
                         {                            
@@ -692,8 +800,8 @@
                             
                             SW_OFF_PL_EPS();
 
-                            ACK_L234(tm_pointer,0xA0,GETpacket_seq_count(tc_ptr));
-                            return tm_ptr;                            
+                            ACK_L234(tm_ptr_short,0xA0,GETpacket_seq_count(tc_ptr));
+                            return tm_ptr_short;                            
                         }
                         else if(GETpid(tc_ptr)==0x16)
                         {                            
@@ -702,8 +810,8 @@
                             
                             SW_ON_V_A_EN();
 
-                            ACK_L234(tm_pointer,0xA0,GETpacket_seq_count(tc_ptr));
-                            return tm_ptr;                        
+                            ACK_L234(tm_ptr_short,0xA0,GETpacket_seq_count(tc_ptr));
+                            return tm_ptr_short;                        
                         }
                         else if(GETpid(tc_ptr)==0x26)
                         {                        
@@ -711,8 +819,8 @@
                             
                             SW_OFF_V_A_EN();
 
-                            ACK_L234(tm_pointer,0xA0,GETpacket_seq_count(tc_ptr));
-                            return tm_ptr;                                                    
+                            ACK_L234(tm_ptr_short,0xA0,GETpacket_seq_count(tc_ptr));
+                            return tm_ptr_short;                                                    
                         }
                         else if(GETpid(tc_ptr)==0x31)
                         {                            
@@ -720,8 +828,8 @@
                             
                             RST_SD();
 
-                            ACK_L234(tm_pointer,0xA0,GETpacket_seq_count(tc_ptr));
-                            return tm_ptr;                                                        
+                            ACK_L234(tm_ptr_short,0xA0,GETpacket_seq_count(tc_ptr));
+                            return tm_ptr_short;                                                        
                         }
                         else if(GETpid(tc_ptr)==0x33)
                         {                            
@@ -729,8 +837,8 @@
                             
                             RST_BAE();
 
-                            ACK_L234(tm_pointer,0xA0,GETpacket_seq_count(tc_ptr));
-                            return tm_ptr;                            
+                            ACK_L234(tm_ptr_short,0xA0,GETpacket_seq_count(tc_ptr));
+                            return tm_ptr_short;                            
                         }
                         else if(GETpid(tc_ptr)==0x34)
                         {                            
@@ -738,25 +846,24 @@
                             
                             RST_PL_BEE();
 
-                            ACK_L234(tm_pointer,0xA0,GETpacket_seq_count(tc_ptr));
-                            return tm_ptr;                                                        
+                            ACK_L234(tm_ptr_short,0xA0,GETpacket_seq_count(tc_ptr));
+                            return tm_ptr_short;                                                        
                         }
                         else if(GETpid(tc_ptr)==0x38)
                         {
                             //gPC.printf()
                             
                             CDMS_INTERNAL_RESET();
-                            ACK_L234(tm_pointer,0xA0,GETpacket_seq_count(tc_ptr));
-                            return tm_ptr;
+                            ACK_L234(tm_ptr_short,0xA0,GETpacket_seq_count(tc_ptr));
                         }
                         else if(GETpid(tc_ptr)==0x40)
                         {                         
                             //gPC.printf("RESET_HK_COUNTER\r\n"); // call PWR_SWCH_ON function
                             
-                            STANDBY_PRCS();         //////// Need to Complete this function
+                            STANDBY_PRCS();
 
-                            ACK_L234(tm_pointer,0xA0,GETpacket_seq_count(tc_ptr));
-                            return tm_ptr;                                                    
+                            ACK_L234(tm_ptr_short,0xA0,GETpacket_seq_count(tc_ptr));
+                            return tm_ptr_short;                                                    
                         }
                         else if(GETpid(tc_ptr)==0x41)
                         {                            
@@ -764,8 +871,8 @@
                             
                             RST_HK_COUNTER();
 
-                            ACK_L234(tm_pointer,0xA0,GETpacket_seq_count(tc_ptr));
-                            return tm_ptr;    
+                            ACK_L234(tm_ptr_short,0xA0,GETpacket_seq_count(tc_ptr));
+                            return tm_ptr_short;    
                         }
                         else if(GETpid(tc_ptr)==0xF1)
                         {          
@@ -774,7 +881,7 @@
                             uint32_t time_temp = FCTN_CDMS_RD_RTC();                        //RTC_RD_EROR has to incorporated
                             tm_pointer->TM_string[0] = 0x78;     
                             tm_pointer->TM_string[1] = GETpacket_seq_count(tc_ptr);                                    
-                            tm_pointer->TM_string[2] = 0xA0;    // ACK CODE
+                            tm_pointer->TM_string[2] = 0xA0;
                             tm_pointer->TM_string[3] = 0x00;
                             tm_pointer->TM_string[4] = (uint8_t)((time_temp & 0xFF000000)>>24);
                             tm_pointer->TM_string[5] = (uint8_t)((time_temp & 0x00FF0000)>>16);
@@ -787,14 +894,14 @@
                             crc16 = crc16_gen(tm_ptr->TM_string,132);
                             tm_pointer->TM_string[132] = (uint8_t)((crc16&0xFF00)>>8);
                             tm_pointer->TM_string[133] = (uint8_t)(crc16&0x00FF);
-                            tm_pointer->next_TM = NULL;                                                                     //incomplete
-                            return tm_ptr;
+                            tm_pointer->next_TM = NULL;                 
+                            return tm_ptr;                                                     //incomplete
                         }
                         else if(GETpid(tc_ptr)==0xF0)
                         {
                             uint8_t statusbits[64];
                             if( CDMS_RD_SD_HK(statusbits) != 0){
-                                ACK_L234(tm_pointer,0xC0,GETpacket_seq_count(tc_ptr));
+                                ACK_L234(tm_pointer,0xA0,GETpacket_seq_count(tc_ptr));
                                 return tm_ptr;
                             }
                             else
@@ -818,19 +925,25 @@
                                 tm_pointer->next_TM = NULL;                                                                     //incomplete
                                 return tm_ptr;
                             }
+                        }
+                        else if(GETpid(tc_ptr)==0xF1)
+                        {
+                            CDMS_CALIB_RTC((uint64_t)(tc_ptr->TC_string[4])<<32 + (uint64_t)(tc_ptr->TC_string[5])<<24 + (uint64_t)(tc_ptr->TC_string[5])<<16 + (uint64_t)(tc_ptr->TC_string[6])<<8  +(uint64_t)(tc_ptr->TC_string[7]));
+                            ACK_L234(tm_pointer,0xC0,GETpacket_seq_count(tc_ptr));
+                            return tm_ptr;
                         }                               
                         else 
                         {
                             gPC.printf("INVALID FID\r\n");
-                            ACK_L234(tm_pointer,0x02,GETpacket_seq_count(tc_ptr));  
-                            return tm_ptr;
+                            ACK_L234(tm_ptr_short,0x02,GETpacket_seq_count(tc_ptr));  
+                            return tm_ptr_short;
                         }
                     }
                     else 
                     {
                         gPC.printf("INVALID SERVICE SUBTYPE\r\n");
-                        ACK_L234(tm_pointer,0x02,GETpacket_seq_count(tc_ptr));  
-                        return tm_ptr;
+                        ACK_L234(tm_ptr_short,0x02,GETpacket_seq_count(tc_ptr));  
+                        return tm_ptr_short;
                     }                                    
                 }
                 case 0x70:
@@ -930,15 +1043,15 @@
                     else
                     {
                         gPC.printf("INVALID SERVICE SUBTYPE\r\n");
-                        ACK_L234(tm_pointer,0x02,GETpacket_seq_count(tc_ptr));  
-                        return tm_ptr;
+                        ACK_L234(tm_ptr_short,0x02,GETpacket_seq_count(tc_ptr));  
+                        return tm_ptr_short;
                     }
                 }
                 default:
                 {
                     gPC.printf("ILLEGAL TC"); 
-                    ACK_L234(tm_pointer,0x02,GETpacket_seq_count(tc_ptr));
-                    return tm_ptr;                    
+                    ACK_L234(tm_ptr_short,0x02,GETpacket_seq_count(tc_ptr));
+                    return tm_ptr_short;                    
                 }
             }
         }
@@ -954,8 +1067,8 @@
                 
             if(y==1)                                                            
             {                                                                               
-                ACK_L234(tm_pointer,0x03,GETpacket_seq_count(tc_ptr));
-                return tm_ptr;
+                ACK_L234(tm_ptr_short,0x03,GETpacket_seq_count(tc_ptr));
+                return tm_ptr_short;
                 break;
             }                                  
             else if(y==0)
@@ -980,25 +1093,25 @@
                     }
                     else if(y==1)
                     {
-                        ACK_L234(tm_pointer,0x85,GETpacket_seq_count(tc_ptr));                
+                        ACK_L234(tm_ptr_short,0x85,GETpacket_seq_count(tc_ptr));                
                         //gPC.printf("\n\rPTE->PDIR = 0x%08X",PTE->PDIR);
-                        return tm_ptr;
+                        return tm_ptr_short;
                         break;  
                     }
                 }
                 else if(PL_I2C_Intr == 0)                                       //name to be changed later
                 {
                     gPC.printf("PL_I2C_Intr is not high\r\n");                    
-                    ACK_L234(tm_pointer,0x84,GETpacket_seq_count(tc_ptr));
-                    return tm_ptr;
+                    ACK_L234(tm_ptr_short,0x84,GETpacket_seq_count(tc_ptr));
+                    return tm_ptr_short;
                 }
             }                             
         }
         default:    //invalid TC
         {
             gPC.printf("INVALID TC\r\n");                 
-            ACK_L234(tm_pointer,0x02,GETpacket_seq_count(tc_ptr));
-            return tm_ptr;
+            ACK_L234(tm_ptr_short,0x02,GETpacket_seq_count(tc_ptr));
+            return tm_ptr_short;
         }
     }
     return;