2022-10-04 15:23:42 +00:00
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
//
|
2022-12-05 17:58:23 +00:00
|
|
|
// SCSI Target Emulator PiSCSI
|
2022-10-04 15:23:42 +00:00
|
|
|
// for Raspberry Pi
|
|
|
|
//
|
2023-10-15 06:38:15 +00:00
|
|
|
// Copyright (C) 2022-2023 Uwe Seimet
|
2022-10-04 15:23:42 +00:00
|
|
|
//
|
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2022-11-10 06:44:06 +00:00
|
|
|
#include "shared/scsi.h"
|
2023-10-15 06:38:15 +00:00
|
|
|
#include "shared/piscsi_exceptions.h"
|
|
|
|
#include <unordered_map>
|
|
|
|
#include <functional>
|
2022-10-04 15:23:42 +00:00
|
|
|
|
2023-10-15 06:38:15 +00:00
|
|
|
using namespace scsi_defs;
|
2022-12-03 04:20:27 +00:00
|
|
|
|
2022-10-04 15:23:42 +00:00
|
|
|
class PhaseHandler
|
|
|
|
{
|
2022-12-03 04:20:27 +00:00
|
|
|
phase_t phase = phase_t::busfree;
|
2022-10-04 15:23:42 +00:00
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
PhaseHandler() = default;
|
|
|
|
virtual ~PhaseHandler() = default;
|
|
|
|
|
|
|
|
virtual void BusFree() = 0;
|
|
|
|
virtual void Selection() = 0;
|
|
|
|
virtual void Command() = 0;
|
|
|
|
virtual void Status() = 0;
|
|
|
|
virtual void DataIn() = 0;
|
|
|
|
virtual void DataOut() = 0;
|
|
|
|
virtual void MsgIn() = 0;
|
|
|
|
virtual void MsgOut() = 0;
|
|
|
|
|
2023-10-15 06:38:15 +00:00
|
|
|
virtual bool Process(int) = 0;
|
2022-10-04 15:23:42 +00:00
|
|
|
|
|
|
|
protected:
|
|
|
|
|
2022-12-03 04:20:27 +00:00
|
|
|
phase_t GetPhase() const { return phase; }
|
|
|
|
void SetPhase(phase_t p) { phase = p; }
|
|
|
|
bool IsSelection() const { return phase == phase_t::selection; }
|
|
|
|
bool IsBusFree() const { return phase == phase_t::busfree; }
|
|
|
|
bool IsCommand() const { return phase == phase_t::command; }
|
|
|
|
bool IsStatus() const { return phase == phase_t::status; }
|
|
|
|
bool IsDataIn() const { return phase == phase_t::datain; }
|
|
|
|
bool IsDataOut() const { return phase == phase_t::dataout; }
|
|
|
|
bool IsMsgIn() const { return phase == phase_t::msgin; }
|
|
|
|
bool IsMsgOut() const { return phase == phase_t::msgout; }
|
2023-10-15 06:38:15 +00:00
|
|
|
|
|
|
|
void ProcessPhase() const
|
|
|
|
{
|
|
|
|
try {
|
|
|
|
phase_executors.at(phase)();
|
|
|
|
}
|
|
|
|
catch(const out_of_range&) {
|
|
|
|
throw scsi_exception(sense_key::aborted_command);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
const unordered_map<phase_t, function<void()>> phase_executors = {
|
|
|
|
{ phase_t::busfree, [this] () { BusFree(); } },
|
|
|
|
{ phase_t::selection, [this] () { Selection(); } },
|
|
|
|
{ phase_t::dataout, [this] () { DataOut(); } },
|
|
|
|
{ phase_t::datain, [this] () { DataIn(); } },
|
|
|
|
{ phase_t::command, [this] () { Command(); } },
|
|
|
|
{ phase_t::status, [this] () { Status(); } },
|
|
|
|
{ phase_t::msgout, [this] () { MsgOut(); } },
|
|
|
|
{ phase_t::msgin, [this] () { MsgIn(); } },
|
|
|
|
};
|
2022-10-04 15:23:42 +00:00
|
|
|
};
|