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

Subversion Repositories openrisc

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

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
using std::ostream;
39
using std::cerr;
40
using std::dec;
41
using std::endl;
42
using std::hex;
43
using std::setfill;
44
using std::setw;
45
 
46
//-----------------------------------------------------------------------------
47
//! Constructor
48
 
49
//! Allocate the new data buffer
50
 
51
//! @param[in]  _rspConnection  The RSP connection we will use
52
//! @param[in]  _bufSize        Size of data buffer to allocate
53
//-----------------------------------------------------------------------------
54 462 julius
RspPacket::RspPacket(int _bufSize):
55
bufSize(_bufSize)
56 63 julius
{
57 462 julius
        data = new char[_bufSize];
58 63 julius
 
59 462 julius
}                               // RspPacket ();
60 63 julius
 
61
//-----------------------------------------------------------------------------
62
//! Destructor
63
 
64
//! Give back the data buffer
65
//-----------------------------------------------------------------------------
66 462 julius
RspPacket::~RspPacket()
67 63 julius
{
68 462 julius
        delete[]data;
69 63 julius
 
70 462 julius
}                               // ~RspPacket ()
71 63 julius
 
72
//-----------------------------------------------------------------------------
73
//! Pack a string into a packet.
74
 
75
//! A convenience version of this method.
76
 
77
//! @param  str  The string to copy into the data packet before sending
78
//-----------------------------------------------------------------------------
79
void
80 462 julius
 RspPacket::packStr(const char *str)
81 63 julius
{
82 462 julius
        int slen = strlen(str);
83 63 julius
 
84 462 julius
        // Construct the packet to send, so long as string is not too big, otherwise
85
        // truncate. Add EOS at the end for convenient debug printout
86
        if (slen >= bufSize) {
87
                cerr << "Warning: String \"" << str
88
                    << "\" too large for RSP packet: truncated\n" << endl;
89
                slen = bufSize - 1;
90
        }
91 63 julius
 
92 462 julius
        strncpy(data, str, slen);
93
        data[slen] = 0;
94
        len = slen;
95 63 julius
 
96 462 julius
}                               // packStr ()
97 63 julius
 
98
//-----------------------------------------------------------------------------
99
//! Get the data buffer size
100
 
101
//! @return  The data buffer size
102
//-----------------------------------------------------------------------------
103 462 julius
int RspPacket::getBufSize()
104 63 julius
{
105 462 julius
        return bufSize;
106 63 julius
 
107 462 julius
}                               // getBufSize ()
108 63 julius
 
109
//-----------------------------------------------------------------------------
110
//! Get the current number of chars in the data buffer
111
 
112
//! @return  The number of chars in the data buffer
113
//-----------------------------------------------------------------------------
114 462 julius
int RspPacket::getLen()
115 63 julius
{
116 462 julius
        return len;
117 63 julius
 
118 462 julius
}                               // getLen ()
119 63 julius
 
120
//-----------------------------------------------------------------------------
121
//! Set the number of chars in the data buffer
122
 
123
//! @param[in] _len  The number of chars to be set
124
//-----------------------------------------------------------------------------
125 462 julius
void RspPacket::setLen(int _len)
126 63 julius
{
127 462 julius
        len = _len;
128 63 julius
 
129 462 julius
}                               // setLen ()
130 63 julius
 
131
//-----------------------------------------------------------------------------
132
//! Output stream operator
133
 
134
//! @param[out] s  Stream to output to
135
//! @param[in]  p  Packet to output
136
//-----------------------------------------------------------------------------
137 462 julius
ostream & operator<<(ostream & s, RspPacket & p)
138 63 julius
{
139 462 julius
        return s << "RSP packet: " << std::dec << std::setw(3) << p.getLen()
140
            << std::setw(0) << " chars, \"" << p.data << "\"";
141 63 julius
 
142 462 julius
}                               // operator<< ()

powered by: WebSVN 2.1.0

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