DMA issue to be tested
Dependencies: FreescaleIAP SimpleDMA mbed-rtos mbed
Fork of CDMS_CODE by
Diff: ThreadsAndFunctions.h
- Revision:
- 262:752c8689944a
- Parent:
- 261:1e54415b34d3
- Child:
- 263:3b872778b8c7
diff -r 1e54415b34d3 -r 752c8689944a ThreadsAndFunctions.h --- a/ThreadsAndFunctions.h Thu Jul 14 13:07:30 2016 +0000 +++ b/ThreadsAndFunctions.h Thu Jul 14 17:57:05 2016 +0000 @@ -43,6 +43,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(); @@ -70,15 +76,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;\ @@ -89,6 +95,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");*/\ } @@ -103,6 +110,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);\ } @@ -122,6 +130,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 ){ @@ -140,6 +149,11 @@ 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"); @@ -178,26 +192,22 @@ if( tempGSver == 0xFF ){ /*gPC.puts("GS code match !!\r\n");*/ gFLAGS = gFLAGS | COM_SESSION_VALIDITY; + sys_reset_cdms_timer->start(cdms_reset_timeout); 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");*/ @@ -210,6 +220,7 @@ gSESSION_TIMEOUT.detach(); gFLAGS = gFLAGS & (~COM_SESSION_FLAG); // WARNING: clear COM_MNG_TMTC ? + gFLAGS = gFLAGS & (~COM_MNG_TMTC_RUNNING_FLAG); } } else{ @@ -241,6 +252,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); } @@ -249,6 +261,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); } @@ -267,29 +282,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;