CDMS code for testing sbc
Dependencies: FreescaleIAP SimpleDMA mbed-rtos mbed
Fork of CDMS_CODE by
ThreadsAndFunctions.h@134:4694fc291ce1, 2016-03-01 (annotated)
- Committer:
- ee12b079
- Date:
- Tue Mar 01 17:42:30 2016 +0000
- Revision:
- 134:4694fc291ce1
- Parent:
- 124:7f0d823c5881
- Child:
- 135:522f7d73d04f
testing
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
shreeshas95 | 0:f016e9e8d48b | 1 | // UART ISR |
shreeshas95 | 0:f016e9e8d48b | 2 | void rx_read(){ |
shreeshas95 | 2:2caf2a9a13aa | 3 | gRX_CURRENT_DATA_NODE->values[gRX_COUNT] = RX1M.getc(); |
shreeshas95 | 2:2caf2a9a13aa | 4 | gFLAGS = gFLAGS | UART_INT_FLAG; |
shreeshas95 | 0:f016e9e8d48b | 5 | gCOM_MNG_TMTC_THREAD->signal_set(COM_MNG_TMTC_SIGNAL_UART_INT); |
shreeshas95 | 0:f016e9e8d48b | 6 | } |
shreeshas95 | 0:f016e9e8d48b | 7 | |
shreeshas95 | 0:f016e9e8d48b | 8 | // RX_TIMEOUT ISR |
shreeshas95 | 0:f016e9e8d48b | 9 | void after_receive(){ |
shreeshas95 | 0:f016e9e8d48b | 10 | gRX_TIMEOUT.detach(); |
shreeshas95 | 2:2caf2a9a13aa | 11 | gFLAGS = gFLAGS | NEW_TC_RECEIVED; |
shreeshas95 | 0:f016e9e8d48b | 12 | gCOM_MNG_TMTC_THREAD->signal_set(COM_MNG_TMTC_SIGNAL_UART_INT); |
shreeshas95 | 0:f016e9e8d48b | 13 | } |
shreeshas95 | 0:f016e9e8d48b | 14 | |
shreeshas95 | 0:f016e9e8d48b | 15 | // SESSION_TIMOUT ISR |
shreeshas95 | 0:f016e9e8d48b | 16 | void after_session(){ |
shreeshas95 | 0:f016e9e8d48b | 17 | gSESSION_TIMEOUT.detach(); |
shreeshas95 | 6:79d422d1ed42 | 18 | gFLAGS = gFLAGS | COM_SESSION_TIMEOUT_FLAG; |
shreeshas95 | 6:79d422d1ed42 | 19 | if( gMASTER_STATE != TCL_STATE_EXECUTING ){ |
shreeshas95 | 6:79d422d1ed42 | 20 | gCOM_MNG_TMTC_THREAD->signal_set(COM_MNG_TMTC_SIGNAL_UART_INT); |
shreeshas95 | 6:79d422d1ed42 | 21 | } |
shreeshas95 | 0:f016e9e8d48b | 22 | } |
shreeshas95 | 0:f016e9e8d48b | 23 | |
shreeshas95 | 0:f016e9e8d48b | 24 | #define reset_all {\ |
shreeshas95 | 0:f016e9e8d48b | 25 | Base_tc *tcp = gHEAD_NODE_TCL;\ |
ee12b079 | 134:4694fc291ce1 | 26 | if (DEBUG)\ |
ee12b079 | 134:4694fc291ce1 | 27 | gPC.puts("inside reset\r\n");\ |
shreeshas95 | 5:ab276a17ca07 | 28 | gFLAGS = 0x0000;\ |
shreeshas95 | 0:f016e9e8d48b | 29 | while(tcp != NULL){\ |
shreeshas95 | 0:f016e9e8d48b | 30 | Base_tc *temp = tcp->next_TC;\ |
shreeshas95 | 0:f016e9e8d48b | 31 | delete tcp;\ |
shreeshas95 | 0:f016e9e8d48b | 32 | tcp = temp;\ |
shreeshas95 | 0:f016e9e8d48b | 33 | }\ |
shreeshas95 | 5:ab276a17ca07 | 34 | gHEAD_NODE_TCL = NULL;\ |
shreeshas95 | 5:ab276a17ca07 | 35 | gLAST_NODE_TCL = NULL;\ |
shreeshas95 | 5:ab276a17ca07 | 36 | gMASTER_STATE = TCL_STATE_INCOMPLETE;\ |
shreeshas95 | 0:f016e9e8d48b | 37 | gTOTAL_INCORRECT_SIZE_TC = 0;\ |
shreeshas95 | 0:f016e9e8d48b | 38 | gTOTAL_CRC_FAIL_TC = 0;\ |
shreeshas95 | 2:2caf2a9a13aa | 39 | gTOTAL_REPEATED_TC = 0;\ |
shreeshas95 | 5:ab276a17ca07 | 40 | gTOTAL_VALID_TC = 0;\ |
shreeshas95 | 5:ab276a17ca07 | 41 | for(int i = 0 ; i < TM_LONG_SIZE ; ++i){\ |
shreeshas95 | 5:ab276a17ca07 | 42 | gLAST_TM[i] = 0x00;\ |
shreeshas95 | 5:ab276a17ca07 | 43 | }\ |
shreeshas95 | 5:ab276a17ca07 | 44 | gLAST_TM_SHORT_OR_LONG = SHORT_TM_CODE;\ |
shreeshas95 | 0:f016e9e8d48b | 45 | COM_RX_DATA_NODE *dataptr = gRX_HEAD_DATA_NODE;\ |
shreeshas95 | 0:f016e9e8d48b | 46 | while( dataptr != NULL ){\ |
shreeshas95 | 0:f016e9e8d48b | 47 | COM_RX_DATA_NODE *temp = dataptr->next_node;\ |
shreeshas95 | 0:f016e9e8d48b | 48 | delete dataptr;\ |
shreeshas95 | 0:f016e9e8d48b | 49 | dataptr = temp;\ |
shreeshas95 | 0:f016e9e8d48b | 50 | }\ |
shreeshas95 | 0:f016e9e8d48b | 51 | gRX_HEAD_DATA_NODE = new COM_RX_DATA_NODE;\ |
shreeshas95 | 0:f016e9e8d48b | 52 | gRX_HEAD_DATA_NODE->next_node = NULL;\ |
shreeshas95 | 0:f016e9e8d48b | 53 | gRX_CURRENT_DATA_NODE = gRX_HEAD_DATA_NODE;\ |
shreeshas95 | 0:f016e9e8d48b | 54 | gRX_COUNT = 0;\ |
shreeshas95 | 2:2caf2a9a13aa | 55 | /*PENDING : ALL GLOBAL VAARIABLES AND FLAGS*/\ |
ee12b079 | 134:4694fc291ce1 | 56 | if (DEBUG)\ |
ee12b079 | 134:4694fc291ce1 | 57 | gPC.puts("finished reset all\r\n");\ |
shreeshas95 | 2:2caf2a9a13aa | 58 | } |
shreeshas95 | 2:2caf2a9a13aa | 59 | |
shreeshas95 | 2:2caf2a9a13aa | 60 | #define PUT_RAW_BYTE {\ |
shreeshas95 | 2:2caf2a9a13aa | 61 | if( gRX_COUNT < (RX_BUFFER_LENGTH-1) ){\ |
shreeshas95 | 2:2caf2a9a13aa | 62 | ++gRX_COUNT;\ |
shreeshas95 | 2:2caf2a9a13aa | 63 | }\ |
shreeshas95 | 2:2caf2a9a13aa | 64 | else{\ |
shreeshas95 | 2:2caf2a9a13aa | 65 | gRX_COUNT = 0;\ |
shreeshas95 | 2:2caf2a9a13aa | 66 | gRX_CURRENT_DATA_NODE->next_node = new COM_RX_DATA_NODE;\ |
shreeshas95 | 2:2caf2a9a13aa | 67 | gRX_CURRENT_DATA_NODE = gRX_CURRENT_DATA_NODE->next_node;\ |
shreeshas95 | 2:2caf2a9a13aa | 68 | gRX_CURRENT_DATA_NODE->next_node = NULL;\ |
shreeshas95 | 2:2caf2a9a13aa | 69 | }\ |
shreeshas95 | 2:2caf2a9a13aa | 70 | gRX_TIMEOUT.attach(&after_receive, RX_TIMEOUT_LIMIT);\ |
shreeshas95 | 0:f016e9e8d48b | 71 | } |
shreeshas95 | 0:f016e9e8d48b | 72 | |
shreeshas95 | 0:f016e9e8d48b | 73 | void COM_MNG_TMTC_FUN(void const *args){ |
shreeshas95 | 4:104dd82c99b8 | 74 | if( !(gFLAGS & COM_SESSION_FLAG) ){ |
ee12b079 | 96:4ca92f9775e0 | 75 | //gLEDR = 1; |
ee12b079 | 96:4ca92f9775e0 | 76 | //gLEDG = 1; |
shreeshas95 | 4:104dd82c99b8 | 77 | } |
shreeshas95 | 0:f016e9e8d48b | 78 | while(true){ |
shreeshas95 | 0:f016e9e8d48b | 79 | Thread::signal_wait( COM_MNG_TMTC_SIGNAL_UART_INT ); |
shreeshas95 | 0:f016e9e8d48b | 80 | if( gFLAGS & UART_INT_FLAG ){ |
shreeshas95 | 0:f016e9e8d48b | 81 | gFLAGS = gFLAGS & (~UART_INT_FLAG); |
shreeshas95 | 2:2caf2a9a13aa | 82 | if( !(gFLAGS & COM_SESSION_FLAG) ){ |
shreeshas95 | 2:2caf2a9a13aa | 83 | // PENDING : DISABLE THREADS |
shreeshas95 | 124:7f0d823c5881 | 84 | gPAY_SPI.bulkRead_end(); |
shreeshas95 | 2:2caf2a9a13aa | 85 | gFLAGS = gFLAGS | COM_SESSION_FLAG; |
shreeshas95 | 2:2caf2a9a13aa | 86 | gSESSION_TIMEOUT.attach(&after_session, SESSION_TIME_LIMIT); |
shreeshas95 | 2:2caf2a9a13aa | 87 | gFLAGS = gFLAGS | COM_RX_FLAG; |
shreeshas95 | 2:2caf2a9a13aa | 88 | PUT_RAW_BYTE; |
shreeshas95 | 2:2caf2a9a13aa | 89 | // PENDING : MEASURE RSSI |
shreeshas95 | 4:104dd82c99b8 | 90 | if( gFLAGS & COM_SESSION_FLAG ){ |
ee12b079 | 96:4ca92f9775e0 | 91 | //gLEDR = 0; |
ee12b079 | 96:4ca92f9775e0 | 92 | //gLEDG = 0; |
shreeshas95 | 4:104dd82c99b8 | 93 | } |
shreeshas95 | 2:2caf2a9a13aa | 94 | } |
shreeshas95 | 2:2caf2a9a13aa | 95 | else if( gFLAGS & COM_RX_FLAG ){ |
ee12b079 | 96:4ca92f9775e0 | 96 | //gLEDR = 0; |
ee12b079 | 96:4ca92f9775e0 | 97 | //gLEDG = 1; |
shreeshas95 | 2:2caf2a9a13aa | 98 | PUT_RAW_BYTE; |
shreeshas95 | 0:f016e9e8d48b | 99 | } |
shreeshas95 | 0:f016e9e8d48b | 100 | else{ |
ee12b079 | 96:4ca92f9775e0 | 101 | //gLEDR = 1; |
ee12b079 | 96:4ca92f9775e0 | 102 | //gLEDG = 0; |
shreeshas95 | 2:2caf2a9a13aa | 103 | gFLAGS = gFLAGS | COM_RX_FLAG; |
shreeshas95 | 2:2caf2a9a13aa | 104 | PUT_RAW_BYTE; |
shreeshas95 | 0:f016e9e8d48b | 105 | } |
shreeshas95 | 0:f016e9e8d48b | 106 | } |
shreeshas95 | 4:104dd82c99b8 | 107 | else if( gFLAGS & NEW_TC_RECEIVED ){ |
ee12b079 | 134:4694fc291ce1 | 108 | if (DEBUG) |
ee12b079 | 134:4694fc291ce1 | 109 | gPC.puts("NEW TC RECEIVED\r\n"); |
ee12b079 | 134:4694fc291ce1 | 110 | // DEBUF_PRINT("NEW TC RECEIVED\r\n"); |
ee12b079 | 96:4ca92f9775e0 | 111 | Thread::wait(2000); /*To be removed in flight model*/ |
shreeshas95 | 0:f016e9e8d48b | 112 | gFLAGS = gFLAGS & (~NEW_TC_RECEIVED); |
shreeshas95 | 4:104dd82c99b8 | 113 | gFLAGS = gFLAGS | COM_MNG_TMTC_RUNNING_FLAG; |
shreeshas95 | 2:2caf2a9a13aa | 114 | |
shreeshas95 | 0:f016e9e8d48b | 115 | // DISABLE THE RX1M INTERRUPT |
shreeshas95 | 0:f016e9e8d48b | 116 | RX1M.attach(NULL); |
shreeshas95 | 0:f016e9e8d48b | 117 | |
shreeshas95 | 4:104dd82c99b8 | 118 | // VERIFY CRC, REPEATED PSC AND UPDATE TOTAL_VALID_TC, INCORRECT SIZE TC, CRC FAIL TC |
shreeshas95 | 2:2caf2a9a13aa | 119 | while(gRX_COUNT < (RX_BUFFER_LENGTH)){ |
shreeshas95 | 2:2caf2a9a13aa | 120 | gRX_CURRENT_DATA_NODE->values[gRX_COUNT] = 0x00; |
shreeshas95 | 0:f016e9e8d48b | 121 | ++gRX_COUNT; |
shreeshas95 | 0:f016e9e8d48b | 122 | } |
shreeshas95 | 0:f016e9e8d48b | 123 | gRX_COUNT = 0; |
shreeshas95 | 4:104dd82c99b8 | 124 | raw_data_to_tc(); |
shreeshas95 | 6:79d422d1ed42 | 125 | gFLAGS = gFLAGS & (~COM_RX_FLAG); |
aniruddhv | 51:da85d84768e2 | 126 | |
shreeshas95 | 2:2caf2a9a13aa | 127 | if( gTOTAL_VALID_TC > 0 ){ |
ee12b079 | 134:4694fc291ce1 | 128 | if (DEBUG) |
ee12b079 | 134:4694fc291ce1 | 129 | gPC.printf("valid TC rx: %u\r\n", gTOTAL_VALID_TC); |
shreeshas95 | 4:104dd82c99b8 | 130 | if( gTOTAL_VALID_TC < COM_MAX_TC_LIMIT ){ |
shreeshas95 | 4:104dd82c99b8 | 131 | // CHECK WEATHER TC LIST HAS MISSING TC OR WEATHER LAST FRAME BIT IS HIGH IN THE LAST PSC-TC |
aniruddhv | 12:ffdb29353058 | 132 | /*gPC.puts("checking for tc list complete\r\n");*/ |
shreeshas95 | 4:104dd82c99b8 | 133 | uint8_t tempContinue = 0xFF; |
shreeshas95 | 4:104dd82c99b8 | 134 | continueToExecute(tempContinue); |
shreeshas95 | 4:104dd82c99b8 | 135 | if(tempContinue == 0x00){ |
aniruddhv | 12:ffdb29353058 | 136 | /*gPC.puts("tc list is complete\r\n");*/ |
shreeshas95 | 4:104dd82c99b8 | 137 | // CHECK WEATHER GS VERIFICATION CODE MATCHES |
shreeshas95 | 4:104dd82c99b8 | 138 | uint8_t tempGSver = 0x00; |
shreeshas95 | 4:104dd82c99b8 | 139 | GScodeVerification(tempGSver); |
shreeshas95 | 5:ab276a17ca07 | 140 | /*PENDING: INCLUDE GS VERIFICATION CODE*/ |
aniruddhv | 37:c9a739750806 | 141 | if( tempGSver == 0xFF ){ |
aniruddhv | 37:c9a739750806 | 142 | /*gPC.puts("GS code match !!\r\n");*/ |
shreeshas95 | 4:104dd82c99b8 | 143 | gFLAGS = gFLAGS | COM_SESSION_VALIDITY; |
shreeshas95 | 4:104dd82c99b8 | 144 | COM_POWER_ON_TX; |
shreeshas95 | 4:104dd82c99b8 | 145 | // PENDING: PA HOT HANDLED IN EXECUTE_XXX FUNCTIONS |
shreeshas95 | 4:104dd82c99b8 | 146 | uint8_t tempPAHot = 0x00; |
shreeshas95 | 4:104dd82c99b8 | 147 | isPAhot(tempPAHot); |
shreeshas95 | 4:104dd82c99b8 | 148 | if( tempPAHot == 0xFF ){ |
shreeshas95 | 6:79d422d1ed42 | 149 | gFLAGS = gFLAGS & ~(COM_PA_HOT_FLAG); |
shreeshas95 | 6:79d422d1ed42 | 150 | gCOM_PA_COOLING_TIMEOUT.detach(); |
ee12b079 | 98:fd99ddc0e0a1 | 151 | gPC.puts("EXECUTING TELECOMMANDS\r\n"); |
ee12b079 | 98:fd99ddc0e0a1 | 152 | // DEBUF_PRINT("EXECUTING TELECOMMANDS\r\n"); |
shreeshas95 | 4:104dd82c99b8 | 153 | EXECUTE_OBOSC_ONLY; |
shreeshas95 | 4:104dd82c99b8 | 154 | EXECUTE_TC; |
aniruddhv | 12:ffdb29353058 | 155 | /*gPC.puts("COMPLETED EXECUTION\r\n");*/ |
shreeshas95 | 4:104dd82c99b8 | 156 | } |
shreeshas95 | 4:104dd82c99b8 | 157 | else{ |
shreeshas95 | 4:104dd82c99b8 | 158 | gFLAGS = gFLAGS | COM_PA_HOT_FLAG; |
shreeshas95 | 6:79d422d1ed42 | 159 | // PENDING: power off transmitter only |
shreeshas95 | 6:79d422d1ed42 | 160 | gCOM_PA_COOLING_TIMEOUT.attach(&after_cooling_pa, COM_PA_COOLING_TIME_LIMIT); |
shreeshas95 | 6:79d422d1ed42 | 161 | gFLAGS = gFLAGS & (~COM_MNG_TMTC_RUNNING_FLAG); |
shreeshas95 | 4:104dd82c99b8 | 162 | RX1M.attach(&rx_read, Serial::RxIrq); |
shreeshas95 | 4:104dd82c99b8 | 163 | } |
shreeshas95 | 4:104dd82c99b8 | 164 | } |
shreeshas95 | 4:104dd82c99b8 | 165 | else{ |
aniruddhv | 12:ffdb29353058 | 166 | /*gPC.puts("GS code mismatch !!\r\n");*/ |
shreeshas95 | 6:79d422d1ed42 | 167 | RX1M.attach(&rx_read, Serial::RxIrq); |
shreeshas95 | 4:104dd82c99b8 | 168 | reset_all; |
shreeshas95 | 4:104dd82c99b8 | 169 | gFLAGS = gFLAGS & (~COM_SESSION_VALIDITY); |
shreeshas95 | 4:104dd82c99b8 | 170 | // PENDING : ENABLE THREADS |
shreeshas95 | 124:7f0d823c5881 | 171 | gPAY_SPI.bulkRead_start(); |
shreeshas95 | 4:104dd82c99b8 | 172 | gSESSION_TIMEOUT.detach(); |
shreeshas95 | 4:104dd82c99b8 | 173 | gFLAGS = gFLAGS & (~COM_SESSION_FLAG); |
shreeshas95 | 4:104dd82c99b8 | 174 | // WARNING: clear COM_MNG_TMTC ? |
shreeshas95 | 4:104dd82c99b8 | 175 | } |
shreeshas95 | 0:f016e9e8d48b | 176 | } |
shreeshas95 | 2:2caf2a9a13aa | 177 | else{ |
aniruddhv | 69:20f09a0c3fd2 | 178 | //gPC.puts("tc list is not complete\r\n"); |
shreeshas95 | 5:ab276a17ca07 | 179 | if(tempContinue & 0x01){ |
aniruddhv | 69:20f09a0c3fd2 | 180 | //gPC.puts("last packet bit not found\r\n"); |
shreeshas95 | 5:ab276a17ca07 | 181 | } |
shreeshas95 | 5:ab276a17ca07 | 182 | if( tempContinue & 0x02 ){ |
aniruddhv | 69:20f09a0c3fd2 | 183 | //gPC.puts("missing psc found\r\n"); |
shreeshas95 | 5:ab276a17ca07 | 184 | } |
aniruddhv | 69:20f09a0c3fd2 | 185 | //gPC.printf("crc fail tc = %u\r\n", gTOTAL_CRC_FAIL_TC); |
aniruddhv | 69:20f09a0c3fd2 | 186 | //gPC.printf("incorrect size tc = %u\r\n", gTOTAL_INCORRECT_SIZE_TC); |
aniruddhv | 69:20f09a0c3fd2 | 187 | //gPC.printf("repeated psc = %u\r\n", gTOTAL_REPEATED_TC); |
shreeshas95 | 5:ab276a17ca07 | 188 | Base_tc *test_tc = gHEAD_NODE_TCL; |
shreeshas95 | 5:ab276a17ca07 | 189 | while( test_tc != NULL ){ |
shreeshas95 | 5:ab276a17ca07 | 190 | int length = 0; |
shreeshas95 | 5:ab276a17ca07 | 191 | if( GETshort_or_long_tc(test_tc) == SHORT_TC_CODE ){ |
shreeshas95 | 5:ab276a17ca07 | 192 | length = TC_SHORT_SIZE; |
shreeshas95 | 5:ab276a17ca07 | 193 | } |
shreeshas95 | 5:ab276a17ca07 | 194 | else{ |
shreeshas95 | 5:ab276a17ca07 | 195 | length = TC_LONG_SIZE; |
shreeshas95 | 5:ab276a17ca07 | 196 | } |
rohit3342 | 16:538de1b20b3a | 197 | for(int i = 0 ; i < length ; ++i ){ |
aniruddhv | 69:20f09a0c3fd2 | 198 | //gPC.printf("%x ", test_tc->TC_string[i]); |
shreeshas95 | 5:ab276a17ca07 | 199 | } |
aniruddhv | 69:20f09a0c3fd2 | 200 | //gPC.puts("\r\n"); |
shreeshas95 | 5:ab276a17ca07 | 201 | test_tc = test_tc->next_TC; |
shreeshas95 | 5:ab276a17ca07 | 202 | } |
aniruddhv | 69:20f09a0c3fd2 | 203 | //gPC.puts("\r\n"); |
shreeshas95 | 4:104dd82c99b8 | 204 | COM_POWER_ON_TX; |
shreeshas95 | 4:104dd82c99b8 | 205 | // PENDING : POWER OFF TX |
shreeshas95 | 4:104dd82c99b8 | 206 | RX1M.attach(&rx_read, Serial::RxIrq); |
shreeshas95 | 4:104dd82c99b8 | 207 | gFLAGS = gFLAGS & (~COM_MNG_TMTC_RUNNING_FLAG); |
shreeshas95 | 2:2caf2a9a13aa | 208 | } |
shreeshas95 | 0:f016e9e8d48b | 209 | } |
shreeshas95 | 0:f016e9e8d48b | 210 | else{ |
shreeshas95 | 4:104dd82c99b8 | 211 | COM_POWER_ON_TX; |
shreeshas95 | 6:79d422d1ed42 | 212 | // POWER OFF TX transmitter only |
shreeshas95 | 4:104dd82c99b8 | 213 | // WARNING: reset_all ? clear com_session ? |
shreeshas95 | 2:2caf2a9a13aa | 214 | RX1M.attach(&rx_read, Serial::RxIrq); |
shreeshas95 | 4:104dd82c99b8 | 215 | gFLAGS = gFLAGS & (~COM_MNG_TMTC_RUNNING_FLAG); |
shreeshas95 | 0:f016e9e8d48b | 216 | } |
shreeshas95 | 2:2caf2a9a13aa | 217 | } |
shreeshas95 | 4:104dd82c99b8 | 218 | else{ |
aniruddhv | 12:ffdb29353058 | 219 | /*gPC.puts("No valid TC received\r\n");*/ |
shreeshas95 | 2:2caf2a9a13aa | 220 | RX1M.attach(&rx_read, Serial::RxIrq); |
shreeshas95 | 4:104dd82c99b8 | 221 | gFLAGS = gFLAGS & (~COM_MNG_TMTC_RUNNING_FLAG); |
shreeshas95 | 6:79d422d1ed42 | 222 | reset_all; |
shreeshas95 | 6:79d422d1ed42 | 223 | // PENDING : ENABLE THREADS |
shreeshas95 | 124:7f0d823c5881 | 224 | gPAY_SPI.bulkRead_start(); |
shreeshas95 | 6:79d422d1ed42 | 225 | gSESSION_TIMEOUT.detach(); |
shreeshas95 | 6:79d422d1ed42 | 226 | gFLAGS = gFLAGS & (~COM_SESSION_FLAG); |
shreeshas95 | 2:2caf2a9a13aa | 227 | } |
shreeshas95 | 2:2caf2a9a13aa | 228 | } |
shreeshas95 | 2:2caf2a9a13aa | 229 | else if( gFLAGS & COM_PA_HOT_FLAG ){ |
aniruddhv | 12:ffdb29353058 | 230 | /*gPC.puts("checking for PA hot in main\r\n");*/ |
shreeshas95 | 6:79d422d1ed42 | 231 | if( gFLAGS & COM_RX_FLAG ){ |
shreeshas95 | 6:79d422d1ed42 | 232 | uint8_t tempPA = 0xFF; |
shreeshas95 | 6:79d422d1ed42 | 233 | isPAhot(tempPA); |
shreeshas95 | 6:79d422d1ed42 | 234 | if( tempPA == 0x00 ){ |
shreeshas95 | 6:79d422d1ed42 | 235 | gCOM_PA_COOLING_TIMEOUT.attach(&after_cooling_pa, COM_PA_COOLING_TIME_LIMIT); |
shreeshas95 | 6:79d422d1ed42 | 236 | } |
shreeshas95 | 6:79d422d1ed42 | 237 | else{ |
shreeshas95 | 6:79d422d1ed42 | 238 | gFLAGS = gFLAGS & ~(COM_PA_HOT_FLAG); |
shreeshas95 | 6:79d422d1ed42 | 239 | gCOM_PA_COOLING_TIMEOUT.detach(); |
shreeshas95 | 6:79d422d1ed42 | 240 | } |
shreeshas95 | 0:f016e9e8d48b | 241 | } |
shreeshas95 | 0:f016e9e8d48b | 242 | else{ |
shreeshas95 | 6:79d422d1ed42 | 243 | uint8_t tempPA = 0xFF; |
shreeshas95 | 6:79d422d1ed42 | 244 | isPAhot(tempPA); |
shreeshas95 | 6:79d422d1ed42 | 245 | if( tempPA == 0x00 ){ |
shreeshas95 | 6:79d422d1ed42 | 246 | gCOM_PA_COOLING_TIMEOUT.attach(&after_cooling_pa, COM_PA_COOLING_TIME_LIMIT); |
shreeshas95 | 6:79d422d1ed42 | 247 | } |
shreeshas95 | 6:79d422d1ed42 | 248 | else{ |
aniruddhv | 12:ffdb29353058 | 249 | /*gPC.puts("PA IS COOLED DOWN\r\n");*/ |
shreeshas95 | 6:79d422d1ed42 | 250 | gFLAGS = gFLAGS & (~COM_PA_HOT_FLAG); |
shreeshas95 | 6:79d422d1ed42 | 251 | gFLAGS = gFLAGS | COM_MNG_TMTC_RUNNING_FLAG; |
shreeshas95 | 6:79d422d1ed42 | 252 | RX1M.attach(NULL); |
shreeshas95 | 6:79d422d1ed42 | 253 | gCOM_PA_COOLING_TIMEOUT.detach(); |
shreeshas95 | 6:79d422d1ed42 | 254 | COM_POWER_ON_TX; |
shreeshas95 | 6:79d422d1ed42 | 255 | EXECUTE_OBOSC_ONLY; |
shreeshas95 | 6:79d422d1ed42 | 256 | EXECUTE_TC; |
shreeshas95 | 6:79d422d1ed42 | 257 | } |
shreeshas95 | 0:f016e9e8d48b | 258 | } |
shreeshas95 | 2:2caf2a9a13aa | 259 | } |
shreeshas95 | 6:79d422d1ed42 | 260 | else if( gFLAGS & COM_SESSION_TIMEOUT_FLAG ){ |
aniruddhv | 12:ffdb29353058 | 261 | /*gPC.puts("session timeout: resetting in main\r\n");*/ |
shreeshas95 | 6:79d422d1ed42 | 262 | COM_POWER_OFF_TX; |
shreeshas95 | 6:79d422d1ed42 | 263 | /*PENDING : ENABLE THREADS*/ |
shreeshas95 | 124:7f0d823c5881 | 264 | gPAY_SPI.bulkRead_start(); |
shreeshas95 | 6:79d422d1ed42 | 265 | gSESSION_TIMEOUT.detach(); |
shreeshas95 | 6:79d422d1ed42 | 266 | gFLAGS = gFLAGS & (~COM_MNG_TMTC_RUNNING_FLAG); |
shreeshas95 | 6:79d422d1ed42 | 267 | gFLAGS = gFLAGS & (~COM_SESSION_FLAG); |
shreeshas95 | 6:79d422d1ed42 | 268 | reset_all; |
shreeshas95 | 6:79d422d1ed42 | 269 | } |
shreeshas95 | 2:2caf2a9a13aa | 270 | else{ |
aniruddhv | 12:ffdb29353058 | 271 | /*gPC.puts("INVALID SIGNAL RECEIVED IN MAIN\r\n");*/ |
shreeshas95 | 2:2caf2a9a13aa | 272 | // SOME INVALID SIGNAL RECEIVED |
shreeshas95 | 4:104dd82c99b8 | 273 | COM_POWER_OFF_TX; |
shreeshas95 | 2:2caf2a9a13aa | 274 | reset_all; |
shreeshas95 | 2:2caf2a9a13aa | 275 | // PENDING : ENABLE THREADS |
shreeshas95 | 124:7f0d823c5881 | 276 | gPAY_SPI.bulkRead_start(); |
shreeshas95 | 2:2caf2a9a13aa | 277 | gSESSION_TIMEOUT.detach(); |
shreeshas95 | 2:2caf2a9a13aa | 278 | gFLAGS = gFLAGS & (~COM_SESSION_FLAG); |
shreeshas95 | 0:f016e9e8d48b | 279 | } |
shreeshas95 | 0:f016e9e8d48b | 280 | } |
shreeshas95 | 3:6c81fc8834e2 | 281 | } |
shreeshas95 | 3:6c81fc8834e2 | 282 | |
shreeshas95 | 101:bece931236a2 | 283 | void payload_isr_fun(){ |
shreeshas95 | 101:bece931236a2 | 284 | gSCIENCE_THREAD->signal_set(SCIENCE_SIGNAL); |
shreeshas95 | 101:bece931236a2 | 285 | } |
ee12b079 | 93:4d76de54a699 | 286 | |
ee12b079 | 96:4ca92f9775e0 | 287 | void SCIENCE_FUN(void const *args){ |
ee12b079 | 96:4ca92f9775e0 | 288 | |
shreeshas95 | 101:bece931236a2 | 289 | // initialisation of payload spi |
shreeshas95 | 101:bece931236a2 | 290 | gPAY_SPI.frequency(1000000); |
shreeshas95 | 101:bece931236a2 | 291 | gPAY_SPI.format(8,0); |
shreeshas95 | 101:bece931236a2 | 292 | gPAY_SPI.bulkRead_init(gPAYLOAD_BUFFER, PAYLOAD_BUFFER_LENGTH, &payload_isr_fun); |
shreeshas95 | 101:bece931236a2 | 293 | gPAY_SPI.bulkRead_start(); |
ee12b079 | 96:4ca92f9775e0 | 294 | |
ee12b079 | 97:717c7908c822 | 295 | while(true){ |
ee12b079 | 98:fd99ddc0e0a1 | 296 | gPC.puts("entering sci\r\n"); |
ee12b079 | 97:717c7908c822 | 297 | gSCIENCE_THREAD->signal_wait(SCIENCE_SIGNAL); |
ee12b079 | 98:fd99ddc0e0a1 | 298 | gPC.puts("sig_set\r\n"); |
shreeshas95 | 101:bece931236a2 | 299 | srp(gPAYLOAD_BUFFER); |
ee12b079 | 98:fd99ddc0e0a1 | 300 | gPC.puts("exit_srp\r\n"); |
shreeshas95 | 101:bece931236a2 | 301 | gPAY_SPI.bulkRead_start(); |
ee12b079 | 97:717c7908c822 | 302 | } |
shreeshas95 | 101:bece931236a2 | 303 | } |