OpenCores
URL https://opencores.org/ocsvn/w11/w11/trunk

Subversion Repositories w11

[/] [w11/] [tags/] [w11a_V0.7/] [tools/] [src/] [librlink/] [RlinkCommandList.cpp] - Blame information for rev 30

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 30 wfjm
// $Id: RlinkCommandList.cpp 661 2015-04-03 18:28:41Z mueller $
2 10 wfjm
//
3 30 wfjm
// Copyright 2011-2015 by Walter F.J. Mueller <W.F.J.Mueller@gsi.de>
4 10 wfjm
//
5
// This program is free software; you may redistribute and/or modify it under
6
// the terms of the GNU General Public License as published by the Free
7
// Software Foundation, either version 2, or at your option any later version.
8
//
9
// This program is distributed in the hope that it will be useful, but
10
// WITHOUT ANY WARRANTY, without even the implied warranty of MERCHANTABILITY
11
// or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
12
// for complete details.
13
// 
14
// Revision History: 
15
// Date         Rev Version  Comment
16 30 wfjm
// 2015-04-02   661   1.3    expect logic: add SetLastExpect methods
17 27 wfjm
// 2014-11-23   606   1.2    new rlink v4 iface
18 25 wfjm
// 2014-08-02   576   1.1    rename LastExpect->SetLastExpect
19 19 wfjm
// 2013-05-06   495   1.0.3  add RlinkContext to Print() args
20
// 2013-02-03   481   1.0.2  use Rexception
21 12 wfjm
// 2011-04-25   380   1.0.1  use boost/foreach
22 10 wfjm
// 2011-03-05   366   1.0    Initial version
23
// 2011-01-15   355   0.1    First draft
24
// ---------------------------------------------------------------------------
25
 
26
/*!
27
  \file
28 30 wfjm
  \version $Id: RlinkCommandList.cpp 661 2015-04-03 18:28:41Z mueller $
29 10 wfjm
  \brief   Implemenation of class RlinkCommandList.
30
 */
31
 
32
#include <string>
33
 
34 12 wfjm
#include "boost/foreach.hpp"
35 19 wfjm
#define foreach_ BOOST_FOREACH
36 12 wfjm
 
37 10 wfjm
#include "RlinkCommandList.hpp"
38
 
39
#include "librtools/RosPrintf.hpp"
40
#include "librtools/RosFill.hpp"
41 19 wfjm
#include "librtools/Rexception.hpp"
42 10 wfjm
 
43
using namespace std;
44
 
45
/*!
46
  \class Retro::RlinkCommandList
47
  \brief FIXME_docs
48
*/
49
 
50 19 wfjm
// all method definitions in namespace Retro
51
namespace Retro {
52
 
53 10 wfjm
//------------------------------------------+-----------------------------------
54
//! Default constructor
55
 
56
RlinkCommandList::RlinkCommandList()
57 27 wfjm
  : fList(),
58
    fLaboIndex(-1)
59 10 wfjm
{
60
  fList.reserve(16);                        // should prevent most re-alloc's
61
}
62
 
63
//------------------------------------------+-----------------------------------
64
//! Copy constructor
65
 
66
RlinkCommandList::RlinkCommandList(const RlinkCommandList& rhs)
67
  : fList()
68
{
69
  operator=(rhs);
70
}
71
 
72
//------------------------------------------+-----------------------------------
73
//! Destructor
74
 
75
RlinkCommandList::~RlinkCommandList()
76
{
77 19 wfjm
  foreach_ (RlinkCommand* pcmd, fList) { delete pcmd; }
78 10 wfjm
}
79
 
80
//------------------------------------------+-----------------------------------
81
//! FIXME_docs
82
 
83
size_t RlinkCommandList::AddCommand(RlinkCommand* cmd)
84
{
85
  size_t ind = fList.size();
86
  fList.push_back(cmd);
87
  return ind;
88
}
89
 
90
//------------------------------------------+-----------------------------------
91
//! FIXME_docs
92
 
93
size_t RlinkCommandList::AddCommand(const RlinkCommand& cmd)
94
{
95
  return AddCommand(new RlinkCommand(cmd));
96
}
97
 
98
//------------------------------------------+-----------------------------------
99
//! FIXME_docs
100
 
101
size_t RlinkCommandList::AddCommand(const RlinkCommandList& clist)
102
{
103
  size_t ind = fList.size();
104
  for (size_t i=0; i<clist.Size(); i++) {
105
    AddCommand(new RlinkCommand(clist[i]));
106
  }
107
  return ind;
108
}
109
 
110
//------------------------------------------+-----------------------------------
111
//! FIXME_docs
112
 
113
size_t RlinkCommandList::AddRreg(uint16_t addr)
114
{
115
  RlinkCommand* pcmd = new RlinkCommand();
116
  pcmd->CmdRreg(addr);
117
  return AddCommand(pcmd);
118
}
119
 
120
//------------------------------------------+-----------------------------------
121
//! FIXME_docs
122
 
123
size_t RlinkCommandList::AddRblk(uint16_t addr, size_t size)
124
{
125
  RlinkCommand* pcmd = new RlinkCommand();
126
  pcmd->CmdRblk(addr, size);
127
  return AddCommand(pcmd);
128
}
129
 
130
//------------------------------------------+-----------------------------------
131
//! FIXME_docs
132
 
133
size_t RlinkCommandList::AddRblk(uint16_t addr, uint16_t* block, size_t size)
134
{
135
  RlinkCommand* pcmd = new RlinkCommand();
136
  pcmd->CmdRblk(addr, block, size);
137
  return AddCommand(pcmd);
138
}
139
 
140
//------------------------------------------+-----------------------------------
141
//! FIXME_docs
142
 
143
size_t RlinkCommandList::AddWreg(uint16_t addr, uint16_t data)
144
{
145
  RlinkCommand* pcmd = new RlinkCommand();
146
  pcmd->CmdWreg(addr, data);
147
  return AddCommand(pcmd);
148
}
149
 
150
//------------------------------------------+-----------------------------------
151
//! FIXME_docs
152
 
153
size_t RlinkCommandList::AddWblk(uint16_t addr, std::vector<uint16_t> block)
154
{
155
  RlinkCommand* pcmd = new RlinkCommand();
156
  pcmd->CmdWblk(addr, block);
157
  return AddCommand(pcmd);
158
}
159
 
160
//------------------------------------------+-----------------------------------
161
//! FIXME_docs
162
 
163
size_t RlinkCommandList::AddWblk(uint16_t addr, const uint16_t* block,
164
                                 size_t size)
165
{
166
  RlinkCommand* pcmd = new RlinkCommand();
167
  pcmd->CmdWblk(addr, block, size);
168
  return AddCommand(pcmd);
169
}
170
 
171
//------------------------------------------+-----------------------------------
172
//! FIXME_docs
173
 
174 27 wfjm
size_t RlinkCommandList::AddLabo()
175 10 wfjm
{
176
  RlinkCommand* pcmd = new RlinkCommand();
177 27 wfjm
  pcmd->CmdLabo();
178 10 wfjm
  return AddCommand(pcmd);
179
}
180
 
181
//------------------------------------------+-----------------------------------
182
//! FIXME_docs
183
 
184
size_t RlinkCommandList::AddAttn()
185
{
186
  RlinkCommand* pcmd = new RlinkCommand();
187
  pcmd->CmdAttn();
188
  return AddCommand(pcmd);
189
}
190
 
191
//------------------------------------------+-----------------------------------
192
//! FIXME_docs
193
 
194
size_t RlinkCommandList::AddInit(uint16_t addr, uint16_t data)
195
{
196
  RlinkCommand* pcmd = new RlinkCommand();
197
  pcmd->CmdInit(addr, data);
198
  return AddCommand(pcmd);
199
}
200
 
201
//------------------------------------------+-----------------------------------
202
//! FIXME_docs
203
 
204 30 wfjm
void RlinkCommandList::SetLastExpectStatus(uint8_t stat, uint8_t statmsk)
205
{
206
  if (fList.empty())
207
    throw Rexception("RlinkCommandList::SetLastExpectStatus()",
208
                     "Bad state: list empty");
209
  fList.back()->SetExpectStatus(stat, statmsk);
210
  return;
211
}
212
 
213
//------------------------------------------+-----------------------------------
214
//! FIXME_docs
215
 
216
void RlinkCommandList::SetLastExpectData(uint16_t data, uint16_t datamsk)
217
{
218
  if (fList.empty())
219
    throw Rexception("RlinkCommandList::SetLastExpectData()",
220
                     "Bad state: list empty");
221
  RlinkCommand& cmd = *fList.back();
222
  if (!cmd.Expect()) cmd.SetExpect(new RlinkCommandExpect());
223
  cmd.Expect()->SetData(data, datamsk);
224
  return;
225
}
226
 
227
//------------------------------------------+-----------------------------------
228
//! FIXME_docs
229
 
230
void RlinkCommandList::SetLastExpectDone(uint16_t done)
231
{
232
  if (fList.empty())
233
    throw Rexception("RlinkCommandList::SetLastExpectDone()",
234
                     "Bad state: list empty");
235
  RlinkCommand& cmd = *fList.back();
236
  if (!cmd.Expect()) cmd.SetExpect(new RlinkCommandExpect());
237
  cmd.Expect()->SetDone(done);
238
  return;
239
}
240
 
241
//------------------------------------------+-----------------------------------
242
//! FIXME_docs
243
 
244
void RlinkCommandList::SetLastExpectBlock(const std::vector<uint16_t>& block)
245
{
246
  if (fList.empty())
247
    throw Rexception("RlinkCommandList::SetLastExpectBlock()",
248
                     "Bad state: list empty");
249
  RlinkCommand& cmd = *fList.back();
250
  if (!cmd.Expect()) cmd.SetExpect(new RlinkCommandExpect());
251
  cmd.Expect()->SetBlock(block);
252
  return;
253
}
254
 
255
//------------------------------------------+-----------------------------------
256
//! FIXME_docs
257
 
258
  void RlinkCommandList::SetLastExpectBlock(const std::vector<uint16_t>& block,
259
                                        const std::vector<uint16_t>& blockmsk)
260
{
261
  if (fList.empty())
262
    throw Rexception("RlinkCommandList::SetLastExpectBlock()",
263
                     "Bad state: list empty");
264
  RlinkCommand& cmd = *fList.back();
265
  if (!cmd.Expect()) cmd.SetExpect(new RlinkCommandExpect());
266
  cmd.Expect()->SetBlock(block, blockmsk);
267
  return;
268
}
269
 
270
//------------------------------------------+-----------------------------------
271
//! FIXME_docs
272
 
273 25 wfjm
void RlinkCommandList::SetLastExpect(RlinkCommandExpect* pexp)
274 10 wfjm
{
275 30 wfjm
  if (fList.empty())
276 25 wfjm
    throw Rexception("RlinkCommandList::SetLastExpect()",
277 19 wfjm
                     "Bad state: list empty");
278 30 wfjm
  fList.back()->SetExpect(pexp);
279 10 wfjm
  return;
280
}
281
 
282
//------------------------------------------+-----------------------------------
283
//! FIXME_docs
284
 
285
void RlinkCommandList::Clear()
286
{
287 27 wfjm
  foreach_ (RlinkCommand* pcmd, fList) { delete pcmd; }
288 10 wfjm
  fList.clear();
289 27 wfjm
  fLaboIndex = -1;
290 10 wfjm
  return;
291
}
292
 
293
//------------------------------------------+-----------------------------------
294
//! FIXME_docs
295
 
296 30 wfjm
void RlinkCommandList::Print(std::ostream& os,
297 19 wfjm
                             const RlinkAddrMap* pamap, size_t abase,
298
                             size_t dbase, size_t sbase) const
299 10 wfjm
{
300 19 wfjm
  foreach_ (RlinkCommand* pcmd, fList) {
301 30 wfjm
    pcmd->Print(os, pamap, abase, dbase, sbase);
302 10 wfjm
  }
303
  return;
304
}
305
 
306
//------------------------------------------+-----------------------------------
307
//! FIXME_docs
308
 
309
void RlinkCommandList::Dump(std::ostream& os, int ind, const char* text) const
310
{
311
  RosFill bl(ind);
312
  os << bl << (text?text:"--") << "RlinkCommandList @ " << this << endl;
313
 
314 27 wfjm
  os << bl << "  fLaboIndex:      " << fLaboIndex << endl;
315 10 wfjm
  for (size_t i=0; i<Size(); i++) {
316
    string pref("fList[");
317
    pref << RosPrintf(i) << RosPrintf("]: ");
318
    fList[i]->Dump(os, ind+2, pref.c_str());
319
  }
320
 
321
  return;
322
}
323
 
324
//------------------------------------------+-----------------------------------
325
//! FIXME_docs
326
 
327
RlinkCommandList&
328
  Retro::RlinkCommandList::operator=( const RlinkCommandList& rhs)
329
{
330
  if (&rhs == this) return *this;
331 12 wfjm
 
332 19 wfjm
  foreach_ (RlinkCommand* pcmd, fList) { delete pcmd; }
333 10 wfjm
  fList.clear();
334
  for (size_t i=0; i<rhs.Size(); i++) AddCommand(rhs[i]);
335
  return *this;
336
}
337
 
338
//------------------------------------------+-----------------------------------
339
//! FIXME_docs
340
 
341
Retro::RlinkCommand& Retro::RlinkCommandList::operator[](size_t ind)
342
{
343
  return *fList.at(ind);
344
}
345
 
346
//------------------------------------------+-----------------------------------
347
//! FIXME_docs
348
 
349
const Retro::RlinkCommand& Retro::RlinkCommandList::operator[](size_t ind) const
350
{
351
  return *fList.at(ind);
352
}
353
 
354 19 wfjm
} // end namespace Retro

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.