00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036 function send_i2c($width,$bus,$a,$d,$raw=0) {
00037 $w=($width==16)?2:1;
00038 $i2c_fn='/dev/xi2c'.($raw?'raw':(($w==2)?'16':'8')).(($bus==0)?'':'_aux');
00039 $i2c = fopen($i2c_fn, 'w');
00040 fseek ($i2c, $w*$a) ;
00041 if ($w==1) $res=fwrite($i2c, chr ($d));
00042 else $res=fwrite($i2c, chr (floor($d/256)).chr ($d-256*floor($d/256)));
00043 fclose($i2c);
00044 return $res;
00045 }
00046
00047 function receive_i2c($width,$bus,$a,$raw=0) {
00048 $w=($width==16)?2:1;
00049 $i2c_fn='/dev/xi2c'.($raw?'raw':(($w==2)?'16':'8')).(($bus==0)?'':'_aux');
00050 $i2c = fopen($i2c_fn, 'r');
00051 fseek ($i2c, $w*$a);
00052 $data = fread($i2c, $w);
00053 fclose($i2c);
00054 if (strlen($data)<$w) return -1;
00055 $v=unpack(($w==1)?'C':'n1',$data);
00056 return $v[1];
00057 }
00058
00059 function receive_i2c_4($width,$bus,$a,$raw=0) {
00060 $w=($width==16)?2:1;
00061 $i2c_fn='/dev/xi2c'.($raw?'raw':(($w==2)?'16':'8')).(($bus==0)?'':'_aux');
00062 $i2c = fopen($i2c_fn, 'r');
00063 fseek ($i2c, 4, SEEK_END);
00064 fseek ($i2c, $w*$a);
00065
00066 $data = fread($i2c, 2*$w);
00067 fclose($i2c);
00068 if (strlen($data)<2*$w) return -1;
00069 $v=unpack(($w==1)?'C*':'N*',$data);
00070
00071
00072 return $v[1];
00073 }
00074
00075 function receive_i2c_n($width,$bus,$a,$raw=0) {
00076 $w=($width==16)?2:1;
00077 $i2c_fn='/dev/xi2c'.($raw?'raw':(($w==2)?'16':'8')).(($bus==0)?'':'_aux');
00078 $i2c = fopen($i2c_fn, 'r');
00079 fseek ($i2c, 16*4, SEEK_END);
00080 fseek ($i2c, $w*$a);
00081
00082 $data = fread($i2c, 2*$w*4*4);
00083 fclose($i2c);
00084 if (strlen($data)<2*$w) return -1;
00085 $v=unpack(($w==1)?'C*':'N*',$data);
00086
00087
00088 return array($v[1],$v[2],$v[3],$v[4],$v[5],$v[6],$v[7],$v[8],$v[9],$v[10],$v[11],$v[12],$v[13],$v[14],$v[15],$v[16]);
00089 }
00090
00091 function send_i2c_4($width,$bus,$a,$d,$raw=0) {
00092 $w=($width==16)?2:1;
00093 $i2c_fn='/dev/xi2c'.($raw?'raw':(($w==2)?'16':'8')).(($bus==0)?'':'_aux');
00094 $i2c = fopen($i2c_fn, 'w');
00095 fseek ($i2c, $w*$a) ;
00096 if ($w==1) $res=fwrite($i2c, chr ($d));
00097 else $res=fwrite($i2c, chr (floor($d/(256*256*256))).chr (($d - 256*256*256*floor($d/(256*256*256)))/(256*256)).chr (($d - 256*256*floor($d/(256*256)))/256).chr ($d - 256*floor($d/(256))) );
00098
00099
00100 printf("0x%02x%02x%02x%02x ",(floor($d/(256*256*256))),(($d - 256*256*256*floor($d/(256*256*256)))/(256*256)),(($d - 256*256*floor($d/(256*256)))/256),($d - 256*floor($d/(256))));
00101
00102
00103 fclose($i2c);
00104 return $res;
00105 }
00106
00107 function dcm_reset($width,$bus,$raw=0){
00108
00109 printf("sent 0x%04x ",0x0810); send_i2c_4($width,$bus,0x0810,0xffffffff,$raw=0);
00110 printf("\nsent 0x%04x ",0x0810); send_i2c_4($width,$bus,0x0810,0x00000000,$raw=0);
00111
00112 }
00113
00114 function ramb_check($width,$bus,$raw=0){
00115 printf("Data sent: ");
00116
00117 send_i2c_4($width,0,0x0801,0x01020304,$raw=0);
00118 send_i2c_4($width,0,0x0801,0x05060708,$raw=0);
00119 send_i2c_4($width,0,0x0801,0x090a0b0c,$raw=0);
00120 send_i2c_4($width,0,0x0801,0x0d0e0f10,$raw=0);
00121
00122 send_i2c_4($width,$bus,0x0801,0x11121314,$raw=0);
00123 send_i2c_4($width,$bus,0x0801,0x15161718,$raw=0);
00124 send_i2c_4($width,$bus,0x0801,0x191a1b1c,$raw=0);
00125 send_i2c_4($width,$bus,0x0801,0x1d1e1f20,$raw=0);
00126
00127 send_i2c_4($width,$bus,0x0801,0x21222324,$raw=0);
00128 send_i2c_4($width,$bus,0x0801,0x25262728,$raw=0);
00129 send_i2c_4($width,$bus,0x0801,0x292a2b2c,$raw=0);
00130 send_i2c_4($width,$bus,0x0801,0x2d2e2f30,$raw=0);
00131
00132 send_i2c_4($width,$bus,0x0801,0x31323334,$raw=0);
00133 send_i2c_4($width,$bus,0x0801,0x35363738,$raw=0);
00134 send_i2c_4($width,$bus,0x0801,0x393a3b3c,$raw=0);
00135 send_i2c_4($width,$bus,0x0801,0x3d3e3f40,$raw=0);
00136
00137 printf("\nData received: ");
00138 for ($i=0;$i<16;$i++)
00139 {
00140 $data=receive_i2c_4($width,$bus,0x0868,$raw=0);
00141 printf("0x%08x ",$data);
00142 }
00143 }
00144
00145 function ddr_init($width,$bus,$raw=0){
00146
00147 printf("sent 0x%04x ",0x0827); send_i2c_4($width,$bus,0x0827,0x00000000,$raw=0); printf("\n");
00148
00149 printf("sent 0x%04x ",0x0823); send_i2c_4($width,$bus,0x0823,0x00017fff,$raw=0);
00150
00151 $data=receive_i2c_4($width,$bus,0x0841,$raw=0);
00152 printf("read 0x%04x 0x%08x\n",0x0841,$data);
00153
00154 printf("sent 0x%04x ",0x0823); send_i2c_4($width,$bus,0x0823,0x00002002,$raw=0);
00155
00156 $data=receive_i2c_4($width,$bus,0x0841,$raw=0);
00157 printf("read 0x%04x 0x%08x\n",0x0841,$data);
00158
00159 printf("sent 0x%04x ",0x0823); send_i2c_4($width,$bus,0x0823,0x00000163,$raw=0);
00160
00161 $data=receive_i2c_4($width,$bus,0x0841,$raw=0);
00162 printf("read 0x%04x 0x%08x\n",0x0841,$data);
00163
00164 printf("sent 0x%04x ",0x0823); send_i2c_4($width,$bus,0x0823,0x00008000,$raw=0);
00165
00166 $data=receive_i2c_4($width,$bus,0x0841,$raw=0);
00167 printf("read 0x%04x 0x%08x\n",0x0841,$data);
00168
00169 printf("sent 0x%04x ",0x0823); send_i2c_4($width,$bus,0x0823,0x00008000,$raw=0);
00170
00171 $data=receive_i2c_4($width,$bus,0x0841,$raw=0);
00172 printf("read 0x%04x 0x%08x\n",0x0841,$data);
00173
00174 printf("sent 0x%04x ",0x0823); send_i2c_4($width,$bus,0x0823,0x00017fff,$raw=0);
00175
00176 $data=receive_i2c_4($width,$bus,0x0841,$raw=0);
00177 printf("read 0x%04x 0x%08x\n",0x0841,$data);
00178
00179 }
00180
00181 function ddr_check($width,$bus,$raw=0){
00182
00183 printf("sent 0x%04x ",0x0827); send_i2c_4($width,$bus,0x0827,0x00000000,$raw=0); printf("\n");
00184 printf("sent 0x%04x ",0x0827); send_i2c_4($width,$bus,0x0827,0x00000001,$raw=0); printf("\n");
00185
00186 printf("sent 0x%04x ",0x082c); send_i2c_4($width,$bus,0x082c,0x00004001,$raw=0); printf("\n");
00187 printf("sent 0x%04x ",0x082d); send_i2c_4($width,$bus,0x082d,0x000001f0,$raw=0); printf("\n");
00188 printf("sent 0x%04x ",0x082e); send_i2c_4($width,$bus,0x082e,0x00000005,$raw=0); printf("\n");
00189
00190 printf("sent 0x%04x ",0x0827); send_i2c_4($width,$bus,0x0827,0x00000021,$raw=0); printf("\n");
00191
00192 printf("\nSent array:\n");
00193
00194 printf("<font color=\"#0000FF\">");
00195
00196
00197 for($aha=0;$aha<128;$aha++){
00198 send_i2c_4($width,$bus,0x0831,4*$aha,$raw=0);
00199 send_i2c_4($width,$bus,0x0831,4*$aha+1,$raw=0);
00200 send_i2c_4($width,$bus,0x0831,4*$aha+2,$raw=0);
00201 send_i2c_4($width,$bus,0x0831,4*$aha+3,$raw=0); printf("\n");
00202 }
00203
00204 printf("\n");
00205 printf("</font>");
00206
00207 printf("sent 0x%04x ",0x0834);send_i2c_4($width,$bus,0x0834,0x11223344,$raw=0); printf("\n");
00208
00209 printf("sent 0x%04x ",0x082c); send_i2c_4($width,$bus,0x082c,0x00000001,$raw=0);printf("\n");
00210 printf("sent 0x%04x ",0x082d); send_i2c_4($width,$bus,0x082d,0x000001f0,$raw=0);printf("\n");
00211 printf("sent 0x%04x ",0x082e); send_i2c_4($width,$bus,0x082e,0x00000005,$raw=0);printf("\n");
00212
00213 $data=receive_i2c_4($width,$bus,0x0860,$raw=0);
00214 printf("i2c_4 read slave 0x%04x ",0x0860);
00215 printf("acquired data is 0x%08x\n",$data);
00216
00217 $data=receive_i2c_4($width,$bus,0x0860,$raw=0);
00218 printf("i2c_4 read slave 0x%04x ",0x0860);
00219 printf("acquired data is 0x%08x\n",$data);
00220
00221 $data_array=receive_i2c_n($width,$bus,0x0833,$raw=0);
00222
00223 $j=0;
00224 printf("\nAcquired data:\n");
00225 printf("<font color=\"#0000FF\">");
00226
00227 for ($i=0,$index=count($data_array); $i<$index;$i++)
00228 {
00229 printf("0x%08x ",$data_array[$i]);
00230
00231 if ($j==3)
00232 {
00233 $j=0; printf("\n");
00234 }else{
00235 $j++;
00236 };
00237 }
00238
00239 printf("</font>\n");
00240
00241 }
00242
00243 function ddr_read($width,$bus,$raw=0){
00244
00245 printf("sent 0x%04x ",0x0834);send_i2c_4($width,$bus,0x0834,0x11223344,$raw=0); printf("\n");
00246
00247 printf("sent 0x%04x ",0x082d); send_i2c_4($width,$bus,0x082d,0x000001f0,$raw=0);printf("\n");
00248 printf("sent 0x%04x ",0x082e); send_i2c_4($width,$bus,0x082e,0x00000000,$raw=0);printf("\n");
00249
00250
00251 printf("\nAcquired data:\n");
00252
00253 for($k=0;$k<2;$k++){
00254
00255 printf("sent 0x%04x ",0x082c); send_i2c_4($width,$bus,0x082c,4*$k,$raw=0);printf("\n");
00256
00257
00258 for($g=0;$g<32;$g++){
00259 $data_array=receive_i2c_n($width,$bus,0x0833,$raw=0);
00260
00261 $j=0;
00262
00263 printf("<font color=\"#0000FF\">");
00264 for ($i=0,$index=count($data_array); $i<$index;$i++)
00265 {
00266 printf("%08x ",$data_array[$i]);
00267
00268 if ($j==15)
00269 {
00270 $j=0; printf("\n");
00271 }else{
00272 $j++;
00273 };
00274 }
00275 printf("</font>");
00276 }
00277
00278 printf("\n");
00279 }
00280
00281 printf("</font>\n");
00282
00283 }
00284
00285 function channels_init($width,$bus,$raw=0){
00286 send_i2c_4($width,$bus,0x0827,0x00000001,$raw=0); printf("sent %d\n",$cnt); $cnt++;
00287
00288 send_i2c_4($width,$bus,0x0827,0x00000003,$raw=0); printf("sent %d\n",$cnt); $cnt++;
00289
00290 send_i2c_4($width,$bus,0x0821,0x00000ff0,$raw=0); printf("sent %d\n",$cnt); $cnt++;
00291 send_i2c_4($width,$bus,0x0822,0x00000fff,$raw=0); printf("sent %d\n",$cnt); $cnt++;
00292 send_i2c_4($width,$bus,0x0820,0x00004000,$raw=0); printf("sent %d\n",$cnt); $cnt++;
00293
00294
00295
00296 send_i2c_4($width,$bus,0x0829,0x00000ff0,$raw=0); printf("sent %d\n",$cnt); $cnt++;
00297 send_i2c_4($width,$bus,0x082a,0x00000fff,$raw=0); printf("sent %d\n",$cnt); $cnt++;
00298 send_i2c_4($width,$bus,0x0828,0x00000000,$raw=0); printf("sent %d\n",$cnt); $cnt++;
00299
00300 send_i2c_4($width,$bus,0x0827,0x00000017,$raw=0); printf("sent %d\n",$cnt); $cnt++;
00301 }
00302
00303
00304
00305 $width=16;
00306 $bus=0;
00307 $adr=0x0860;
00308 $datax=5;
00309 $nopars=false;
00310 $raw=0;
00311
00312 $phase_shift=0;
00313 $channel=9;
00314 $lines=4;
00315 $pixes=1619;
00316 $delay=0x000fffff;
00317 $change_channel=0;
00318 $sphase=0x00000000;
00319 $ch1_ch2_delay=2;
00320
00321 printf("<pre>");
00322
00323 foreach($_GET as $key=>$value) {
00324 switch($key) {
00325 case "phase_shift" : $phase_shift=$value+0; break;
00326 case "sphase" : $sphase=$value+0; break;
00327 case "delay" : $delay=$value+0; break;
00328 case "ch1_ch2_delay" : $c1_ch2_delay=$value+0; break;
00329 case "cc" : $cc=$value+0; break;
00330 case "dr" : $dr=$value+0; break;
00331 case "lines" : $lines=$value+0; break;
00332 case "channel" : $channel=$value+0; break;
00333 case "pixes" : $pixes=$value+0; break;
00334 }
00335 }
00336
00337 if ($dr==1) {
00338 dcm_reset($width,$bus,$raw=0);
00339 }
00340
00341 if ($cc==1) {
00342 send_i2c_4($width,$bus,0x083a,$sphase,$raw=0);
00343 send_i2c_4($width,$bus,0x083b,$ch1_ch2_delay,$raw=0);
00344 send_i2c_4($width,$bus,0x0838,$delay,$raw=0); printf("\nSet delay to <font size=\"6\">".$delay."0 ns</font>\n");
00345 send_i2c_4($width,$bus,0x0835,$channel,$raw=0); printf("\nSet channel to <font size=\"6\">$channel</font>\n");
00346 }
00347
00348 $data=receive_i2c_4($width,$bus,0x0860,$raw=0);
00349 printf("i2c_4 read slave 0x%04x ",0x0860);
00350 printf("acquired data is 0x%08x\n",$data);
00351
00352 $data=receive_i2c_4($width,$bus,0x0840,$raw=0);
00353 printf("i2c_4 read slave 0x%04x ",0x0840);
00354 printf("acquired data is 0x%08x\n",$data);
00355
00356 $data=receive_i2c_4($width,$bus,0x0870,$raw=0);
00357 printf("i2c_4 read slave 0x%04x \n",0x0870);
00358 printf("\nThe delay between frames <font size=\"6\">0x%08x</font>\n",$data);
00359
00360 $data=receive_i2c_4($width,$bus,0x0871,$raw=0);
00361 printf("i2c_4 read slave 0x%04x \n",0x0871);
00362 printf("\nThe delay between frames <font size=\"6\">0x%08x</font>\n",$data);
00363
00364
00365
00366
00367
00368
00369
00370
00371
00372
00373
00374
00375
00376
00377
00378
00379
00380
00381
00382
00383
00384
00385
00386
00387
00388
00389
00390
00391
00392
00393
00394
00395
00396
00397
00398
00399
00400
00401
00402
00403
00404
00405
00406
00407
00408
00409
00410
00411
00412
00413
00414
00415
00416
00417
00418
00419
00420
00421
00422
00423
00424
00425
00426
00427
00428
00429
00430
00431
00432
00433
00434
00435
00436
00437
00438
00439
00440
00441
00442
00443
00444
00445
00446
00447
00448
00449
00450
00451 printf("</pre>");
00452
00453 ?>