for frequency correction testing
Dependencies: FreescaleIAP SimpleDMA mbed-rtos mbed
Fork of CDMS_CODE by
COM_SND_TM.h
00001 bool sent_tmfrom_SDcard; 00002 bool restart_adf_flag=false; 00003 #define S_FRAME_SIZE 48 00004 #define ISR 40 00005 #define TM_FRAME_SIZE 134 //in bytes 00006 #define T_FRAME_SIZE 159 00007 #define EOS_SIZE 120 00008 #define MAX_ADF_LEN 65535 00009 00010 const unsigned char S_frame[] = {0x46,0x9D,0xFB,0xF0,0xD2,0xBA,0x89,0xE4,0x46,0x9D,0xFB,0xF0,0xD2,0xBA,0x89,0xE4,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}; 00011 const unsigned char EoS[] = {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x1A,0x77,0xEF,0xC3,0x4A,0xEA,0x27,0x91,0x1A,0x77,0xEF,0xC3,0x4A,0xEA,0x27,0x90,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x1A,0x77,0xEF,0xC3,0x4A,0xEA,0x27,0x91,0x1A,0x77,0xEF,0xC3,0x4A,0xEA,0x27,0x90,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}; 00012 const unsigned char FCCH80[] = {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}; 00013 const unsigned char SCH40[] = {0x0a,0x3f,0x46,0xb4,0x00}; 00014 const unsigned char EXOR_SEQ[] = {0x55,0xF1,0x51,0x3D,0xA7,0x42,0xAE,0x2E,0x2E,0x28,0x76,0x80,0x62,0x41,0xC4,0x75,0x4D,0x87,0xDB,0xE1,0x02,0x61,0x60,0x96,0x9C,0xCB,0x8A,0xBD,0x37,0xE4,0x72,0x5D,0xF2,0x19,0x62,0x06,0x9A,0xF9,0x38,0xB0,0x49,0x75,0xD0,0x17,0x1B,0xCC,0x0B,0xEB,0x1B,0x50,0xA2,0x2A,0x8E,0xFA,0x4D,0x6F,0x1B,0xF8,0x0F,0x97,0x39,0x25,0x60,0x55,0x9A,0xDF,0x1D,0x10,0x7F,0xBD,0x3E,0xBF,0xE5,0x68,0x02,0xD1,0x99,0x0D,0xDF,0x84,0x2E,0x15,0xE3,0x08,0xD7,0x44,0x10,0x41,0xCE,0x93,0xF6,0x59,0x71,0xD2,0xF7,0x1C,0x4A,0x44,0x2D,0xA9,0x44,0x98,0x3A,0x00,0x71,0xCC,0x2A,0x35,0xC1,0x81,0xCF,0x44,0xF7,0x6A,0x0E,0xE4,0xF2,0xFC,0xD6,0x0B,0xA8,0x95,0x7B,0x86,0xB5,0xF8,0x33,0xE9,0xBF,0x6A,0x0E,0xE6,0x53,0x82}; 00015 uint32_t TIME_LATEST_TM; 00016 unsigned char interleave_data[2][144]; 00017 #define print_tm(ptr) {\ 00018 for( int i = 0; i < 134; i++ ){\ 00019 gPC.putc(ptr[i]);\ 00020 }\ 00021 } 00022 00023 class SND_TM{ 00024 00025 Base_tm * head_ptr; 00026 00027 // transmit data variables 00028 unsigned char Tframe_c; //_c represents counter, counts Tframe written in a segment 00029 unsigned char EOS_c; //count no of bytes of eos have been weitten in the rolling buffer 00030 unsigned char Sframe_c; //count no of bytes of Sframe have been weitten in the rolling buffer 00031 unsigned char SCH40_c; //count no of bytes of SCH40 have been weitten in the rolling buffer 00032 unsigned char data_c; 00033 unsigned char FCCH80_c; 00034 unsigned char RB_c; //rolling buffer counter 00035 unsigned char segment_c; //counts the numver of segments sent 00036 unsigned char MAX_SEGMENT; 00037 bool Sframe; //Sframe = 1bit of CF1 00038 bool SCH40_f; 00039 bool FCCH80_f; 00040 bool data_f; 00041 bool repeat_data_f; 00042 bool transmit_data_f; 00043 bool eos_f; 00044 bool junk_f; 00045 bool segment_r; //flag checking if more sessions are required 00046 00047 00048 // type 1 frame 00049 00050 Base_tm *T0F_pointer ; 00051 00052 int diff_prev; 00053 void differential_encode(unsigned char* ptr, int length){ 00054 for(int i=0; i<length;i++){ 00055 unsigned char s = ptr[i] , t; 00056 t = s ^ (s >> 1); 00057 (diff_prev == 0) ? t=t^0x00 : t=t^0x80 ; 00058 diff_prev = int(s & 0x01); 00059 ptr[i] = t; 00060 } 00061 } 00062 00063 int type0_no; //number of type zero frames 00064 int type1_no; 00065 int total_frames; //number of type one packe (TMP) 00066 int SEGMENT_NO; //number of type one packe (TMP) 00067 int TOTAL_SEGMENT_NO; 00068 int LAST_SEGMENT_SIZE; 00069 void inline data_number(){ 00070 int type1_frame_no; 00071 Base_tm*head = head_ptr; 00072 type0_no = 0; 00073 type1_no = 0; 00074 while(head != NULL){ 00075 switch( GETshort_or_long_tm(head) ){ 00076 case 0: 00077 type0_no++; 00078 break; 00079 case 1: 00080 type1_no++; 00081 break; 00082 } 00083 00084 head=head->next_TM; 00085 } 00086 type1_frame_no = ( type1_no % 10 == 0 )? (type1_no / 10) : ( (type1_no / 10) + 1); 00087 total_frames = type0_no + type1_frame_no ; 00088 TOTAL_SEGMENT_NO = (total_frames*2 % (ISR) == 0) ? ( total_frames*2/(ISR) ) : (total_frames*2/(ISR) + 1); //subtracting 1 since the last SCH40_f is not detected 00089 SEGMENT_NO = TOTAL_SEGMENT_NO; 00090 if(SEGMENT_NO > MAX_SEGMENT) 00091 { 00092 SEGMENT_NO = MAX_SEGMENT; 00093 } 00094 if(SEGMENT_NO == 1) segment_r = 0; else segment_r = 1; 00095 TOTAL_SEGMENT_NO -= SEGMENT_NO; 00096 LAST_SEGMENT_SIZE = total_frames*2%ISR?total_frames*2%ISR:ISR; 00097 } 00098 00099 #define next_type_structure(ptr){\ 00100 unsigned char temp = GETshort_or_long_tm(ptr);\ 00101 if((temp == 0) && (ptr->next_TM != NULL) ){\ 00102 do{\ 00103 ptr = ptr->next_TM;\ 00104 temp = GETshort_or_long_tm(ptr);\ 00105 }\ 00106 while(temp == 1 && ptr->next_TM != NULL);\ 00107 if(temp == 1){\ 00108 ptr = NULL;\ 00109 }\ 00110 }\ 00111 else if((temp == 1) && (ptr->next_TM != NULL)){\ 00112 do{\ 00113 ptr = ptr->next_TM;\ 00114 temp = GETshort_or_long_tm(ptr);\ 00115 }\ 00116 while(temp == 0 && ptr->next_TM != NULL);\ 00117 if(temp == 0){\ 00118 ptr = NULL;\ 00119 }\ 00120 }\ 00121 else{\ 00122 ptr = NULL;\ 00123 }\ 00124 } 00125 00126 /* 00127 brief: take input type 0 or 1 and return the address of the first node in the list that have that type 00128 parameter: type 0 or 1 00129 return: pointer of the first node having same type 00130 */ 00131 #define exor(ptr) { for(int i=0 ; i<134; i++ ) ptr[i]=ptr[i]^EXOR_SEQ[i];} 00132 00133 00134 #define first_type_structure( type,return_ptr) {\ 00135 Base_tm* temp_ptr = head_ptr;\ 00136 if(type == 0){\ 00137 while(GETshort_or_long_tm(temp_ptr) == 1){\ 00138 temp_ptr = temp_ptr->next_TM;\ 00139 if(temp_ptr == NULL){\ 00140 return_ptr = NULL ;\ 00141 }\ 00142 }\ 00143 }\ 00144 else if(type == 1){\ 00145 while(GETshort_or_long_tm(temp_ptr) == 0){\ 00146 temp_ptr = temp_ptr->next_TM;\ 00147 if(temp_ptr == NULL){\ 00148 return_ptr = NULL;\ 00149 }\ 00150 }\ 00151 }\ 00152 return_ptr = temp_ptr;\ 00153 } 00154 00155 00156 00157 Base_tm *T1F_pointer ; 00158 int T1F_counter; 00159 unsigned char TMframe_type1[TM_FRAME_SIZE]; 00160 bool type1_frame_flag; //should be true for every new list 00161 00162 #define type1_frame(ptr){\ 00163 int i=4;\ 00164 if(type1_frame_flag){\ 00165 first_type_structure(1,T1F_pointer);\ 00166 T1F_counter = 0;\ 00167 type1_frame_flag = false;\ 00168 }\ 00169 for(i = 4 ; (i < 134) && (T1F_pointer != NULL) ; i++){\ 00170 TMframe_type1[i] = T1F_pointer->TM_string[T1F_counter];\ 00171 if(T1F_counter++ == 12){\ 00172 T1F_counter = 0;\ 00173 next_type_structure(T1F_pointer);\ 00174 }\ 00175 }\ 00176 TIME_LATEST_TM = FCTN_CDMS_RD_RTC()&0x13;\ 00177 TMframe_type1[0] = (1<<7) + (( (i-4)/13 )<<3) + (TIME_LATEST_TM >>16);\ 00178 TMframe_type1[1] = TIME_LATEST_TM >>8;\ 00179 TMframe_type1[2] = TIME_LATEST_TM;\ 00180 TMframe_type1[3] = crc8_gen(TMframe_type1,3);\ 00181 if(T1F_pointer == NULL && i>12){\ 00182 for( ; i < 134 ; i++){\ 00183 TMframe_type1[i] = TMframe_type1[i-13];\ 00184 }\ 00185 }\ 00186 ptr=TMframe_type1;\ 00187 } 00188 00189 00190 bool type0_frame_flag; 00191 00192 00193 #define type0_frame(ptr){\ 00194 if(type0_frame_flag){\ 00195 first_type_structure(0,T0F_pointer);\ 00196 type0_frame_flag = false;\ 00197 }\ 00198 else {\ 00199 next_type_structure(T0F_pointer);\ 00200 }\ 00201 ptr = T0F_pointer->TM_string;\ 00202 } 00203 00204 unsigned char convoluted_frame[270]; 00205 Convolution ConvObj2; 00206 void convolution (unsigned char * ptr){ 00207 ConvObj2.convolutionEncode(ptr, convoluted_frame); 00208 ConvObj2.convolutionEncode(ptr + 67, convoluted_frame + 135); 00209 } 00210 unsigned char DS_index; 00211 bool DS_state; 00212 int DS_counter; 00213 bool DS_f; 00214 bool make_DataStream_f; 00215 00216 #define make_DataStream {\ 00217 unsigned char* ptr;\ 00218 if(make_DataStream_f == true){\ 00219 DS_state = true;\ 00220 DS_counter = 0;\ 00221 DS_f = false;\ 00222 make_DataStream_f = false;\ 00223 }\ 00224 if(DS_state){\ 00225 if(DS_counter < total_frames-type0_no){\ 00226 type1_frame(ptr); \ 00227 DS_f = true;\ 00228 }\ 00229 else if(DS_counter < total_frames ){\ 00230 type0_frame(ptr);\ 00231 DS_f = true;\ 00232 }\ 00233 DS_counter++;\ 00234 }\ 00235 DS_state = !DS_state;\ 00236 if (DS_f){\ 00237 DS_f = false;\ 00238 exor(ptr);\ 00239 convolution(ptr);\ 00240 interleave(convoluted_frame,interleave_data[0]);\ 00241 interleave(convoluted_frame+ 135,interleave_data[1]);}\ 00242 DS_index = (DS_state==true)?1:0;\ 00243 } 00244 00245 00246 // 00247 public: 00248 SND_TM(){ 00249 MAX_SEGMENT = (MAX_ADF_LEN-EOS_SIZE)/( S_FRAME_SIZE + ISR*T_FRAME_SIZE); 00250 //(max length - eos size)/(sframe length + tFrameLength*ISR) 00251 } 00252 00253 00254 00255 void head_pointer(Base_tm* ptr){ 00256 head_ptr = ptr ; 00257 type1_frame_flag = true; 00258 type0_frame_flag = true; 00259 make_DataStream_f = true; 00260 transmit_data_f = true; 00261 sent_tmfrom_SDcard = false; 00262 diff_prev = 0; 00263 data_number(); 00264 } 00265 00266 void head_pointer_sdcard(Base_tm* ptr){ 00267 head_ptr = ptr ; 00268 type1_frame_flag = true; 00269 type0_frame_flag = true; 00270 make_DataStream_f = true; 00271 transmit_data_f = true; 00272 data_number(); 00273 } 00274 00275 int make_shor_tm(){ 00276 make_DataStream; 00277 int y = ( type1_no % 10 == 0 )? (type1_no / 10) : ( (type1_no / 10) + 1); 00278 return y; 00279 } 00280 void inline transmit_data(unsigned char * transmit , bool * last_buffer){ 00281 if(transmit_data_f){ 00282 RB_c = 0; 00283 Sframe_c = 0; 00284 SCH40_c = 0; 00285 FCCH80_c = 0; 00286 Tframe_c = 0; 00287 EOS_c = 0; 00288 segment_c = 0; 00289 data_c = 0; 00290 00291 Sframe = true; 00292 SCH40_f = false; 00293 data_f = false; 00294 FCCH80_f = false; 00295 transmit_data_f = false; 00296 restart_adf_flag = false; 00297 *last_buffer = false; 00298 } 00299 00300 for(RB_c = 0 ; RB_c<112 ; RB_c++){ 00301 00302 if(junk_f || *last_buffer){ 00303 transmit[RB_c] = 0x00; 00304 continue; 00305 } 00306 00307 if(Sframe){ 00308 transmit[RB_c] = S_frame[Sframe_c++]; 00309 if(Sframe_c == 48){ 00310 // printf("exit s frame\n"); 00311 Sframe_c = 0; 00312 Sframe = false; 00313 SCH40_f =true; 00314 } 00315 continue; 00316 } 00317 // 00318 if(SCH40_f){ 00319 transmit[RB_c] = SCH40[SCH40_c++]; 00320 if(SCH40_c == 5 ){ 00321 SCH40_c = 0; 00322 SCH40_f = false; 00323 00324 00325 if(Tframe_c >= LAST_SEGMENT_SIZE && segment_r == 0) 00326 { 00327 memset(interleave_data, 0, sizeof(interleave_data)); 00328 repeat_data_f = true; 00329 DS_index = !DS_index; 00330 } 00331 else 00332 { 00333 data_f = true; 00334 make_DataStream; 00335 } 00336 // printf("exit SCH40 frame\n"); 00337 } 00338 continue; 00339 } 00340 // 00341 if(data_f){ 00342 transmit[RB_c] = interleave_data[DS_index][data_c++]; 00343 if(data_c == 144){ 00344 data_c = 0; 00345 FCCH80_f = true; 00346 data_f = false; 00347 // printf("exit Data\n"); 00348 } 00349 continue; 00350 } 00351 if(repeat_data_f){ 00352 transmit[RB_c] = interleave_data[DS_index][data_c++]; 00353 if(data_c == 144){ 00354 data_c = 0; 00355 FCCH80_f = true; 00356 repeat_data_f = false; 00357 // printf("exit Data\n"); 00358 } 00359 continue; 00360 } 00361 00362 if(FCCH80_f){ 00363 transmit[RB_c] = FCCH80[FCCH80_c++]; 00364 if(FCCH80_c == 10){ 00365 FCCH80_c = 0; 00366 FCCH80_f = false; 00367 // printf("exit FCCH80\n"); 00368 if(++Tframe_c != ISR) 00369 SCH40_f = true; 00370 else{ 00371 Tframe_c = 0; 00372 segment_c++; 00373 if(segment_c >= SEGMENT_NO - 1 && TOTAL_SEGMENT_NO == 0) segment_r = 0; else segment_r = 1; 00374 if(segment_c == SEGMENT_NO) 00375 {eos_f = true;} 00376 else{ 00377 Sframe = true; 00378 } 00379 } 00380 } 00381 continue; 00382 } 00383 00384 if(eos_f){ 00385 transmit[RB_c] = EoS[EOS_c++]; 00386 if(EOS_c == EOS_SIZE){ 00387 EOS_c = 0; 00388 eos_f = false; 00389 if(segment_c == SEGMENT_NO && segment_r == 0){ 00390 *last_buffer = true; 00391 } 00392 else if(segment_c == SEGMENT_NO && segment_r != 0){ 00393 segment_c = 0; 00394 SEGMENT_NO = TOTAL_SEGMENT_NO; 00395 if(SEGMENT_NO > MAX_SEGMENT) 00396 { 00397 SEGMENT_NO = MAX_SEGMENT; 00398 } 00399 if(SEGMENT_NO == 1) segment_r = 0; else segment_r = 1; 00400 TOTAL_SEGMENT_NO -= SEGMENT_NO; 00401 restart_adf_flag = true;//what does this do?? 00402 Sframe = true; 00403 junk_f = true; 00404 } 00405 00406 } 00407 continue; 00408 } 00409 } 00410 differential_encode(transmit,112); 00411 if(restart_adf_flag == true){ 00412 diff_prev = 0; 00413 junk_f = false; 00414 } 00415 00416 } 00417 00418 }; 00419 SND_TM snd_tm;
Generated on Sat Jul 16 2022 01:27:53 by 1.7.2