CDMS code for testing sbc

Dependencies:   FreescaleIAP SimpleDMA mbed-rtos mbed

Fork of CDMS_CODE by shubham c

Revision:
0:f016e9e8d48b
Child:
1:a0055b3280c8
diff -r 000000000000 -r f016e9e8d48b ThreadsAndFunctions.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ThreadsAndFunctions.h	Tue Dec 01 10:56:10 2015 +0000
@@ -0,0 +1,108 @@
+// UART ISR
+void rx_read(){
+    *gRX_CURRENT_PTR = RX1M.getc();
+    gFLAGS = gFLAGS | (0xFF & UART_INT_FLAG);
+    gCOM_MNG_TMTC_THREAD->signal_set(COM_MNG_TMTC_SIGNAL_UART_INT);
+}
+
+// RX_TIMEOUT ISR
+void after_receive(){
+    gRX_TIMEOUT.detach();
+    gFLAGS = gFLAGS | (0xFF & NEW_TC_RECEIVED);
+    gCOM_MNG_TMTC_THREAD->signal_set(COM_MNG_TMTC_SIGNAL_UART_INT);
+}
+
+// SESSION_TIMOUT ISR
+void after_session(){
+    gSESSION_TIMEOUT.detach();
+    gFLAGS = gFLAGS | (0xFF & END_SESSION);
+}
+
+#define reset_all {\
+    Base_tc *tcp = gHEAD_NODE_TCL;\
+    while(tcp != NULL){\
+        Base_tc *temp = tcp->next_TC;\
+        delete tcp;\
+        tcp = temp;\
+    }\
+    rx_tc_frames = 0;\
+    rx_tc_frames = 0;\
+    gTOTAL_INCORRECT_SIZE_TC = 0;\
+    gTOTAL_CRC_FAIL_TC = 0;\
+    COM_RX_DATA_NODE *dataptr = gRX_HEAD_DATA_NODE;\
+    while( dataptr != NULL ){\
+        COM_RX_DATA_NODE *temp = dataptr->next_node;\
+        delete dataptr;\
+        dataptr = temp;\
+    }\
+    gRX_HEAD_DATA_NODE = new COM_RX_DATA_NODE;\
+    gRX_HEAD_DATA_NODE->next_node = NULL;\
+    gRX_CURRENT_DATA_NODE = gRX_HEAD_DATA_NODE;\
+    gRX_CURRENT_PTR = gRX_HEAD_DATA_NODE->values;\
+    gRX_COUNT = 0;\
+}
+
+void COM_MNG_TMTC_FUN(void const *args){
+    while(true){
+        Thread::signal_wait( COM_MNG_TMTC_SIGNAL_UART_INT );
+        if( gFLAGS & UART_INT_FLAG ){
+            gFLAGS = gFLAGS & (~UART_INT_FLAG);
+            if( gRX_COUNT < (RX_BUFFER_LENGTH-1) ){
+                ++gRX_CURRENT_PTR;
+                ++gRX_COUNT;
+            }
+            else{
+                gLEDG = !gLEDG;
+                gRX_COUNT = 0;
+                gRX_CURRENT_DATA_NODE->next_node = new COM_RX_DATA_NODE;
+                gRX_CURRENT_DATA_NODE = gRX_CURRENT_DATA_NODE->next_node;
+                gRX_CURRENT_DATA_NODE->next_node = NULL;
+                gRX_CURRENT_PTR = gRX_CURRENT_DATA_NODE->values;
+            }
+            gRX_TIMEOUT.attach(&after_receive, RX_TIMEOUT_LIMIT);
+        }
+        else if( gFLAGS & NEW_TC_RECEIVED ){
+            gFLAGS = gFLAGS & (~NEW_TC_RECEIVED);
+            
+            // DISABLE THE RX1M INTERRUPT
+            RX1M.attach(NULL);
+            
+            // PENDING: BEACON
+            while(gRX_COUNT < (RX_BUFFER_LENGTH-1)){
+                *gRX_CURRENT_PTR = 0x00;
+                ++gRX_CURRENT_PTR;
+                ++gRX_COUNT;
+            }
+            gRX_COUNT = 0;
+            
+            if( (gMASTER_STATE == TCL_STATE_IDLE) || (gMASTER_STATE == TCL_STATE_ABORTED) || (gMASTER_STATE == TCL_STATE_COMPLETED)){
+                raw_data_to_tc();
+                if( (gTOTAL_VALID_TC > 0) && (gFLAGS & START_SESSION) ){
+                    gFLAGS = gFLAGS & (~START_SESSION);
+                    gSESSION_TIMEOUT.attach(&after_session, SESSION_TIME_LIMIT);
+                }
+                uint8_t tempContinue = 0xFF;
+                continueToExecute(tempContinue);
+                if( tempContinue == 0x00 ){
+                    if(gMASTER_STATE == TCL_STATE_ABORTED){
+                        gMASTER_STATE = TCL_STATE_EXECUTING;
+                        send_l1_ack;
+                        EXECUTE_OBOSC_ONLY;
+                    }
+                    EXECUTE_TC;
+                }
+                else{
+                    send_l1_ack;
+                }
+                gPC.puts("Completed Execution\r\n");
+            }
+            else{
+                // invalid state found - reset
+                reset_all;
+            }
+            
+            // PENDING: BEACON
+            RX1M.attach(&rx_read, Serial::RxIrq);
+        }
+    }
+}
\ No newline at end of file