Cat
SpecsMezzanine.cpp
Go to the documentation of this file.
1 // $Id: SpecsMezzanine.cpp,v 1.4 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 #include "SpecsBus.h"
9 
10 // local
11 #include "SpecsMezzanine.h"
12 
13 //-----------------------------------------------------------------------------
14 // Implementation file for class : SpecsMezzanine
15 //
16 // 2005-05-25 : Frédéric Machefert
17 //-----------------------------------------------------------------------------
18 
19 //=============================================================================
20 // Standard constructor, initializes variables
21 //=============================================================================
23  debug("SpecsMezzanine::SpecsMezzanine","SpecsMezzanine built.");
24 
25  setAddress(0x0);
26  setName("SpecsMezzanine");
27  setType("SpecsMezzanine");
28 
29  m_bus = new SpecsBus();
30  m_bus->setParent(this);
31  addChild(m_bus);
32 
33  m_dcu=new DCU();
34  m_dcu->setName("DCU");
35  m_dcu->setOutputSelect (0xF) ; // i2c short distance for DCU
36  m_dcu->setAddress (0) ;
37  addI2c(m_dcu);
38 }
39 
40 //=============================================================================
41 // Destructor
42 //=============================================================================
44 
45 //=============================================================================
46 // Add a device connected to the parallel bus of the mezzanine
47 //=============================================================================
49  element->setParent(m_bus);
50  m_bus->addChild(element);
51  debug("SpecsMezzanine::addBus",
52  element->name()+" added to the bus child tree.");
53 }
54 
55 //=============================================================================
56 // Command line function for the SpecsMezzanine
57 //=============================================================================
58 bool SpecsMezzanine::cmdline(std::vector <std::string> cmd){
59 
60  if ( cmd.size()==0){
61  info("cmdline","Date : "+itos(date()));
62  return true;
63  info("cmdline","Address [Address] : "+itos(address()));
64  return true;
65  }
66 
67  transform(cmd[0].begin(),cmd[0].end(),cmd[0].begin(),tolower);
68 
69  if (cmd[0].compare("address")==0){
70  this->setAddress(atoi(cmd[1].c_str()));
71  return true;
72  }
73 
74  if (cmd[0].compare("address")==0){
75  this->setAddress(atoi(cmd[1].c_str()));
76  return true;
77  }
78 
79  if (cmd[0].compare("reset")==0){
80  this->reset();
81  return true;
82  }
83 
84  if (cmd[0].compare("internalreset")==0){
85  this->resetInternal();
86  return true;
87  }
88 
89  if (cmd[0].compare("led")==0){
90  if ( 0==atoi(cmd[1].c_str()) ) {
91  setLed ( false );
92  }
93  else {
94  setLed ( true );
95  }
96  return true;
97  }
98 
99  if (cmd[0].compare("regwrite")==0){
100  info("cmdline",
101  "Register "+ cmd[1]+ " -> Write " + cmd[2]);
102  this->specsWriteRegister( atoi(cmd[1].c_str()),
103  atoi(cmd[2].c_str()));
104  return true;
105  }
106 
107  if (cmd[0].compare("i2cwritereg")==0){
108  int add = atoi(cmd[1].c_str());
109  int out = atoi(cmd[2].c_str());
110  int ssadd = atoi(cmd[3].c_str());
111  int nword = atoi(cmd[4].c_str());
112  U8 data[100];
113  for ( int i = 0 ; i< nword ; ++i ) {
114  data[i]=(unsigned char) (atoi(cmd[5+i].c_str()));
115  }
116  info("cmdline",
117  "I2C Register "+ cmd[2]+ "/" + itos(add) +
118  " -> Write " + cmd[4] + " words.");
119  this->specsWriteI2c( add , out , ssadd , nword, data );
120  return true;
121  }
122 
123  if (cmd[0].compare("i2creadreg")==0){
124  int add = atoi(cmd[1].c_str());
125  int out = atoi(cmd[2].c_str());
126  int ssadd = atoi(cmd[3].c_str());
127  int nword = atoi(cmd[4].c_str());
128  U8 data[100];
129  info("cmdline",
130  "I2C Register "+ cmd[2]+ "/" + itos(add) +
131  " -> Read " + cmd[3] + " words.");
132  this->specsReadI2c( add , out , ssadd , nword, data );
133  for ( int i = 0 ; i< nword ; ++i ) {
134  info(""," word ["+ itos (i) + "]" + itos(data[i]));
135  }
136  return true;
137  }
138 
139  if (cmd[0].compare("regread")==0){
140  U16 val;
141  this->specsReadRegister( atoi(cmd[1].c_str()),
142  val);
143  info("cmdline",
144  "Register "+ cmd[1]+ " -> " + itos(val) );
145  return true;
146  }
147 
148  if (cmd[0].compare("help")==0){
149  this->help();
150  return true;
151  }
152 
153  return false;
154 }
155 
156 //=============================================================================
157 // Help function for the Specs Mezzanine
158 //=============================================================================
160  info("SpecsMezzanine","Specs Mezzanine Element help");
161  msgSvc(0,"","");
162  msgSvc(0,"","Address # : set slave address at #");
163  msgSvc(0,"","Reset : reset of the slave");
164  msgSvc(0,"","ResetInternal : internal reset of the slave");
165  msgSvc(0,"","RegWrite #0 #1 : write register #0 with value #1");
166  msgSvc(0,"","RegRead #0 #1 : read register #");
167 
168  msgSvc(0,"","");
169 }
170 
171 //=============================================================================
172 // Get the Date of the Specs Mezzanine fimware
173 //=============================================================================
175  unsigned char reg = 8 ;
176 #ifndef _NODEVICE_
177  U16 val ;
178  this -> specsReadRegister( reg , val );
179  val = (val&0xFF00)*100+(val&0xFF);
180  return val;
181 #else
182  warning("" , "Compilation in _NoDevice_ mode." );
183 #endif
184  return 0;
185 }
186 
187 //=============================================================================
188 // Set the LED state for the Mezzanine
189 //=============================================================================
190 void SpecsMezzanine::setLed ( bool state ){
191  unsigned char reg = 4 ;
192 #ifndef _NODEVICE_
193  U16 val;
194  this -> specsReadRegister( reg , val );
195  if ( state ) {
196  val = ( val & 0xF7FF ) ;
197  this -> specsWriteRegister(reg, (val>>8) );
198  debug("SpecsMezzanine::led","setting Glue LEDs On");
199  }
200  else {
201  val = ( val | 0x0800 ) ;
202  this -> specsWriteRegister(reg , (val>>8) ) ;
203  debug("SpecsMezzanine::led","setting Glue LEDs OFF");
204  }
205 #else
206  warning("" , "Compilation in _NoDevice_ mode." );
207 #endif
208 }
209 
210 //=============================================================================
211 // Get the LED state for the Mezzanine
212 //=============================================================================
214  unsigned char reg = 4 ;
215 #ifndef _NODEVICE_
216  U16 val ;
217  this -> specsReadRegister( reg , val );
218  if ( 0 != ( val & 0x0800 ) ){
219  debug("SpecsMezzanine::led","Glue LEDs are OFF");
220  return false;
221  }
222 #else
223  warning("" , "Compilation in _NoDevice_ mode." );
224  return true;
225 #endif
226  debug("SpecsMezzanine::led","Glue LEDs are ON");
227  return true;
228 }
229 
230 //=============================================================================
void info(std::string mymsg)
Definition: Object.h:38
std::string itos(int)
Definition: Tools.cpp:46
SpecsMezzanine()
Standard constructor.
void setOutputSelect(U8 outputSelect)
Definition: DCU.h:54
void reset()
Definition: SpecsSlave.cpp:204
void setParent(Hierarchy *parent)
Definition: Hierarchy.cpp:67
void add(int attribut)
Definition: Attrib.h:67
void setName(std::string name)
Definition: Object.h:51
bool specsReadI2c(unsigned char address, unsigned char nOctects, U8 *i2cWords)
virtual ~SpecsMezzanine()
Standard Desctructor.
bool specsWriteI2c(unsigned char address, unsigned char nData, U8 *data)
void setAddress(U8 address)
Definition: DCU.h:51
unsigned char address()
void resetInternal()
Definition: SpecsSlave.cpp:184
bool specsWriteRegister(unsigned char, unsigned short)
void setType(std::string type)
Definition: Object.h:52
unsigned char U8
Definition: ICECALv3.h:55
void debug(std::string mymsg)
Definition: Object.h:37
def data(object, stream=None)
Definition: shell.py:150
void addBus(Element *)
void setAddress(unsigned char)
Definition: SpecsSlave.cpp:50
Definition: DCU.h:15
SpecsBus * m_bus
std::string name() const
Definition: Object.h:28
virtual void addChild(Hierarchy *element)
Definition: Hierarchy.cpp:83
void msgSvc(int level, std::string msg, std::string name)
Definition: Object.h:33
unsigned short U16
Definition: ICECALv3.h:54
void warning(std::string mymsg)
Definition: Object.h:39
void addI2c(Hierarchy *)
Definition: SpecsSlave.cpp:175
bool cmdline(std::vector< std::string >)
bool specsReadRegister(unsigned char, U16 &)