ICP  1
dae2_card.h
Go to the documentation of this file.
1 #ifndef DAE2CARD_H
2 #define DAE2CARD_H
3 
4 #include "isisvme_types.h"
5 #include "isiscrpt_types.h"
6 
7 #include "icp_interfaces.h"
8 #include "IsisBase.h"
9 #include "DAEstatus.h"
10 
11 #include "dae2_policy.h"
12 #include "dae3_policy.h"
13 
14 #include "isisvme.h"
15 
17 {
18  unsigned sub_ver : 8;
19  unsigned minor_ver : 8;
20  unsigned hard_ver : 8;
21  unsigned hard_type : 6;
22  unsigned main_func : 2;
23 };
24 
25 typedef int CardOptions;
26 
28 {
29 public:
31  enum CardType
32  {
33  EmptySlot = 0, UnknownCard = 1, EnvCard = 2,
36  };
37  virtual ~DAE2CardIntf() { }
38  virtual int position() const = 0;
39  virtual std::string daeDevice() const = 0;
40 };
41 
42 template <class DAECardPolicy>
43 class DAE2Card : public ISIS::Base, public DAE2CardIntf, public DAECardPolicy
44 {
45 public:
46 
47  DAE2Card(int position, ISISVME* vme, DAEstatus& status);
48  int setRegisterBits(unsigned long address, isisU32_t mask, bool preserve, DAEstatus& status, bool little_endian = false);
49  int clearRegisterBits(unsigned long address, isisU32_t mask,DAEstatus& status, bool little_endian = false);
50  int setAndClearRegisterBits(unsigned long address, isisU32_t mask, bool preserve, DAEstatus& status, bool little_endian = false);
51  int changeRegisterBits(unsigned long address, isisU32_t mask, bool set, bool check, DAEstatus& status, bool little_endian = false);
52  bool registerBitsSet(unsigned long address, isisU32_t mask, DAEstatus& status, bool little_endian = false);
53  bool registerBitsClear(unsigned long address, isisU32_t mask, DAEstatus& status, bool little_endian = false);
54  int setAndClearRegisterBits(const unused_t& address, isisU32_t mask, bool preserve, DAEstatus& status, bool little_endian = false) { return DAEstatus::Success; }
55 
56  int readRegister(unsigned long address, isisU32_t* value, DAEstatus& status, bool little_endian = false, bool retry = true);
57  int writeRegister(unsigned long address, isisU32_t value, DAEstatus& status, bool little_endian = false);
58  int readRegister(unsigned long address, isisU16_t* value, DAEstatus& status, bool little_endian = false, bool retry = true);
59  int writeRegister16(unsigned long address, isisU16_t value, DAEstatus& status, bool little_endian = false);
60  int readRegister16As32(unsigned long address0, unsigned long address1, isisU32_t* value, DAEstatus& status, bool little_endian = false);
61  int writeRegister32As16(unsigned long address0, unsigned long address1, isisU32_t value, DAEstatus& status, bool little_endian = false);
62  int readRegister(const unused_t& address, isisU32_t* value, DAEstatus& status, bool little_endian = false, bool retry = true) { return DAEstatus::Success; }
63  int writeRegister(const unused_t& address, isisU32_t value, DAEstatus& status, bool little_endian = false) { return DAEstatus::Success; }
64  int writeRegister16(const unused_t& address, isisU16_t value, DAEstatus& status, bool little_endian = false) { return DAEstatus::Success; }
65 
66  // len is number of 32/64 bit items to write
67 // template <typename T> int readMemory(unsigned long address, T* buffer, int len, ISISVME::TransferProps props, DAEstatus& status);
68 // template <typename T> int readMemoryChunked(unsigned long address, T* buffer, int len, int chunk_len, ISISVME::TransferProps props, DAEstatus& status);
69 // template <typename T> int writeMemory(unsigned long address, T* buffer, int len, uint64_t read_check_mask, ISISVME::TransferProps props, DAEstatus& status);
70 // template <typename T> int zeroMemory(unsigned long start, int len, uint64_t read_check_mask, ISISVME::TransferProps props, DAEstatus& status);
71  static bool isCardPresent(int position, ISISVME* vme, DAEstatus& status);
72  int position() const { return m_position; };
73  std::string daeDevice() const;
74  virtual void printStatus(std::ostream& os, DAEstatus& dstatus);
75  std::string getFirmwareVersionAsString(DAEstatus& status);
76  static CardType getCardType(int position, ISISVME* vme, DAEstatus& dstatus);
77 
78  virtual ~DAE2Card() { }
79 
80  void printRegister(const char* name, unsigned long address, std::ostream& os, bool print_bits_set = false);
81 
82  virtual int resetCardState(DAEstatus& status) = 0;
83  static unsigned long makeAddress(int position, unsigned long address)
84  {
85  return DAECardPolicy::makeAddress(position, address);
86  }
87 
88 protected:
89  int m_position; // card number
90 
92 
93 protected:
94  void reverseEndian(isisU32_t* value);
95  void reverseEndian(isisU16_t* value);
96  static int getFirmwareVersion(int position, ISISVME* vme, firmware_version* fw, DAEstatus& status);
97  static const char* yesNoStr(bool b) { return (b ? "yes" : "no"); }
98  std::string loggingPrefix() const { return Poco::format("(card %d on %s) ", m_position, daeDevice()); }
99  virtual unsigned long makeAddress(unsigned long address)
100  {
101  return makeAddress(m_position, address);
102  }
103 public:
104 // memory is 32 bit and little endian; len is number of 32 bit items
105  template <typename T>
106  int readMemory(unsigned long address, typename T* buffer, int len, ISISVME::TransferProps props, DAEstatus& status)
107  {
108  address = makeAddress(address);
109  return m_vme->readBlock(address, buffer, len, props, status);
110  }
111  template <typename T>
112  int readMemoryChunked(unsigned long address, T* buffer, int len, int chunk_len, ISISVME::TransferProps props, DAEstatus& status)
113  {
114  int n, stat;
115  stat = ISISVME::Success;
116  while((stat == ISISVME::Success) && (len > 0))
117  {
118  n = (len > chunk_len ? chunk_len : len);
119  stat = readMemory(address, buffer, n, props, status);
120  address += sizeof(T) * n;
121  buffer += n;
122  len -= n;
123  }
124  return stat;
125  }
126 
127  template <typename T>
128  int writeMemory(unsigned long address, T* buffer, int len, uint64_t read_check_mask, ISISVME::TransferProps props, DAEstatus& status)
129  {
130  int stat, i;
131  bool little_endian = (props & ISISVME::TransferLittleEndian ? true : false);
132  bool block_transfer = (props & ISISVME::TransferBlock ? true : false);
133  address = makeAddress(address);
134  if (read_check_mask == 0)
135  {
136  return m_vme->writeBlock(address, buffer, len, props, status);
137  }
138  bool done = false;
139  T* read_buffer = new T[len];
140  std::list<int> failed_elements;
141  stat = m_vme->writeBlock(address, buffer, len, props, status);
142  stat = m_vme->readBlock(address, read_buffer, len, props, status);
143  for(i=0; i<len; i++)
144  {
145  if ( (buffer[i] & read_check_mask) != (read_buffer[i] & read_check_mask) )
146  {
147  failed_elements.push_back(i);
148  }
149  }
150  if (failed_elements.size() == 0)
151  {
152  delete[] read_buffer;
153  return DAEstatus::Success;
154  }
155  status.addInfoVa(FAC_DAE, "DAE2Card::writeMemory: %d errors - retrying write of %d words to 0x%x (BT=%s,LE=%s,check_mask=0x%llx)",
156  failed_elements.size(), len, address, yesNoStr(block_transfer), yesNoStr(little_endian), read_check_mask);
157  Sleep(10);
158  std::list<int>::const_iterator iter = failed_elements.begin();
159  while(iter != failed_elements.end())
160  {
161  i = *iter;
162  stat = m_vme->writeBlock(address + 4 * i, buffer + i, 1, props, status);
163  stat = m_vme->readBlock(address + 4 * i, read_buffer + i, 1, props, status);
164  if ( (buffer[i] & read_check_mask) == (read_buffer[i] & read_check_mask) )
165  {
166  iter++;
167  }
168  else
169  {
170  status.addInfoVa(FAC_DAE, "DAE2Card::writeMemory: retry failed to address 0x%x (write=0x%x, read=0x%x, mask=0x%llx)", address + 4 * i, buffer[i], read_buffer[i], read_check_mask);
171  Sleep(10);
172  }
173  }
174  delete[] read_buffer;
175  return stat;
176  }
177 
178  template <typename T>
179  int zeroMemory(unsigned long start, int len, uint64_t read_check_mask, ISISVME::TransferProps props, DAEstatus& status)
180  {
181  int l, buflen = 64*1024;
182  T* buffer = new T[buflen];
183  memset(buffer, 0, buflen*sizeof(T));
184  while(len > 0)
185  {
186  l = (len > buflen ? buflen : len);
187  writeMemory(start, buffer, l, read_check_mask, props, status);
188  start += sizeof(T) * l;
189  len -= l;
190  }
191  delete []buffer;
192  return 0;
193  }
194 
195 };
196 
197 
198 
199 template <class DAECardPolicy>
201 {
202  *value = (((*value) << 24) & 0xff000000) |
203  (((*value) << 8) & 0x00ff0000) |
204  (((*value) >> 8) & 0x0000ff00) |
205  (((*value) >> 24) & 0x000000ff);
206 }
207 
208 template <class DAECardPolicy>
210 {
211  *value = (((*value) & 0xff) << 8) | ((*value) >> 8);
212 }
213 
214 template <class DAECardPolicy>
216 {
217 protected:
221 
222 public:
223  DAE2Register(MyDAE2Card* card, isisU32_t address) : m_card(card), m_address(address) {}
224  virtual ~DAE2Register() {}
225  int setBits(isisU32_t mask, bool preserve, DAEstatus& status, bool little_endian = false)
226  {
227  return m_card->setRegisterBits(m_address, mask, preserve, status, little_endian);
228  }
229  int clearBits(isisU32_t mask, DAEstatus& status, bool little_endian = false)
230  {
231  return m_card->clearRegisterBits(m_address, mask, status, little_endian);
232  }
233  int enable(bool choice, isisU32_t mask, DAEstatus& status, bool little_endian = false)
234  {
235  return m_card->changeRegisterBits(m_address, mask, choice, true, status, little_endian);
236  }
237  isisU32_t read(DAEstatus& status, bool little_endian = false, bool retry = true)
238  {
239  isisU32_t value = 0;
240  m_card->readRegister(m_address, &value, status, little_endian, retry);
241  return value;
242  }
243 
244 private:
246 };
247 
248 #endif /* DAE2CARD_H */
uint32_t TransferProps
combination of TransferProp values
Definition: isisvme.h:16
#define FAC_DAE
int enable(bool choice, isisU32_t mask, DAEstatus &status, bool little_endian=false)
Definition: dae2_card.h:233
unsigned hard_type
Definition: dae2_card.h:21
DAE2Register(MyDAE2Card *card, isisU32_t address)
Definition: dae2_card.h:223
unused_t
Definition: dae_policy.h:4
int readMemoryChunked(unsigned long address, T *buffer, int len, int chunk_len, ISISVME::TransferProps props, DAEstatus &status)
Definition: dae2_card.h:112
virtual int readBlock(unsigned long address, isisU32_t *data, long nitems, TransferProps props, DAEstatus &status)=0
void reverseEndian(isisU32_t *value)
Definition: dae2_card.h:200
virtual unsigned long makeAddress(unsigned long address)
Definition: dae2_card.h:99
int readRegister(const unused_t &address, isisU32_t *value, DAEstatus &status, bool little_endian=false, bool retry=true)
Definition: dae2_card.h:62
std::string getFirmwareVersionAsString(DAEstatus &status)
Definition: dae2_card.cpp:460
int setRegisterBits(unsigned long address, isisU32_t mask, bool preserve, DAEstatus &status, bool little_endian=false)
Definition: dae2_card.cpp:183
unsigned long isisU32_t
Definition: isisvme_types.h:8
virtual int writeBlock(unsigned long address, isisU32_t *data, long nitems, TransferProps props, DAEstatus &status)=0
virtual std::string daeDevice() const =0
static const int Success
Definition: DAEstatus.h:140
static CardType getCardType(int position, ISISVME *vme, DAEstatus &dstatus)
Definition: dae2_card.cpp:361
int setAndClearRegisterBits(const unused_t &address, isisU32_t mask, bool preserve, DAEstatus &status, bool little_endian=false)
Definition: dae2_card.h:54
bool registerBitsSet(unsigned long address, isisU32_t mask, DAEstatus &status, bool little_endian=false)
Definition: dae2_card.cpp:269
isisU32_t m_address
Definition: dae2_card.h:220
int clearRegisterBits(unsigned long address, isisU32_t mask, DAEstatus &status, bool little_endian=false)
Definition: dae2_card.cpp:201
virtual void printStatus(std::ostream &os, DAEstatus &dstatus)
Definition: dae2_card.cpp:453
int CardOptions
Definition: dae2_card.h:25
std::string loggingPrefix() const
Definition: dae2_card.h:98
DAE2Card(int position, ISISVME *vme, DAEstatus &status)
Definition: dae2_card.cpp:7
virtual ~DAE2Register()
Definition: dae2_card.h:224
int readMemory(unsigned long address, typename T *buffer, int len, ISISVME::TransferProps props, DAEstatus &status)
Definition: dae2_card.h:106
virtual int position() const =0
int setBits(isisU32_t mask, bool preserve, DAEstatus &status, bool little_endian=false)
Definition: dae2_card.h:225
isisU32_t read(DAEstatus &status, bool little_endian=false, bool retry=true)
Definition: dae2_card.h:237
int writeRegister(unsigned long address, isisU32_t value, DAEstatus &status, bool little_endian=false)
Definition: dae2_card.cpp:155
static bool isCardPresent(int position, ISISVME *vme, DAEstatus &status)
Definition: dae2_card.cpp:317
unsigned sub_ver
Definition: dae2_card.h:18
int readRegister(unsigned long address, isisU32_t *value, DAEstatus &status, bool little_endian=false, bool retry=true)
Definition: dae2_card.cpp:23
int setAndClearRegisterBits(unsigned long address, isisU32_t mask, bool preserve, DAEstatus &status, bool little_endian=false)
Definition: dae2_card.cpp:243
unsigned short isisU16_t
Definition: isisvme_types.h:7
MyDAE2Card * m_card
Definition: dae2_card.h:219
ISISVME * m_vme
Definition: dae2_card.h:91
int clearBits(isisU32_t mask, DAEstatus &status, bool little_endian=false)
Definition: dae2_card.h:229
int writeRegister16(const unused_t &address, isisU16_t value, DAEstatus &status, bool little_endian=false)
Definition: dae2_card.h:64
std::string daeDevice() const
Definition: dae2_card.cpp:13
unsigned hard_ver
Definition: dae2_card.h:20
int changeRegisterBits(unsigned long address, isisU32_t mask, bool set, bool check, DAEstatus &status, bool little_endian=false)
Definition: dae2_card.cpp:216
virtual ~DAE2CardIntf()
Definition: dae2_card.h:37
virtual ~DAE2Card()
Definition: dae2_card.h:78
static unsigned long makeAddress(int position, unsigned long address)
Definition: dae2_card.h:83
int writeMemory(unsigned long address, T *buffer, int len, uint64_t read_check_mask, ISISVME::TransferProps props, DAEstatus &status)
Definition: dae2_card.h:128
int position() const
Definition: dae2_card.h:72
int writeRegister16(unsigned long address, isisU16_t value, DAEstatus &status, bool little_endian=false)
Definition: dae2_card.cpp:169
static int getFirmwareVersion(int position, ISISVME *vme, firmware_version *fw, DAEstatus &status)
Definition: dae2_card.cpp:537
unsigned main_func
Definition: dae2_card.h:22
int writeRegister32As16(unsigned long address0, unsigned long address1, isisU32_t value, DAEstatus &status, bool little_endian=false)
Definition: dae2_card.cpp:135
int readRegister16As32(unsigned long address0, unsigned long address1, isisU32_t *value, DAEstatus &status, bool little_endian=false)
Definition: dae2_card.cpp:114
virtual int resetCardState(DAEstatus &status)=0
static const char * yesNoStr(bool b)
Definition: dae2_card.h:97
int addInfoVa(int facility, const char *format,...)
Definition: DAEstatus.cpp:91
int writeRegister(const unused_t &address, isisU32_t value, DAEstatus &status, bool little_endian=false)
Definition: dae2_card.h:63
DAE2Card< DAECardPolicy > MyDAE2Card
Definition: dae2_card.h:218
bool registerBitsClear(unsigned long address, isisU32_t mask, DAEstatus &status, bool little_endian=false)
Definition: dae2_card.cpp:290
int zeroMemory(unsigned long start, int len, uint64_t read_check_mask, ISISVME::TransferProps props, DAEstatus &status)
Definition: dae2_card.h:179
int m_position
Definition: dae2_card.h:89
unsigned minor_ver
Definition: dae2_card.h:19
void printRegister(const char *name, unsigned long address, std::ostream &os, bool print_bits_set=false)
Definition: dae2_card.cpp:53