![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
CDMS_CODE_samp_23SEP_DMA_flag
Dependencies: FreescaleIAP SimpleDMA mbed-rtos mbed
Fork of CDMS_CODE_samp_23SEP_DMA by
ThreadsAndFunctions.h@3:6c81fc8834e2, 2015-12-23 (annotated)
- Committer:
- shreeshas95
- Date:
- Wed Dec 23 05:37:55 2015 +0000
- Revision:
- 3:6c81fc8834e2
- Parent:
- 2:2caf2a9a13aa
- Child:
- 4:104dd82c99b8
for krishan to test adf
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 | 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 | 0:f016e9e8d48b | 61 | while(true){ |
shreeshas95 | 0:f016e9e8d48b | 62 | Thread::signal_wait( COM_MNG_TMTC_SIGNAL_UART_INT ); |
shreeshas95 | 0:f016e9e8d48b | 63 | if( gFLAGS & UART_INT_FLAG ){ |
shreeshas95 | 0:f016e9e8d48b | 64 | gFLAGS = gFLAGS & (~UART_INT_FLAG); |
shreeshas95 | 2:2caf2a9a13aa | 65 | if( !(gFLAGS & COM_SESSION_FLAG) ){ |
shreeshas95 | 2:2caf2a9a13aa | 66 | // PENDING : DISABLE THREADS |
shreeshas95 | 2:2caf2a9a13aa | 67 | gFLAGS = gFLAGS | COM_SESSION_FLAG; |
shreeshas95 | 2:2caf2a9a13aa | 68 | gSESSION_TIMEOUT.attach(&after_session, SESSION_TIME_LIMIT); |
shreeshas95 | 2:2caf2a9a13aa | 69 | gFLAGS = gFLAGS | COM_RX_FLAG; |
shreeshas95 | 2:2caf2a9a13aa | 70 | PUT_RAW_BYTE; |
shreeshas95 | 2:2caf2a9a13aa | 71 | // PENDING : MEASURE RSSI |
shreeshas95 | 2:2caf2a9a13aa | 72 | } |
shreeshas95 | 2:2caf2a9a13aa | 73 | else if( gFLAGS & COM_RX_FLAG ){ |
shreeshas95 | 2:2caf2a9a13aa | 74 | PUT_RAW_BYTE; |
shreeshas95 | 0:f016e9e8d48b | 75 | } |
shreeshas95 | 0:f016e9e8d48b | 76 | else{ |
shreeshas95 | 2:2caf2a9a13aa | 77 | gFLAGS = gFLAGS | COM_RX_FLAG; |
shreeshas95 | 2:2caf2a9a13aa | 78 | PUT_RAW_BYTE; |
shreeshas95 | 0:f016e9e8d48b | 79 | } |
shreeshas95 | 0:f016e9e8d48b | 80 | } |
shreeshas95 | 2:2caf2a9a13aa | 81 | else if( (gFLAGS & NEW_TC_RECEIVED) && (gFLAGS & COM_MNG_TMTC_RUNNING_FLAG) ){ |
shreeshas95 | 0:f016e9e8d48b | 82 | gFLAGS = gFLAGS & (~NEW_TC_RECEIVED); |
shreeshas95 | 2:2caf2a9a13aa | 83 | gFLAGS = gFLAGS & (~COM_RX_FLAG); |
shreeshas95 | 2:2caf2a9a13aa | 84 | |
shreeshas95 | 0:f016e9e8d48b | 85 | // DISABLE THE RX1M INTERRUPT |
shreeshas95 | 0:f016e9e8d48b | 86 | RX1M.attach(NULL); |
shreeshas95 | 0:f016e9e8d48b | 87 | |
shreeshas95 | 2:2caf2a9a13aa | 88 | while(gRX_COUNT < (RX_BUFFER_LENGTH)){ |
shreeshas95 | 2:2caf2a9a13aa | 89 | gRX_CURRENT_DATA_NODE->values[gRX_COUNT] = 0x00; |
shreeshas95 | 0:f016e9e8d48b | 90 | ++gRX_COUNT; |
shreeshas95 | 0:f016e9e8d48b | 91 | } |
shreeshas95 | 0:f016e9e8d48b | 92 | gRX_COUNT = 0; |
shreeshas95 | 2:2caf2a9a13aa | 93 | |
shreeshas95 | 2:2caf2a9a13aa | 94 | // VERIFY CRC, REPEATED PSC AND UPDATE TOTAL_VALID_TC, INCORRECT SIZE TC, CRC FAIL TC |
shreeshas95 | 2:2caf2a9a13aa | 95 | raw_data_to_tc(); |
shreeshas95 | 2:2caf2a9a13aa | 96 | if( gTOTAL_VALID_TC > 0 ){ |
shreeshas95 | 2:2caf2a9a13aa | 97 | // CHECK WEATHER TC LIST HAS MISSING TC OR WEATHER LAST FRAME BIT IS HIGH IN THE LAST PSC-TC |
shreeshas95 | 0:f016e9e8d48b | 98 | uint8_t tempContinue = 0xFF; |
shreeshas95 | 0:f016e9e8d48b | 99 | continueToExecute(tempContinue); |
shreeshas95 | 2:2caf2a9a13aa | 100 | if(tempContinue == 0x00){ |
shreeshas95 | 2:2caf2a9a13aa | 101 | // CHECK WEATHER GS VERIFICATION CODE MATCHES |
shreeshas95 | 2:2caf2a9a13aa | 102 | uint8_t tempGSver = 0x00; |
shreeshas95 | 2:2caf2a9a13aa | 103 | GScodeVerification(tempGSver); |
shreeshas95 | 2:2caf2a9a13aa | 104 | if( tempGSver ){ |
shreeshas95 | 2:2caf2a9a13aa | 105 | gFLAGS = gFLAGS | COM_SESSION_VALIDITY; |
shreeshas95 | 2:2caf2a9a13aa | 106 | // PENDING : COM_POWER_ON_TX |
shreeshas95 | 0:f016e9e8d48b | 107 | EXECUTE_OBOSC_ONLY; |
shreeshas95 | 2:2caf2a9a13aa | 108 | EXECUTE_TC; |
shreeshas95 | 0:f016e9e8d48b | 109 | } |
shreeshas95 | 2:2caf2a9a13aa | 110 | else{ |
shreeshas95 | 2:2caf2a9a13aa | 111 | gFLAGS = gFLAGS & (~COM_SESSION_VALIDITY); |
shreeshas95 | 2:2caf2a9a13aa | 112 | // PENDING : ENABLE THREADS |
shreeshas95 | 2:2caf2a9a13aa | 113 | gSESSION_TIMEOUT.detach(); |
shreeshas95 | 2:2caf2a9a13aa | 114 | gFLAGS = gFLAGS & (~COM_SESSION_FLAG); |
shreeshas95 | 2:2caf2a9a13aa | 115 | } |
shreeshas95 | 0:f016e9e8d48b | 116 | } |
shreeshas95 | 0:f016e9e8d48b | 117 | else{ |
shreeshas95 | 2:2caf2a9a13aa | 118 | // PENDING : COM_POWER_ON_TX |
shreeshas95 | 2:2caf2a9a13aa | 119 | // PENDING : POWER OFF TX |
shreeshas95 | 2:2caf2a9a13aa | 120 | RX1M.attach(&rx_read, Serial::RxIrq); |
shreeshas95 | 0:f016e9e8d48b | 121 | } |
shreeshas95 | 2:2caf2a9a13aa | 122 | } |
shreeshas95 | 2:2caf2a9a13aa | 123 | else if( !(gFLAGS & COM_TX_FLAG) ){ |
shreeshas95 | 2:2caf2a9a13aa | 124 | RX1M.attach(&rx_read, Serial::RxIrq); |
shreeshas95 | 2:2caf2a9a13aa | 125 | // PENDING : ENABLE THREADS |
shreeshas95 | 2:2caf2a9a13aa | 126 | gSESSION_TIMEOUT.detach(); |
shreeshas95 | 2:2caf2a9a13aa | 127 | gFLAGS = gFLAGS & (~COM_SESSION_FLAG); |
shreeshas95 | 2:2caf2a9a13aa | 128 | } |
shreeshas95 | 2:2caf2a9a13aa | 129 | } |
shreeshas95 | 2:2caf2a9a13aa | 130 | else if( gFLAGS & COM_PA_HOT_FLAG ){ |
shreeshas95 | 2:2caf2a9a13aa | 131 | uint8_t tempPA = 0xFF; |
shreeshas95 | 2:2caf2a9a13aa | 132 | isPAhot(tempPA); |
shreeshas95 | 2:2caf2a9a13aa | 133 | if( tempPA == 0x00 ){ |
shreeshas95 | 2:2caf2a9a13aa | 134 | gCOM_PA_COOLING_TIMER.attach(&after_cooling_pa, COM_PA_COOLING_TIME_LIMIT); |
shreeshas95 | 0:f016e9e8d48b | 135 | } |
shreeshas95 | 0:f016e9e8d48b | 136 | else{ |
shreeshas95 | 2:2caf2a9a13aa | 137 | gFLAGS = gFLAGS & (~COM_PA_HOT_FLAG); |
shreeshas95 | 2:2caf2a9a13aa | 138 | gCOM_PA_COOLING_TIMER.detach(); |
shreeshas95 | 2:2caf2a9a13aa | 139 | // PENDING : COM POWER ON TX |
shreeshas95 | 2:2caf2a9a13aa | 140 | EXECUTE_OBOSC_ONLY; |
shreeshas95 | 2:2caf2a9a13aa | 141 | EXECUTE_TC; |
shreeshas95 | 0:f016e9e8d48b | 142 | } |
shreeshas95 | 2:2caf2a9a13aa | 143 | } |
shreeshas95 | 2:2caf2a9a13aa | 144 | else{ |
shreeshas95 | 2:2caf2a9a13aa | 145 | // SOME INVALID SIGNAL RECEIVED |
shreeshas95 | 0:f016e9e8d48b | 146 | |
shreeshas95 | 2:2caf2a9a13aa | 147 | // PENDING : COM_POWER_OFF_TX |
shreeshas95 | 2:2caf2a9a13aa | 148 | reset_all; |
shreeshas95 | 2:2caf2a9a13aa | 149 | // PENDING : ENABLE THREADS |
shreeshas95 | 2:2caf2a9a13aa | 150 | gSESSION_TIMEOUT.detach(); |
shreeshas95 | 2:2caf2a9a13aa | 151 | gFLAGS = gFLAGS & (~COM_SESSION_FLAG); |
shreeshas95 | 0:f016e9e8d48b | 152 | } |
shreeshas95 | 0:f016e9e8d48b | 153 | } |
shreeshas95 | 3:6c81fc8834e2 | 154 | } |
shreeshas95 | 3:6c81fc8834e2 | 155 | |
shreeshas95 | 3:6c81fc8834e2 | 156 | void SCIENCE_FUN(void const *args){ |
shreeshas95 | 3:6c81fc8834e2 | 157 | // SPIpayload.format(8,0); |
shreeshas95 | 3:6c81fc8834e2 | 158 | // SPIpayload.frequency(1000000); |
shreeshas95 | 3:6c81fc8834e2 | 159 | for ( int i = 0 ; i < PAYLOAD_BUFFER_LENGTH ; i++ ){ |
shreeshas95 | 3:6c81fc8834e2 | 160 | gPAYLOAD_BUFFER[i] = 1; |
shreeshas95 | 3:6c81fc8834e2 | 161 | } |
shreeshas95 | 3:6c81fc8834e2 | 162 | |
shreeshas95 | 3:6c81fc8834e2 | 163 | // initialise the buffer for dma |
shreeshas95 | 3:6c81fc8834e2 | 164 | // SPIpayload.bulkRead_init(VAR_SPACE::payload_dma_buffer, PAYLOAD_DMA_SIZE, &payload_interrupt_fun); |
shreeshas95 | 3:6c81fc8834e2 | 165 | // start dma read |
shreeshas95 | 3:6c81fc8834e2 | 166 | // SPIpayload.bulkRead_start(); |
shreeshas95 | 3:6c81fc8834e2 | 167 | |
shreeshas95 | 3:6c81fc8834e2 | 168 | // attach DMA interrupt |
shreeshas95 | 3:6c81fc8834e2 | 169 | while(true){ |
shreeshas95 | 3:6c81fc8834e2 | 170 | gSCIENCE_THREAD->signal_wait(0x01); |
shreeshas95 | 3:6c81fc8834e2 | 171 | |
shreeshas95 | 3:6c81fc8834e2 | 172 | //*********************************************************THE TEST |
shreeshas95 | 3:6c81fc8834e2 | 173 | |
shreeshas95 | 3:6c81fc8834e2 | 174 | //read rtc time later |
shreeshas95 | 3:6c81fc8834e2 | 175 | uint64_t RTC_time = 0; |
shreeshas95 | 3:6c81fc8834e2 | 176 | Science_Data_Compression::complete_compression( gPAYLOAD_BUFFER , RTC_time); |
shreeshas95 | 3:6c81fc8834e2 | 177 | // SPI_mutex.lock(); |
shreeshas95 | 3:6c81fc8834e2 | 178 | // disk_write(SDcard_lastWritten , 5); |
shreeshas95 | 3:6c81fc8834e2 | 179 | // SPI_mutex.unlock(); |
shreeshas95 | 3:6c81fc8834e2 | 180 | |
shreeshas95 | 3:6c81fc8834e2 | 181 | //**********************************************THE TEST |
shreeshas95 | 3:6c81fc8834e2 | 182 | |
shreeshas95 | 3:6c81fc8834e2 | 183 | |
shreeshas95 | 3:6c81fc8834e2 | 184 | |
shreeshas95 | 3:6c81fc8834e2 | 185 | // counter_for_payload++; |
shreeshas95 | 3:6c81fc8834e2 | 186 | // if(counter_for_payload == 10){ |
shreeshas95 | 3:6c81fc8834e2 | 187 | // payload_ticker.detach(); |
shreeshas95 | 3:6c81fc8834e2 | 188 | // ledg = 0; |
shreeshas95 | 3:6c81fc8834e2 | 189 | // PC.puts("its over\r\n"); |
shreeshas95 | 3:6c81fc8834e2 | 190 | // } |
shreeshas95 | 3:6c81fc8834e2 | 191 | |
shreeshas95 | 3:6c81fc8834e2 | 192 | |
shreeshas95 | 3:6c81fc8834e2 | 193 | |
shreeshas95 | 3:6c81fc8834e2 | 194 | |
shreeshas95 | 3:6c81fc8834e2 | 195 | // SPIpayload.bulkRead_start(); |
shreeshas95 | 3:6c81fc8834e2 | 196 | |
shreeshas95 | 3:6c81fc8834e2 | 197 | } |
shreeshas95 | 0:f016e9e8d48b | 198 | } |