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.1.1.1  2008/11/27 20:04:03  elphel
00024 *!
00025 *!
00026 *!  Revision 1.4  2008/04/29 05:50:18  elphel
00027 *!  made it handle unsigned long >=0x80000000
00028 *!
00029 *!  Revision 1.3  2008/03/20 22:32:38  elphel
00030 *!  cleanup, modified to return xml
00031 *!
00032 *!  Revision 1.2  2008/03/17 17:44:03  elphel
00033 *!  updated to make use of elhel_fpga_* (extension) instead of file read/write
00034 *!
00035 *!  Revision 1.1  2007/12/06 19:02:50  elphel
00036 *!  collected most of the camera PHP script into one  /packages/web/353/php_top directory
00037 *!
00038 *!  Revision 1.1  2007/10/27 00:55:31  elphel
00039 *!  untested revision - need to go
00040 *!
00041 *!  Revision 1.1  2007/10/16 19:25:27  elphel
00042 *!  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
00043 *!
00044 *!
00045 */
00046     $address="";
00047     $data="";
00048      foreach($_GET as $key=>$value) {
00049        switch($key) {
00050        case "a":
00051        case "adr":
00052          $address=$value+0;
00053          break;
00054        case "a4":
00055        case "adr4":
00056          $address=$value+0x2000;
00057          break;
00058        case "d":
00059        case "data":
00060          $sdata=$value;
00061          $data=$value+0;
00062 // Is there easier way to handle unsigned longs in PHP?
00063          if ((strtoupper(substr($sdata,0,2))=="0X") && (strlen($sdata)==10)) {
00064            $data1=substr($sdata,0,6)+0;
00065            if ($data1>=32768) $data1-=65536;
00066            $data=$data1*65536+("0x".substr($sdata,6,4));
00067          }
00068          break;
00069        }
00070       }
00071     if ($address=="") {
00072       echo <<<USAGE
00073    <p>This read/writes fpga registers. Use with extreme care.</p>
00074    <ul>
00075     <li><b>fpga.php?a=<i>register_address</i></b> -  read FPGA register <i>register_address</i></li>
00076     <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>
00077     <li><b>fpga.php?a4=<i>register_address</i></b> - read FPGA register <i>register_address</i> (csp4)</li>
00078   </ul>
00079   <p><i>Note: only reading autoincrementing registers requires csp4 mode</i></p>
00080 USAGE;
00081       exit (0);
00082     }
00083     $xml = new SimpleXMLElement("<?xml version='1.0'?><fpga/>");
00084     $xml->addChild ('address',($address>=0x2000)?($address-0x2000):$address);
00085     $xml->addChild ('hex_address',sprintf("0x%x",($address>=0x2000)?($address-0x2000):$address));
00086     if ($data==="") {
00087        $data=elphel_fpga_read($address);
00088        $xml->addChild ('read',$data);
00089        $xml->addChild ('hex_read',sprintf("0x%x",$data));
00090     } else {
00091        elphel_fpga_write($address,$data);
00092        $xml->addChild ('written',$data);
00093        $xml->addChild ('hex_written',sprintf("0x%x",$data));
00094     }
00095     $rslt=$xml->asXML();
00096     header("Content-Type: text/xml");
00097     header("Content-Length: ".strlen($rslt)."\n");
00098     header("Pragma: no-cache\n");
00099     printf($rslt);
00100 ?>

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