00001 <?php
00002
00003
00004
00005
00006
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
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");
00032 exec("fpcf -c 10 2");
00033 exec("fpcf -c 11 1");
00034 exec("fpcf -c 12 2");
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");
00043
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");
00052 exec("fpcf -c 11 2");
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");
00061
00062 $boundary=readbscan('/dev/sfpgabscan');
00063 exec("fpcf -c 10 1");
00064 exec("fpcf -c 12 1");
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
00076
00077
00078
00079
00080 return "";
00081 }
00082
00083 $boards=array (
00084 '0' => array ('model' => '10347', 'scl' =>241,'sda' => 199),
00085 '1' => array ('model' => '10359', 'scl' =>280,'sda' => 296)
00086
00087 );
00088
00089
00090 $rslt=checkSclSda($boards);
00091 echo $rslt;
00092 if ($rslt=="") exit (-1);
00093 exit (0);
00094
00095
00096
00097
00098
00099 ?>