Repository for CDMS code
Dependencies: SimpleDMA mbed-rtos mbed eeprom
Fork of COM_MNG_TMTC_SIMPLE by
ThreadsAndFunctions.h@1:a0055b3280c8, 2015-12-14 (annotated)
- Committer:
- shreeshas95
- Date:
- Mon Dec 14 12:04:01 2015 +0000
- Revision:
- 1:a0055b3280c8
- Parent:
- 0:f016e9e8d48b
- Child:
- 2:2caf2a9a13aa
Simple working version code
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 | 0:f016e9e8d48b | 3 | *gRX_CURRENT_PTR = RX1M.getc(); |
shreeshas95 | 0:f016e9e8d48b | 4 | gFLAGS = gFLAGS | (0xFF & 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 | 0:f016e9e8d48b | 11 | gFLAGS = gFLAGS | (0xFF & 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 | 0:f016e9e8d48b | 18 | gFLAGS = gFLAGS | (0xFF & END_SESSION); |
shreeshas95 | 0:f016e9e8d48b | 19 | } |
shreeshas95 | 0:f016e9e8d48b | 20 | |
shreeshas95 | 0:f016e9e8d48b | 21 | #define reset_all {\ |
shreeshas95 | 0:f016e9e8d48b | 22 | Base_tc *tcp = gHEAD_NODE_TCL;\ |
shreeshas95 | 0:f016e9e8d48b | 23 | while(tcp != NULL){\ |
shreeshas95 | 0:f016e9e8d48b | 24 | Base_tc *temp = tcp->next_TC;\ |
shreeshas95 | 0:f016e9e8d48b | 25 | delete tcp;\ |
shreeshas95 | 0:f016e9e8d48b | 26 | tcp = temp;\ |
shreeshas95 | 0:f016e9e8d48b | 27 | }\ |
shreeshas95 | 0:f016e9e8d48b | 28 | rx_tc_frames = 0;\ |
shreeshas95 | 0:f016e9e8d48b | 29 | rx_tc_frames = 0;\ |
shreeshas95 | 0:f016e9e8d48b | 30 | gTOTAL_INCORRECT_SIZE_TC = 0;\ |
shreeshas95 | 0:f016e9e8d48b | 31 | gTOTAL_CRC_FAIL_TC = 0;\ |
shreeshas95 | 0:f016e9e8d48b | 32 | COM_RX_DATA_NODE *dataptr = gRX_HEAD_DATA_NODE;\ |
shreeshas95 | 0:f016e9e8d48b | 33 | while( dataptr != NULL ){\ |
shreeshas95 | 0:f016e9e8d48b | 34 | COM_RX_DATA_NODE *temp = dataptr->next_node;\ |
shreeshas95 | 0:f016e9e8d48b | 35 | delete dataptr;\ |
shreeshas95 | 0:f016e9e8d48b | 36 | dataptr = temp;\ |
shreeshas95 | 0:f016e9e8d48b | 37 | }\ |
shreeshas95 | 0:f016e9e8d48b | 38 | gRX_HEAD_DATA_NODE = new COM_RX_DATA_NODE;\ |
shreeshas95 | 0:f016e9e8d48b | 39 | gRX_HEAD_DATA_NODE->next_node = NULL;\ |
shreeshas95 | 0:f016e9e8d48b | 40 | gRX_CURRENT_DATA_NODE = gRX_HEAD_DATA_NODE;\ |
shreeshas95 | 0:f016e9e8d48b | 41 | gRX_CURRENT_PTR = gRX_HEAD_DATA_NODE->values;\ |
shreeshas95 | 0:f016e9e8d48b | 42 | gRX_COUNT = 0;\ |
shreeshas95 | 0:f016e9e8d48b | 43 | } |
shreeshas95 | 0:f016e9e8d48b | 44 | |
shreeshas95 | 0:f016e9e8d48b | 45 | void COM_MNG_TMTC_FUN(void const *args){ |
shreeshas95 | 0:f016e9e8d48b | 46 | while(true){ |
shreeshas95 | 0:f016e9e8d48b | 47 | Thread::signal_wait( COM_MNG_TMTC_SIGNAL_UART_INT ); |
shreeshas95 | 0:f016e9e8d48b | 48 | if( gFLAGS & UART_INT_FLAG ){ |
shreeshas95 | 0:f016e9e8d48b | 49 | gFLAGS = gFLAGS & (~UART_INT_FLAG); |
shreeshas95 | 0:f016e9e8d48b | 50 | if( gRX_COUNT < (RX_BUFFER_LENGTH-1) ){ |
shreeshas95 | 0:f016e9e8d48b | 51 | ++gRX_CURRENT_PTR; |
shreeshas95 | 0:f016e9e8d48b | 52 | ++gRX_COUNT; |
shreeshas95 | 0:f016e9e8d48b | 53 | } |
shreeshas95 | 0:f016e9e8d48b | 54 | else{ |
shreeshas95 | 0:f016e9e8d48b | 55 | gLEDG = !gLEDG; |
shreeshas95 | 0:f016e9e8d48b | 56 | gRX_COUNT = 0; |
shreeshas95 | 0:f016e9e8d48b | 57 | gRX_CURRENT_DATA_NODE->next_node = new COM_RX_DATA_NODE; |
shreeshas95 | 0:f016e9e8d48b | 58 | gRX_CURRENT_DATA_NODE = gRX_CURRENT_DATA_NODE->next_node; |
shreeshas95 | 0:f016e9e8d48b | 59 | gRX_CURRENT_DATA_NODE->next_node = NULL; |
shreeshas95 | 0:f016e9e8d48b | 60 | gRX_CURRENT_PTR = gRX_CURRENT_DATA_NODE->values; |
shreeshas95 | 0:f016e9e8d48b | 61 | } |
shreeshas95 | 0:f016e9e8d48b | 62 | gRX_TIMEOUT.attach(&after_receive, RX_TIMEOUT_LIMIT); |
shreeshas95 | 0:f016e9e8d48b | 63 | } |
shreeshas95 | 0:f016e9e8d48b | 64 | else if( gFLAGS & NEW_TC_RECEIVED ){ |
shreeshas95 | 0:f016e9e8d48b | 65 | gFLAGS = gFLAGS & (~NEW_TC_RECEIVED); |
shreeshas95 | 0:f016e9e8d48b | 66 | |
shreeshas95 | 0:f016e9e8d48b | 67 | // DISABLE THE RX1M INTERRUPT |
shreeshas95 | 0:f016e9e8d48b | 68 | RX1M.attach(NULL); |
shreeshas95 | 0:f016e9e8d48b | 69 | |
shreeshas95 | 0:f016e9e8d48b | 70 | // PENDING: BEACON |
shreeshas95 | 0:f016e9e8d48b | 71 | while(gRX_COUNT < (RX_BUFFER_LENGTH-1)){ |
shreeshas95 | 0:f016e9e8d48b | 72 | *gRX_CURRENT_PTR = 0x00; |
shreeshas95 | 0:f016e9e8d48b | 73 | ++gRX_CURRENT_PTR; |
shreeshas95 | 0:f016e9e8d48b | 74 | ++gRX_COUNT; |
shreeshas95 | 0:f016e9e8d48b | 75 | } |
shreeshas95 | 0:f016e9e8d48b | 76 | gRX_COUNT = 0; |
shreeshas95 | 0:f016e9e8d48b | 77 | |
shreeshas95 | 0:f016e9e8d48b | 78 | if( (gMASTER_STATE == TCL_STATE_IDLE) || (gMASTER_STATE == TCL_STATE_ABORTED) || (gMASTER_STATE == TCL_STATE_COMPLETED)){ |
shreeshas95 | 0:f016e9e8d48b | 79 | raw_data_to_tc(); |
shreeshas95 | 0:f016e9e8d48b | 80 | if( (gTOTAL_VALID_TC > 0) && (gFLAGS & START_SESSION) ){ |
shreeshas95 | 0:f016e9e8d48b | 81 | gFLAGS = gFLAGS & (~START_SESSION); |
shreeshas95 | 0:f016e9e8d48b | 82 | gSESSION_TIMEOUT.attach(&after_session, SESSION_TIME_LIMIT); |
shreeshas95 | 0:f016e9e8d48b | 83 | } |
shreeshas95 | 0:f016e9e8d48b | 84 | uint8_t tempContinue = 0xFF; |
shreeshas95 | 0:f016e9e8d48b | 85 | continueToExecute(tempContinue); |
shreeshas95 | 0:f016e9e8d48b | 86 | if( tempContinue == 0x00 ){ |
shreeshas95 | 0:f016e9e8d48b | 87 | if(gMASTER_STATE == TCL_STATE_ABORTED){ |
shreeshas95 | 0:f016e9e8d48b | 88 | gMASTER_STATE = TCL_STATE_EXECUTING; |
shreeshas95 | 0:f016e9e8d48b | 89 | send_l1_ack; |
shreeshas95 | 0:f016e9e8d48b | 90 | EXECUTE_OBOSC_ONLY; |
shreeshas95 | 0:f016e9e8d48b | 91 | } |
shreeshas95 | 1:a0055b3280c8 | 92 | send_l1_ack; |
shreeshas95 | 0:f016e9e8d48b | 93 | EXECUTE_TC; |
shreeshas95 | 0:f016e9e8d48b | 94 | } |
shreeshas95 | 0:f016e9e8d48b | 95 | else{ |
shreeshas95 | 0:f016e9e8d48b | 96 | send_l1_ack; |
shreeshas95 | 0:f016e9e8d48b | 97 | } |
shreeshas95 | 0:f016e9e8d48b | 98 | gPC.puts("Completed Execution\r\n"); |
shreeshas95 | 0:f016e9e8d48b | 99 | } |
shreeshas95 | 0:f016e9e8d48b | 100 | else{ |
shreeshas95 | 0:f016e9e8d48b | 101 | // invalid state found - reset |
shreeshas95 | 0:f016e9e8d48b | 102 | reset_all; |
shreeshas95 | 0:f016e9e8d48b | 103 | } |
shreeshas95 | 0:f016e9e8d48b | 104 | |
shreeshas95 | 0:f016e9e8d48b | 105 | // PENDING: BEACON |
shreeshas95 | 0:f016e9e8d48b | 106 | RX1M.attach(&rx_read, Serial::RxIrq); |
shreeshas95 | 0:f016e9e8d48b | 107 | } |
shreeshas95 | 0:f016e9e8d48b | 108 | } |
shreeshas95 | 0:f016e9e8d48b | 109 | } |