
Compression code changed and RLY_TMTC pointers managed
Dependencies: FreescaleIAP SimpleDMA mbed-rtos mbed
Fork of CDMS_CODE by
Diff: ThreadsAndFunctions.h
- Revision:
- 179:67588115bca3
- Parent:
- 144:4c20fcc105ce
- Child:
- 180:ccc21cc163f8
--- a/ThreadsAndFunctions.h Fri Apr 22 13:13:42 2016 +0000 +++ b/ThreadsAndFunctions.h Fri Apr 22 19:43:13 2016 +0000 @@ -1,3 +1,64 @@ +//Science Thread +//SPI ISR +void payload_isr_fun(){ + gSCIENCE_THREAD->signal_set(SCIENCE_SIGNAL); +} + +#define SPI_LINK_TEST(tm_ptr) {\ + Base_tc *linktest_tc = new Short_tc;\ + linktest_tc->next_TC = NULL;\ + PUTshort_or_long(linktest_tc,SHORT_TC_CODE);\ + PUTcrc_pass(linktest_tc,0x1);\ + PUTexec_status(linktest_tc,0);\ + linktest_tc->TC_string[0] = 0x01;\ + linktest_tc->TC_string[1] = 0xC0;\ + linktest_tc->TC_string[2] = 0x81;\ + linktest_tc->TC_string[3] = 0xD1;\ + linktest_tc->TC_string[4] = 0;\ + linktest_tc->TC_string[5] = 0;\ + linktest_tc->TC_string[6] = 0;\ + linktest_tc->TC_string[7] = 0;\ + linktest_tc->TC_string[8] = 0;\ + uint16_t crc16 = crc16_gen(linktest_tc->TC_string, 9);\ + linktest_tc->TC_string[9] = (crc16 & 0xFF00)>>8;\ + linktest_tc->TC_string[10] = (crc16 & 0x00FF);\ + tm_ptr = FCTN_CDMS_RLY_TMTC(linktest_tc);\ +} + +#define Pause_gPAY_SPI{\ + gPAY_SPI.bulkRead_init(gPAYLOAD_BUFFER, PAYLOAD_BUFFER_LENGTH, NULL);\ + gPAY_SPI.bulkRead_start();\ + } + + +#define Init_gPAY_SPI{\ + gPAY_SPI.bulkRead_init(gPAYLOAD_BUFFER, PAYLOAD_BUFFER_LENGTH, &payload_isr_fun);\ + gPAY_SPI.bulkRead_start();\ + } + +void SCIENCE_FUN(void const *args){ + + // initialisation of payload spi + gPAY_SPI.frequency(1000000); + gPAY_SPI.format(8,0); + gPAY_SPI.bulkRead_init(gPAYLOAD_BUFFER, PAYLOAD_BUFFER_LENGTH, &payload_isr_fun); + gPAY_SPI.bulkRead_start(); + Pause_gPAY_SPI; + Init_gPAY_SPI; + + + while(true){ + gPC.puts("entering sci\r\n"); + gSCIENCE_THREAD->signal_wait(SCIENCE_SIGNAL); + gPC.puts("sig_set\r\n"); + srp(gPAYLOAD_BUFFER); + gPC.puts("exit_srp\r\n"); + gPAY_SPI.bulkRead_start(); + + } +} + +//COM THREAD // UART ISR void rx_read(){ gRX_CURRENT_DATA_NODE->values[gRX_COUNT] = RX1M.getc(); @@ -23,8 +84,7 @@ #define reset_all {\ Base_tc *tcp = gHEAD_NODE_TCL;\ - if (DEBUG)\ - gPC.puts("inside reset\r\n");\ + /*gPC.puts("inside reset\r\n");*/\ gFLAGS = 0x0000;\ while(tcp != NULL){\ Base_tc *temp = tcp->next_TC;\ @@ -53,8 +113,7 @@ gRX_CURRENT_DATA_NODE = gRX_HEAD_DATA_NODE;\ gRX_COUNT = 0;\ /*PENDING : ALL GLOBAL VAARIABLES AND FLAGS*/\ - if (DEBUG)\ - gPC.puts("finished reset all\r\n");\ + /*gPC.puts("finished reset all\r\n");*/\ } #define PUT_RAW_BYTE {\ @@ -81,7 +140,24 @@ gFLAGS = gFLAGS & (~UART_INT_FLAG); if( !(gFLAGS & COM_SESSION_FLAG) ){ // PENDING : DISABLE THREADS - gPAY_SPI.bulkRead_end(); + Base_tm *tm_ptr = new Short_tm; + SPI_LINK_TEST(tm_ptr); + /*DELETE THE TM AFTER USE*/\ + Base_tm *del_tm = tm_ptr;\ + int overCount = 0;\ + while( del_tm != NULL ){\ + if( (overCount < TM_OVERFLOW_CONSTANT) ){\ + Base_tm *temp = del_tm->next_TM;\ + delete del_tm;\ + del_tm = temp;\ + ++overCount;\ + }\ + else{\ + RESET_CDMS;\ + break;\ + }\ + }\ + Pause_gPAY_SPI; gFLAGS = gFLAGS | COM_SESSION_FLAG; gSESSION_TIMEOUT.attach(&after_session, SESSION_TIME_LIMIT); gFLAGS = gFLAGS | COM_RX_FLAG; @@ -105,10 +181,8 @@ } } else if( gFLAGS & NEW_TC_RECEIVED ){ - if (DEBUG) - gPC.puts("NEW TC RECEIVED\r\n"); -// DEBUF_PRINT("NEW TC RECEIVED\r\n"); - Thread::wait(2000); /*To be removed in flight model*/ + gPC.puts("NEW TC RECEIVED\r\n"); + Thread::wait(10000); gFLAGS = gFLAGS & (~NEW_TC_RECEIVED); gFLAGS = gFLAGS | COM_MNG_TMTC_RUNNING_FLAG; @@ -125,39 +199,33 @@ gFLAGS = gFLAGS & (~COM_RX_FLAG); if( gTOTAL_VALID_TC > 0 ){ - if (DEBUG) - gPC.printf("valid TC rx: %u\r\n", gTOTAL_VALID_TC); + /*gPC.printf("valid TC rx: %u\r\n", gTOTAL_VALID_TC);*/ if( gTOTAL_VALID_TC < COM_MAX_TC_LIMIT ){ // CHECK WEATHER TC LIST HAS MISSING TC OR WEATHER LAST FRAME BIT IS HIGH IN THE LAST PSC-TC - if (DEBUG) - gPC.puts("checking for tc list complete\r\n"); + /*gPC.puts("checking for tc list complete\r\n");*/ uint8_t tempContinue = 0xFF; continueToExecute(tempContinue); if(tempContinue == 0x00){ - if (DEBUG) - gPC.puts("tc list is complete\r\n"); + /*gPC.puts("tc list is complete\r\n");*/ // CHECK WEATHER GS VERIFICATION CODE MATCHES uint8_t tempGSver = 0x00; GScodeVerification(tempGSver); /*PENDING: INCLUDE GS VERIFICATION CODE*/ if( tempGSver == 0xFF ){ - if (DEBUG) - gPC.puts("GS code match !!\r\n"); + /*gPC.puts("GS code match !!\r\n");*/ gFLAGS = gFLAGS | COM_SESSION_VALIDITY; - COM_POWER_ON_TX(); + 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); gCOM_PA_COOLING_TIMEOUT.detach(); - if (DEBUG) - gPC.puts("EXECUTING TELECOMMANDS\r\n"); -// DEBUF_PRINT("EXECUTING TELECOMMANDS\r\n"); + gPC.puts("EXECUTING TELECOMMANDS\r\n"); +// DEBUF_PRINT("EXECUTING TELECOMMANDS\r\n"); EXECUTE_OBOSC_ONLY; EXECUTE_TC; - if (DEBUG) - gPC.puts("COMPLETED EXECUTION\r\n"); + gPC.puts("COMPLETED EXECUTION\r\n"); } else{ gFLAGS = gFLAGS | COM_PA_HOT_FLAG; @@ -168,35 +236,28 @@ } } else{ - if(DEBUG) - gPC.puts("GS code mismatch !!\r\n"); + /*gPC.puts("GS code mismatch !!\r\n");*/ RX1M.attach(&rx_read, Serial::RxIrq); reset_all; gFLAGS = gFLAGS & (~COM_SESSION_VALIDITY); // PENDING : ENABLE THREADS - gPAY_SPI.bulkRead_start(); + Init_gPAY_SPI; gSESSION_TIMEOUT.detach(); gFLAGS = gFLAGS & (~COM_SESSION_FLAG); // WARNING: clear COM_MNG_TMTC ? } } else{ - if (DEBUG) - gPC.puts("tc list is not complete\r\n"); + gPC.puts("tc list is not complete\r\n"); if(tempContinue & 0x01){ - if (DEBUG) - gPC.puts("last packet bit not found\r\n"); + //gPC.puts("last packet bit not found\r\n"); } if( tempContinue & 0x02 ){ - if (DEBUG) - gPC.puts("missing psc found\r\n"); + //gPC.puts("missing psc found\r\n"); } - if (DEBUG){ - gPC.printf("crc fail tc = %u\r\n", gTOTAL_CRC_FAIL_TC); - gPC.printf("incorrect size tc = %u\r\n", gTOTAL_INCORRECT_SIZE_TC); - gPC.printf("repeated psc = %u\r\n", gTOTAL_REPEATED_TC); - gPC.puts("\r\n"); - } + //gPC.printf("crc fail tc = %u\r\n", gTOTAL_CRC_FAIL_TC); + //gPC.printf("incorrect size tc = %u\r\n", gTOTAL_INCORRECT_SIZE_TC); + //gPC.printf("repeated psc = %u\r\n", gTOTAL_REPEATED_TC); Base_tc *test_tc = gHEAD_NODE_TCL; while( test_tc != NULL ){ int length = 0; @@ -207,24 +268,20 @@ length = TC_LONG_SIZE; } for(int i = 0 ; i < length ; ++i ){ - int x = 128; - for( int j = 7 ; j >= 0 ; --j ){ - gPC.printf("%d", (test_tc->TC_string[i] & x)>>j); - x = x/2; - } + //gPC.printf("%x ", test_tc->TC_string[i]); } - gPC.puts("\r\n"); + //gPC.puts("\r\n"); test_tc = test_tc->next_TC; } //gPC.puts("\r\n"); - COM_POWER_ON_TX(); + COM_POWER_ON_TX; // PENDING : POWER OFF TX RX1M.attach(&rx_read, Serial::RxIrq); gFLAGS = gFLAGS & (~COM_MNG_TMTC_RUNNING_FLAG); } } else{ - COM_POWER_ON_TX(); + COM_POWER_ON_TX; // POWER OFF TX transmitter only // WARNING: reset_all ? clear com_session ? RX1M.attach(&rx_read, Serial::RxIrq); @@ -232,20 +289,18 @@ } } else{ - if (DEBUG) - gPC.puts("No valid TC received\r\n"); + gPC.puts("No valid TC received\r\n"); RX1M.attach(&rx_read, Serial::RxIrq); gFLAGS = gFLAGS & (~COM_MNG_TMTC_RUNNING_FLAG); reset_all; // PENDING : ENABLE THREADS - gPAY_SPI.bulkRead_start(); + Init_gPAY_SPI; gSESSION_TIMEOUT.detach(); gFLAGS = gFLAGS & (~COM_SESSION_FLAG); } } else if( gFLAGS & COM_PA_HOT_FLAG ){ - if (DEBUG) - gPC.puts("checking for PA hot in main\r\n"); + /*gPC.puts("checking for PA hot in main\r\n");*/ if( gFLAGS & COM_RX_FLAG ){ uint8_t tempPA = 0xFF; isPAhot(tempPA); @@ -269,55 +324,31 @@ gFLAGS = gFLAGS | COM_MNG_TMTC_RUNNING_FLAG; RX1M.attach(NULL); gCOM_PA_COOLING_TIMEOUT.detach(); - COM_POWER_ON_TX(); + COM_POWER_ON_TX; EXECUTE_OBOSC_ONLY; EXECUTE_TC; } } } else if( gFLAGS & COM_SESSION_TIMEOUT_FLAG ){ - if (DEBUG) - gPC.puts("session timeout: resetting in main\r\n"); + /*gPC.puts("session timeout: resetting in main\r\n");*/ COM_POWER_OFF_TX; /*PENDING : ENABLE THREADS*/ - gPAY_SPI.bulkRead_start(); + gSESSION_TIMEOUT.detach(); gFLAGS = gFLAGS & (~COM_MNG_TMTC_RUNNING_FLAG); gFLAGS = gFLAGS & (~COM_SESSION_FLAG); reset_all; } else{ - if (DEBUG) - gPC.puts("INVALID SIGNAL RECEIVED IN MAIN\r\n"); + /*gPC.puts("INVALID SIGNAL RECEIVED IN MAIN\r\n");*/ // SOME INVALID SIGNAL RECEIVED COM_POWER_OFF_TX; reset_all; // PENDING : ENABLE THREADS - gPAY_SPI.bulkRead_start(); + Init_gPAY_SPI; gSESSION_TIMEOUT.detach(); gFLAGS = gFLAGS & (~COM_SESSION_FLAG); } } -} - -void payload_isr_fun(){ - gSCIENCE_THREAD->signal_set(SCIENCE_SIGNAL); -} - -void SCIENCE_FUN(void const *args){ - - // initialisation of payload spi - gPAY_SPI.frequency(1000000); - gPAY_SPI.format(8,0); - gPAY_SPI.bulkRead_init(gPAYLOAD_BUFFER, PAYLOAD_BUFFER_LENGTH, &payload_isr_fun); - gPAY_SPI.bulkRead_start(); - - while(true){ - gPC.puts("entering science thread\r\n"); - gSCIENCE_THREAD->signal_wait(SCIENCE_SIGNAL); - gPC.puts("sig_set\r\n"); - srp(gPAYLOAD_BUFFER); - gPC.puts("exit_srp\r\n"); - gPAY_SPI.bulkRead_start(); - } } \ No newline at end of file