iitm sat / Mbed 2 deprecated CDMS_CODE_samp_23SEP_DMA

Dependencies:   FreescaleIAP SimpleDMA mbed-rtos mbed

Fork of CDMS_CODE by shubham c

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers common_functions.h Source File

common_functions.h

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