w11 - cpp 0.794
Backend server for Rlink and w11
Loading...
Searching...
No Matches
RlinkCommand.hpp
Go to the documentation of this file.
1// $Id: RlinkCommand.hpp 1185 2019-07-12 17:29:12Z mueller $
2// SPDX-License-Identifier: GPL-3.0-or-later
3// Copyright 2011-2019 by Walter F.J. Mueller <W.F.J.Mueller@gsi.de>
4//
5// Revision History:
6// Date Rev Version Comment
7// 2019-03-10 1121 1.4.3 add BlockDoneAll()
8// 2018-12-24 1092 1.4.2 rename IsBlockExt -> HasBlockExt
9// 2018-12-23 1091 1.4.1 CmdWblk(),SetBlockWrite(): add move version
10// 2018-12-01 1076 1.4 use unique_ptr
11// 2017-04-07 868 1.3.2 Dump(): add detail arg
12// 2017-03-11 859 1.3.1 add CommandInfo()
13// 2015-04-02 661 1.3 expect logic: add stat check, Print() without cntx
14// 2014-12-21 617 1.2.2 use kStat_M_RbTout for rbus timeout
15// 2014-12-20 616 1.2.1 add kFlagChkDone
16// 2014-12-06 609 1.2 new rlink v4 iface
17// 2013-05-06 495 1.0.1 add RlinkContext to Print() args; drop oper<<()
18// 2011-03-27 374 1.0 Initial version
19// 2011-01-09 354 0.1 First draft
20// ---------------------------------------------------------------------------
21
22
27#ifndef included_Retro_RlinkCommand
28#define included_Retro_RlinkCommand 1
29
30#include <cstddef>
31#include <cstdint>
32#include <string>
33#include <vector>
34#include <ostream>
35#include <memory>
36
37#include "librtools/Rtools.hpp"
38
39#include "RlinkContext.hpp"
40#include "RlinkAddrMap.hpp"
42
43#include "librtools/Rbits.hpp"
44
45namespace Retro {
46
47 class RlinkCommand : public Rbits {
48 public:
49 typedef std::unique_ptr<RlinkCommandExpect> exp_uptr_t;
50
52 RlinkCommand(const RlinkCommand& rhs);
54
55 void CmdRreg(uint16_t addr);
56 void CmdRblk(uint16_t addr, size_t size);
57 void CmdRblk(uint16_t addr, uint16_t* pblock, size_t size);
58 void CmdWreg(uint16_t addr, uint16_t data);
59 void CmdWblk(uint16_t addr, const std::vector<uint16_t>& block);
60 void CmdWblk(uint16_t addr, std::vector<uint16_t>&& block);
61 void CmdWblk(uint16_t addr, const uint16_t* pblock, size_t size);
62 void CmdLabo();
63 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 SetBlockWrite(std::vector<uint16_t>&& block);
72 void SetBlockRead(size_t size) ;
73 void SetBlockExt(uint16_t* pblock, size_t size);
74 void SetBlockDone(uint16_t dcnt);
75 void SetStatus(uint8_t stat);
76 void SetFlagBit(uint32_t mask);
77 void ClearFlagBit(uint32_t mask);
78 void SetRcvSize(size_t rsize);
79
80 void SetExpect(exp_uptr_t&& upexp);
82 void SetExpectStatus(uint8_t stat, uint8_t statmsk=0xff);
83 void SetExpectStatusDefault(uint8_t stat=0, uint8_t statmsk=0x0);
84
85 uint8_t Request() const;
86 uint8_t Command() const;
87 uint8_t SeqNumber() const;
88 uint16_t Address() const;
89 uint16_t Data() const;
90 const std::vector<uint16_t>& Block() const;
91 bool HasBlockExt() const;
92 uint16_t* BlockPointer();
93 const uint16_t* BlockPointer() const;
94 size_t BlockSize() const;
95 size_t BlockDone() const;
96 bool BlockDoneAll() const;
97 uint8_t Status() const;
98 uint32_t Flags() const;
99 bool TestFlagAny(uint32_t mask) const;
100 bool TestFlagAll(uint32_t mask) const;
101 size_t RcvSize() const;
102
103 bool HasExpect() const;
104 const RlinkCommandExpect& Expect() const;
105 uint8_t ExpectStatusValue() const;
106 uint8_t ExpectStatusMask() const;
107 bool ExpectStatusSet() const;
108 bool StatusCheck() const;
109 bool StatusIsChecked() const;
110
111 void Print(std::ostream& os, const RlinkAddrMap* pamap=0,
112 size_t abase=16, size_t dbase=16,
113 size_t sbase=16) const;
114 std::string CommandInfo() const;
115 void Dump(std::ostream& os, int ind=0, const char* text=0,
116 int detail=0) const;
117
118 static const char* CommandName(uint8_t cmd);
119 static const RflagName* FlagNames();
120
122
123 // some constants (also defined in cpp)
124 static const uint8_t kCmdRreg = 0;
125 static const uint8_t kCmdRblk = 1;
126 static const uint8_t kCmdWreg = 2;
127 static const uint8_t kCmdWblk = 3;
128 static const uint8_t kCmdLabo = 4;
129 static const uint8_t kCmdAttn = 5;
130 static const uint8_t kCmdInit = 6;
131
132 static const uint32_t kFlagInit = 1u<<0;
133 static const uint32_t kFlagSend = 1u<<1;
134 static const uint32_t kFlagDone = 1u<<2;
135 static const uint32_t kFlagLabo = 1u<<3;
136
137 static const uint32_t kFlagPktBeg = 1u<<4;
138 static const uint32_t kFlagPktEnd = 1u<<5;
139
140 static const uint32_t kFlagErrNak = 1u<<8;
141 static const uint32_t kFlagErrDec = 1u<<9;
142
143 static const uint32_t kFlagChkStat= 1u<<12;
144 static const uint32_t kFlagChkData= 1u<<13;
145 static const uint32_t kFlagChkDone= 1u<<14;
146
147 static const uint8_t kStat_M_Stat = 0xf0;
148 static const uint8_t kStat_V_Stat = 4;
149 static const uint8_t kStat_B_Stat = 0x0f;
150 static const uint8_t kStat_M_Attn = kBBit03;
151 static const uint8_t kStat_M_RbTout = kBBit02;
152 static const uint8_t kStat_M_RbNak = kBBit01;
153 static const uint8_t kStat_M_RbErr = kBBit00;
154
155 protected:
156 void SetCmdSimple(uint8_t cmd, uint16_t addr, uint16_t data);
157
158 protected:
159 uint8_t fRequest;
160 uint16_t fAddress;
161 uint16_t fData;
162 std::vector<uint16_t> fBlock;
163 uint16_t* fpBlockExt;
165 size_t fBlockDone;
166 uint8_t fStatus;
167 uint32_t fFlags;
168 size_t fRcvSize;
173 };
174
175} // end namespace Retro
176
177#include "RlinkCommand.ipp"
178
179#endif
static const uint8_t kBBit01
Definition: Rbits.hpp:24
static const uint8_t kBBit00
Definition: Rbits.hpp:23
static const uint8_t kBBit02
Definition: Rbits.hpp:25
static const uint8_t kBBit03
Definition: Rbits.hpp:26
void SetStatus(uint8_t stat)
FIXME_docs.
void SetCommand(uint8_t cmd, uint16_t addr=0, uint16_t data=0)
FIXME_docs.
void SetExpect(exp_uptr_t &&upexp)
FIXME_docs.
static const uint8_t kStat_B_Stat
RlinkCommand()
Default constructor.
static const uint32_t kFlagPktEnd
command last in packet
static const uint8_t kCmdInit
command code send initialize
uint8_t fExpectStatusVal
status value
void SetBlockExt(uint16_t *pblock, size_t size)
FIXME_docs.
void SetFlagBit(uint32_t mask)
FIXME_docs.
void SetCmdSimple(uint8_t cmd, uint16_t addr, uint16_t data)
static const uint32_t kFlagSend
command send
uint16_t Data() const
FIXME_docs.
void SetRcvSize(size_t rsize)
FIXME_docs.
~RlinkCommand()
Destructor.
uint8_t Request() const
FIXME_docs.
static const uint8_t kCmdRblk
command code read block
uint8_t fExpectStatusMsk
status mask
bool BlockDoneAll() const
FIXME_docs.
void SetExpectStatusDefault(uint8_t stat=0, uint8_t statmsk=0x0)
FIXME_docs.
void SetBlockRead(size_t size)
FIXME_docs.
static const uint32_t kFlagChkStat
stat expect check failed
uint8_t fStatus
rlink command status
size_t fBlockDone
valid transfer count
uint16_t Address() const
FIXME_docs.
uint8_t ExpectStatusMask() const
FIXME_docs.
size_t RcvSize() const
FIXME_docs.
bool TestFlagAny(uint32_t mask) const
FIXME_docs.
void CmdRreg(uint16_t addr)
FIXME_docs.
static const uint8_t kStat_M_RbErr
stat: rberr flag set
uint8_t SeqNumber() const
FIXME_docs.
void CmdAttn()
FIXME_docs.
uint8_t Status() const
FIXME_docs.
static const char * CommandName(uint8_t cmd)
FIXME_docs.
size_t fBlockExtSize
transfer size if data external
void CmdWreg(uint16_t addr, uint16_t data)
FIXME_docs.
const std::vector< uint16_t > & Block() const
FIXME_docs.
void CmdRblk(uint16_t addr, size_t size)
FIXME_docs.
bool ExpectStatusSet() const
FIXME_docs.
void Dump(std::ostream &os, int ind=0, const char *text=0, int detail=0) const
FIXME_docs.
uint8_t fRequest
rlink request (cmd+seqnum)
bool StatusIsChecked() const
FIXME_docs.
bool fExpectStatusSet
stat chk set explicitely
void Print(std::ostream &os, const RlinkAddrMap *pamap=0, size_t abase=16, size_t dbase=16, size_t sbase=16) const
FIXME_docs.
bool StatusCheck() const
FIXME_docs.
static const uint32_t kFlagErrNak
error: nak abort
static const uint8_t kStat_M_RbNak
stat: rbnak flag set
uint8_t ExpectStatusValue() const
FIXME_docs.
bool TestFlagAll(uint32_t mask) const
FIXME_docs.
uint16_t fAddress
rbus address
void CmdLabo()
FIXME_docs.
static const uint8_t kStat_M_Attn
stat: attn flag set
static const uint8_t kStat_M_RbTout
stat: rbtout flag set
static const uint32_t kFlagDone
command done
RlinkCommand & operator=(const RlinkCommand &rhs)
FIXME_docs.
static const uint32_t kFlagLabo
command labo'ed
void SetData(uint16_t data)
FIXME_docs.
uint8_t Command() const
FIXME_docs.
uint16_t * fpBlockExt
external data for blk commands
size_t BlockSize() const
FIXME_docs.
static const uint8_t kCmdRreg
command code read register
static const uint32_t kFlagChkDone
done expect check failed
std::vector< uint16_t > fBlock
data vector for blk commands
static const uint8_t kStat_V_Stat
uint32_t Flags() const
FIXME_docs.
static const uint8_t kCmdWreg
command code write register
static const uint32_t kFlagPktBeg
command first in packet
void CmdWblk(uint16_t addr, const std::vector< uint16_t > &block)
FIXME_docs.
void SetSeqNumber(uint8_t snum)
FIXME_docs.
void SetAddress(uint16_t addr)
FIXME_docs.
static const RflagName * FlagNames()
FIXME_docs.
bool HasBlockExt() const
FIXME_docs.
size_t BlockDone() const
FIXME_docs.
static const uint32_t kFlagErrDec
error: decode error
void SetExpectStatus(uint8_t stat, uint8_t statmsk=0xff)
FIXME_docs.
bool HasExpect() const
FIXME_docs.
exp_uptr_t fupExpect
pointer to expect container
void SetBlockDone(uint16_t dcnt)
FIXME_docs.
size_t fRcvSize
receive size for command
static const uint8_t kStat_M_Stat
stat: external stat bits
void CmdInit(uint16_t addr, uint16_t data)
FIXME_docs.
static const uint32_t kFlagChkData
data expect check failed
static const uint8_t kCmdAttn
command code get attention
std::unique_ptr< RlinkCommandExpect > exp_uptr_t
static const uint8_t kCmdLabo
command code list abort
const RlinkCommandExpect & Expect() const
FIXME_docs.
void SetBlockWrite(const std::vector< uint16_t > &block)
FIXME_docs.
std::string CommandInfo() const
FIXME_docs.
uint16_t * BlockPointer()
FIXME_docs.
RlinkCommandExpect & EnsureExpect()
FIXME_docs.
void ClearFlagBit(uint32_t mask)
FIXME_docs.
uint32_t fFlags
state bits
static const uint32_t kFlagInit
cmd,addr,data setup
static const uint8_t kCmdWblk
command code write block
Declaration of class ReventLoop.
Definition: ReventLoop.cpp:47