DMA issue to be tested
Dependencies: FreescaleIAP SimpleDMA mbed-rtos mbed
Fork of CDMS_CODE by
Diff: ThreadsAndFunctions.h
- Revision:
- 212:3d13a06bcd3a
- Parent:
- 180:ccc21cc163f8
diff -r 77bee0cbebfe -r 3d13a06bcd3a ThreadsAndFunctions.h --- a/ThreadsAndFunctions.h Sat Jun 18 09:07:28 2016 +0000 +++ b/ThreadsAndFunctions.h Sun Jul 03 05:37:25 2016 +0000 @@ -23,6 +23,7 @@ linktest_tc->TC_string[9] = (crc16 & 0xFF00)>>8;\ linktest_tc->TC_string[10] = (crc16 & 0x00FF);\ tm_ptr = FCTN_CDMS_RLY_TMTC(linktest_tc);\ + delete linktest_tc;\ } #define Pause_gPAY_SPI{\ @@ -66,6 +67,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(); @@ -101,7 +108,7 @@ for(int i = 0 ; i < TM_LONG_SIZE ; ++i){\ /*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;\ @@ -112,6 +119,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");*/\ } @@ -126,6 +134,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);\ } @@ -140,6 +149,7 @@ gFLAGS = gFLAGS & (~UART_INT_FLAG); if( !(gFLAGS & COM_SESSION_FLAG) ){ // PENDING : DISABLE THREADS + // gCDMS_HK_TIMER.stop(); Base_tm *tm_ptr = new Short_tm; SPI_LINK_TEST(tm_ptr); /*DELETE THE TM AFTER USE*/\ @@ -161,6 +171,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 ){ @@ -179,10 +190,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(10000); + Thread::wait(10000);/*For testing with transmitter. To be removed later*/ gFLAGS = gFLAGS & (~NEW_TC_RECEIVED); gFLAGS = gFLAGS | COM_MNG_TMTC_RUNNING_FLAG; @@ -210,30 +226,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; - // 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{ /*gPC.puts("GS code mismatch !!\r\n");*/ @@ -241,10 +251,11 @@ reset_all; gFLAGS = gFLAGS & (~COM_SESSION_VALIDITY); // PENDING : ENABLE THREADS + // gCDMS_HK_TIMER.start(5000); Init_gPAY_SPI; gSESSION_TIMEOUT.detach(); gFLAGS = gFLAGS & (~COM_SESSION_FLAG); - // WARNING: clear COM_MNG_TMTC ? + gFLAGS = gFLAGS & (~COM_MNG_TMTC_RUNNING_FLAG); } } else{ @@ -275,7 +286,7 @@ } //gPC.puts("\r\n"); COM_POWER_ON_TX; - // COM_TX_CNTRL = 0; + COM_TX_CNTRL = 0; RX1M.attach(&rx_read, Serial::RxIrq); gFLAGS = gFLAGS & (~COM_MNG_TMTC_RUNNING_FLAG); } @@ -295,6 +306,7 @@ gFLAGS = gFLAGS & (~COM_MNG_TMTC_RUNNING_FLAG); reset_all; // PENDING : ENABLE THREADS + // gCDMS_HK_TIMER.start(5000); Init_gPAY_SPI; gSESSION_TIMEOUT.detach(); gFLAGS = gFLAGS & (~COM_SESSION_FLAG); @@ -302,40 +314,28 @@ } 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; } } - } + } else if( gFLAGS & COM_SESSION_TIMEOUT_FLAG ){ /*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); @@ -347,6 +347,7 @@ COM_POWER_OFF_TX; reset_all; // PENDING : ENABLE THREADS + // gCDMS_HK_TIMER.start(5000); Init_gPAY_SPI; gSESSION_TIMEOUT.detach(); gFLAGS = gFLAGS & (~COM_SESSION_FLAG);