#include "params/SerialDevice.hh"
#include "params/SerialNullDevice.hh"
-SerialDevice::SerialDevice(const SerialDeviceParams *p)
- : SimObject(p), interfaceCallback(nullptr)
+SerialDevice::SerialDevice(const SerialDeviceParams *p) : SimObject(p)
{
}
}
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
assert(dataAvailable());
// Registering a callback is optional.
if (interfaceCallback)
- interfaceCallback->process();
+ interfaceCallback();
}
#ifndef __DEV_SERIAL_HH__
#define __DEV_SERIAL_HH__
-#include "base/callback.hh"
+#include <functional>
+
#include "sim/sim_object.hh"
struct SerialDeviceParams;
* 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.
private:
/** Currently regisxtered host interface layer callback */
- Callback *interfaceCallback;
+ std::function<void()> interfaceCallback;
};
/**
#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(); });
}
* @return interrupt status
*/
bool intStatus() { return status ? true : false; }
-
- protected:
- MakeCallback<Uart, &Uart::dataAvailable> callbackDataAvail;
};
#endif // __UART_HH__
: 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);
config.cols = 80;
config.rows = 24;
- device.regInterfaceCallback(&callbackDataAvail);
+ device.regInterfaceCallback([this]() { qRecv.trySend(); });
}
protected:
SerialDevice &device;
- MakeCallback<VirtIOConsole::TermRecvQueue,
- &VirtIOConsole::TermRecvQueue::trySend> callbackDataAvail;
};
#endif // __DEV_VIRTIO_CONSOLE_HH__