fpga/x359/test_scripts/phases_adjust.php

Go to the documentation of this file.
00001 <?php
00002 /*!***************************************************************************
00003 *! FILE NAME  : adjust_phases.php
00004 *! DESCRIPTION: Provides single byte/short r/w from/to the i2c
00005 *!              Setting per-slave protection mask,
00006 *!              Synchronizing system clock with a "CMOS" one
00007 *! Copyright (C) 2008 Elphel, Inc
00008 *! -----------------------------------------------------------------------------**
00009 *!
00010 *!  This program is free software: you can redistribute it and/or modify
00011 *!  it under the terms of the GNU General Public License as published by
00012 *!  the Free Software Foundation, either version 3 of the License, or
00013 *!  (at your option) any later version.
00014 *!
00015 *!  This program is distributed in the hope that it will be useful,
00016 *!  but WITHOUT ANY WARRANTY; without even the implied warranty of
00017 *!  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018 *!  GNU General Public License for more details.
00019 *!
00020 *!  You should have received a copy of the GNU General Public License
00021 *!  along with this program.  If not, see <http://www.gnu.org/licenses/>.
00022 *! -----------------------------------------------------------------------------**
00023 *!  $Log: phases_adjust.php,v $
00024 *!  Revision 1.1  2008/06/23 08:11:58  dzhimiev
00025 *!  1. added more scripts for 10359 board
00026 *!
00027 *!  Revision 1.2  2008/06/16 07:43:58  dzhimiev
00028 *!  mcontr address range changed from 0x0820-0x082F to 0x0840-0x085F (for making extra channels)
00029 *!
00030 *!  Revision 1.2  2008/02/13 00:30:01  elphel
00031 *!  Added system time synchronization  with "CMOS" clock
00032 *!
00033 *!  Revision 1.1  2008/02/12 21:53:20  elphel
00034 *!  Modified I2c to support multiple buses, added raw access (no address registers) and per-slave protection bitmasks
00035 *!
00036 *!
00037 */
00038 
00039 function send_i2c($width,$bus,$a,$d,$raw=0) { //$a<0 - use raw read/write
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 } // end of send_i2c()
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 } // end of receive_i2c()
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          //print_r($v);
00074          //printf("0x%x\n",$v[1]);
00075          return $v[1];
00076 } // end of receive_i2c()
00077 
00078 function send_i2c_4($width,$bus,$a,$d,$raw=0) { //$a<0 - use raw read/write
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, 'w');
00082    fseek ($i2c, $w*$a) ;
00083    if ($w==1)    $res=fwrite($i2c, chr ($d));
00084    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))) );
00085 
00086          //printf("Sending passage ");
00087          //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))));   
00088          //printf("\n");
00089 
00090    fclose($i2c);
00091    return $res;
00092 } // end of send_i2c()
00093 
00094 function dcm_reset($width,$bus,$raw=0){
00095         printf("<font size=\"4\">Resetting DCMs</font>\n");
00096         printf("sent 0x%04x ",0x0810); send_i2c_4($width,$bus,0x0810,0xffffffff,$raw=0);
00097         printf("\nsent 0x%04x ",0x0810); send_i2c_4($width,$bus,0x0810,0x00000000,$raw=0);
00098         printf("\n\n");
00099 }
00100 
00101   $width=16;
00102   $bus=0;
00103   $raw=0;
00104 
00105         $phase_shift=0;
00106         $dcm_addr=0;
00107         $n=1;
00108 
00109         $sphase=0x7;
00110 
00111         printf("<pre><title>Phases adjust</title>");
00112 
00113         foreach($_GET as $key=>$value) {
00114                 switch($key) {
00115                         case "rst"            : $dcm_rst=$value+0;        break;
00116                         case "dcm"            : $dcm_addr=$value+0;       break;
00117                         case "phase_shift"    : $phase_shift=$value+0;    break;
00118                         case "n"              : $n=$value+0;              break;
00119                         case "sphase"         : $sphase=$value+0;         break;
00120                 }
00121         }
00122 
00123 if ($dcm_rst==1) {
00124 dcm_reset($width,$bus,$raw=0);
00125 }
00126 
00127 switch($dcm_addr) {
00128         case 1  : $adr=0x0807; break;
00129         case 2  : $adr=0x0809; break;
00130         case 3  : $adr=0x080a; break;
00131         default : $adr=0;
00132 }
00133 
00134 if ($dcm_addr<>0){
00135         for($i=0;$i<$n;$i++){
00136                 send_i2c_4($width,$bus,$adr,$phase_shift,$raw=0);
00137                 usleep(1);
00138         }
00139         printf("DCM %d, number of shifts applied: <font size=\"6\">%d</font>\n",$dcm_addr,$n);
00140 }
00141 
00142         $adr=0x083a;
00143         send_i2c_4($width,$bus,$adr,$sphase,$raw=0);
00144 
00145         if (($sphase & 0x1)==0x1) printf("S1. Vact/Hact - sclk0 FALLING edge, PXD - sclk0 FALLING edge\n");
00146         else                      printf("S1. Vact/Hact - sclk0  RISING edge, PXD - sclk0 FALLING edge\n"); 
00147 
00148         if (($sphase & 0x2)==0x2) printf("S2. Vact/Hact - sclk0 FALLING edge, PXD - sclk0 FALLING edge\n");
00149         else                      printf("S2. Vact/Hact - sclk0  RISING edge, PXD - sclk0 FALLING edge\n");
00150 
00151         if (($sphase & 0x4)==0x4) printf("S3. Vact/Hact - sclk0 FALLING edge, PXD - sclk0 FALLING edge\n");
00152         else                      printf("S3. Vact/Hact - sclk0  RISING edge, PXD - sclk0 FALLING edge\n");
00153 
00154         $adr=0x0861;
00155         $data=receive_i2c_4($width,$bus,$adr,$raw=0);
00156         printf("read 0x%04x : DCM1 phase step number is <font size=\"6\">0x%08x</font>\n",$adr,$data);
00157         
00158         $adr=0x0862;
00159         $data=receive_i2c_4($width,$bus,$adr,$raw=0);
00160         printf("read 0x%04x : DCM_S2 phase step number is <font size=\"6\">0x%08x</font>\n",$adr,$data);
00161 
00162         $adr=0x0863;
00163         $data=receive_i2c_4($width,$bus,$adr,$raw=0);
00164         printf("read 0x%04x : DCM_S3 phase step number is <font size=\"6\">0x%08x</font>\n",$adr,$data);
00165 
00166 printf("</pre>");
00167 
00168 ?>

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