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