* data transfer between the disk and the disk controller.
*/
virtual void readMemory(uint64_t address, uint32_t amount,
- Callback *event) = 0;
+ const std::function<void()> &event) = 0;
virtual void writeMemory(uint64_t address, uint32_t amount,
- Callback *event) = 0;
+ const std::function<void()> &event) = 0;
};
#endif //__DEV_ARM_ABSTRACT_NVM_HH__
* an event that uses the callback function on completion of the action.
*/
void
-FlashDevice::accessDevice(uint64_t address, uint32_t amount, Callback *event,
- Actions action)
+FlashDevice::accessDevice(uint64_t address, uint32_t amount,
+ const std::function<void()> &event, Actions action)
{
DPRINTF(FlashDevice, "Flash calculation for %d bytes in %d pages\n"
, amount, pageSize);
else
cbe.time = time[count] +
planeEventQueue[count].back().time;
- cbe.function = NULL;
planeEventQueue[count].push_back(cbe);
DPRINTF(FlashDevice, "scheduled at: %ld\n", cbe.time);
* the callback entry first need to be cleared before it can
* be called.
*/
- Callback *temp = planeEventQueue[plane_address].front().
- function;
+ auto temp = planeEventQueue[plane_address].front().function;
planeEventQueue[plane_address].pop_front();
/**Found a callback, lets make it happen*/
- if (temp != NULL) {
+ if (temp) {
DPRINTF(FlashDevice, "Callback, %d\n", plane_address);
- temp->process();
+ temp();
}
}
}
struct CallBackEntry {
Tick time;
- Callback *function;
+ std::function<void()> function;
};
struct FlashDeviceStats {
};
/** Device access functions Inherrited from AbstractNVM*/
- void initializeMemory(uint64_t disk_size, uint32_t sector_size) override
+ void
+ initializeMemory(uint64_t disk_size, uint32_t sector_size) override
{
initializeFlash(disk_size, sector_size);
}
- void readMemory(uint64_t address, uint32_t amount,
- Callback *event) override
+ void
+ readMemory(uint64_t address, uint32_t amount,
+ const std::function<void()> &event) override
{
accessDevice(address, amount, event, ActionRead);
}
- void writeMemory(uint64_t address, uint32_t amount,
- Callback *event) override
+ void
+ writeMemory(uint64_t address, uint32_t amount,
+ const std::function<void()> &event) override
{
accessDevice(address, amount, event, ActionWrite);
}
void initializeFlash(uint64_t disk_size, uint32_t sector_size);
/**Flash action function*/
- void accessDevice(uint64_t address, uint32_t amount, Callback *event,
- Actions action);
+ void accessDevice(uint64_t address, uint32_t amount,
+ const std::function<void()> &event, Actions action);
/** Event rescheduler*/
void actionComplete();
* Constructor and destructor functions of UFSHCM device
*/
UFSHostDevice::UFSSCSIDevice::UFSSCSIDevice(const UFSHostDeviceParams* p,
- uint32_t lun_id, Callback *transfer_cb,
- Callback *read_cb):
+ uint32_t lun_id, const Callback &transfer_cb,
+ const Callback &read_cb):
SimObject(p),
flashDisk(p->image[lun_id]),
flashDevice(p->internalflash[lun_id]),
* or from the UFS SCSI device to the UFS host.
*/
signalDone = transfer_cb;
- memReadCallback = new MakeCallback<UFSSCSIDevice,
- &UFSHostDevice::UFSSCSIDevice::readCallback>(this);
+ memReadCallback = [this]() { readCallback(); };
deviceReadCallback = read_cb;
- memWriteCallback = new MakeCallback<UFSSCSIDevice,
- &UFSHostDevice::UFSSCSIDevice::SSDWriteDone>(this);
+ memWriteCallback = [this]() { SSDWriteDone(); };
/**
* make ascii out of lun_id (and add more characters)
lunAvail);
UFSDevice.resize(lunAvail);
- transferDoneCallback = new MakeCallback<UFSHostDevice,
- &UFSHostDevice::LUNSignal>(this);
- memReadCallback = new MakeCallback<UFSHostDevice,
- &UFSHostDevice::readCallback>(this);
-
for (int count = 0; count < lunAvail; count++) {
- UFSDevice[count] = new UFSSCSIDevice(p, count, transferDoneCallback,
- memReadCallback);
+ UFSDevice[count] = new UFSSCSIDevice(p, count,
+ [this]() { LUNSignal(); },
+ [this]() { readCallback(); });
}
if (UFSSlots > 31)
//Callback UFS Host
setSignal();
- signalDone->process();
+ signalDone();
}
}
/**Callback: transferdone*/
setSignal();
- signalDone->process();
+ signalDone();
}
}
* UFSHostDevice::readCallback
*/
setReadSignal();
- deviceReadCallback->process();
+ deviceReadCallback();
//Are we done yet?
SSDReadDone();
#define __DEV_ARM_UFS_DEVICE_HH__
#include <deque>
+#include <functional>
#include "base/addr_range.hh"
#include "base/bitfield.hh"
class UFSSCSIDevice: SimObject
{
public:
+ using Callback = std::function<void()>;
+
/**
* Constructor and destructor
*/
- UFSSCSIDevice(const UFSHostDeviceParams* p, uint32_t lun_id, Callback*
- transfer_cb, Callback *read_cb);
+ UFSSCSIDevice(const UFSHostDeviceParams* p, uint32_t lun_id,
+ const Callback &transfer_cb, const Callback &read_cb);
~UFSSCSIDevice();
/**
/**
* Callbacks between Host and Device
*/
- Callback* signalDone;
- Callback* deviceReadCallback;
+ Callback signalDone;
+ Callback deviceReadCallback;
/**
* Callbacks between Device and Memory
*/
- Callback* memReadCallback;
- Callback* memWriteCallback;
+ Callback memReadCallback;
+ Callback memWriteCallback;
/*
* Default response header layout. For more information refer to
std::deque<EventFunctionWrapper> readDoneEvent;
std::deque<EventFunctionWrapper> writeDoneEvent;
- /**
- * Callbacks for the logic units. One to indicate the completion of a
- * transaction, the other one to indicate the completion of a read
- * action.
- */
- Callback* transferDoneCallback;
- Callback* memReadCallback;
-
/**
* The events that control the functionality.
* After a doorbell has been set, either a taskevent or a transfer event