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