Latest FM Code with EEPROM

Dependencies:   FreescaleIAP SimpleDMA eeprom mbed-rtos mbed

Fork of CDMS_QM_03MAR2017_Flash_with_obsrs by Team Fox

Revision:
231:e2bd2a990bfe
Parent:
228:335da5b0d3e4
diff -r 335da5b0d3e4 -r e2bd2a990bfe COM_MNG_TMTC.h
--- a/COM_MNG_TMTC.h	Mon Jul 04 23:13:24 2016 +0000
+++ b/COM_MNG_TMTC.h	Tue Jul 05 11:27:29 2016 +0000
@@ -14,7 +14,6 @@
 
 //DigitalIn tm_status_4m_slv(PIN39); //I2C interrupt to CDMS from BAE
 //DigitalIn tm_status_4m_pl(PIN61); //I2C interrupt to CDMS from PL
-#define RESET_CDMS NVIC_SystemReset()
 
 uint8_t received = 0;
 uint16_t mid1;
@@ -46,7 +45,7 @@
 
 
 
-#define detect_ack(tm_ptr, temp_ack, tc_psc) {\
+#define detect_ack(tm_ptr, temp_ack) {\
     if( tm_ptr != NULL ){\
         int length = TM_SHORT_SIZE;\
         if( GETshort_or_long_tm(tm_ptr) == SHORT_TM_CODE ){\
@@ -63,20 +62,20 @@
             if( (temp8 == 0xC0) || (temp8 == 0xA0) )\
                 temp_ack = 0x01;\
             else{\
-                temp_ack = 0x00;\
+                temp_ack = 0x02;\
                 /*CHECK FOR NACK CODE: CRC FAIL NACK*/\
                 temp8 = tm_ptr->TM_string[TM_ACK_CODE_INDEX];\
                 temp8 = temp8 & 0x0F;\
                 if( temp8 == CRC_FAIL_NACK_CODE ){\
-                    tm_ptr->TM_string[2] = tc_psc;\
+                    temp_ack = 0x04;\
                 }\
             }\
         }\
         else\
-            temp_ack = 0x00;\
+            temp_ack = 0x03;\
     }\
     else{\
-        temp_ack = 0x00;\
+        temp_ack = 0x02;\
     }\
 }
 
@@ -1048,7 +1047,7 @@
     }\
     else if( (service_subtype != OBOSC_SUB_DISABLE) && (service_subtype != OBOSC_SUB_RETRY) ){\
         /*CHANGE THE ACK CODE TO INVALID TC*/\
-        ackl234new->TM_string[2] = 0xA2;\
+        ackl234new->TM_string[2] = 0xAF;\
     }\
     if (DEBUG)\
         gPC.puts("completed obosc\r\n");\
@@ -1058,6 +1057,7 @@
 
 
 #define EXECUTE_OBOSC_ONLY {\
+    gMASTER_STATE = TCL_STATE_EXECUTING;\
     int reset_flag = 0;\
     if (DEBUG)\
         gPC.puts("iNSIDE EXECUTE_OBOSC_ONLY\r\n");\
@@ -1086,8 +1086,14 @@
                             while(obosc_tm_core != NULL){\
                                obosc_tm_core = obosc_tm_core->next_TM;\
                             }\
-                            uint16_t temp16 = TC_STATE_SUCCESSFULLY_EXECUTED;\
-                            PUTexec_status(current_TC, temp16);\
+                            if(obosc_tm_current->TM_string[2] == 0xA0){\
+                                uint16_t temp16 = TC_STATE_SUCCESSFULLY_EXECUTED;\
+                                PUTexec_status(current_TC, temp16);\
+                            }\
+                            else{\
+                                uint16_t temp16 = TC_STATE_EXECUTION_FAILED;\
+                                PUTexec_status(current_TC, temp16);\
+                            }\
                             while( obosc_tm_current != NULL ){\
                                 int length = TM_SHORT_SIZE;\
                                 if( GETshort_or_long_tm(obosc_tm_current) == SHORT_TM_CODE ){\
@@ -1101,9 +1107,6 @@
                                 }\
                                 obosc_tm_current = obosc_tm_current->next_TM;\
                             }\
-                            if ( reset_flag ==1 ){\
-                                reset_all;\
-                            }\
                         }\
                     }\
                 }\
@@ -1111,7 +1114,7 @@
                 ++overCount;\
             }\
             else{\
-                /*PENDING: REST CDMS: MEMORY LEAK FOUND*/\
+                RESET_CDMS;\
                 break;\
             }\
         }\
@@ -1151,6 +1154,12 @@
                 break;\
             }\
         }\
+    }\
+    if ( reset_flag == 1 ){\
+        reset_all;\
+        /*PENDING: Enable threads*/\
+        /*gCDMS_HK_TIMER.start(5000);*/\
+        gSESSION_TIMEOUT.detach();\
     }\    
 }
 
@@ -1248,19 +1257,33 @@
                             }\
                             /*DETECT ACK OR NACK*/\
                             uint8_t temp83 = 0x00;\
-                            uint8_t temp84 = GETpacket_seq_count(current_TC);\
-                            detect_ack(put_tm_here, temp83, temp84);\
+                            detect_ack(put_tm_here, temp83);\
                             if( temp83 == 0x01){\
                                 uint16_t temp16 = TC_STATE_SUCCESSFULLY_EXECUTED;\
                                 PUTexec_status(current_TC, temp16);\
                             }\
+                            else if( temp83 == 0x03){\
+                                /*gPC.puts("TC_STATE_EXECUTION_UNKNOWN");*/\
+                                uint16_t temp16 = TC_STATE_EXECUTION_UNKNOWN;\
+                                PUTexec_status(current_TC, temp16);\
+                            }\
+                            else if( temp83 == 0x04){\
+                                /*gPC.puts("TC_STATE_EXECUTION_UNKNOWN");*/\
+                                uint16_t temp16 = TC_STATE_EXECUTION_FAILED;\
+                                PUTexec_status(current_TC, temp16);\
+                                uint8_t temp84 = GETpacket_seq_count(current_TC);\
+                                put_tm_here->TM_string[2] = temp84;\
+                                uint16_t crc16 = crc16_gen(put_tm_here->TM_string, 11);\
+                                put_tm_here->TM_string[11]  = (crc16 & 0xFF00)>>8;\
+                                put_tm_here->TM_string[12] = (crc16 & 0x00FF);\
+                            }\
                             else{\
                                 /*gPC.puts("TC_STATE_EXECUTION_FAILED");*/\
                                 uint16_t temp16 = TC_STATE_EXECUTION_FAILED;\
                                 PUTexec_status(current_TC, temp16);\
                             }\
                             /*ABORT ON NACK AND TC LIST COMPLETED: UPDATE IN gMASTERSTATE*/\
-                            if( (GETexec_status(current_TC) == TC_STATE_EXECUTION_FAILED) && (GETabort_on_nack(current_TC) == 1) ){\
+                            if( ((GETexec_status(current_TC) == TC_STATE_EXECUTION_FAILED) || (GETexec_status(current_TC) == TC_STATE_EXECUTION_UNKNOWN)) && (GETabort_on_nack(current_TC) == 1) ){\
                                 gMASTER_STATE = TCL_STATE_ABORTED;\
                             }\
                             else if( execute_psc == (gTOTAL_VALID_TC-1) ){\
@@ -1269,20 +1292,23 @@
                             }\
                             /*update last executed L1_ack*/\
                             if( put_tm_here != NULL ){\
-                                if( GETshort_or_long_tm(put_tm_here) == SHORT_TM_CODE ){\
+                                Base_tm *ptr_tm = put_tm_here;\
+                                while(ptr_tm->next_TM != NULL)\
+                                    ptr_tm = ptr_tm->next_TM;\
+                                if( GETshort_or_long_tm(ptr_tm) == SHORT_TM_CODE ){\
                                     for(int i = 0 ; i < TM_SHORT_SIZE ; ++i){\
-                                        gLAST_TM[i] = put_tm_here->TM_string[i];\
+                                        gLAST_TM[i] = ptr_tm->TM_string[i];\
                                         gLAST_TM_SHORT_OR_LONG = SHORT_TM_CODE;\
                                     }\
                                 }\
                                 else{\
                                     for( int i = 0 ; i < TM_LONG_SIZE ; ++i ){\
-                                        gLAST_TM[i] = put_tm_here->TM_string[i];\
+                                        gLAST_TM[i] = ptr_tm->TM_string[i];\
                                         gLAST_TM_SHORT_OR_LONG = LONG_TM_CODE;\
                                     }\
                                 }\
                             }\
-                            /*PENDING: APPEND ACK L1*/\
+                            P_COM_HK;\
                             Base_tm *tm_ptr = tm_ptr_head;\
                             get_ack_l1(tm_ptr->next_TM);\
                             int overflowCountExecute = 0;\
@@ -1297,11 +1323,6 @@
                                 }\
                             }\
                             tm_ptr->next_TM = put_tm_here;\
-                            /*CHECK FOR HOT PA*/\
-                            isPAhot(tempPAhot);\
-                            if( tempPAhot == 0x00 ){\
-                                gFLAGS = gFLAGS | COM_PA_HOT_FLAG;\
-                            }\
                             tm_ptr = tm_ptr_head;\
                             while( tm_ptr != NULL ){\
                                 int length = TM_SHORT_SIZE;\
@@ -1342,112 +1363,10 @@
                             if (DEBUG)\
                                 gPC.printf("sd card at %u\r\n", execute_psc);\
                             /*EXECUTION OF SD-CARD DATA SENDING (OBSRS)*/\
-                            Base_tm *tm_ptr_head = NULL;\
-                            get_call_sign(tm_ptr_head);\
-                            Base_tm *put_tm_here = NULL;\
-                            /*execute_obsrs(current_TC, put_tm_here)*/\
-                            /*read_TC(current_TC);*/\
                             execute_OBSRS_TC(current_TC);\
                             gPC.puts("en_adf");\
                             transmit_adf;\
                             gPC.puts("ex_adf");\
-                            uint8_t tempExec = TC_STATE_SUCCESSFULLY_EXECUTED;\
-                            PUTexec_status(current_TC, tempExec);\
-                            /*PENDING: ABORT ON NACK CHECK, gMASTER_STATE VERIFICATION WITH SD CARD, session timeout, last executed ack l234*/\
-                            if( (GETexec_status(current_TC) == TC_STATE_EXECUTION_FAILED) && (GETabort_on_nack(current_TC) == 1) ){\
-                                gMASTER_STATE = TCL_STATE_ABORTED;\
-                            }\
-                            else if( execute_psc == (gTOTAL_VALID_TC-1) ){\
-                                gMASTER_STATE = TCL_STATE_COMPLETED;\
-                            }\
-                            else{\
-                                uint8_t check1 = 1;\
-                                for( uint8_t test_psc = execute_psc+1 ; test_psc < gTOTAL_VALID_TC ; ++test_psc ){\
-                                    Base_tc* test_TC = gHEAD_NODE_TCL;\
-                                    while(test_TC != NULL){\
-                                        if( GETpacket_seq_count(test_TC) == test_psc ){\
-                                            uint8_t checkval;\
-                                            isit_obosc(test_TC, checkval);\
-                                            if( checkval == 0 ){\
-                                                check1 = 0;\
-                                            }\
-                                        }\
-                                        test_TC = test_TC->next_TC;\
-                                    }\
-                                }\
-                                if( check1 == 0x01 ){\
-                                    gMASTER_STATE = TCL_STATE_COMPLETED;\
-                                }\
-                            }\
-                            /*update last executed L1_ack*/\
-                            if( put_tm_here != NULL ){\
-                                if( GETshort_or_long_tm(put_tm_here) == SHORT_TM_CODE ){\
-                                    for(int i = 0 ; i < TM_SHORT_SIZE ; ++i){\
-                                        gLAST_TM[i] = put_tm_here->TM_string[i];\
-                                        gLAST_TM_SHORT_OR_LONG = SHORT_TM_CODE;\
-                                    }\
-                                }\
-                                else{\
-                                    for( int i = 0 ; i < TM_LONG_SIZE ; ++i ){\
-                                        gLAST_TM[i] = put_tm_here->TM_string[i];\
-                                        gLAST_TM_SHORT_OR_LONG = LONG_TM_CODE;\
-                                    }\
-                                }\
-                            }\
-                            /*PENDING: APPEND ACK L1*/\
-                            Base_tm *tm_ptr = tm_ptr_head;\
-                            get_ack_l1(tm_ptr->next_TM);\
-                            int overflowCountExecute = 0;\
-                            while( tm_ptr->next_TM != NULL ){\
-                                if( overflowCountExecute < TM_OVERFLOW_CONSTANT ){\
-                                    tm_ptr = tm_ptr->next_TM;\
-                                    ++overflowCountExecute;\
-                                }\
-                                else{\
-                                    RESET_CDMS;\
-                                    break;\
-                                }\
-                            }\
-                            tm_ptr->next_TM = put_tm_here;\
-                            /*CHECK FOR HOT PA*/\
-                            uint8_t tempPAhot = 0x00;\
-                            isPAhot(tempPAhot);\
-                            if( tempPAhot == 0x00 ){\
-                                gFLAGS = gFLAGS | COM_PA_HOT_FLAG;\
-                            }\
-                            tm_ptr = tm_ptr_head;\
-                            while( tm_ptr != NULL ){\
-                                int length = TM_SHORT_SIZE;\
-                                if( GETshort_or_long_tm(tm_ptr) == SHORT_TM_CODE ){\
-                                    length = TM_SHORT_SIZE;\
-                                }\
-                                else{\
-                                    length = TM_LONG_SIZE;\
-                                }\
-                                /*gPC.puts("Printing Call Sign, ACK_L1, TM list");*/\
-                                for(int i = 0 ; i < length ; ++i){\
-                                    /*gPC.putc(tm_ptr->TM_string[i]);*/\
-                                }\
-                                tm_ptr = tm_ptr->next_TM;\
-                            }\
-                            /*SEND call sign, ACK_L1, OBSRS TO GS*/\
-                            /*snd_tm.head_pointer(tm_ptr_head);*/\
-                            /*transmit_adf;*/\
-                            /*DELETE THE TM AFTER USE*/\
-                            tm_ptr = tm_ptr_head;\
-                            overflowCountExecute = 0;\
-                            while(tm_ptr != NULL){\
-                                if( overflowCountExecute < TM_OVERFLOW_CONSTANT ){\
-                                    Base_tm *temp = tm_ptr->next_TM;\
-                                    delete tm_ptr;\
-                                    tm_ptr = temp;\
-                                    ++overflowCountExecute;\
-                                }\
-                                else{\
-                                    RESET_CDMS;\
-                                    break;\
-                                }\
-                            }\
                         }\
                     }\
                     break;\
@@ -1467,15 +1386,15 @@
             if (DEBUG)\
                 gPC.puts("ABORTING DUE TO ABORT ON NACK\r\n");\
             /*EXITED DUE TO ABORT ON NACK:*/\
-            /*COM_TX_CNTRL = 0;*/\
+            COM_TX_CNTRL = 0;\
             RX1M.attach(&rx_read, Serial::RxIrq);\
             gFLAGS = gFLAGS & (~COM_MNG_TMTC_RUNNING_FLAG);\
             break;\
         }\
-        else if( gFLAGS & COM_PA_HOT_FLAG ){\
+        else if( (gFLAGS & COM_PA_HOT_FLAG) || (gFLAGS & COM_PA_OC_FLAG) ){\
             /*PA HOT: WAIT FOR TIMEOUT*/\
             gCOM_PA_COOLING_TIMEOUT.attach(&after_cooling_pa, COM_PA_COOLING_TIME_LIMIT);\
-            /*COM_TX_CNTRL = 0;*/\
+            COM_TX_CNTRL = 0;\
             RX1M.attach(&rx_read, Serial::RxIrq);\
             gFLAGS = gFLAGS & (~COM_MNG_TMTC_RUNNING_FLAG);\
             break;\
@@ -1488,10 +1407,10 @@
             gPC.printf("completed or session timed out: %x\r\n", gMASTER_STATE);\
         /*COMPLETED EXECUTION OF TC*/\
         gMASTER_STATE = TCL_STATE_COMPLETED;\
-        /*COM_POWER_OFF_TX;*/\
+        COM_POWER_OFF_TX;\
         reset_all;\
         /*PENDING : ENABLE THREADS*/\
-        gPAY_SPI.bulkRead_start();\
+        /*gCDMS_HK_TIMER.start(5000);*/\
         gSESSION_TIMEOUT.detach();\
         gFLAGS = gFLAGS & (~COM_MNG_TMTC_RUNNING_FLAG);\
         gFLAGS = gFLAGS & (~COM_SESSION_FLAG);\