Remove non-working Banana Pi code (#1252)

* Remove non-working Banana Pi code

* Remove SonarQube suppressions which can be resolved by a code update

* Update device detection
This commit is contained in:
Uwe Seimet 2023-10-22 17:29:26 +02:00 committed by GitHub
parent 2acb742043
commit 43088ab3bc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
29 changed files with 103 additions and 2890 deletions

View File

@ -32,16 +32,6 @@ jobs:
with:
connect-type: "STANDARD"
aibom:
uses: PiSCSI/piscsi/.github/workflows/arm_cross_compile.yml@develop
with:
connect-type: "AIBOM"
gamernium:
uses: PiSCSI/piscsi/.github/workflows/arm_cross_compile.yml@develop
with:
connect-type: "GAMERNIUM"
# The fullspec connection board is the most common
debug-fullspec:
uses: PiSCSI/piscsi/.github/workflows/arm_cross_compile.yml@develop

View File

@ -1,87 +0,0 @@
//---------------------------------------------------------------------------
//
// SCSI Target Emulator PiSCSI
// for Raspberry Pi
//
// Powered by XM6 TypeG Technology.
// Copyright (C) 2016-2020 GIMONS
//
//---------------------------------------------------------------------------
#pragma once
#include "hal/pi_defs/bpi-m2p.h"
#include <string>
//
// RaSCSI Adapter Aibom version
//
const std::string CONNECT_DESC = "AIBOM PRODUCTS version"; // Startup message
// Select signal control mode
const static int SIGNAL_CONTROL_MODE = 2; // SCSI positive logic specification
// Control signal output logic
#define ACT_ON ON // ACTIVE SIGNAL ON
#define ENB_ON ON // ENABLE SIGNAL ON
#define IND_IN OFF // INITIATOR SIGNAL INPUT
#define TAD_IN OFF // TARGET SIGNAL INPUT
#define DTD_IN OFF // DATA SIGNAL INPUT
// Control signal pin assignment (-1 means no control)
const static int PIN_ACT = 4; // ACTIVE
const static int PIN_ENB = 17; // ENABLE
const static int PIN_IND = 27; // INITIATOR CTRL DIRECTION
const static int PIN_TAD = -1; // TARGET CTRL DIRECTION
const static int PIN_DTD = 18; // DATA DIRECTION
// SCSI signal pin assignment
const static int PIN_DT0 = 6; // Data 0
const static int PIN_DT1 = 12; // Data 1
const static int PIN_DT2 = 13; // Data 2
const static int PIN_DT3 = 16; // Data 3
const static int PIN_DT4 = 19; // Data 4
const static int PIN_DT5 = 20; // Data 5
const static int PIN_DT6 = 26; // Data 6
const static int PIN_DT7 = 21; // Data 7
const static int PIN_DP = 5; // Data parity
const static int PIN_ATN = 22; // ATN
const static int PIN_RST = 25; // RST
const static int PIN_ACK = 10; // ACK
const static int PIN_REQ = 7; // REQ
const static int PIN_MSG = 9; // MSG
const static int PIN_CD = 11; // CD
const static int PIN_IO = 23; // IO
const static int PIN_BSY = 24; // BSY
const static int PIN_SEL = 8; // SEL
// Warning: The Allwinner/Banana Pi GPIO numbers DO NOT correspond to
// the Raspberry Pi GPIO numbers.
// For example, Pin 7 is GPIO4 on a Raspberry Pi. Its GPIO 6 on a Banana Pi
// For Banana Pi, the pins are specified by physical pin number, NOT GPIO number
// (The Macro's convert the pin number to logical BPi GPIO number)
const static int BPI_PIN_ACT = BPI_M2P_07; // ACTIVE
const static int BPI_PIN_ENB = BPI_M2P_11; // ENABLE
const static int BPI_PIN_IND = BPI_M2P_13; // INITIATOR CTRL DIRECTION
const static int BPI_PIN_TAD = -1; // TARGET CTRL DIRECTION
const static int BPI_PIN_DTD = BPI_M2P_12; // DATA DIRECTION
const static int BPI_PIN_DT0 = BPI_M2P_31; // Data 0
const static int BPI_PIN_DT1 = BPI_M2P_32; // Data 1
const static int BPI_PIN_DT2 = BPI_M2P_33; // Data 2
const static int BPI_PIN_DT3 = BPI_M2P_36; // Data 3
const static int BPI_PIN_DT4 = BPI_M2P_35; // Data 4
const static int BPI_PIN_DT5 = BPI_M2P_38; // Data 5
const static int BPI_PIN_DT6 = BPI_M2P_37; // Data 6
const static int BPI_PIN_DT7 = BPI_M2P_40; // Data 7
const static int BPI_PIN_DP = BPI_M2P_29; // Data parity
const static int BPI_PIN_ATN = BPI_M2P_15; // ATN
const static int BPI_PIN_RST = BPI_M2P_22; // RST
const static int BPI_PIN_ACK = BPI_M2P_19; // ACK
const static int BPI_PIN_REQ = BPI_M2P_26; // REQ
const static int BPI_PIN_MSG = BPI_M2P_21; // MSG
const static int BPI_PIN_CD = BPI_M2P_23; // CD
const static int BPI_PIN_IO = BPI_M2P_16; // IO
const static int BPI_PIN_BSY = BPI_M2P_18; // BSY
const static int BPI_PIN_SEL = BPI_M2P_24; // SEL

View File

@ -10,7 +10,6 @@
#pragma once
#include "hal/pi_defs/bpi-m2p.h"
#include <string>
//
@ -55,33 +54,3 @@ const static int PIN_CD = 24; // CD
const static int PIN_IO = 25; // IO
const static int PIN_BSY = 26; // BSY
const static int PIN_SEL = 27; // SEL
// Warning: The Allwinner/Banana Pi GPIO numbers DO NOT correspond to
// the Raspberry Pi GPIO numbers.
// For example, Pin 7 is GPIO4 on a Raspberry Pi. Its GPIO 6 on a Banana Pi
// For Banana Pi, the pins are specified by physical pin number, NOT GPIO number
// (The Macro's convert the pin number to logical BPi GPIO number)
const static int BPI_PIN_ACT = BPI_M2P_07; // ACTIVE
const static int BPI_PIN_ENB = BPI_M2P_29; // ENABLE
const static int BPI_PIN_IND = BPI_M2P_31; // INITIATOR CTRL DIRECTION
const static int BPI_PIN_TAD = BPI_M2P_26; // TARGET CTRL DIRECTION
const static int BPI_PIN_DTD = BPI_M2P_24; // DATA DIRECTION
const static int BPI_PIN_DT0 = BPI_M2P_19; // Data 0
const static int BPI_PIN_DT1 = BPI_M2P_23; // Data 1
const static int BPI_PIN_DT2 = BPI_M2P_32; // Data 2
const static int BPI_PIN_DT3 = BPI_M2P_33; // Data 3
const static int BPI_PIN_DT4 = BPI_M2P_08; // Data 4
const static int BPI_PIN_DT5 = BPI_M2P_10; // Data 5
const static int BPI_PIN_DT6 = BPI_M2P_36; // Data 6
const static int BPI_PIN_DT7 = BPI_M2P_11; // Data 7
const static int BPI_PIN_DP = BPI_M2P_12; // Data parity
const static int BPI_PIN_ATN = BPI_M2P_35; // ATN
const static int BPI_PIN_RST = BPI_M2P_38; // RST
const static int BPI_PIN_ACK = BPI_M2P_40; // ACK
const static int BPI_PIN_REQ = BPI_M2P_15; // REQ
const static int BPI_PIN_MSG = BPI_M2P_16; // MSG
const static int BPI_PIN_CD = BPI_M2P_18; // CD
const static int BPI_PIN_IO = BPI_M2P_22; // IO
const static int BPI_PIN_BSY = BPI_M2P_37; // BSY
const static int BPI_PIN_SEL = BPI_M2P_13; // SEL

View File

@ -1,87 +0,0 @@
//---------------------------------------------------------------------------
//
// SCSI Target Emulator PiSCSI
// for Raspberry Pi
//
// Powered by XM6 TypeG Technology.
// Copyright (C) 2016-2020 GIMONS
//
//---------------------------------------------------------------------------
#pragma once
#include "hal/pi_defs/bpi-m2p.h"
#include <string>
//
// RaSCSI Adapter GAMERnium.com version
//
const std::string CONNECT_DESC = "GAMERnium.com version"; // Startup message
// Select signal control mode
const static int SIGNAL_CONTROL_MODE = 0; // SCSI logical specification
// Control signal output logic
#define ACT_ON ON // ACTIVE SIGNAL ON
#define ENB_ON ON // ENABLE SIGNAL ON
#define IND_IN OFF // INITIATOR SIGNAL INPUT
#define TAD_IN OFF // TARGET SIGNAL INPUT
#define DTD_IN ON // DATA SIGNAL INPUT
// Control signal pin assignment (-1 means no control)
const static int PIN_ACT = 14; // ACTIVE
const static int PIN_ENB = 6; // ENABLE
const static int PIN_IND = 7; // INITIATOR CTRL DIRECTION
const static int PIN_TAD = 8; // TARGET CTRL DIRECTION
const static int PIN_DTD = 5; // DATA DIRECTION
// SCSI signal pin assignment
const static int PIN_DT0 = 21; // Data 0
const static int PIN_DT1 = 26; // Data 1
const static int PIN_DT2 = 20; // Data 2
const static int PIN_DT3 = 19; // Data 3
const static int PIN_DT4 = 16; // Data 4
const static int PIN_DT5 = 13; // Data 5
const static int PIN_DT6 = 12; // Data 6
const static int PIN_DT7 = 11; // Data 7
const static int PIN_DP = 25; // Data parity
const static int PIN_ATN = 10; // ATN
const static int PIN_RST = 22; // RST
const static int PIN_ACK = 24; // ACK
const static int PIN_REQ = 15; // REQ
const static int PIN_MSG = 17; // MSG
const static int PIN_CD = 18; // CD
const static int PIN_IO = 4; // IO
const static int PIN_BSY = 27; // BSY
const static int PIN_SEL = 23; // SEL
// Warning: The Allwinner/Banana Pi GPIO numbers DO NOT correspond to
// the Raspberry Pi GPIO numbers.
// For example, Pin 7 is GPIO4 on a Raspberry Pi. Its GPIO 6 on a Banana Pi
// For Banana Pi, the pins are specified by physical pin number, NOT GPIO number
// (The Macro's convert the pin number to logical BPi GPIO number)
const static int BPI_PIN_ACT = BPI_M2P_08; // ACTIVE
const static int BPI_PIN_ENB = BPI_M2P_31; // ENABLE
const static int BPI_PIN_IND = BPI_M2P_04; // INITIATOR CTRL DIRECTION
const static int BPI_PIN_TAD = BPI_M2P_24; // TARGET CTRL DIRECTION
const static int BPI_PIN_DTD = BPI_M2P_29; // DATA DIRECTION
const static int BPI_PIN_DT0 = BPI_M2P_40; // Data 0
const static int BPI_PIN_DT1 = BPI_M2P_37; // Data 1
const static int BPI_PIN_DT2 = BPI_M2P_38; // Data 2
const static int BPI_PIN_DT3 = BPI_M2P_35; // Data 3
const static int BPI_PIN_DT4 = BPI_M2P_36; // Data 4
const static int BPI_PIN_DT5 = BPI_M2P_33; // Data 5
const static int BPI_PIN_DT6 = BPI_M2P_32; // Data 6
const static int BPI_PIN_DT7 = BPI_M2P_23; // Data 7
const static int BPI_PIN_DP = BPI_M2P_22; // Data parity
const static int BPI_PIN_ATN = BPI_M2P_19; // ATN
const static int BPI_PIN_RST = BPI_M2P_15; // RST
const static int BPI_PIN_ACK = BPI_M2P_18; // ACK
const static int BPI_PIN_REQ = BPI_M2P_10; // REQ
const static int BPI_PIN_MSG = BPI_M2P_11; // MSG
const static int BPI_PIN_CD = BPI_M2P_12; // CD
const static int BPI_PIN_IO = BPI_M2P_07; // IO
const static int BPI_PIN_BSY = BPI_M2P_13; // BSY
const static int BPI_PIN_SEL = BPI_M2P_16; // SEL

View File

@ -10,7 +10,6 @@
#pragma once
#include "hal/pi_defs/bpi-m2p.h"
#include <string>
//
@ -55,33 +54,3 @@ const static int PIN_CD = 24; // CD
const static int PIN_IO = 25; // IO
const static int PIN_BSY = 26; // BSY
const static int PIN_SEL = 27; // SEL
// Warning: The Allwinner/Banana Pi GPIO numbers DO NOT correspond to
// the Raspberry Pi GPIO numbers.
// For example, Pin 7 is GPIO4 on a Raspberry Pi. Its GPIO 6 on a Banana Pi
// For Banana Pi, the pins are specified by physical pin number, NOT GPIO number
// (The Macro's convert the pin number to logical BPi GPIO number)
const static int BPI_PIN_ACT = BPI_M2P_07; // ACTIVE
const static int BPI_PIN_ENB = BPI_M2P_29; // ENABLE
const static int BPI_PIN_IND = -1; // INITIATOR CTRL DIRECTION
const static int BPI_PIN_TAD = -1; // TARGET CTRL DIRECTION
const static int BPI_PIN_DTD = -1; // DATA DIRECTION
const static int BPI_PIN_DT0 = BPI_M2P_19; // Data 0
const static int BPI_PIN_DT1 = BPI_M2P_23; // Data 1
const static int BPI_PIN_DT2 = BPI_M2P_32; // Data 2
const static int BPI_PIN_DT3 = BPI_M2P_33; // Data 3
const static int BPI_PIN_DT4 = BPI_M2P_08; // Data 4
const static int BPI_PIN_DT5 = BPI_M2P_10; // Data 5
const static int BPI_PIN_DT6 = BPI_M2P_36; // Data 6
const static int BPI_PIN_DT7 = BPI_M2P_11; // Data 7
const static int BPI_PIN_DP = BPI_M2P_12; // Data parity
const static int BPI_PIN_ATN = BPI_M2P_35; // ATN
const static int BPI_PIN_RST = BPI_M2P_38; // RST
const static int BPI_PIN_ACK = BPI_M2P_40; // ACK
const static int BPI_PIN_REQ = BPI_M2P_15; // REQ
const static int BPI_PIN_MSG = BPI_M2P_16; // MSG
const static int BPI_PIN_CD = BPI_M2P_18; // CD
const static int BPI_PIN_IO = BPI_M2P_22; // IO
const static int BPI_PIN_BSY = BPI_M2P_37; // BSY
const static int BPI_PIN_SEL = BPI_M2P_13; // SEL

View File

@ -1,64 +0,0 @@
//---------------------------------------------------------------------------
//
// SCSI Target Emulator PiSCSI
// for Raspberry Pi
//
// Copyright (C) 2022 akuker
//
// [ SCSI Bus Monitor ]
//
//---------------------------------------------------------------------------
#include "data_sample_bananam2p.h"
#include "hal/sunxi_utils.h"
#include <cstdint>
uint8_t DataSample_BananaM2p::GetDAT() const
{
uint8_t ret_val = 0;
ret_val |= GetSignal(BPI_PIN_DT0) ? 0x01 : 0x00; // NOSONAR: GCC 10 doesn't fully support std::byte
ret_val |= GetSignal(BPI_PIN_DT1) ? 0x02 : 0x00; // NOSONAR: GCC 10 doesn't fully support std::byte
ret_val |= GetSignal(BPI_PIN_DT2) ? 0x04 : 0x00; // NOSONAR: GCC 10 doesn't fully support std::byte
ret_val |= GetSignal(BPI_PIN_DT3) ? 0x08 : 0x00; // NOSONAR: GCC 10 doesn't fully support std::byte
ret_val |= GetSignal(BPI_PIN_DT4) ? 0x10 : 0x00; // NOSONAR: GCC 10 doesn't fully support std::byte
ret_val |= GetSignal(BPI_PIN_DT5) ? 0x20 : 0x00; // NOSONAR: GCC 10 doesn't fully support std::byte
ret_val |= GetSignal(BPI_PIN_DT6) ? 0x40 : 0x00; // NOSONAR: GCC 10 doesn't fully support std::byte
ret_val |= GetSignal(BPI_PIN_DT7) ? 0x80 : 0x00; // NOSONAR: GCC 10 doesn't fully support std::byte
return ret_val;
}
bool DataSample_BananaM2p::GetSignal(int pin) const
{
int bank = SunXI::GPIO_BANK(pin);
int num = SunXI::GPIO_NUM(pin);
return (bool)((data[bank] >> num) & 0x1);
}
// This will return the Banana Pi data in the "Raspberry Pi" data format.
uint32_t DataSample_BananaM2p::GetRawCapture() const
{
uint32_t rpi_data = 0;
rpi_data |= ((uint32_t)GetSignal(BPI_PIN_BSY)) << PIN_BSY;
rpi_data |= ((uint32_t)GetSignal(BPI_PIN_SEL)) << PIN_SEL;
rpi_data |= ((uint32_t)GetSignal(BPI_PIN_ATN)) << PIN_ATN;
rpi_data |= ((uint32_t)GetSignal(BPI_PIN_ACK)) << PIN_ACK;
rpi_data |= ((uint32_t)GetSignal(BPI_PIN_RST)) << PIN_RST;
rpi_data |= ((uint32_t)GetSignal(BPI_PIN_MSG)) << PIN_MSG;
rpi_data |= ((uint32_t)GetSignal(BPI_PIN_CD)) << PIN_CD;
rpi_data |= ((uint32_t)GetSignal(BPI_PIN_IO)) << PIN_IO;
rpi_data |= ((uint32_t)GetSignal(BPI_PIN_REQ)) << PIN_REQ;
rpi_data |= ((uint32_t)GetSignal(BPI_PIN_ACT)) << PIN_ACT;
rpi_data |= ((uint32_t)GetSignal(BPI_PIN_DP)) << PIN_DP;
rpi_data |= ((uint32_t)GetSignal(BPI_PIN_DT0)) << PIN_DT0;
rpi_data |= ((uint32_t)GetSignal(BPI_PIN_DT1)) << PIN_DT1;
rpi_data |= ((uint32_t)GetSignal(BPI_PIN_DT2)) << PIN_DT2;
rpi_data |= ((uint32_t)GetSignal(BPI_PIN_DT3)) << PIN_DT3;
rpi_data |= ((uint32_t)GetSignal(BPI_PIN_DT4)) << PIN_DT4;
rpi_data |= ((uint32_t)GetSignal(BPI_PIN_DT5)) << PIN_DT5;
rpi_data |= ((uint32_t)GetSignal(BPI_PIN_DT6)) << PIN_DT6;
rpi_data |= ((uint32_t)GetSignal(BPI_PIN_DT7)) << PIN_DT7;
return rpi_data;
}

View File

@ -1,94 +0,0 @@
//---------------------------------------------------------------------------
//
// SCSI Target Emulator PiSCSI
// for Raspberry Pi
//
// Copyright (C) 2022 akuker
//
// [ Logical representation of a single data sample ]
//
//---------------------------------------------------------------------------
#pragma once
#include "hal/data_sample.h"
#include "shared/scsi.h"
#include <array>
#if defined CONNECT_TYPE_STANDARD
#include "hal/connection_type/connection_standard.h"
#elif defined CONNECT_TYPE_FULLSPEC
#include "hal/connection_type/connection_fullspec.h"
#elif defined CONNECT_TYPE_AIBOM
#include "hal/connection_type/connection_aibom.h"
#elif defined CONNECT_TYPE_GAMERNIUM
#include "hal/connection_type/connection_gamernium.h"
#else
#error Invalid connection type or none specified
#endif
class DataSample_BananaM2p final : public DataSample
{
public:
bool GetSignal(int pin) const override;
bool GetBSY() const override
{
return GetSignal(BPI_PIN_BSY);
}
bool GetSEL() const override
{
return GetSignal(BPI_PIN_SEL);
}
bool GetATN() const override
{
return GetSignal(BPI_PIN_ATN);
}
bool GetACK() const override
{
return GetSignal(BPI_PIN_ACK);
}
bool GetRST() const override
{
return GetSignal(BPI_PIN_RST);
}
bool GetMSG() const override
{
return GetSignal(BPI_PIN_MSG);
}
bool GetCD() const override
{
return GetSignal(BPI_PIN_CD);
}
bool GetIO() const override
{
return GetSignal(BPI_PIN_IO);
}
bool GetREQ() const override
{
return GetSignal(BPI_PIN_REQ);
}
bool GetACT() const override
{
return GetSignal(BPI_PIN_ACT);
}
bool GetDP() const override
{
return GetSignal(BPI_PIN_DP);
}
uint8_t GetDAT() const override;
uint32_t GetRawCapture() const override;
DataSample_BananaM2p(const array<uint32_t, 12> &in_data, uint64_t in_timestamp)
: DataSample{in_timestamp}, data{in_data}
{
}
DataSample_BananaM2p() = default;
~DataSample_BananaM2p() override = default;
private:
array<uint32_t, 12> data = {0};
};

View File

@ -18,10 +18,6 @@
#include "hal/connection_type/connection_standard.h"
#elif defined CONNECT_TYPE_FULLSPEC
#include "hal/connection_type/connection_fullspec.h"
#elif defined CONNECT_TYPE_AIBOM
#include "hal/connection_type/connection_aibom.h"
#elif defined CONNECT_TYPE_GAMERNIUM
#include "hal/connection_type/connection_gamernium.h"
#else
#error Invalid connection type or none specified
#endif
@ -106,4 +102,4 @@ class DataSample_Raspberry final : public DataSample
private:
uint32_t data = 0;
};
};

View File

@ -6,15 +6,12 @@
// Powered by XM6 TypeG Technology.
// Copyright (C) 2016-2020 GIMONS
//
// [ GPIO-SCSI bus ]
//
//---------------------------------------------------------------------------
#include "hal/gpiobus.h"
#include "hal/sbc_version.h"
#include "hal/systimer.h"
#include <spdlog/spdlog.h>
#include <array>
#include <sys/ioctl.h>
#include <sys/mman.h>
#include <sys/time.h>
@ -393,12 +390,7 @@ bool GPIOBUS::PollSelectEvent()
#else
GPIO_FUNCTION_TRACE
spdlog::trace(__PRETTY_FUNCTION__);
errno = 0;
int prev_mode = -1;
if (SBC_Version::IsBananaPi()) {
prev_mode = GetMode(BPI_PIN_SEL);
SetMode(BPI_PIN_SEL, GPIO_IRQ_IN);
}
errno = 0;
if (epoll_event epev; epoll_wait(epfd, &epev, 1, -1) <= 0) {
spdlog::warn("epoll_wait failed");
@ -410,9 +402,6 @@ bool GPIOBUS::PollSelectEvent()
return false;
}
if (SBC_Version::IsBananaPi()) {
SetMode(BPI_PIN_SEL, prev_mode);
}
return true;
#endif
}
@ -435,10 +424,10 @@ void GPIOBUS::ClearSelectEvent()
bool GPIOBUS::WaitSignal(int pin, bool ast)
{
// Get current time
uint32_t now = SysTimer::GetTimerLow();
const uint32_t now = SysTimer::GetTimerLow();
// Calculate timeout (3000ms)
uint32_t timeout = 3000 * 1000;
const uint32_t timeout = 3000 * 1000;
do {
// Immediately upon receiving a reset

View File

@ -5,7 +5,6 @@
//
// Powered by XM6 TypeG Technology.
// Copyright (C) 2016-2020 GIMONS
// [ GPIO-SCSI bus ]
//
//---------------------------------------------------------------------------
@ -13,7 +12,6 @@
#include "hal/bus.h"
#include "shared/scsi.h"
#include <array>
#include <memory>
#include <vector>
@ -28,17 +26,11 @@
//---------------------------------------------------------------------------
//#define CONNECT_TYPE_STANDARD // Standard (SCSI logic, standard pin assignment)
//#define CONNECT_TYPE_FULLSPEC // Full spec (SCSI logic, standard pin assignment)
//#define CONNECT_TYPE_AIBOM // AIBOM version (positive logic, unique pin assignment)
//#define CONNECT_TYPE_GAMERNIUM // GAMERnium.com version (standard logic, unique pin assignment)
#if defined CONNECT_TYPE_STANDARD
#include "hal/connection_type/connection_standard.h"
#elif defined CONNECT_TYPE_FULLSPEC
#include "hal/connection_type/connection_fullspec.h"
#elif defined CONNECT_TYPE_AIBOM
#include "hal/connection_type/connection_aibom.h"
#elif defined CONNECT_TYPE_GAMERNIUM
#include "hal/connection_type/connection_gamernium.h"
#else
#error Invalid connection type or none specified
#endif
@ -176,11 +168,11 @@ class GPIOBUS : public BUS
bool Init(mode_e mode = mode_e::TARGET) override;
// Command receive handshake
int CommandHandShake(vector<uint8_t> &) override;
int CommandHandShake(vector<uint8_t>&) override;
// Data receive handshake
int ReceiveHandShake(uint8_t *buf, int count) override;
int ReceiveHandShake(uint8_t *, int) override;
// Data transmission handshake
int SendHandShake(uint8_t *buf, int count, int delay_after_bytes) override;
int SendHandShake(uint8_t *, int, int) override;
// SEL signal event polling
bool PollSelectEvent() override;
@ -208,13 +200,13 @@ class GPIOBUS : public BUS
virtual void DrvConfig(uint32_t drive) = 0;
// Operation mode
mode_e actmode = mode_e::TARGET; // NOSONAR: This protected so derived classes can access it
mode_e actmode = mode_e::TARGET;
#ifdef __linux__
// SEL signal event request
struct gpioevent_request selevreq = {}; // NOSONAR: This protected so derived classes can access it
struct gpioevent_request selevreq = {};
// epoll file descriptor
int epfd = 0; // NOSONAR: This is protected so derived classes can access it
int epfd = 0;
#endif
};

File diff suppressed because it is too large Load Diff

View File

@ -1,203 +0,0 @@
//---------------------------------------------------------------------------
//
// SCSI Target Emulator PiSCSI
// for Raspberry Pi
//
// Powered by XM6 TypeG Technology.
// Copyright (C) 2016-2020 GIMONS
// [ GPIO-SCSI bus ]
//
//---------------------------------------------------------------------------
#pragma once
#include "hal/data_sample_bananam2p.h"
#include "hal/gpiobus.h"
#include "hal/pi_defs/bpi-gpio.h"
#include "hal/sbc_version.h"
#include "hal/sunxi_utils.h"
#include "shared/scsi.h"
#include <map>
//---------------------------------------------------------------------------
//
// Class definition
//
//---------------------------------------------------------------------------
class GPIOBUS_BananaM2p : public GPIOBUS
{
public:
// Basic Functions
GPIOBUS_BananaM2p() = default;
~GPIOBUS_BananaM2p() override = default;
// Destructor
bool Init(mode_e mode = mode_e::TARGET) override;
void Cleanup() override;
void Reset() override;
//---------------------------------------------------------------------------
//
// Bus signal acquisition
//
//---------------------------------------------------------------------------
uint32_t Acquire() override;
void SetENB(bool ast) override;
// Set ENB signal
bool GetBSY() const override;
// Get BSY signal
void SetBSY(bool ast) override;
// Set BSY signal
bool GetSEL() const override;
// Get SEL signal
void SetSEL(bool ast) override;
// Set SEL signal
bool GetATN() const override;
// Get ATN signal
void SetATN(bool ast) override;
// Set ATN signal
bool GetACK() const override;
// Get ACK signal
void SetACK(bool ast) override;
// Set ACK signal
bool GetACT() const override;
// Get ACT signal
void SetACT(bool ast) override;
// Set ACT signal
bool GetRST() const override;
// Get RST signal
void SetRST(bool ast) override;
// Set RST signal
bool GetMSG() const override;
// Get MSG signal
void SetMSG(bool ast) override;
// Set MSG signal
bool GetCD() const override;
// Get CD signal
void SetCD(bool ast) override;
// Set CD signal
bool GetIO() override;
// Get IO signal
void SetIO(bool ast) override;
// Set IO signal
bool GetREQ() const override;
// Get REQ signal
void SetREQ(bool ast) override;
// Set REQ signal
bool GetDP() const override;
uint8_t GetDAT() override;
// Get DAT signal
void SetDAT(uint8_t dat) override;
// Set DAT signal
bool WaitREQ(bool ast) override
{
return WaitSignal(BPI_PIN_REQ, ast);
}
bool WaitACK(bool ast) override
{
return WaitSignal(BPI_PIN_ACK, ast);
}
// TODO: Restore these back to protected
// protected:
// SCSI I/O signal control
void MakeTable() override;
// Create work data
void SetControl(int pin, bool ast) override;
// Set Control Signal
void SetMode(int pin, int mode) override;
// Set SCSI I/O mode
int GetMode(int pin) override;
inline bool GetSignal(int pin) const override;
// Set SCSI output signal value
void SetSignal(int pin, bool ast) override;
// Interrupt control
// IRQ Disabled
void DisableIRQ() override;
// IRQ Enabled
void EnableIRQ() override;
// GPIO pin functionality settings
void PinConfig(int pin, int mode) override;
// GPIO pin direction setting
void PullConfig(int pin, int mode) override;
// GPIO pin pull up/down resistor setting
void PinSetSignal(int pin, bool ast) override;
// Set GPIO output signal
void DrvConfig(uint32_t drive) override;
// Set GPIO drive strength
unique_ptr<DataSample> GetSample(uint64_t timestamp) override
{
Acquire();
return make_unique<DataSample_BananaM2p>(signals, timestamp);
}
bool SetupSelEvent();
volatile uint32_t *gpio_map = nullptr;
// Timer control register
volatile uint32_t *tmr_ctrl;
array<uint32_t, 12> signals = {0}; // All bus signals
int sunxi_setup(void);
void sunxi_set_pullupdn(int gpio, int pud);
void sunxi_setup_gpio(int gpio, int direction, int pud);
void sunxi_output_gpio(int gpio, int value);
int sunxi_input_gpio(int gpio) const;
int bpi_found = -1;
volatile SunXI::sunxi_gpio_reg_t *pio_map;
volatile SunXI::sunxi_gpio_reg_t *r_pio_map;
volatile uint32_t *r_gpio_map;
uint8_t *gpio_mmap_reg;
uint32_t sunxi_capture_all_gpio();
void set_pullupdn(int gpio, int pud);
// These definitions are from c_gpio.c and should be removed at some point!!
const int SETUP_OK = 0;
SBC_Version::sbc_version_type sbc_version;
static const array<int, 19> SignalTable;
void InitializeGpio();
std::vector<int> gpio_banks;
// Note: These MUST be in order from bit 0 to bit 7 with parity as the last item in the array
const array<int, 9> pintbl = {BPI_PIN_DT0, BPI_PIN_DT1, BPI_PIN_DT2, BPI_PIN_DT3, BPI_PIN_DT4,
BPI_PIN_DT5, BPI_PIN_DT6, BPI_PIN_DT7, BPI_PIN_DP};
void sunxi_set_all_gpios(array<uint32_t, 12> &mask, array<uint32_t, 12> &value);
array<uint32_t, 12> gpio_data_masks = {0};
#if defined(__x86_64__) || defined(__X86__) || defined(__aarch64__)
// The SEL_EVENT functions need to do something to prevent SonarCloud from
// claiming they should be const
int dummy_var = 0;
#endif
};

View File

@ -1,51 +1,48 @@
//---------------------------------------------------------------------------
//
// SCSI Target Emulator PiSCSI
// for Raspberry Pi
// SCSI Target Emulator PiSCSI
// for Raspberry Pi
//
// Copyright (C) 2022 akuker
// [ GPIO bus factory ]
// Copyright (C) 2022 akuker
// Copyright (C) 2023 Uwe Seimet
//
//---------------------------------------------------------------------------
#include <memory>
#include "hal/gpiobus_bananam2p.h"
#include "hal/gpiobus_factory.h"
#include "hal/gpiobus_raspberry.h"
#include "hal/gpiobus_virtual.h"
#include "hal/sbc_version.h"
#include <unistd.h>
#include <spdlog/spdlog.h>
using namespace std;
unique_ptr<BUS> GPIOBUS_Factory::Create(BUS::mode_e mode)
{
unique_ptr<BUS> return_ptr;
unique_ptr<BUS> bus;
try {
// TODO Make the factory a friend of GPIOBUS and make the GPIOBUS constructor private
// so that clients cannot use it anymore but have to use the factory.
// Also make Init() private.
SBC_Version::Init();
if (SBC_Version::IsBananaPi()) {
spdlog::trace("Creating GPIOBUS_BananaM2p");
return_ptr = make_unique<GPIOBUS_BananaM2p>();
} else if (SBC_Version::IsRaspberryPi()) {
spdlog::trace("Creating GPIOBUS_Raspberry");
return_ptr = make_unique<GPIOBUS_Raspberry>();
if (SBC_Version::IsRaspberryPi()) {
if (getuid()) {
spdlog::error("GPIO bus access requires root permissions. Are you running as root?");
return nullptr;
}
bus = make_unique<GPIOBUS_Raspberry>();
} else {
spdlog::trace("Creating Virtual GPIOBUS");
return_ptr = make_unique<GPIOBUS_Virtual>();
bus = make_unique<GPIOBUS_Virtual>();
}
if (!return_ptr->Init(mode)) {
return nullptr;
if (bus->Init(mode)) {
bus->Reset();
}
return_ptr->Reset();
} catch (const invalid_argument&) {
spdlog::error("Exception while trying to initialize GPIO bus. Are you running as root?");
return_ptr = nullptr;
} catch (const invalid_argument& e) {
spdlog::error(string("Exception while trying to initialize GPIO bus: ") + e.what());
return nullptr;
}
return return_ptr;
return bus;
}

View File

@ -15,10 +15,10 @@
//
//---------------------------------------------------------------------------
#include <spdlog/spdlog.h>
#include "hal/gpiobus_raspberry.h"
#include "hal/gpiobus.h"
#include "hal/systimer.h"
#include "hal/log.h"
#include <map>
#include <cstring>
#ifdef __linux__
@ -185,7 +185,7 @@ bool GPIOBUS_Raspberry::Init(mode_e mode)
// GPIO chip open
fd = open("/dev/gpiochip0", 0);
if (fd == -1) {
LOGERROR("Unable to open /dev/gpiochip0. If PiSCSI is running, please shut it down first.")
spdlog::error("Unable to open /dev/gpiochip0. If PiSCSI is running, please shut it down first.");
return false;
}
@ -201,7 +201,7 @@ bool GPIOBUS_Raspberry::Init(mode_e mode)
// Get event request
if (ioctl(fd, GPIO_GET_LINEEVENT_IOCTL, &selevreq) == -1) {
LOGERROR("Unable to register event request. If PiSCSI is running, please shut it down first.")
spdlog::error("Unable to register event request. If PiSCSI is running, please shut it down first.");
close(fd);
return false;
}

View File

@ -162,9 +162,9 @@ class GPIOBUS_Raspberry : public GPIOBUS
protected:
// All bus signals
uint32_t signals = 0; // NOSONAR: Must be protected (not private) for testability
uint32_t signals = 0;
// GPIO input level
volatile uint32_t *level = nullptr; // NOSONAR: Must be protected (not private) for testability
volatile uint32_t *level = nullptr;
private:
// SCSI I/O signal control

View File

@ -6,8 +6,6 @@
// Powered by XM6 TypeG Technology.
// Copyright (C) 2016-2020 GIMONS
//
// [ GPIO-SCSI bus ]
//
//---------------------------------------------------------------------------
#include "hal/gpiobus_virtual.h"

View File

@ -5,7 +5,6 @@
//
// Powered by XM6 TypeG Technology.
// Copyright (C) 2016-2020 GIMONS
// [ GPIO-SCSI bus ]
//
//---------------------------------------------------------------------------

View File

@ -1,356 +0,0 @@
/*
Copyright (c) 2014-2017 Banana Pi
Updates Copyright (C) 2022 akuker
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#pragma once
const int GPIO_NOT_USED = -1;
const int GPIO_PA00 = 0;
const int GPIO_PA01 = 1;
const int GPIO_PA02 = 2;
const int GPIO_PA03 = 3;
const int GPIO_PA04 = 4;
const int GPIO_PA05 = 5;
const int GPIO_PA06 = 6;
const int GPIO_PA07 = 7;
const int GPIO_PA08 = 8;
const int GPIO_PA09 = 9;
const int GPIO_PA10 = 10;
const int GPIO_PA11 = 11;
const int GPIO_PA12 = 12;
const int GPIO_PA13 = 13;
const int GPIO_PA14 = 14;
const int GPIO_PA15 = 15;
const int GPIO_PA16 = 16;
const int GPIO_PA17 = 17;
const int GPIO_PA18 = 18;
const int GPIO_PA19 = 19;
const int GPIO_PA20 = 20;
const int GPIO_PA21 = 21;
const int GPIO_PA22 = 22;
const int GPIO_PA23 = 23;
const int GPIO_PA24 = 24;
const int GPIO_PA25 = 25;
const int GPIO_PA26 = 26;
const int GPIO_PA27 = 27;
const int GPIO_PA28 = 28;
const int GPIO_PA29 = 29;
const int GPIO_PA30 = 30;
const int GPIO_PA31 = 31;
const int GPIO_PB00 = 32;
const int GPIO_PB01 = 1 + GPIO_PB00;
const int GPIO_PB02 = 2 + GPIO_PB00;
const int GPIO_PB03 = 3 + GPIO_PB00;
const int GPIO_PB04 = 4 + GPIO_PB00;
const int GPIO_PB05 = 5 + GPIO_PB00;
const int GPIO_PB06 = 6 + GPIO_PB00;
const int GPIO_PB07 = 7 + GPIO_PB00;
const int GPIO_PB08 = 8 + GPIO_PB00;
const int GPIO_PB09 = 9 + GPIO_PB00;
const int GPIO_PB10 = 10 + GPIO_PB00;
const int GPIO_PB11 = 11 + GPIO_PB00;
const int GPIO_PB12 = 12 + GPIO_PB00;
const int GPIO_PB13 = 13 + GPIO_PB00;
const int GPIO_PB14 = 14 + GPIO_PB00;
const int GPIO_PB15 = 15 + GPIO_PB00;
const int GPIO_PB16 = 16 + GPIO_PB00;
const int GPIO_PB17 = 17 + GPIO_PB00;
const int GPIO_PB18 = 18 + GPIO_PB00;
const int GPIO_PB19 = 19 + GPIO_PB00;
const int GPIO_PB20 = 20 + GPIO_PB00;
const int GPIO_PB21 = 21 + GPIO_PB00;
const int GPIO_PB22 = 22 + GPIO_PB00;
const int GPIO_PB23 = 23 + GPIO_PB00;
const int GPIO_PB24 = 24 + GPIO_PB00;
const int GPIO_PB25 = 25 + GPIO_PB00;
const int GPIO_PB26 = 26 + GPIO_PB00;
const int GPIO_PB27 = 27 + GPIO_PB00;
const int GPIO_PB28 = 28 + GPIO_PB00;
const int GPIO_PB29 = 29 + GPIO_PB00;
const int GPIO_PB30 = 30 + GPIO_PB00;
const int GPIO_PB31 = 31 + GPIO_PB00;
const int GPIO_PC00 = 64;
const int GPIO_PC01 = 1 + GPIO_PC00;
const int GPIO_PC02 = 2 + GPIO_PC00;
const int GPIO_PC03 = 3 + GPIO_PC00;
const int GPIO_PC04 = 4 + GPIO_PC00;
const int GPIO_PC05 = 5 + GPIO_PC00;
const int GPIO_PC06 = 6 + GPIO_PC00;
const int GPIO_PC07 = 7 + GPIO_PC00;
const int GPIO_PC08 = 8 + GPIO_PC00;
const int GPIO_PC09 = 9 + GPIO_PC00;
const int GPIO_PC10 = 10 + GPIO_PC00;
const int GPIO_PC11 = 11 + GPIO_PC00;
const int GPIO_PC12 = 12 + GPIO_PC00;
const int GPIO_PC13 = 13 + GPIO_PC00;
const int GPIO_PC14 = 14 + GPIO_PC00;
const int GPIO_PC15 = 15 + GPIO_PC00;
const int GPIO_PC16 = 16 + GPIO_PC00;
const int GPIO_PC17 = 17 + GPIO_PC00;
const int GPIO_PC18 = 18 + GPIO_PC00;
const int GPIO_PC19 = 19 + GPIO_PC00;
const int GPIO_PC20 = 20 + GPIO_PC00;
const int GPIO_PC21 = 21 + GPIO_PC00;
const int GPIO_PC22 = 22 + GPIO_PC00;
const int GPIO_PC23 = 23 + GPIO_PC00;
const int GPIO_PC24 = 24 + GPIO_PC00;
const int GPIO_PC25 = 25 + GPIO_PC00;
const int GPIO_PC26 = 26 + GPIO_PC00;
const int GPIO_PC27 = 27 + GPIO_PC00;
const int GPIO_PC28 = 28 + GPIO_PC00;
const int GPIO_PC29 = 29 + GPIO_PC00;
const int GPIO_PC30 = 30 + GPIO_PC00;
const int GPIO_PC31 = 31 + GPIO_PC00;
const int GPIO_PD00 = 96;
const int GPIO_PD01 = 1 + GPIO_PD00;
const int GPIO_PD02 = 2 + GPIO_PD00;
const int GPIO_PD03 = 3 + GPIO_PD00;
const int GPIO_PD04 = 4 + GPIO_PD00;
const int GPIO_PD05 = 5 + GPIO_PD00;
const int GPIO_PD06 = 6 + GPIO_PD00;
const int GPIO_PD07 = 7 + GPIO_PD00;
const int GPIO_PD08 = 8 + GPIO_PD00;
const int GPIO_PD09 = 9 + GPIO_PD00;
const int GPIO_PD10 = 10 + GPIO_PD00;
const int GPIO_PD11 = 11 + GPIO_PD00;
const int GPIO_PD12 = 12 + GPIO_PD00;
const int GPIO_PD13 = 13 + GPIO_PD00;
const int GPIO_PD14 = 14 + GPIO_PD00;
const int GPIO_PD15 = 15 + GPIO_PD00;
const int GPIO_PD16 = 16 + GPIO_PD00;
const int GPIO_PD17 = 17 + GPIO_PD00;
const int GPIO_PD18 = 18 + GPIO_PD00;
const int GPIO_PD19 = 19 + GPIO_PD00;
const int GPIO_PD20 = 20 + GPIO_PD00;
const int GPIO_PD21 = 21 + GPIO_PD00;
const int GPIO_PD22 = 22 + GPIO_PD00;
const int GPIO_PD23 = 23 + GPIO_PD00;
const int GPIO_PD24 = 24 + GPIO_PD00;
const int GPIO_PD25 = 25 + GPIO_PD00;
const int GPIO_PD26 = 26 + GPIO_PD00;
const int GPIO_PD27 = 27 + GPIO_PD00;
const int GPIO_PD28 = 28 + GPIO_PD00;
const int GPIO_PD29 = 29 + GPIO_PD00;
const int GPIO_PD30 = 30 + GPIO_PD00;
const int GPIO_PD31 = 31 + GPIO_PD00;
const int GPIO_PE00 = 128;
const int GPIO_PE01 = 1 + GPIO_PE00;
const int GPIO_PE02 = 2 + GPIO_PE00;
const int GPIO_PE03 = 3 + GPIO_PE00;
const int GPIO_PE04 = 4 + GPIO_PE00;
const int GPIO_PE05 = 5 + GPIO_PE00;
const int GPIO_PE06 = 6 + GPIO_PE00;
const int GPIO_PE07 = 7 + GPIO_PE00;
const int GPIO_PE08 = 8 + GPIO_PE00;
const int GPIO_PE09 = 9 + GPIO_PE00;
const int GPIO_PE10 = 10 + GPIO_PE00;
const int GPIO_PE11 = 11 + GPIO_PE00;
const int GPIO_PE12 = 12 + GPIO_PE00;
const int GPIO_PE13 = 13 + GPIO_PE00;
const int GPIO_PE14 = 14 + GPIO_PE00;
const int GPIO_PE15 = 15 + GPIO_PE00;
const int GPIO_PE16 = 16 + GPIO_PE00;
const int GPIO_PE17 = 17 + GPIO_PE00;
const int GPIO_PE18 = 18 + GPIO_PE00;
const int GPIO_PE19 = 19 + GPIO_PE00;
const int GPIO_PE20 = 20 + GPIO_PE00;
const int GPIO_PE21 = 21 + GPIO_PE00;
const int GPIO_PE22 = 22 + GPIO_PE00;
const int GPIO_PE23 = 23 + GPIO_PE00;
const int GPIO_PE24 = 24 + GPIO_PE00;
const int GPIO_PE25 = 25 + GPIO_PE00;
const int GPIO_PE26 = 26 + GPIO_PE00;
const int GPIO_PE27 = 27 + GPIO_PE00;
const int GPIO_PE28 = 28 + GPIO_PE00;
const int GPIO_PE29 = 29 + GPIO_PE00;
const int GPIO_PE30 = 30 + GPIO_PE00;
const int GPIO_PE31 = 31 + GPIO_PE00;
const int GPIO_PG00 = 192;
const int GPIO_PG01 = 1 + GPIO_PG00;
const int GPIO_PG02 = 2 + GPIO_PG00;
const int GPIO_PG03 = 3 + GPIO_PG00;
const int GPIO_PG04 = 4 + GPIO_PG00;
const int GPIO_PG05 = 5 + GPIO_PG00;
const int GPIO_PG06 = 6 + GPIO_PG00;
const int GPIO_PG07 = 7 + GPIO_PG00;
const int GPIO_PG08 = 8 + GPIO_PG00;
const int GPIO_PG09 = 9 + GPIO_PG00;
const int GPIO_PG10 = 10 + GPIO_PG00;
const int GPIO_PG11 = 11 + GPIO_PG00;
const int GPIO_PG12 = 12 + GPIO_PG00;
const int GPIO_PG13 = 13 + GPIO_PG00;
const int GPIO_PG14 = 14 + GPIO_PG00;
const int GPIO_PG15 = 15 + GPIO_PG00;
const int GPIO_PG16 = 16 + GPIO_PG00;
const int GPIO_PG17 = 17 + GPIO_PG00;
const int GPIO_PG18 = 18 + GPIO_PG00;
const int GPIO_PG19 = 19 + GPIO_PG00;
const int GPIO_PG20 = 20 + GPIO_PG00;
const int GPIO_PG21 = 21 + GPIO_PG00;
const int GPIO_PG22 = 22 + GPIO_PG00;
const int GPIO_PG23 = 23 + GPIO_PG00;
const int GPIO_PG24 = 24 + GPIO_PG00;
const int GPIO_PG25 = 25 + GPIO_PG00;
const int GPIO_PG26 = 26 + GPIO_PG00;
const int GPIO_PG27 = 27 + GPIO_PG00;
const int GPIO_PG28 = 28 + GPIO_PG00;
const int GPIO_PG29 = 29 + GPIO_PG00;
const int GPIO_PG30 = 30 + GPIO_PG00;
const int GPIO_PG31 = 31 + GPIO_PG00;
const int GPIO_PH00 = 224;
const int GPIO_PH01 = 1 + GPIO_PH00;
const int GPIO_PH02 = 2 + GPIO_PH00;
const int GPIO_PH03 = 3 + GPIO_PH00;
const int GPIO_PH04 = 4 + GPIO_PH00;
const int GPIO_PH05 = 5 + GPIO_PH00;
const int GPIO_PH06 = 6 + GPIO_PH00;
const int GPIO_PH07 = 7 + GPIO_PH00;
const int GPIO_PH08 = 8 + GPIO_PH00;
const int GPIO_PH09 = 9 + GPIO_PH00;
const int GPIO_PH10 = 10 + GPIO_PH00;
const int GPIO_PH11 = 11 + GPIO_PH00;
const int GPIO_PH12 = 12 + GPIO_PH00;
const int GPIO_PH13 = 13 + GPIO_PH00;
const int GPIO_PH14 = 14 + GPIO_PH00;
const int GPIO_PH15 = 15 + GPIO_PH00;
const int GPIO_PH16 = 16 + GPIO_PH00;
const int GPIO_PH17 = 17 + GPIO_PH00;
const int GPIO_PH18 = 18 + GPIO_PH00;
const int GPIO_PH19 = 19 + GPIO_PH00;
const int GPIO_PH20 = 20 + GPIO_PH00;
const int GPIO_PH21 = 21 + GPIO_PH00;
const int GPIO_PH22 = 22 + GPIO_PH00;
const int GPIO_PH23 = 23 + GPIO_PH00;
const int GPIO_PH24 = 24 + GPIO_PH00;
const int GPIO_PH25 = 25 + GPIO_PH00;
const int GPIO_PH26 = 26 + GPIO_PH00;
const int GPIO_PH27 = 27 + GPIO_PH00;
const int GPIO_PH28 = 28 + GPIO_PH00;
const int GPIO_PH29 = 29 + GPIO_PH00;
const int GPIO_PH30 = 30 + GPIO_PH00;
const int GPIO_PH31 = 31 + GPIO_PH00;
const int GPIO_PI00 = 256;
const int GPIO_PI01 = 1 + GPIO_PI00;
const int GPIO_PI02 = 2 + GPIO_PI00;
const int GPIO_PI03 = 3 + GPIO_PI00;
const int GPIO_PI04 = 4 + GPIO_PI00;
const int GPIO_PI05 = 5 + GPIO_PI00;
const int GPIO_PI06 = 6 + GPIO_PI00;
const int GPIO_PI07 = 7 + GPIO_PI00;
const int GPIO_PI08 = 8 + GPIO_PI00;
const int GPIO_PI09 = 9 + GPIO_PI00;
const int GPIO_PI10 = 10 + GPIO_PI00;
const int GPIO_PI11 = 11 + GPIO_PI00;
const int GPIO_PI12 = 12 + GPIO_PI00;
const int GPIO_PI13 = 13 + GPIO_PI00;
const int GPIO_PI14 = 14 + GPIO_PI00;
const int GPIO_PI15 = 15 + GPIO_PI00;
const int GPIO_PI16 = 16 + GPIO_PI00;
const int GPIO_PI17 = 17 + GPIO_PI00;
const int GPIO_PI18 = 18 + GPIO_PI00;
const int GPIO_PI19 = 19 + GPIO_PI00;
const int GPIO_PI20 = 20 + GPIO_PI00;
const int GPIO_PI21 = 21 + GPIO_PI00;
const int GPIO_PI22 = 22 + GPIO_PI00;
const int GPIO_PI23 = 23 + GPIO_PI00;
const int GPIO_PI24 = 24 + GPIO_PI00;
const int GPIO_PI25 = 25 + GPIO_PI00;
const int GPIO_PI26 = 26 + GPIO_PI00;
const int GPIO_PI27 = 27 + GPIO_PI00;
const int GPIO_PI28 = 28 + GPIO_PI00;
const int GPIO_PI29 = 29 + GPIO_PI00;
const int GPIO_PI30 = 30 + GPIO_PI00;
const int GPIO_PI31 = 31 + GPIO_PI00;
const int GPIO_PL00 = 352;
const int GPIO_PL01 = 1 + GPIO_PL00;
const int GPIO_PL02 = 2 + GPIO_PL00;
const int GPIO_PL03 = 3 + GPIO_PL00;
const int GPIO_PL04 = 4 + GPIO_PL00;
const int GPIO_PL05 = 5 + GPIO_PL00;
const int GPIO_PL06 = 6 + GPIO_PL00;
const int GPIO_PL07 = 7 + GPIO_PL00;
const int GPIO_PL08 = 8 + GPIO_PL00;
const int GPIO_PL09 = 9 + GPIO_PL00;
const int GPIO_PL10 = 10 + GPIO_PL00;
const int GPIO_PL11 = 11 + GPIO_PL00;
const int GPIO_PL12 = 12 + GPIO_PL00;
const int GPIO_PL13 = 13 + GPIO_PL00;
const int GPIO_PL14 = 14 + GPIO_PL00;
const int GPIO_PL15 = 15 + GPIO_PL00;
const int GPIO_PL16 = 16 + GPIO_PL00;
const int GPIO_PL17 = 17 + GPIO_PL00;
const int GPIO_PL18 = 18 + GPIO_PL00;
const int GPIO_PL19 = 19 + GPIO_PL00;
const int GPIO_PL20 = 20 + GPIO_PL00;
const int GPIO_PL21 = 21 + GPIO_PL00;
const int GPIO_PL22 = 22 + GPIO_PL00;
const int GPIO_PL23 = 23 + GPIO_PL00;
const int GPIO_PL24 = 24 + GPIO_PL00;
const int GPIO_PL25 = 25 + GPIO_PL00;
const int GPIO_PL26 = 26 + GPIO_PL00;
const int GPIO_PL27 = 27 + GPIO_PL00;
const int GPIO_PL28 = 28 + GPIO_PL00;
const int GPIO_PL29 = 29 + GPIO_PL00;
const int GPIO_PL30 = 30 + GPIO_PL00;
const int GPIO_PL31 = 31 + GPIO_PL00;
const int GPIO_PM00 = 384;
const int GPIO_PM01 = 1 + GPIO_PM00;
const int GPIO_PM02 = 2 + GPIO_PM00;
const int GPIO_PM03 = 3 + GPIO_PM00;
const int GPIO_PM04 = 4 + GPIO_PM00;
const int GPIO_PM05 = 5 + GPIO_PM00;
const int GPIO_PM06 = 6 + GPIO_PM00;
const int GPIO_PM07 = 7 + GPIO_PM00;
const int GPIO_PM08 = 8 + GPIO_PM00;
const int GPIO_PM09 = 9 + GPIO_PM00;
const int GPIO_PM10 = 10 + GPIO_PM00;
const int GPIO_PM11 = 11 + GPIO_PM00;
const int GPIO_PM12 = 12 + GPIO_PM00;
const int GPIO_PM13 = 13 + GPIO_PM00;
const int GPIO_PM14 = 14 + GPIO_PM00;
const int GPIO_PM15 = 15 + GPIO_PM00;
const int GPIO_PM16 = 16 + GPIO_PM00;
const int GPIO_PM17 = 17 + GPIO_PM00;
const int GPIO_PM18 = 18 + GPIO_PM00;
const int GPIO_PM19 = 19 + GPIO_PM00;
const int GPIO_PM20 = 20 + GPIO_PM00;
const int GPIO_PM21 = 21 + GPIO_PM00;
const int GPIO_PM22 = 22 + GPIO_PM00;
const int GPIO_PM23 = 23 + GPIO_PM00;
const int GPIO_PM24 = 24 + GPIO_PM00;
const int GPIO_PM25 = 25 + GPIO_PM00;
const int GPIO_PM26 = 26 + GPIO_PM00;
const int GPIO_PM27 = 27 + GPIO_PM00;
const int GPIO_PM28 = 28 + GPIO_PM00;
const int GPIO_PM29 = 29 + GPIO_PM00;
const int GPIO_PM30 = 30 + GPIO_PM00;
const int GPIO_PM31 = 31 + GPIO_PM00;

View File

@ -1,71 +0,0 @@
/*
Copyright (c) 2014-2017 Banana Pi
Updates Copyright (C) 2022 akuker
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#pragma once
#include "hal/pi_defs/bpi-gpio.h"
/* The following define the mapping of the Banana Pi CPU pins to the logical
* GPIO numbers. The GPIO numbers are used by the software to set/configure
* the CPU registers. */
const int BPI_M2P_01 = GPIO_NOT_USED;
const int BPI_M2P_03 = GPIO_PA12;
const int BPI_M2P_05 = GPIO_PA11;
const int BPI_M2P_07 = GPIO_PA06;
const int BPI_M2P_09 = GPIO_NOT_USED;
const int BPI_M2P_11 = GPIO_PA01;
const int BPI_M2P_13 = GPIO_PA00;
const int BPI_M2P_15 = GPIO_PA03;
const int BPI_M2P_17 = GPIO_NOT_USED;
const int BPI_M2P_19 = GPIO_PC00;
const int BPI_M2P_21 = GPIO_PC01;
const int BPI_M2P_23 = GPIO_PC02;
const int BPI_M2P_25 = GPIO_NOT_USED;
const int BPI_M2P_27 = GPIO_PA19;
const int BPI_M2P_29 = GPIO_PA07;
const int BPI_M2P_31 = GPIO_PA08;
const int BPI_M2P_33 = GPIO_PA09;
const int BPI_M2P_35 = GPIO_PA10;
const int BPI_M2P_37 = GPIO_PA17;
const int BPI_M2P_39 = GPIO_NOT_USED;
const int BPI_M2P_02 = GPIO_NOT_USED;
const int BPI_M2P_04 = GPIO_NOT_USED;
const int BPI_M2P_06 = GPIO_NOT_USED;
const int BPI_M2P_08 = GPIO_PA13;
const int BPI_M2P_10 = GPIO_PA14;
const int BPI_M2P_12 = GPIO_PA16;
const int BPI_M2P_14 = GPIO_NOT_USED;
const int BPI_M2P_16 = GPIO_PA15;
const int BPI_M2P_18 = GPIO_PC04;
const int BPI_M2P_20 = GPIO_NOT_USED;
const int BPI_M2P_22 = GPIO_PA02;
const int BPI_M2P_24 = GPIO_PC03;
const int BPI_M2P_26 = GPIO_PC07;
const int BPI_M2P_28 = GPIO_PA18;
const int BPI_M2P_30 = GPIO_NOT_USED;
const int BPI_M2P_32 = GPIO_PL02;
const int BPI_M2P_34 = GPIO_NOT_USED;
const int BPI_M2P_36 = GPIO_PL04;
const int BPI_M2P_38 = GPIO_PA21;
const int BPI_M2P_40 = GPIO_PA20;

View File

@ -10,26 +10,18 @@
//---------------------------------------------------------------------------
#include "sbc_version.h"
#include "log.h"
#include <spdlog/spdlog.h>
#include <fstream>
#include <iostream>
#include <sstream>
SBC_Version::sbc_version_type SBC_Version::m_sbc_version = sbc_version_type::sbc_unknown;
SBC_Version::sbc_version_type SBC_Version::sbc_version = sbc_version_type::sbc_unknown;
// TODO: THESE NEED TO BE VALIDATED!!!!
const std::string SBC_Version::m_str_raspberry_pi_1 = "Raspberry Pi 1";
const std::string SBC_Version::m_str_raspberry_pi_2_3 = "Raspberry Pi 2/3";
const std::string SBC_Version::m_str_raspberry_pi_4 = "Raspberry Pi 4";
const std::string SBC_Version::m_str_bananapi_m1_plus = "Banana Pi M1 Plus";
const std::string SBC_Version::m_str_bananapi_m2_berry = "Banana Pi M2 Berry/Ultra";
const std::string SBC_Version::m_str_bananapi_m2_zero = "Banana Pi M2 Zero";
const std::string SBC_Version::m_str_bananapi_m2_plus = "Banana Pi BPI-M2-Plus H3";
const std::string SBC_Version::m_str_bananapi_m3 = "Banana Pi M3";
const std::string SBC_Version::m_str_bananapi_m4 = "Banana Pi M4";
const std::string SBC_Version::m_str_bananapi_m5 = "Banana Pi M5";
const std::string SBC_Version::m_str_bananapi_m64 = "Banana Pi M64";
const std::string SBC_Version::m_str_unknown_sbc = "Unknown SBC";
const string SBC_Version::str_raspberry_pi_1 = "Raspberry Pi 1";
const string SBC_Version::str_raspberry_pi_2_3 = "Raspberry Pi 2/3";
const string SBC_Version::str_raspberry_pi_4 = "Raspberry Pi 4";
const string SBC_Version::str_unknown_sbc = "Unknown SBC";
// The strings in this table should align with the 'model' embedded
// in the device tree. This can be aquired by running:
@ -39,57 +31,41 @@ const std::string SBC_Version::m_str_unknown_sbc = "Unknown SBC";
// "Raspberry Pi 4 Model B" will match with both of the following:
// - Raspberry Pi 4 Model B Rev 1.4
// - Raspberry Pi 4 Model B Rev 1.3
const std::map<std::string, SBC_Version::sbc_version_type, std::less<>> SBC_Version::m_proc_device_tree_mapping = {
// TODO Is there a better way to detect the Pi type than relying on strings?
const map<string, SBC_Version::sbc_version_type, less<>> SBC_Version::proc_device_tree_mapping = {
{"Raspberry Pi 1 Model ", sbc_version_type::sbc_raspberry_pi_1},
{"Raspberry Pi 2 Model ", sbc_version_type::sbc_raspberry_pi_2_3},
{"Raspberry Pi 3 Model ", sbc_version_type::sbc_raspberry_pi_2_3},
{"Raspberry Pi 4 Model ", sbc_version_type::sbc_raspberry_pi_4},
{"Raspberry Pi 400 ", sbc_version_type::sbc_raspberry_pi_4},
{"Raspberry Pi Zero W", sbc_version_type::sbc_raspberry_pi_1},
{"Raspberry Pi Zero", sbc_version_type::sbc_raspberry_pi_1},
{"Banana Pi BPI-M2-Zero ", sbc_version_type::sbc_bananapi_m2_zero},
{"Banana Pi BPI-M2-Ultra ", sbc_version_type::sbc_bananapi_m2_berry},
{"Banana Pi BPI-M2-Plus H3", sbc_version_type::sbc_bananapi_m2_plus},
{"Banana Pi M2 Berry ", sbc_version_type::sbc_bananapi_m2_berry},
// sbc_bananapi_m3, TBD....
// sbc_bananapi_m4,
{"Raspberry Pi Zero", sbc_version_type::sbc_raspberry_pi_1}
};
const std::string SBC_Version::m_device_tree_model_path = "/proc/device-tree/model";
const string SBC_Version::m_device_tree_model_path = "/proc/device-tree/model";
//---------------------------------------------------------------------------
//
// Convert the SBC Version to a printable string
//
//---------------------------------------------------------------------------
const std::string *SBC_Version::GetString()
string SBC_Version::GetAsString()
{
switch (m_sbc_version) {
switch (sbc_version) {
case sbc_version_type::sbc_raspberry_pi_1:
return &m_str_raspberry_pi_1;
return str_raspberry_pi_1;
case sbc_version_type::sbc_raspberry_pi_2_3:
return &m_str_raspberry_pi_2_3;
return str_raspberry_pi_2_3;
case sbc_version_type::sbc_raspberry_pi_4:
return &m_str_raspberry_pi_4;
case sbc_version_type::sbc_bananapi_m2_berry:
return &m_str_bananapi_m2_berry;
case sbc_version_type::sbc_bananapi_m2_zero:
return &m_str_bananapi_m2_zero;
case sbc_version_type::sbc_bananapi_m2_plus:
return &m_str_bananapi_m2_plus;
case sbc_version_type::sbc_bananapi_m3:
return &m_str_bananapi_m3;
case sbc_version_type::sbc_bananapi_m4:
return &m_str_bananapi_m4;
return str_raspberry_pi_4;
default:
LOGERROR("Unknown type of sbc detected: %d", static_cast<int>(m_sbc_version))
return &m_str_unknown_sbc;
return str_unknown_sbc;
}
}
SBC_Version::sbc_version_type SBC_Version::GetSbcVersion()
{
return m_sbc_version;
return sbc_version;
}
//---------------------------------------------------------------------------
@ -100,71 +76,43 @@ SBC_Version::sbc_version_type SBC_Version::GetSbcVersion()
//---------------------------------------------------------------------------
void SBC_Version::Init()
{
LOGTRACE("%s", __PRETTY_FUNCTION__)
std::string device_tree_model;
const std::ifstream input_stream(SBC_Version::m_device_tree_model_path);
ifstream input_stream(SBC_Version::m_device_tree_model_path);
if (input_stream.fail()) {
#if defined(__x86_64__) || defined(__X86__)
// We expect this to fail on x86
LOGINFO("Detected device %s", GetString()->c_str())
m_sbc_version = sbc_version_type::sbc_unknown;
spdlog::warn("Detected " + GetAsString());
sbc_version = sbc_version_type::sbc_unknown;
return;
#else
LOGERROR("Failed to open %s. Are you running as root?", SBC_Version::m_device_tree_model_path.c_str())
throw std::invalid_argument("Failed to open /proc/device-tree/model");
spdlog::error("Failed to open " + SBC_Version::m_device_tree_model_path + ". Are you running as root?");
throw invalid_argument("Failed to open /proc/device-tree/model");
#endif
}
std::stringstream str_buffer;
stringstream str_buffer;
str_buffer << input_stream.rdbuf();
device_tree_model = str_buffer.str();
const string device_tree_model = str_buffer.str();
for (const auto &[key, value] : m_proc_device_tree_mapping) {
if (device_tree_model.rfind(key, 0) == 0) {
m_sbc_version = value;
LOGINFO("Detected device %s", GetString()->c_str())
return;
}
for (const auto& [key, value] : proc_device_tree_mapping) {
if (device_tree_model.starts_with(key)) {
sbc_version = value;
spdlog::info("Detected " + GetAsString());
return;
}
}
LOGERROR("%s Unable to determine single board computer type. Defaulting to Raspberry Pi 4", __PRETTY_FUNCTION__)
m_sbc_version = sbc_version_type::sbc_raspberry_pi_4;
sbc_version = sbc_version_type::sbc_raspberry_pi_4;
spdlog::error("Unable to determine single board computer type. Defaulting to Raspberry Pi 4");
}
bool SBC_Version::IsRaspberryPi()
{
LOGTRACE("%s", __PRETTY_FUNCTION__)
switch (m_sbc_version) {
switch (sbc_version) {
case sbc_version_type::sbc_raspberry_pi_1:
case sbc_version_type::sbc_raspberry_pi_2_3:
case sbc_version_type::sbc_raspberry_pi_4:
return true;
case sbc_version_type::sbc_bananapi_m2_berry:
case sbc_version_type::sbc_bananapi_m2_zero:
case sbc_version_type::sbc_bananapi_m2_plus:
case sbc_version_type::sbc_bananapi_m3:
case sbc_version_type::sbc_bananapi_m4:
return false;
default:
return false;
}
}
bool SBC_Version::IsBananaPi()
{
LOGTRACE("%s", __PRETTY_FUNCTION__)
switch (m_sbc_version) {
case sbc_version_type::sbc_raspberry_pi_1:
case sbc_version_type::sbc_raspberry_pi_2_3:
case sbc_version_type::sbc_raspberry_pi_4:
return false;
case sbc_version_type::sbc_bananapi_m2_berry:
case sbc_version_type::sbc_bananapi_m2_zero:
case sbc_version_type::sbc_bananapi_m2_plus:
case sbc_version_type::sbc_bananapi_m3:
case sbc_version_type::sbc_bananapi_m4:
return true;
default:
return false;
}
@ -174,11 +122,10 @@ bool SBC_Version::IsBananaPi()
// (imported from bcm_host.c)
uint32_t SBC_Version::GetDeviceTreeRanges(const char *filename, uint32_t offset)
{
LOGTRACE("%s", __PRETTY_FUNCTION__)
uint32_t address = ~0;
if (FILE *fp = fopen(filename, "rb"); fp) {
fseek(fp, offset, SEEK_SET);
if (std::array<uint8_t, 4> buf; fread(buf.data(), 1, buf.size(), fp) == buf.size()) {
if (array<uint8_t, 4> buf; fread(buf.data(), 1, buf.size(), fp) == buf.size()) {
address = (int)buf[0] << 24 | (int)buf[1] << 16 | (int)buf[2] << 8 | (int)buf[3] << 0;
}
fclose(fp);
@ -189,15 +136,12 @@ uint32_t SBC_Version::GetDeviceTreeRanges(const char *filename, uint32_t offset)
#if defined __linux__
uint32_t SBC_Version::GetPeripheralAddress(void)
{
LOGTRACE("%s", __PRETTY_FUNCTION__)
uint32_t address = GetDeviceTreeRanges("/proc/device-tree/soc/ranges", 4);
if (address == 0) {
address = GetDeviceTreeRanges("/proc/device-tree/soc/ranges", 8);
}
address = (address == (uint32_t)~0) ? 0x20000000 : address;
LOGDEBUG("Peripheral address : 0x%8x\n", address)
return address;
}
#elif defined __NetBSD__
@ -215,7 +159,6 @@ uint32_t SBC_Version::GetPeripheralAddress(void)
// Use BCM2835 address
address = 0x20000000;
}
LOGDEBUG("Peripheral address : 0x%lx\n", address);
return address;
}
#else

View File

@ -15,6 +15,8 @@
#include <map>
#include <string>
using namespace std;
//===========================================================================
//
// Single Board Computer Versions
@ -28,16 +30,7 @@ class SBC_Version
sbc_unknown = 0,
sbc_raspberry_pi_1,
sbc_raspberry_pi_2_3,
sbc_raspberry_pi_4,
sbc_bananapi_m1_plus,
sbc_bananapi_m2_ultra,
sbc_bananapi_m2_berry,
sbc_bananapi_m2_zero,
sbc_bananapi_m2_plus,
sbc_bananapi_m3,
sbc_bananapi_m4,
sbc_bananapi_m5,
sbc_bananapi_m64,
sbc_raspberry_pi_4
};
SBC_Version() = delete;
@ -48,32 +41,22 @@ class SBC_Version
static sbc_version_type GetSbcVersion();
static bool IsRaspberryPi();
static bool IsBananaPi();
static const std::string *GetString();
static string GetAsString();
static uint32_t GetPeripheralAddress();
private:
static sbc_version_type m_sbc_version;
static sbc_version_type sbc_version;
static const std::string m_str_raspberry_pi_1;
static const std::string m_str_raspberry_pi_2_3;
static const std::string m_str_raspberry_pi_4;
static const std::string m_str_bananapi_m1_plus;
static const std::string m_str_bananapi_m2_ultra;
static const std::string m_str_bananapi_m2_berry;
static const std::string m_str_bananapi_m2_zero;
static const std::string m_str_bananapi_m2_plus;
static const std::string m_str_bananapi_m3;
static const std::string m_str_bananapi_m4;
static const std::string m_str_bananapi_m5;
static const std::string m_str_bananapi_m64;
static const std::string m_str_unknown_sbc;
static const string str_raspberry_pi_1;
static const string str_raspberry_pi_2_3;
static const string str_raspberry_pi_4;
static const string str_unknown_sbc;
static const std::map<std::string, sbc_version_type, std::less<>> m_proc_device_tree_mapping;
static const map<std::string, sbc_version_type, less<>> proc_device_tree_mapping;
static const std::string m_device_tree_model_path;
static const string m_device_tree_model_path;
static uint32_t GetDeviceTreeRanges(const char *filename, uint32_t offset);
};

View File

@ -1,59 +0,0 @@
//---------------------------------------------------------------------------
//
// SCSI Target Emulator PiSCSI
// for Raspberry Pi
//
// Copyright (C) 2022 akuker
//
// [ Utility functions for working with Allwinner CPUs ]
//
// This should include generic functions that can be applicable to
// different variants of the SunXI (Allwinner) SoCs
//
// Large portions of this functionality were derived from c_gpio.c, which
// is part of the RPI.GPIO library available here:
// https://github.com/BPI-SINOVOIP/RPi.GPIO/blob/master/source/c_gpio.c
//
// Permission is hereby granted, free of charge, to any person obtaining a copy of
// this software and associated documentation files (the "Software"), to deal in
// the Software without restriction, including without limitation the rights to
// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
// of the Software, and to permit persons to whom the Software is furnished to do
// so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
//
//---------------------------------------------------------------------------
#include "hal/sunxi_utils.h"
#include <stdio.h>
#include <string>
using namespace std;
static const string CYAN = "\033[36m"; /* Cyan */
static const string WHITE = "\033[37m"; /* White */
// TODO: this is only a debug function that will be removed at a later date.....
void dump_gpio_registers(const SunXI::sunxi_gpio_reg_t *regs)
{
printf("%s--- GPIO BANK 0 CFG: %08X %08X %08X %08X\n", CYAN.c_str(), regs->gpio_bank[0].CFG[0],
regs->gpio_bank[0].CFG[1], regs->gpio_bank[0].CFG[2], regs->gpio_bank[0].CFG[3]);
printf("--- Dat: (%08X) DRV: %08X %08X\n", regs->gpio_bank[0].DAT, regs->gpio_bank[0].DRV[0],
regs->gpio_bank[0].DRV[1]);
printf("--- Pull: %08X %08x\n", regs->gpio_bank[0].PULL[0], regs->gpio_bank[0].PULL[1]);
printf("--- GPIO INT CFG: %08X %08X %08X\n", regs->gpio_int.CFG[0], regs->gpio_int.CFG[1], regs->gpio_int.CFG[2]);
printf("--- CTL: (%08X) STA: %08X DEB: %08X\n %s", regs->gpio_int.CTL, regs->gpio_int.STA, regs->gpio_int.DEB,
WHITE.c_str());
}

View File

@ -1,189 +0,0 @@
//---------------------------------------------------------------------------
//
// SCSI Target Emulator PiSCSI
// for Raspberry Pi
//
// Copyright (C) 2022 akuker
//
// [ Utility functions for working with Allwinner CPUs ]
//
// This should include generic functions that can be applicable to
// different variants of the SunXI (Allwinner) SoCs
//
// Large portions of this functionality were derived from c_gpio.c, which
// is part of the RPI.GPIO library available here:
// https://github.com/BPI-SINOVOIP/RPi.GPIO/blob/master/source/c_gpio.c
//
// Permission is hereby granted, free of charge, to any person obtaining a copy of
// this software and associated documentation files (the "Software"), to deal in
// the Software without restriction, including without limitation the rights to
// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
// of the Software, and to permit persons to whom the Software is furnished to do
// so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
//
//---------------------------------------------------------------------------
#pragma once
#include <cstdint>
#ifndef __arm__
#include <time.h>
#endif
class SunXI
{
public:
static inline int GPIO_BANK(int pin)
{
return (pin >> 5);
}
static inline int GPIO_NUM(int pin)
{
return (pin & 0x1F);
}
static inline int GPIO_CFG_INDEX(int pin)
{
return ((pin & 0x1F) >> 3);
}
static inline int GPIO_CFG_OFFSET(int pin)
{
return (((pin & 0x1F) & 0x7) << 2);
}
static inline int GPIO_PUL_INDEX(int pin)
{
return ((pin & 0x1F) >> 4);
}
static inline int GPIO_PUL_OFFSET(int pin)
{
return ((pin & 0x0F) << 1);
}
static inline int GPIO_DRV_INDEX(int pin)
{
return ((pin & 0x1F) >> 4);
}
static inline int GPIO_DRV_OFFSET(int pin)
{
return ((pin & 0x0F) << 1);
}
static inline void short_wait(void)
{
for (int i = 0; i < 150; i++) {
#ifndef __arm__
// Timing doesn't really matter if we're not on ARM.
// The SunXI SoCs are all ARM-based.
const timespec ts = {.tv_sec = 0, .tv_nsec = 1};
nanosleep(&ts, nullptr);
#else
// wait 150 cycles
asm volatile("nop");
#endif
}
}
enum class gpio_configure_values_e : uint8_t {
gpio_input = 0b000,
gpio_output = 0b001,
gpio_alt_func_1 = 0b010,
gpio_alt_func_2 = 0b011,
gpio_reserved_1 = 0b100,
gpio_reserved_2 = 0b101,
gpio_interupt = 0b110,
gpio_disable = 0b111
};
struct sunxi_gpio {
unsigned int CFG[4]; // NOSONAR: Intentionally using C style arrays for low level register access
unsigned int DAT;
unsigned int DRV[2]; // NOSONAR: Intentionally using C style arrays for low level register access
unsigned int PULL[2]; // NOSONAR: Intentionally using C style arrays for low level register access
};
using sunxi_gpio_t = struct sunxi_gpio;
/* gpio interrupt control */
struct sunxi_gpio_int {
unsigned int CFG[3]; // NOSONAR: Intentionally using C style arrays for low level register access
unsigned int CTL;
unsigned int STA;
unsigned int DEB;
};
using sunxi_gpio_int_t = struct sunxi_gpio_int;
struct sunxi_gpio_reg {
struct sunxi_gpio gpio_bank[9]; // NOSONAR: Intentionally using C style arrays for low level register access
unsigned char res[0xbc]; // NOSONAR: Intentionally using C style arrays for low level register access
struct sunxi_gpio_int gpio_int;
};
using sunxi_gpio_reg_t = struct sunxi_gpio_reg;
static const uint32_t PAGE_SIZE = (4 * 1024);
static const uint32_t BLOCK_SIZE = (4 * 1024);
static const int SETUP_DEVMEM_FAIL = 1;
static const int SETUP_MALLOC_FAIL = 2;
static const int SETUP_MMAP_FAIL = 3;
static const int SETUP_CPUINFO_FAIL = 4;
static const int SETUP_NOT_RPI_FAIL = 5;
static const int INPUT = 1;
static const int OUTPUT = 0;
static const int ALT0 = 4;
static const int HIGH = 1;
static const int LOW = 0;
static const int PUD_OFF = 0;
static const int PUD_DOWN = 1;
static const int PUD_UP = 2;
static const uint32_t SUNXI_R_GPIO_BASE = 0x01F02000;
static const uint32_t SUNXI_R_GPIO_REG_OFFSET = 0xC00;
static const uint32_t SUNXI_GPIO_BASE = 0x01C20000;
static const uint32_t SUNXI_GPIO_REG_OFFSET = 0x800;
static const uint32_t SUNXI_CFG_OFFSET = 0x00;
static const uint32_t SUNXI_DATA_OFFSET = 0x10;
static const uint32_t SUNXI_PUD_OFFSET = 0x1C;
static const uint32_t SUNXI_BANK_SIZE = 0x24;
static const uint32_t MAP_SIZE = (4096 * 2);
static const uint32_t MAP_MASK = (MAP_SIZE - 1);
static const int FSEL_OFFSET = 0; // 0x0000
static const int SET_OFFSET = 7; // 0x001c / 4
static const int CLR_OFFSET = 10; // 0x0028 / 4
static const int PINLEVEL_OFFSET = 13; // 0x0034 / 4
static const int EVENT_DETECT_OFFSET = 16; // 0x0040 / 4
static const int RISING_ED_OFFSET = 19; // 0x004c / 4
static const int FALLING_ED_OFFSET = 22; // 0x0058 / 4
static const int HIGH_DETECT_OFFSET = 25; // 0x0064 / 4
static const int LOW_DETECT_OFFSET = 28; // 0x0070 / 4
static const int PULLUPDN_OFFSET = 37; // 0x0094 / 4
static const int PULLUPDNCLK_OFFSET = 38; // 0x0098 / 4
static const uint32_t TMR_REGISTER_BASE = 0x01C20C00;
static const uint32_t TMR_IRQ_EN_REG = 0x0; // T imer IRQ Enable Register
static const uint32_t TMR_IRQ_STA_REG = 0x4; // Timer Status Register
static const uint32_t TMR0_CTRL_REG = 0x10; // Timer 0 Control Register
static const uint32_t TMR0_INTV_VALUE_REG = 0x14; // Timer 0 Interval Value Register
static const uint32_t TMR0_CUR_VALUE_REG = 0x18; // Timer 0 Current Value Register
static const uint32_t TMR1_CTRL_REG = 0x20; // Timer 1 Control Register
static const uint32_t TMR1_INTV_VALUE_REG = 0x24; // Timer 1 Interval Value Register
static const uint32_t TMR1_CUR_VALUE_REG = 0x28; // Timer 1 Current Value Register
static const uint32_t AVS_CNT_CTL_REG = 0x80; // AVS Control Register
static const uint32_t AVS_CNT0_REG = 0x84; // AVS Counter 0 Register
static const uint32_t AVS_CNT1_REG = 0x88; // AVS Counter 1 Register
static const uint32_t AVS_CNT_DIV_REG = 0x8C; // AVS Divisor Register
static const uint32_t WDOG0_IRQ_EN_REG = 0xA0; // Watchdog 0 IRQ Enable Register
static const uint32_t WDOG0_IRQ_STA_REG = 0xA4; // Watchdog 0 Status Register
static const uint32_t WDOG0_CTRL_REG = 0xB0; // Watchdog 0 Control Register
static const uint32_t WDOG0_CFG_REG = 0xB4; // Watchdog 0 Configuration Register
static const uint32_t WDOG0_MODE_REG = 0xB8; // Watchdog 0 Mode Register
};

View File

@ -12,31 +12,25 @@
//---------------------------------------------------------------------------
#include "hal/systimer.h"
#include "hal/systimer_allwinner.h"
#include "hal/systimer_raspberry.h"
#include <spdlog/spdlog.h>
#include <sys/mman.h>
#include "hal/gpiobus.h"
#include "hal/sbc_version.h"
bool SysTimer::initialized = false;
bool SysTimer::is_allwinnner = false;
bool SysTimer::is_raspberry = false;
bool SysTimer::initialized = false;
bool SysTimer::is_raspberry = false;
std::unique_ptr<PlatformSpecificTimer> SysTimer::systimer_ptr;
using namespace std;
unique_ptr<PlatformSpecificTimer> SysTimer::systimer_ptr;
void SysTimer::Init()
{
spdlog::trace(__PRETTY_FUNCTION__);
if (!initialized) {
if (SBC_Version::IsRaspberryPi()) {
systimer_ptr = make_unique<SysTimer_Raspberry>();
is_raspberry = true;
} else if (SBC_Version::IsBananaPi()) {
systimer_ptr = make_unique<SysTimer_AllWinner>();
is_allwinnner = true;
}
systimer_ptr->Init();
initialized = true;
@ -48,16 +42,19 @@ 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)
{
systimer_ptr->SleepNsec(nsec);
}
// Sleep for N microseconds
void SysTimer::SleepUsec(uint32_t usec)
{

View File

@ -1,155 +0,0 @@
//---------------------------------------------------------------------------
//
// SCSI Target Emulator PiSCSI
// for Raspberry Pi
//
// Copyright (C) 2022 akuker
//
// [ High resolution timer for the Allwinner series of SoC's]
//
//---------------------------------------------------------------------------
#include "hal/systimer_allwinner.h"
#include <sys/mman.h>
#include "hal/gpiobus.h"
#include "hal/log.h"
const std::string SysTimer_AllWinner::dev_mem_filename = "/dev/mem";
//---------------------------------------------------------------------------
//
// Initialize the system timer
//
//---------------------------------------------------------------------------
void SysTimer_AllWinner::Init()
{
LOGTRACE("%s", __PRETTY_FUNCTION__)
int fd;
if ((fd = open("/dev/mem", O_RDWR | O_SYNC)) < 0) {
LOGERROR("I can't open /dev/mem. Are you running as root?")
exit(-1);
}
hsitimer_regs =
(sun8i_hsitimer_registers *)mmap(nullptr, 4096, PROT_READ | PROT_WRITE, MAP_SHARED, fd, hs_timer_base_address);
if (hsitimer_regs == MAP_FAILED) {
LOGERROR("Unable to map high speed timer registers. Are you running as root?")
}
sysbus_regs = (struct sun8i_sysbus_registers *)mmap(nullptr, 4096, PROT_READ | PROT_WRITE, MAP_SHARED, fd,
system_bus_base_address);
if (sysbus_regs == MAP_FAILED) {
LOGERROR("Unable to map system bus registers. Are you running as root?")
}
enable_hs_timer();
}
void SysTimer_AllWinner::enable_hs_timer()
{
// By default, the HSTimer clock gating is masked. When it is necessary to use
// the HSTimer, its clock gating should be opened in BUS Clock Gating Register 0
// and then de-assert the software reset in BUS Software Reset Register 0 on the
// CCU module. If it is not needed to use the HSTimer, both the gating bit and
// the software reset bit should be set 0.
LOGTRACE("%s [Before Enable] CLK GATE: %08X SOFT RST: %08X", __PRETTY_FUNCTION__, sysbus_regs->bus_clk_gating_reg0,
sysbus_regs->bus_soft_rst_reg0)
sysbus_regs->bus_clk_gating_reg0 = sysbus_regs->bus_clk_gating_reg0 | (1 << BUS_CLK_GATING_REG0_HSTMR);
sysbus_regs->bus_soft_rst_reg0 = sysbus_regs->bus_soft_rst_reg0 | (1 << BUS_SOFT_RST_REG0_HSTMR);
LOGTRACE("%s [After Enable] CLK GATE: %08X SOFT RST: %08X", __PRETTY_FUNCTION__, sysbus_regs->bus_clk_gating_reg0,
sysbus_regs->bus_soft_rst_reg0)
// Set interval value to the maximum value. (its a 52 bit register)
hsitimer_regs->hs_tmr_intv_hi_reg = (1 << 20) - 1; //(0xFFFFF)
hsitimer_regs->hs_tmr_intv_lo_reg = UINT32_MAX;
// Select prescale value of 1, continuous mode
hsitimer_regs->hs_tmr_ctrl_reg = HS_TMR_CLK_PRE_SCALE_1;
// Set reload bit
hsitimer_regs->hs_tmr_ctrl_reg = hsitimer_regs->hs_tmr_ctrl_reg | HS_TMR_RELOAD;
// Enable HSTimer
hsitimer_regs->hs_tmr_ctrl_reg = hsitimer_regs->hs_tmr_ctrl_reg | HS_TMR_EN;
}
// TODO: According to the data sheet, we should turn off the HS timer when we're done with it. But, its just going to
// eat up a little extra power if we leave it running.
void SysTimer_AllWinner::disable_hs_timer()
{
LOGTRACE("%s", __PRETTY_FUNCTION__)
LOGINFO("[Before Disable] CLK GATE: %08X SOFT RST: %08X", sysbus_regs->bus_clk_gating_reg0,
sysbus_regs->bus_soft_rst_reg0)
sysbus_regs->bus_clk_gating_reg0 = sysbus_regs->bus_clk_gating_reg0 & ~(1 << BUS_CLK_GATING_REG0_HSTMR);
sysbus_regs->bus_soft_rst_reg0 = sysbus_regs->bus_soft_rst_reg0 & ~(1 << BUS_SOFT_RST_REG0_HSTMR);
LOGINFO("[After Disable] CLK GATE: %08X SOFT RST: %08X", sysbus_regs->bus_clk_gating_reg0,
sysbus_regs->bus_soft_rst_reg0)
}
uint32_t SysTimer_AllWinner::GetTimerLow()
{
// PiSCSI expects the timer to count UP, but the Allwinner HS timer counts
// down. So, we subtract the current timer value from UINT32_MAX
return UINT32_MAX - (hsitimer_regs->hs_tmr_curnt_lo_reg / 200);
}
uint32_t SysTimer_AllWinner::GetTimerHigh()
{
return (uint32_t)0;
}
//---------------------------------------------------------------------------
//
// Sleep in nanoseconds
//
//---------------------------------------------------------------------------
void SysTimer_AllWinner::SleepNsec(uint32_t nsec)
{
// If time is less than one HS timer clock tick, don't do anything
if (nsec < 20) {
return;
}
// The HS timer receives a 200MHz clock input, which equates to
// one clock tick every 5 ns.
auto clockticks = (uint32_t)std::ceil(nsec / 5);
uint32_t enter_time = hsitimer_regs->hs_tmr_curnt_lo_reg;
// TODO: NEED TO HANDLE COUNTER OVERFLOW
LOGTRACE("%s entertime: %08X ns: %d clockticks: %d", __PRETTY_FUNCTION__, enter_time, nsec, clockticks)
while ((enter_time - hsitimer_regs->hs_tmr_curnt_lo_reg) < clockticks)
;
return;
}
//---------------------------------------------------------------------------
//
// Sleep in microseconds
//
//---------------------------------------------------------------------------
void SysTimer_AllWinner::SleepUsec(uint32_t usec)
{
LOGTRACE("%s", __PRETTY_FUNCTION__)
// If time is 0, don't do anything
if (usec == 0) {
return;
}
uint32_t enter_time = GetTimerLow();
while ((GetTimerLow() - enter_time) < usec)
;
}

View File

@ -1,106 +0,0 @@
//---------------------------------------------------------------------------
//
// SCSI Target Emulator PiSCSI
// for Raspberry Pi
//
// Copyright (C) 2022 akuker
//
// [ High resolution timer ]
//
//---------------------------------------------------------------------------
#pragma once
#include "systimer.h"
#include <stdint.h>
#include <string>
//===========================================================================
//
// System timer
//
//===========================================================================
class SysTimer_AllWinner : public PlatformSpecificTimer
{
public:
// Default constructor
SysTimer_AllWinner() = default;
// Default destructor
~SysTimer_AllWinner() override = default;
// Initialization
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
void SleepUsec(uint32_t usec) override;
private:
void enable_hs_timer();
void disable_hs_timer();
static const std::string dev_mem_filename;
/* Reference: Allwinner H3 Datasheet, section 4.9.3 */
static const uint32_t hs_timer_base_address = 0x01C60000;
/* Note: Currently the high speed timer is NOT in the armbian
* device tree. If it is ever added, this should be pulled
* from there */
using sun8i_hsitimer_registers = struct {
/* 0x00 HS Timer IRQ Enabled Register */
uint32_t hs_tmr_irq_en_reg;
/* 0x04 HS Timer Status Register */
uint32_t hs_tmr_irq_stat_reg;
/* 0x08 Unused */
uint32_t unused_08;
/* 0x0C Unused */
uint32_t unused_0C;
/* 0x10 HS Timer Control Register */
uint32_t hs_tmr_ctrl_reg;
/* 0x14 HS Timer Interval Value Low Reg */
uint32_t hs_tmr_intv_lo_reg;
/* 0x18 HS Timer Interval Value High Register */
uint32_t hs_tmr_intv_hi_reg;
/* 0x1C HS Timer Current Value Low Register */
uint32_t hs_tmr_curnt_lo_reg;
/* 0x20 HS Timer Current Value High Register */
uint32_t hs_tmr_curnt_hi_reg;
};
/* Constants for the HS Timer IRQ enable Register (section 4.9.4.1) */
static const uint32_t HS_TMR_INTERUPT_ENB = (1 << 0);
/* Constants for the HS Timer Control Register (section 4.9.4.3) */
static const uint32_t HS_TMR_EN = (1 << 0);
static const uint32_t HS_TMR_RELOAD = (1 << 1);
static const uint32_t HS_TMR_CLK_PRE_SCALE_1 = (0 << 4);
static const uint32_t HS_TMR_CLK_PRE_SCALE_2 = (1 << 4);
static const uint32_t HS_TMR_CLK_PRE_SCALE_4 = (2 << 4);
static const uint32_t HS_TMR_CLK_PRE_SCALE_8 = (3 << 4);
static const uint32_t HS_TMR_CLK_PRE_SCALE_16 = (4 << 4); // NOSONAR This matches the datasheet
static const uint32_t HS_TMR_MODE_SINGLE = (1 << 7);
static const uint32_t HS_TMR_TEST_MODE = (1 << 31);
volatile sun8i_hsitimer_registers *hsitimer_regs;
/* Reference: Allwinner H3 Datasheet, section 4.3.4 */
static const uint32_t system_bus_base_address = 0x01C20000;
struct sun8i_sysbus_registers {
uint32_t pad_00_5C[(0x60 / sizeof(uint32_t))]; // NOSONAR c-style array used for padding
/* 0x0060 Bus Clock Gating Register 0 */
uint32_t bus_clk_gating_reg0;
uint32_t pad_64_2C0[((0x2C0 - 0x64) / sizeof(uint32_t))]; // NOSONAR c-style array used for padding
/* 0x2C0 Bus Software Reset Register 0 */
uint32_t bus_soft_rst_reg0;
};
/* Bit associated with the HS Timer */
static const uint32_t BUS_CLK_GATING_REG0_HSTMR = 19;
static const uint32_t BUS_SOFT_RST_REG0_HSTMR = 19;
struct sun8i_sysbus_registers *sysbus_regs;
};

View File

@ -26,6 +26,8 @@ volatile uint32_t *SysTimer_Raspberry::systaddr = nullptr;
volatile uint32_t *SysTimer_Raspberry::armtaddr = nullptr;
volatile uint32_t SysTimer_Raspberry::corefreq = 0;
using namespace std;
//---------------------------------------------------------------------------
//
// Initialize the system timer
@ -34,7 +36,7 @@ volatile uint32_t SysTimer_Raspberry::corefreq = 0;
void SysTimer_Raspberry::Init()
{
// Get the base address
auto baseaddr = SBC_Version::GetPeripheralAddress();
const auto baseaddr = SBC_Version::GetPeripheralAddress();
// Open /dev/mem
int mem_fd = open("/dev/mem", O_RDWR | O_SYNC);
@ -63,7 +65,7 @@ void SysTimer_Raspberry::Init()
//
// Clock id
// 0x000000004: CORE
std::array<uint32_t, 32> maxclock = {32, 0, 0x00030004, 8, 0, 4, 0, 0};
const array<uint32_t, 32> maxclock = {32, 0, 0x00030004, 8, 0, 4, 0, 0};
// Save the base address
systaddr = (uint32_t *)map + SYST_OFFSET / sizeof(uint32_t);
@ -113,7 +115,7 @@ void SysTimer_Raspberry::SleepNsec(uint32_t nsec)
}
// Calculate the timer difference
uint32_t diff = corefreq * nsec / 1000;
const uint32_t diff = corefreq * nsec / 1000;
// Return if the difference in time is too small
if (diff == 0) {
@ -121,7 +123,7 @@ void SysTimer_Raspberry::SleepNsec(uint32_t nsec)
}
// Start
uint32_t start = armtaddr[ARMT_FREERUN];
const uint32_t start = armtaddr[ARMT_FREERUN];
// Loop until timer has elapsed
while ((armtaddr[ARMT_FREERUN] - start) < diff)
@ -140,7 +142,7 @@ void SysTimer_Raspberry::SleepUsec(uint32_t usec)
return;
}
uint32_t now = GetTimerLow();
const uint32_t now = GetTimerLow();
while ((GetTimerLow() - now) < usec)
;
}

View File

@ -119,6 +119,9 @@ void ScsiDump::ParseArguments(span<char *> args)
if (!error.empty()) {
throw parser_exception(error);
}
if (target_lun == -1) {
target_lun = 0;
}
} break;
case 'v':
@ -534,7 +537,7 @@ ScsiDump::inquiry_info_t ScsiDump::GetDeviceInfo()
cout << divider_str << "\n";
cout << "PiSCSI board ID: " << initiator_id << "\n";
cout << divider_str << "\n" << flush;
cout << "Target device ID: " << target_id << ", LUN: " << target_lun << "\n";
cout << "Target device is " << target_id << ":" << target_lun << "\n";
Inquiry();

View File

@ -7,6 +7,7 @@
//
//---------------------------------------------------------------------------
#include <spdlog/spdlog.h>
#include "scsiloop/scsiloop_gpio.h"
#include "hal/gpiobus_factory.h"
#include "hal/sbc_version.h"
@ -17,18 +18,12 @@
#include "hal/connection_type/connection_standard.h"
#elif defined CONNECT_TYPE_FULLSPEC
#include "hal/connection_type/connection_fullspec.h"
#elif defined CONNECT_TYPE_AIBOM
#include "hal/connection_type/connection_aibom.h"
#elif defined CONNECT_TYPE_GAMERNIUM
#include "hal/connection_type/connection_gamernium.h"
#else
#error Invalid connection type or none specified
#endif
ScsiLoop_GPIO::ScsiLoop_GPIO()
{
LOGTRACE("%s", __PRETTY_FUNCTION__);
bus = GPIOBUS_Factory::Create(BUS::mode_e::TARGET);
if (bus == nullptr) {
throw bus_exception("Unable to create bus");
@ -116,91 +111,8 @@ ScsiLoop_GPIO::ScsiLoop_GPIO()
local_pin_dt6 = PIN_DT6;
local_pin_dt7 = PIN_DT7;
local_pin_dp = PIN_DP;
} else if (SBC_Version::GetSbcVersion() == SBC_Version::sbc_version_type::sbc_bananapi_m2_plus) {
loopback_conn_table.push_back(
loopback_connection{.this_pin = BPI_PIN_DT0, .connected_pin = BPI_PIN_ACK, .dir_ctrl_pin = BPI_PIN_DTD});
loopback_conn_table.push_back(
loopback_connection{.this_pin = BPI_PIN_DT1, .connected_pin = BPI_PIN_SEL, .dir_ctrl_pin = BPI_PIN_DTD});
loopback_conn_table.push_back(
loopback_connection{.this_pin = BPI_PIN_DT2, .connected_pin = BPI_PIN_ATN, .dir_ctrl_pin = BPI_PIN_DTD});
loopback_conn_table.push_back(
loopback_connection{.this_pin = BPI_PIN_DT3, .connected_pin = BPI_PIN_RST, .dir_ctrl_pin = BPI_PIN_DTD});
loopback_conn_table.push_back(
loopback_connection{.this_pin = BPI_PIN_DT4, .connected_pin = BPI_PIN_CD, .dir_ctrl_pin = BPI_PIN_DTD});
loopback_conn_table.push_back(
loopback_connection{.this_pin = BPI_PIN_DT5, .connected_pin = BPI_PIN_IO, .dir_ctrl_pin = BPI_PIN_DTD});
loopback_conn_table.push_back(
loopback_connection{.this_pin = BPI_PIN_DT6, .connected_pin = BPI_PIN_MSG, .dir_ctrl_pin = BPI_PIN_DTD});
loopback_conn_table.push_back(
loopback_connection{.this_pin = BPI_PIN_DT7, .connected_pin = BPI_PIN_REQ, .dir_ctrl_pin = BPI_PIN_DTD});
loopback_conn_table.push_back(
loopback_connection{.this_pin = BPI_PIN_DP, .connected_pin = BPI_PIN_BSY, .dir_ctrl_pin = BPI_PIN_DTD});
loopback_conn_table.push_back(
loopback_connection{.this_pin = BPI_PIN_ATN, .connected_pin = BPI_PIN_DT2, .dir_ctrl_pin = BPI_PIN_IND});
loopback_conn_table.push_back(
loopback_connection{.this_pin = BPI_PIN_RST, .connected_pin = BPI_PIN_DT3, .dir_ctrl_pin = BPI_PIN_IND});
loopback_conn_table.push_back(
loopback_connection{.this_pin = BPI_PIN_ACK, .connected_pin = BPI_PIN_DT0, .dir_ctrl_pin = BPI_PIN_IND});
loopback_conn_table.push_back(
loopback_connection{.this_pin = BPI_PIN_REQ, .connected_pin = BPI_PIN_DT7, .dir_ctrl_pin = BPI_PIN_TAD});
loopback_conn_table.push_back(
loopback_connection{.this_pin = BPI_PIN_MSG, .connected_pin = BPI_PIN_DT6, .dir_ctrl_pin = BPI_PIN_TAD});
loopback_conn_table.push_back(
loopback_connection{.this_pin = BPI_PIN_CD, .connected_pin = BPI_PIN_DT4, .dir_ctrl_pin = BPI_PIN_TAD});
loopback_conn_table.push_back(
loopback_connection{.this_pin = BPI_PIN_IO, .connected_pin = BPI_PIN_DT5, .dir_ctrl_pin = BPI_PIN_TAD});
loopback_conn_table.push_back(
loopback_connection{.this_pin = BPI_PIN_BSY, .connected_pin = BPI_PIN_DP, .dir_ctrl_pin = BPI_PIN_TAD});
loopback_conn_table.push_back(
loopback_connection{.this_pin = BPI_PIN_SEL, .connected_pin = BPI_PIN_DT1, .dir_ctrl_pin = BPI_PIN_IND});
pin_name_lookup[BPI_PIN_DT0] = " d0";
pin_name_lookup[BPI_PIN_DT1] = " d1";
pin_name_lookup[BPI_PIN_DT2] = " d2";
pin_name_lookup[BPI_PIN_DT3] = " d3";
pin_name_lookup[BPI_PIN_DT4] = " d4";
pin_name_lookup[BPI_PIN_DT5] = " d5";
pin_name_lookup[BPI_PIN_DT6] = " d6";
pin_name_lookup[BPI_PIN_DT7] = " d7";
pin_name_lookup[BPI_PIN_DP] = " dp";
pin_name_lookup[BPI_PIN_ATN] = "atn";
pin_name_lookup[BPI_PIN_RST] = "rst";
pin_name_lookup[BPI_PIN_ACK] = "ack";
pin_name_lookup[BPI_PIN_REQ] = "req";
pin_name_lookup[BPI_PIN_MSG] = "msg";
pin_name_lookup[BPI_PIN_CD] = " cd";
pin_name_lookup[BPI_PIN_IO] = " io";
pin_name_lookup[BPI_PIN_BSY] = "bsy";
pin_name_lookup[BPI_PIN_SEL] = "sel";
pin_name_lookup[BPI_PIN_IND] = "ind";
pin_name_lookup[BPI_PIN_TAD] = "tad";
pin_name_lookup[BPI_PIN_DTD] = "dtd";
local_pin_dtd = BPI_PIN_DTD;
local_pin_tad = BPI_PIN_TAD;
local_pin_ind = BPI_PIN_IND;
local_pin_ack = BPI_PIN_ACK;
local_pin_sel = BPI_PIN_SEL;
local_pin_atn = BPI_PIN_ATN;
local_pin_rst = BPI_PIN_RST;
local_pin_cd = BPI_PIN_CD;
local_pin_io = BPI_PIN_IO;
local_pin_msg = BPI_PIN_MSG;
local_pin_req = BPI_PIN_REQ;
local_pin_bsy = BPI_PIN_BSY;
local_pin_dt0 = BPI_PIN_DT0;
local_pin_dt1 = BPI_PIN_DT1;
local_pin_dt2 = BPI_PIN_DT2;
local_pin_dt3 = BPI_PIN_DT3;
local_pin_dt4 = BPI_PIN_DT4;
local_pin_dt5 = BPI_PIN_DT5;
local_pin_dt6 = BPI_PIN_DT6;
local_pin_dt7 = BPI_PIN_DT7;
local_pin_dp = BPI_PIN_DP;
} else {
LOGERROR("Unsupported board version: %s", SBC_Version::GetString()->c_str());
spdlog::error("Unsupported board version: " + SBC_Version::GetAsString());
}
}