June 30

Dependencies:   FreescaleIAP SimpleDMA mbed-rtos mbed

Fork of CDMS_CODE by shubham c

Committer:
chaithanyarss
Date:
Sat Jul 02 13:36:18 2016 +0000
Revision:
191:d14b1c783736
Parent:
187:2c7263530c57
;

Who changed what in which revision?

UserRevisionLine numberNew 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;\
aniruddhv 180:ccc21cc163f8 96 gMASTER_STATE = TCL_STATE_COMPLETED;\
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){\
aniruddhv 180:ccc21cc163f8 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){
chaithanyarss 187:2c7263530c57 138 COM_POWER_ON_TX();
shreeshas95 0:f016e9e8d48b 139 Thread::signal_wait( COM_MNG_TMTC_SIGNAL_UART_INT );
shreeshas95 0:f016e9e8d48b 140 if( gFLAGS & UART_INT_FLAG ){
shreeshas95 0:f016e9e8d48b 141 gFLAGS = gFLAGS & (~UART_INT_FLAG);
shreeshas95 2:2caf2a9a13aa 142 if( !(gFLAGS & COM_SESSION_FLAG) ){
shreeshas95 2:2caf2a9a13aa 143 // PENDING : DISABLE THREADS
aniruddhv 179:67588115bca3 144 Base_tm *tm_ptr = new Short_tm;
aniruddhv 179:67588115bca3 145 SPI_LINK_TEST(tm_ptr);
aniruddhv 179:67588115bca3 146 /*DELETE THE TM AFTER USE*/\
aniruddhv 179:67588115bca3 147 Base_tm *del_tm = tm_ptr;\
aniruddhv 179:67588115bca3 148 int overCount = 0;\
aniruddhv 179:67588115bca3 149 while( del_tm != NULL ){\
aniruddhv 179:67588115bca3 150 if( (overCount < TM_OVERFLOW_CONSTANT) ){\
aniruddhv 179:67588115bca3 151 Base_tm *temp = del_tm->next_TM;\
aniruddhv 179:67588115bca3 152 delete del_tm;\
aniruddhv 179:67588115bca3 153 del_tm = temp;\
aniruddhv 179:67588115bca3 154 ++overCount;\
aniruddhv 179:67588115bca3 155 }\
aniruddhv 179:67588115bca3 156 else{\
aniruddhv 179:67588115bca3 157 RESET_CDMS;\
aniruddhv 179:67588115bca3 158 break;\
aniruddhv 179:67588115bca3 159 }\
aniruddhv 179:67588115bca3 160 }\
aniruddhv 179:67588115bca3 161 Pause_gPAY_SPI;
shreeshas95 2:2caf2a9a13aa 162 gFLAGS = gFLAGS | COM_SESSION_FLAG;
shreeshas95 2:2caf2a9a13aa 163 gSESSION_TIMEOUT.attach(&after_session, SESSION_TIME_LIMIT);
shreeshas95 2:2caf2a9a13aa 164 gFLAGS = gFLAGS | COM_RX_FLAG;
shreeshas95 2:2caf2a9a13aa 165 PUT_RAW_BYTE;
shreeshas95 2:2caf2a9a13aa 166 // PENDING : MEASURE RSSI
shreeshas95 4:104dd82c99b8 167 if( gFLAGS & COM_SESSION_FLAG ){
ee12b079 96:4ca92f9775e0 168 //gLEDR = 0;
ee12b079 96:4ca92f9775e0 169 //gLEDG = 0;
shreeshas95 4:104dd82c99b8 170 }
shreeshas95 2:2caf2a9a13aa 171 }
shreeshas95 2:2caf2a9a13aa 172 else if( gFLAGS & COM_RX_FLAG ){
ee12b079 96:4ca92f9775e0 173 //gLEDR = 0;
ee12b079 96:4ca92f9775e0 174 //gLEDG = 1;
shreeshas95 2:2caf2a9a13aa 175 PUT_RAW_BYTE;
shreeshas95 0:f016e9e8d48b 176 }
shreeshas95 0:f016e9e8d48b 177 else{
ee12b079 96:4ca92f9775e0 178 //gLEDR = 1;
ee12b079 96:4ca92f9775e0 179 //gLEDG = 0;
shreeshas95 2:2caf2a9a13aa 180 gFLAGS = gFLAGS | COM_RX_FLAG;
shreeshas95 2:2caf2a9a13aa 181 PUT_RAW_BYTE;
shreeshas95 0:f016e9e8d48b 182 }
shreeshas95 0:f016e9e8d48b 183 }
shreeshas95 4:104dd82c99b8 184 else if( gFLAGS & NEW_TC_RECEIVED ){
aniruddhv 179:67588115bca3 185 gPC.puts("NEW TC RECEIVED\r\n");
aniruddhv 179:67588115bca3 186 Thread::wait(10000);
shreeshas95 0:f016e9e8d48b 187 gFLAGS = gFLAGS & (~NEW_TC_RECEIVED);
shreeshas95 4:104dd82c99b8 188 gFLAGS = gFLAGS | COM_MNG_TMTC_RUNNING_FLAG;
shreeshas95 2:2caf2a9a13aa 189
shreeshas95 0:f016e9e8d48b 190 // DISABLE THE RX1M INTERRUPT
shreeshas95 0:f016e9e8d48b 191 RX1M.attach(NULL);
shreeshas95 0:f016e9e8d48b 192
shreeshas95 4:104dd82c99b8 193 // VERIFY CRC, REPEATED PSC AND UPDATE TOTAL_VALID_TC, INCORRECT SIZE TC, CRC FAIL TC
shreeshas95 2:2caf2a9a13aa 194 while(gRX_COUNT < (RX_BUFFER_LENGTH)){
shreeshas95 2:2caf2a9a13aa 195 gRX_CURRENT_DATA_NODE->values[gRX_COUNT] = 0x00;
shreeshas95 0:f016e9e8d48b 196 ++gRX_COUNT;
shreeshas95 0:f016e9e8d48b 197 }
shreeshas95 0:f016e9e8d48b 198 gRX_COUNT = 0;
shreeshas95 4:104dd82c99b8 199 raw_data_to_tc();
shreeshas95 6:79d422d1ed42 200 gFLAGS = gFLAGS & (~COM_RX_FLAG);
aniruddhv 51:da85d84768e2 201
shreeshas95 2:2caf2a9a13aa 202 if( gTOTAL_VALID_TC > 0 ){
aniruddhv 179:67588115bca3 203 /*gPC.printf("valid TC rx: %u\r\n", gTOTAL_VALID_TC);*/
shreeshas95 4:104dd82c99b8 204 if( gTOTAL_VALID_TC < COM_MAX_TC_LIMIT ){
shreeshas95 4:104dd82c99b8 205 // CHECK WEATHER TC LIST HAS MISSING TC OR WEATHER LAST FRAME BIT IS HIGH IN THE LAST PSC-TC
aniruddhv 179:67588115bca3 206 /*gPC.puts("checking for tc list complete\r\n");*/
shreeshas95 4:104dd82c99b8 207 uint8_t tempContinue = 0xFF;
shreeshas95 4:104dd82c99b8 208 continueToExecute(tempContinue);
shreeshas95 4:104dd82c99b8 209 if(tempContinue == 0x00){
aniruddhv 179:67588115bca3 210 /*gPC.puts("tc list is complete\r\n");*/
shreeshas95 4:104dd82c99b8 211 // CHECK WEATHER GS VERIFICATION CODE MATCHES
shreeshas95 4:104dd82c99b8 212 uint8_t tempGSver = 0x00;
shreeshas95 4:104dd82c99b8 213 GScodeVerification(tempGSver);
shreeshas95 5:ab276a17ca07 214 /*PENDING: INCLUDE GS VERIFICATION CODE*/
aniruddhv 37:c9a739750806 215 if( tempGSver == 0xFF ){
aniruddhv 179:67588115bca3 216 /*gPC.puts("GS code match !!\r\n");*/
shreeshas95 4:104dd82c99b8 217 gFLAGS = gFLAGS | COM_SESSION_VALIDITY;
aniruddhv 179:67588115bca3 218 COM_POWER_ON_TX;
shreeshas95 4:104dd82c99b8 219 // PENDING: PA HOT HANDLED IN EXECUTE_XXX FUNCTIONS
shreeshas95 4:104dd82c99b8 220 uint8_t tempPAHot = 0x00;
shreeshas95 4:104dd82c99b8 221 isPAhot(tempPAHot);
shreeshas95 4:104dd82c99b8 222 if( tempPAHot == 0xFF ){
shreeshas95 6:79d422d1ed42 223 gFLAGS = gFLAGS & ~(COM_PA_HOT_FLAG);
shreeshas95 6:79d422d1ed42 224 gCOM_PA_COOLING_TIMEOUT.detach();
aniruddhv 179:67588115bca3 225 gPC.puts("EXECUTING TELECOMMANDS\r\n");
aniruddhv 179:67588115bca3 226 // DEBUF_PRINT("EXECUTING TELECOMMANDS\r\n");
shreeshas95 4:104dd82c99b8 227 EXECUTE_OBOSC_ONLY;
shreeshas95 4:104dd82c99b8 228 EXECUTE_TC;
aniruddhv 179:67588115bca3 229 gPC.puts("COMPLETED EXECUTION\r\n");
shreeshas95 4:104dd82c99b8 230 }
shreeshas95 4:104dd82c99b8 231 else{
shreeshas95 4:104dd82c99b8 232 gFLAGS = gFLAGS | COM_PA_HOT_FLAG;
aniruddhv 180:ccc21cc163f8 233 // COM_TX_CNTRL = 0;
shreeshas95 6:79d422d1ed42 234 gCOM_PA_COOLING_TIMEOUT.attach(&after_cooling_pa, COM_PA_COOLING_TIME_LIMIT);
shreeshas95 6:79d422d1ed42 235 gFLAGS = gFLAGS & (~COM_MNG_TMTC_RUNNING_FLAG);
shreeshas95 4:104dd82c99b8 236 RX1M.attach(&rx_read, Serial::RxIrq);
shreeshas95 4:104dd82c99b8 237 }
shreeshas95 4:104dd82c99b8 238 }
shreeshas95 4:104dd82c99b8 239 else{
aniruddhv 179:67588115bca3 240 /*gPC.puts("GS code mismatch !!\r\n");*/
shreeshas95 6:79d422d1ed42 241 RX1M.attach(&rx_read, Serial::RxIrq);
shreeshas95 4:104dd82c99b8 242 reset_all;
shreeshas95 4:104dd82c99b8 243 gFLAGS = gFLAGS & (~COM_SESSION_VALIDITY);
shreeshas95 4:104dd82c99b8 244 // PENDING : ENABLE THREADS
aniruddhv 179:67588115bca3 245 Init_gPAY_SPI;
shreeshas95 4:104dd82c99b8 246 gSESSION_TIMEOUT.detach();
shreeshas95 4:104dd82c99b8 247 gFLAGS = gFLAGS & (~COM_SESSION_FLAG);
shreeshas95 4:104dd82c99b8 248 // WARNING: clear COM_MNG_TMTC ?
shreeshas95 4:104dd82c99b8 249 }
shreeshas95 0:f016e9e8d48b 250 }
shreeshas95 2:2caf2a9a13aa 251 else{
aniruddhv 179:67588115bca3 252 gPC.puts("tc list is not complete\r\n");
shreeshas95 5:ab276a17ca07 253 if(tempContinue & 0x01){
aniruddhv 179:67588115bca3 254 //gPC.puts("last packet bit not found\r\n");
shreeshas95 5:ab276a17ca07 255 }
shreeshas95 5:ab276a17ca07 256 if( tempContinue & 0x02 ){
aniruddhv 179:67588115bca3 257 //gPC.puts("missing psc found\r\n");
shreeshas95 5:ab276a17ca07 258 }
aniruddhv 179:67588115bca3 259 //gPC.printf("crc fail tc = %u\r\n", gTOTAL_CRC_FAIL_TC);
aniruddhv 179:67588115bca3 260 //gPC.printf("incorrect size tc = %u\r\n", gTOTAL_INCORRECT_SIZE_TC);
aniruddhv 179:67588115bca3 261 //gPC.printf("repeated psc = %u\r\n", gTOTAL_REPEATED_TC);
shreeshas95 5:ab276a17ca07 262 Base_tc *test_tc = gHEAD_NODE_TCL;
shreeshas95 5:ab276a17ca07 263 while( test_tc != NULL ){
shreeshas95 5:ab276a17ca07 264 int length = 0;
shreeshas95 5:ab276a17ca07 265 if( GETshort_or_long_tc(test_tc) == SHORT_TC_CODE ){
shreeshas95 5:ab276a17ca07 266 length = TC_SHORT_SIZE;
shreeshas95 5:ab276a17ca07 267 }
shreeshas95 5:ab276a17ca07 268 else{
shreeshas95 5:ab276a17ca07 269 length = TC_LONG_SIZE;
shreeshas95 5:ab276a17ca07 270 }
rohit3342 16:538de1b20b3a 271 for(int i = 0 ; i < length ; ++i ){
aniruddhv 179:67588115bca3 272 //gPC.printf("%x ", test_tc->TC_string[i]);
shreeshas95 5:ab276a17ca07 273 }
aniruddhv 179:67588115bca3 274 //gPC.puts("\r\n");
shreeshas95 5:ab276a17ca07 275 test_tc = test_tc->next_TC;
shreeshas95 5:ab276a17ca07 276 }
aniruddhv 69:20f09a0c3fd2 277 //gPC.puts("\r\n");
aniruddhv 179:67588115bca3 278 COM_POWER_ON_TX;
aniruddhv 180:ccc21cc163f8 279 // COM_TX_CNTRL = 0;
shreeshas95 4:104dd82c99b8 280 RX1M.attach(&rx_read, Serial::RxIrq);
shreeshas95 4:104dd82c99b8 281 gFLAGS = gFLAGS & (~COM_MNG_TMTC_RUNNING_FLAG);
shreeshas95 2:2caf2a9a13aa 282 }
shreeshas95 0:f016e9e8d48b 283 }
shreeshas95 0:f016e9e8d48b 284 else{
aniruddhv 179:67588115bca3 285 COM_POWER_ON_TX;
aniruddhv 180:ccc21cc163f8 286 // COM_TX_CNTRL = 0;
aniruddhv 180:ccc21cc163f8 287 reset_all;
aniruddhv 180:ccc21cc163f8 288 gFLAGS = gFLAGS & (~COM_SESSION_FLAG);
shreeshas95 2:2caf2a9a13aa 289 RX1M.attach(&rx_read, Serial::RxIrq);
shreeshas95 4:104dd82c99b8 290 gFLAGS = gFLAGS & (~COM_MNG_TMTC_RUNNING_FLAG);
shreeshas95 0:f016e9e8d48b 291 }
shreeshas95 2:2caf2a9a13aa 292 }
shreeshas95 4:104dd82c99b8 293 else{
aniruddhv 179:67588115bca3 294 gPC.puts("No valid TC received\r\n");
shreeshas95 2:2caf2a9a13aa 295 RX1M.attach(&rx_read, Serial::RxIrq);
shreeshas95 4:104dd82c99b8 296 gFLAGS = gFLAGS & (~COM_MNG_TMTC_RUNNING_FLAG);
shreeshas95 6:79d422d1ed42 297 reset_all;
shreeshas95 6:79d422d1ed42 298 // PENDING : ENABLE THREADS
aniruddhv 179:67588115bca3 299 Init_gPAY_SPI;
shreeshas95 6:79d422d1ed42 300 gSESSION_TIMEOUT.detach();
shreeshas95 6:79d422d1ed42 301 gFLAGS = gFLAGS & (~COM_SESSION_FLAG);
shreeshas95 2:2caf2a9a13aa 302 }
shreeshas95 2:2caf2a9a13aa 303 }
shreeshas95 2:2caf2a9a13aa 304 else if( gFLAGS & COM_PA_HOT_FLAG ){
aniruddhv 179:67588115bca3 305 /*gPC.puts("checking for PA hot in main\r\n");*/
shreeshas95 6:79d422d1ed42 306 if( gFLAGS & COM_RX_FLAG ){
shreeshas95 6:79d422d1ed42 307 uint8_t tempPA = 0xFF;
shreeshas95 6:79d422d1ed42 308 isPAhot(tempPA);
shreeshas95 6:79d422d1ed42 309 if( tempPA == 0x00 ){
shreeshas95 6:79d422d1ed42 310 gCOM_PA_COOLING_TIMEOUT.attach(&after_cooling_pa, COM_PA_COOLING_TIME_LIMIT);
shreeshas95 6:79d422d1ed42 311 }
shreeshas95 6:79d422d1ed42 312 else{
shreeshas95 6:79d422d1ed42 313 gFLAGS = gFLAGS & ~(COM_PA_HOT_FLAG);
shreeshas95 6:79d422d1ed42 314 gCOM_PA_COOLING_TIMEOUT.detach();
shreeshas95 6:79d422d1ed42 315 }
shreeshas95 0:f016e9e8d48b 316 }
shreeshas95 0:f016e9e8d48b 317 else{
shreeshas95 6:79d422d1ed42 318 uint8_t tempPA = 0xFF;
shreeshas95 6:79d422d1ed42 319 isPAhot(tempPA);
shreeshas95 6:79d422d1ed42 320 if( tempPA == 0x00 ){
shreeshas95 6:79d422d1ed42 321 gCOM_PA_COOLING_TIMEOUT.attach(&after_cooling_pa, COM_PA_COOLING_TIME_LIMIT);
shreeshas95 6:79d422d1ed42 322 }
shreeshas95 6:79d422d1ed42 323 else{
aniruddhv 12:ffdb29353058 324 /*gPC.puts("PA IS COOLED DOWN\r\n");*/
shreeshas95 6:79d422d1ed42 325 gFLAGS = gFLAGS & (~COM_PA_HOT_FLAG);
shreeshas95 6:79d422d1ed42 326 gFLAGS = gFLAGS | COM_MNG_TMTC_RUNNING_FLAG;
shreeshas95 6:79d422d1ed42 327 RX1M.attach(NULL);
shreeshas95 6:79d422d1ed42 328 gCOM_PA_COOLING_TIMEOUT.detach();
aniruddhv 179:67588115bca3 329 COM_POWER_ON_TX;
shreeshas95 6:79d422d1ed42 330 EXECUTE_OBOSC_ONLY;
shreeshas95 6:79d422d1ed42 331 EXECUTE_TC;
shreeshas95 6:79d422d1ed42 332 }
shreeshas95 0:f016e9e8d48b 333 }
shreeshas95 2:2caf2a9a13aa 334 }
shreeshas95 6:79d422d1ed42 335 else if( gFLAGS & COM_SESSION_TIMEOUT_FLAG ){
aniruddhv 179:67588115bca3 336 /*gPC.puts("session timeout: resetting in main\r\n");*/
shreeshas95 6:79d422d1ed42 337 COM_POWER_OFF_TX;
shreeshas95 6:79d422d1ed42 338 /*PENDING : ENABLE THREADS*/
aniruddhv 179:67588115bca3 339
shreeshas95 6:79d422d1ed42 340 gSESSION_TIMEOUT.detach();
shreeshas95 6:79d422d1ed42 341 gFLAGS = gFLAGS & (~COM_MNG_TMTC_RUNNING_FLAG);
shreeshas95 6:79d422d1ed42 342 gFLAGS = gFLAGS & (~COM_SESSION_FLAG);
shreeshas95 6:79d422d1ed42 343 reset_all;
shreeshas95 6:79d422d1ed42 344 }
shreeshas95 2:2caf2a9a13aa 345 else{
aniruddhv 179:67588115bca3 346 /*gPC.puts("INVALID SIGNAL RECEIVED IN MAIN\r\n");*/
shreeshas95 2:2caf2a9a13aa 347 // SOME INVALID SIGNAL RECEIVED
shreeshas95 4:104dd82c99b8 348 COM_POWER_OFF_TX;
shreeshas95 2:2caf2a9a13aa 349 reset_all;
shreeshas95 2:2caf2a9a13aa 350 // PENDING : ENABLE THREADS
aniruddhv 179:67588115bca3 351 Init_gPAY_SPI;
shreeshas95 2:2caf2a9a13aa 352 gSESSION_TIMEOUT.detach();
shreeshas95 2:2caf2a9a13aa 353 gFLAGS = gFLAGS & (~COM_SESSION_FLAG);
shreeshas95 0:f016e9e8d48b 354 }
shreeshas95 0:f016e9e8d48b 355 }
shreeshas95 101:bece931236a2 356 }