packages/web/353/php_top/fpga.php

Go to the documentation of this file.
00001 <?php
00002 /*!*******************************************************************************
00003 *! FILE NAME  : fpga.php
00004 *! DESCRIPTION: Provides control of FPGA compressor/image acquisition
00005 *!              to the circular buffer (circbuf)
00006 *! Copyright (C) 2007 Elphel, Inc
00007 *! -----------------------------------------------------------------------------**
00008 *!
00009 *!  This program is free software: you can redistribute it and/or modify
00010 *!  it under the terms of the GNU General Public License as published by
00011 *!  the Free Software Foundation, either version 3 of the License, or
00012 *!  (at your option) any later version.
00013 *!
00014 *!  This program is distributed in the hope that it will be useful,
00015 *!  but WITHOUT ANY WARRANTY; without even the implied warranty of
00016 *!  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00017 *!  GNU General Public License for more details.
00018 *!
00019 *!  You should have received a copy of the GNU General Public License
00020 *!  along with this program.  If not, see <http://www.gnu.org/licenses/>.
00021 *! -----------------------------------------------------------------------------**
00022 *!  $Log: fpga.php,v $
00023 *!  Revision 1.4  2008/04/29 05:50:18  elphel
00024 *!  made it handle unsigned long >=0x80000000
00025 *!
00026 *!  Revision 1.3  2008/03/20 22:32:38  elphel
00027 *!  cleanup, modified to return xml
00028 *!
00029 *!  Revision 1.2  2008/03/17 17:44:03  elphel
00030 *!  updated to make use of elhel_fpga_* (extension) instead of file read/write
00031 *!
00032 *!  Revision 1.1  2007/12/06 19:02:50  elphel
00033 *!  collected most of the camera PHP script into one  /packages/web/353/php_top directory
00034 *!
00035 *!  Revision 1.1  2007/10/27 00:55:31  elphel
00036 *!  untested revision - need to go
00037 *!
00038 *!  Revision 1.1  2007/10/16 19:25:27  elphel
00039 *!  Added php script to control driver parameters (P_XXX, as defined in c313a.h) instead of the IOCTL. It is possible to control sensor phase with it
00040 *!
00041 *!
00042 */
00043     $address="";
00044     $data="";
00045      foreach($_GET as $key=>$value) {
00046        switch($key) {
00047        case "a":
00048        case "adr":
00049          $address=$value+0;
00050          break;
00051        case "a4":
00052        case "adr4":
00053          $address=$value+0x2000;
00054          break;
00055        case "d":
00056        case "data":
00057          $sdata=$value;
00058          $data=$value+0;
00059 // Is there easier way to handle unsigned longs in PHP?
00060          if ((strtoupper(substr($sdata,0,2))=="0X") && (strlen($sdata)==10)) {
00061            $data1=substr($sdata,0,6)+0;
00062            if ($data1>=32768) $data1-=65536;
00063            $data=$data1*65536+("0x".substr($sdata,6,4));
00064          }
00065          break;
00066        }
00067       }
00068     if ($address=="") {
00069       echo <<<USAGE
00070    <p>This read/writes fpga registers. Use with extreme care.</p>
00071    <ul>
00072     <li><b>fpga.php?a=<i>register_address</i></b> -  read FPGA register <i>register_address</i></li>
00073     <li><b>fpga.php?a=<i>register_address</i>&d=<i>data</i></b> - write <i>data</i> to FPGA register <i>register_address</i></li>
00074     <li><b>fpga.php?a4=<i>register_address</i></b> - read FPGA register <i>register_address</i> (csp4)</li>
00075   </ul>
00076   <p><i>Note: only reading autoincrementing registers requires csp4 mode</i></p>
00077 USAGE;
00078       exit (0);
00079     }
00080     $xml = new SimpleXMLElement("<?xml version='1.0'?><fpga/>");
00081     $xml->addChild ('address',($address>=0x2000)?($address-0x2000):$address);
00082     $xml->addChild ('hex_address',sprintf("0x%x",($address>=0x2000)?($address-0x2000):$address));
00083     if ($data==="") {
00084        $data=elphel_fpga_read($address);
00085        $xml->addChild ('read',$data);
00086        $xml->addChild ('hex_read',sprintf("0x%x",$data));
00087     } else {
00088        elphel_fpga_write($address,$data);
00089        $xml->addChild ('written',$data);
00090        $xml->addChild ('hex_written',sprintf("0x%x",$data));
00091     }
00092     $rslt=$xml->asXML();
00093     header("Content-Type: text/xml");
00094     header("Content-Length: ".strlen($rslt)."\n");
00095     header("Pragma: no-cache\n");
00096     printf($rslt);
00097 ?>

Generated on Thu Aug 7 16:19:01 2008 for elphel by  doxygen 1.5.1