CDMS_CODE_samp_23SEP_DMA_flag

Dependencies:   FreescaleIAP SimpleDMA mbed-rtos mbed

Fork of CDMS_CODE_samp_23SEP_DMA by iitm sat

Revision:
212:3d13a06bcd3a
Parent:
211:77bee0cbebfe
--- a/COM_MNG_TMTC.h	Sat Jun 18 09:07:28 2016 +0000
+++ b/COM_MNG_TMTC.h	Sun Jul 03 05:37:25 2016 +0000
@@ -41,7 +41,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 ){\
@@ -58,21 +58,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 ){\
-                    temp_ack = 0x02;
-                    tm_ptr->TM_string[2] = tc_psc;\
+                    temp_ack = 0x04;\                    
                 }\
             }\
         }\
         else\
-            temp_ack = 0x00;\
+            temp_ack = 0x03;\
     }\
     else{\
-        temp_ack = 0x00;\
+        temp_ack = 0x02;\
     }\
 }
 
@@ -828,6 +827,7 @@
      }
 }
 // CDMS TEAM CODE END
+
 // EXECUTE OBOSC
 #define execute_obosc_core(tc_ptr, tm_ptr, reset_flag) {\
     if (DEBUG)\
@@ -927,13 +927,11 @@
         get_tc_list(ackl234new->next_TM, GETpacket_seq_count(tc_ptr));\
     }\
     else if( service_subtype == OBOSC_SUB_RESET ){\
-        /*reset_all;*/\
         reset_flag = 1;\
-        /*PENDING: VERIFY reset_all, RESET CDMS*/\
     }\
     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");\
@@ -943,6 +941,7 @@
 
 
 #define EXECUTE_OBOSC_ONLY {\
+    gMASTER_STATE = TCL_STATE_EXECUTING;\
     int reset_flag = 0;\
     if (DEBUG)\
         gPC.puts("iNSIDE EXECUTE_OBOSC_ONLY\r\n");\
@@ -971,8 +970,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 ){\
@@ -986,9 +991,6 @@
                                 }\
                                 obosc_tm_current = obosc_tm_current->next_TM;\
                             }\
-                            if ( reset_flag ==1 ){\
-                                reset_all;\
-                            }\
                         }\
                     }\
                 }\
@@ -996,7 +998,7 @@
                 ++overCount;\
             }\
             else{\
-                /*PENDING: REST CDMS: MEMORY LEAK FOUND*/\
+                RESET_CDMS;\
                 break;\
             }\
         }\
@@ -1019,8 +1021,8 @@
         }\
         obosc_tm_current->next_TM = obosc_tm;\
         /*Sending OBOSC TM to GS*/\
-        /*snd_tm.head_pointer(obosc_tm_head);*/\
-        /*transmit_adf;*/\
+        snd_tm.head_pointer(obosc_tm_head);\
+        transmit_adf;\
         /*DELETE THE TM AFTER USE*/\
         obosc_tm_current = obosc_tm_head;\
         int overCount = 0;\
@@ -1036,7 +1038,13 @@
                 break;\
             }\
         }\
-    }\    
+    }\
+    if ( reset_flag == 1 ){\
+        reset_all;\
+        /*PENDING: Enable threads*/\
+        /*gCDMS_HK_TIMER.start(5000);*/\
+        gSESSION_TIMEOUT.detach();\
+    }\
 }
 
 #define EXECUTE_TC {\
@@ -1086,7 +1094,7 @@
                             tm_ptr = tm_ptr->next_TM;\
                         }\ 
                         /*Send only call sign, ACK_L1 to GS*/\
-                        /*snd_tm.head_pointer(tm_ptr_head);*/\
+                        snd_tm.head_pointer(tm_ptr_head);\
                         /*transmit_adf;*/\
                         /*DELETE THE TM AFTER USE*/\
                         tm_ptr = tm_ptr_head;\
@@ -1128,29 +1136,37 @@
                             else{\
                                 /*gPC.printf("cdms relay tmtc at %u\r\n", execute_psc);*/\
                                 /*call CDMS_RLY_TMTC*/\
-                                /*CDMS_RLY_TMTC(current_TC, put_tm_here);*/\
                                 put_tm_here =  FCTN_CDMS_RLY_TMTC(current_TC);\
                             }\
                             /*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 == 0x02){\
+                            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) ){\
@@ -1159,20 +1175,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;\
@@ -1187,11 +1206,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;\
@@ -1232,112 +1246,7 @@
                             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;\
@@ -1357,15 +1266,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;\
@@ -1381,6 +1290,7 @@
         COM_POWER_OFF_TX;\
         reset_all;\
         /*PENDING : ENABLE THREADS*/\
+        /*gCDMS_HK_TIMER.start(5000);*/\
         gPAY_SPI.bulkRead_start();\
         gSESSION_TIMEOUT.detach();\
         gFLAGS = gFLAGS & (~COM_MNG_TMTC_RUNNING_FLAG);\