dev: Use lambdas instead of the Callback type for serial devices.
Issue-on: https://gem5.atlassian.net/browse/GEM5-698 Change-Id: Idb87fa0b90d14981fd61f997285f61b2ef304227 Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/32647 Reviewed-by: Andreas Sandberg <andreas.sandberg@arm.com> Maintainer: Gabe Black <gabeblack@google.com> Tested-by: kokoro <noreply+kokoro@google.com>
This commit is contained in:
@@ -41,8 +41,7 @@
|
||||
#include "params/SerialDevice.hh"
|
||||
#include "params/SerialNullDevice.hh"
|
||||
|
||||
SerialDevice::SerialDevice(const SerialDeviceParams *p)
|
||||
: SimObject(p), interfaceCallback(nullptr)
|
||||
SerialDevice::SerialDevice(const SerialDeviceParams *p) : SimObject(p)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -51,14 +50,14 @@ SerialDevice::~SerialDevice()
|
||||
}
|
||||
|
||||
void
|
||||
SerialDevice::regInterfaceCallback(Callback *c)
|
||||
SerialDevice::regInterfaceCallback(const std::function<void()> &callback)
|
||||
{
|
||||
// This can happen if the user has connected multiple UARTs to the
|
||||
// same terminal. In that case, each of them tries to register
|
||||
// callbacks.
|
||||
if (interfaceCallback)
|
||||
fatal("A UART has already been associated with this device.\n");
|
||||
interfaceCallback = c;
|
||||
fatal_if(interfaceCallback,
|
||||
"A UART has already been associated with this device.");
|
||||
interfaceCallback = callback;
|
||||
}
|
||||
|
||||
void
|
||||
@@ -67,7 +66,7 @@ SerialDevice::notifyInterface()
|
||||
assert(dataAvailable());
|
||||
// Registering a callback is optional.
|
||||
if (interfaceCallback)
|
||||
interfaceCallback->process();
|
||||
interfaceCallback();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -38,7 +38,8 @@
|
||||
#ifndef __DEV_SERIAL_HH__
|
||||
#define __DEV_SERIAL_HH__
|
||||
|
||||
#include "base/callback.hh"
|
||||
#include <functional>
|
||||
|
||||
#include "sim/sim_object.hh"
|
||||
|
||||
struct SerialDeviceParams;
|
||||
@@ -103,9 +104,9 @@ class SerialDevice : public SimObject
|
||||
* method. The interface layer may use this method to register a
|
||||
* callback that informs it of pending data.
|
||||
*
|
||||
* @param c Callback instance from interface layer.
|
||||
* @param c Callback from interface layer.
|
||||
*/
|
||||
void regInterfaceCallback(Callback *c);
|
||||
void regInterfaceCallback(const std::function<void()> &callback);
|
||||
|
||||
/**
|
||||
* Check if there is pending data from the serial device.
|
||||
@@ -136,7 +137,7 @@ class SerialDevice : public SimObject
|
||||
|
||||
private:
|
||||
/** Currently regisxtered host interface layer callback */
|
||||
Callback *interfaceCallback;
|
||||
std::function<void()> interfaceCallback;
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
@@ -32,13 +32,11 @@
|
||||
|
||||
#include "dev/serial/uart.hh"
|
||||
|
||||
Uart::Uart(const Params *p, Addr pio_size)
|
||||
: BasicPioDevice(p, pio_size),
|
||||
platform(p->platform), device(p->device),
|
||||
callbackDataAvail(this)
|
||||
Uart::Uart(const Params *p, Addr pio_size) :
|
||||
BasicPioDevice(p, pio_size), platform(p->platform), device(p->device)
|
||||
{
|
||||
status = 0;
|
||||
|
||||
// setup serial device callbacks
|
||||
device->regInterfaceCallback(&callbackDataAvail);
|
||||
device->regInterfaceCallback([this]() { dataAvailable(); });
|
||||
}
|
||||
|
||||
@@ -70,9 +70,6 @@ class Uart : public BasicPioDevice
|
||||
* @return interrupt status
|
||||
*/
|
||||
bool intStatus() { return status ? true : false; }
|
||||
|
||||
protected:
|
||||
MakeCallback<Uart, &Uart::dataAvailable> callbackDataAvail;
|
||||
};
|
||||
|
||||
#endif // __UART_HH__
|
||||
|
||||
@@ -45,7 +45,7 @@ VirtIOConsole::VirtIOConsole(Params *params)
|
||||
: VirtIODeviceBase(params, ID_CONSOLE, sizeof(Config), F_SIZE),
|
||||
qRecv(params->system->physProxy, byteOrder, params->qRecvSize, *this),
|
||||
qTrans(params->system->physProxy, byteOrder, params->qTransSize, *this),
|
||||
device(*params->device), callbackDataAvail(qRecv)
|
||||
device(*params->device)
|
||||
{
|
||||
registerQueue(qRecv);
|
||||
registerQueue(qTrans);
|
||||
@@ -53,7 +53,7 @@ VirtIOConsole::VirtIOConsole(Params *params)
|
||||
config.cols = 80;
|
||||
config.rows = 24;
|
||||
|
||||
device.regInterfaceCallback(&callbackDataAvail);
|
||||
device.regInterfaceCallback([this]() { qRecv.trySend(); });
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -148,8 +148,6 @@ class VirtIOConsole : public VirtIODeviceBase
|
||||
|
||||
protected:
|
||||
SerialDevice &device;
|
||||
MakeCallback<VirtIOConsole::TermRecvQueue,
|
||||
&VirtIOConsole::TermRecvQueue::trySend> callbackDataAvail;
|
||||
};
|
||||
|
||||
#endif // __DEV_VIRTIO_CONSOLE_HH__
|
||||
|
||||
Reference in New Issue
Block a user