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

Subversion Repositories w11

[/] [w11/] [tags/] [w11a_V0.7/] [tools/] [src/] [librlink/] [RlinkConnect.hpp] - Blame information for rev 28

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

Line No. Rev Author Line
1 28 wfjm
// $Id: RlinkConnect.hpp 626 2015-01-03 14:41:37Z mueller $
2 10 wfjm
//
3 28 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 28 wfjm
// 2015-01-01   626   2.1    full rlink v4 implementation
17
// 2014-12-25   621   2.0.2  Reorganize packet send/revd stats
18
// 2014-12-20   616   2.0.1  add BlockDone expect checks
19 27 wfjm
// 2014-12-10   611   2.0    re-organize for rlink v4
20 20 wfjm
// 2013-04-21   509   1.3.3  add SndAttn() method
21 19 wfjm
// 2013-03-05   495   1.3.2  add Exec() without emsg (will send emsg to LogFile)
22
// 2013-03-01   493   1.3.1  add Server(Active..|SignalAttn)() methods
23
// 2013-02-23   492   1.3    use scoped_ptr for Port; Close allways allowed
24
//                           use RlinkContext, add Context(), Exec(..., cntx)
25
// 2013-02-22   491   1.2    use new RlogFile/RlogMsg interfaces
26
// 2013-02-03   481   1.1.3  add SetServer(),Server()
27
// 2013-01-13   474   1.1.2  add PollAttn() method
28 15 wfjm
// 2011-11-28   434   1.1.1  struct LogOpts: use uint32_t for lp64 compatibility
29 12 wfjm
// 2011-04-24   380   1.1    use boost::noncopyable (instead of private dcl's);
30
//                           use boost::(mutex&lock), implement Lockable IF
31
// 2011-04-22   379   1.0.1  add Lock(), Unlock()
32 10 wfjm
// 2011-04-02   375   1.0    Initial version
33
// 2011-01-15   356   0.1    First draft
34
// ---------------------------------------------------------------------------
35
 
36
/*!
37
  \file
38 28 wfjm
  \version $Id: RlinkConnect.hpp 626 2015-01-03 14:41:37Z mueller $
39 10 wfjm
  \brief   Declaration of class \c RlinkConnect.
40
*/
41
 
42
#ifndef included_Retro_RlinkConnect
43
#define included_Retro_RlinkConnect 1
44
 
45
#include <cstdint>
46
#include <string>
47
#include <vector>
48
#include <ostream>
49
 
50 12 wfjm
#include "boost/utility.hpp"
51
#include "boost/thread/recursive_mutex.hpp"
52 19 wfjm
#include "boost/shared_ptr.hpp"
53
#include "boost/scoped_ptr.hpp"
54 12 wfjm
 
55 10 wfjm
#include "librtools/RerrMsg.hpp"
56
#include "librtools/Rstats.hpp"
57
#include "librtools/RlogFile.hpp"
58
 
59
#include "RlinkPort.hpp"
60
#include "RlinkCommandList.hpp"
61 27 wfjm
#include "RlinkPacketBufSnd.hpp"
62
#include "RlinkPacketBufRcv.hpp"
63 10 wfjm
#include "RlinkAddrMap.hpp"
64 19 wfjm
#include "RlinkContext.hpp"
65 10 wfjm
 
66 27 wfjm
#include "librtools/Rbits.hpp"
67
 
68 10 wfjm
namespace Retro {
69
 
70 19 wfjm
  class RlinkServer;                        // forw decl to avoid circular incl
71
 
72 27 wfjm
  class RlinkConnect : public Rbits, private boost::noncopyable {
73 10 wfjm
    public:
74
      struct LogOpts {
75 15 wfjm
        uint32_t      baseaddr;
76
        uint32_t      basedata;
77
        uint32_t      basestat;
78
        uint32_t      printlevel;           // 0=off,1=err,2=chk,3=all
79
        uint32_t      dumplevel;            // 0=off,1=err,2=chk,3=all
80
        uint32_t      tracelevel;           // 0=off,1=buf,2=char
81 10 wfjm
 
82
                      LogOpts()
83
                        : baseaddr(16), basedata(16), basestat(16),
84
                          printlevel(0), dumplevel(0), tracelevel(0)
85
                      {}
86
      };
87
 
88
                    RlinkConnect();
89 19 wfjm
                   ~RlinkConnect();
90 10 wfjm
 
91
      bool          Open(const std::string& name, RerrMsg& emsg);
92
      void          Close();
93
      bool          IsOpen() const;
94
      RlinkPort*    Port() const;
95
 
96 19 wfjm
      RlinkContext& Context();
97
 
98
      void          SetServer(RlinkServer* pserv);
99
      RlinkServer*  Server() const;
100
      bool          ServerActive() const;
101
      bool          ServerActiveInside() const;
102
      bool          ServerActiveOutside() const;
103
 
104 12 wfjm
      // provide boost Lockable interface
105
      void          lock();
106
      bool          try_lock();
107
      void          unlock();
108
 
109 10 wfjm
      bool          Exec(RlinkCommandList& clist, RerrMsg& emsg);
110 19 wfjm
      bool          Exec(RlinkCommandList& clist, RlinkContext& cntx,
111
                         RerrMsg& emsg);
112
      bool          Exec(RlinkCommandList& clist);
113
      bool          Exec(RlinkCommandList& clist, RlinkContext& cntx);
114 10 wfjm
 
115 27 wfjm
      double        WaitAttn(double timeout, uint16_t& apat, RerrMsg& emsg);
116 10 wfjm
      bool          SndOob(uint16_t addr, uint16_t data, RerrMsg& emsg);
117 20 wfjm
      bool          SndAttn(RerrMsg& emsg);
118 10 wfjm
 
119 28 wfjm
      uint32_t      SysId() const;
120
      size_t        RbufSize() const;
121
      size_t        BlockSizeMax() const;
122
      size_t        BlockSizePrudent() const;
123
 
124 10 wfjm
      bool          AddrMapInsert(const std::string& name, uint16_t addr);
125
      bool          AddrMapErase(const std::string& name);
126
      bool          AddrMapErase(uint16_t addr);
127
      void          AddrMapClear();
128 28 wfjm
      const RlinkAddrMap& AddrMap() const;
129 10 wfjm
 
130
      const Rstats& Stats() const;
131 27 wfjm
      const Rstats& SndStats() const;
132
      const Rstats& RcvStats() const;
133 10 wfjm
 
134
      void          SetLogOpts(const LogOpts& opts);
135
      const LogOpts&  GetLogOpts() const;
136 19 wfjm
 
137
      bool          LogOpen(const std::string& name);
138
      void          LogUseStream(std::ostream* pstr,
139
                                 const std::string& name = "");
140 10 wfjm
      RlogFile&     LogFile() const;
141 19 wfjm
      const boost::shared_ptr<RlogFile>&   LogFileSPtr() const;
142 10 wfjm
 
143
      void          Print(std::ostream& os) const;
144
      void          Dump(std::ostream& os, int ind=0, const char* text=0) const;
145
 
146 27 wfjm
      void          HandleUnsolicitedData();
147
 
148
    // some constants (also defined in cpp)
149
      static const uint16_t kRbaddr_RLCNTL = 0xffff; //!< rlink core reg RLCNTL
150
      static const uint16_t kRbaddr_RLSTAT = 0xfffe; //!< rlink core reg RLSTAT
151
      static const uint16_t kRbaddr_RLID1  = 0xfffd; //!< rlink core reg RLID1
152
      static const uint16_t kRbaddr_RLID0  = 0xfffc; //!< rlink core reg RLID0
153
 
154
      static const uint16_t kRLCNTL_M_AnEna = kWBit15;//!< RLCNTL: an  enable
155
      static const uint16_t kRLCNTL_M_AtoEna= kWBit14;//!< RLCNTL: ato enable
156
      static const uint16_t kRLCNTL_M_AtoVal= 0x00ff; //!< RLCNTL: ato value
157
 
158
      static const uint16_t kRLSTAT_V_LCmd  =  8;     //!< RLSTAT: lcmd
159
      static const uint16_t kRLSTAT_B_LCmd  = 0x00ff; //!< RLSTAT: lcmd
160
      static const uint16_t kRLSTAT_M_BAbo  = kWBit07;//!< RLSTAT: babo
161
      static const uint16_t kRLSTAT_M_RBSize= 0x0007; //!< RLSTAT: rbuf size
162
 
163
      static const uint16_t kSBCNTL_V_RLMON = 15; //!< SBCNTL: rlmon enable bit
164
      static const uint16_t kSBCNTL_V_RLBMON= 14; //!< SBCNTL: rlbmon enable bit
165
      static const uint16_t kSBCNTL_V_RBMON = 13; //!< SBCNTL: rbmon enable bit
166
 
167 28 wfjm
      // space beyond data for rblk =  8 :cmd(1) cnt(2) dcnt(2) stat(1) crc(2)
168
      //                   and wblk =  3 :cmd(1) cnt(2)
169
      static const uint16_t kRbufBlkDelta=16; //!< rbuf needed for rblk or wblk
170
      // 512 byte are enough space for a prudent amount of non-blk commands
171
      static const uint16_t kRbufPrudentDelta=512; //!< Rbuf space reserve
172
 
173 10 wfjm
    // statistics counter indices
174
      enum stats {
175 27 wfjm
        kStatNExec = 0,                     //!< Exec() calls
176
        kStatNExecPart,                     //!< ExecPart() calls
177
        kStatNCmd,                          //!< commands executed
178
        kStatNRreg,                         //!< rreg commands
179
        kStatNRblk,                         //!< rblk commands
180
        kStatNWreg,                         //!< wreg commands
181
        kStatNWblk,                         //!< wblk commands
182
        kStatNLabo,                         //!< labo commands
183
        kStatNAttn,                         //!< attn commands
184
        kStatNInit,                         //!< init commands
185
        kStatNRblkWord,                     //!< words rcvd with rblk
186
        kStatNWblkWord,                     //!< words send with wblk
187
        kStatNExpData,                      //!< Expect() for data defined
188 28 wfjm
        kStatNExpDone,                      //!< Expect() for done defined
189
        kStatNExpStat,                      //!< Expect() for stat defined
190 27 wfjm
        kStatNChkData,                      //!< expect data failed
191 28 wfjm
        kStatNChkDone,                      //!< expect done failed
192 27 wfjm
        kStatNChkStat,                      //!< expect stat failed
193
        kStatNSndOob,                       //!< SndOob() calls
194
        kStatNErrMiss,                      //!< decode: missing data
195
        kStatNErrCmd,                       //!< decode: command mismatch
196
        kStatNErrLen,                       //!< decode: length mismatch
197
        kStatNErrCrc,                       //!< decode: crc mismatch
198 10 wfjm
        kDimStat
199
      };
200
 
201
    protected:
202 12 wfjm
      bool          ExecPart(RlinkCommandList& clist, size_t ibeg, size_t iend,
203 19 wfjm
                             RerrMsg& emsg, RlinkContext& cntx);
204 12 wfjm
 
205 27 wfjm
      void          EncodeRequest(RlinkCommandList& clist, size_t ibeg,
206
                                  size_t iend);
207
      int           DecodeResponse(RlinkCommandList& clist, size_t ibeg,
208
                                   size_t iend, RlinkContext& cntx);
209
      bool          DecodeAttnNotify(uint16_t& apat);
210
      bool          ReadResponse(double timeout, RerrMsg& emsg);
211
      void          AcceptResponse();
212
      void          ProcessUnsolicitedData();
213
      void          ProcessAttnNotify();
214
 
215 12 wfjm
    protected:
216 19 wfjm
      boost::scoped_ptr<RlinkPort> fpPort;  //!< ptr to port
217
      RlinkServer*  fpServ;                 //!< ptr to server (optional)
218 10 wfjm
      uint8_t       fSeqNumber[8];          //!< command sequence number
219 27 wfjm
      RlinkPacketBufSnd fSndPkt;            //!< send    packet buffer
220
      RlinkPacketBufRcv fRcvPkt;            //!< receive packet buffer
221 19 wfjm
      RlinkContext  fContext;               //!< default context
222 10 wfjm
      RlinkAddrMap  fAddrMap;               //!< name<->address mapping
223
      Rstats        fStats;                 //!< statistics
224
      LogOpts       fLogOpts;               //!< log options
225 19 wfjm
      boost::shared_ptr<RlogFile> fspLog;   //!< log file ptr
226
      boost::recursive_mutex fConnectMutex; //!< mutex to lock whole connect
227 27 wfjm
      uint16_t      fAttnNotiPatt;          //!< attn notifier pattern
228
      double        fTsLastAttnNoti;        //!< time stamp last attn notify
229 28 wfjm
      uint32_t      fSysId;                 //!< SYSID of connected device
230
      size_t        fRbufSize;              //!< Rbuf size (in bytes)
231 10 wfjm
  };
232
 
233
} // end namespace Retro
234
 
235
#include "RlinkConnect.ipp"
236
 
237
#endif

powered by: WebSVN 2.1.0

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