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