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 function sensor_init($width,$bus,$channel,$init_pars,$raw=0){
00304
00305
00306 for ($i=0;$i<256;$i++){
00307 send_i2c($width,$bus,0x4800+$i,$init_pars[$i],$raw=0);
00308
00309
00310
00311 $readout=receive_i2c($width,$bus,0x4800+$i,$raw=0);
00312 printf("%04x ",$readout);
00313
00314 if($j==15){
00315 $j=0; printf("\n");
00316 }else{
00317 $j++;
00318 }
00319 }
00320 }
00321
00322 $width=16;
00323 $bus=0;
00324 $adr=0x0860;
00325 $datax=5;
00326 $nopars=false;
00327 $raw=0;
00328
00329 $phase_shift=0;
00330 $channel=33;
00331 $lines=1940;
00332 $pixes=2595;
00333 $delay=0x00ffffff;
00334 $sphase=7;
00335 $ch1_ch2_delay=115;
00336
00337 printf("<pre>");
00338
00339 foreach($_GET as $key=>$value) {
00340 switch($key) {
00341 case "phase_shift" : $phase_shift=$value+0; break;
00342 case "delay" : $delay=$value+0; break;
00343 case "ch1_ch2_delay": $ch1_ch2_delay=$value+0;break;
00344 case "channel" : $channel=$value+0; break;
00345 case "lines" : $lines=$value+0; break;
00346 case "pixes" : $pixes=$value+0; break;
00347 }
00348 }
00349
00350 if ($phase_shift==0) {
00351 printf("<h3>Reset DCM</h3>");
00352 dcm_reset($width,$bus,$raw=0);
00353
00354 printf("<h3>Set sensors data latch at rise='0'/fall='1'</h3>");
00355 send_i2c_4($width,$bus,0x083a,$sphase,$raw=0);
00356
00357 printf("<h3>Set delay between ch1 and ch2 trigger signals</h3>");
00358 send_i2c_4($width,$bus,0x083b,$ch1_ch2_delay,$raw=0);
00359
00360 printf("\nSwitch to sensor <font size=\"6\">1</font>\n");
00361 send_i2c_4($width,$bus,0x0835,0x00000001,$raw=0);
00362
00363 for ($i=0;$i<256;$i++){
00364 $init_pars[$i]=receive_i2c($width,$bus,0x4800+$i,$raw=0);
00365
00366 printf("%04x ",$init_pars[$i]);
00367
00368 if($j==15){
00369 $j=0; printf("\n");
00370 }else{
00371 $j++;
00372 }
00373
00374 }
00375
00376 send_i2c_4($width,$bus,0x0835,0x00000002,$raw=0); printf("\nInitializing sensor <font size=\"6\">2</font>\n");
00377 sensor_init(16,0,0x00000004,$init_pars,$raw=0);
00378
00379 send_i2c_4($width,$bus,0x0835,0x00000004,$raw=0); printf("\nInitializing sensor <font size=\"6\">3</font>\n");
00380 sensor_init(16,0,0x00000002,$init_pars,$raw=0);
00381
00382 send_i2c_4($width,$bus,0x0835,0x00000001,$raw=0); printf("\nSet back to sensor <font size=\"6\">1</font>\n");
00383
00384
00385 for ($i=0;$i<20;$i++){
00386 send_i2c_4($width,$bus,0x0807,0x00000001,$raw=0);
00387 }
00388 }else{
00389 printf("<h3>Phase Shift DCM</h3>");
00390 send_i2c_4($width,$bus,0x0808,$phase_shift,$raw=0);
00391 }
00392
00393
00394
00395
00396 printf("<h3>DDR Initialization sequence</h3>");
00397 ddr_init($width,$bus,$raw=0);
00398
00399 printf("<h3>Write data array to DDR and read it back</h3>");
00400
00401
00402 send_i2c_4($width,$bus,0x0835,$channel,$raw=0); printf("\nSet channel to <font size=\"6\">$channel</font>\n");
00403
00404 send_i2c_4($width,$bus,0x0838,$delay,$raw=0);
00405
00406 send_i2c_4($width,$bus,0x0837,(0x10000*$lines)+$pixes,$raw=0); printf("\nSet frame resolution to <font size=\"6\">$pixes"."x$lines</font>\n");
00407
00408 printf("<h3>Initialize channels 0 & 2</h3>");
00409 channels_init($width,$bus,$raw=0);
00410
00411
00412
00413
00414
00415 printf("</pre>");
00416
00417 ?>