Use standard C++ timer for long timeouts (#1327), remove unused code (#1328)

* Replace timer in WaitSignal()

' Remove unused code

* Remove unused file
This commit is contained in:
Uwe Seimet 2023-11-14 16:03:25 +01:00 committed by Daniel Markstedt
parent 6a1e0f8669
commit 31be1b3e8f
18 changed files with 37 additions and 149 deletions

View File

@ -60,23 +60,28 @@ const char* BUS::GetPhaseStrRaw(phase_t current_phase) {
return it != phase_str_mapping.end() ? it->second : "INVALID"; 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 // |MSG|C/D|I/O| Phase
// Reference Table 8: https://www.staff.uni-mainz.de/tacke/scsi/SCSI2-06.html // | 0 | 0 | 0 | DATA OUT
// This determines the phase based upon the Msg, C/D and I/O signals. // | 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<phase_t, 8> BUS::phase_table = { const array<phase_t, 8> BUS::phase_table = {
// | MSG|C/D|I/O | phase_t::dataout,
phase_t::dataout, // | 0 | 0 | 0 | phase_t::datain,
phase_t::datain, // | 0 | 0 | 1 | phase_t::command,
phase_t::command, // | 0 | 1 | 0 | phase_t::status,
phase_t::status, // | 0 | 1 | 1 | phase_t::reserved,
phase_t::reserved, // | 1 | 0 | 0 | phase_t::reserved,
phase_t::reserved, // | 1 | 0 | 1 | phase_t::msgout,
phase_t::msgout, // | 1 | 1 | 0 | phase_t::msgin
phase_t::msgin // | 1 | 1 | 1 |
}; };
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------

View File

@ -68,8 +68,7 @@ class BUS : public PinControl
// Operation modes definition // Operation modes definition
enum class mode_e { enum class mode_e {
TARGET = 0, TARGET = 0,
INITIATOR = 1, INITIATOR = 1
MONITOR = 2,
}; };
static int GetCommandByteCount(uint8_t); static int GetCommandByteCount(uint8_t);
@ -86,7 +85,6 @@ class BUS : public PinControl
// Get the string phase name, based upon the raw data // Get the string phase name, based upon the raw data
static const char *GetPhaseStrRaw(phase_t current_phase); static const char *GetPhaseStrRaw(phase_t current_phase);
virtual int GetMode(int pin) = 0;
virtual uint32_t Acquire() = 0; virtual uint32_t Acquire() = 0;
virtual unique_ptr<DataSample> GetSample(uint64_t timestamp = 0) = 0; virtual unique_ptr<DataSample> GetSample(uint64_t timestamp = 0) = 0;
@ -97,9 +95,6 @@ class BUS : public PinControl
// SEL signal event polling // SEL signal event polling
virtual bool PollSelectEvent() = 0; virtual bool PollSelectEvent() = 0;
// Clear SEL signal event
virtual void ClearSelectEvent() = 0;
virtual bool GetSignal(int pin) const = 0; virtual bool GetSignal(int pin) const = 0;
// Get SCSI input signal value // Get SCSI input signal value
virtual void SetSignal(int pin, bool ast) = 0; virtual void SetSignal(int pin, bool ast) = 0;

View File

@ -31,7 +31,6 @@ class DataSample
virtual bool GetREQ() const = 0; virtual bool GetREQ() const = 0;
virtual bool GetACT() const = 0; virtual bool GetACT() const = 0;
virtual uint8_t GetDAT() const = 0; virtual uint8_t GetDAT() const = 0;
virtual bool GetDP() const = 0;
virtual uint32_t GetRawCapture() const = 0; virtual uint32_t GetRawCapture() const = 0;

View File

@ -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"

View File

@ -74,10 +74,6 @@ class DataSample_Raspberry final : public DataSample
{ {
return GetSignal(PIN_ACT); return GetSignal(PIN_ACT);
} }
bool GetDP() const override
{
return GetSignal(PIN_DP);
}
uint8_t GetDAT() const override uint8_t GetDAT() const override
{ {
uint8_t ret_val = 0; uint8_t ret_val = 0;
@ -106,4 +102,4 @@ class DataSample_Raspberry final : public DataSample
private: private:
uint32_t data = 0; uint32_t data = 0;
}; };

View File

@ -1,10 +1,11 @@
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
// //
// SCSI Target Emulator PiSCSI // SCSI Target Emulator PiSCSI
// for Raspberry Pi // for Raspberry Pi
// //
// Powered by XM6 TypeG Technology. // Powered by XM6 TypeG Technology.
// Copyright (C) 2016-2020 GIMONS // Copyright (C) 2016-2020 GIMONS
// Copyright (C) 2023 Uwe Seimet
// //
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
@ -18,6 +19,7 @@
#ifdef __linux__ #ifdef __linux__
#include <sys/epoll.h> #include <sys/epoll.h>
#endif #endif
#include <chrono>
using namespace std; using namespace std;
@ -403,42 +405,23 @@ bool GPIOBUS::PollSelectEvent()
#endif #endif
} }
//---------------------------------------------------------------------------
//
// Cancel SEL signal event
//
//---------------------------------------------------------------------------
void GPIOBUS::ClearSelectEvent()
{
GPIO_FUNCTION_TRACE
}
//---------------------------------------------------------------------------
//
// Wait for signal change
//
//---------------------------------------------------------------------------
bool GPIOBUS::WaitSignal(int pin, bool ast) bool GPIOBUS::WaitSignal(int pin, bool ast)
{ {
// Get current time const auto now = chrono::steady_clock::now();
const uint32_t now = SysTimer::GetTimerLow();
// Calculate timeout (3000ms)
const uint32_t timeout = 3000 * 1000;
// Wait up to 3 s
do { do {
// Immediately upon receiving a reset
Acquire(); Acquire();
if (GetRST()) {
return false;
}
// Check for the signal edge
if (GetSignal(pin) == ast) { if (GetSignal(pin) == ast) {
return true; 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::seconds>(chrono::steady_clock::now() - now).count()) < 3);
return false; return false;
} }

View File

@ -182,8 +182,6 @@ class GPIOBUS : public BUS
// SEL signal event polling // SEL signal event polling
bool PollSelectEvent() override; bool PollSelectEvent() override;
// Clear SEL signal event
void ClearSelectEvent() override;
protected: protected:
virtual void MakeTable() = 0; virtual void MakeTable() = 0;

View File

@ -644,17 +644,6 @@ void GPIOBUS_Raspberry::SetDAT(uint8_t dat)
#endif // SIGNAL_CONTROL_MODE #endif // SIGNAL_CONTROL_MODE
} }
bool GPIOBUS_Raspberry::GetDP() const
{
return GetSignal(PIN_DP);
}
//---------------------------------------------------------------------------
//
// Create work table
//
//---------------------------------------------------------------------------
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
// //
// Signal table // Signal table

View File

@ -137,8 +137,6 @@ class GPIOBUS_Raspberry : public GPIOBUS
// Set REQ signal // Set REQ signal
void SetREQ(bool ast) override; void SetREQ(bool ast) override;
bool GetDP() const override;
// Get DAT signal // Get DAT signal
uint8_t GetDAT() override; uint8_t GetDAT() override;
// Set DAT signal // Set DAT signal
@ -174,12 +172,6 @@ class GPIOBUS_Raspberry : public GPIOBUS
// Set Control Signal // Set Control Signal
void SetMode(int pin, int mode) override; void SetMode(int pin, int mode) override;
// Set SCSI I/O mode // 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; bool GetSignal(int pin) const override;
// Get SCSI input signal value // Get SCSI input signal value
void SetSignal(int pin, bool ast) override; void SetSignal(int pin, bool ast) override;

View File

@ -372,11 +372,6 @@ void GPIOBUS_Virtual::SetREQ(bool ast)
SetSignal(PIN_REQ, ast); SetSignal(PIN_REQ, ast);
} }
bool GPIOBUS_Virtual::GetDP() const
{
return GetSignal(PIN_DP);
}
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
// //
// Get data signals // Get data signals

View File

@ -97,8 +97,6 @@ class GPIOBUS_Virtual final : public GPIOBUS
void SetREQ(bool ast) override; void SetREQ(bool ast) override;
// Set REQ signal // Set REQ signal
bool GetDP() const override;
bool WaitREQ(bool ast) override bool WaitREQ(bool ast) override
{ {
return WaitSignal(PIN_REQ, ast); return WaitSignal(PIN_REQ, ast);
@ -120,12 +118,6 @@ class GPIOBUS_Virtual final : public GPIOBUS
// Set Control Signal // Set Control Signal
void SetMode(int pin, int mode) override; void SetMode(int pin, int mode) override;
// Set SCSI I/O mode // 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; bool GetSignal(int pin) const override;
// Get SCSI input signal value // Get SCSI input signal value
void SetSignal(int pin, bool ast) override; void SetSignal(int pin, bool ast) override;

View File

@ -52,9 +52,6 @@ class PinControl
// Set ENB signal // Set ENB signal
virtual void SetENB(bool ast) = 0; virtual void SetENB(bool ast) = 0;
// Get parity signal
virtual bool GetDP() const = 0;
// GPIO pin direction setting // GPIO pin direction setting
virtual void PinConfig(int pin, int mode) = 0; virtual void PinConfig(int pin, int mode) = 0;
// GPIO pin pull up/down resistor setting // GPIO pin pull up/down resistor setting
@ -65,4 +62,4 @@ class PinControl
PinControl() = default; PinControl() = default;
virtual ~PinControl() = default; virtual ~PinControl() = default;
}; };

View File

@ -43,12 +43,6 @@ uint32_t SysTimer::GetTimerLow()
return systimer_ptr->GetTimerLow(); return systimer_ptr->GetTimerLow();
} }
// Get system timer high byte
uint32_t SysTimer::GetTimerHigh()
{
return systimer_ptr->GetTimerHigh();
}
// Sleep for N nanoseconds // Sleep for N nanoseconds
void SysTimer::SleepNsec(uint32_t nsec) void SysTimer::SleepNsec(uint32_t nsec)
{ {

View File

@ -29,8 +29,6 @@ class PlatformSpecificTimer
virtual void Init() = 0; virtual void Init() = 0;
// Get system timer low byte // Get system timer low byte
virtual uint32_t GetTimerLow() = 0; virtual uint32_t GetTimerLow() = 0;
// Get system timer high byte
virtual uint32_t GetTimerHigh() = 0;
// Sleep for N nanoseconds // Sleep for N nanoseconds
virtual void SleepNsec(uint32_t nsec) = 0; virtual void SleepNsec(uint32_t nsec) = 0;
// Sleep for N microseconds // Sleep for N microseconds
@ -48,8 +46,6 @@ class SysTimer
static void Init(); static void Init();
// Get system timer low byte // Get system timer low byte
static uint32_t GetTimerLow(); static uint32_t GetTimerLow();
// Get system timer high byte
static uint32_t GetTimerHigh();
// Sleep for N nanoseconds // Sleep for N nanoseconds
static void SleepNsec(uint32_t nsec); static void SleepNsec(uint32_t nsec);
// Sleep for N microseconds // Sleep for N microseconds
@ -57,7 +53,6 @@ class SysTimer
private: private:
static bool initialized; static bool initialized;
static bool is_allwinnner;
static bool is_raspberry; static bool is_raspberry;
static std::unique_ptr<PlatformSpecificTimer> systimer_ptr; static std::unique_ptr<PlatformSpecificTimer> systimer_ptr;

View File

@ -92,16 +92,6 @@ uint32_t SysTimer_Raspberry::GetTimerLow()
return systaddr[SYST_CLO]; return systaddr[SYST_CLO];
} }
//---------------------------------------------------------------------------
//
// Get system timer high byte
//
//---------------------------------------------------------------------------
uint32_t SysTimer_Raspberry::GetTimerHigh()
{
return systaddr[SYST_CHI];
}
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
// //
// Sleep in nanoseconds // Sleep in nanoseconds

View File

@ -32,8 +32,6 @@ class SysTimer_Raspberry : public PlatformSpecificTimer
void Init() override; void Init() override;
// Get system timer low byte // Get system timer low byte
uint32_t GetTimerLow() override; uint32_t GetTimerLow() override;
// Get system timer high byte
uint32_t GetTimerHigh() override;
// Sleep for N nanoseconds // Sleep for N nanoseconds
void SleepNsec(uint32_t nsec) override; void SleepNsec(uint32_t nsec) override;
// Sleep for N microseconds // Sleep for N microseconds

View File

@ -219,16 +219,3 @@ TEST(GpiobusRaspberry, GetREQ)
bus.Acquire(); bus.Acquire();
EXPECT_EQ(false, bus.GetREQ()); 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());
}

View File

@ -53,7 +53,6 @@ public:
MOCK_METHOD(void, SetENB, (bool), (override)); MOCK_METHOD(void, SetENB, (bool), (override));
MOCK_METHOD(uint8_t, GetDAT, (), (override)); MOCK_METHOD(uint8_t, GetDAT, (), (override));
MOCK_METHOD(void, SetDAT, (uint8_t), (override)); MOCK_METHOD(void, SetDAT, (uint8_t), (override));
MOCK_METHOD(bool, GetDP, (), (const override));
MOCK_METHOD(uint32_t, Acquire, (), (override)); MOCK_METHOD(uint32_t, Acquire, (), (override));
MOCK_METHOD(int, CommandHandShake, (vector<uint8_t>&), (override)); MOCK_METHOD(int, CommandHandShake, (vector<uint8_t>&), (override));
MOCK_METHOD(int, ReceiveHandShake, (uint8_t *, int), (override)); MOCK_METHOD(int, ReceiveHandShake, (uint8_t *, int), (override));
@ -61,13 +60,11 @@ public:
MOCK_METHOD(bool, GetSignal, (int), (const override)); MOCK_METHOD(bool, GetSignal, (int), (const override));
MOCK_METHOD(void, SetSignal, (int, bool), (override)); MOCK_METHOD(void, SetSignal, (int, bool), (override));
MOCK_METHOD(bool, PollSelectEvent, (), (override)); MOCK_METHOD(bool, PollSelectEvent, (), (override));
MOCK_METHOD(void, ClearSelectEvent, (), (override));
MOCK_METHOD(unique_ptr<DataSample>, GetSample, (uint64_t), (override)); MOCK_METHOD(unique_ptr<DataSample>, GetSample, (uint64_t), (override));
MOCK_METHOD(void, PinConfig, (int, int), (override)); MOCK_METHOD(void, PinConfig, (int, int), (override));
MOCK_METHOD(void, PullConfig, (int , int ), (override)); MOCK_METHOD(void, PullConfig, (int , int ), (override));
MOCK_METHOD(void, SetControl, (int , bool ), (override)); MOCK_METHOD(void, SetControl, (int , bool ), (override));
MOCK_METHOD(void, SetMode, (int , int ), (override)); MOCK_METHOD(void, SetMode, (int , int ), (override));
MOCK_METHOD(int, GetMode, (int ), (override));
MockBus() = default; MockBus() = default;
~MockBus() override = default; ~MockBus() override = default;