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.
SD_read.h
00001 // It takes 276us to read from sd card and write in 112 buffer 00002 00003 //~ #include"SDcard.h" 00004 #define T_frames 39 00005 unsigned char buffer_112_counter,sent_tm = 0; 00006 int disk_read(uint8_t *, uint64_t),j; 00007 bool new_session = true; 00008 bool last_buffer = false; 00009 bool first_block = true; 00010 bool last_block =false; 00011 bool repeat_T_frame = false; 00012 unsigned int counter_in_block=0,diff_prev=0; 00013 unsigned char EOS_counter = 0; 00014 unsigned char enable_T_frame = false; 00015 unsigned long long int start_block_num ; // Read from TC 00016 unsigned long long int end_block_num ; // Read from TC 00017 unsigned long long int Number_of_blocks_to_read ; 00018 unsigned long long int block_counter = 0; 00019 unsigned char buffer_512[512], buffer_112[112],counter_in_S_frame=0,counter_in_SCH=0; 00020 unsigned char S_frame[48]={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}; 00021 //unsigned char SCH[40] = {0x0A,0x3F,0x46,0xB4,0x00}; 00022 unsigned char EoS[120]; 00023 unsigned char make_EOS_flag =true; 00024 00025 void differential_encode(unsigned char* ptr, int length){ 00026 00027 for(int i=0; i<length;i++){ 00028 00029 unsigned char s = ptr[i] , t; 00030 t = s ^ (s >> 1); 00031 (diff_prev == 0) ? t=t^0x00 : t=t^0x80 ; 00032 diff_prev = int(s & 0x01); 00033 ptr[i] = t; 00034 } 00035 00036 } 00037 00038 void make_EOS() 00039 { 00040 00041 for(int i = 0 ; i < 24 ; ++i){ 00042 EoS[i] = 0x00; 00043 } 00044 00045 //~ S-FRAME [1] 00046 //~ first two bits of S-FRAME 00047 EoS[23] = 0x01; 00048 00049 EoS[24] = 0x1a; 00050 EoS[25] = 0x77; 00051 EoS[26] = 0xef; 00052 EoS[27] = 0xc3; 00053 EoS[28] = 0x4a; 00054 EoS[29] = 0xea; 00055 EoS[30] = 0x27; 00056 EoS[31] = 0x91; 00057 EoS[32] = 0x1a; 00058 EoS[33] = 0x77; 00059 EoS[34] = 0xef; 00060 EoS[35] = 0xc3; 00061 EoS[36] = 0x4a; 00062 EoS[37] = 0xea; 00063 EoS[38] = 0x27; 00064 EoS[39] = 0x90; 00065 00066 for(int i = 40 ; i < 72 ; ++i){ 00067 EoS[i] = 0x00; 00068 } 00069 00070 //~ S-FRAME [2] 00071 //~ first two bits of S-FRAME 00072 EoS[71] = 0x01; 00073 00074 EoS[72] = 0x1a; 00075 EoS[73] = 0x77; 00076 EoS[74] = 0xef; 00077 EoS[75] = 0xc3; 00078 EoS[76] = 0x4a; 00079 EoS[77] = 0xea; 00080 EoS[78] = 0x27; 00081 EoS[79] = 0x91; 00082 EoS[80] = 0x1a; 00083 EoS[81] = 0x77; 00084 EoS[82] = 0xef; 00085 EoS[83] = 0xc3; 00086 EoS[84] = 0x4a; 00087 EoS[85] = 0xea; 00088 EoS[86] = 0x27; 00089 EoS[87] = 0x90; 00090 00091 for(int i = 88 ; i < 120 ; ++i){ 00092 EoS[i] = 0x00; 00093 } 00094 00095 } 00096 00097 void send_tm_from_SD_card(){ 00098 00099 00100 if(make_EOS_flag == true){ 00101 make_EOS(); 00102 make_EOS_flag = false; 00103 Number_of_blocks_to_read = end_block_num - start_block_num +1; 00104 } 00105 00106 00107 for(buffer_112_counter=0;buffer_112_counter<112;buffer_112_counter++){ 00108 00109 00110 if(new_session == true){ //check if it is beginnig of session 00111 00112 buffer_112[buffer_112_counter]=S_frame[counter_in_S_frame++]; // sending S frame 00113 00114 if(counter_in_S_frame==48){ 00115 // cout<<"new_session_over\n"; 00116 counter_in_S_frame=0; 00117 new_session = false; 00118 enable_T_frame = true; 00119 // enable_SCH = true; 00120 } 00121 } 00122 else if(enable_T_frame == true){ // To send t frames 00123 00124 if(block_counter != Number_of_blocks_to_read){ 00125 00126 if(first_block){ // Read first block 00127 // cout<<"brooooooo"<<start_block_num<<"yo"<<endl; 00128 00129 disk_read(buffer_512,start_block_num ); 00130 counter_in_block = 0; 00131 block_counter++; 00132 00133 first_block = false; 00134 // cout<<"first block exit\n"; 00135 // cout<<Number_of_blocks_to_read; 00136 00137 //printf("\n"); 00138 // for(int j=0;j<512;j++){ 00139 // printf("%02X ",buffer_512[j]); 00140 // } 00141 // printf("\n"); 00142 // if(block_counter == Number_of_blocks_to_read){ 00143 // last_block = true; 00144 // } 00145 00146 00147 } 00148 if((counter_in_block == 318 )&&(sent_tm<38)){ // Read next block 00149 00150 // cout<<"next block exit\n"; 00151 disk_read(buffer_512,start_block_num + block_counter ); 00152 counter_in_block = 0; 00153 block_counter++; 00154 if(block_counter == Number_of_blocks_to_read){ 00155 last_block = true; 00156 } 00157 } 00158 } 00159 00160 if(!last_block){ 00161 00162 // cout<<int(sent_tm)<<" "; 00163 if(sent_tm<38){ 00164 buffer_112[buffer_112_counter] = buffer_512[counter_in_block++]; // sending T frames 00165 // cout<<int (counter_in_block)<<" "; 00166 if(counter_in_block == 318){ 00167 00168 sent_tm = sent_tm + 2; 00169 } 00170 } 00171 else if(sent_tm == (T_frames-1)){ 00172 buffer_112[buffer_112_counter] = buffer_512[(counter_in_block++ )-159]; 00173 if(counter_in_block == 318){ 00174 // cout<<"last block exit\n"; 00175 sent_tm = T_frames; 00176 } 00177 } 00178 else if(sent_tm == T_frames){ // Give eos and start new session 00179 buffer_112[buffer_112_counter]=EoS[EOS_counter++]; 00180 if(EOS_counter == 120){ 00181 enable_T_frame = false; 00182 new_session = true; 00183 EOS_counter =0; 00184 sent_tm=0; 00185 repeat_T_frame = false; 00186 // cout<<"eos exit\n"; 00187 } 00188 } 00189 } 00190 if(last_block){ 00191 // cout<<"lb"; 00192 if(sent_tm == (T_frames-1) && (repeat_T_frame == false)){ 00193 buffer_112[buffer_112_counter] = buffer_512[(counter_in_block++ )-159]; 00194 if(counter_in_block == 318){ 00195 // cout<<"repeat block exit\n"; 00196 sent_tm = T_frames; 00197 } 00198 } 00199 if((sent_tm == T_frames) && (repeat_T_frame == false)){ // Give eos and start new session 00200 buffer_112[buffer_112_counter]=EoS[EOS_counter++]; 00201 if(EOS_counter == 120){ 00202 // cout<<"eos exit"; 00203 enable_T_frame = false; 00204 new_session = true; 00205 EOS_counter =0; 00206 sent_tm=0; 00207 } 00208 } 00209 else if((sent_tm < (T_frames-1)) && (repeat_T_frame == false)){ 00210 buffer_112[buffer_112_counter] = buffer_512[counter_in_block++]; // sending last two T frames 00211 if(counter_in_block == 318){ 00212 sent_tm = sent_tm + 2; 00213 repeat_T_frame= true; 00214 } 00215 } 00216 else if((sent_tm< T_frames) && (repeat_T_frame == true)){ 00217 buffer_112[buffer_112_counter] = buffer_512[(counter_in_block++ )-159]; 00218 if(counter_in_block == 477){ 00219 sent_tm = sent_tm +1; 00220 counter_in_block = counter_in_block-159; 00221 } 00222 } 00223 else if((sent_tm == T_frames ) && (repeat_T_frame == true)){ // Give eos and start new session 00224 00225 buffer_112[buffer_112_counter]=EoS[EOS_counter++]; 00226 if(EOS_counter == 120){ 00227 enable_T_frame = false; 00228 new_session = true; 00229 EOS_counter =0; 00230 // printf("yoooo %d",int(sent_tm)); 00231 sent_tm=0; 00232 00233 last_block = false; 00234 last_buffer = true; 00235 // printf("i m here"); 00236 break; 00237 } 00238 } 00239 00240 } 00241 00242 } 00243 00244 } 00245 differential_encode(buffer_112, 112); 00246 if(last_buffer ==true){ 00247 diff_prev=0; 00248 } 00249 00250 }
Generated on Mon Jul 18 2022 08:46:33 by
1.7.2