FM

Dependencies:   SimpleDMA eeprom mbed-rtos mbed FreescaleIAP

Fork of CDMS_CODE by shubham c

Files at this revision

API Documentation at this revision

Comitter:
chaithanyarss
Date:
Sun Jan 22 03:12:16 2017 +0000
Parent:
344:1675dbde0bae
Commit message:
EERPOM completely added

Changed in this revision

COM_MNG_TMTC.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
E2PROM.h Show annotated file Show diff for this revision Revisions of this file
FMS_all.h Show annotated file Show diff for this revision Revisions of this file
FreescaleIAP.lib Show diff for this revision Revisions of this file
RAM.h Show diff for this revision Revisions of this file
TEST_PL.h Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/COM_MNG_TMTC.h	Sun Jan 08 14:52:55 2017 +0000
+++ b/COM_MNG_TMTC.h	Sun Jan 22 03:12:16 2017 +0000
@@ -480,14 +480,12 @@
                                     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];
+                                    flasharray_thres[z] = scp_thresfhold_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);
+                                
+                                THRES_WRITE_TO EEPROM(mid, (int8_t*)flasharray_thres);
                                 
                                 Base_tm *tm_ptr_short = new Short_tm;
                                 ACK_L234(tm_ptr_short,0xA0,GETpacket_seq_count(tc_ptr));
@@ -497,12 +495,11 @@
                             {
                                 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);
+                                    
+                                THRES_WRITE_TO EEPROM(mid, (int8_t*)flasharray_thres);
+                                
                                 Base_tm *tm_ptr_short = new Short_tm;
                                 ACK_L234(tm_ptr_short,0xA0,GETpacket_seq_count(tc_ptr));
                                 return tm_ptr_short;
@@ -511,12 +508,11 @@
                             {
                                 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);
+                                
+                                THRES_WRITE_TO EEPROM(mid, (int8_t*)flasharray_thres);
+                                
                                 Base_tm *tm_ptr_short = new Short_tm;
                                 ACK_L234(tm_ptr_short,0xA0,GETpacket_seq_count(tc_ptr));
                                 return tm_ptr_short;
@@ -525,12 +521,11 @@
                             {
                                 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);
+                                
+                                THRES_WRITE_TO EEPROM(mid, (int8_t*)flasharray_thres);
+                                
                                 Base_tm *tm_ptr_short = new Short_tm;
                                 ACK_L234(tm_ptr_short,0xA0,GETpacket_seq_count(tc_ptr));
                                 return tm_ptr_short;
@@ -546,8 +541,6 @@
                                 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];
@@ -557,8 +550,9 @@
                                 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);
+                                
+                                THRES_WRITE_TO EEPROM(mid, (int8_t*)flasharray_thres);
+                                
                                 Base_tm *tm_ptr_short = new Short_tm;
                                 ACK_L234(tm_ptr_short,0xA0,GETpacket_seq_count(tc_ptr));
                                 return tm_ptr_short;
@@ -569,14 +563,13 @@
                                     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);
+                                
+                                THRES_WRITE_TO EEPROM(mid, (int8_t*)flasharray_thres);
+                                
                                 Base_tm *tm_ptr_short = new Short_tm;
                                 ACK_L234(tm_ptr_short,0xA0,GETpacket_seq_count(tc_ptr));
                                 return tm_ptr_short;
@@ -585,12 +578,11 @@
                             {
                                 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);
+                                
+                                THRES_WRITE_TO EEPROM(mid, (int8_t*)flasharray_thres);
+                                
                                 Base_tm *tm_ptr_short = new Short_tm;
                                 ACK_L234(tm_ptr_short,0xA0,GETpacket_seq_count(tc_ptr));
                                 return tm_ptr_short;
@@ -599,12 +591,11 @@
                             {
                                 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);
+                                
+                                THRES_WRITE_TO EEPROM(mid, (int8_t*)flasharray_thres);
+                                
                                 Base_tm *tm_ptr_short = new Short_tm;
                                 ACK_L234(tm_ptr_short,0xA0,GETpacket_seq_count(tc_ptr));
                                 return tm_ptr_short;
@@ -613,12 +604,11 @@
                             {
                                 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);
+                                    
+                                THRES_WRITE_TO EEPROM(mid, (int8_t*)flasharray_thres);
+                                
                                 Base_tm *tm_ptr_short = new Short_tm;
                                 ACK_L234(tm_ptr_short,0xA0,GETpacket_seq_count(tc_ptr));
                                 return tm_ptr_short;
--- a/DefinitionsAndGlobals.h	Sun Jan 08 14:52:55 2017 +0000
+++ b/DefinitionsAndGlobals.h	Sun Jan 22 03:12:16 2017 +0000
@@ -368,7 +368,7 @@
 uint8_t PL_EPS_LATCH_SW_EN;
 uint8_t RTC_INIT_STATUS;
 uint8_t CDMS_RTC_DISABLE;
-uint16_t CDMS_RESET_COUNTER;
+uint16_t CDMS_RESET_COUNTER = 99;
 uint32_t TIME_LATEST_CDSMS_RESET;
 uint16_t COM_TC_BYTES_LIMIT;
 uint8_t COM_RX_CURRENT_MAX;
@@ -377,7 +377,7 @@
 uint8_t COM_PA_RECOVERY_TIMEOUT;
 uint8_t COM_SESSION_TIMEOUT = 60;  //confirm with Anirudh 
 uint8_t COM_RSSI_MIN;
-uint16_t SD_LIB_BLK_CURRENT;
+uint32_t SD_LIB_BLK_CURRENT;
 
 // Ambigouties
 uint8_t EN_RTC = 0x01;
--- a/E2PROM.h	Sun Jan 08 14:52:55 2017 +0000
+++ b/E2PROM.h	Sun Jan 22 03:12:16 2017 +0000
@@ -6,33 +6,35 @@
 #define check 10
 
 EEPROM e2prom(ee_sda, ee_scl, 0, EEPROM::T24C512);
-int32_t INITIAL_EEPROM[32] = {1,1,1,1,1,0,0,0,0,35000,0xff,300,85,20,20,3,80000,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
+int32_t INITIAL_EEPROM[32] = {1,1,1,1,1,0,0,0,0,35001,0xff,300,85,20,20,3,80000,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
 
 void WRITE_TO_EEPROM(uint32_t address, int32_t data_block)
 {
-    e2prom.write(address+10,data_block);
+    e2prom.write(address*4+10,data_block);
 }
 
-int32_t READ_FROM_EERPOM(uint32_t address)
+uint32_t READ_FROM_EERPOM(uint32_t address)
 {
     int32_t data;
-    e2prom.read(address+10, data);
-    return data;
+    e2prom.read(address*4+10, data);
+    return (uint32_t)data;
 }
 
 void INIT_EEPROM()
 {
     int32_t test_buffer;
     e2prom.ready();
-    e2prom.read(9,test_buffer);
+    e2prom.read(2,test_buffer);
     if(test_buffer == 0)
     {
         for(int i=0;i<32;i++)
             WRITE_TO_EEPROM( i, INITIAL_EEPROM[i]);
         
-        e2prom.write(9,1);
+        e2prom.write(2,1);
+        gPC.printf("starting flash");
     }
     
+    gPC.printf("Reading intial parametrs from flash\n");
     EPS_V_A_EN_STATUS         = READ_FROM_EERPOM(0);
     BAE_STATUS                = READ_FROM_EERPOM(1);
     SD_STATUS                 = READ_FROM_EERPOM(2);
@@ -52,4 +54,11 @@
     SD_LIB_BLK_CURRENT        = READ_FROM_EERPOM(16);
 }
 
+void THRES_WRITE_TO EEPROM(uint16_t mid, int8_t*data)
+{
+    if(mid <11 & mid >1)
+    {
+        e2prom.write((mid-1)*128,data,128);
+    }    
+}
 #endif
\ No newline at end of file
--- a/FMS_all.h	Sun Jan 08 14:52:55 2017 +0000
+++ b/FMS_all.h	Sun Jan 22 03:12:16 2017 +0000
@@ -338,7 +338,8 @@
 
 void CDMS_RESET()
 {
-    NVIC_SystemReset();    
+    NVIC_SystemReset();
+      
 }
 
 /*
--- a/FreescaleIAP.lib	Sun Jan 08 14:52:55 2017 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,1 +0,0 @@
-http://mbed.org/users/Sissors/code/FreescaleIAP/#6749f7702fa5
--- a/RAM.h	Sun Jan 08 14:52:55 2017 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,35 +0,0 @@
-/* Using malloc() to determine free memory.*/
- 
-#include <stdio.h>
-#include <stdlib.h>
-#define FREEMEM_CELL 100
-struct elem { /* Definition of a structure that is FREEMEM_CELL bytes  in size.) */
-    struct elem *next;
-    char dummy[FREEMEM_CELL-2];
-};
-int FreeMem(void) {
-    int counter;
-    struct elem *head, *current, *nextone;
-    current = head = (struct elem*) malloc(sizeof(struct elem));
-    if (head == NULL)
-        return 0;      /*No memory available.*/
-    counter = 0;
-   // __disable_irq();
-    do {
-        counter++;
-        current->next = (struct elem*) malloc(sizeof(struct elem));
-        current = current->next;
-    } while (current != NULL);
-    /* Now counter holds the number of type elem
-       structures we were able to allocate. We
-       must free them all before returning. */
-    current = head;
-    do {
-        nextone = current->next;
-        free(current);
-        current = nextone;
-    } while (nextone != NULL);
-   // __enable_irq();
- 
-    return counter*FREEMEM_CELL;
-}
\ No newline at end of file
--- a/TEST_PL.h	Sun Jan 08 14:52:55 2017 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,575 +0,0 @@
-//F11 to exit full screen mode
-/*---------------------------------------------------------------------------
-                            Testing PL_MAIN
-----------------------------------------------------------------------------*/
-
-
-/* Testing as per the flow chart  */
-/* columns of the array schedule1[][] correspond to Year,Month,Day,Hours,Minutes,Seconds,SID and EXEC_STATUS in integer formats*/
-Base_tm* FCTN_CDMS_RLY_TMTC(Base_tc *tc_ptr);
-
-extern uint8_t schedule1[32][8]=
-                        {
-                            {0,1,1,0,0,15,3,3},
-                            {0,1,1,0,0,45,2,3},
-                            {0,1,1,0,1,0,1,3},
-                            {0,1,1,0,1,25,0,3},     
-                            {0,1,1,0,1,50,3,3},
-                            {0,1,1,0,2,10,2,3},
-                            {0,1,1,0,1,40,2,3},
-                            {0,1,1,0,1,10,2,3},
-                            {0,1,1,0,3,40,2,0},
-                            {0,1,1,0,4,10,2,3},
-                            
-                            {0,1,1,0,4,40,0,1},
-                            {0,1,1,0,5,10,3,3},
-                            {0,1,1,0,5,40,3,3},
-                            {0,1,1,0,6,10,2,3},
-                            {0,1,1,0,6,40,1,0},
-                            {0,1,1,0,7,10,2,3},
-                            {0,1,1,0,7,40,3,3},
-                            {0,1,1,0,8,10,0,3},
-                            {0,1,1,0,8,40,1,3},
-                            {0,1,1,0,9,10,1,2},                           
-
-                            {0,1,1,0,9,40,2,3},
-                            {0,1,1,0,10,10,3,1},
-                            {0,1,1,0,10,40,3,3},                         
-                            {0,1,1,0,11,10,2,1},
-                            {0,0,0,0,11,40,0,0},
-                            {0,1,1,0,12,10,0,0},
-                            {0,1,1,0,12,40,0,0},
-                            {0,1,1,0,13, 0,0,0},
-                            {0,1,1,0,0, 0,0,0},
-                            {0,1,1,0,0, 0,0,0},
-
-                            {0,1,1,0,0, 0,0,0},
-                            {0,1,1,0,0, 0,0,0},
-                        };
-
-void convert(Base_tc* test_tc)
-{    
-    for(uint8_t k=3;k<=127;k+=4)
-    {
-        /*-----------1st byte of a block----------*/
-        test_tc->TC_string[k] &= 0x00;
-        //setting Year (2 bits)
-        //test_tc->TC_string[k] &= (~0xC0);
-        test_tc->TC_string[k] |= ((schedule1[(k-3)/4][0] & 0x03)<<6);
-
-        //setting Month (4 bits)
-        //test_tc->TC_string[k] &= (~0x3C);
-        test_tc->TC_string[k] |= ((schedule1[(k-3)/4][1] & 0x0F)<<2);
-
-        //setting first two bits(MSB) of Day
-        //test_tc->TC_string[k] &= (~0x03);
-        test_tc->TC_string[k] |= ((schedule1[(k-3)/4][2] & 0x18)>>3);
-        /*------------end of 1st byte-------------*/
-
-        /*-----------2nd byte of a block----------*/
-        test_tc->TC_string[k+1] &= 0x00000000;
-        //setting remaining 3 bits of Day
-        //test_tc->TC_string[k+1] &= (~0xE0);
-        test_tc->TC_string[k+1] |= ((schedule1[(k-3)/4][2] & 0x07)<<5);
-
-        //setting Hours (5 bits)
-        //test_tc->TC_string[k+1] &= (~0x1F);
-        test_tc->TC_string[k+1] |= ((schedule1[(k-3)/4][3] & 0x1F));
-        /*------------end of 2nd byte-------------*/
-
-        /*-----------3rd byte of a block----------*/
-        test_tc->TC_string[k+2] &= 0x00000000;
-        //setting Minutes (6 bits)
-        //test_tc->TC_string[k+2] &= (~0xFC);
-        test_tc->TC_string[k+2] |= ((schedule1[(k-3)/4][4] & 0x3F)<<2);
-
-        //setting first 2 bits(MSB) of Seconds
-        //test_tc->TC_string[k+2] &= (~0x03);
-        test_tc->TC_string[k+2] |= ((schedule1[(k-3)/4][5] & 0x30)>>4);
-        /*------------end of 3rd byte-------------*/        
-
-        /*-----------4th byte of a block----------*/
-        test_tc->TC_string[k+3] &= 0x00;
-        //setting remaining 4 bits of Seconds
-        //test_tc->TC_string[k+3] &= (~0xF0);
-        test_tc->TC_string[k+3] |= ((schedule1[(k-3)/4][5] & 0x0F)<<4);
-
-        //setting STATE_ID (2 bits)
-        //test_tc->TC_string[k+3] &= (~0x0C);
-        test_tc->TC_string[k+3] |= ((schedule1[(k-3)/4][6] & 0x03)<<2);
-
-        //setting EXEC_STATUS (2 bits)
-        //test_tc->TC_string[k+3] &= (~0x03);
-        test_tc->TC_string[k+3] |= ((schedule1[(k-3)/4][7] & 0x03));
-        /*------------end of 4th byte-------------*/                
-    }    
-}
-/*void test_schedule_1(Base_tm *test_tm_ptr)
-{
-    Base_tc *test_tc = new Long_tc;
-    test_tc->next_TC = NULL;
-    test_tc->TC_string[0] = 0x01;
-    test_tc->TC_string[1] = 0xB2;
-    test_tc->TC_string[2] = 0x71;
-    convert(test_tc);
-    test_tc->TC_string[131] = 0x00;
-    test_tc->TC_string[132] = 0x00;
-    uint16_t crc16 = crc16_gen(test_tc->TC_string,133);
-    test_tc->TC_string[133] = (uint8_t)(crc16 & 0xFF00)>>8;
-    test_tc->TC_string[134] = (uint8_t)(crc16 & 0x00FF);
-    test_tm_ptr =  FCTN_CDMS_RLY_TMTC(test_tc);
-}
-
-void test_schedule_2(Base_tm *test_tm_ptr)
-{
-    Base_tc *test_tc = new Long_tc;
-    test_tc->next_TC = NULL;
-    test_tc->TC_string[0] = 0x01;
-    test_tc->TC_string[1] = 0xB2;
-    test_tc->TC_string[2] = 0x72;
-    convert(test_tc);
-    test_tc->TC_string[131] = 0x00;
-    test_tc->TC_string[132] = 0x00;
-    uint16_t crc16 = crc16_gen(test_tc->TC_string,133);
-    test_tc->TC_string[133] = (uint8_t)(crc16 & 0xFF00)>>8;
-    test_tc->TC_string[134] = (uint8_t)(crc16 & 0x00FF);
-    test_tm_ptr =  FCTN_CDMS_RLY_TMTC(test_tc);
-}
-
-void test_schedule_3(Base_tm *test_tm_ptr)
-{
-    Base_tc *test_tc = new Long_tc;
-    test_tc->next_TC = NULL;
-    test_tc->TC_string[0] = 0x01;
-    test_tc->TC_string[1] = 0xB2;
-    test_tc->TC_string[2] = 0x73;
-    convert(test_tc);
-    test_tc->TC_string[131] = 0x00;
-    test_tc->TC_string[132] = 0x00;
-    uint16_t crc16 = crc16_gen(test_tc->TC_string,133);
-    test_tc->TC_string[133] = (uint8_t)(crc16 & 0xFF00)>>8;
-    test_tc->TC_string[134] = (uint8_t)(crc16 & 0x00FF);
-    test_tm_ptr =  FCTN_CDMS_RLY_TMTC(test_tc);
-}
-
-void test_schedule_4(Base_tm *test_tm_ptr)
-{
-    Base_tc *test_tc = new Long_tc;
-    test_tc->next_TC = NULL;
-    test_tc->TC_string[0] = 0x01;
-    test_tc->TC_string[1] = 0xB2;
-    test_tc->TC_string[2] = 0x74;
-    convert(test_tc);
-    test_tc->TC_string[131] = 0x00;
-    test_tc->TC_string[132] = 0x00;
-    uint16_t crc16 = crc16_gen(test_tc->TC_string,133);
-    test_tc->TC_string[133] = (uint8_t)(crc16 & 0xFF00)>>8;
-    test_tc->TC_string[134] = (uint8_t)(crc16 & 0x00FF);
-    test_tm_ptr =  FCTN_CDMS_RLY_TMTC(test_tc);
-}
-
-void test_schedule_5(Base_tm *test_tm_ptr)
-{
-    Base_tc *test_tc = new Long_tc;
-    test_tc->next_TC = NULL;
-    test_tc->TC_string[0] = 0x01;
-    test_tc->TC_string[1] = 0xB2;
-    test_tc->TC_string[2] = 0x75;
-    convert(test_tc);
-    test_tc->TC_string[131] = 0x00;
-    test_tc->TC_string[132] = 0x00;
-    uint16_t crc16 = crc16_gen(test_tc->TC_string,133);
-    test_tc->TC_string[133] = (uint8_t)(crc16 & 0xFF00)>>8;
-    test_tc->TC_string[134] = (uint8_t)(crc16 & 0x00FF);
-    test_tm_ptr =  FCTN_CDMS_RLY_TMTC(test_tc);
-}
-
-void test_schedule_6(Base_tm *test_tm_ptr)
-{
-    Base_tc *test_tc = new Long_tc;
-    test_tc->next_TC = NULL;
-    test_tc->TC_string[0] = 0x01;
-    test_tc->TC_string[1] = 0xB2;
-    test_tc->TC_string[2] = 0x76;
-    convert(test_tc);
-    test_tc->TC_string[131] = 0x00;
-    test_tc->TC_string[132] = 0x00;
-    uint16_t crc16 = crc16_gen(test_tc->TC_string,133);
-    test_tc->TC_string[133] = (uint8_t)(crc16 & 0xFF00)>>8;
-    test_tc->TC_string[134] = (uint8_t)(crc16 & 0x00FF);
-    test_tm_ptr =  FCTN_CDMS_RLY_TMTC(test_tc);
-}
-
-void test_schedule_F(Base_tm *test_tm_ptr)
-{
-    Base_tc *test_tc = new Long_tc;
-    test_tc->next_TC = NULL;
-    test_tc->TC_string[0] = 0x01;
-    test_tc->TC_string[1] = 0xB2;
-    test_tc->TC_string[2] = 0x7F;
-    convert(test_tc);
-    test_tc->TC_string[131] = 0x00;
-    test_tc->TC_string[132] = 0x00;
-    uint16_t crc16 = crc16_gen(test_tc->TC_string,133);
-    test_tc->TC_string[133] = (uint8_t)(crc16 & 0xFF00)>>8;
-    test_tc->TC_string[134] = (uint8_t)(crc16 & 0x00FF);
-    test_tm_ptr =  FCTN_CDMS_RLY_TMTC(test_tc);
-}*/
-#define test_schedule_1(test_tm_ptr) {\
-    Base_tc *test_tc = NULL;\
-    if(!(test_tc  = new Long_tc))\
-    {\
-       gPC.printf("\n\rError: out of memory");\
-       return;\
-    }\
-    test_tc->next_TC = NULL;\
-    test_tc->TC_string[0] = 0x01;\
-    test_tc->TC_string[1] = 0xB2;\
-    test_tc->TC_string[2] = 0x71;\
-    convert(test_tc);\
-    test_tc->TC_string[131] = 0x00;\
-    test_tc->TC_string[132] = 0x00;\
-    uint16_t crc16 = crc16_gen(test_tc->TC_string,133);\
-    test_tc->TC_string[133] = (uint8_t)(crc16 & 0xFF00)>>8;\
-    test_tc->TC_string[134] = (uint8_t)(crc16 & 0x00FF);\
-    test_tm_ptr =  FCTN_CDMS_RLY_TMTC(test_tc);\
-    delete test_tc;\
-    Base_tm *temp;\
-    temp = test_tm_ptr;\
-    while(test_tm_ptr!=NULL)\
-    {\
-        temp = temp->next_TM;\
-        delete test_tm_ptr;\
-        test_tm_ptr = temp;\
-    }\
-}
-#define test_schedule_2(test_tm_ptr) {\
-    Base_tc *test_tc = new Long_tc;\
-    test_tc->next_TC = NULL;\
-    test_tc->TC_string[0] = 0x01;\
-    test_tc->TC_string[1] = 0xB2;\
-    test_tc->TC_string[2] = 0x72;\
-    convert(test_tc);\
-    test_tc->TC_string[131] = 0x00;\
-    test_tc->TC_string[132] = 0x00;\
-    uint16_t crc16 = crc16_gen(test_tc->TC_string,133);\
-    test_tc->TC_string[133] = (uint8_t)(crc16 & 0xFF00)>>8;\
-    test_tc->TC_string[134] = (uint8_t)(crc16 & 0x00FF);\
-    test_tm_ptr =  FCTN_CDMS_RLY_TMTC(test_tc);\
-    delete test_tc;\
-    Base_tm *temp;\
-    temp = test_tm_ptr;\
-    while(test_tm_ptr!=NULL)\
-    {\
-        temp = temp->next_TM;\
-        delete test_tm_ptr;\
-        test_tm_ptr = temp;\
-    }\
-}
-#define test_schedule_3(test_tm_ptr) {\
-    Base_tc *test_tc = new Long_tc;\
-    test_tc->next_TC = NULL;\
-    test_tc->TC_string[0] = 0x01;\
-    test_tc->TC_string[1] = 0xB2;\
-    test_tc->TC_string[2] = 0x73;\
-    convert(test_tc);\
-    test_tc->TC_string[131] = 0x00;\
-    test_tc->TC_string[132] = 0x00;\
-    uint16_t crc16 = crc16_gen(test_tc->TC_string,133);\
-    test_tc->TC_string[133] = (uint8_t)(crc16 & 0xFF00)>>8;\
-    test_tc->TC_string[134] = (uint8_t)(crc16 & 0x00FF);\
-    test_tm_ptr =  FCTN_CDMS_RLY_TMTC(test_tc);\
-    delete test_tc;\
-    Base_tm *temp;\
-    temp = test_tm_ptr;\
-    while(test_tm_ptr!=NULL)\
-    {\
-        temp = temp->next_TM;\
-        delete test_tm_ptr;\
-        test_tm_ptr = temp;\
-    }\
-}
-#define test_schedule_4(test_tm_ptr) {\
-    Base_tc *test_tc = new Long_tc;\
-    test_tc->next_TC = NULL;\
-    test_tc->TC_string[0] = 0x01;\
-    test_tc->TC_string[1] = 0xB2;\
-    test_tc->TC_string[2] = 0x74;\
-    convert(test_tc);\
-    test_tc->TC_string[131] = 0x00;\
-    test_tc->TC_string[132] = 0x00;\
-    uint16_t crc16 = crc16_gen(test_tc->TC_string,133);\
-    test_tc->TC_string[133] = (uint8_t)(crc16 & 0xFF00)>>8;\
-    test_tc->TC_string[134] = (uint8_t)(crc16 & 0x00FF);\
-    test_tm_ptr =  FCTN_CDMS_RLY_TMTC(test_tc);\
-    delete test_tc;\
-    Base_tm *temp;\
-    temp = test_tm_ptr;\
-    while(test_tm_ptr!=NULL)\
-    {\
-        temp = temp->next_TM;\
-        delete test_tm_ptr;\
-        test_tm_ptr = temp;\
-    }\
-}
-#define test_schedule_5(test_tm_ptr) {\
-    Base_tc *test_tc = new Long_tc;\
-    test_tc->next_TC = NULL;\
-    test_tc->TC_string[0] = 0x01;\
-    test_tc->TC_string[1] = 0xB2;\
-    test_tc->TC_string[2] = 0x75;\
-    convert(test_tc);\
-    test_tc->TC_string[131] = 0x00;\
-    test_tc->TC_string[132] = 0x00;\
-    uint16_t crc16 = crc16_gen(test_tc->TC_string,133);\
-    test_tc->TC_string[133] = (uint8_t)(crc16 & 0xFF00)>>8;\
-    test_tc->TC_string[134] = (uint8_t)(crc16 & 0x00FF);\
-    test_tm_ptr =  FCTN_CDMS_RLY_TMTC(test_tc);\
-    delete test_tc;\
-    Base_tm *temp;\
-    temp = test_tm_ptr;\
-    while(test_tm_ptr!=NULL)\
-    {\
-        temp = temp->next_TM;\
-        delete test_tm_ptr;\
-        test_tm_ptr = temp;\
-    }\
-}
-#define test_schedule_6(test_tm_ptr) {\
-    Base_tc *test_tc = new Long_tc;\
-    test_tc->next_TC = NULL;\
-    test_tc->TC_string[0] = 0x01;\
-    test_tc->TC_string[1] = 0xB2;\
-    test_tc->TC_string[2] = 0x76;\
-    convert(test_tc);\
-    test_tc->TC_string[131] = 0x00;\
-    test_tc->TC_string[132] = 0x00;\
-    uint16_t crc16 = crc16_gen(test_tc->TC_string,133);\
-    test_tc->TC_string[133] = (uint8_t)(crc16 & 0xFF00)>>8;\
-    test_tc->TC_string[134] = (uint8_t)(crc16 & 0x00FF);\
-    test_tm_ptr =  FCTN_CDMS_RLY_TMTC(test_tc);\
-    delete test_tc;\
-    Base_tm *temp;\
-    temp = test_tm_ptr;\
-    while(test_tm_ptr!=NULL)\
-    {\
-        temp = temp->next_TM;\
-        delete test_tm_ptr;\
-        test_tm_ptr = temp;\
-    }\
-}
-#define test_schedule_F(test_tm_ptr) {\
-    Base_tc *test_tc = NULL;\
-    if(!(test_tc  = new Long_tc))\
-    {\
-       gPC.printf("\n\rError: out of memory");\
-       return;\
-    }\
-    test_tc->next_TC = NULL;\
-    test_tc->TC_string[0] = 0x01;\
-    test_tc->TC_string[1] = 0xB2;\
-    test_tc->TC_string[2] = 0x7F;\
-    for(uint8_t i=3;i<133;i++)\
-    {\
-        test_tc->TC_string[i] = 0;\
-    }\
-    uint16_t crc16 = crc16_gen(test_tc->TC_string,133);\
-    test_tc->TC_string[133] = (uint8_t)(crc16 & 0xFF00)>>8;\
-    test_tc->TC_string[134] = (uint8_t)(crc16 & 0x00FF);\
-    test_tm_ptr =  FCTN_CDMS_RLY_TMTC(test_tc);\
-    delete test_tc;\
-}
-void send_verify_0xF(Base_tm* test_tm_ptr)
-{
-    uint32_t temp_blk[4] = {0};
-    uint8_t j=0,tm_data_err_count=0;
-    Base_tm* temp_ptr;
-    test_schedule_F(test_tm_ptr);
-    gPC.printf("\n\r----------------------------------------------------------------------------------");
-    gPC.printf("\n\rTC_Schedule_Report(0xF):\n");
-    temp_ptr=test_tm_ptr;
-    while(temp_ptr!=NULL)
-    {
-        /*gPC.printf("\n\rTM[0] = %02X",temp_ptr->TM_string[0]);
-        gPC.printf("\tTM[1] = %02X",temp_ptr->TM_string[1]);
-        gPC.printf("\tTM[2] = %02X",temp_ptr->TM_string[2]);
-        gPC.printf("\tTM[3] = %02X",temp_ptr->TM_string[3]);*/
-        for(uint8_t i=0;i<=112;i+=16)
-        {
-            temp_blk[0] &= 0x00000000;
-            temp_blk[0] |= (((uint32_t)(temp_ptr->TM_string[i+4]))&0x000000FF)<<24;
-            temp_blk[0] |= (((uint32_t)(temp_ptr->TM_string[i+5]))&0x000000FF)<<16;
-            temp_blk[0] |= (((uint32_t)(temp_ptr->TM_string[i+6]))&0x000000FF)<<8;
-            temp_blk[0] |= (((uint32_t)(temp_ptr->TM_string[i+7]))&0x000000FF);
-
-            temp_blk[1] &= 0x00000000;
-            temp_blk[1] |= (((uint32_t)(temp_ptr->TM_string[i+8]))&0x000000FF)<<24;
-            temp_blk[1] |= (((uint32_t)(temp_ptr->TM_string[i+9]))&0x000000FF)<<16;
-            temp_blk[1] |= (((uint32_t)(temp_ptr->TM_string[i+10]))&0x000000FF)<<8;
-            temp_blk[1] |= (((uint32_t)(temp_ptr->TM_string[i+11]))&0x000000FF);
-
-            temp_blk[2] &= 0x00000000;
-            temp_blk[2] |= (((uint32_t)(temp_ptr->TM_string[i+12]))&0x000000FF)<<24;
-            temp_blk[2] |= (((uint32_t)(temp_ptr->TM_string[i+13]))&0x000000FF)<<16;
-            temp_blk[2] |= (((uint32_t)(temp_ptr->TM_string[i+14]))&0x000000FF)<<8;
-            temp_blk[2] |= (((uint32_t)(temp_ptr->TM_string[i+15]))&0x000000FF);
-            
-            temp_blk[3] &= 0x00000000;
-            temp_blk[3] |= (((uint32_t)(temp_ptr->TM_string[i+16]))&0x000000FF)<<24;
-            temp_blk[3] |= (((uint32_t)(temp_ptr->TM_string[i+17]))&0x000000FF)<<16;
-            temp_blk[3] |= (((uint32_t)(temp_ptr->TM_string[i+18]))&0x000000FF)<<8;
-            temp_blk[3] |= (((uint32_t)(temp_ptr->TM_string[i+19]))&0x000000FF);
-
-            if(temp_blk[0]!=pl_block[(i/4)+j])
-                tm_data_err_count++;
-            if(temp_blk[1]!=pl_block[(i/4)+j+1])
-                tm_data_err_count++;
-            if(temp_blk[2]!=pl_block[(i/4)+j+2])
-                tm_data_err_count++;
-            if(temp_blk[3]!=pl_block[(i/4)+j+3])
-                tm_data_err_count++;
-            //gPC.printf("\n\r%03d-0x%08X\t%03d-0x%08X",(i/4)+j,temp_blk[0],(i/4)+1+j,temp_blk[1]);
-            //gPC.printf("\t%03d-0x%08X\t%03d-0x%08X\n",(i/4)+2+j,temp_blk[2],(i/4)+3+j,temp_blk[3]);             
-        }
-        j+=32;
-        //gPC.printf("\n");
-        temp_ptr = temp_ptr->next_TM;
-    }
-    if(tm_data_err_count!=0)
-    {
-        gPC.printf("\n\rTM Data(0xF) not matching pl_block!!!");
-        gPC.printf("\n\rNumber of mismatches = %d",tm_data_err_count);
-    }
-    else if(tm_data_err_count==0)
-    {
-        gPC.printf("\n\rNo errors in TM Data(0xF)");
-    }
-    gPC.printf("\n\r----------------------------------------------------------------------------------");
-    Base_tm *temp;\
-    temp = test_tm_ptr;\
-    while(test_tm_ptr!=NULL)\
-    {\
-        temp = temp->next_TM;\
-        delete test_tm_ptr;\
-        test_tm_ptr = temp;\
-    }\
-}
-void verify_extracted(uint8_t c)
-{
-    uint8_t wrong_extracted=0;
-    uint8_t temp_extracted[8] = {0};
-    for(uint8_t z=(32*(c-1));z<(32*c);z++)
-    {        
-        temp_extracted[0] = (uint8_t)((pl_block[z]&0xC0000000)>>30);
-        temp_extracted[1] = (uint8_t)((pl_block[z]&0x3C000000)>>26);
-        temp_extracted[2] = (uint8_t)((pl_block[z]&0x03E00000)>>21);
-        temp_extracted[3] = (uint8_t)((pl_block[z]&0x001F0000)>>16);
-        temp_extracted[4] = (uint8_t)((pl_block[z]&0x0000FC00)>>10);
-        temp_extracted[5] = (uint8_t)((pl_block[z]&0x000003F0)>>4);
-        temp_extracted[6] = (uint8_t)((pl_block[z]&0x0000000C)>>2);
-        temp_extracted[7] = (uint8_t)((pl_block[z]&0x00000003));
-        
-        for(uint8_t y=0;y<8;y++)
-        {
-            if(temp_extracted[y]!=schedule1[z-(32*(c-1))][y])
-                wrong_extracted++;
-        }
-    }
-    if(wrong_extracted!=0)
-    {
-        gPC.printf("\n\rExtracted values do not match input values!!!");
-        gPC.printf("\n\rNumber of wrong extracted values = %d",wrong_extracted);
-        wrong_extracted = 0;
-    }
-    else if(wrong_extracted==0)
-        gPC.printf("\n\rExtracted values are correct(0x%d)",c);        
-}
-void test_pl_main()
-{
-    uint32_t temp_pl_block[192] = {0};
-    uint8_t wrong_modify=0,z;
-    Base_tm* test_tm_ptr;    
-    for(z=0;z<192;z++)
-        pl_block[z] = 0xFFFFFFFF;
-   // testing 0xF
-    send_verify_0xF(test_tm_ptr);
-    for(z=0;z<192;z++)  
-        temp_pl_block[z] = pl_block[z];
-        
-    //testing TC = 0x1,0x2...0x6
-    int w =1;
-    for(uint8_t v=1;v<7;v++)
-    {        
-        switch(v)
-        {
-            case 1: test_schedule_1(test_tm_ptr);
-                    break;
-            case 2: test_schedule_2(test_tm_ptr);
-                    break;
-            case 3: test_schedule_3(test_tm_ptr);
-                    break;
-            case 4: test_schedule_4(test_tm_ptr);
-                    break;
-            case 5: test_schedule_5(test_tm_ptr);
-                    break;
-            case 6: test_schedule_6(test_tm_ptr);
-                    break;
-        }
-        //gPC.printf("\n\rIndex:%d",w);
-        if(v==1)
-        {
-            test_schedule_1(test_tm_ptr);
-        }
-        else if(v==2)
-        {
-            test_schedule_2(test_tm_ptr);
-        }
-        else if(v==3)
-        {
-            test_schedule_3(test_tm_ptr);
-        }
-        else if(v==4)        
-        {
-            test_schedule_4(test_tm_ptr);
-        }
-        else if(v==5)
-        {
-            test_schedule_5(test_tm_ptr);
-        }
-        else if(v==6)
-        {
-            test_schedule_6(test_tm_ptr);
-        }
-        for(z=0;z<192;z++)
-        {
-            if((z>=((v-1)*32)) && (z<=((v*32)-1)))
-                z++;
-            else
-            {
-                if(temp_pl_block[z]!=pl_block[z])
-                    wrong_modify++;
-            }
-        }
-        if(wrong_modify!=0)
-        {
-            gPC.printf("\n\rWrong values of pl_block modified by TC = 0x%d",v);
-            gPC.printf("\n\rNumber of wrong modifications = %d",wrong_modify);
-            wrong_modify = 0;
-        }
-        else if(wrong_modify==0)
-        {
-            gPC.printf("\n\rTC(0x%d) updated pl_block correctly",v);
-            for(uint8_t i=0;i<=188;i+=4)
-            {
-                //gPC.printf("\n\r%03d-0x%08X\t%03d-0x%08X",(i),pl_block[i],(i)+1,pl_block[(i)+1]);
-                //gPC.printf("\t%03d-0x%08X\t%03d-0x%08X\n",(i)+2,pl_block[(i)+2],(i)+3,pl_block[(i)+3]);
-            }
-        }
-        send_verify_0xF(test_tm_ptr);
-        verify_extracted(v);
-        for(z=0;z<192;z++)
-            temp_pl_block[z] = pl_block[z];
-        wait(1);
-    }
-    gPC.printf("\n\rTesting TC_TM block processing complete");
-}
\ No newline at end of file
--- a/main.cpp	Sun Jan 08 14:52:55 2017 +0000
+++ b/main.cpp	Sun Jan 22 03:12:16 2017 +0000
@@ -17,7 +17,6 @@
 #include "eeprom.h"
 #include "E2PROM.h"
 #include "COM_SND_TM_functions.h"
-//#include "Flash.h"
 #include "cdms_rtc.h"
 #include "COM_SND_TM.h"
 #include "cdms_sd.h"
@@ -34,11 +33,10 @@
 #include "COM_POWER_ON_TX.h"
 #include "OBSRS.h"
 #include "ThreadsAndFunctions.h"
-#include "TEST_PL.h"
 
 int main()
 {    
-    
+    gPC.baud(1200);//changed for bypassing COM    
     //RELAY SWITCHING 
     
     
@@ -60,8 +58,6 @@
     gRX_CURRENT_DATA_NODE = gRX_HEAD_DATA_NODE;
     gRX_COUNT = 0;
     RX1M.attach(&rx_read, Serial::RxIrq);
-    
-   gPC.baud(1200);//changed for bypassing COM
    
     
     //Base_tm *tm_ptr = NULL;
@@ -84,13 +80,14 @@
     
     FCTN_CDMS_INIT_RTC();/* rtc initialization*/
     FCTN_CDMS_SD_INIT();/* sd card initialization*/
+    INIT_EEPROM();
     
     CDMS_RESET_COUNTER++;
-    WRITE_TO_EEPROM(17,(int32_t)CDMS_RESET_COUNTER);
-    //FCTN_CDMS_WR_FLASH(17,CDMS_RESET_COUNTER);
+    WRITE_TO_EEPROM(7,(int32_t)CDMS_RESET_COUNTER);
+
+    gPC.printf("reset counter: %d",CDMS_RESET_COUNTER);
     TIME_LATEST_CDSMS_RESET = FCTN_CDMS_RD_RTC() >> 7;
     WRITE_TO_EEPROM(8,(int32_t)TIME_LATEST_CDSMS_RESET);
-    //FCTN_CDMS_WR_FLASH(8,TIME_LATEST_CDSMS_RESET);
     
     uint8_t test[512];
     for(int i =0; i<512; i++)
@@ -106,21 +103,21 @@
     #if DEBUG
     gPC.puts("allocating threads\r\n");
     #endif
-    
+
     //DMA iobject decalaration
     gPAY_SPI = new dmaSPISlave(PAY_SPI_MOSI, PAY_SPI_MISO, PAY_SPI_CLK, PAY_SPI_CS);
     
     // COM_POWER_ON_TX();
-    
+    gPC.puts("point : 1\r\n");
     // COM_MNG_TMTC THREAD
     gCOM_MNG_TMTC_THREAD = new Thread(COM_MNG_TMTC_FUN);
     gCOM_MNG_TMTC_THREAD->set_priority(osPriorityRealtime);
-    
+    gPC.puts("point : 2\r\n");
     gHK_THREAD = new Thread(FCTN_CDMS_HK_MAIN);
     gHK_THREAD->set_priority(osPriorityAboveNormal);
-    
-    gSCIENCE_THREAD = new Thread(SCIENCE_FUN);
-    gSCIENCE_THREAD->set_priority(osPriorityHigh);
+    gPC.puts("point : 3\r\n");
+    //gSCIENCE_THREAD = new Thread(SCIENCE_FUN);
+    //gSCIENCE_THREAD->set_priority(osPriorityHigh);
     
     #if DEBUG
     gPC.puts("completed allocating threads\r\n");