diff --git a/cpp/hal/bus.cpp b/cpp/hal/bus.cpp index ff2edd1b..b135342a 100644 --- a/cpp/hal/bus.cpp +++ b/cpp/hal/bus.cpp @@ -60,23 +60,28 @@ const char* BUS::GetPhaseStrRaw(phase_t current_phase) { return it != phase_str_mapping.end() ? it->second : "INVALID"; } -//--------------------------------------------------------------------------- +// Phase Table +// Reference Table 8: https://www.staff.uni-mainz.de/tacke/scsi/SCSI2-06.html +// This determines the phase based upon the Msg, C/D and I/O signals. // -// Phase Table -// Reference Table 8: https://www.staff.uni-mainz.de/tacke/scsi/SCSI2-06.html -// This determines the phase based upon the Msg, C/D and I/O signals. -// -//--------------------------------------------------------------------------- +// |MSG|C/D|I/O| Phase +// | 0 | 0 | 0 | DATA OUT +// | 0 | 0 | 1 | DATA IN +// | 0 | 1 | 0 | COMMAND +// | 0 | 1 | 1 | STATUS +// | 1 | 0 | 0 | RESERVED +// | 1 | 0 | 1 | RESERVED +// | 1 | 1 | 0 | MESSAGE OUT +// | 1 | 1 | 1 | MESSAGE IN const array BUS::phase_table = { - // | MSG|C/D|I/O | - phase_t::dataout, // | 0 | 0 | 0 | - phase_t::datain, // | 0 | 0 | 1 | - phase_t::command, // | 0 | 1 | 0 | - phase_t::status, // | 0 | 1 | 1 | - phase_t::reserved, // | 1 | 0 | 0 | - phase_t::reserved, // | 1 | 0 | 1 | - phase_t::msgout, // | 1 | 1 | 0 | - phase_t::msgin // | 1 | 1 | 1 | + phase_t::dataout, + phase_t::datain, + phase_t::command, + phase_t::status, + phase_t::reserved, + phase_t::reserved, + phase_t::msgout, + phase_t::msgin }; //--------------------------------------------------------------------------- diff --git a/cpp/hal/bus.h b/cpp/hal/bus.h index 23740fe2..17a1a805 100644 --- a/cpp/hal/bus.h +++ b/cpp/hal/bus.h @@ -68,8 +68,7 @@ class BUS : public PinControl // Operation modes definition enum class mode_e { TARGET = 0, - INITIATOR = 1, - MONITOR = 2, + INITIATOR = 1 }; static int GetCommandByteCount(uint8_t); @@ -86,7 +85,6 @@ class BUS : public PinControl // Get the string phase name, based upon the raw data static const char *GetPhaseStrRaw(phase_t current_phase); - virtual int GetMode(int pin) = 0; virtual uint32_t Acquire() = 0; virtual unique_ptr GetSample(uint64_t timestamp = 0) = 0; @@ -97,9 +95,6 @@ class BUS : public PinControl // SEL signal event polling virtual bool PollSelectEvent() = 0; - // Clear SEL signal event - virtual void ClearSelectEvent() = 0; - virtual bool GetSignal(int pin) const = 0; // Get SCSI input signal value virtual void SetSignal(int pin, bool ast) = 0; diff --git a/cpp/hal/data_sample.h b/cpp/hal/data_sample.h index c5a57e30..d7e794b0 100644 --- a/cpp/hal/data_sample.h +++ b/cpp/hal/data_sample.h @@ -31,7 +31,6 @@ class DataSample virtual bool GetREQ() const = 0; virtual bool GetACT() const = 0; virtual uint8_t GetDAT() const = 0; - virtual bool GetDP() const = 0; virtual uint32_t GetRawCapture() const = 0; diff --git a/cpp/hal/data_sample_raspberry.cpp b/cpp/hal/data_sample_raspberry.cpp deleted file mode 100644 index 9634a912..00000000 --- a/cpp/hal/data_sample_raspberry.cpp +++ /dev/null @@ -1,14 +0,0 @@ -//--------------------------------------------------------------------------- -// -// SCSI Target Emulator PiSCSI -// for Raspberry Pi -// -// Copyright (C) 2022 akuker -// -// [ SCSI Bus Monitor ] -// -//--------------------------------------------------------------------------- - -#include "shared/scsi.h" -#include "data_sample.h" - diff --git a/cpp/hal/data_sample_raspberry.h b/cpp/hal/data_sample_raspberry.h index a0b5e1e7..ee7cbc0e 100644 --- a/cpp/hal/data_sample_raspberry.h +++ b/cpp/hal/data_sample_raspberry.h @@ -74,10 +74,6 @@ class DataSample_Raspberry final : public DataSample { return GetSignal(PIN_ACT); } - bool GetDP() const override - { - return GetSignal(PIN_DP); - } uint8_t GetDAT() const override { uint8_t ret_val = 0; @@ -106,4 +102,4 @@ class DataSample_Raspberry final : public DataSample private: uint32_t data = 0; -}; \ No newline at end of file +}; diff --git a/cpp/hal/gpiobus.cpp b/cpp/hal/gpiobus.cpp index 837fc6d7..397ed9cf 100644 --- a/cpp/hal/gpiobus.cpp +++ b/cpp/hal/gpiobus.cpp @@ -1,10 +1,11 @@ //--------------------------------------------------------------------------- // -// SCSI Target Emulator PiSCSI -// for Raspberry Pi +// SCSI Target Emulator PiSCSI +// for Raspberry Pi // -// Powered by XM6 TypeG Technology. -// Copyright (C) 2016-2020 GIMONS +// Powered by XM6 TypeG Technology. +// Copyright (C) 2016-2020 GIMONS +// Copyright (C) 2023 Uwe Seimet // //--------------------------------------------------------------------------- @@ -18,6 +19,7 @@ #ifdef __linux__ #include #endif +#include using namespace std; @@ -403,42 +405,23 @@ bool GPIOBUS::PollSelectEvent() #endif } -//--------------------------------------------------------------------------- -// -// Cancel SEL signal event -// -//--------------------------------------------------------------------------- -void GPIOBUS::ClearSelectEvent() -{ - GPIO_FUNCTION_TRACE -} - -//--------------------------------------------------------------------------- -// -// Wait for signal change -// -//--------------------------------------------------------------------------- bool GPIOBUS::WaitSignal(int pin, bool ast) { - // Get current time - const uint32_t now = SysTimer::GetTimerLow(); - - // Calculate timeout (3000ms) - const uint32_t timeout = 3000 * 1000; + const auto now = chrono::steady_clock::now(); + // Wait up to 3 s do { - // Immediately upon receiving a reset Acquire(); - if (GetRST()) { - return false; - } - // Check for the signal edge if (GetSignal(pin) == ast) { return true; } - } while ((SysTimer::GetTimerLow() - now) < timeout); - // We timed out waiting for the signal + // Abort on a reset + if (GetRST()) { + return false; + } + } while ((chrono::duration_cast(chrono::steady_clock::now() - now).count()) < 3); + return false; } diff --git a/cpp/hal/gpiobus.h b/cpp/hal/gpiobus.h index fe774115..0e9e8129 100644 --- a/cpp/hal/gpiobus.h +++ b/cpp/hal/gpiobus.h @@ -182,8 +182,6 @@ class GPIOBUS : public BUS // SEL signal event polling bool PollSelectEvent() override; - // Clear SEL signal event - void ClearSelectEvent() override; protected: virtual void MakeTable() = 0; diff --git a/cpp/hal/gpiobus_raspberry.cpp b/cpp/hal/gpiobus_raspberry.cpp index 44e09dfe..030413fd 100644 --- a/cpp/hal/gpiobus_raspberry.cpp +++ b/cpp/hal/gpiobus_raspberry.cpp @@ -644,17 +644,6 @@ void GPIOBUS_Raspberry::SetDAT(uint8_t dat) #endif // SIGNAL_CONTROL_MODE } -bool GPIOBUS_Raspberry::GetDP() const -{ - return GetSignal(PIN_DP); -} - -//--------------------------------------------------------------------------- -// -// Create work table -// -//--------------------------------------------------------------------------- - //--------------------------------------------------------------------------- // // Signal table diff --git a/cpp/hal/gpiobus_raspberry.h b/cpp/hal/gpiobus_raspberry.h index a79df0e5..9918fe21 100644 --- a/cpp/hal/gpiobus_raspberry.h +++ b/cpp/hal/gpiobus_raspberry.h @@ -137,8 +137,6 @@ class GPIOBUS_Raspberry : public GPIOBUS // Set REQ signal void SetREQ(bool ast) override; - bool GetDP() const override; - // Get DAT signal uint8_t GetDAT() override; // Set DAT signal @@ -174,12 +172,6 @@ class GPIOBUS_Raspberry : public GPIOBUS // Set Control Signal void SetMode(int pin, int mode) override; // Set SCSI I/O mode - int GetMode(int pin) override - { - // Not implemented (or needed for thist gpio bus type) - (void)pin; - return -1; - } bool GetSignal(int pin) const override; // Get SCSI input signal value void SetSignal(int pin, bool ast) override; diff --git a/cpp/hal/gpiobus_virtual.cpp b/cpp/hal/gpiobus_virtual.cpp index 136dae24..5648a871 100644 --- a/cpp/hal/gpiobus_virtual.cpp +++ b/cpp/hal/gpiobus_virtual.cpp @@ -372,11 +372,6 @@ void GPIOBUS_Virtual::SetREQ(bool ast) SetSignal(PIN_REQ, ast); } -bool GPIOBUS_Virtual::GetDP() const -{ - return GetSignal(PIN_DP); -} - //--------------------------------------------------------------------------- // // Get data signals diff --git a/cpp/hal/gpiobus_virtual.h b/cpp/hal/gpiobus_virtual.h index 85e00c79..991e3f85 100644 --- a/cpp/hal/gpiobus_virtual.h +++ b/cpp/hal/gpiobus_virtual.h @@ -97,8 +97,6 @@ class GPIOBUS_Virtual final : public GPIOBUS void SetREQ(bool ast) override; // Set REQ signal - bool GetDP() const override; - bool WaitREQ(bool ast) override { return WaitSignal(PIN_REQ, ast); @@ -120,12 +118,6 @@ class GPIOBUS_Virtual final : public GPIOBUS // Set Control Signal void SetMode(int pin, int mode) override; // Set SCSI I/O mode - int GetMode(int pin) override - { - // Not implemented (or needed for thist gpio bus type) - (void)pin; - return -1; - } bool GetSignal(int pin) const override; // Get SCSI input signal value void SetSignal(int pin, bool ast) override; diff --git a/cpp/hal/pin_control.h b/cpp/hal/pin_control.h index 902a5de7..d5690d89 100644 --- a/cpp/hal/pin_control.h +++ b/cpp/hal/pin_control.h @@ -52,9 +52,6 @@ class PinControl // Set ENB signal virtual void SetENB(bool ast) = 0; - // Get parity signal - virtual bool GetDP() const = 0; - // GPIO pin direction setting virtual void PinConfig(int pin, int mode) = 0; // GPIO pin pull up/down resistor setting @@ -65,4 +62,4 @@ class PinControl PinControl() = default; virtual ~PinControl() = default; -}; \ No newline at end of file +}; diff --git a/cpp/hal/systimer.cpp b/cpp/hal/systimer.cpp index c2b4e7b8..9073ed82 100644 --- a/cpp/hal/systimer.cpp +++ b/cpp/hal/systimer.cpp @@ -43,12 +43,6 @@ uint32_t SysTimer::GetTimerLow() return systimer_ptr->GetTimerLow(); } -// Get system timer high byte -uint32_t SysTimer::GetTimerHigh() -{ - return systimer_ptr->GetTimerHigh(); -} - // Sleep for N nanoseconds void SysTimer::SleepNsec(uint32_t nsec) { diff --git a/cpp/hal/systimer.h b/cpp/hal/systimer.h index 0479ec5c..b4c4822d 100644 --- a/cpp/hal/systimer.h +++ b/cpp/hal/systimer.h @@ -29,8 +29,6 @@ class PlatformSpecificTimer virtual void Init() = 0; // Get system timer low byte virtual uint32_t GetTimerLow() = 0; - // Get system timer high byte - virtual uint32_t GetTimerHigh() = 0; // Sleep for N nanoseconds virtual void SleepNsec(uint32_t nsec) = 0; // Sleep for N microseconds @@ -48,8 +46,6 @@ class SysTimer static void Init(); // Get system timer low byte static uint32_t GetTimerLow(); - // Get system timer high byte - static uint32_t GetTimerHigh(); // Sleep for N nanoseconds static void SleepNsec(uint32_t nsec); // Sleep for N microseconds @@ -57,7 +53,6 @@ class SysTimer private: static bool initialized; - static bool is_allwinnner; static bool is_raspberry; static std::unique_ptr systimer_ptr; diff --git a/cpp/hal/systimer_raspberry.cpp b/cpp/hal/systimer_raspberry.cpp index 8814ea02..76da6abf 100644 --- a/cpp/hal/systimer_raspberry.cpp +++ b/cpp/hal/systimer_raspberry.cpp @@ -92,16 +92,6 @@ uint32_t SysTimer_Raspberry::GetTimerLow() return systaddr[SYST_CLO]; } -//--------------------------------------------------------------------------- -// -// Get system timer high byte -// -//--------------------------------------------------------------------------- -uint32_t SysTimer_Raspberry::GetTimerHigh() -{ - return systaddr[SYST_CHI]; -} - //--------------------------------------------------------------------------- // // Sleep in nanoseconds diff --git a/cpp/hal/systimer_raspberry.h b/cpp/hal/systimer_raspberry.h index 809d8229..e5ba2197 100644 --- a/cpp/hal/systimer_raspberry.h +++ b/cpp/hal/systimer_raspberry.h @@ -32,8 +32,6 @@ class SysTimer_Raspberry : public PlatformSpecificTimer void Init() override; // Get system timer low byte uint32_t GetTimerLow() override; - // Get system timer high byte - uint32_t GetTimerHigh() override; // Sleep for N nanoseconds void SleepNsec(uint32_t nsec) override; // Sleep for N microseconds diff --git a/cpp/test/gpiobus_raspberry_test.cpp b/cpp/test/gpiobus_raspberry_test.cpp index 5a94d670..03184557 100644 --- a/cpp/test/gpiobus_raspberry_test.cpp +++ b/cpp/test/gpiobus_raspberry_test.cpp @@ -219,16 +219,3 @@ TEST(GpiobusRaspberry, GetREQ) bus.Acquire(); EXPECT_EQ(false, bus.GetREQ()); } - -TEST(GpiobusRaspberry, GetDP) -{ - SetableGpiobusRaspberry bus; - - bus.TestSetGpios(0x00); - bus.TestSetGpioPin(PIN_DP, true); - bus.Acquire(); - EXPECT_EQ(true, bus.GetDP()); - bus.TestSetGpioPin(PIN_DP, false); - bus.Acquire(); - EXPECT_EQ(false, bus.GetDP()); -} diff --git a/cpp/test/mocks.h b/cpp/test/mocks.h index cc761802..3fefdb40 100644 --- a/cpp/test/mocks.h +++ b/cpp/test/mocks.h @@ -53,7 +53,6 @@ public: MOCK_METHOD(void, SetENB, (bool), (override)); MOCK_METHOD(uint8_t, GetDAT, (), (override)); MOCK_METHOD(void, SetDAT, (uint8_t), (override)); - MOCK_METHOD(bool, GetDP, (), (const override)); MOCK_METHOD(uint32_t, Acquire, (), (override)); MOCK_METHOD(int, CommandHandShake, (vector&), (override)); MOCK_METHOD(int, ReceiveHandShake, (uint8_t *, int), (override)); @@ -61,13 +60,11 @@ public: MOCK_METHOD(bool, GetSignal, (int), (const override)); MOCK_METHOD(void, SetSignal, (int, bool), (override)); MOCK_METHOD(bool, PollSelectEvent, (), (override)); - MOCK_METHOD(void, ClearSelectEvent, (), (override)); MOCK_METHOD(unique_ptr, GetSample, (uint64_t), (override)); MOCK_METHOD(void, PinConfig, (int, int), (override)); MOCK_METHOD(void, PullConfig, (int , int ), (override)); MOCK_METHOD(void, SetControl, (int , bool ), (override)); MOCK_METHOD(void, SetMode, (int , int ), (override)); - MOCK_METHOD(int, GetMode, (int ), (override)); MockBus() = default; ~MockBus() override = default;