Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: FreescaleIAP SimpleDMA mbed-rtos mbed
Fork of CDMS_CODE by
common_functions.h
00001 00002 #define RESET_CDMS NVIC_SystemReset() 00003 #define get_tc_list(tm_ptr, thePSC){\ 00004 uint8_t TM_PSC = 0xFF;\ 00005 uint8_t TC_PSC = thePSC;\ 00006 int overflowCount = 0;\ 00007 uint8_t TC_LIST_TAG = 0x00;\ 00008 Base_tc *temp_tc = gHEAD_NODE_TCL;\ 00009 bool first_time = true;\ 00010 Base_tm *current_tm = NULL;\ 00011 while( temp_tc != NULL ){\ 00012 if( overflowCount < TCL_OVERFLOW_CONSTANT ){\ 00013 TM_PSC = TM_PSC + 1;\ 00014 /*Increment TM_PSC for every new TM pointer created*/\ 00015 Base_tm *temp_tm = new Long_tm;\ 00016 temp_tm->next_TM = NULL;\ 00017 temp_tm->TM_string[0] = 0x38;\ 00018 /*Frame type(1) = 0; TMID = 0111; Spare = 000*/\ 00019 temp_tm->TM_string[1] = TC_PSC;\ 00020 temp_tm->TM_string[3] = TM_PSC;\ 00021 int indexCustom = 4, num_of_short_tc = 0;\ 00022 while(temp_tc != NULL){\ 00023 if( overflowCount < TCL_OVERFLOW_CONSTANT ){\ 00024 if( GETshort_or_long_tc(temp_tc) == SHORT_TC_CODE ){\ 00025 for( int i = 0 ; i < TC_SHORT_SIZE ; ++i ){\ 00026 temp_tm->TM_string[indexCustom + i] = temp_tc->TC_string[i];\ 00027 }\ 00028 indexCustom = indexCustom + TC_SHORT_SIZE;\ 00029 ++overflowCount;\ 00030 /*INCREMENT STUFF*/\ 00031 temp_tc = temp_tc->next_TC;\ 00032 num_of_short_tc = num_of_short_tc + 1;\ 00033 if (temp_tc == NULL){\ 00034 for (int i = indexCustom ; i < TM_LONG_SIZE-2 ; ++i){\ 00035 temp_tm->TM_string[i] = 0;\ 00036 /*Fill remaining values with 0*/\ 00037 }\ 00038 TC_LIST_TAG = num_of_short_tc;\ 00039 break;\ 00040 }\ 00041 if( (GETshort_or_long_tc(temp_tc) == LONG_TC_CODE) || (num_of_short_tc == OBOSC_TCL_MAX_SHORT_SIZE) ){\ 00042 /*Next TC is long or memory is filled*/\ 00043 for(int i = indexCustom; i < TM_LONG_SIZE-2 ; ++i){\ 00044 temp_tm->TM_string[i] = 0;\ 00045 /*Fill remaining values with 0*/\ 00046 }\ 00047 TC_LIST_TAG = num_of_short_tc;\ 00048 break;\ 00049 }\ 00050 }\ 00051 else if (TC_LIST_TAG == OBOSC_TCL_TAG_LONG_FIRST_HALF){\ 00052 /*Long TC, 2nd half*/\ 00053 for (int i = 0; i < OBOSC_LONG_TC_SECOND_HALF_SIZE ; ++i){\ 00054 temp_tm->TM_string[indexCustom + i] = temp_tc->TC_string[OBOSC_LONG_TC_FIRST_HALF_SIZE + i];\ 00055 /*Fill the TM with TC_values*/\ 00056 }\ 00057 for (int i = OBOSC_LONG_TC_SECOND_HALF_SIZE + indexCustom ; i < TM_LONG_SIZE-2 ; ++i ){\ 00058 temp_tm->TM_string[i] = 0;\ 00059 /*Fill remaining values with 0*/\ 00060 }\ 00061 temp_tc = temp_tc->next_TC;\ 00062 TC_LIST_TAG = OBOSC_TCL_TAG_LONG_SECOND_HALF;\ 00063 ++overflowCount;\ 00064 break;\ 00065 }\ 00066 else{\ 00067 /*Long TC, 1st half */\ 00068 for (int i = 0; i < OBOSC_LONG_TC_FIRST_HALF_SIZE; ++i){\ 00069 /*gPC.printf("indexCustom = %d\r\n", indexCustom);*/\ 00070 temp_tm->TM_string[indexCustom + i] = temp_tc->TC_string[i];\ 00071 /*Fill the TM with TC_values*/\ 00072 }\ 00073 for (int i = OBOSC_LONG_TC_FIRST_HALF_SIZE + indexCustom ; i < TM_LONG_SIZE-2 ; ++i ){\ 00074 temp_tm->TM_string[i] = 0;\ 00075 /*Fill remaining values with 0*/\ 00076 }\ 00077 TC_LIST_TAG = OBOSC_TCL_TAG_LONG_FIRST_HALF;\ 00078 break;\ 00079 }\ 00080 }\ 00081 else{\ 00082 RESET_CDMS;\ 00083 break;\ 00084 }\ 00085 }\ 00086 temp_tm->TM_string[2] = TC_LIST_TAG;\ 00087 /*TC_LIST_TAG as is updated in the inner while loop*/\ 00088 uint16_t crc16 = crc16_gen(temp_tm->TM_string, TM_LONG_SIZE-2);\ 00089 temp_tm->TM_string[TM_LONG_SIZE-2] = (crc16 & 0xFF00) >> 8 ;\ 00090 temp_tm->TM_string[TM_LONG_SIZE-1] = crc16 & 0x00FF;\ 00091 /*Attach this new node to the TM linked list*/\ 00092 if( first_time ){\ 00093 first_time = false;\ 00094 tm_ptr = temp_tm;\ 00095 current_tm = temp_tm;\ 00096 }\ 00097 else{\ 00098 current_tm->next_TM = temp_tm;\ 00099 current_tm = current_tm->next_TM;\ 00100 }\ 00101 /*Attach this new node at the end*/\ 00102 }\ 00103 else{\ 00104 RESET_CDMS;\ 00105 break;\ 00106 }\ 00107 }\ 00108 } 00109 00110 #define put_crc_l1_ack(tm_ptr) {\ 00111 /*TC LIST STATUS*/\ 00112 tm_ptr->TM_string[3] |= (gMASTER_STATE << 6) & 0xC0;\ 00113 /*PA HOT*/\ 00114 if( gFLAGS & COM_PA_HOT_FLAG ){\ 00115 tm_ptr->TM_string[3] |= (1 << 5);\ 00116 }\ 00117 else{\ 00118 tm_ptr->TM_string[3] &= ~(1 << 5);\ 00119 }\ 00120 /*PA OC*/\ 00121 if( gFLAGS & COM_PA_OC_FLAG ){\ 00122 tm_ptr->TM_string[3] |= (1 << 4);\ 00123 }\ 00124 else{\ 00125 tm_ptr->TM_string[3] &= ~(1 << 4);\ 00126 }\ 00127 uint16_t crc_checksum = crc16_gen(tm_ptr->TM_string, TM_SHORT_SIZE-2);\ 00128 tm_ptr->TM_string[TM_SHORT_SIZE-2] = (crc_checksum >> 8) & 0xFF;\ 00129 tm_ptr->TM_string[TM_SHORT_SIZE-1] = crc_checksum & 0xFF;\ 00130 } 00131 00132 #define fill_l1_ack(tm_ptr) {\ 00133 tm_ptr->next_TM = NULL;\ 00134 tm_ptr->TM_string[0] = TMID_ACK_L1 << 4;\ 00135 tm_ptr->TM_string[1] = gTOTAL_INCORRECT_SIZE_TC & 0xFF;\ 00136 tm_ptr->TM_string[2] = gTOTAL_CRC_FAIL_TC & 0xFF;\ 00137 } 00138 00139 #define P_COM_HK{\ 00140 uint8_t returnHere;\ 00141 isPAhot(returnHere);\ 00142 if (returnHere == 0xFF)\ 00143 gFLAGS = gFLAGS | COM_PA_HOT_FLAG;\ 00144 else\ 00145 gFLAGS = gFLAGS & ~(COM_PA_HOT_FLAG);\ 00146 if (gFLAGS & COM_PA_OC_FLAG){\ 00147 COM_TX_CNTRL = 1;\ 00148 wait_ms(5);\ 00149 }\ 00150 isPAoc(returnHere);\ 00151 if (returnHere == 0xFF)\ 00152 gFLAGS = gFLAGS | COM_PA_OC_FLAG;\ 00153 else\ 00154 gFLAGS = gFLAGS & ~(COM_PA_OC_FLAG);\ 00155 /*P_CDMS_HANDLE_HW_FAULTS*/\ 00156 } 00157 00158 #define isPAhot(returnHere){\ 00159 uint8_t pa_temp = 0;\ 00160 SelectLinec0=0;\ 00161 SelectLinec1=0;\ 00162 SelectLinec2=0;\ 00163 SelectLinec3=1;\ 00164 pa_temp = TempInput.read();\ 00165 pa_temp = pa_temp * 3.3;\ 00166 float resistance;\ 00167 resistance = 24000 * pa_temp/(3.3 - pa_temp);\ 00168 if(pa_temp > 1.47) {\ 00169 pa_temp = 3694/log(24.032242*resistance);\ 00170 }\ 00171 else{\ 00172 pa_temp = 3365.4/log(7.60573*resistance);\ 00173 }\ 00174 COM_PA_IC_TMP = quantiz(tstart_thermistor,tstep_thermistor,pa_temp);\ 00175 /*comment this ater*/\ 00176 COM_PA_IC_TMP = 0;\ 00177 /*COM_PA_TMP_HIGH to be found*/\ 00178 if (COM_PA_IC_TMP > COM_PA_TMP_HIGH){\ 00179 returnHere = 0xFF;\ 00180 gPC.puts("PA is measured HOT\r\n");\ 00181 }\ 00182 else{\ 00183 returnHere = 0;\ 00184 gPC.puts("PA is measured not HOT\r\n");\ 00185 }\ 00186 } 00187 00188 #define isPAoc(returnHere){\ 00189 if (!com_oc_sw_status){\ 00190 returnHere = 0xFF;\ 00191 }\ 00192 else{\ 00193 returnHere = 0;\ 00194 }\ 00195 } 00196 00197 #define get_call_sign(tm_ptr) {\ 00198 Base_tm* call_sign_tm = new Short_tm;\ 00199 call_sign_tm->next_TM = NULL;\ 00200 tm_ptr = call_sign_tm;\ 00201 for( int i = 0 ; i < TM_SHORT_SIZE ; ++i ){\ 00202 call_sign_tm->TM_string[i] = gCALL_SIGN_STRING[i];\ 00203 }\ 00204 } 00205 00206 #define get_ack_l1( tm_ptr ){\ 00207 Base_tc *current_TC = gHEAD_NODE_TCL;\ 00208 Base_tm *l1_ack = new Short_tm;\ 00209 /*APPEND TO THE tm_ptr HERE*/\ 00210 tm_ptr = l1_ack;\ 00211 fill_l1_ack(l1_ack);\ 00212 int TC_count = 0;\ 00213 int overflowCountL1 = 0;\ 00214 while(current_TC != NULL){\ 00215 if( overflowCountL1 < TCL_OVERFLOW_CONSTANT ){\ 00216 /*IF CRC PASS*/\ 00217 if( (GETcrc_pass(current_TC) == 1) ){\ 00218 if(TC_count > 4){\ 00219 put_crc_l1_ack( l1_ack );\ 00220 /*extend the TM linked list*/\ 00221 TC_count = 0;\ 00222 l1_ack->next_TM = new Short_tm;\ 00223 l1_ack = l1_ack->next_TM;\ 00224 fill_l1_ack(l1_ack);\ 00225 }\ 00226 /*PSC starts from 7th byte*/\ 00227 l1_ack->TM_string[6+TC_count] = GETpacket_seq_count(current_TC);\ 00228 /*TC exec status*/\ 00229 switch(TC_count){\ 00230 case 0:\ 00231 l1_ack->TM_string[3] = (GETexec_status(current_TC)) & 0x0F;\ 00232 break;\ 00233 case 1:\ 00234 l1_ack->TM_string[4] = (GETexec_status(current_TC) << 4) & 0xF0;\ 00235 break;\ 00236 case 2:\ 00237 l1_ack->TM_string[4] |= (GETexec_status(current_TC)) & 0x0F;\ 00238 break;\ 00239 case 3:\ 00240 l1_ack->TM_string[5] = (GETexec_status(current_TC) << 4) & 0xF0;\ 00241 break;\ 00242 case 4:\ 00243 l1_ack->TM_string[5] |= (GETexec_status(current_TC)) & 0x0F;\ 00244 }\ 00245 ++TC_count;\ 00246 }\ 00247 current_TC = current_TC->next_TC;\ 00248 ++overflowCountL1;\ 00249 }\ 00250 else{\ 00251 RESET_CDMS;\ 00252 break;\ 00253 }\ 00254 }\ 00255 /*FILL UP THE REMAINING FIELDS WITH 0x00 as PSC, AND 0xF as tc exec status*/\ 00256 if( (TC_count < 5) && (TC_count != 0) ){\ 00257 while(TC_count < 5){\ 00258 l1_ack->TM_string[6+TC_count] = 0x00;\ 00259 switch(TC_count){\ 00260 case 1:\ 00261 l1_ack->TM_string[4] = 0xF0;\ 00262 break;\ 00263 case 2:\ 00264 l1_ack->TM_string[4] |= 0x0F;\ 00265 break;\ 00266 case 3:\ 00267 l1_ack->TM_string[5] = 0xF0;\ 00268 break;\ 00269 case 4:\ 00270 l1_ack->TM_string[5] |= 0x0F;\ 00271 }\ 00272 ++TC_count;\ 00273 }\ 00274 }\ 00275 put_crc_l1_ack(l1_ack);\ 00276 }
Generated on Tue Jul 26 2022 00:15:16 by
