CDMS code for testing sbc

Dependencies:   FreescaleIAP SimpleDMA mbed-rtos mbed

Fork of CDMS_CODE by shubham c

Revision:
217:93505a6f8db7
Parent:
216:570251b23c7b
Child:
218:c63cdba0550f
diff -r 570251b23c7b -r 93505a6f8db7 ThreadsAndFunctions.h
--- a/ThreadsAndFunctions.h	Sun Jul 03 09:47:05 2016 +0000
+++ b/ThreadsAndFunctions.h	Sun Jul 03 11:35:55 2016 +0000
@@ -36,6 +36,12 @@
     gCOM_MNG_TMTC_THREAD->signal_set(COM_MNG_TMTC_SIGNAL_UART_INT);
 }
 
+// COM_RX_DISABLE ISR
+void after_com_disable(){
+    gCOM_RX_DISABLE.detach();
+    RX1M.attach(&rx_read, Serial::RxIrq);
+}
+
 // RX_TIMEOUT ISR
 void after_receive(){
     gRX_TIMEOUT.detach();
@@ -63,15 +69,15 @@
     }\
     gHEAD_NODE_TCL = NULL;\
     gLAST_NODE_TCL = NULL;\
-    gMASTER_STATE = TCL_STATE_INCOMPLETE;\
+    gMASTER_STATE = TCL_STATE_COMPLETED;\
     gTOTAL_INCORRECT_SIZE_TC = 0;\
     gTOTAL_CRC_FAIL_TC = 0;\
     gTOTAL_REPEATED_TC = 0;\
     gTOTAL_VALID_TC = 0;\
     for(int i = 0 ; i < TM_LONG_SIZE ; ++i){\
-        gLAST_TM[i] = 0x00;\
+        /*gLAST_TM[i] = 0x00;*/\
     }\
-    gLAST_TM_SHORT_OR_LONG = SHORT_TM_CODE;\
+    /*gLAST_TM_SHORT_OR_LONG = SHORT_TM_CODE;*/\
     COM_RX_DATA_NODE *dataptr = gRX_HEAD_DATA_NODE;\
     while( dataptr != NULL ){\
         COM_RX_DATA_NODE *temp = dataptr->next_node;\
@@ -82,6 +88,7 @@
     gRX_HEAD_DATA_NODE->next_node = NULL;\
     gRX_CURRENT_DATA_NODE = gRX_HEAD_DATA_NODE;\
     gRX_COUNT = 0;\
+    gTOTAL_RAW_BYTES = 0;\
     /*PENDING : ALL GLOBAL VAARIABLES AND FLAGS*/\
     /*gPC.puts("finished reset all\r\n");*/\
 }
@@ -96,6 +103,7 @@
         gRX_CURRENT_DATA_NODE = gRX_CURRENT_DATA_NODE->next_node;\
         gRX_CURRENT_DATA_NODE->next_node = NULL;\
     }\
+    ++gTOTAL_RAW_BYTES;\
     gRX_TIMEOUT.attach(&after_receive, RX_TIMEOUT_LIMIT);\
 }
 
@@ -110,10 +118,12 @@
             gFLAGS = gFLAGS & (~UART_INT_FLAG);
             if( !(gFLAGS & COM_SESSION_FLAG) ){
                 // PENDING : DISABLE THREADS
+                // gCDMS_HK_TIMER.stop();
                 PL_wo_dma->stop();
                 gFLAGS = gFLAGS | COM_SESSION_FLAG;
                 gSESSION_TIMEOUT.attach(&after_session, SESSION_TIME_LIMIT);
                 gFLAGS = gFLAGS | COM_RX_FLAG;
+                gTOTAL_RAW_BYTES = 0;
                 PUT_RAW_BYTE;
                 // PENDING : MEASURE RSSI
                 if( gFLAGS & COM_SESSION_FLAG ){
@@ -132,10 +142,15 @@
                 gFLAGS = gFLAGS | COM_RX_FLAG;
                 PUT_RAW_BYTE;
             }
+            if(gTOTAL_RAW_BYTES > BYTE_OVERFLOW_CONSTANT){
+                RX1M.attach(NULL);
+                gCOM_RX_DISABLE.attach(&after_com_disable, COM_RX_DISABLE_TIMEOUT);
+                after_receive();
+            }
         }
         else if( gFLAGS & NEW_TC_RECEIVED ){
             gPC.puts("NEW TC RECEIVED\r\n");
-            Thread::wait(1000);
+            Thread::wait(1000);/*For testing with transmitter. To be removed later*/
             gFLAGS = gFLAGS & (~NEW_TC_RECEIVED);
             gFLAGS = gFLAGS | COM_MNG_TMTC_RUNNING_FLAG;
 
@@ -163,30 +178,24 @@
                         // CHECK WEATHER GS VERIFICATION CODE MATCHES
                         uint8_t tempGSver = 0x00;
                         GScodeVerification(tempGSver);
-                        /*PENDING: INCLUDE GS VERIFICATION CODE*/
                         if( tempGSver == 0xFF ){
                             /*gPC.puts("GS code match !!\r\n");*/
                             gFLAGS = gFLAGS | COM_SESSION_VALIDITY;
                             COM_POWER_ON_TX;
-                            // PENDING: PA HOT HANDLED IN EXECUTE_XXX FUNCTIONS
-                            uint8_t tempPAHot = 0x00;
-                            isPAhot(tempPAHot);
-                            if( tempPAHot == 0xFF ){
-                                gFLAGS = gFLAGS & ~(COM_PA_HOT_FLAG);
+                            P_COM_HK;
+                            if( (gFLAGS & COM_PA_HOT_FLAG) || ( gFLAGS & COM_PA_OC_FLAG ) ){
+                                COM_TX_CNTRL = 0;
+                                gCOM_PA_COOLING_TIMEOUT.attach(&after_cooling_pa, COM_PA_COOLING_TIME_LIMIT);
+                                gFLAGS = gFLAGS & (~COM_MNG_TMTC_RUNNING_FLAG);
+                                RX1M.attach(&rx_read, Serial::RxIrq);
+                            }
+                            else{
                                 gCOM_PA_COOLING_TIMEOUT.detach();
                                 gPC.puts("EXECUTING TELECOMMANDS\r\n");
-//                                DEBUF_PRINT("EXECUTING TELECOMMANDS\r\n");
                                 EXECUTE_OBOSC_ONLY;
                                 EXECUTE_TC;
                                 gPC.puts("COMPLETED EXECUTION\r\n");
                             }
-                            else{
-                                gFLAGS = gFLAGS | COM_PA_HOT_FLAG;
-                                // PENDING: power off transmitter only
-                                gCOM_PA_COOLING_TIMEOUT.attach(&after_cooling_pa, COM_PA_COOLING_TIME_LIMIT);
-                                gFLAGS = gFLAGS & (~COM_MNG_TMTC_RUNNING_FLAG);
-                                RX1M.attach(&rx_read, Serial::RxIrq);
-                            }
                         }
                         else{
                             /*gPC.puts("GS code mismatch !!\r\n");*/
@@ -194,10 +203,11 @@
                             reset_all;
                             gFLAGS = gFLAGS & (~COM_SESSION_VALIDITY);
                             // PENDING : ENABLE THREADS
+                            // gCDMS_HK_TIMER.start(5000);
                             PL_wo_dma->start(6000);
                             gSESSION_TIMEOUT.detach();
                             gFLAGS = gFLAGS & (~COM_SESSION_FLAG);
-                            // WARNING: clear COM_MNG_TMTC ?
+                            gFLAGS = gFLAGS & (~COM_MNG_TMTC_RUNNING_FLAG);
                         }
                     }
                     else{
@@ -228,15 +238,16 @@
                         }
                         //gPC.puts("\r\n");
                         COM_POWER_ON_TX;
-                        // PENDING : POWER OFF TX
+                        COM_TX_CNTRL = 0;
                         RX1M.attach(&rx_read, Serial::RxIrq);
                         gFLAGS = gFLAGS & (~COM_MNG_TMTC_RUNNING_FLAG);
                     }
                 }
                 else{
                     COM_POWER_ON_TX;
-                    // POWER OFF TX transmitter only
-                    // WARNING: reset_all ? clear com_session ?
+                    COM_TX_CNTRL = 0;
+                    reset_all;
+                    gFLAGS = gFLAGS & (~COM_SESSION_FLAG);
                     RX1M.attach(&rx_read, Serial::RxIrq);
                     gFLAGS = gFLAGS & (~COM_MNG_TMTC_RUNNING_FLAG);
                 }
@@ -247,6 +258,7 @@
                 gFLAGS = gFLAGS & (~COM_MNG_TMTC_RUNNING_FLAG);
                 reset_all;
                 // PENDING : ENABLE THREADS
+                // gCDMS_HK_TIMER.start(5000);
                 PL_wo_dma->start(6000);
                 gSESSION_TIMEOUT.detach();
                 gFLAGS = gFLAGS & (~COM_SESSION_FLAG);
@@ -254,29 +266,17 @@
         }
         else if( gFLAGS & COM_PA_HOT_FLAG ){
             /*gPC.puts("checking for PA hot in main\r\n");*/
-            if( gFLAGS & COM_RX_FLAG ){
-                uint8_t tempPA = 0xFF;
-                isPAhot(tempPA);
-                if( tempPA == 0x00 ){
-                    gCOM_PA_COOLING_TIMEOUT.attach(&after_cooling_pa, COM_PA_COOLING_TIME_LIMIT);
-                }
-                else{
-                    gFLAGS = gFLAGS & ~(COM_PA_HOT_FLAG);
-                    gCOM_PA_COOLING_TIMEOUT.detach();
-                }
+            P_COM_HK;
+            if((gFLAGS & COM_PA_HOT_FLAG) || (gFLAGS & COM_PA_OC_FLAG)){
+                COM_TX_CNTRL = 0;
+                gCOM_PA_COOLING_TIMEOUT.attach(&after_cooling_pa, COM_PA_COOLING_TIME_LIMIT);
             }
             else{
-                uint8_t tempPA = 0xFF;
-                isPAhot(tempPA);
-                if( tempPA == 0x00 ){
-                    gCOM_PA_COOLING_TIMEOUT.attach(&after_cooling_pa, COM_PA_COOLING_TIME_LIMIT);
-                }
-                else{
+                gCOM_PA_COOLING_TIMEOUT.detach();
+                if( !(gFLAGS & COM_RX_FLAG) ){
                     /*gPC.puts("PA IS COOLED DOWN\r\n");*/
-                    gFLAGS = gFLAGS & (~COM_PA_HOT_FLAG);
                     gFLAGS = gFLAGS | COM_MNG_TMTC_RUNNING_FLAG;
                     RX1M.attach(NULL);
-                    gCOM_PA_COOLING_TIMEOUT.detach();
                     COM_POWER_ON_TX;
                     EXECUTE_OBOSC_ONLY;
                     EXECUTE_TC;
@@ -287,7 +287,7 @@
             /*gPC.puts("session timeout: resetting in main\r\n");*/
             COM_POWER_OFF_TX;
             /*PENDING : ENABLE THREADS*/
-            
+            // gCDMS_HK_TIMER.start(5000);
             gSESSION_TIMEOUT.detach();
             gFLAGS = gFLAGS & (~COM_MNG_TMTC_RUNNING_FLAG);
             gFLAGS = gFLAGS & (~COM_SESSION_FLAG);
@@ -299,6 +299,7 @@
             COM_POWER_OFF_TX;
             reset_all;
             // PENDING : ENABLE THREADS
+            // gCDMS_HK_TIMER.start(5000);
             PL_wo_dma->start(6000);
             gSESSION_TIMEOUT.detach();
             gFLAGS = gFLAGS & (~COM_SESSION_FLAG);