1 |
30 |
wfjm |
// $Id: RlinkCommand.hpp 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 stat check, Print() without cntx
|
17 |
28 |
wfjm |
// 2014-12-21 617 1.2.2 use kStat_M_RbTout for rbus timeout
|
18 |
|
|
// 2014-12-20 616 1.2.1 add kFlagChkDone
|
19 |
27 |
wfjm |
// 2014-12-06 609 1.2 new rlink v4 iface
|
20 |
19 |
wfjm |
// 2013-05-06 495 1.0.1 add RlinkContext to Print() args; drop oper<<()
|
21 |
10 |
wfjm |
// 2011-03-27 374 1.0 Initial version
|
22 |
|
|
// 2011-01-09 354 0.1 First draft
|
23 |
|
|
// ---------------------------------------------------------------------------
|
24 |
|
|
|
25 |
|
|
|
26 |
|
|
/*!
|
27 |
|
|
\file
|
28 |
30 |
wfjm |
\version $Id: RlinkCommand.hpp 661 2015-04-03 18:28:41Z mueller $
|
29 |
10 |
wfjm |
\brief Declaration of class RlinkCommand.
|
30 |
|
|
*/
|
31 |
|
|
|
32 |
|
|
#ifndef included_Retro_RlinkCommand
|
33 |
|
|
#define included_Retro_RlinkCommand 1
|
34 |
|
|
|
35 |
|
|
#include <cstddef>
|
36 |
|
|
#include <cstdint>
|
37 |
|
|
#include <vector>
|
38 |
|
|
#include <ostream>
|
39 |
|
|
|
40 |
|
|
#include "librtools/Rtools.hpp"
|
41 |
|
|
|
42 |
19 |
wfjm |
#include "RlinkContext.hpp"
|
43 |
|
|
#include "RlinkAddrMap.hpp"
|
44 |
|
|
#include "RlinkCommandExpect.hpp"
|
45 |
|
|
|
46 |
|
|
#include "librtools/Rbits.hpp"
|
47 |
|
|
|
48 |
10 |
wfjm |
namespace Retro {
|
49 |
|
|
|
50 |
19 |
wfjm |
class RlinkCommand : public Rbits {
|
51 |
10 |
wfjm |
public:
|
52 |
|
|
RlinkCommand();
|
53 |
|
|
RlinkCommand(const RlinkCommand& rhs);
|
54 |
27 |
wfjm |
~RlinkCommand();
|
55 |
10 |
wfjm |
|
56 |
|
|
void CmdRreg(uint16_t addr);
|
57 |
|
|
void CmdRblk(uint16_t addr, size_t size);
|
58 |
|
|
void CmdRblk(uint16_t addr, uint16_t* pblock, size_t size);
|
59 |
|
|
void CmdWreg(uint16_t addr, uint16_t data);
|
60 |
|
|
void CmdWblk(uint16_t addr, const std::vector<uint16_t>& block);
|
61 |
|
|
void CmdWblk(uint16_t addr, const uint16_t* pblock, size_t size);
|
62 |
27 |
wfjm |
void CmdLabo();
|
63 |
10 |
wfjm |
void CmdAttn();
|
64 |
|
|
void CmdInit(uint16_t addr, uint16_t data);
|
65 |
|
|
|
66 |
|
|
void SetCommand(uint8_t cmd, uint16_t addr=0, uint16_t data=0);
|
67 |
|
|
void SetSeqNumber(uint8_t snum);
|
68 |
|
|
void SetAddress(uint16_t addr);
|
69 |
|
|
void SetData(uint16_t data);
|
70 |
|
|
void SetBlockWrite(const std::vector<uint16_t>& block);
|
71 |
|
|
void SetBlockRead(size_t size) ;
|
72 |
|
|
void SetBlockExt(uint16_t* pblock, size_t size);
|
73 |
27 |
wfjm |
void SetBlockDone(uint16_t dcnt);
|
74 |
10 |
wfjm |
void SetStatus(uint8_t stat);
|
75 |
|
|
void SetFlagBit(uint32_t mask);
|
76 |
|
|
void ClearFlagBit(uint32_t mask);
|
77 |
|
|
void SetRcvSize(size_t rsize);
|
78 |
30 |
wfjm |
|
79 |
10 |
wfjm |
void SetExpect(RlinkCommandExpect* pexp);
|
80 |
30 |
wfjm |
void SetExpectStatus(uint8_t stat, uint8_t statmsk=0xff);
|
81 |
|
|
void SetExpectStatusDefault(uint8_t stat=0, uint8_t statmsk=0x0);
|
82 |
10 |
wfjm |
|
83 |
|
|
uint8_t Request() const;
|
84 |
|
|
uint8_t Command() const;
|
85 |
|
|
uint8_t SeqNumber() const;
|
86 |
|
|
uint16_t Address() const;
|
87 |
|
|
uint16_t Data() const;
|
88 |
|
|
const std::vector<uint16_t>& Block() const;
|
89 |
|
|
bool IsBlockExt() const;
|
90 |
|
|
uint16_t* BlockPointer();
|
91 |
|
|
const uint16_t* BlockPointer() const;
|
92 |
|
|
size_t BlockSize() const;
|
93 |
27 |
wfjm |
size_t BlockDone() const;
|
94 |
10 |
wfjm |
uint8_t Status() const;
|
95 |
|
|
uint32_t Flags() const;
|
96 |
|
|
bool TestFlagAny(uint32_t mask) const;
|
97 |
|
|
bool TestFlagAll(uint32_t mask) const;
|
98 |
|
|
size_t RcvSize() const;
|
99 |
30 |
wfjm |
|
100 |
10 |
wfjm |
RlinkCommandExpect* Expect() const;
|
101 |
30 |
wfjm |
uint8_t ExpectStatusValue() const;
|
102 |
|
|
uint8_t ExpectStatusMask() const;
|
103 |
|
|
bool ExpectStatusSet() const;
|
104 |
|
|
bool StatusCheck() const;
|
105 |
|
|
bool StatusIsChecked() const;
|
106 |
10 |
wfjm |
|
107 |
30 |
wfjm |
void Print(std::ostream& os, const RlinkAddrMap* pamap=0,
|
108 |
|
|
size_t abase=16, size_t dbase=16,
|
109 |
|
|
size_t sbase=16) const;
|
110 |
10 |
wfjm |
void Dump(std::ostream& os, int ind=0, const char* text=0) const;
|
111 |
|
|
|
112 |
|
|
static const char* CommandName(uint8_t cmd);
|
113 |
|
|
static const RflagName* FlagNames();
|
114 |
|
|
|
115 |
|
|
RlinkCommand& operator=(const RlinkCommand& rhs);
|
116 |
|
|
|
117 |
19 |
wfjm |
// some constants (also defined in cpp)
|
118 |
10 |
wfjm |
static const uint8_t kCmdRreg = 0; //!< command code read register
|
119 |
|
|
static const uint8_t kCmdRblk = 1; //!< command code read block
|
120 |
|
|
static const uint8_t kCmdWreg = 2; //!< command code write register
|
121 |
|
|
static const uint8_t kCmdWblk = 3; //!< command code write block
|
122 |
27 |
wfjm |
static const uint8_t kCmdLabo = 4; //!< command code list abort
|
123 |
10 |
wfjm |
static const uint8_t kCmdAttn = 5; //!< command code get attention
|
124 |
|
|
static const uint8_t kCmdInit = 6; //!< command code send initialize
|
125 |
|
|
|
126 |
|
|
static const uint32_t kFlagInit = 1u<<0; //!< cmd,addr,data setup
|
127 |
|
|
static const uint32_t kFlagSend = 1u<<1; //!< command send
|
128 |
|
|
static const uint32_t kFlagDone = 1u<<2; //!< command done
|
129 |
27 |
wfjm |
static const uint32_t kFlagLabo = 1u<<3; //!< command labo'ed
|
130 |
10 |
wfjm |
|
131 |
|
|
static const uint32_t kFlagPktBeg = 1u<<4; //!< command first in packet
|
132 |
|
|
static const uint32_t kFlagPktEnd = 1u<<5; //!< command last in packet
|
133 |
|
|
|
134 |
|
|
static const uint32_t kFlagErrNak = 1u<<8; //!< error: nak abort
|
135 |
27 |
wfjm |
static const uint32_t kFlagErrDec = 1u<<9; //!< error: decode error
|
136 |
10 |
wfjm |
|
137 |
|
|
static const uint32_t kFlagChkStat= 1u<<12; //!< stat expect check failed
|
138 |
|
|
static const uint32_t kFlagChkData= 1u<<13; //!< data expect check failed
|
139 |
28 |
wfjm |
static const uint32_t kFlagChkDone= 1u<<14; //!< done expect check failed
|
140 |
10 |
wfjm |
|
141 |
28 |
wfjm |
static const uint8_t kStat_M_Stat = 0xf0; //!< stat: external stat bits
|
142 |
|
|
static const uint8_t kStat_V_Stat = 4;
|
143 |
|
|
static const uint8_t kStat_B_Stat = 0x0f;
|
144 |
|
|
static const uint8_t kStat_M_Attn = kBBit03;//!< stat: attn flag set
|
145 |
|
|
static const uint8_t kStat_M_RbTout = kBBit02;//!< stat: rbtout flag set
|
146 |
|
|
static const uint8_t kStat_M_RbNak = kBBit01;//!< stat: rbnak flag set
|
147 |
|
|
static const uint8_t kStat_M_RbErr = kBBit00;//!< stat: rberr flag set
|
148 |
19 |
wfjm |
|
149 |
10 |
wfjm |
protected:
|
150 |
|
|
void SetCmdSimple(uint8_t cmd, uint16_t addr, uint16_t data);
|
151 |
|
|
|
152 |
|
|
protected:
|
153 |
|
|
uint8_t fRequest; //!< rlink request (cmd+seqnum)
|
154 |
|
|
uint16_t fAddress; //!< rbus address
|
155 |
|
|
uint16_t fData; //!< data
|
156 |
|
|
std::vector<uint16_t> fBlock; //!< data vector for blk commands
|
157 |
|
|
uint16_t* fpBlockExt; //!< external data for blk commands
|
158 |
|
|
size_t fBlockExtSize; //!< transfer size if data external
|
159 |
27 |
wfjm |
size_t fBlockDone; //!< valid transfer count
|
160 |
10 |
wfjm |
uint8_t fStatus; //!< rlink command status
|
161 |
|
|
uint32_t fFlags; //!< state bits
|
162 |
|
|
size_t fRcvSize; //!< receive size for command
|
163 |
30 |
wfjm |
bool fExpectStatusSet; //!< stat chk set explicitely
|
164 |
|
|
uint8_t fExpectStatusVal; //!< status value
|
165 |
|
|
uint8_t fExpectStatusMsk; //!< status mask
|
166 |
10 |
wfjm |
RlinkCommandExpect* fpExpect; //!< pointer to expect container
|
167 |
|
|
};
|
168 |
|
|
|
169 |
|
|
} // end namespace Retro
|
170 |
|
|
|
171 |
|
|
#include "RlinkCommand.ipp"
|
172 |
|
|
|
173 |
|
|
#endif
|