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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [orpsocv2/] [bench/] [sysc/] [src/] [RspPacket.cpp] - Blame information for rev 63

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

Line No. Rev Author Line
1 63 julius
// ----------------------------------------------------------------------------
2
 
3
// RSP packet: implementation
4
 
5
// Copyright (C) 2008  Embecosm Limited <info@embecosm.com>
6
 
7
// Contributor Jeremy Bennett <jeremy.bennett@embecosm.com>
8
 
9
// This file is part of the cycle accurate model of the OpenRISC 1000 based
10
// system-on-chip, ORPSoC, built using Verilator.
11
 
12
// This program is free software: you can redistribute it and/or modify it
13
// under the terms of the GNU Lesser General Public License as published by
14
// the Free Software Foundation, either version 3 of the License, or (at your
15
// option) any later version.
16
 
17
// This program is distributed in the hope that it will be useful, but WITHOUT
18
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
19
// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
20
// License for more details.
21
 
22
// You should have received a copy of the GNU Lesser General Public License
23
// along with this program.  If not, see <http://www.gnu.org/licenses/>.
24
 
25
// ----------------------------------------------------------------------------
26
 
27
// $Id: RspPacket.cpp 327 2009-03-07 19:10:56Z jeremy $
28
 
29
#include <iomanip>
30
#include <iostream>
31
#include <cstring>
32
#include <cerrno>
33
#include <cstdio>
34
 
35
#include "RspPacket.h"
36
#include "Utils.h"
37
 
38
 
39
using std::ostream;
40
using std::cerr;
41
using std::dec;
42
using std::endl;
43
using std::hex;
44
using std::setfill;
45
using std::setw;
46
 
47
 
48
//-----------------------------------------------------------------------------
49
//! Constructor
50
 
51
//! Allocate the new data buffer
52
 
53
//! @param[in]  _rspConnection  The RSP connection we will use
54
//! @param[in]  _bufSize        Size of data buffer to allocate
55
//-----------------------------------------------------------------------------
56
RspPacket::RspPacket (int  _bufSize) :
57
  bufSize (_bufSize)
58
{
59
  data = new char [_bufSize];
60
 
61
}       // RspPacket ();
62
 
63
 
64
//-----------------------------------------------------------------------------
65
//! Destructor
66
 
67
//! Give back the data buffer
68
//-----------------------------------------------------------------------------
69
RspPacket::~RspPacket ()
70
{
71
  delete [] data;
72
 
73
}       // ~RspPacket ()
74
 
75
 
76
//-----------------------------------------------------------------------------
77
//! Pack a string into a packet.
78
 
79
//! A convenience version of this method.
80
 
81
//! @param  str  The string to copy into the data packet before sending
82
//-----------------------------------------------------------------------------
83
void
84
RspPacket::packStr (const char *str)
85
{
86
  int  slen = strlen (str);
87
 
88
  // Construct the packet to send, so long as string is not too big, otherwise
89
  // truncate. Add EOS at the end for convenient debug printout
90
  if (slen >= bufSize)
91
    {
92
      cerr << "Warning: String \"" << str
93
                << "\" too large for RSP packet: truncated\n" << endl;
94
      slen = bufSize - 1;
95
    }
96
 
97
  strncpy (data, str, slen);
98
  data[slen] = 0;
99
  len        = slen;
100
 
101
}       // packStr ()
102
 
103
 
104
//-----------------------------------------------------------------------------
105
//! Get the data buffer size
106
 
107
//! @return  The data buffer size
108
//-----------------------------------------------------------------------------
109
int
110
RspPacket::getBufSize ()
111
{
112
  return  bufSize;
113
 
114
}       // getBufSize ()
115
 
116
 
117
//-----------------------------------------------------------------------------
118
//! Get the current number of chars in the data buffer
119
 
120
//! @return  The number of chars in the data buffer
121
//-----------------------------------------------------------------------------
122
int
123
RspPacket::getLen ()
124
{
125
  return  len;
126
 
127
}       // getLen ()
128
 
129
 
130
//-----------------------------------------------------------------------------
131
//! Set the number of chars in the data buffer
132
 
133
//! @param[in] _len  The number of chars to be set
134
//-----------------------------------------------------------------------------
135
void
136
RspPacket::setLen (int  _len)
137
{
138
  len = _len;
139
 
140
}       // setLen ()
141
 
142
 
143
//-----------------------------------------------------------------------------
144
//! Output stream operator
145
 
146
//! @param[out] s  Stream to output to
147
//! @param[in]  p  Packet to output
148
//-----------------------------------------------------------------------------
149
ostream &
150
operator<< (ostream   &s,
151
            RspPacket &p)
152
{
153
  return  s << "RSP packet: " << std::dec << std::setw (3) << p.getLen()
154
            << std::setw (0) << " chars, \"" << p.data << "\"";
155
 
156
}       // operator<< ()

powered by: WebSVN 2.1.0

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