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