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
00037
00038
00039 function send_i2c($width,$bus,$a,$d,$raw=0) {
00040 $w=($width==16)?2:1;
00041 $i2c_fn='/dev/xi2c'.($raw?'raw':(($w==2)?'16':'8')).(($bus==0)?'':'_aux');
00042 $i2c = fopen($i2c_fn, 'w');
00043 fseek ($i2c, $w*$a) ;
00044 if ($w==1) $res=fwrite($i2c, chr ($d));
00045 else $res=fwrite($i2c, chr (floor($d/256)).chr ($d-256*floor($d/256)));
00046 fclose($i2c);
00047 return $res;
00048 }
00049
00050 function receive_i2c($width,$bus,$a,$raw=0) {
00051 $w=($width==16)?2:1;
00052 $i2c_fn='/dev/xi2c'.($raw?'raw':(($w==2)?'16':'8')).(($bus==0)?'':'_aux');
00053 $i2c = fopen($i2c_fn, 'r');
00054 fseek ($i2c, $w*$a);
00055 $data = fread($i2c, $w);
00056 fclose($i2c);
00057 if (strlen($data)<$w) return -1;
00058 $v=unpack(($w==1)?'C':'n1',$data);
00059 return $v[1];
00060 }
00061
00062 function receive_i2c_4($width,$bus,$a,$raw=0) {
00063 $w=($width==16)?2:1;
00064 $i2c_fn='/dev/xi2c'.($raw?'raw':(($w==2)?'16':'8')).(($bus==0)?'':'_aux');
00065 $i2c = fopen($i2c_fn, 'r');
00066 fseek ($i2c, 4, SEEK_END);
00067 fseek ($i2c, $w*$a);
00068
00069 $data = fread($i2c, 2*$w);
00070 fclose($i2c);
00071 if (strlen($data)<2*$w) return -1;
00072 $v=unpack(($w==1)?'C*':'N*',$data);
00073
00074
00075 return $v[1];
00076 }
00077
00078 function receive_i2c_n($width,$bus,$a,$raw=0) {
00079 $w=($width==16)?2:1;
00080 $i2c_fn='/dev/xi2c'.($raw?'raw':(($w==2)?'16':'8')).(($bus==0)?'':'_aux');
00081 $i2c = fopen($i2c_fn, 'r');
00082 fseek ($i2c, 16*4, SEEK_END);
00083 fseek ($i2c, $w*$a);
00084
00085 $data = fread($i2c, 2*$w*4*4);
00086 fclose($i2c);
00087 if (strlen($data)<2*$w) return -1;
00088 $v=unpack(($w==1)?'C*':'N*',$data);
00089
00090
00091 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]);
00092 }
00093
00094 function send_i2c_4($width,$bus,$a,$d,$raw=0) {
00095 $w=($width==16)?2:1;
00096 $i2c_fn='/dev/xi2c'.($raw?'raw':(($w==2)?'16':'8')).(($bus==0)?'':'_aux');
00097 $i2c = fopen($i2c_fn, 'w');
00098 fseek ($i2c, $w*$a) ;
00099 if ($w==1) $res=fwrite($i2c, chr ($d));
00100 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))) );
00101
00102
00103 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))));
00104
00105
00106 fclose($i2c);
00107 return $res;
00108 }
00109
00110 function dcm_reset($width,$bus,$raw=0){
00111
00112 printf("sent 0x%04x ",0x0810); send_i2c_4($width,$bus,0x0810,0xffffffff,$raw=0);
00113 printf("\nsent 0x%04x ",0x0810); send_i2c_4($width,$bus,0x0810,0x00000000,$raw=0);
00114
00115 }
00116
00117 function ramb_check($width,$bus,$raw=0){
00118 printf("Data sent: ");
00119
00120 send_i2c_4($width,0,0x0801,0x01020304,$raw=0);
00121 send_i2c_4($width,0,0x0801,0x05060708,$raw=0);
00122 send_i2c_4($width,0,0x0801,0x090a0b0c,$raw=0);
00123 send_i2c_4($width,0,0x0801,0x0d0e0f10,$raw=0);
00124
00125 send_i2c_4($width,$bus,0x0801,0x11121314,$raw=0);
00126 send_i2c_4($width,$bus,0x0801,0x15161718,$raw=0);
00127 send_i2c_4($width,$bus,0x0801,0x191a1b1c,$raw=0);
00128 send_i2c_4($width,$bus,0x0801,0x1d1e1f20,$raw=0);
00129
00130 send_i2c_4($width,$bus,0x0801,0x21222324,$raw=0);
00131 send_i2c_4($width,$bus,0x0801,0x25262728,$raw=0);
00132 send_i2c_4($width,$bus,0x0801,0x292a2b2c,$raw=0);
00133 send_i2c_4($width,$bus,0x0801,0x2d2e2f30,$raw=0);
00134
00135 send_i2c_4($width,$bus,0x0801,0x31323334,$raw=0);
00136 send_i2c_4($width,$bus,0x0801,0x35363738,$raw=0);
00137 send_i2c_4($width,$bus,0x0801,0x393a3b3c,$raw=0);
00138 send_i2c_4($width,$bus,0x0801,0x3d3e3f40,$raw=0);
00139
00140 printf("\nData received: ");
00141 for ($i=0;$i<16;$i++)
00142 {
00143 $data=receive_i2c_4($width,$bus,0x0868,$raw=0);
00144 printf("0x%08x ",$data);
00145 }
00146 }
00147
00148 function ddr_init($width,$bus,$raw=0){
00149
00150 printf("sent 0x%04x ",0x0847); send_i2c_4($width,$bus,0x0847,0x00000000,$raw=0); printf("\n");
00151
00152 printf("sent 0x%04x ",0x0843); send_i2c_4($width,$bus,0x0843,0x00017fff,$raw=0);
00153
00154 $data=receive_i2c_4($width,$bus,0x0841,$raw=0);
00155 printf("read 0x%04x 0x%08x\n",0x0841,$data);
00156
00157 printf("sent 0x%04x ",0x0843); send_i2c_4($width,$bus,0x0843,0x00002002,$raw=0);
00158
00159 $data=receive_i2c_4($width,$bus,0x0841,$raw=0);
00160 printf("read 0x%04x 0x%08x\n",0x0841,$data);
00161
00162 printf("sent 0x%04x ",0x0843); send_i2c_4($width,$bus,0x0843,0x00000163,$raw=0);
00163
00164 $data=receive_i2c_4($width,$bus,0x0841,$raw=0);
00165 printf("read 0x%04x 0x%08x\n",0x0841,$data);
00166
00167 printf("sent 0x%04x ",0x0843); send_i2c_4($width,$bus,0x0843,0x00008000,$raw=0);
00168
00169 $data=receive_i2c_4($width,$bus,0x0841,$raw=0);
00170 printf("read 0x%04x 0x%08x\n",0x0841,$data);
00171
00172 printf("sent 0x%04x ",0x0843); send_i2c_4($width,$bus,0x0843,0x00008000,$raw=0);
00173
00174 $data=receive_i2c_4($width,$bus,0x0841,$raw=0);
00175 printf("read 0x%04x 0x%08x\n",0x0841,$data);
00176
00177 printf("sent 0x%04x ",0x0843); send_i2c_4($width,$bus,0x0843,0x00017fff,$raw=0);
00178
00179 $data=receive_i2c_4($width,$bus,0x0841,$raw=0);
00180 printf("read 0x%04x 0x%08x\n",0x0841,$data);
00181
00182 }
00183
00184 function ddr_check($width,$bus,$raw=0){
00185
00186 printf("sent 0x%04x ",0x0847); send_i2c_4($width,$bus,0x0847,0x00000000,$raw=0); printf("\n");
00187 printf("sent 0x%04x ",0x0847); send_i2c_4($width,$bus,0x0847,0x00000001,$raw=0); printf("\n");
00188
00189 printf("sent 0x%04x ",0x084c); send_i2c_4($width,$bus,0x084c,0x00004001,$raw=0); printf("\n");
00190 printf("sent 0x%04x ",0x084d); send_i2c_4($width,$bus,0x084d,0x000001f0,$raw=0); printf("\n");
00191 printf("sent 0x%04x ",0x084e); send_i2c_4($width,$bus,0x084e,0x00000005,$raw=0); printf("\n");
00192
00193 printf("sent 0x%04x ",0x0847); send_i2c_4($width,$bus,0x0847,0x00000021,$raw=0); printf("\n");
00194
00195 printf("\nSent array:\n");
00196
00197 printf("<font color=\"#0000FF\">");
00198
00199
00200 for($aha=0;$aha<128;$aha++){
00201 send_i2c_4($width,$bus,0x0831,4*$aha,$raw=0);
00202 send_i2c_4($width,$bus,0x0831,4*$aha+1,$raw=0);
00203 send_i2c_4($width,$bus,0x0831,4*$aha+2,$raw=0);
00204 send_i2c_4($width,$bus,0x0831,4*$aha+3,$raw=0); printf("\n");
00205 }
00206
00207 printf("\n");
00208 printf("</font>");
00209
00210 printf("sent 0x%04x ",0x0834);send_i2c_4($width,$bus,0x0834,0x11223344,$raw=0); printf("\n");
00211
00212 printf("sent 0x%04x ",0x084c); send_i2c_4($width,$bus,0x084c,0x00000001,$raw=0);printf("\n");
00213 printf("sent 0x%04x ",0x084d); send_i2c_4($width,$bus,0x084d,0x000001f0,$raw=0);printf("\n");
00214 printf("sent 0x%04x ",0x084e); send_i2c_4($width,$bus,0x084e,0x00000005,$raw=0);printf("\n");
00215
00216 $data=receive_i2c_4($width,$bus,0x0860,$raw=0);
00217 printf("i2c_4 read slave 0x%04x ",0x0860);
00218 printf("acquired data is 0x%08x\n",$data);
00219
00220 $data=receive_i2c_4($width,$bus,0x0860,$raw=0);
00221 printf("i2c_4 read slave 0x%04x ",0x0860);
00222 printf("acquired data is 0x%08x\n",$data);
00223
00224 $data_array=receive_i2c_n($width,$bus,0x0833,$raw=0);
00225
00226 $j=0;
00227 printf("\nAcquired data:\n");
00228 printf("<font color=\"#0000FF\">");
00229
00230 for ($i=0,$index=count($data_array); $i<$index;$i++)
00231 {
00232 printf("0x%08x ",$data_array[$i]);
00233
00234 if ($j==3)
00235 {
00236 $j=0; printf("\n");
00237 }else{
00238 $j++;
00239 };
00240 }
00241
00242 printf("</font>\n");
00243
00244 }
00245
00246 function ddr_read($width,$bus,$raw=0){
00247
00248 printf("sent 0x%04x ",0x0834);send_i2c_4($width,$bus,0x0834,0x11223344,$raw=0); printf("\n");
00249
00250 printf("sent 0x%04x ",0x084d); send_i2c_4($width,$bus,0x084d,0x000001f0,$raw=0);printf("\n");
00251 printf("sent 0x%04x ",0x084e); send_i2c_4($width,$bus,0x084e,0x00000000,$raw=0);printf("\n");
00252
00253
00254 printf("\nAcquired data:\n");
00255
00256 for($k=0;$k<2;$k++){
00257
00258 printf("sent 0x%04x ",0x084c); send_i2c_4($width,$bus,0x084c,4*$k,$raw=0);printf("\n");
00259
00260
00261 for($g=0;$g<32;$g++){
00262 $data_array=receive_i2c_n($width,$bus,0x0833,$raw=0);
00263
00264 $j=0;
00265
00266 printf("<font color=\"#0000FF\">");
00267 for ($i=0,$index=count($data_array); $i<$index;$i++)
00268 {
00269 printf("%08x ",$data_array[$i]);
00270
00271 if ($j==15)
00272 {
00273 $j=0; printf("\n");
00274 }else{
00275 $j++;
00276 };
00277 }
00278 printf("</font>");
00279 }
00280
00281 printf("\n");
00282 }
00283
00284 printf("</font>\n");
00285
00286 }
00287
00288 function channels_init($width,$bus,$raw=0){
00289 send_i2c_4($width,$bus,0x0847,0x00000001,$raw=0); printf("sent %d\n",$cnt); $cnt++;
00290
00291 send_i2c_4($width,$bus,0x0847,0x00000003,$raw=0); printf("sent %d\n",$cnt); $cnt++;
00292
00293 send_i2c_4($width,$bus,0x0841,0x00000ff0,$raw=0); printf("sent %d\n",$cnt); $cnt++;
00294 send_i2c_4($width,$bus,0x0842,0x00000fff,$raw=0); printf("sent %d\n",$cnt); $cnt++;
00295 send_i2c_4($width,$bus,0x0840,0x00004000,$raw=0); printf("sent %d\n",$cnt); $cnt++;
00296
00297
00298
00299 send_i2c_4($width,$bus,0x0849,0x00000ff0,$raw=0); printf("sent %d\n",$cnt); $cnt++;
00300 send_i2c_4($width,$bus,0x084a,0x00000fff,$raw=0); printf("sent %d\n",$cnt); $cnt++;
00301 send_i2c_4($width,$bus,0x0848,0x00000000,$raw=0); printf("sent %d\n",$cnt); $cnt++;
00302
00303 send_i2c_4($width,$bus,0x0851,0x00000ff0,$raw=0); printf("sent %d\n",$cnt); $cnt++;
00304 send_i2c_4($width,$bus,0x0852,0x00000fff,$raw=0); printf("sent %d\n",$cnt); $cnt++;
00305 send_i2c_4($width,$bus,0x0850,0x00000000,$raw=0); printf("sent %d\n",$cnt); $cnt++;
00306
00307 send_i2c_4($width,$bus,0x0847,0x0000007f,$raw=0); printf("sent %d\n",$cnt); $cnt++;
00308 }
00309
00310 function sensor_init($width,$bus,$channel,$init_pars,$raw=0){
00311
00312
00313 for ($i=0;$i<256;$i++){
00314 send_i2c($width,$bus,0x4800+$i,$init_pars[$i],$raw=0);
00315
00316
00317
00318 $readout=receive_i2c($width,$bus,0x4800+$i,$raw=0);
00319 printf("%04x ",$readout);
00320
00321 if($j==15){
00322 $j=0; printf("\n");
00323 }else{
00324 $j++;
00325 }
00326 }
00327 }
00328
00329 $width=16;
00330 $bus=0;
00331 $adr=0x0860;
00332 $datax=5;
00333 $nopars=false;
00334 $raw=0;
00335
00336 $phase_shift=0;
00337 $channel=33;
00338 $lines=1940;
00339 $pixes=2595;
00340 $delay=0x00ffffff;
00341 $sphase=7;
00342 $ch1_ch2_delay=115;
00343
00344 printf("<pre><title>Snapshot mode</title>");
00345
00346 foreach($_GET as $key=>$value) {
00347 switch($key) {
00348 case "phase_shift" : $phase_shift=$value+0; break;
00349 case "delay" : $delay=$value+0; break;
00350 case "ch1_ch2_delay": $ch1_ch2_delay=$value+0;break;
00351 case "channel" : $channel=$value+0; break;
00352 case "lines" : $lines=$value+0; break;
00353 case "pixes" : $pixes=$value+0; break;
00354 }
00355 }
00356
00357 if ($phase_shift==0) {
00358
00359
00360
00361
00362
00363
00364 printf("<h3>Set delay between ch1 and ch2 trigger signals</h3>");
00365 send_i2c_4($width,$bus,0x083b,$ch1_ch2_delay,$raw=0);
00366
00367 printf("\nSwitch to sensor <font size=\"6\">1</font>\n");
00368 send_i2c_4($width,$bus,0x0835,0x00000001,$raw=0);
00369 printf("\n");
00370
00371 for ($i=0;$i<256;$i++){
00372 $init_pars[$i]=receive_i2c($width,$bus,0x4800+$i,$raw=0);
00373
00374 printf("%04x ",$init_pars[$i]);
00375
00376 if($j==15){
00377 $j=0; printf("\n");
00378 }else{
00379 $j++;
00380 }
00381
00382 }
00383
00384 send_i2c_4($width,$bus,0x0835,0x00000002,$raw=0); printf("\nInitializing sensor <font size=\"6\">2</font>\n");
00385 sensor_init(16,0,0x00000004,$init_pars,$raw=0);
00386
00387 send_i2c_4($width,$bus,0x0835,0x00000004,$raw=0); printf("\nInitializing sensor <font size=\"6\">3</font>\n");
00388 sensor_init(16,0,0x00000002,$init_pars,$raw=0);
00389
00390 send_i2c_4($width,$bus,0x0835,0x00000001,$raw=0); printf("\nSet back to sensor <font size=\"6\">1</font>\n");
00391
00392
00393 for ($i=0;$i<20;$i++){
00394 send_i2c_4($width,$bus,0x0807,0x00000001,$raw=0);
00395 }
00396 }else{
00397 printf("<h3>Phase Shift DCM</h3>");
00398 send_i2c_4($width,$bus,0x0808,$phase_shift,$raw=0);
00399 }
00400
00401
00402
00403
00404 printf("<h3>DDR Initialization sequence</h3>");
00405 ddr_init($width,$bus,$raw=0);
00406
00407 printf("<h3>Write data array to DDR and read it back</h3>");
00408
00409
00410 send_i2c_4($width,$bus,0x0835,$channel,$raw=0); printf("\nSet channel to <font size=\"6\">$channel</font>\n");
00411
00412 send_i2c_4($width,$bus,0x0838,$delay,$raw=0);
00413
00414 send_i2c_4($width,$bus,0x0837,(0x10000*$lines)+$pixes,$raw=0); printf("\nSet frame resolution to <font size=\"6\">$pixes"."x$lines</font>\n");
00415
00416 printf("<h3>Initialize channels 0 & 2</h3>");
00417 channels_init($width,$bus,$raw=0);
00418
00419
00420
00421
00422
00423 printf("</pre>");
00424
00425 ?>