CDMS code for testing sbc

Dependencies:   FreescaleIAP SimpleDMA mbed-rtos mbed

Fork of CDMS_CODE by shubham c

Revision:
230:e2bd2a990bfe
Parent:
199:9f03d6ca94c9
diff -r 335da5b0d3e4 -r e2bd2a990bfe ThreadsAndFunctions.h
--- a/ThreadsAndFunctions.h	Mon Jul 04 23:13:24 2016 +0000
+++ b/ThreadsAndFunctions.h	Tue Jul 05 11:27:29 2016 +0000
@@ -36,6 +36,13 @@
     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 +70,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 +89,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 +104,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);\
 }
 
@@ -114,6 +123,7 @@
                 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;
 
@@ -168,25 +183,20 @@
                             /*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");*/
@@ -198,6 +208,7 @@
                             gSESSION_TIMEOUT.detach();
                             gFLAGS = gFLAGS & (~COM_SESSION_FLAG);
                             // WARNING: clear COM_MNG_TMTC ?
+                            gFLAGS = gFLAGS & (~COM_MNG_TMTC_RUNNING_FLAG);
                         }
                     }
                     else{
@@ -229,6 +240,7 @@
                         //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);
                     }
@@ -237,6 +249,9 @@
                     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);
                 }
@@ -254,29 +269,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 +290,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);