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 27

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

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

powered by: WebSVN 2.1.0

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