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($a,$d) {
00037 $i2c = fopen('/dev/xi2c16','w');
00038 fseek ($i2c, 2*$a);
00039 $res=fwrite($i2c, chr (floor($d/256)).chr ($d-256*floor($d/256)));
00040 fclose($i2c);
00041 return $res;
00042 }
00043
00044 function receive_i2c($a) {
00045 $i2c = fopen('/dev/xi2c16','r');
00046 fseek ($i2c, 2*$a);
00047 $data = fread($i2c, 2);
00048 fclose($i2c);
00049 if (strlen($data)<2) return -1;
00050 $v=unpack('n1',$data);
00051 return $v[1];
00052 }
00053
00054 function receive_i2c_4($width,$bus,$a,$raw=0) {
00055 $w=($width==16)?2:1;
00056 $i2c_fn='/dev/xi2c'.($raw?'raw':(($w==2)?'16':'8')).(($bus==0)?'':'_aux');
00057 $i2c = fopen($i2c_fn, 'r');
00058 fseek ($i2c, 4, SEEK_END);
00059 fseek ($i2c, $w*$a);
00060
00061 $data = fread($i2c, 2*$w);
00062 fclose($i2c);
00063 if (strlen($data)<2*$w) return -1;
00064 $v=unpack(($w==1)?'C*':'N*',$data);
00065
00066
00067 return $v[1];
00068 }
00069
00070 function receive_i2c_n($width,$bus,$a,$raw=0) {
00071 $w=($width==16)?2:1;
00072 $i2c_fn='/dev/xi2c'.($raw?'raw':(($w==2)?'16':'8')).(($bus==0)?'':'_aux');
00073 $i2c = fopen($i2c_fn, 'r');
00074 fseek ($i2c, 16*4, SEEK_END);
00075 fseek ($i2c, $w*$a);
00076
00077 $data = fread($i2c, 2*$w*4*4);
00078 fclose($i2c);
00079 if (strlen($data)<2*$w) return -1;
00080 $v=unpack(($w==1)?'C*':'N*',$data);
00081
00082
00083 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]);
00084 }
00085
00086 function send_i2c_4($width,$bus,$a,$d,$raw=0) {
00087 $w=($width==16)?2:1;
00088 $i2c_fn='/dev/xi2c'.($raw?'raw':(($w==2)?'16':'8')).(($bus==0)?'':'_aux');
00089 $i2c = fopen($i2c_fn, 'w');
00090 fseek ($i2c, $w*$a) ;
00091 if ($w==1) $res=fwrite($i2c, chr ($d));
00092 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))) );
00093
00094
00095 printf("0x%08x ",$d);
00096
00097
00098 fclose($i2c);
00099 return $res;
00100 }
00101
00102 function send_i2c_4a($width,$bus,$a,$d,$raw=0) {
00103 $w=($width==16)?2:1;
00104 $i2c_fn='/dev/xi2c'.($raw?'raw':(($w==2)?'16':'8')).(($bus==0)?'':'_aux');
00105 $i2c = fopen($i2c_fn, 'w');
00106 fseek ($i2c, $w*$a) ;
00107 if ($w==1) $res=fwrite($i2c, chr ($d));
00108 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))) );
00109
00110
00111 printf("%08d ",$d);
00112
00113
00114 fclose($i2c);
00115 return $res;
00116 }
00117
00118 function send_i2c_4_nc($a,$d) {
00119 $i2c = fopen('/dev/xi2c16','w');
00120 fseek ($i2c, 2*$a) ;
00121 $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))) );
00122 fclose($i2c);
00123 return $res;
00124 }
00125
00126 function dcm_reset($width,$bus,$raw=0){
00127
00128 printf("sent 0x%04x ",0x0810); send_i2c_4($width,$bus,0x0810,0xffffffff,$raw=0);
00129 printf("\nsent 0x%04x ",0x0810); send_i2c_4($width,$bus,0x0810,0x00000000,$raw=0);
00130
00131 }
00132
00133 function ramb_check($width,$bus,$raw=0){
00134 printf("Data sent: ");
00135
00136 send_i2c_4($width,0,0x0801,0x01020343,$raw=0);
00137 send_i2c_4($width,0,0x0801,0x05060787,$raw=0);
00138 send_i2c_4($width,0,0x0801,0x090a0bcb,$raw=0);
00139 send_i2c_4($width,0,0x0801,0x0d0e0f0f,$raw=0);
00140
00141 send_i2c_4($width,$bus,0x0801,0x11121314,$raw=0);
00142 send_i2c_4($width,$bus,0x0801,0x15161718,$raw=0);
00143 send_i2c_4($width,$bus,0x0801,0x191a1b1c,$raw=0);
00144 send_i2c_4($width,$bus,0x0801,0x1d1e1f20,$raw=0);
00145
00146 send_i2c_4($width,$bus,0x0801,0x21222324,$raw=0);
00147 send_i2c_4($width,$bus,0x0801,0x25262728,$raw=0);
00148 send_i2c_4($width,$bus,0x0801,0x292a2b2c,$raw=0);
00149 send_i2c_4($width,$bus,0x0801,0x2d2e2f30,$raw=0);
00150
00151 send_i2c_4($width,$bus,0x0801,0x31323334,$raw=0);
00152 send_i2c_4($width,$bus,0x0801,0x35363738,$raw=0);
00153 send_i2c_4($width,$bus,0x0801,0x393a3b3c,$raw=0);
00154 send_i2c_4($width,$bus,0x0801,0x3d3e3f40,$raw=0);
00155
00156 printf("\nData received: ");
00157 for ($i=0;$i<16;$i++)
00158 {
00159 $data=receive_i2c_4($width,$bus,0x0868,$raw=0);
00160 printf("0x%08x ",$data);
00161 }
00162 }
00163
00164 function ddr_init($width,$bus,$raw=0){
00165
00166 printf("sent 0x%04x ",0x0827); send_i2c_4($width,$bus,0x0827,0x00000000,$raw=0); printf("\n");
00167
00168 printf("sent 0x%04x ",0x0823); send_i2c_4($width,$bus,0x0823,0x00017fff,$raw=0);
00169
00170 $data=receive_i2c_4($width,$bus,0x0841,$raw=0);
00171 printf("read 0x%04x 0x%08x\n",0x0841,$data);
00172
00173 printf("sent 0x%04x ",0x0823); send_i2c_4($width,$bus,0x0823,0x00002002,$raw=0);
00174
00175 $data=receive_i2c_4($width,$bus,0x0841,$raw=0);
00176 printf("read 0x%04x 0x%08x\n",0x0841,$data);
00177
00178 printf("sent 0x%04x ",0x0823); send_i2c_4($width,$bus,0x0823,0x00000163,$raw=0);
00179
00180 $data=receive_i2c_4($width,$bus,0x0841,$raw=0);
00181 printf("read 0x%04x 0x%08x\n",0x0841,$data);
00182
00183 printf("sent 0x%04x ",0x0823); send_i2c_4($width,$bus,0x0823,0x00008000,$raw=0);
00184
00185 $data=receive_i2c_4($width,$bus,0x0841,$raw=0);
00186 printf("read 0x%04x 0x%08x\n",0x0841,$data);
00187
00188 printf("sent 0x%04x ",0x0823); send_i2c_4($width,$bus,0x0823,0x00008000,$raw=0);
00189
00190 $data=receive_i2c_4($width,$bus,0x0841,$raw=0);
00191 printf("read 0x%04x 0x%08x\n",0x0841,$data);
00192
00193 printf("sent 0x%04x ",0x0823); send_i2c_4($width,$bus,0x0823,0x00017fff,$raw=0);
00194
00195 $data=receive_i2c_4($width,$bus,0x0841,$raw=0);
00196 printf("read 0x%04x 0x%08x\n",0x0841,$data);
00197
00198 }
00199
00200 function ddr_page_write($width,$bus,$sa,$raw=0){
00201
00202 send_i2c_4_nc(0x0827,0x00000000);
00203 send_i2c_4_nc(0x0827,0x00000001);
00204
00205 send_i2c_4_nc(0x082c,0x00004000+4*$sa);
00206 send_i2c_4_nc(0x082d,0x000001f0);
00207
00208
00209 send_i2c_4_nc(0x082e,0x00000003);
00210
00211 send_i2c_4_nc(0x0827,0x00000021);
00212
00213 printf("Sent array to Row 0x%08x\n",$sa);
00214
00215 printf("<font color=DARKBLUE>");
00216
00217 $aha1=0;
00218 for($aha=0;$aha<512;$aha++){
00219
00220 $aha2=$aha+0x00010000*$sa;
00221
00222 printf("%08x ",$aha2);
00223
00224 send_i2c_4_nc(0x0831,$aha2);
00225
00226 if ($aha1==15) {$aha1=0; printf("\n");}
00227 else {$aha1++;}
00228
00229 }
00230
00231 printf("</font>");
00232
00233 send_i2c_4_nc(0x0834,0x11223344);
00234 send_i2c_4_nc(0x0834,0x11223344);
00235 send_i2c_4_nc(0x0834,0x11223344);
00236 send_i2c_4_nc(0x0834,0x11223344); printf("\n");
00237
00238 }
00239
00240 function ddr_page_read($width,$bus,$rra,$raw=0){
00241
00242 send_i2c_4_nc(0x0827,0x00000021);
00243
00244 send_i2c_4_nc(0x082d,0x000001f0);
00245 send_i2c_4_nc(0x082e,0x00000003);
00246
00247 printf("Acquired data from row 0x%08x\n",$rra);
00248
00249 send_i2c_4_nc(0x082c,4*$rra);
00250
00251 printf("<font color=\"#0000FF\">");
00252 for($g=0;$g<32;$g++){
00253 $data_array=receive_i2c_n($width,$bus,0x0833,$raw=0);
00254 $j=0;
00255
00256 for ($i=0,$index=count($data_array); $i<$index;$i++)
00257 {
00258 printf("%08x ",$data_array[$i]);
00259 if ($j==15) {$j=0; printf("\n");}
00260 else {$j++; }
00261 }
00262 }
00263 printf("\n</font>");
00264 }
00265
00266 $width=16;
00267 $bus=0;
00268 $raw=0;
00269
00270 $phase_shift=0;
00271 $row_adr=0x3ff;
00272 $N=0;
00273 $N_shifts=1;
00274
00275 foreach($_GET as $key=>$value) {
00276 switch($key) {
00277 case "phase_shift": $phase_shift=$value+0; break;
00278 case "row_adr" : $row_adr=$value+0; break;
00279 case "N" : $N=$value+0; break;
00280 case "N_shifts" : $N_shifts=$value+0; break;
00281 }
00282 }
00283
00284 printf("<pre>");
00285
00286 $testing=46;
00287
00288
00289
00290 if ($phase_shift==0) {
00291 printf("<h3>Reset DCM</h3>");
00292 dcm_reset($width,$bus,$raw=0);
00293 }else{
00294 printf("<h3>Phase Shift DCM</h3>");
00295 for($i=0;$i<$N_shifts;$i++){
00296 send_i2c_4($width,$bus,0x0808,$phase_shift,$raw=0);
00297 usleep(1);
00298 }
00299 }
00300
00301 printf("<h3>RAMB & I2C test</h3>");
00302 ramb_check($width,$bus,$raw=0);
00303
00304 printf("<h3>DDR Initialization sequence</h3>");
00305 ddr_init($width,$bus,$raw=0);
00306
00307 printf("<h3>Write DDR</h3>");
00308 for($i=$row_adr;$i<$row_adr+$N;$i++){
00309 ddr_page_write($width,$bus,$i,$raw=0);
00310 }
00311
00312 printf("<h3>Read DDR</h3>");
00313 for($i=$row_adr;$i<$row_adr+$N;$i++){
00314 ddr_page_read($width,$bus,$i,$raw=0);
00315 }
00316 printf("</pre>");
00317
00318 ?>