// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
|
|
// RSP packet: implementation
|
// RSP packet: implementation
|
|
|
// Copyright (C) 2008 Embecosm Limited <info@embecosm.com>
|
// Copyright (C) 2008 Embecosm Limited <info@embecosm.com>
|
|
|
// Contributor Jeremy Bennett <jeremy.bennett@embecosm.com>
|
// Contributor Jeremy Bennett <jeremy.bennett@embecosm.com>
|
|
|
// This file is part of the cycle accurate model of the OpenRISC 1000 based
|
// This file is part of the cycle accurate model of the OpenRISC 1000 based
|
// system-on-chip, ORPSoC, built using Verilator.
|
// system-on-chip, ORPSoC, built using Verilator.
|
|
|
// This program is free software: you can redistribute it and/or modify it
|
// This program is free software: you can redistribute it and/or modify it
|
// under the terms of the GNU Lesser General Public License as published by
|
// under the terms of the GNU Lesser General Public License as published by
|
// the Free Software Foundation, either version 3 of the License, or (at your
|
// the Free Software Foundation, either version 3 of the License, or (at your
|
// option) any later version.
|
// option) any later version.
|
|
|
// This program is distributed in the hope that it will be useful, but WITHOUT
|
// This program is distributed in the hope that it will be useful, but WITHOUT
|
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
|
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
|
// License for more details.
|
// License for more details.
|
|
|
// You should have received a copy of the GNU Lesser General Public License
|
// You should have received a copy of the GNU Lesser General Public License
|
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
|
|
// $Id: RspPacket.cpp 327 2009-03-07 19:10:56Z jeremy $
|
// $Id: RspPacket.cpp 327 2009-03-07 19:10:56Z jeremy $
|
|
|
#include <iomanip>
|
#include <iomanip>
|
#include <iostream>
|
#include <iostream>
|
#include <cstring>
|
#include <cstring>
|
#include <cerrno>
|
#include <cerrno>
|
#include <cstdio>
|
#include <cstdio>
|
|
|
#include "RspPacket.h"
|
#include "RspPacket.h"
|
#include "Utils.h"
|
#include "Utils.h"
|
|
|
|
|
using std::ostream;
|
using std::ostream;
|
using std::cerr;
|
using std::cerr;
|
using std::dec;
|
using std::dec;
|
using std::endl;
|
using std::endl;
|
using std::hex;
|
using std::hex;
|
using std::setfill;
|
using std::setfill;
|
using std::setw;
|
using std::setw;
|
|
|
|
|
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
//! Constructor
|
//! Constructor
|
|
|
//! Allocate the new data buffer
|
//! Allocate the new data buffer
|
|
|
//! @param[in] _rspConnection The RSP connection we will use
|
//! @param[in] _rspConnection The RSP connection we will use
|
//! @param[in] _bufSize Size of data buffer to allocate
|
//! @param[in] _bufSize Size of data buffer to allocate
|
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
RspPacket::RspPacket (int _bufSize) :
|
RspPacket::RspPacket(int _bufSize):
|
bufSize (_bufSize)
|
bufSize(_bufSize)
|
{
|
{
|
data = new char [_bufSize];
|
data = new char[_bufSize];
|
|
|
} // RspPacket ();
|
} // RspPacket ();
|
|
|
|
|
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
//! Destructor
|
//! Destructor
|
|
|
//! Give back the data buffer
|
//! Give back the data buffer
|
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
RspPacket::~RspPacket ()
|
RspPacket::~RspPacket()
|
{
|
{
|
delete [] data;
|
delete[]data;
|
|
|
} // ~RspPacket ()
|
} // ~RspPacket ()
|
|
|
|
|
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
//! Pack a string into a packet.
|
//! Pack a string into a packet.
|
|
|
//! A convenience version of this method.
|
//! A convenience version of this method.
|
|
|
//! @param str The string to copy into the data packet before sending
|
//! @param str The string to copy into the data packet before sending
|
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
void
|
void
|
RspPacket::packStr (const char *str)
|
RspPacket::packStr(const char *str)
|
{
|
{
|
int slen = strlen (str);
|
int slen = strlen(str);
|
|
|
// Construct the packet to send, so long as string is not too big, otherwise
|
// Construct the packet to send, so long as string is not too big, otherwise
|
// truncate. Add EOS at the end for convenient debug printout
|
// truncate. Add EOS at the end for convenient debug printout
|
if (slen >= bufSize)
|
if (slen >= bufSize) {
|
{
|
|
cerr << "Warning: String \"" << str
|
cerr << "Warning: String \"" << str
|
<< "\" too large for RSP packet: truncated\n" << endl;
|
<< "\" too large for RSP packet: truncated\n" << endl;
|
slen = bufSize - 1;
|
slen = bufSize - 1;
|
}
|
}
|
|
|
strncpy (data, str, slen);
|
strncpy(data, str, slen);
|
data[slen] = 0;
|
data[slen] = 0;
|
len = slen;
|
len = slen;
|
|
|
} // packStr ()
|
} // packStr ()
|
|
|
|
|
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
//! Get the data buffer size
|
//! Get the data buffer size
|
|
|
//! @return The data buffer size
|
//! @return The data buffer size
|
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
int
|
int RspPacket::getBufSize()
|
RspPacket::getBufSize ()
|
|
{
|
{
|
return bufSize;
|
return bufSize;
|
|
|
} // getBufSize ()
|
} // getBufSize ()
|
|
|
|
|
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
//! Get the current number of chars in the data buffer
|
//! Get the current number of chars in the data buffer
|
|
|
//! @return The number of chars in the data buffer
|
//! @return The number of chars in the data buffer
|
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
int
|
int RspPacket::getLen()
|
RspPacket::getLen ()
|
|
{
|
{
|
return len;
|
return len;
|
|
|
} // getLen ()
|
} // getLen ()
|
|
|
|
|
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
//! Set the number of chars in the data buffer
|
//! Set the number of chars in the data buffer
|
|
|
//! @param[in] _len The number of chars to be set
|
//! @param[in] _len The number of chars to be set
|
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
void
|
void RspPacket::setLen(int _len)
|
RspPacket::setLen (int _len)
|
|
{
|
{
|
len = _len;
|
len = _len;
|
|
|
} // setLen ()
|
} // setLen ()
|
|
|
|
|
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
//! Output stream operator
|
//! Output stream operator
|
|
|
//! @param[out] s Stream to output to
|
//! @param[out] s Stream to output to
|
//! @param[in] p Packet to output
|
//! @param[in] p Packet to output
|
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
ostream &
|
ostream & operator<<(ostream & s, RspPacket & p)
|
operator<< (ostream &s,
|
|
RspPacket &p)
|
|
{
|
{
|
return s << "RSP packet: " << std::dec << std::setw (3) << p.getLen()
|
return s << "RSP packet: " << std::dec << std::setw(3) << p.getLen()
|
<< std::setw (0) << " chars, \"" << p.data << "\"";
|
<< std::setw(0) << " chars, \"" << p.data << "\"";
|
|
|
} // operator<< ()
|
} // operator<< ()
|
|
|