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

Subversion Repositories w11

[/] [w11/] [tags/] [w11a_V0.6/] [tools/] [src/] [librlink/] [RlinkPacketBuf.hpp] - Blame information for rev 40

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

Line No. Rev Author Line
1 20 wfjm
// $Id: RlinkPacketBuf.hpp 509 2013-04-21 20:46:20Z 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 20 wfjm
// 2013-04-21   509   1.0.2  add SndAttn() method
17 19 wfjm
// 2013-01-13   474   1.0.1  add PollAttn() method
18 10 wfjm
// 2011-04-02   375   1.0    Initial version
19
// 2011-03-05   366   0.1    First draft
20
// ---------------------------------------------------------------------------
21
 
22
 
23
/*!
24
  \file
25 20 wfjm
  \version $Id: RlinkPacketBuf.hpp 509 2013-04-21 20:46:20Z mueller $
26 10 wfjm
  \brief   Declaration of class RlinkPacketBuf.
27
*/
28
 
29
#ifndef included_Retro_RlinkPacketBuf
30
#define included_Retro_RlinkPacketBuf 1
31
 
32
#include <cstdint>
33
#include <vector>
34
 
35
#include "RlinkPort.hpp"
36
#include "RlinkCrc8.hpp"
37
 
38
namespace Retro {
39
 
40
  class RlinkPacketBuf {
41
    public:
42
 
43
                    RlinkPacketBuf();
44
                    ~RlinkPacketBuf();
45
 
46
      void          Init();
47
 
48
      void          PutWithCrc(uint8_t data);
49
      void          PutWithCrc(uint16_t data);
50
      void          PutCrc();
51
 
52
      bool          SndPacket(RlinkPort* port, RerrMsg& emsg);
53
      bool          RcvPacket(RlinkPort* port, size_t nrcv, float timeout,
54
                              RerrMsg& emsg);
55
 
56
      double        WaitAttn(RlinkPort* port, double timeout, RerrMsg& emsg);
57 19 wfjm
      int           PollAttn(RlinkPort* port, RerrMsg& emsg);
58 10 wfjm
      bool          SndOob(RlinkPort* port, uint16_t addr, uint16_t data,
59
                           RerrMsg& emsg);
60
      bool          SndKeep(RlinkPort* port, RerrMsg& emsg);
61 20 wfjm
      bool          SndAttn(RlinkPort* port, RerrMsg& emsg);
62 10 wfjm
 
63
      bool          CheckSize(size_t nbyte) const;
64
      uint8_t       Get8WithCrc();
65
      uint16_t      Get16WithCrc();
66
      bool          CheckCrc();
67
 
68
      size_t        PktSize() const;
69
      size_t        RawSize() const;
70
 
71
      uint32_t      Flags() const;
72
      bool          TestFlag(uint32_t mask) const;
73
      size_t        Nesc() const;
74
      size_t        Nattn() const;
75
      size_t        Nidle() const;
76
      size_t        Ndrop() const;
77
 
78
      void          Dump(std::ostream& os, int ind=0, const char* text=0) const;
79
 
80 19 wfjm
    // flag bits (also defined in cpp)
81 10 wfjm
      static const uint32_t kFlagSopSeen  = 1<<0;  //!< sop was seen
82
      static const uint32_t kFlagEopSeen  = 1<<1;  //!< eop was seen
83
      static const uint32_t kFlagNakSeen  = 1<<2;  //!< nak was seen
84
      static const uint32_t kFlagAttnSeen = 1<<3;  //!< attn was seen
85
      static const uint32_t kFlagTout     = 1<<16; //!< timeout on read
86
      static const uint32_t kFlagDatDrop  = 1<<17; //!< data before sop dropped
87
      static const uint32_t kFlagDatMiss  = 1<<18; //!< eop before expected data
88
 
89 19 wfjm
    // some constants (also defined in cpp)
90 10 wfjm
      static const uint8_t kCPREF = 0x80;   //!< VHDL def for comma prefix
91
      static const uint8_t kNCOMM = 0x04;   //!< VHDL def for number of commas
92
      static const uint8_t kCommaIdle = kCPREF+0; //!< IDLE comma
93
      static const uint8_t kCommaSop  = kCPREF+1; //!< SOP comma
94
      static const uint8_t kCommaEop  = kCPREF+2; //!< EOP comma
95
      static const uint8_t kCommaNak  = kCPREF+3; //!< NAK comma
96
      static const uint8_t kCommaAttn = kCPREF+4; //!< ATTN comma
97
      static const uint8_t kSymEsc    = kCPREF+0x0f;  //!< ESC symbol
98
 
99
    protected:
100
      bool          SndRaw(RlinkPort* port, RerrMsg& emsg);
101
      int           RcvRaw(RlinkPort* port, size_t size, float timeout,
102
                           RerrMsg& emsg);
103
 
104
      void          SetFlagBit(uint32_t mask);
105
      void          ClearFlagBit(uint32_t mask);
106
 
107
    protected:
108
      std::vector<uint8_t> fPktBuf;         //!< packet buffer
109
      std::vector<uint8_t> fRawBuf;         //!< raw data buffer
110
      size_t        fRawBufSize;            //!< # of valid bytes in RawBuf
111
      RlinkCrc8     fCrc;                   //!< crc accumulator
112
      uint32_t      fFlags;                 //!< request/response flags
113
      size_t        fNdone;                 //!< number of input bytes processed
114
      size_t        fNesc;                  //!< number of escapes handled
115
      size_t        fNattn;                 //!< number of ATTN commas seen
116
      size_t        fNidle;                 //!< number of IDLE commas seen
117
      size_t        fNdrop;                 //!< number of dropped input bytes
118
  };
119
 
120
} // end namespace Retro
121
 
122
#include "RlinkPacketBuf.ipp"
123
 
124
#endif

powered by: WebSVN 2.1.0

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