00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036 function send_i2c($width,$bus,$a,$d,$raw=0) {
00037 $w=($width==16)?2:1;
00038 $i2c_fn='/dev/xi2c'.($raw?'raw':(($w==2)?'16':'8')).(($bus==0)?'':'_aux');
00039 $i2c = fopen($i2c_fn, 'w');
00040 fseek ($i2c, $w*$a) ;
00041 if ($w==1) $res=fwrite($i2c, chr ($d));
00042 else $res=fwrite($i2c, chr (floor($d/256)).chr ($d-256*floor($d/256)));
00043 fclose($i2c);
00044 return $res;
00045 }
00046
00047 function send_i2c_4($width,$bus,$a,$d,$raw=0) {
00048 $w=2;
00049 $i2c_fn='/dev/xi2c'.($raw?'raw':(($w==2)?'16':'8')).(($bus==0)?'':'_aux');
00050 $i2c = fopen($i2c_fn, 'w');
00051 fseek ($i2c, $w*$a) ;
00052 if ($w==1) $res=fwrite($i2c, chr ($d));
00053 else $res=fwrite($i2c, chr (floor($d/(256*256*256))).chr (($d - 256*256*256*floor($d/(256*256*256)))/(256*256)).chr (($d - 256*256*floor($d/(256*256)))/256).chr ($d - 256*floor($d/(256))) );
00054
00055
00056
00057
00058
00059 fclose($i2c);
00060 return $res;
00061 }
00062
00063 function receive_i2c($width,$bus,$a,$raw=0) {
00064 $w=($width==16)?2:1;
00065 $i2c_fn='/dev/xi2c'.($raw?'raw':(($w==2)?'16':'8')).(($bus==0)?'':'_aux');
00066 $i2c = fopen($i2c_fn, 'r');
00067 fseek ($i2c, $w*$a);
00068 $data = fread($i2c, $w);
00069 fclose($i2c);
00070 if (strlen($data)<$w) return -1;
00071 $v=unpack(($w==1)?'C':'n1',$data);
00072 return $v[1];
00073 }
00074
00075 function receive_i2c_4($width,$bus,$a,$raw=0) {
00076 $w=($width==16)?2:1;
00077 $i2c_fn='/dev/xi2c'.($raw?'raw':(($w==2)?'16':'8')).(($bus==0)?'':'_aux');
00078 $i2c = fopen($i2c_fn, 'r');
00079 fseek ($i2c, 4, SEEK_END);
00080 fseek ($i2c, $w*$a);
00081
00082 $data = fread($i2c, 2*$w);
00083 fclose($i2c);
00084 if (strlen($data)<2*$w) return -1;
00085 $v=unpack(($w==1)?'C*':'N*',$data);
00086
00087
00088 return $v[1];
00089 }
00090
00091 function dcm_reset($width,$bus,$raw=0){
00092
00093 printf("sent 0x%04x ",0x0810); send_i2c_4($width,$bus,0x0810,0xffffffff,$raw=0);
00094 printf("\nsent 0x%04x ",0x0810); send_i2c_4($width,$bus,0x0810,0x00000000,$raw=0);
00095
00096 }
00097
00098 function sensor_init($width,$bus,$channel,$init_pars,$raw=0){
00099
00100
00101 for ($i=0;$i<256;$i++){
00102 send_i2c($width,$bus,0x4800+$i,$init_pars[$i],$raw=0);
00103
00104
00105
00106 $readout=receive_i2c($width,$bus,0x4800+$i,$raw=0);
00107 printf("%04x ",$readout);
00108
00109 if($j==15){
00110 $j=0; printf("\n");
00111 }else{
00112 $j++;
00113 }
00114 }
00115 }
00116
00117 $width=16;
00118 $bus=0;
00119 $sphase=0x0000007;
00120
00121 printf("<pre>\n");
00122
00123 dcm_reset($width,$bus,$raw=0);
00124
00125 send_i2c_4($width,$bus,0x0835,0x00000001,$raw=0); printf("\nSet to sensor <font size=\"6\">1</font>\n");
00126
00127
00128 for ($i=0;$i<256;$i++){
00129 $init_pars[$i]=receive_i2c($width,$bus,0x4800+$i,$raw=0);
00130
00131 printf("%04x ",$init_pars[$i]);
00132
00133 if($j==15){
00134 $j=0; printf("\n");
00135 }else{
00136 $j++;
00137 }
00138
00139 }
00140
00141
00142 send_i2c_4($width,$bus,0x0835,0x00000002,$raw=0); printf("\nInitializing sensor <font size=\"6\">2</font>\n");
00143 sensor_init(16,0,0x00000004,$init_pars,$raw=0);
00144
00145 send_i2c_4($width,$bus,0x0835,0x00000004,$raw=0); printf("\nInitializing sensor <font size=\"6\">3</font>\n");
00146 sensor_init(16,0,0x00000002,$init_pars,$raw=0);
00147
00148 send_i2c_4($width,$bus,0x0835,0x00000001,$raw=0); printf("\nSet back to sensor <font size=\"6\">1</font>\n");
00149
00150
00151 for ($i=0;$i<20;$i++){
00152 send_i2c_4($width,$bus,0x0807,0x00000001,$raw=0);
00153 }
00154
00155 printf("</pre>\n");
00156
00157 ?>