sd 32 update

Dependencies:   FreescaleIAP mbed-rtos mbed

Fork of COM_MNG_TMTC_SIMPLE by Shreesha S

Revision:
5:ab276a17ca07
Parent:
4:104dd82c99b8
Child:
6:79d422d1ed42
--- a/COM_MNG_TMTC.h	Tue Dec 29 06:50:19 2015 +0000
+++ b/COM_MNG_TMTC.h	Wed Dec 30 06:36:38 2015 +0000
@@ -54,8 +54,8 @@
         length = TM_LONG_SIZE;\
     }\
     uint16_t crc = crc16_gen(tm_ptr->TM_string, length-2);\
-    if( (((crc & 0xFF00) >> 8) == tm_ptr->TM_string[length-2]) && ( (crc & 0x00FF) == tm_ptr->TM_string[length-1] ) ){\
-        if( tm_ptr != NULL ){\
+    if( tm_ptr != NULL ){\
+        if( (((crc & 0xFF00) >> 8) == tm_ptr->TM_string[length-2]) && ( (crc & 0x00FF) == tm_ptr->TM_string[length-1] ) ){\
             uint8_t temp8;\
             temp8 = tm_ptr->TM_string[TM_ACK_CODE_INDEX];\
             temp8 = temp8 & 0xE0;\
@@ -66,7 +66,7 @@
                 /*CHECK FOR NACK CODE: CRC FAIL NACK*/\
                 temp8 = tm_ptr->TM_string[TM_ACK_CODE_INDEX];\
                 temp8 = temp8 & 0x0F;\
-                if( temp8 == 0x1 ){\
+                if( temp8 == CRC_FAIL_NACK_CODE ){\
                     tm_ptr->TM_string[2] = tc_psc;\
                 }\
             }\
@@ -135,6 +135,7 @@
 */
 #define continueToExecute(returnHere) {\
     uint8_t tempReturn = 0x00;\
+    /*search for missing psc*/\
     for(uint8_t p = PSC_START_VALUE ; p < (gTOTAL_VALID_TC + PSC_START_VALUE) ; ++p){\
         bool flag = false;\
         Base_tc *node_ptr = gHEAD_NODE_TCL;\
@@ -152,17 +153,30 @@
             break;\
         }\
     }\
+    /*search for last packet bit*/\
+    tempReturn = tempReturn + 0x01;\
     Base_tc *tcp = gHEAD_NODE_TCL;\
     while(tcp != NULL){\
         if(GETpacket_seq_count(tcp) == (gTOTAL_VALID_TC + PSC_START_VALUE - 1)){\
-            if( ( (tcp->TC_string[1]) & 0x20 ) == 0x00 ){\
-                tempReturn = tempReturn + 0x01;\
+            if( ( (tcp->TC_string[1]) & 0x20 ) == 0x20 ){\
+                tempReturn = tempReturn - 0x01;\
             }\
             break;\
         }\
         tcp = tcp->next_TC;\
     }\
     returnHere = tempReturn;\
+    /*UPDATE gMASTER STATE*/\
+    if( (returnHere == 0x00) ){\
+        if( (gMASTER_STATE == TCL_STATE_INCOMPLETE) || (gMASTER_STATE == TCL_STATE_COMPLETED) ){\
+            gMASTER_STATE = TCL_STATE_COMPLETED;\
+        }\
+    }\
+    else{\
+        if( (gMASTER_STATE == TCL_STATE_INCOMPLETE) || (gMASTER_STATE == TCL_STATE_COMPLETED) ){\
+            gMASTER_STATE = TCL_STATE_INCOMPLETE;\
+        }\
+    }\
 }
 
 /*
@@ -211,13 +225,13 @@
             /*IF CRC PASS*/\
             if( (GETcrc_pass(current_TC) == 1) ){\
                 if(TC_count > 4){\
+                    /*PENDING: FILL TC_EXEC_CODE, APPEND CRC TO THE TM*/\
+                    put_crc_l1_ack( l1_ack );\
                     /*extend the TM linked list*/\
                     TC_count = 0;\
                     l1_ack->next_TM = new Short_tm;\
                     l1_ack = l1_ack->next_TM;\
                     fill_l1_ack(l1_ack);\
-                    /*PENDING: FILL TC_EXEC_CODE, APPEND CRC TO THE TM*/\
-                    put_crc_l1_ack( l1_ack );\
                 }\
                 /*PSC starts from 7th byte*/\
                 l1_ack->TM_string[6+TC_count] = GETpacket_seq_count(current_TC);\
@@ -267,30 +281,25 @@
             }\
             ++TC_count;\
         }\
-        put_crc_l1_ack(l1_ack);\
     }\
+    put_crc_l1_ack(l1_ack);\
 }
 
 /*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 */
 #define get_tc_list(tm_ptr, thePSC){\
-    uint8_t TM_PSC = 0x00;\
+    uint8_t TM_PSC = 0xFF;\
     uint8_t TC_PSC = thePSC;\
     int overflowCount = 0;\
     uint8_t TC_LIST_TAG = 0x00;\
     Base_tc *temp_tc = gHEAD_NODE_TCL;\
     bool first_time = true;\
-    Base_tm *theHeadTM = NULL;\
+    Base_tm *current_tm = NULL;\
     while( temp_tc != NULL ){\
         if( overflowCount < TCL_OVERFLOW_CONSTANT ){\
             TM_PSC = TM_PSC + 1;\
             /*Increment TM_PSC for every new TM pointer created*/\
             Base_tm *temp_tm = new Long_tm;\
             temp_tm->next_TM = NULL;\
-            if( first_time ){\
-                first_time = false;\
-                tm_ptr = temp_tm;\
-                theHeadTM = temp_tm;\
-            }\
             uint8_t temp8 = LONG_TM_CODE;\
             PUTshort_or_long_tm(temp_tm->fields, temp8);\
             temp8 = TMID_TCL;\
@@ -299,20 +308,20 @@
             /*Frame type(1) = 0; TMID = 0111; Spare = 000*/\
             temp_tm->TM_string[1] = TC_PSC;\
             temp_tm->TM_string[3] = TM_PSC;\
-            int index = 4, num_of_short_tc = 0;\
+            int indexCustom = 4, num_of_short_tc = 0;\
             while(temp_tc != NULL){\
                 if( overflowCount < TCL_OVERFLOW_CONSTANT ){\
                     if( GETshort_or_long_tc(temp_tc) == SHORT_TC_CODE ){\
                         for( int i = 0 ; i < TC_SHORT_SIZE ; ++i ){\
-                            temp_tm->TM_string[index + i] = temp_tc->TC_string[i];\
+                            temp_tm->TM_string[indexCustom + i] = temp_tc->TC_string[i];\
                         }\
-                        index = index + TC_SHORT_SIZE;\
+                        indexCustom = indexCustom + TC_SHORT_SIZE;\
                         ++overflowCount;\
                         /*INCREMENT STUFF*/\
                         temp_tc = temp_tc->next_TC;\
                         num_of_short_tc = num_of_short_tc + 1;\
                         if (temp_tc == NULL){\
-                            for (int i = index ; i < TM_LONG_SIZE-2 ; ++i){\
+                            for (int i = indexCustom ; i < TM_LONG_SIZE-2 ; ++i){\
                                 temp_tm->TM_string[i] = 0;\
                                 /*Fill remaining values with 0*/\
                             }\
@@ -321,7 +330,7 @@
                         }\
                         if( (GETshort_or_long_tc(temp_tc) == LONG_TC_CODE) || (num_of_short_tc == OBOSC_TCL_MAX_SHORT_SIZE) ){\
                             /*Next TC is long or memory is filled*/\
-                            for(int i = index; i < TM_LONG_SIZE-2 ; ++i){\
+                            for(int i = indexCustom; i < TM_LONG_SIZE-2 ; ++i){\
                                 temp_tm->TM_string[i] = 0;\
                                 /*Fill remaining values with 0*/\
                             }\
@@ -332,10 +341,10 @@
                     else if (TC_LIST_TAG == OBOSC_TCL_TAG_LONG_FIRST_HALF){\
                         /*Long TC, 2nd half*/\
                         for (int i = 0; i < OBOSC_LONG_TC_SECOND_HALF_SIZE ; ++i){\
-                            temp_tm->TM_string[index + i] = temp_tc->TC_string[OBOSC_LONG_TC_FIRST_HALF_SIZE + i];\
+                            temp_tm->TM_string[indexCustom + i] = temp_tc->TC_string[OBOSC_LONG_TC_FIRST_HALF_SIZE + i];\
                             /*Fill the TM with TC_values*/\
                         }\
-                        for (int i = OBOSC_LONG_TC_SECOND_HALF_SIZE + index ; i < TM_LONG_SIZE-2 ; ++i ){\
+                        for (int i = OBOSC_LONG_TC_SECOND_HALF_SIZE + indexCustom ; i < TM_LONG_SIZE-2 ; ++i ){\
                             temp_tm->TM_string[i] = 0;\
                             /*Fill remaining values with 0*/\
                         }\
@@ -347,11 +356,12 @@
                     else{\
                         /*Long TC, 1st half */\
                         for (int i = 0; i < OBOSC_LONG_TC_FIRST_HALF_SIZE; ++i){\
-                            temp_tm->TM_string[index + i] = temp_tc->TC_string[i];\
+                            /*gPC.printf("indexCustom = %d\r\n", indexCustom);*/\
+                            temp_tm->TM_string[indexCustom + i] = temp_tc->TC_string[i];\
                             /*Fill the TM with TC_values*/\
                         }\
-                        for (int i = OBOSC_LONG_TC_FIRST_HALF_SIZE + index ; i < TM_LONG_SIZE-2 ; ++i ){\
-                            temp_tm->TM_string[i] = 0;                  \
+                        for (int i = OBOSC_LONG_TC_FIRST_HALF_SIZE + indexCustom ; i < TM_LONG_SIZE-2 ; ++i ){\
+                            temp_tm->TM_string[i] = 0;\
                             /*Fill remaining values with 0*/\
                         }\
                         TC_LIST_TAG = OBOSC_TCL_TAG_LONG_FIRST_HALF;\
@@ -369,10 +379,15 @@
             temp_tm->TM_string[TM_LONG_SIZE-2] = (crc16 & 0xFF00) >> 8 ;\
             temp_tm->TM_string[TM_LONG_SIZE-1] = crc16 & 0x00FF;\
             /*Attach this new node to the TM linked list*/\
-            Base_tm *temp_tm_find = theHeadTM;\
-            while(temp_tm_find->next_TM != NULL)\
-                temp_tm_find = temp_tm_find->next_TM;\
-            temp_tm_find->next_TM = temp_tm;\
+            if( first_time ){\
+                first_time = false;\
+                tm_ptr = temp_tm;\
+                current_tm = temp_tm;\
+            }\
+            else{\
+                current_tm->next_TM = temp_tm;\
+                current_tm = current_tm->next_TM;\
+            }\
             /*Attach this new node at the end*/\
         }\
         else{\
@@ -396,10 +411,19 @@
     int modify_overflow = 0x00;\
     switch( service_subtype ){\
         case OBOSC_SUB_DISABLE:\
+            gPC.puts("target psc are ");\
+            for(int i = 3 ; i < 9 ; ++i){\
+                gPC.printf("%u ", tc_ptr->TC_string[i]);\
+            }\
+            gPC.puts("\r\n");\
+            /*gPC.puts("disable type obosc\r\n");*/\
             while( modify_this != NULL ){\
                 if( modify_overflow < TCL_OVERFLOW_CONSTANT ){\
+                    uint8_t modify_psc = GETpacket_seq_count(modify_this);\
+                    /*gPC.printf("mosify_psc = %u\r\n", modify_psc);*/\
                     for( int i = 3 ; i < 9 ; ++i ){\
-                        if( tc_ptr->TC_string[i] == GETpacket_seq_count(modify_this) ){\
+                        uint8_t target_psc = tc_ptr->TC_string[i];\
+                        if( (target_psc == modify_psc) && (target_psc != 0) ){\
                             uint16_t tempExec = TC_STATE_DISABLED;\
                             PUTexec_status( modify_this, tempExec );\
                             break;\
@@ -415,12 +439,16 @@
             }\
             break;\
         case OBOSC_SUB_RETRY:\
+            gPC.puts("retry type obosc\r\n");\
             while( modify_this != NULL ){\
                 if( modify_overflow < TCL_OVERFLOW_CONSTANT ){\
+                    uint8_t modify_psc = GETpacket_seq_count(modify_this);\
                     for( int i = 3 ; i < 9 ; ++i ){\
-                        if( tc_ptr->TC_string[i] == GETpacket_seq_count(modify_this) ){\
+                        uint8_t target_psc = tc_ptr->TC_string[i];\
+                        if( (target_psc == modify_psc) && (target_psc != 0) ){\
                             uint16_t tempExec = TC_STATE_MARKED_RETRY;\
                             PUTexec_status( modify_this, tempExec );\
+                            gPC.puts("reqquired tc found: disable\r\n");\
                             break;\
                         }\
                     }\
@@ -489,10 +517,11 @@
         reset_all;\
         /*PENDING: VERIFY reset_all, RESET CDMS*/\
     }\
-    else{\
+    else if( (service_subtype != OBOSC_SUB_DISABLE) && (service_subtype != OBOSC_SUB_RETRY) ){\
         /*CHANGE THE ACK CODE TO INVALID TC*/\
         ackl234new->TM_string[2] = 0xA2;\
     }\
+    gPC.puts("completed obosc\r\n");\
 }
 
 /*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 */
@@ -539,6 +568,7 @@
                         if( (current_exec_status == TC_STATE_SUCCESSFULLY_EXECUTED) || (current_exec_status == TC_STATE_DISABLED) )\
                             break;\
                         else if( (current_exec_status == TC_STATE_UNEXECUTED) || (current_exec_status == TC_STATE_MARKED_RETRY) ){\
+                            gPC.printf("It is obosc: %u\r\n", execute_psc);\
                             /*EXECUTION OF OBOSC TC*/\
                             /*WARNING: LARGE MEMORY UTILIZATION FOR TC-LIST-REPORT */\
                             execute_obosc_core(current_TC, obosc_tm_current->next_TM);\
@@ -578,6 +608,7 @@
             Base_tm *temp = obosc_tm_current->next_TM;\
             delete obosc_tm_current;\
             obosc_tm_current = temp;\
+            ++overCount;\
         }\
         else{\
             /*PENDING: RESET CDMS: MEMORY LEAK FOUND*/\
@@ -587,6 +618,7 @@
 }
 
 #define EXECUTE_TC {\
+    gMASTER_STATE = TCL_STATE_EXECUTING;\
     for(uint8_t execute_psc = PSC_START_VALUE ; execute_psc < (PSC_START_VALUE+gTOTAL_VALID_TC) ; ++execute_psc ){\
         /*gLEDG = !gLEDG;*/\
         /*gLEDR = !gLEDR;*/\
@@ -596,9 +628,12 @@
             if( overflowCount < TCL_OVERFLOW_CONSTANT ){\
                 if( (GETcrc_pass(current_TC) == 1) && (GETpacket_seq_count(current_TC) == execute_psc) ){\
                     uint8_t current_exec_status = GETexec_status(current_TC);\
-                    if( (current_exec_status == TC_STATE_SUCCESSFULLY_EXECUTED) || (current_exec_status == TC_STATE_DISABLED) )\
+                    if( (current_exec_status == TC_STATE_SUCCESSFULLY_EXECUTED) || (current_exec_status == TC_STATE_DISABLED) ){\
+                        gPC.printf("disabled or completed at %u\n", execute_psc);\
                         break;\
+                    }\
                     else if( (current_exec_status == TC_STATE_EXECUTION_FAILED) && (GETabort_on_nack(current_TC) == 1) ){\
+                        gPC.printf("abort on nack at %u psc\r\n", execute_psc);\
                         gMASTER_STATE = TCL_STATE_ABORTED;\
                         break;\
                     }\
@@ -607,6 +642,7 @@
                         uint8_t temp81 = 0x00;\
                         isit_sdcard(current_TC, temp81);\
                         if( temp81 == 0x00 ){\
+                            gPC.printf("non sd card at %u\r\n", execute_psc);\
                             /*EXECUTION OF NON SD-CARD (BOTH OBOSC and CDMS functions)*/\
                             Base_tm *tm_ptr_head = NULL;\
                             get_call_sign(tm_ptr_head);\
@@ -615,10 +651,12 @@
                             uint8_t tempPAhot = 0x00;\
                             isit_obosc(current_TC, temp82);\
                             if(temp82 == 0x01){\
+                                gPC.printf("obosc tc inside normal tc at %u\r\n", execute_psc);\
                                 /*EXECUTION OF OBOSC TC*/\
                                 /*SKIP EXECUTION OF OBOSC HERE*/\
                             }\
                             else{\
+                                gPC.printf("cdms relay tmtc at %u\r\n", execute_psc);\
                                 /*call CDMS_RLY_TMTC*/\
                                 /*CDMS_RLY_TMTC(current_TC, put_tm_here);*/\
                             }\
@@ -697,6 +735,7 @@
                             }\
                         }\
                         else{\
+                            gPC.printf("sd card at %u\r\n", execute_psc);\
                             /*EXECUTION OF SD-CARD DATA SENDING (OBSRS)*/\
                             /*CHECK FOR HOT PA*/\
                             uint8_t tempPAhot = 0x00;\
@@ -722,6 +761,7 @@
             }\
         }\
         if( gMASTER_STATE == TCL_STATE_ABORTED ){\
+            gPC.puts("ABORTING DUE TO ABORT ON NACK\r\n");\
             /*EXITED DUE TO ABORT ON NACK:*/\
             /*PENDING : POWER OFF COM TX*/\
             RX1M.attach(&rx_read, Serial::RxIrq);\
@@ -736,14 +776,16 @@
             gFLAGS = gFLAGS & (~COM_MNG_TMTC_RUNNING_FLAG);\
             break;\
         }\
+        gPC.printf("successflly executed %u tc\r\n", execute_psc);\
     }\
-    /*COMPLETED EXECUTION OF TC*/\
-    gMASTER_STATE = TCL_STATE_COMPLETED;\
-    /*PENDING : COM POWER OFF TX*/\
-    reset_all;\
-    /*PENDING : ENABLE THREADS*/\
-    gSESSION_TIMEOUT.detach();\
-    gFLAGS = gFLAGS & (~COM_MNG_TMTC_RUNNING_FLAG);\
-    gFLAGS = gFLAGS & (~COM_SESSION_FLAG);\
-    break;\
+    if( gMASTER_STATE != TCL_STATE_ABORTED ){\
+        /*COMPLETED EXECUTION OF TC*/\
+        gMASTER_STATE = TCL_STATE_COMPLETED;\
+        COM_POWER_OFF_TX;\
+        reset_all;\
+        /*PENDING : ENABLE THREADS*/\
+        gSESSION_TIMEOUT.detach();\
+        gFLAGS = gFLAGS & (~COM_MNG_TMTC_RUNNING_FLAG);\
+        gFLAGS = gFLAGS & (~COM_SESSION_FLAG);\
+    }\
 }
\ No newline at end of file