packages/web/353/php_top/bdetect.php

Go to the documentation of this file.
00001 <?php
00002 /*
00003  * This programs tries to recognize the "sensor" board FPGA using JTAG
00004  * and control of the main FPGA of the SCL and SDA pins.
00005  * It changes values of these two pins and reads JTAG boundary scan
00006  * of the 'sensor board' FPGA
00007  
00008  */
00009 
00010 
00011 function readbscan($filename) {
00012    $jtag  = fopen($filename, 'r+');
00013    $ffs=  str_repeat ( chr(0xff), 97);
00014    $ret=  fwrite($jtag, $ffs);
00015 //   printf ("fwrite returned %d<br/>\n",$ret);
00016    fseek ($jtag,0);
00017    $boundary= fread($jtag, 97);
00018    fclose($jtag);
00019   return $boundary;
00020 }
00021 function read_fpga_reg($addr) {
00022    $fpga  = fopen('/dev/fpgaio', 'r+');
00023    fseek ($fpga,$addr<<2);
00024    $rd=fread($fpga, 4);
00025    fclose($fpga);
00026    $v=unpack('V1',$rd);
00027    print_r($v[1]);
00028    return $v[1];
00029 }
00030 function checkSclSda($boards) {
00031    exec("fpcf -c  f 1"); // SCL=0
00032    exec("fpcf -c 10 2"); // SCL_EN=1
00033    exec("fpcf -c 11 1"); // SDA=0
00034    exec("fpcf -c 12 2"); // SDA_EN=1
00035    $test=array();
00036    $boundary=readbscan('/dev/sfpgabscan');
00037    foreach ($boards as $key => $value) {
00038      $test[$key]= (((ord($boundary[$value['sda'] >> 3]) >> (7 -($value['sda'] & 7))) &1) == 0) &&
00039                   (((ord($boundary[$value['scl'] >> 3]) >> (7 -($value['scl'] & 7))) &1) == 0);
00040    }
00041    
00042    exec("fpcf -c  f 2"); // SCL=1
00043 //   exec("fpcf -c 11 1"); // SDA=0
00044    $boundary=readbscan('/dev/sfpgabscan');
00045    foreach ($boards as $key => $value) {
00046      $test[$key] = $test[$key] &&
00047                      (((ord($boundary[$value['sda'] >> 3]) >> (7 -($value['sda'] & 7))) &1) == 0) &&
00048                      (((ord($boundary[$value['scl'] >> 3]) >> (7 -($value['scl'] & 7))) &1) == 1);
00049    }
00050    
00051    exec("fpcf -c  f 1"); // SCL=0
00052    exec("fpcf -c 11 2"); // SDA=1
00053    $boundary=readbscan('/dev/sfpgabscan');
00054    foreach ($boards as $key => $value) {
00055      $test[$key] = $test[$key] &&
00056                      (((ord($boundary[$value['sda'] >> 3]) >> (7 -($value['sda'] & 7))) &1) == 1) &&
00057                      (((ord($boundary[$value['scl'] >> 3]) >> (7 -($value['scl'] & 7))) &1) == 0);
00058    }
00059    
00060    exec("fpcf -c  f 2"); // SCL=1
00061 //   exec("fpcf -c 11 2"); // SDA=1
00062    $boundary=readbscan('/dev/sfpgabscan');
00063    exec("fpcf -c 10 1"); // SCL_EN=0
00064    exec("fpcf -c 12 1"); // SDA_EN=0
00065    
00066    foreach ($boards as $key => $value) {
00067      $test[$key] = $test[$key] &&
00068                      (((ord($boundary[$value['sda'] >> 3]) >> (7 -($value['sda'] & 7))) &1) == 1) &&
00069                      (((ord($boundary[$value['scl'] >> 3]) >> (7 -($value['scl'] & 7))) &1) == 1);
00070      if($test[$key]) {
00071        return $value['model'];
00072      }
00073    }
00074    
00075 //   return $sdascl;                 
00076 //echo "<pre>\n";
00077 //var_dump ($sdascl);
00078 //echo "</pre>\n";
00079 
00080    return "";
00081 }   
00082 
00083 $boards=array (
00084                 '0' => array ('model' => '10347', 'scl' =>241,'sda' => 199),  // E4, C1
00085                 '1' => array ('model' => '10359', 'scl' =>280,'sda' => 296)   // H6, J5
00086 
00087 );
00088 
00089 
00090 $rslt=checkSclSda($boards);
00091 echo $rslt;
00092 if ($rslt=="") exit (-1);
00093 exit (0);
00094 //echo "<pre>\n";
00095 //var_dump ($rslt);
00096 //echo "</pre>\n";
00097 
00098 
00099 ?> 

Generated on Fri Nov 28 00:06:24 2008 for elphel by  doxygen 1.5.1