fpga/x359/test_scripts/mem_test.php

Go to the documentation of this file.
00001 <?php
00002 /*!***************************************************************************
00003 *! FILE NAME  : mem_test.php
00004 *! DESCRIPTION: tests DDR memory on the 10359 board
00005 *! Copyright (C) 2008 Elphel, Inc
00006 *! -----------------------------------------------------------------------------**
00007 *!
00008 *!  This program is free software: you can redistribute it and/or modify
00009 *!  it under the terms of the GNU General Public License as published by
00010 *!  the Free Software Foundation, either version 3 of the License, or
00011 *!  (at your option) any later version.
00012 *!
00013 *!  This program is distributed in the hope that it will be useful,
00014 *!  but WITHOUT ANY WARRANTY; without even the implied warranty of
00015 *!  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016 *!  GNU General Public License for more details.
00017 *!
00018 *!  You should have received a copy of the GNU General Public License
00019 *!  along with this program.  If not, see <http://www.gnu.org/licenses/>.
00020 *! -----------------------------------------------------------------------------**
00021 *!  $Log: mem_test.php,v $
00022 *!  Revision 1.4  2008/06/23 08:11:58  dzhimiev
00023 *!  1. added more scripts for 10359 board
00024 *!
00025 *!  Revision 1.2  2008/06/16 07:43:58  dzhimiev
00026 *!  mcontr address range changed from 0x0820-0x082F to 0x0840-0x085F (for making extra channels)
00027 *!
00028 *!  Revision 1.2  2008/05/01 20:27:08  dzhimiev
00029 *!  reformatted a little
00030 *!
00031 *!  Revision 1.1  2008/04/23 01:55:49  dzhimiev
00032 *!  1. added x359 files to src lists
00033 *!  2. x359 read/write DDR
00034 *!  3. x359 3 channels mux directly to out
00035 *!  4. x359 one channel through DDR and another directly frames switching at out
00036 *!
00037 */
00038 
00039 function send_i2c($a,$d) {
00040         $i2c  = fopen('/dev/xi2c16','w');
00041         fseek ($i2c, 2*$a);
00042         $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($a) {
00048         $i2c  = fopen('/dev/xi2c16','r');
00049         fseek ($i2c, 2*$a);
00050         $data = fread($i2c, 2);
00051         fclose($i2c);
00052         if (strlen($data)<2) return -1;
00053         $v=unpack('n1',$data);
00054         return $v[1];
00055 }
00056 
00057 function receive_i2c_4($width,$bus,$a,$raw=0) {
00058    $w=($width==16)?2:1;
00059    $i2c_fn='/dev/xi2c'.($raw?'raw':(($w==2)?'16':'8')).(($bus==0)?'':'_aux');
00060    $i2c  = fopen($i2c_fn, 'r');
00061          fseek ($i2c, 4, SEEK_END);
00062    fseek ($i2c, $w*$a);
00063          
00064    $data = fread($i2c, 2*$w);
00065    fclose($i2c);
00066    if (strlen($data)<2*$w) return -1;
00067    $v=unpack(($w==1)?'C*':'N*',$data);
00068          //print_r($v);
00069          //printf("0x%x\n",$v[1]);
00070          return $v[1];
00071 } // end of receive_i2c()
00072 
00073 function receive_i2c_n($width,$bus,$a,$raw=0) {
00074    $w=($width==16)?2:1;
00075    $i2c_fn='/dev/xi2c'.($raw?'raw':(($w==2)?'16':'8')).(($bus==0)?'':'_aux');
00076    $i2c  = fopen($i2c_fn, 'r');
00077          fseek ($i2c, 16*4, SEEK_END);
00078    fseek ($i2c, $w*$a);
00079          
00080    $data = fread($i2c, 2*$w*4*4);
00081    fclose($i2c);
00082    if (strlen($data)<2*$w) return -1;
00083    $v=unpack(($w==1)?'C*':'N*',$data);
00084          //print_r($v);
00085          //printf("0x%x\n",$v[1]);
00086          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]);
00087 } // end of receive_i2c()
00088 
00089 function send_i2c_4($width,$bus,$a,$d,$raw=0) { //$a<0 - use raw read/write
00090    $w=($width==16)?2:1;
00091    $i2c_fn='/dev/xi2c'.($raw?'raw':(($w==2)?'16':'8')).(($bus==0)?'':'_aux');
00092    $i2c  = fopen($i2c_fn, 'w');
00093    fseek ($i2c, $w*$a) ;
00094    if ($w==1)    $res=fwrite($i2c, chr ($d));
00095    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))) );
00096 
00097          //printf("Sending passage ");
00098          printf("0x%08x ",$d);  
00099          //printf("\n");
00100 
00101    fclose($i2c);
00102    return $res;
00103 } // end of send_i2c()
00104 
00105 function send_i2c_4_nc($a,$d) {
00106         $i2c  = fopen('/dev/xi2c16','w');
00107         fseek ($i2c, 2*$a) ;
00108         $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         fclose($i2c);
00110         return $res;
00111 } 
00112 
00113 function dcm_reset($width,$bus,$raw=0){
00114 
00115         printf("sent 0x%04x ",0x0810); send_i2c_4($width,$bus,0x0810,0xffffffff,$raw=0);
00116         printf("\nsent 0x%04x ",0x0810); send_i2c_4($width,$bus,0x0810,0x00000000,$raw=0);
00117         
00118 }
00119 
00120 function ramb_check($width,$bus,$raw=0){
00121         printf("Data sent:     ");
00122 
00123         send_i2c_4($width,0,0x0801,0x01020343,$raw=0);
00124         send_i2c_4($width,0,0x0801,0x05060787,$raw=0);
00125         send_i2c_4($width,0,0x0801,0x090a0bcb,$raw=0);
00126         send_i2c_4($width,0,0x0801,0x0d0e0f0f,$raw=0);
00127 
00128         send_i2c_4($width,$bus,0x0801,0x11121314,$raw=0);
00129         send_i2c_4($width,$bus,0x0801,0x15161718,$raw=0);
00130         send_i2c_4($width,$bus,0x0801,0x191a1b1c,$raw=0);
00131         send_i2c_4($width,$bus,0x0801,0x1d1e1f20,$raw=0);
00132 
00133         send_i2c_4($width,$bus,0x0801,0x21222324,$raw=0);
00134         send_i2c_4($width,$bus,0x0801,0x25262728,$raw=0);
00135         send_i2c_4($width,$bus,0x0801,0x292a2b2c,$raw=0);
00136         send_i2c_4($width,$bus,0x0801,0x2d2e2f30,$raw=0);
00137 
00138         send_i2c_4($width,$bus,0x0801,0x31323334,$raw=0);
00139         send_i2c_4($width,$bus,0x0801,0x35363738,$raw=0);
00140         send_i2c_4($width,$bus,0x0801,0x393a3b3c,$raw=0);
00141         send_i2c_4($width,$bus,0x0801,0x3d3e3f40,$raw=0);
00142 
00143         printf("\nData received: ");
00144         for ($i=0;$i<16;$i++)
00145         {
00146                 $data=receive_i2c_4($width,$bus,0x0868,$raw=0); // first try to read 4
00147                 printf("0x%08x ",$data);// 0x%x",$data[2]);
00148         }
00149 }
00150 
00151 function ddr_init($width,$bus,$raw=0){
00152 
00153         printf("sent 0x%04x ",0x0847); send_i2c_4($width,$bus,0x0847,0x00000000,$raw=0); printf("\n");
00154 
00155         printf("sent 0x%04x ",0x0843); send_i2c_4($width,$bus,0x0843,0x00017fff,$raw=0); 
00156 
00157         $data=receive_i2c_4($width,$bus,0x0841,$raw=0); 
00158         printf("read 0x%04x 0x%08x\n",0x0841,$data);
00159 
00160         printf("sent 0x%04x ",0x0843); send_i2c_4($width,$bus,0x0843,0x00002002,$raw=0); 
00161 
00162         $data=receive_i2c_4($width,$bus,0x0841,$raw=0); 
00163         printf("read 0x%04x 0x%08x\n",0x0841,$data);
00164 
00165         printf("sent 0x%04x ",0x0843); send_i2c_4($width,$bus,0x0843,0x00000163,$raw=0); 
00166 
00167         $data=receive_i2c_4($width,$bus,0x0841,$raw=0); 
00168         printf("read 0x%04x 0x%08x\n",0x0841,$data);
00169 
00170         printf("sent 0x%04x ",0x0843); send_i2c_4($width,$bus,0x0843,0x00008000,$raw=0);
00171 
00172         $data=receive_i2c_4($width,$bus,0x0841,$raw=0); 
00173         printf("read 0x%04x 0x%08x\n",0x0841,$data);
00174 
00175         printf("sent 0x%04x ",0x0843); send_i2c_4($width,$bus,0x0843,0x00008000,$raw=0);
00176 
00177         $data=receive_i2c_4($width,$bus,0x0841,$raw=0); 
00178         printf("read 0x%04x 0x%08x\n",0x0841,$data);
00179 
00180         printf("sent 0x%04x ",0x0843); send_i2c_4($width,$bus,0x0843,0x00017fff,$raw=0); 
00181 
00182         $data=receive_i2c_4($width,$bus,0x0841,$raw=0);
00183         printf("read 0x%04x 0x%08x\n",0x0841,$data);
00184 
00185 }
00186 
00187 function ddr_page_write($width,$bus,$sa,$raw=0){
00188 
00189         send_i2c_4_nc(0x0847,0x00000000); // turn off channels
00190         send_i2c_4_nc(0x0847,0x00000001); // turn on auto refresh
00191 
00192         send_i2c_4_nc(0x084c,0x00004000+4*$sa); // set ch3 start addr
00193         send_i2c_4_nc(0x084d,0x000001f0); // set block size to write = 256 16-bit words
00194         //send_i2c_4_nc($width,$bus,0x082e,0x00000003,$raw=0); // number of blocks can be written
00195         //send_i2c_4_nc($width,$bus,0x082e,0x00000004,$raw=0); // number of blocks can be written
00196         send_i2c_4_nc(0x084e,0x00000003); // number of blocks can be written
00197 
00198         send_i2c_4_nc(0x0847,0x00000021); // turn on channel 3
00199 
00200         printf("Sent array to Row 0x%08x\n",$sa);
00201 
00202         printf("<font color=DARKBLUE>");
00203 
00204         $aha1=0;
00205         for($aha=0;$aha<512;$aha++){
00206 
00207                 $aha2=$aha+0x00010000*$sa;
00208 
00209                 printf("%08x ",$aha2);
00210 
00211                 send_i2c_4_nc(0x0831,$aha2);
00212                 
00213                 if ($aha1==15) {$aha1=0; printf("\n");}
00214                 else           {$aha1++;} 
00215 
00216         }
00217 
00218         printf("</font>");
00219 
00220         send_i2c_4_nc(0x0834,0x11223344); // write 256, 0x11223344 - means nothing
00221         send_i2c_4_nc(0x0834,0x11223344); // write 256, 0x11223344 - means nothing
00222         send_i2c_4_nc(0x0834,0x11223344); // write 256, 0x11223344 - means nothing
00223         send_i2c_4_nc(0x0834,0x11223344); printf("\n"); // write 256, 0x11223344 - means nothing
00224 
00225 }
00226 
00227 function ddr_page_read($width,$bus,$rra,$raw=0){
00228         //send_i2c_4_nc(0x0827,0x00000000); // turn off channels
00229         send_i2c_4_nc(0x0847,0x00000021); // turn on channel 3
00230 
00231         send_i2c_4_nc(0x084d,0x000001f0);
00232         send_i2c_4_nc(0x084e,0x00000003);
00233         
00234         printf("Acquired data from row 0x%08x\n",$rra);
00235 
00236         send_i2c_4_nc(0x084c,4*$rra);
00237         
00238         printf("<font color=\"#0000FF\">");
00239         for($g=0;$g<32;$g++){
00240                 $data_array=receive_i2c_n($width,$bus,0x0833,$raw=0); // read page
00241                 $j=0;
00242                 
00243                 for ($i=0,$index=count($data_array); $i<$index;$i++) 
00244                 {
00245                         printf("%08x ",$data_array[$i]);
00246                         if ($j==15) {$j=0; printf("\n");}
00247                         else        {$j++;              }
00248                 }
00249         }
00250         printf("\n</font>");
00251 }
00252 
00253   $width=16;
00254   $bus=0;
00255   $raw=0;
00256 
00257         $phase_shift=0;
00258         $row_adr=0x3ff;
00259         $N=0;
00260         $N_shifts=1;
00261 
00262         foreach($_GET as $key=>$value) {
00263                 switch($key) {
00264                         case "phase_shift": $phase_shift=$value+0; break;
00265                         case "row_adr"    : $row_adr=$value+0;     break;
00266                         case "N"          : $N=$value+0;           break;
00267                         case "N_shifts"   : $N_shifts=$value+0;    break;
00268                 }
00269         }
00270 
00271         printf("<pre><title>Memory test</title>");
00272         
00273         if ($phase_shift==0) {
00274                 printf("<h3>Reset DCM</h3>");
00275                 dcm_reset($width,$bus,$raw=0);
00276         }else{
00277                 printf("<h3>Phase Shift DCM</h3>");
00278                 for($i=0;$i<$N_shifts;$i++){
00279                         send_i2c_4($width,$bus,0x0808,$phase_shift,$raw=0);
00280                         usleep(1);
00281                 }
00282         }
00283 
00284         printf("<h3>RAMB & I2C test</h3>");
00285         ramb_check($width,$bus,$raw=0);
00286 
00287         printf("<h3>DDR Initialization sequence</h3>");
00288         ddr_init($width,$bus,$raw=0);
00289 
00290         printf("<h3>Write DDR</h3>");
00291         for($i=$row_adr;$i<$row_adr+$N;$i++){
00292                 ddr_page_write($width,$bus,$i,$raw=0); // $rsa=
00293         }
00294 
00295         printf("<h3>Read DDR</h3>");
00296         for($i=$row_adr;$i<$row_adr+$N;$i++){
00297                 ddr_page_read($width,$bus,$i,$raw=0); // $rsa=
00298         }
00299         printf("</pre>");
00300 
00301 ?>

Generated on Thu Aug 7 16:18:59 2008 for elphel by  doxygen 1.5.1