packages/web/353/php_top/usb10369a.php

Go to the documentation of this file.
00001 #!/usr/local/sbin/php -q
00002 <?php
00003 /*!***************************************************************************
00004 *! FILE NAME  : usb10369a.php
00005 *! DESCRIPTION: initializes USB hub on the 10369a board
00006 *! Copyright (C) 2008 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: usb10369a.php,v $
00023 *!  Revision 1.2  2008/06/26 00:07:34  spectr_rain
00024 *!  *** empty log message ***
00025 *!
00026 *!
00027 */
00028 function smbus_send($a,$d) { // d - array
00029    $i2c_fn='/dev/xi2c8_aux';
00030    $i2c  = fopen($i2c_fn, 'w');
00031    fseek ($i2c, $a) ;
00032    $cmd=chr(count($d));
00033    foreach ($d as $b) $cmd.=chr($b);
00034 //   var_dump($cmd);
00035    $res=fwrite($i2c, $cmd);
00036    fclose($i2c);
00037    return $res;
00038 } // end of i2c_send()
00039       $base_addr=  0x2c00;
00040       $defaults=array(
00041         array("addr"=>0x0,"data"=>0x34), // VID_LSB
00042         array("addr"=>0x1,"data"=>0x12), // VID_MSB
00043         array("addr"=>0x6,"data"=>0x9b), // CONFIG_BYTE_1
00044         array("addr"=>0x7,"data"=>0x10), // CONFIG_BYTE_2
00045         array("addr"=>0x8,"data"=>0x0 ), // CONFIG_BYTE_3
00046         array("addr"=>0xff,"data"=>0x1 ) // CMD
00047       );
00048 echo "<pre>\n";
00049       foreach ($defaults as $line) {
00050          $rslt=smbus_send($base_addr+$line["addr"],array($line["data"]+0)); 
00051          printf("smbus_send(0x%x,0x%x) returned %d\n",$base_addr+$line["addr"],$line["data"]+0,$rslt);
00052       }
00053 echo "</pre>\n";
00054 ?>

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