
publishing to check changes in cdms code
Dependencies: FreescaleIAP SimpleDMA mbed-rtos mbed
Fork of CDMS_CODE_samp_23SEP_DMA_flag by
Revision 262:752c8689944a, committed 2016-07-14
- Comitter:
- aniruddhv
- Date:
- Thu Jul 14 17:57:05 2016 +0000
- Parent:
- 261:1e54415b34d3
- Child:
- 263:3b872778b8c7
- Commit message:
- Merged Aniruddh's code, changed power_on and power_off BAE, added PAHOT and PAOC measurements, added sys_reset_cdms timer
Changed in this revision
--- a/COM_MNG_TMTC.h Thu Jul 14 13:07:30 2016 +0000 +++ b/COM_MNG_TMTC.h Thu Jul 14 17:57:05 2016 +0000 @@ -47,7 +47,7 @@ -#define detect_ack(tm_ptr, temp_ack, tc_psc) {\ +#define detect_ack(tm_ptr, temp_ack) {\ if( tm_ptr != NULL ){\ int length = TM_SHORT_SIZE;\ if( GETshort_or_long_tm(tm_ptr) == SHORT_TM_CODE ){\ @@ -64,20 +64,20 @@ if( (temp8 == 0xC0) || (temp8 == 0xA0) )\ temp_ack = 0x01;\ else{\ - temp_ack = 0x00;\ + temp_ack = 0x02;\ /*CHECK FOR NACK CODE: CRC FAIL NACK*/\ temp8 = tm_ptr->TM_string[TM_ACK_CODE_INDEX];\ temp8 = temp8 & 0x0F;\ if( temp8 == CRC_FAIL_NACK_CODE ){\ - tm_ptr->TM_string[2] = tc_psc;\ + temp_ack = 0x04;\ }\ }\ }\ else\ - temp_ack = 0x00;\ + temp_ack = 0x03;\ }\ else{\ - temp_ack = 0x00;\ + temp_ack = 0x02;\ }\ } @@ -1222,7 +1222,7 @@ }\ else if( (service_subtype != OBOSC_SUB_DISABLE) && (service_subtype != OBOSC_SUB_RETRY) ){\ /*CHANGE THE ACK CODE TO INVALID TC*/\ - ackl234new->TM_string[2] = 0xA2;\ + ackl234new->TM_string[2] = 0xAF;\ }\ if (DEBUG)\ gPC.puts("completed obosc\r\n");\ @@ -1232,6 +1232,7 @@ #define EXECUTE_OBOSC_ONLY {\ + gMASTER_STATE = TCL_STATE_EXECUTING;\ int reset_flag = 0;\ if (DEBUG)\ gPC.puts("iNSIDE EXECUTE_OBOSC_ONLY\r\n");\ @@ -1260,8 +1261,14 @@ while(obosc_tm_core != NULL){\ obosc_tm_core = obosc_tm_core->next_TM;\ }\ - uint16_t temp16 = TC_STATE_SUCCESSFULLY_EXECUTED;\ - PUTexec_status(current_TC, temp16);\ + if(obosc_tm_current->TM_string[2] == 0xA0){\ + uint16_t temp16 = TC_STATE_SUCCESSFULLY_EXECUTED;\ + PUTexec_status(current_TC, temp16);\ + }\ + else{\ + uint16_t temp16 = TC_STATE_EXECUTION_FAILED;\ + PUTexec_status(current_TC, temp16);\ + }\ while( obosc_tm_current != NULL ){\ int length = TM_SHORT_SIZE;\ if( GETshort_or_long_tm(obosc_tm_current) == SHORT_TM_CODE ){\ @@ -1275,9 +1282,6 @@ }\ obosc_tm_current = obosc_tm_current->next_TM;\ }\ - if ( reset_flag ==1 ){\ - reset_all;\ - }\ }\ }\ }\ @@ -1285,7 +1289,7 @@ ++overCount;\ }\ else{\ - /*PENDING: REST CDMS: MEMORY LEAK FOUND*/\ + RESET_CDMS;\ break;\ }\ }\ @@ -1325,6 +1329,12 @@ break;\ }\ }\ + }\ + if ( reset_flag == 1 ){\ + reset_all;\ + /*PENDING: Enable threads*/\ + /*gCDMS_HK_TIMER.start(5000);*/\ + gSESSION_TIMEOUT.detach();\ }\ } @@ -1422,19 +1432,33 @@ }\ /*DETECT ACK OR NACK*/\ uint8_t temp83 = 0x00;\ - uint8_t temp84 = GETpacket_seq_count(current_TC);\ - detect_ack(put_tm_here, temp83, temp84);\ + detect_ack(put_tm_here, temp83);\ if( temp83 == 0x01){\ uint16_t temp16 = TC_STATE_SUCCESSFULLY_EXECUTED;\ PUTexec_status(current_TC, temp16);\ }\ + else if( temp83 == 0x03){\ + /*gPC.puts("TC_STATE_EXECUTION_UNKNOWN");*/\ + uint16_t temp16 = TC_STATE_EXECUTION_UNKNOWN;\ + PUTexec_status(current_TC, temp16);\ + }\ + else if( temp83 == 0x04){\ + /*gPC.puts("TC_STATE_EXECUTION_UNKNOWN");*/\ + uint16_t temp16 = TC_STATE_EXECUTION_FAILED;\ + PUTexec_status(current_TC, temp16);\ + uint8_t temp84 = GETpacket_seq_count(current_TC);\ + put_tm_here->TM_string[2] = temp84;\ + uint16_t crc16 = crc16_gen(put_tm_here->TM_string, 11);\ + put_tm_here->TM_string[11] = (crc16 & 0xFF00)>>8;\ + put_tm_here->TM_string[12] = (crc16 & 0x00FF);\ + }\ else{\ /*gPC.puts("TC_STATE_EXECUTION_FAILED");*/\ uint16_t temp16 = TC_STATE_EXECUTION_FAILED;\ PUTexec_status(current_TC, temp16);\ }\ /*ABORT ON NACK AND TC LIST COMPLETED: UPDATE IN gMASTERSTATE*/\ - if( (GETexec_status(current_TC) == TC_STATE_EXECUTION_FAILED) && (GETabort_on_nack(current_TC) == 1) ){\ + if( ((GETexec_status(current_TC) == TC_STATE_EXECUTION_FAILED) || (GETexec_status(current_TC) == TC_STATE_EXECUTION_UNKNOWN)) && (GETabort_on_nack(current_TC) == 1) ){\ gMASTER_STATE = TCL_STATE_ABORTED;\ }\ else if( execute_psc == (gTOTAL_VALID_TC-1) ){\ @@ -1443,20 +1467,23 @@ }\ /*update last executed L1_ack*/\ if( put_tm_here != NULL ){\ - if( GETshort_or_long_tm(put_tm_here) == SHORT_TM_CODE ){\ + Base_tm *ptr_tm = put_tm_here;\ + while(ptr_tm->next_TM != NULL)\ + ptr_tm = ptr_tm->next_TM;\ + if( GETshort_or_long_tm(ptr_tm) == SHORT_TM_CODE ){\ for(int i = 0 ; i < TM_SHORT_SIZE ; ++i){\ - gLAST_TM[i] = put_tm_here->TM_string[i];\ + gLAST_TM[i] = ptr_tm->TM_string[i];\ gLAST_TM_SHORT_OR_LONG = SHORT_TM_CODE;\ }\ }\ else{\ for( int i = 0 ; i < TM_LONG_SIZE ; ++i ){\ - gLAST_TM[i] = put_tm_here->TM_string[i];\ + gLAST_TM[i] = ptr_tm->TM_string[i];\ gLAST_TM_SHORT_OR_LONG = LONG_TM_CODE;\ }\ }\ }\ - /*PENDING: APPEND ACK L1*/\ + P_COM_HK;\ Base_tm *tm_ptr = tm_ptr_head;\ get_ack_l1(tm_ptr->next_TM);\ int overflowCountExecute = 0;\ @@ -1471,11 +1498,6 @@ }\ }\ tm_ptr->next_TM = put_tm_here;\ - /*CHECK FOR HOT PA*/\ - isPAhot(tempPAhot);\ - if( tempPAhot == 0x00 ){\ - gFLAGS = gFLAGS | COM_PA_HOT_FLAG;\ - }\ tm_ptr = tm_ptr_head;\ while( tm_ptr != NULL ){\ int length = TM_SHORT_SIZE;\ @@ -1516,112 +1538,10 @@ if (DEBUG)\ gPC.printf("sd card at %u\r\n", execute_psc);\ /*EXECUTION OF SD-CARD DATA SENDING (OBSRS)*/\ - Base_tm *tm_ptr_head = NULL;\ - get_call_sign(tm_ptr_head);\ - Base_tm *put_tm_here = NULL;\ - /*execute_obsrs(current_TC, put_tm_here)*/\ - /*read_TC(current_TC);*/\ execute_OBSRS_TC(current_TC);\ gPC.puts("en_adf");\ transmit_adf;\ gPC.puts("ex_adf");\ - uint8_t tempExec = TC_STATE_SUCCESSFULLY_EXECUTED;\ - PUTexec_status(current_TC, tempExec);\ - /*PENDING: ABORT ON NACK CHECK, gMASTER_STATE VERIFICATION WITH SD CARD, session timeout, last executed ack l234*/\ - if( (GETexec_status(current_TC) == TC_STATE_EXECUTION_FAILED) && (GETabort_on_nack(current_TC) == 1) ){\ - gMASTER_STATE = TCL_STATE_ABORTED;\ - }\ - else if( execute_psc == (gTOTAL_VALID_TC-1) ){\ - gMASTER_STATE = TCL_STATE_COMPLETED;\ - }\ - else{\ - uint8_t check1 = 1;\ - for( uint8_t test_psc = execute_psc+1 ; test_psc < gTOTAL_VALID_TC ; ++test_psc ){\ - Base_tc* test_TC = gHEAD_NODE_TCL;\ - while(test_TC != NULL){\ - if( GETpacket_seq_count(test_TC) == test_psc ){\ - uint8_t checkval;\ - isit_obosc(test_TC, checkval);\ - if( checkval == 0 ){\ - check1 = 0;\ - }\ - }\ - test_TC = test_TC->next_TC;\ - }\ - }\ - if( check1 == 0x01 ){\ - gMASTER_STATE = TCL_STATE_COMPLETED;\ - }\ - }\ - /*update last executed L1_ack*/\ - if( put_tm_here != NULL ){\ - if( GETshort_or_long_tm(put_tm_here) == SHORT_TM_CODE ){\ - for(int i = 0 ; i < TM_SHORT_SIZE ; ++i){\ - gLAST_TM[i] = put_tm_here->TM_string[i];\ - gLAST_TM_SHORT_OR_LONG = SHORT_TM_CODE;\ - }\ - }\ - else{\ - for( int i = 0 ; i < TM_LONG_SIZE ; ++i ){\ - gLAST_TM[i] = put_tm_here->TM_string[i];\ - gLAST_TM_SHORT_OR_LONG = LONG_TM_CODE;\ - }\ - }\ - }\ - /*PENDING: APPEND ACK L1*/\ - Base_tm *tm_ptr = tm_ptr_head;\ - get_ack_l1(tm_ptr->next_TM);\ - int overflowCountExecute = 0;\ - while( tm_ptr->next_TM != NULL ){\ - if( overflowCountExecute < TM_OVERFLOW_CONSTANT ){\ - tm_ptr = tm_ptr->next_TM;\ - ++overflowCountExecute;\ - }\ - else{\ - RESET_CDMS;\ - break;\ - }\ - }\ - tm_ptr->next_TM = put_tm_here;\ - /*CHECK FOR HOT PA*/\ - uint8_t tempPAhot = 0x00;\ - isPAhot(tempPAhot);\ - if( tempPAhot == 0x00 ){\ - gFLAGS = gFLAGS | COM_PA_HOT_FLAG;\ - }\ - tm_ptr = tm_ptr_head;\ - while( tm_ptr != NULL ){\ - int length = TM_SHORT_SIZE;\ - if( GETshort_or_long_tm(tm_ptr) == SHORT_TM_CODE ){\ - length = TM_SHORT_SIZE;\ - }\ - else{\ - length = TM_LONG_SIZE;\ - }\ - /*gPC.puts("Printing Call Sign, ACK_L1, TM list");*/\ - for(int i = 0 ; i < length ; ++i){\ - /*gPC.putc(tm_ptr->TM_string[i]);*/\ - }\ - tm_ptr = tm_ptr->next_TM;\ - }\ - /*SEND call sign, ACK_L1, OBSRS TO GS*/\ - /*snd_tm.head_pointer(tm_ptr_head);*/\ - /*transmit_adf;*/\ - /*DELETE THE TM AFTER USE*/\ - tm_ptr = tm_ptr_head;\ - overflowCountExecute = 0;\ - while(tm_ptr != NULL){\ - if( overflowCountExecute < TM_OVERFLOW_CONSTANT ){\ - Base_tm *temp = tm_ptr->next_TM;\ - delete tm_ptr;\ - tm_ptr = temp;\ - ++overflowCountExecute;\ - }\ - else{\ - RESET_CDMS;\ - break;\ - }\ - }\ }\ }\ break;\ @@ -1641,15 +1561,15 @@ if (DEBUG)\ gPC.puts("ABORTING DUE TO ABORT ON NACK\r\n");\ /*EXITED DUE TO ABORT ON NACK:*/\ - /*COM_TX_CNTRL = 0;*/\ + COM_TX_CNTRL = 0;\ RX1M.attach(&rx_read, Serial::RxIrq);\ gFLAGS = gFLAGS & (~COM_MNG_TMTC_RUNNING_FLAG);\ break;\ }\ - else if( gFLAGS & COM_PA_HOT_FLAG ){\ + else if( (gFLAGS & COM_PA_HOT_FLAG) || (gFLAGS & COM_PA_OC_FLAG) ){\ /*PA HOT: WAIT FOR TIMEOUT*/\ gCOM_PA_COOLING_TIMEOUT.attach(&after_cooling_pa, COM_PA_COOLING_TIME_LIMIT);\ - /*COM_TX_CNTRL = 0;*/\ + COM_TX_CNTRL = 0;\ RX1M.attach(&rx_read, Serial::RxIrq);\ gFLAGS = gFLAGS & (~COM_MNG_TMTC_RUNNING_FLAG);\ break;\
--- a/COM_POWER_OFF_TX.h Thu Jul 14 13:07:30 2016 +0000 +++ b/COM_POWER_OFF_TX.h Thu Jul 14 17:57:05 2016 +0000 @@ -1,15 +1,97 @@ +#define RESET_CDMS_TC {\ + Base_tc *RESET_tc = new Short_tc;\ + RESET_tc->next_TC = NULL;\ + PUTshort_or_long(RESET_tc,SHORT_TC_CODE);\ + PUTcrc_pass(RESET_tc,0x1);\ + PUTexec_status(RESET_tc,0);\ + RESET_tc->TC_string[0] = 0x01;\ + RESET_tc->TC_string[1] = 0x81;\ + RESET_tc->TC_string[2] = 0x81;\ + RESET_tc->TC_string[3] = 0x38;\ + RESET_tc->TC_string[4] = 0;\ + RESET_tc->TC_string[5] = 0;\ + RESET_tc->TC_string[6] = 0;\ + RESET_tc->TC_string[7] = 0;\ + RESET_tc->TC_string[8] = 0;\ + uint16_t crc16 = crc16_gen(RESET_tc->TC_string, 9);\ + RESET_tc->TC_string[9] = (crc16 & 0xFF00)>>8;\ + RESET_tc->TC_string[10] = (crc16 & 0x00FF);\ + Base_tm *tm_ptr = NULL;\ + tm_ptr = FCTN_CDMS_RLY_TMTC(RESET_tc);\ + delete RESET_tc;\ + /*DELETE THE TM AFTER USE*/\ + Base_tm *del_tm = tm_ptr;\ + while( del_tm != NULL ){\ + Base_tm *temp = del_tm->next_TM;\ + delete del_tm;\ + del_tm = temp;\ + }\ +} + +#define resume_bcn {\ + Base_tc *beacon_tc = new Long_tc;\ + beacon_tc->next_TC = NULL;\ + PUTshort_or_long(beacon_tc,LONG_TC_CODE);\ + PUTcrc_pass(beacon_tc,0x1);\ + PUTexec_status(beacon_tc,0);\ + beacon_tc->TC_string[0] = 0x01;\ + beacon_tc->TC_string[1] = BCN_APID_SOURCE;\ + beacon_tc->TC_string[2] = BCN_SERVICE;\ + beacon_tc->TC_string[3] = 0xE2;\ + beacon_tc->TC_string[4] = 0x00;\ + beacon_tc->TC_string[5] = 0;\ + beacon_tc->TC_string[6] = 0;\ + beacon_tc->TC_string[7] = 0;\ + beacon_tc->TC_string[8] = 0;\ + uint16_t crc16 = crc16_gen(beacon_tc->TC_string, 9);\ + beacon_tc->TC_string[9] = (crc16 & 0xFF00)>>8;\ + beacon_tc->TC_string[10] = (crc16 & 0x00FF);\ + for(int i = 11; i < 135; i++){\ + beacon_tc->TC_string[i] = 0;\ + }\ + Base_tm *tm_ptr = NULL;\ + tm_ptr = FCTN_CDMS_RLY_TMTC(beacon_tc);\ + delete beacon_tc;\ + /*DELETE THE TM AFTER USE*/\ + Base_tm *del_tm = tm_ptr;\ + int overCount = 0;\ + while( del_tm != NULL ){\ + if( (overCount < TM_OVERFLOW_CONSTANT) ){\ + Base_tm *temp = del_tm->next_TM;\ + delete del_tm;\ + del_tm = temp;\ + ++overCount;\ + }\ + else{\ + RESET_CDMS;\ + break;\ + }\ + }\ +} + #define COM_POWER_OFF_TX {\ /*gPC.puts("Inside COM_POWER_OFF_TX\r\n");*/\ - /*PENDING: POWER OFF TRANSMITTER*/\ + COM_TX_CNTRL = 0;\ RX1M.attach(&rx_read, Serial::RxIrq);\ gFLAGS = gFLAGS & (~COM_MNG_TMTC_RUNNING_FLAG);\ - /*PENDING: SWITCH RF RELAY TO BEACON*/\ - /*PENDING: RF_SW_STATUS = RF_BCN*/\ - /*PENDING: POWER ON BAE*/\ - /*PENDING: SET BAE SW_EN_STATUS*/\ - /*PENDING: RESUME BEACON*/\ + RF_SW_CNTRL_BCN = 1;\ + Thread::wait(25);\ + RF_SW_CNTRL_BCN = 0;\ + gFLAGS = gFLAGS | RF_SW_STATUS_FLAG;\ + if( gFLAGS & COM_AUTO_POWER_OFF_BAE_FLAG ){\ + SW_ON_BAE;\ + gFLAGS & (~COM_AUTO_POWER_OFF_BAE_FLAG);\ + resume_bcn;\ + }\ + else{\ + if( gFLAGS & BAE_SW_EN_FLAG ){\ + resume_bcn;\ + }\ + }\ gFLAGS = gFLAGS & (~COM_PA_HOT_FLAG);\ + gFLAGS = gFLAGS & (~COM_PA_OC_FLAG);\ gCOM_PA_COOLING_TIMEOUT.detach();\ gFLAGS = gFLAGS & (~COM_TX_FLAG);\ - /*gPC.puts("ompleted com_power_off tx\r\n");*/\ + gFLAGS = gFLAGS & (~COM_SESSION_TIMEOUT_FLAG);\ + /*gPC.puts("completed com_power_off tx\r\n");*/\ } \ No newline at end of file
--- a/COM_POWER_ON_TX.h Thu Jul 14 13:07:30 2016 +0000 +++ b/COM_POWER_ON_TX.h Thu Jul 14 17:57:05 2016 +0000 @@ -1,107 +1,367 @@ -#define COM_POWER_ON_TX {\ - /*gPC.puts("Inside COM_POWER_ON_TX\r\n");*/\ - if( !(gFLAGS & COM_TX_FLAG) ){\ - gFLAGS = gFLAGS | COM_TX_FLAG;\ - /*WARNING: INFINITE WHILE LOOP POSSIBLE: if standby ack received and bcn tx main status = 0*/\ - bool retryFlag = true;\ - while( retryFlag == true ){\ - uint8_t standbyAck = 0xFF;\ - /*PENDING: SET BEACON TO STANDBY*/\ - if( standbyAck == 0xFF ){\ - /*ACK RECCEIVED*/\ - /*PENDING: BEACON TX MAIN STATUS*/\ - if( true ){\ - retryFlag = false;\ - /*PENDING: SWITCH RELAY TO COM_TX*/\ - /*PENDING: RF_SW_STATUS = RF_COM_TX*/\ - }\ - else{\ - gCOM_MNG_TMTC_THREAD->wait(5000);\ - }\ - }\ - else{\ - /*PENDING: RESET BAE*/\ - uint8_t standbyAck2 = 0x00;\ - /*PENDING: SET BEACON TO STANDBY*/\ - if( standbyAck2 == 0xFF ){\ - /*PENDING: BEACON TX MAIN STAUTS*/\ - if( true ){\ - retryFlag = false;\ - /*PENDING: SWITCH RF RELAY TO COM TX*/\ - /*PENDING: RF_SW_STATUS = RF_COM_TX*/\ - }\ - }\ - else{\ - retryFlag = false;\ - /*PENDING: POWER OFF BEACON*/\ - /*PENDING: CLEAR BAE SW_EN*/\ - /*PENDING: SWITCH RF RELAY TO COM TX*/\ - /*PENDING: RF_SW_STATUS = RF_COM_TX*/\ - }\ - }\ +#define STANDBY_PRCS(tm_ptr){\ + Base_tc *stdby_tc = new Long_tc;\ + stdby_tc->next_TC = NULL;\ + PUTshort_or_long(stdby_tc,LONG_TC_CODE);\ + PUTcrc_pass(stdby_tc,0x1);\ + PUTexec_status(stdby_tc,0);\ + stdby_tc->TC_string[0] = 0x01;\ + stdby_tc->TC_string[1] = 0x41;\ + stdby_tc->TC_string[2] = 0x81;\ + stdby_tc->TC_string[3] = 0x40;\ + stdby_tc->TC_string[4] = 0;\ + stdby_tc->TC_string[5] = 0;\ + stdby_tc->TC_string[6] = 0;\ + stdby_tc->TC_string[7] = 0;\ + stdby_tc->TC_string[8] = 0;\ + uint16_t crc16 = crc16_gen(stdby_tc->TC_string, 9);\ + stdby_tc->TC_string[9] = (crc16 & 0xFF00)>>8;\ + stdby_tc->TC_string[10] = (crc16 & 0x00FF);\ + for(int i = 11; i < 135; i++){\ + stdby_tc->TC_string[i] = 0;\ + }\ + tm_ptr = FCTN_CDMS_RLY_TMTC(stdby_tc);\ + delete stdby_tc;\ +} + +#define SET_BCN_STANDBY(tm_ptr){\ + Base_tc *beacon_tc = new Long_tc;\ + beacon_tc->next_TC = NULL;\ + PUTshort_or_long(beacon_tc,LONG_TC_CODE);\ + PUTcrc_pass(beacon_tc,0x1);\ + PUTexec_status(beacon_tc,0);\ + beacon_tc->TC_string[0] = 0x01;\ + beacon_tc->TC_string[1] = BCN_APID_SOURCE;\ + beacon_tc->TC_string[2] = BCN_SERVICE;\ + beacon_tc->TC_string[3] = 0xE2;\ + beacon_tc->TC_string[4] = 0x01;\ + beacon_tc->TC_string[5] = 0;\ + beacon_tc->TC_string[6] = 0;\ + beacon_tc->TC_string[7] = 0;\ + beacon_tc->TC_string[8] = 0;\ + uint16_t crc16 = crc16_gen(beacon_tc->TC_string, 9);\ + beacon_tc->TC_string[9] = (crc16 & 0xFF00)>>8;\ + beacon_tc->TC_string[10] = (crc16 & 0x00FF);\ + for(int i = 11; i < 135; i++){\ + beacon_tc->TC_string[i] = 0;\ + }\ + tm_ptr = FCTN_CDMS_RLY_TMTC(beacon_tc);\ + delete beacon_tc;\ +} + +#define P_CDMS_HK_MAIN {\ + Base_tc *hk_main_ptr = new Short_tc;\ + hk_main_ptr->next_TC = NULL;\ + PUTshort_or_long(hk_main_ptr,SHORT_TC_CODE);\ + PUTcrc_pass(hk_main_ptr,0x1);\ + PUTexec_status(hk_main_ptr,0);\ + hk_main_ptr->TC_string[0] = 0x01;\ + hk_main_ptr->TC_string[1] = 0x81;\ + hk_main_ptr->TC_string[2] = 0x81;\ + hk_main_ptr->TC_string[3] = 0x04;\ + hk_main_ptr->TC_string[4] = 0;\ + hk_main_ptr->TC_string[5] = 0;\ + hk_main_ptr->TC_string[6] = 0;\ + hk_main_ptr->TC_string[7] = 0;\ + hk_main_ptr->TC_string[8] = 0;\ + uint16_t crc16 = crc16_gen(hk_main_ptr->TC_string, 9);\ + hk_main_ptr->TC_string[9] = (crc16 & 0xFF00)>>8;\ + hk_main_ptr->TC_string[10] = (crc16 & 0x00FF);\ + Base_tm *tm_ptr = NULL;\ + tm_ptr = FCTN_CDMS_RLY_TMTC(hk_main_ptr);\ + delete hk_main_ptr;\ + /*DELETE THE TM AFTER USE*/\ + Base_tm *del_tm = tm_ptr;\ + int overCount = 0;\ + while( del_tm != NULL ){\ + if( (overCount < TM_OVERFLOW_CONSTANT) ){\ + Base_tm *temp = del_tm->next_TM;\ + delete del_tm;\ + del_tm = temp;\ + ++overCount;\ }\ - }\ - /*PENDING: POWER ON COM_TX*/\ - uint8_t adfConfigPass = 0xFF;\ - for( int i = 0 ; i < COM_TX_CONFIG_LIMIT ; ++i ){\ - /*PENDING: CONFIGURE ADF*/\ - if( adfConfigPass == 0xFF ){\ + else{\ + RESET_CDMS;\ break;\ }\ }\ - if( adfConfigPass == 0xFF ){\ - /*adf successfully configured*/\ - /*CALL SIGN*/\ - Base_tm *power_on_tm = NULL;\ - Base_tm *power_on_tm_head = NULL;\ - get_call_sign( power_on_tm_head );\ - power_on_tm = power_on_tm_head;\ - /*ACK L1*/\ - get_ack_l1(power_on_tm->next_TM);\ - int overFlowCountADF = 0;\ - while( power_on_tm->next_TM != NULL ){\ - if( overFlowCountADF < TM_OVERFLOW_CONSTANT ){\ - power_on_tm = power_on_tm->next_TM;\ - ++overFlowCountADF;\ - }\ - else{\ - /*PENDING: RESET CDMS*/\ - break;\ - }\ - }\ - get_tc_list(power_on_tm->next_TM, 0x00);\ - /*PENDING: TRANSMIT ABOVE TM*/\ - /*Call Sign, ACK_L1, TC_LIST*/\ - /*snd_tm.head_pointer(power_on_tm_head);*/\ - /*transmit_adf;*/\ - /*deleting the telemetry*/\ - power_on_tm = power_on_tm_head;\ - overFlowCountADF = 0;\ - while( power_on_tm != NULL ){\ - if( overFlowCountADF < TM_OVERFLOW_CONSTANT ){\ - Base_tm *temp = power_on_tm->next_TM;\ - delete power_on_tm;\ - power_on_tm = temp;\ - ++overFlowCountADF;\ - }\ - else{\ - /*PENDING: RESET CDMS*/\ - break;\ - }\ - }\ +} + +#define P_BCN_TX_MAIN(tm_ptr) {\ + Base_tc *bcn_tx_main_ptr = new Long_tc;\ + bcn_tx_main_ptr->next_TC = NULL;\ + PUTshort_or_long(bcn_tx_main_ptr,LONG_TC_CODE);\ + PUTcrc_pass(bcn_tx_main_ptr,0x1);\ + PUTexec_status(bcn_tx_main_ptr,0);\ + bcn_tx_main_ptr->TC_string[0] = 0x01;\ + bcn_tx_main_ptr->TC_string[1] = 0x41;\ + bcn_tx_main_ptr->TC_string[2] = 0x81;\ + bcn_tx_main_ptr->TC_string[3] = 0x07;\ + bcn_tx_main_ptr->TC_string[4] = 0;\ + bcn_tx_main_ptr->TC_string[5] = 0;\ + bcn_tx_main_ptr->TC_string[6] = 0;\ + bcn_tx_main_ptr->TC_string[7] = 0;\ + bcn_tx_main_ptr->TC_string[8] = 0;\ + uint16_t crc16 = crc16_gen(bcn_tx_main_ptr->TC_string, 9);\ + bcn_tx_main_ptr->TC_string[9] = (crc16 & 0xFF00)>>8;\ + bcn_tx_main_ptr->TC_string[10] = (crc16 & 0x00FF);\ + for(int i = 11; i < 135; i++){\ + bcn_tx_main_ptr->TC_string[i] = 0;\ }\ - else{\ - /*PENDING: COM_POWER OFF TX*/\ - /*PENDING: CDMS HK MAIN*/\ - uint8_t ackReceived = 0x00;\ - /*PENDING: BCN TX MAIN*/\ - if( ackReceived == 0xFF ){\ - gCOM_MNG_TMTC_THREAD->wait(5000);\ - /*PENDING: RESET CDMS*/\ - }\ - else{\ - /*PENDING: RESET CDMS*/\ - }\ - }\ - /*gPC.puts("COMPLETED COM_POWER_ON_TX\r\n");*/\ + tm_ptr = FCTN_CDMS_RLY_TMTC(bcn_tx_main_ptr);\ + delete bcn_tx_main_ptr;\ +} + +void COM_POWER_ON_TX() { + if (DEBUG) + gPC.puts("Inside COM_POWER_ON_TX\r\n"); + if( !(gFLAGS & COM_TX_FLAG) ){ + gFLAGS = gFLAGS | COM_TX_FLAG; + if( gFLAGS & BAE_SW_EN_FLAG ){ + /*WARNING: INFINITE WHILE LOOP POSSIBLE: if standby ack received and bcn tx main status = 0*/ + bool retryFlag = true; + while( retryFlag == true ){ + Base_tm *tm_ptr = NULL; + SET_BCN_STANDBY(tm_ptr); + uint8_t bcn_main_status = (tm_ptr->TM_string[2] & 0xEF); + if(( bcn_main_status == 0xC0 )||( bcn_main_status ==0xA0 )){ + /*ACK RECCEIVED*/ + if( bcn_main_status == 0xA0 ){ + retryFlag = false; + RF_SW_CNTRL_TX = 1; + Thread::wait(25); + RF_SW_CNTRL_TX = 0; + gFLAGS = gFLAGS & (~RF_SW_STATUS_FLAG);/*RF_SW_STATUS_FLAG set to RF_COM_TX*/ + } + else{ + Thread::wait(5000); + } + } + else{ + SW_RST_BAE(); + Base_tm *tm_ptr2 = NULL; + SET_BCN_STANDBY(tm_ptr2); + uint8_t standbyAck2 = 0; + uint8_t bcn_main_status2 = (tm_ptr2->TM_string[2] & 0xEF); + if( ( bcn_main_status2 == 0xC0 )||( bcn_main_status2 == 0xA0 ) ){ + if( bcn_main_status2 == 0xA0 ){ + retryFlag = false; + RF_SW_CNTRL_TX = 1; + Thread::wait(25); + RF_SW_CNTRL_TX = 0; + gFLAGS = gFLAGS & (~RF_SW_STATUS_FLAG); + } + else{ + Thread::wait(5000); + } + } + else{ + retryFlag = false; + SW_OFF_BAE(); + gFLAGS = gFLAGS | COM_AUTO_POWER_OFF_BAE_FLAG; + RF_SW_CNTRL_TX = 1; + Thread::wait(25); + RF_SW_CNTRL_TX = 0; + gFLAGS = gFLAGS & (~RF_SW_STATUS_FLAG);/*RF_SW_STATUS_FLAG set to RF_COM_TX*/ + } + /*DELETE THE TM AFTER USE*/ + Base_tm *del_tm = tm_ptr2; + int overCount = 0; + while( del_tm != NULL ){ + if( (overCount < TM_OVERFLOW_CONSTANT) ){ + Base_tm *temp = del_tm->next_TM; + delete del_tm; + del_tm = temp; + ++overCount; + } + else{ + RESET_CDMS; + break; + } + } + } + /*DELETE THE TM AFTER USE*/ + Base_tm *del_tm = tm_ptr; + int overCount = 0; + while( del_tm != NULL ){ + if( (overCount < TM_OVERFLOW_CONSTANT) ){ + Base_tm *temp = del_tm->next_TM; + delete del_tm; + del_tm = temp; + ++overCount; + } + else{ + RESET_CDMS; + break; + } + } + } + } + else{ + RF_SW_CNTRL_TX = 1; + Thread::wait(25); + RF_SW_CNTRL_TX = 0; + gFLAGS = gFLAGS & (~RF_SW_STATUS_FLAG);/*RF_SW_STATUS_FLAG set to RF_COM_TX*/ + } + } + COM_TX_CNTRL = 1; + uint8_t adfConfigPass = 0xFF; + for( int i = 0 ; i < COM_TX_CONFIG_LIMIT ; ++i ){ + /*PENDING: CONFIGURE ADF and set adfConfigPass*/ + if( adfConfigPass == 0xFF ){ + break; + } + } + if( adfConfigPass == 0xFF ){ + /*adf successfully configured*/ + gFLAGS = gFLAGS | COM_TX_STATUS_FLAG; + /*CALL SIGN*/ + Base_tm *power_on_tm = NULL; + Base_tm *power_on_tm_head = NULL; + get_call_sign( power_on_tm_head ); + power_on_tm = power_on_tm_head; + /*ACK L1*/ + get_ack_l1(power_on_tm->next_TM); + int overFlowCountADF = 0; + while( power_on_tm->next_TM != NULL ){ + if( overFlowCountADF < TM_OVERFLOW_CONSTANT ){ + power_on_tm = power_on_tm->next_TM; + ++overFlowCountADF; + } + else{ + RESET_CDMS; + break; + } + } + get_tc_list(power_on_tm->next_TM, 0x00); + /*Call Sign, ACK_L1, TC_LIST*/ + /*snd_tm.head_pointer(power_on_tm_head);*/ + /*transmit_adf;*/ + uint8_t transmissionPass = 0xFF; + /*PENDING: get acknowledgement of transmission*/ + /*deleting the telemetry*/ + power_on_tm = power_on_tm_head; + overFlowCountADF = 0; + while( power_on_tm != NULL ){ + if( overFlowCountADF < TM_OVERFLOW_CONSTANT ){ + Base_tm *temp = power_on_tm->next_TM; + delete power_on_tm; + power_on_tm = temp; + ++overFlowCountADF; + } + else{ + RESET_CDMS; + break; + } + } + if( transmissionPass == 0 ){ + /*NOT Transmitted succesfully*/ + COM_POWER_OFF_TX; + P_CDMS_HK_MAIN; + Base_tm *ptr_tm = NULL; + STANDBY_PRCS(ptr_tm); + uint8_t standbyACK = 0x00; + uint8_t bcn_main_status = (ptr_tm->TM_string[2] & 0xEF); + if(( bcn_main_status == 0xC0 )||( bcn_main_status ==0xA0 )){ + standbyACK = 1; + } + if(standbyACK == 1){ + uint8_t ackReceived = 0x00; + Base_tm *tm_ptr = NULL; + P_BCN_TX_MAIN(tm_ptr); + uint8_t ackcode = tm_ptr->TM_string[2] & 0xEF; + if( (ackcode == 0xA0) || (ackcode == 0xC0)) + ackReceived = 0xFF; + /*DELETE THE TM AFTER USE*/ + Base_tm *del_tm = tm_ptr; + int overCount = 0; + while( del_tm != NULL ){ + if( (overCount < TM_OVERFLOW_CONSTANT) ){ + Base_tm *temp = del_tm->next_TM; + delete del_tm; + del_tm = temp; + ++overCount; + } + else{ + RESET_CDMS; + break; + } + } + if( ackReceived == 0xFF ){ + Thread::wait(5000); + } + } + /*DELETE THE TM AFTER USE*/ + Base_tm *del_tm = ptr_tm; + int overCount = 0; + while( del_tm != NULL ){ + if( (overCount < TM_OVERFLOW_CONSTANT) ){ + Base_tm *temp = del_tm->next_TM; + delete del_tm; + del_tm = temp; + ++overCount; + } + else{ + RESET_CDMS; + break; + } + } + RESET_CDMS_TC; + } + } + else{ + /*ADF not configured*/ + gFLAGS = gFLAGS & (~COM_TX_STATUS_FLAG); + COM_POWER_OFF_TX; + P_CDMS_HK_MAIN; + Base_tm *ptr_tm = NULL; + STANDBY_PRCS(ptr_tm); + uint8_t standbyACK = 0x00; + uint8_t bcn_main_status = (ptr_tm->TM_string[2] & 0xEF); + if(( bcn_main_status == 0xC0 )||( bcn_main_status ==0xA0 )){ + standbyACK = 1; + } + if(standbyACK == 1){ + uint8_t ackReceived = 0x00; + Base_tm *tm_ptr = NULL; + P_BCN_TX_MAIN(tm_ptr); + uint8_t ackcode = tm_ptr->TM_string[2] & 0xEF; + if( (ackcode == 0xA0) || (ackcode == 0xC0)) + ackReceived = 0xFF; + /*DELETE THE TM AFTER USE*/ + Base_tm *del_tm = tm_ptr; + int overCount = 0; + while( del_tm != NULL ){ + if( (overCount < TM_OVERFLOW_CONSTANT) ){ + Base_tm *temp = del_tm->next_TM; + delete del_tm; + del_tm = temp; + ++overCount; + } + else{ + RESET_CDMS; + break; + } + } + if( ackReceived == 0xFF ){ + Thread::wait(5000); + } + } + /*DELETE THE TM AFTER USE*/ + Base_tm *del_tm = ptr_tm; + int overCount = 0; + while( del_tm != NULL ){ + if( (overCount < TM_OVERFLOW_CONSTANT) ){ + Base_tm *temp = del_tm->next_TM; + delete del_tm; + del_tm = temp; + ++overCount; + } + else{ + RESET_CDMS; + break; + } + } + RESET_CDMS_TC; + } + /*gPC.puts("COMPLETED COM_POWER_ON_TX\r\n");*/ } \ No newline at end of file
--- a/COM_RCV_TC.h Thu Jul 14 13:07:30 2016 +0000 +++ b/COM_RCV_TC.h Thu Jul 14 17:57:05 2016 +0000 @@ -261,5 +261,4 @@ gRX_COUNT = 0; /*gPC.puts("Completed conversion of raw_data\r\n")*/; - // PENDING: SORT THE LINKED LIST ACCORDING TO PSC VALUE } \ No newline at end of file
--- a/DefinitionsAndGlobals.h Thu Jul 14 13:07:30 2016 +0000 +++ b/DefinitionsAndGlobals.h Thu Jul 14 17:57:05 2016 +0000 @@ -38,10 +38,9 @@ // TC LIST #define TCL_STATE_INCOMPLETE 0x00 - #define TCL_STATE_ABORTED 0x03 - #define TCL_STATE_EXECUTING 0x04 - #define TCL_STATE_COMPLETED 0x05 - #define TCL_STATE_EXCEEDED_LIMIT 0x06 + #define TCL_STATE_ABORTED 0x01 + #define TCL_STATE_EXECUTING 0x02 + #define TCL_STATE_COMPLETED 0x03 // LIST OF FLAGS #define UART_INT_FLAG 0x0001 @@ -52,6 +51,7 @@ #define COM_SESSION_VALIDITY 0x0020 #define ALL_CRC_PASS_FLAG 0x0040 #define COM_PA_HOT_FLAG 0x0080 + #define COM_PA_OC_FLAG 0x8000 #define COM_TX_FLAG 0x0100 #define COM_SESSION_TIMEOUT_FLAG 0x0200 #define COM_AUTO_POWER_OFF_BAE_FLAG 0x0400 @@ -69,10 +69,11 @@ #define COM_MNG_TMTC_SIGNAL_UART_INT 0x01 #define COM_MNG_TMTC_SIGNAL_ADF_NSD 0x02 #define COM_MNG_TMTC_SIGNAL_ADF_SD 0x03 + #define cdms_reset_timeout 345600000 // COM_MNG_TMTC #define COM_PA_COOLING_TIME_LIMIT 20 - #define COM_MAX_TC_LIMIT 200 + #define COM_MAX_TC_LIMIT 256 #define TM_ACK_CODE_INDEX 2 #define CRC_FAIL_NACK_CODE 0x01 @@ -83,6 +84,7 @@ // max value of telecommands in a tcl #define TCL_OVERFLOW_CONSTANT 256 #define TM_OVERFLOW_CONSTANT 256 + #define BYTE_OVERFLOW_CONSTANT 35000 // starting value of packet sequence count at each pass #define PSC_START_VALUE 1 @@ -142,8 +144,8 @@ #define BAE_RESET_PID 0x33 //RF RELAY - #define RF_RELAY_CNTRL_TX PTA7 - #define RF_RELAY_CNTRL_BCN PTA12 + #define RF_RELAY_CNTRL_TX PTB7 + #define RF_RELAY_CNTRL_BCN PTB12 //CDMS HK #define HK_SIGNAL 0x05 @@ -173,6 +175,7 @@ COM_RX_DATA_NODE *gRX_CURRENT_DATA_NODE = NULL; // uint8_t *gRX_CURRENT_PTR = NULL; uint32_t gRX_COUNT = 0; +uint16_t gTOTAL_RAW_BYTES = 0; uint16_t gTOTAL_INCORRECT_SIZE_TC = 0x00; uint16_t gTOTAL_CRC_FAIL_TC = 0x00; uint16_t gTOTAL_REPEATED_TC = 0x00; @@ -194,6 +197,7 @@ //COM_RX DigitalOut COM_RX_CNTRL(PIN72); DigitalOut COM_TX_CNTRL(PIN56); +DigitalIn COM_TX_OC_FAULT(PIN69); // TC LIST Base_tc* gHEAD_NODE_TCL = NULL; @@ -205,10 +209,10 @@ Thread* gCOM_MNG_TMTC_THREAD = NULL; Timeout gRX_TIMEOUT; Timeout gSESSION_TIMEOUT; +Timeout gCOM_RX_DISABLE; // COM_MNG_TMTC - - +RtosTimer *sys_reset_cdms_timer; // PA cooling timeout Timeout gCOM_PA_COOLING_TIMEOUT;
--- a/FMS_all.h Thu Jul 14 13:07:30 2016 +0000 +++ b/FMS_all.h Thu Jul 14 17:57:05 2016 +0000 @@ -35,6 +35,7 @@ void RST_PL_BEE(); void CDMS_RESET(); void SYS_PWR_RESET(); // Have to be decided with EPS team. +void sys_pwr_reset(void const *args); void EPS_V_A_EN(); void EPS_V_C_EN(); @@ -43,6 +44,9 @@ void CDMS_CALIB_RTC(uint8_t *); void TOTAL_RESET_WITH_CDMS(); +void sys_pwr_reset(void const *args){ + SYS_PWR_RESET(); +} void STANDBY_PRCS() {
--- a/P_COM_INIT.h Thu Jul 14 13:07:30 2016 +0000 +++ b/P_COM_INIT.h Thu Jul 14 17:57:05 2016 +0000 @@ -4,7 +4,7 @@ Thread::wait(25);\ RF_SW_CNTRL_BCN = 0;\ gFLAGS = gFLAGS | RF_SW_STATUS_FLAG;\ - //COM_RX_CNTRL = 0;\ + COM_RX_CNTRL = 0;\ Thread::wait(200);\ COM_RX_CNTRL = 1;\ gFLAGS = gFLAGS & (~COM_INIT_STATUS_FLAG);\
--- a/ThreadsAndFunctions.h Thu Jul 14 13:07:30 2016 +0000 +++ b/ThreadsAndFunctions.h Thu Jul 14 17:57:05 2016 +0000 @@ -43,6 +43,12 @@ gCOM_MNG_TMTC_THREAD->signal_set(COM_MNG_TMTC_SIGNAL_UART_INT); } +// COM_RX_DISABLE ISR +void after_com_disable(){ + gCOM_RX_DISABLE.detach(); + RX1M.attach(&rx_read, Serial::RxIrq); +} + // RX_TIMEOUT ISR void after_receive(){ gRX_TIMEOUT.detach(); @@ -70,15 +76,15 @@ }\ gHEAD_NODE_TCL = NULL;\ gLAST_NODE_TCL = NULL;\ - gMASTER_STATE = TCL_STATE_INCOMPLETE;\ + gMASTER_STATE = TCL_STATE_COMPLETED;\ gTOTAL_INCORRECT_SIZE_TC = 0;\ gTOTAL_CRC_FAIL_TC = 0;\ gTOTAL_REPEATED_TC = 0;\ gTOTAL_VALID_TC = 0;\ for(int i = 0 ; i < TM_LONG_SIZE ; ++i){\ - gLAST_TM[i] = 0x00;\ + /*gLAST_TM[i] = 0x00;*/\ }\ - gLAST_TM_SHORT_OR_LONG = SHORT_TM_CODE;\ + /*gLAST_TM_SHORT_OR_LONG = SHORT_TM_CODE;*/\ COM_RX_DATA_NODE *dataptr = gRX_HEAD_DATA_NODE;\ while( dataptr != NULL ){\ COM_RX_DATA_NODE *temp = dataptr->next_node;\ @@ -89,6 +95,7 @@ gRX_HEAD_DATA_NODE->next_node = NULL;\ gRX_CURRENT_DATA_NODE = gRX_HEAD_DATA_NODE;\ gRX_COUNT = 0;\ + gTOTAL_RAW_BYTES = 0;\ /*PENDING : ALL GLOBAL VAARIABLES AND FLAGS*/\ /*gPC.puts("finished reset all\r\n");*/\ } @@ -103,6 +110,7 @@ gRX_CURRENT_DATA_NODE = gRX_CURRENT_DATA_NODE->next_node;\ gRX_CURRENT_DATA_NODE->next_node = NULL;\ }\ + ++gTOTAL_RAW_BYTES;\ gRX_TIMEOUT.attach(&after_receive, RX_TIMEOUT_LIMIT);\ } @@ -122,6 +130,7 @@ gFLAGS = gFLAGS | COM_SESSION_FLAG; gSESSION_TIMEOUT.attach(&after_session, SESSION_TIME_LIMIT); gFLAGS = gFLAGS | COM_RX_FLAG; + gTOTAL_RAW_BYTES = 0; PUT_RAW_BYTE; // PENDING : MEASURE RSSI if( gFLAGS & COM_SESSION_FLAG ){ @@ -140,6 +149,11 @@ gFLAGS = gFLAGS | COM_RX_FLAG; PUT_RAW_BYTE; } + if(gTOTAL_RAW_BYTES > BYTE_OVERFLOW_CONSTANT){ + RX1M.attach(NULL); + gCOM_RX_DISABLE.attach(&after_com_disable, COM_RX_DISABLE_TIMEOUT); + after_receive(); + } } else if( gFLAGS & NEW_TC_RECEIVED ){ gPC.puts("NEW TC RECEIVED\r\n"); @@ -178,26 +192,22 @@ if( tempGSver == 0xFF ){ /*gPC.puts("GS code match !!\r\n");*/ gFLAGS = gFLAGS | COM_SESSION_VALIDITY; + sys_reset_cdms_timer->start(cdms_reset_timeout); COM_POWER_ON_TX; - // PENDING: PA HOT HANDLED IN EXECUTE_XXX FUNCTIONS - uint8_t tempPAHot = 0x00; - isPAhot(tempPAHot); - if( tempPAHot == 0xFF ){ - gFLAGS = gFLAGS & ~(COM_PA_HOT_FLAG); + P_COM_HK; + if( (gFLAGS & COM_PA_HOT_FLAG) || ( gFLAGS & COM_PA_OC_FLAG ) ){ + COM_TX_CNTRL = 0; + gCOM_PA_COOLING_TIMEOUT.attach(&after_cooling_pa, COM_PA_COOLING_TIME_LIMIT); + gFLAGS = gFLAGS & (~COM_MNG_TMTC_RUNNING_FLAG); + RX1M.attach(&rx_read, Serial::RxIrq); + } + else{ gCOM_PA_COOLING_TIMEOUT.detach(); gPC.puts("EXECUTING TELECOMMANDS\r\n"); -// DEBUF_PRINT("EXECUTING TELECOMMANDS\r\n"); EXECUTE_OBOSC_ONLY; EXECUTE_TC; gPC.puts("COMPLETED EXECUTION\r\n"); } - else{ - gFLAGS = gFLAGS | COM_PA_HOT_FLAG; - // PENDING: power off transmitter only - gCOM_PA_COOLING_TIMEOUT.attach(&after_cooling_pa, COM_PA_COOLING_TIME_LIMIT); - gFLAGS = gFLAGS & (~COM_MNG_TMTC_RUNNING_FLAG); - RX1M.attach(&rx_read, Serial::RxIrq); - } } else{ /*gPC.puts("GS code mismatch !!\r\n");*/ @@ -210,6 +220,7 @@ gSESSION_TIMEOUT.detach(); gFLAGS = gFLAGS & (~COM_SESSION_FLAG); // WARNING: clear COM_MNG_TMTC ? + gFLAGS = gFLAGS & (~COM_MNG_TMTC_RUNNING_FLAG); } } else{ @@ -241,6 +252,7 @@ //gPC.puts("\r\n"); COM_POWER_ON_TX; // PENDING : POWER OFF TX + COM_TX_CNTRL = 0; RX1M.attach(&rx_read, Serial::RxIrq); gFLAGS = gFLAGS & (~COM_MNG_TMTC_RUNNING_FLAG); } @@ -249,6 +261,9 @@ COM_POWER_ON_TX; // POWER OFF TX transmitter only // WARNING: reset_all ? clear com_session ? + COM_TX_CNTRL = 0; + reset_all; + gFLAGS = gFLAGS & (~COM_SESSION_FLAG); RX1M.attach(&rx_read, Serial::RxIrq); gFLAGS = gFLAGS & (~COM_MNG_TMTC_RUNNING_FLAG); } @@ -267,29 +282,17 @@ } else if( gFLAGS & COM_PA_HOT_FLAG ){ /*gPC.puts("checking for PA hot in main\r\n");*/ - if( gFLAGS & COM_RX_FLAG ){ - uint8_t tempPA = 0xFF; - isPAhot(tempPA); - if( tempPA == 0x00 ){ - gCOM_PA_COOLING_TIMEOUT.attach(&after_cooling_pa, COM_PA_COOLING_TIME_LIMIT); - } - else{ - gFLAGS = gFLAGS & ~(COM_PA_HOT_FLAG); - gCOM_PA_COOLING_TIMEOUT.detach(); - } + P_COM_HK; + if((gFLAGS & COM_PA_HOT_FLAG) || (gFLAGS & COM_PA_OC_FLAG)){ + COM_TX_CNTRL = 0; + gCOM_PA_COOLING_TIMEOUT.attach(&after_cooling_pa, COM_PA_COOLING_TIME_LIMIT); } else{ - uint8_t tempPA = 0xFF; - isPAhot(tempPA); - if( tempPA == 0x00 ){ - gCOM_PA_COOLING_TIMEOUT.attach(&after_cooling_pa, COM_PA_COOLING_TIME_LIMIT); - } - else{ + gCOM_PA_COOLING_TIMEOUT.detach(); + if( !(gFLAGS & COM_RX_FLAG) ){ /*gPC.puts("PA IS COOLED DOWN\r\n");*/ - gFLAGS = gFLAGS & (~COM_PA_HOT_FLAG); gFLAGS = gFLAGS | COM_MNG_TMTC_RUNNING_FLAG; RX1M.attach(NULL); - gCOM_PA_COOLING_TIMEOUT.detach(); COM_POWER_ON_TX; EXECUTE_OBOSC_ONLY; EXECUTE_TC;
--- a/common_functions.h Thu Jul 14 13:07:30 2016 +0000 +++ b/common_functions.h Thu Jul 14 17:57:05 2016 +0000 @@ -77,7 +77,7 @@ }\ }\ else{\ - /*PENDING: reset cdms*/\ + RESET_CDMS;\ break;\ }\ }\ @@ -99,18 +99,24 @@ /*Attach this new node at the end*/\ }\ else{\ - /*PENDING: reset CDMS*/\ + RESET_CDMS;\ break;\ }\ }\ } #define put_crc_l1_ack(tm_ptr) {\ - tm_ptr->TM_string[2] = gTOTAL_CRC_FAIL_TC & 0xFF;\ /*TC LIST STATUS*/\ - tm_ptr->TM_string[3] |= (gMASTER_STATE << 5) & 0xE0;\ + tm_ptr->TM_string[3] |= (gMASTER_STATE << 6) & 0xC0;\ /*PA HOT*/\ if( gFLAGS & COM_PA_HOT_FLAG ){\ + tm_ptr->TM_string[3] |= (1 << 5);\ + }\ + else{\ + tm_ptr->TM_string[3] &= ~(1 << 5);\ + }\ + /*PA OC*/\ + if( gFLAGS & COM_PA_OC_FLAG ){\ tm_ptr->TM_string[3] |= (1 << 4);\ }\ else{\ @@ -124,14 +130,60 @@ #define fill_l1_ack(tm_ptr) {\ tm_ptr->next_TM = NULL;\ tm_ptr->TM_string[0] = TMID_ACK_L1 << 4;\ - /*PENDING: PA TEMPERATURE*/\ tm_ptr->TM_string[1] = gTOTAL_INCORRECT_SIZE_TC & 0xFF;\ tm_ptr->TM_string[2] = gTOTAL_CRC_FAIL_TC & 0xFF;\ } +#define P_COM_HK{\ + uint8_t returnHere;\ + isPAhot(returnHere);\ + if (returnHere == 0xFF)\ + gFLAGS = gFLAGS & ~(COM_PA_HOT_FLAG);\ + else\ + gFLAGS = gFLAGS | COM_PA_HOT_FLAG;\ + if (gFLAGS & COM_PA_OC_FLAG){\ + COM_TX_CNTRL = 1;\ + wait_ms(5);\ + }\ + isPAoc(returnHere);\ + if (returnHere == 0xFF)\ + gFLAGS = gFLAGS & ~(COM_PA_OC_FLAG);\ + else\ + gFLAGS = gFLAGS | COM_PA_OC_FLAG;\ + /*P_CDMS_HANDLE_HW_FAULTS*/\ +} + #define isPAhot(returnHere){\ - /*PENDING : COMPLETE THIS FUNCTION*/\ - returnHere = 0xFF;\ + uint8_t pa_temp = 0;\ + uint8_t pa_temp_quant = 0;\ + SelectLinec0=0;\ + SelectLinec1=0;\ + SelectLinec2=0;\ + SelectLinec3=1;\ + pa_temp = TempInput.read();\ + pa_temp = pa_temp * 3.3;\ + int resistance;\ + resistance = 24000 * pa_temp/(3.3 - pa_temp);\ + if(pa_temp > 1.47) {\ + pa_temp = 3694/log(24.032242*resistance);\ + }\ + else{\ + pa_temp = 3365.4/log(7.60573*resistance);\ + }\ + pa_temp_quant = quantiz(tstart_thermistor,tstep_thermistor,pa_temp);\ + if (pa_temp_quant > COM_PA_TMP_HIGH){\ + returnHere = 0;\ + }\ + else{\ + returnHere = 0xFF;\ + }\ +} + +#define isPAoc(returnHere){\ + if (COM_TX_OC_FAULT)\ + returnHere = 0;\ + else\ + returnHere = 0xFF;\ } #define get_call_sign(tm_ptr) {\ @@ -156,7 +208,6 @@ /*IF CRC PASS*/\ if( (GETcrc_pass(current_TC) == 1) ){\ if(TC_count > 4){\ - /*PENDING: FILL TC_EXEC_CODE, APPEND CRC TO THE TM*/\ put_crc_l1_ack( l1_ack );\ /*extend the TM linked list*/\ TC_count = 0;\ @@ -189,7 +240,7 @@ ++overflowCountL1;\ }\ else{\ - /*PENDING: RESET CDMS*/\ + RESET_CDMS;\ break;\ }\ }\
--- a/main.cpp Thu Jul 14 13:07:30 2016 +0000 +++ b/main.cpp Thu Jul 14 17:57:05 2016 +0000 @@ -9,7 +9,7 @@ #include "dmaSPIslave.h" #include "rtos.h" #include "mbed_debug.h" - +void rx_read(); #include "Structures.h" #include "pinconfig.h" #include "DefinitionsAndGlobals.h" @@ -22,7 +22,6 @@ #include "common_functions.h" #include "RESET_functions.h" #include "CDMS_HK.h" -#include "OBSRS.h" #include "adf.h" #include "COM_RCV_TC.h" #include "Flash.h" @@ -30,9 +29,9 @@ #include "FMS_all.h" #include "Compression.h" #include "COM_MNG_TMTC.h" +#include "COM_POWER_OFF_TX.h" #include "COM_POWER_ON_TX.h" -#include "COM_POWER_OFF_TX.h" - +#include "OBSRS.h" #include "ThreadsAndFunctions.h" #include "TEST_PL.h" @@ -187,6 +186,9 @@ HK_counter = new RtosTimer(hk_isr, osTimerPeriodic,(void * )NULL); HK_counter->start(10000); + sys_reset_cdms_timer = new RtosTimer(sys_pwr_reset, osTimerPeriodic, (void * )NULL); + sys_reset_cdms_timer->start(cdms_reset_timeout); + /*PL_wo_dma = new RtosTimer(payload_isr_fun_dma, osTimerPeriodic,(void * )NULL); PL_wo_dma->start(6000);*/ //gSCIENCE_THREAD->signal_set(SCIENCE_SIGNAL);