DMA issue to be tested

Dependencies:   FreescaleIAP SimpleDMA mbed-rtos mbed

Fork of CDMS_CODE by shubham c

Committer:
shreeshas95
Date:
Tue Dec 29 06:50:19 2015 +0000
Revision:
4:104dd82c99b8
Parent:
3:6c81fc8834e2
Child:
5:ab276a17ca07
Before making major modifications for testing

Who changed what in which revision?

UserRevisionLine numberNew 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 2:2caf2a9a13aa 18 gFLAGS = gFLAGS & (~COM_SESSION_FLAG);
shreeshas95 2:2caf2a9a13aa 19 gCOM_MNG_TMTC_THREAD->signal_set(COM_MNG_TMTC_SIGNAL_UART_INT);
shreeshas95 0:f016e9e8d48b 20 }
shreeshas95 0:f016e9e8d48b 21
shreeshas95 0:f016e9e8d48b 22 #define reset_all {\
shreeshas95 0:f016e9e8d48b 23 Base_tc *tcp = gHEAD_NODE_TCL;\
shreeshas95 0:f016e9e8d48b 24 while(tcp != NULL){\
shreeshas95 0:f016e9e8d48b 25 Base_tc *temp = tcp->next_TC;\
shreeshas95 0:f016e9e8d48b 26 delete tcp;\
shreeshas95 0:f016e9e8d48b 27 tcp = temp;\
shreeshas95 0:f016e9e8d48b 28 }\
shreeshas95 0:f016e9e8d48b 29 rx_tc_frames = 0;\
shreeshas95 0:f016e9e8d48b 30 rx_tc_frames = 0;\
shreeshas95 0:f016e9e8d48b 31 gTOTAL_INCORRECT_SIZE_TC = 0;\
shreeshas95 0:f016e9e8d48b 32 gTOTAL_CRC_FAIL_TC = 0;\
shreeshas95 2:2caf2a9a13aa 33 gTOTAL_REPEATED_TC = 0;\
shreeshas95 0:f016e9e8d48b 34 COM_RX_DATA_NODE *dataptr = gRX_HEAD_DATA_NODE;\
shreeshas95 0:f016e9e8d48b 35 while( dataptr != NULL ){\
shreeshas95 0:f016e9e8d48b 36 COM_RX_DATA_NODE *temp = dataptr->next_node;\
shreeshas95 0:f016e9e8d48b 37 delete dataptr;\
shreeshas95 0:f016e9e8d48b 38 dataptr = temp;\
shreeshas95 0:f016e9e8d48b 39 }\
shreeshas95 0:f016e9e8d48b 40 gRX_HEAD_DATA_NODE = new COM_RX_DATA_NODE;\
shreeshas95 0:f016e9e8d48b 41 gRX_HEAD_DATA_NODE->next_node = NULL;\
shreeshas95 0:f016e9e8d48b 42 gRX_CURRENT_DATA_NODE = gRX_HEAD_DATA_NODE;\
shreeshas95 0:f016e9e8d48b 43 gRX_COUNT = 0;\
shreeshas95 2:2caf2a9a13aa 44 /*PENDING : ALL GLOBAL VAARIABLES AND FLAGS*/\
shreeshas95 2:2caf2a9a13aa 45 }
shreeshas95 2:2caf2a9a13aa 46
shreeshas95 2:2caf2a9a13aa 47 #define PUT_RAW_BYTE {\
shreeshas95 2:2caf2a9a13aa 48 if( gRX_COUNT < (RX_BUFFER_LENGTH-1) ){\
shreeshas95 2:2caf2a9a13aa 49 ++gRX_COUNT;\
shreeshas95 2:2caf2a9a13aa 50 }\
shreeshas95 2:2caf2a9a13aa 51 else{\
shreeshas95 2:2caf2a9a13aa 52 gRX_COUNT = 0;\
shreeshas95 2:2caf2a9a13aa 53 gRX_CURRENT_DATA_NODE->next_node = new COM_RX_DATA_NODE;\
shreeshas95 2:2caf2a9a13aa 54 gRX_CURRENT_DATA_NODE = gRX_CURRENT_DATA_NODE->next_node;\
shreeshas95 2:2caf2a9a13aa 55 gRX_CURRENT_DATA_NODE->next_node = NULL;\
shreeshas95 2:2caf2a9a13aa 56 }\
shreeshas95 2:2caf2a9a13aa 57 gRX_TIMEOUT.attach(&after_receive, RX_TIMEOUT_LIMIT);\
shreeshas95 0:f016e9e8d48b 58 }
shreeshas95 0:f016e9e8d48b 59
shreeshas95 0:f016e9e8d48b 60 void COM_MNG_TMTC_FUN(void const *args){
shreeshas95 4:104dd82c99b8 61 if( !(gFLAGS & COM_SESSION_FLAG) ){
shreeshas95 4:104dd82c99b8 62 gPC.puts("com session is flase\r\n");
shreeshas95 4:104dd82c99b8 63 gLEDR = 1;
shreeshas95 4:104dd82c99b8 64 gLEDG = 1;
shreeshas95 4:104dd82c99b8 65 }
shreeshas95 0:f016e9e8d48b 66 while(true){
shreeshas95 0:f016e9e8d48b 67 Thread::signal_wait( COM_MNG_TMTC_SIGNAL_UART_INT );
shreeshas95 0:f016e9e8d48b 68 if( gFLAGS & UART_INT_FLAG ){
shreeshas95 0:f016e9e8d48b 69 gFLAGS = gFLAGS & (~UART_INT_FLAG);
shreeshas95 2:2caf2a9a13aa 70 if( !(gFLAGS & COM_SESSION_FLAG) ){
shreeshas95 2:2caf2a9a13aa 71 // PENDING : DISABLE THREADS
shreeshas95 2:2caf2a9a13aa 72 gFLAGS = gFLAGS | COM_SESSION_FLAG;
shreeshas95 2:2caf2a9a13aa 73 gSESSION_TIMEOUT.attach(&after_session, SESSION_TIME_LIMIT);
shreeshas95 2:2caf2a9a13aa 74 gFLAGS = gFLAGS | COM_RX_FLAG;
shreeshas95 2:2caf2a9a13aa 75 PUT_RAW_BYTE;
shreeshas95 2:2caf2a9a13aa 76 // PENDING : MEASURE RSSI
shreeshas95 4:104dd82c99b8 77 if( gFLAGS & COM_SESSION_FLAG ){
shreeshas95 4:104dd82c99b8 78 gLEDR = 0;
shreeshas95 4:104dd82c99b8 79 gLEDG = 0;
shreeshas95 4:104dd82c99b8 80 }
shreeshas95 2:2caf2a9a13aa 81 }
shreeshas95 2:2caf2a9a13aa 82 else if( gFLAGS & COM_RX_FLAG ){
shreeshas95 4:104dd82c99b8 83 gLEDR = 0;
shreeshas95 4:104dd82c99b8 84 gLEDG = 1;
shreeshas95 2:2caf2a9a13aa 85 PUT_RAW_BYTE;
shreeshas95 0:f016e9e8d48b 86 }
shreeshas95 0:f016e9e8d48b 87 else{
shreeshas95 4:104dd82c99b8 88 gLEDR = 1;
shreeshas95 4:104dd82c99b8 89 gLEDG = 0;
shreeshas95 2:2caf2a9a13aa 90 gFLAGS = gFLAGS | COM_RX_FLAG;
shreeshas95 2:2caf2a9a13aa 91 PUT_RAW_BYTE;
shreeshas95 0:f016e9e8d48b 92 }
shreeshas95 0:f016e9e8d48b 93 }
shreeshas95 4:104dd82c99b8 94 else if( gFLAGS & NEW_TC_RECEIVED ){
shreeshas95 4:104dd82c99b8 95 gPC.puts("NEW TC RECEIVED\r\n");
shreeshas95 0:f016e9e8d48b 96 gFLAGS = gFLAGS & (~NEW_TC_RECEIVED);
shreeshas95 2:2caf2a9a13aa 97 gFLAGS = gFLAGS & (~COM_RX_FLAG);
shreeshas95 4:104dd82c99b8 98 gFLAGS = gFLAGS | COM_MNG_TMTC_RUNNING_FLAG;
shreeshas95 2:2caf2a9a13aa 99
shreeshas95 0:f016e9e8d48b 100 // DISABLE THE RX1M INTERRUPT
shreeshas95 0:f016e9e8d48b 101 RX1M.attach(NULL);
shreeshas95 0:f016e9e8d48b 102
shreeshas95 4:104dd82c99b8 103 // VERIFY CRC, REPEATED PSC AND UPDATE TOTAL_VALID_TC, INCORRECT SIZE TC, CRC FAIL TC
shreeshas95 2:2caf2a9a13aa 104 while(gRX_COUNT < (RX_BUFFER_LENGTH)){
shreeshas95 2:2caf2a9a13aa 105 gRX_CURRENT_DATA_NODE->values[gRX_COUNT] = 0x00;
shreeshas95 0:f016e9e8d48b 106 ++gRX_COUNT;
shreeshas95 0:f016e9e8d48b 107 }
shreeshas95 0:f016e9e8d48b 108 gRX_COUNT = 0;
shreeshas95 4:104dd82c99b8 109 raw_data_to_tc();
shreeshas95 2:2caf2a9a13aa 110
shreeshas95 2:2caf2a9a13aa 111 if( gTOTAL_VALID_TC > 0 ){
shreeshas95 4:104dd82c99b8 112 gPC.printf("valid TC rx: %u\r\n", gTOTAL_VALID_TC);
shreeshas95 4:104dd82c99b8 113 if( gTOTAL_VALID_TC < COM_MAX_TC_LIMIT ){
shreeshas95 4:104dd82c99b8 114 // CHECK WEATHER TC LIST HAS MISSING TC OR WEATHER LAST FRAME BIT IS HIGH IN THE LAST PSC-TC
shreeshas95 4:104dd82c99b8 115 gPC.puts("checking for tc list complete\r\n");
shreeshas95 4:104dd82c99b8 116 uint8_t tempContinue = 0xFF;
shreeshas95 4:104dd82c99b8 117 continueToExecute(tempContinue);
shreeshas95 4:104dd82c99b8 118 if(tempContinue == 0x00){
shreeshas95 4:104dd82c99b8 119 gPC.puts("tc list is complete\r\n");
shreeshas95 4:104dd82c99b8 120 // CHECK WEATHER GS VERIFICATION CODE MATCHES
shreeshas95 4:104dd82c99b8 121 uint8_t tempGSver = 0x00;
shreeshas95 4:104dd82c99b8 122 GScodeVerification(tempGSver);
shreeshas95 4:104dd82c99b8 123 if( tempGSver ){
shreeshas95 4:104dd82c99b8 124 gPC.puts("GC code match !!\r\n");
shreeshas95 4:104dd82c99b8 125 gFLAGS = gFLAGS | COM_SESSION_VALIDITY;
shreeshas95 4:104dd82c99b8 126 COM_POWER_ON_TX;
shreeshas95 4:104dd82c99b8 127 // PENDING: PA HOT HANDLED IN EXECUTE_XXX FUNCTIONS
shreeshas95 4:104dd82c99b8 128 uint8_t tempPAHot = 0x00;
shreeshas95 4:104dd82c99b8 129 isPAhot(tempPAHot);
shreeshas95 4:104dd82c99b8 130 if( tempPAHot == 0xFF ){
shreeshas95 4:104dd82c99b8 131 gPC.puts("EXECUTING TELECOMMANDS\r\n");
shreeshas95 4:104dd82c99b8 132 EXECUTE_OBOSC_ONLY;
shreeshas95 4:104dd82c99b8 133 EXECUTE_TC;
shreeshas95 4:104dd82c99b8 134 gPC.puts("COMPLETED EXECUTION\r\n");
shreeshas95 4:104dd82c99b8 135 }
shreeshas95 4:104dd82c99b8 136 else{
shreeshas95 4:104dd82c99b8 137 gFLAGS = gFLAGS | COM_PA_HOT_FLAG;
shreeshas95 4:104dd82c99b8 138 COM_POWER_OFF_TX;
shreeshas95 4:104dd82c99b8 139 RX1M.attach(&rx_read, Serial::RxIrq);
shreeshas95 4:104dd82c99b8 140 gFLAGS = gFLAGS & (~COM_MNG_TMTC_RUNNING_FLAG);
shreeshas95 4:104dd82c99b8 141 }
shreeshas95 4:104dd82c99b8 142 }
shreeshas95 4:104dd82c99b8 143 else{
shreeshas95 4:104dd82c99b8 144 gPC.puts("GS code mismatch !!\r\n");
shreeshas95 4:104dd82c99b8 145 reset_all;
shreeshas95 4:104dd82c99b8 146 gFLAGS = gFLAGS & (~COM_SESSION_VALIDITY);
shreeshas95 4:104dd82c99b8 147 // PENDING : ENABLE THREADS
shreeshas95 4:104dd82c99b8 148 gSESSION_TIMEOUT.detach();
shreeshas95 4:104dd82c99b8 149 gFLAGS = gFLAGS & (~COM_SESSION_FLAG);
shreeshas95 4:104dd82c99b8 150 // WARNING: clear COM_MNG_TMTC ?
shreeshas95 4:104dd82c99b8 151 }
shreeshas95 0:f016e9e8d48b 152 }
shreeshas95 2:2caf2a9a13aa 153 else{
shreeshas95 4:104dd82c99b8 154 COM_POWER_ON_TX;
shreeshas95 4:104dd82c99b8 155 // PENDING : POWER OFF TX
shreeshas95 4:104dd82c99b8 156 RX1M.attach(&rx_read, Serial::RxIrq);
shreeshas95 4:104dd82c99b8 157 gFLAGS = gFLAGS & (~COM_MNG_TMTC_RUNNING_FLAG);
shreeshas95 2:2caf2a9a13aa 158 }
shreeshas95 0:f016e9e8d48b 159 }
shreeshas95 0:f016e9e8d48b 160 else{
shreeshas95 4:104dd82c99b8 161 COM_POWER_ON_TX;
shreeshas95 4:104dd82c99b8 162 // POWER OFF TX
shreeshas95 4:104dd82c99b8 163 // WARNING: reset_all ? clear com_session ?
shreeshas95 2:2caf2a9a13aa 164 RX1M.attach(&rx_read, Serial::RxIrq);
shreeshas95 4:104dd82c99b8 165 gFLAGS = gFLAGS & (~COM_MNG_TMTC_RUNNING_FLAG);
shreeshas95 0:f016e9e8d48b 166 }
shreeshas95 2:2caf2a9a13aa 167 }
shreeshas95 4:104dd82c99b8 168 else{
shreeshas95 4:104dd82c99b8 169 gPC.puts("No valid TC recweived\r\n");
shreeshas95 2:2caf2a9a13aa 170 RX1M.attach(&rx_read, Serial::RxIrq);
shreeshas95 4:104dd82c99b8 171 gFLAGS = gFLAGS & (~COM_MNG_TMTC_RUNNING_FLAG);
shreeshas95 4:104dd82c99b8 172
shreeshas95 4:104dd82c99b8 173 if( !(gFLAGS & COM_TX_FLAG) ){
shreeshas95 4:104dd82c99b8 174 reset_all;
shreeshas95 4:104dd82c99b8 175 // PENDING : ENABLE THREADS
shreeshas95 4:104dd82c99b8 176 gSESSION_TIMEOUT.detach();
shreeshas95 4:104dd82c99b8 177 gFLAGS = gFLAGS & (~COM_SESSION_FLAG);
shreeshas95 4:104dd82c99b8 178 }
shreeshas95 4:104dd82c99b8 179 // else wait
shreeshas95 2:2caf2a9a13aa 180 }
shreeshas95 2:2caf2a9a13aa 181 }
shreeshas95 2:2caf2a9a13aa 182 else if( gFLAGS & COM_PA_HOT_FLAG ){
shreeshas95 2:2caf2a9a13aa 183 uint8_t tempPA = 0xFF;
shreeshas95 2:2caf2a9a13aa 184 isPAhot(tempPA);
shreeshas95 2:2caf2a9a13aa 185 if( tempPA == 0x00 ){
shreeshas95 4:104dd82c99b8 186 gCOM_PA_COOLING_TIMEOUT.attach(&after_cooling_pa, COM_PA_COOLING_TIME_LIMIT);
shreeshas95 0:f016e9e8d48b 187 }
shreeshas95 0:f016e9e8d48b 188 else{
shreeshas95 2:2caf2a9a13aa 189 gFLAGS = gFLAGS & (~COM_PA_HOT_FLAG);
shreeshas95 4:104dd82c99b8 190 gCOM_PA_COOLING_TIMEOUT.detach();
shreeshas95 4:104dd82c99b8 191 COM_POWER_ON_TX;
shreeshas95 2:2caf2a9a13aa 192 EXECUTE_OBOSC_ONLY;
shreeshas95 2:2caf2a9a13aa 193 EXECUTE_TC;
shreeshas95 0:f016e9e8d48b 194 }
shreeshas95 2:2caf2a9a13aa 195 }
shreeshas95 2:2caf2a9a13aa 196 else{
shreeshas95 2:2caf2a9a13aa 197 // SOME INVALID SIGNAL RECEIVED
shreeshas95 4:104dd82c99b8 198 COM_POWER_OFF_TX;
shreeshas95 2:2caf2a9a13aa 199 reset_all;
shreeshas95 2:2caf2a9a13aa 200 // PENDING : ENABLE THREADS
shreeshas95 2:2caf2a9a13aa 201 gSESSION_TIMEOUT.detach();
shreeshas95 2:2caf2a9a13aa 202 gFLAGS = gFLAGS & (~COM_SESSION_FLAG);
shreeshas95 0:f016e9e8d48b 203 }
shreeshas95 0:f016e9e8d48b 204 }
shreeshas95 3:6c81fc8834e2 205 }
shreeshas95 3:6c81fc8834e2 206
shreeshas95 4:104dd82c99b8 207 //void SCIENCE_FUN(void const *args){
shreeshas95 4:104dd82c99b8 208 //// SPIpayload.format(8,0);
shreeshas95 4:104dd82c99b8 209 //// SPIpayload.frequency(1000000);
shreeshas95 4:104dd82c99b8 210 // for ( int i = 0 ; i < PAYLOAD_BUFFER_LENGTH ; i++ ){
shreeshas95 4:104dd82c99b8 211 // gPAYLOAD_BUFFER[i] = 1;
shreeshas95 4:104dd82c99b8 212 // }
shreeshas95 4:104dd82c99b8 213 //
shreeshas95 4:104dd82c99b8 214 // // initialise the buffer for dma
shreeshas95 4:104dd82c99b8 215 // // SPIpayload.bulkRead_init(VAR_SPACE::payload_dma_buffer, PAYLOAD_DMA_SIZE, &payload_interrupt_fun);
shreeshas95 4:104dd82c99b8 216 // // start dma read
shreeshas95 4:104dd82c99b8 217 // // SPIpayload.bulkRead_start();
shreeshas95 4:104dd82c99b8 218 //
shreeshas95 4:104dd82c99b8 219 // // attach DMA interrupt
shreeshas95 4:104dd82c99b8 220 // while(true){
shreeshas95 4:104dd82c99b8 221 // gSCIENCE_THREAD->signal_wait(0x01);
shreeshas95 4:104dd82c99b8 222 //
shreeshas95 4:104dd82c99b8 223 ////*********************************************************THE TEST
shreeshas95 4:104dd82c99b8 224 //
shreeshas95 4:104dd82c99b8 225 // //read rtc time later
shreeshas95 4:104dd82c99b8 226 // uint64_t RTC_time = 0;
shreeshas95 4:104dd82c99b8 227 // Science_Data_Compression::complete_compression( gPAYLOAD_BUFFER , RTC_time);
shreeshas95 4:104dd82c99b8 228 //// SPI_mutex.lock();
shreeshas95 4:104dd82c99b8 229 //// disk_write(SDcard_lastWritten , 5);
shreeshas95 4:104dd82c99b8 230 //// SPI_mutex.unlock();
shreeshas95 4:104dd82c99b8 231 //
shreeshas95 4:104dd82c99b8 232 ////**********************************************THE TEST
shreeshas95 4:104dd82c99b8 233 //
shreeshas95 4:104dd82c99b8 234 //// counter_for_payload++;
shreeshas95 4:104dd82c99b8 235 //// if(counter_for_payload == 10){
shreeshas95 4:104dd82c99b8 236 //// payload_ticker.detach();
shreeshas95 4:104dd82c99b8 237 //// ledg = 0;
shreeshas95 4:104dd82c99b8 238 //// PC.puts("its over\r\n");
shreeshas95 4:104dd82c99b8 239 //// }
shreeshas95 4:104dd82c99b8 240 //
shreeshas95 4:104dd82c99b8 241 //// SPIpayload.bulkRead_start();
shreeshas95 4:104dd82c99b8 242 //
shreeshas95 4:104dd82c99b8 243 // }
shreeshas95 4:104dd82c99b8 244 //}