Disk: Read driver for Plasion
parent
4c9d6c5ee7
commit
6bcd8e5637
|
|
@ -153,6 +153,7 @@ set(SRC_FILES
|
||||||
disk/diskwritedriver.cpp
|
disk/diskwritedriver.cpp
|
||||||
disk/nulldiskdriver.cpp
|
disk/nulldiskdriver.cpp
|
||||||
disk/neomemorydiskreaddriver.cpp
|
disk/neomemorydiskreaddriver.cpp
|
||||||
|
disk/plasiondiskreaddriver.cpp
|
||||||
${PLATFORM_SRC}
|
${PLATFORM_SRC}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@
|
||||||
#include "icsneo/communication/command.h"
|
#include "icsneo/communication/command.h"
|
||||||
#include "icsneo/communication/decoder.h"
|
#include "icsneo/communication/decoder.h"
|
||||||
#include "icsneo/communication/packetizer.h"
|
#include "icsneo/communication/packetizer.h"
|
||||||
|
#include "icsneo/communication/message/neoreadmemorysdmessage.h"
|
||||||
|
|
||||||
using namespace icsneo;
|
using namespace icsneo;
|
||||||
|
|
||||||
|
|
@ -134,6 +135,12 @@ void MultiChannelCommunication::hidReadTask() {
|
||||||
if(numVnets >= 3)
|
if(numVnets >= 3)
|
||||||
currentQueue = &vnetQueues[2];
|
currentQueue = &vnetQueues[2];
|
||||||
break;
|
break;
|
||||||
|
case CommandType::SDCC1_to_HostPC: {
|
||||||
|
auto msg = std::make_shared<NeoReadMemorySDMessage>();
|
||||||
|
std::swap(msg->data, payloadBytes);
|
||||||
|
dispatchMessage(msg);
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(currentQueue == nullptr) {
|
if(currentQueue == nullptr) {
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,74 @@
|
||||||
|
#include "icsneo/disk/plasiondiskreaddriver.h"
|
||||||
|
#include "icsneo/communication/message/neoreadmemorysdmessage.h"
|
||||||
|
#include "icsneo/communication/multichannelcommunication.h"
|
||||||
|
#include <cstring>
|
||||||
|
|
||||||
|
using namespace icsneo;
|
||||||
|
using namespace icsneo::Disk;
|
||||||
|
|
||||||
|
optional<uint64_t> PlasionDiskReadDriver::readLogicalDiskAligned(Communication& com, device_eventhandler_t report,
|
||||||
|
uint64_t pos, uint8_t* into, uint64_t amount, std::chrono::milliseconds timeout) {
|
||||||
|
static std::shared_ptr<MessageFilter> NeoMemorySDRead = std::make_shared<MessageFilter>(Network::NetID::NeoMemorySDRead);
|
||||||
|
|
||||||
|
if(amount > getBlockSizeBounds().second)
|
||||||
|
return nullopt;
|
||||||
|
|
||||||
|
if(amount % getBlockSizeBounds().first != 0)
|
||||||
|
return nullopt;
|
||||||
|
|
||||||
|
if(pos % getBlockSizeBounds().first != 0)
|
||||||
|
return nullopt;
|
||||||
|
|
||||||
|
if(cachePos != pos || std::chrono::steady_clock::now() > cachedAt + CacheTime) {
|
||||||
|
// The cache does not have this data, go get it
|
||||||
|
std::mutex m;
|
||||||
|
std::condition_variable cv;
|
||||||
|
uint32_t copied = 0;
|
||||||
|
bool error = false;
|
||||||
|
std::unique_lock<std::mutex> lk(m);
|
||||||
|
auto cb = com.addMessageCallback(MessageCallback([&](std::shared_ptr<Message> msg) {
|
||||||
|
std::unique_lock<std::mutex> lk(m);
|
||||||
|
|
||||||
|
const auto sdmsg = std::dynamic_pointer_cast<NeoReadMemorySDMessage>(msg);
|
||||||
|
if(!sdmsg || cache.size() < copied + sdmsg->data.size()) {
|
||||||
|
error = true;
|
||||||
|
lk.unlock();
|
||||||
|
cv.notify_all();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Invalidate the cache here in case we fail half-way through
|
||||||
|
cachedAt = std::chrono::steady_clock::time_point();
|
||||||
|
|
||||||
|
memcpy(cache.data() + copied, sdmsg->data.data(), sdmsg->data.size());
|
||||||
|
copied += sdmsg->data.size();
|
||||||
|
if(copied == amount) {
|
||||||
|
lk.unlock();
|
||||||
|
cv.notify_all();
|
||||||
|
}
|
||||||
|
}, NeoMemorySDRead));
|
||||||
|
|
||||||
|
uint32_t sector = pos / SectorSize;
|
||||||
|
com.rawWrite({
|
||||||
|
uint8_t(MultiChannelCommunication::CommandType::HostPC_from_SDCC1),
|
||||||
|
uint8_t(sector & 0xFF),
|
||||||
|
uint8_t((sector >> 8) & 0xFF),
|
||||||
|
uint8_t((sector >> 16) & 0xFF),
|
||||||
|
uint8_t((sector >> 24) & 0xFF),
|
||||||
|
uint8_t(amount & 0xFF),
|
||||||
|
uint8_t((amount >> 8) & 0xFF),
|
||||||
|
});
|
||||||
|
|
||||||
|
bool hitTimeout = !cv.wait_for(lk, timeout, [&copied, &error, &amount] { return error || copied == amount; });
|
||||||
|
com.removeMessageCallback(cb);
|
||||||
|
|
||||||
|
if(hitTimeout)
|
||||||
|
return nullopt;
|
||||||
|
|
||||||
|
cachedAt = std::chrono::steady_clock::now();
|
||||||
|
cachePos = pos;
|
||||||
|
}
|
||||||
|
|
||||||
|
memcpy(into, cache.data(), amount);
|
||||||
|
return amount;
|
||||||
|
}
|
||||||
|
|
@ -24,10 +24,6 @@ public:
|
||||||
void joinThreads() override;
|
void joinThreads() override;
|
||||||
bool sendPacket(std::vector<uint8_t>& bytes) override;
|
bool sendPacket(std::vector<uint8_t>& bytes) override;
|
||||||
|
|
||||||
protected:
|
|
||||||
bool preprocessPacket(std::deque<uint8_t>& usbReadFifo);
|
|
||||||
|
|
||||||
private:
|
|
||||||
enum class CommandType : uint8_t {
|
enum class CommandType : uint8_t {
|
||||||
PlasmaReadRequest = 0x10, // Status read request to HSC
|
PlasmaReadRequest = 0x10, // Status read request to HSC
|
||||||
PlasmaStatusResponse = 0x11, // Status response by HSC
|
PlasmaStatusResponse = 0x11, // Status response by HSC
|
||||||
|
|
@ -49,6 +45,10 @@ private:
|
||||||
Microblaze_to_HostPC = 0x81 // Microblaze processor data to host PC
|
Microblaze_to_HostPC = 0x81 // Microblaze processor data to host PC
|
||||||
};
|
};
|
||||||
|
|
||||||
|
protected:
|
||||||
|
bool preprocessPacket(std::deque<uint8_t>& usbReadFifo);
|
||||||
|
|
||||||
|
private:
|
||||||
static bool CommandTypeIsValid(CommandType cmd) {
|
static bool CommandTypeIsValid(CommandType cmd) {
|
||||||
switch(cmd) {
|
switch(cmd) {
|
||||||
case CommandType::PlasmaReadRequest:
|
case CommandType::PlasmaReadRequest:
|
||||||
|
|
@ -77,8 +77,10 @@ private:
|
||||||
static bool CommandTypeHasAddress(CommandType cmd) {
|
static bool CommandTypeHasAddress(CommandType cmd) {
|
||||||
// Check CommandTypeIsValid before this, you will get false on an invalid command
|
// Check CommandTypeIsValid before this, you will get false on an invalid command
|
||||||
switch(cmd) {
|
switch(cmd) {
|
||||||
case CommandType::SDCC1_to_HostPC:
|
case CommandType::HostPC_to_SDCC1:
|
||||||
case CommandType::SDCC2_to_HostPC:
|
case CommandType::HostPC_from_SDCC1:
|
||||||
|
case CommandType::HostPC_to_SDCC2:
|
||||||
|
case CommandType::HostPC_from_SDCC2:
|
||||||
return true;
|
return true;
|
||||||
default:
|
default:
|
||||||
return false;
|
return false;
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,7 @@
|
||||||
#include "icsneo/device/tree/plasion/plasion.h"
|
#include "icsneo/device/tree/plasion/plasion.h"
|
||||||
#include "icsneo/device/devicetype.h"
|
#include "icsneo/device/devicetype.h"
|
||||||
#include "icsneo/platform/ftdi.h"
|
#include "icsneo/platform/ftdi.h"
|
||||||
|
#include "icsneo/disk/plasiondiskreaddriver.h"
|
||||||
|
|
||||||
namespace icsneo {
|
namespace icsneo {
|
||||||
|
|
||||||
|
|
@ -24,7 +25,7 @@ public:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
NeoVIION(neodevice_t neodevice) : Plasion(neodevice) {
|
NeoVIION(neodevice_t neodevice) : Plasion(neodevice) {
|
||||||
initialize<FTDI>();
|
initialize<FTDI, NullSettings, Disk::PlasionDiskReadDriver>();
|
||||||
getWritableNeoDevice().type = DEVICE_TYPE;
|
getWritableNeoDevice().type = DEVICE_TYPE;
|
||||||
productId = PRODUCT_ID;
|
productId = PRODUCT_ID;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,43 @@
|
||||||
|
#ifndef __PLASIONDISKREADDRIVER_H__
|
||||||
|
#define __PLASIONDISKREADDRIVER_H__
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
|
||||||
|
#include "icsneo/disk/diskreaddriver.h"
|
||||||
|
#include <limits>
|
||||||
|
#include <chrono>
|
||||||
|
|
||||||
|
namespace icsneo {
|
||||||
|
|
||||||
|
namespace Disk {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A disk read driver which uses the PLASION HID command set to read from the disk
|
||||||
|
*/
|
||||||
|
class PlasionDiskReadDriver : public ReadDriver {
|
||||||
|
public:
|
||||||
|
Access getAccess() const override { return Access::EntireCard; }
|
||||||
|
std::pair<uint32_t, uint32_t> getBlockSizeBounds() const override {
|
||||||
|
static_assert(SectorSize <= std::numeric_limits<uint32_t>::max(), "Incorrect sector size");
|
||||||
|
static_assert(SectorSize >= std::numeric_limits<uint32_t>::min(), "Incorrect sector size");
|
||||||
|
return { static_cast<uint32_t>(SectorSize), static_cast<uint32_t>(MaxSize) };
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
static constexpr const uint32_t MaxSize = 65024;
|
||||||
|
static constexpr const std::chrono::duration CacheTime = std::chrono::seconds(1);
|
||||||
|
|
||||||
|
std::array<uint8_t, MaxSize> cache;
|
||||||
|
uint64_t cachePos = 0;
|
||||||
|
std::chrono::time_point<std::chrono::steady_clock> cachedAt;
|
||||||
|
|
||||||
|
optional<uint64_t> readLogicalDiskAligned(Communication& com, device_eventhandler_t report,
|
||||||
|
uint64_t pos, uint8_t* into, uint64_t amount, std::chrono::milliseconds timeout) override;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace Disk
|
||||||
|
|
||||||
|
} // namespace icsneo
|
||||||
|
|
||||||
|
#endif // __cplusplus
|
||||||
|
#endif // __NEOMEMORYDISKREADDRIVER_H__
|
||||||
Loading…
Reference in New Issue