Cat
SpecsGlue.cpp
Go to the documentation of this file.
1 // $Id: SpecsGlue.cpp,v 1.3 2006/10/24 13:28:41 fmachefe Exp $
2 // include files
3 #include <algorithm>
4 
5 // CAT include files
6 #include "Tools.h"
7 #include "SpecsI2c.h"
8 
9 // local
10 #include "SpecsGlue.h"
11 
12 //-----------------------------------------------------------------------------
13 // Implementation file for class : SpecsGlue
14 //
15 // 2005-05-25 : Frédéric Machefert
16 //-----------------------------------------------------------------------------
17 
18 //=============================================================================
19 // Standard constructor, initializes variables
20 //=============================================================================
22  setAddress(0x0);
23  setName("SpecsGlue");
24  setType("SpecsGlue");
25 }
26 
27 //=============================================================================
28 // Destructor
29 //=============================================================================
31 
32 //=============================================================================
33 // Command line function for the SpecsMezzanine
34 //=============================================================================
35 /*
36 bool SpecsGlue::cmdline(std::vector <std::string> cmd){
37 
38  if ( cmd.size()==0){
39  info("cmdline","Date : "+itos(date()));
40  info("cmdline","Address [Address] : "+itos(address()));
41  info("cmdline","I2C Clk [I2cClkMode] : "+itos(i2cClkMode()));
42  return true;
43  }
44 
45  transform(cmd[0].begin(),cmd[0].end(),cmd[0].begin(),tolower);
46 
47  if (cmd[0].compare("address")==0){
48  this->setAddress(atoi(cmd[1].c_str()));
49  return true;
50  }
51 
52  if (cmd[0].compare("address")==0){
53  this->setAddress(atoi(cmd[1].c_str()));
54  return true;
55  }
56 
57  if (cmd[0].compare("reset")==0){
58  this->reset();
59  return true;
60  }
61 
62  if (cmd[0].compare("internalreset")==0){
63  this->resetInternal();
64  return true;
65  }
66 
67  if (cmd[0].compare("led")==0){
68  if ( 0==atoi(cmd[1].c_str()) ) {
69  setLed ( false );
70  }
71  else {
72  setLed ( true );
73  }
74  return true;
75  }
76 
77  if (cmd[0].compare("i2cclkmode")==0){
78  setI2cClkMode ( atoi(cmd[1].c_str()) );
79  return true;
80  }
81 
82  if (cmd[0].compare("regwrite")==0){
83  msgSvc(INFO,"cmdline",
84  "Register "+ cmd[1]+ " -> Write " + cmd[2]);
85  this->specsWriteRegister( atoi(cmd[1].c_str()),
86  atoi(cmd[2].c_str()));
87  return true;
88  }
89 
90  if (cmd[0].compare("i2cwritereg")==0){
91  int add = atoi(cmd[1].c_str());
92  int out = atoi(cmd[2].c_str());
93  int ssadd = atoi(cmd[3].c_str());
94  int nword = atoi(cmd[4].c_str());
95  U8 data[100];
96  for ( int i = 0 ; i< nword ; ++i ) {
97  data[i]=(unsigned char) (atoi(cmd[5+i].c_str()));
98  }
99  msgSvc(INFO,"cmdline",
100  "I2C Register "+ cmd[2]+ "/" + itos(add) +
101  " -> Write " + cmd[4] + " words.");
102  this->specsWriteI2c( add , out , ssadd , nword, data );
103  return true;
104  }
105 
106  if (cmd[0].compare("i2creadreg")==0){
107  int add = atoi(cmd[1].c_str());
108  int out = atoi(cmd[2].c_str());
109  int ssadd = atoi(cmd[3].c_str());
110  int nword = atoi(cmd[4].c_str());
111  U8 data[100];
112  msgSvc(INFO,"cmdline",
113  "I2C Register "+ cmd[2]+ "/" + itos(add) +
114  " -> Read " + cmd[3] + " words.");
115  this->specsReadI2c( add , out , ssadd , nword, data );
116  for ( int i = 0 ; i< nword ; ++i ) {
117  msgSvc(INFO,""," word ["+ itos (i) + "]" + itos(data[i]));
118  }
119  return true;
120  }
121 
122  if (cmd[0].compare("regread")==0){
123  U16 val;
124  this->specsReadRegister( atoi(cmd[1].c_str()),
125  val);
126  msgSvc(INFO,"cmdline",
127  "Register "+ cmd[1]+ " -> " + itos(val) );
128  return true;
129  }
130 
131  if (cmd[0].compare("help")==0){
132  this->help();
133  return true;
134  }
135 
136  return false;
137 }
138 */
139 
140 //=============================================================================
141 // Help function for the Specs Glue
142 //=============================================================================
144  info("SpecsGlue","Specs Glue Element help");
145  info("","");
146  info("","Address # : set slave address at #");
147  info("","Reset : reset of the slave");
148  info("","ResetInternal : internal reset of the slave");
149  info("","RegWrite #0 #1 : write register #0 with value #1");
150  info("","RegRead #0 #1 : read register #");
151 
152  info( "","");
153 }
154 
155 //=============================================================================
156 // Get the Date of the Specs Glue fimware
157 //=============================================================================
159  unsigned char reg = 8 ;
160 #ifndef _NODEVICE_
161  U16 val;
162  this -> specsReadRegister( reg , val );
163  val = (val&0xFF00)*100+(val&0xFF);
164  return val;
165 #else
166  warning("" , "Compilation in _NoDevice_ mode." );
167 #endif
168  return 0;
169 }
170 
171 //=============================================================================
172 // Set the LED state for the Glue
173 //=============================================================================
174 void SpecsGlue::setLed ( bool state ){
175  unsigned char reg = 4 ;
176 #ifndef _NODEVICE_
177  U16 val;
178  this -> specsReadRegister( reg , val );
179  if ( state ) {
180  val = ( val & 0xFFF7 ) ;
181  this -> specsWriteRegister(reg, val );
182  debug("SpecsGlue::led","setting Glue LEDs On");
183  }
184  else {
185  val = ( val | 0x0008 ) ;
186  this -> specsWriteRegister(reg , val ) ;
187  debug("SpecsGlue::led","setting Glue LEDs OFF");
188  }
189 #else
190  debug("" , "Compilation in _NoDevice_ mode." );
191 #endif
192 }
193 
194 //=============================================================================
195 // Get the LED state for the Glue
196 //=============================================================================
197 bool SpecsGlue::led ( ) {
198  unsigned char reg = 4 ;
199 #ifndef _NODEVICE_
200  U16 val ;
201  this -> specsReadRegister( reg , val );
202  if ( 0 != ( val & 0x0008 ) ){
203  debug("SpecsGlue::led","Glue LEDs are OFF");
204  return false;
205  }
206 #else
207  warning("" , "Compilation in _NoDevice_ mode." );
208  return true;
209 #endif
210  debug("SpecsGlue::led","Glue LEDs are ON");
211  return true;
212 }
213 
214 //=============================================================================
215 // Set the i2c clock state when idle
216 //=============================================================================
217 void SpecsGlue::setI2cClkMode ( int mode ){
218  unsigned char reg = 4 ;
219 #ifndef _NODEVICE_
220  U16 val;
221  this -> specsReadRegister( reg , val );
222  if ( 0==mode ) {
223  val = ( val & 0xFFFB ) ;
224  this -> specsWriteRegister(reg, val );
225  debug("SpecsGlue::led","setting Glue I2C Mode Clk idle 1");
226  }
227  else {
228  val = ( val | 0x0004 ) ;
229  this -> specsWriteRegister(reg , val ) ;
230  debug("SpecsGlue::led","setting Glue I2C Mode Clk idle 0");
231  }
232 #else
233  warning("" , "Compilation in _NoDevice_ mode." );
234 #endif
235 }
236 
237 
238 //=============================================================================
239 // Get the i2c clock state when idle
240 //=============================================================================
242  unsigned char reg = 4 ;
243 #ifndef _NODEVICE_
244  U16 val ;
245  this -> specsReadRegister( reg , val );
246  if ( 0 != ( val & 0x0004 ) ){
247  debug("SpecsGlue::led","Glue I2C Mode Clk idle 0");
248  return 1;
249  }
250 #else
251  warning("" , "Compilation in _NoDevice_ mode." );
252  return 0;
253 #endif
254  debug("SpecsGlue::led","Glue I2C Mode Clk idle 1");
255  return 0;
256 }
257 
258 
259 
260 //=============================================================================
261 
void info(std::string mymsg)
Definition: Object.h:38
void setLed(bool)
Definition: SpecsGlue.cpp:174
void setName(std::string name)
Definition: Object.h:51
void setI2cClkMode(int)
Definition: SpecsGlue.cpp:217
virtual ~SpecsGlue()
Standard Destructor.
Definition: SpecsGlue.cpp:30
bool led()
Definition: SpecsGlue.cpp:197
bool specsWriteRegister(unsigned char, unsigned short)
void setType(std::string type)
Definition: Object.h:52
void debug(std::string mymsg)
Definition: Object.h:37
void setAddress(unsigned char)
Definition: SpecsSlave.cpp:50
SpecsGlue()
Standard constructor.
Definition: SpecsGlue.cpp:21
int i2cClkMode()
Definition: SpecsGlue.cpp:241
void help()
Definition: SpecsGlue.cpp:143
unsigned short U16
Definition: ICECALv3.h:54
void warning(std::string mymsg)
Definition: Object.h:39
int date()
Definition: SpecsGlue.cpp:158
bool specsReadRegister(unsigned char, U16 &)