diff --git a/.github/workflows/build_code.yml b/.github/workflows/build_code.yml index e0c38852..a17b01ba 100644 --- a/.github/workflows/build_code.yml +++ b/.github/workflows/build_code.yml @@ -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 diff --git a/cpp/hal/connection_type/connection_aibom.h b/cpp/hal/connection_type/connection_aibom.h deleted file mode 100644 index 0dd3c314..00000000 --- a/cpp/hal/connection_type/connection_aibom.h +++ /dev/null @@ -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 - -// -// 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 diff --git a/cpp/hal/connection_type/connection_fullspec.h b/cpp/hal/connection_type/connection_fullspec.h index b5e706f2..9a21c3c7 100644 --- a/cpp/hal/connection_type/connection_fullspec.h +++ b/cpp/hal/connection_type/connection_fullspec.h @@ -10,7 +10,6 @@ #pragma once -#include "hal/pi_defs/bpi-m2p.h" #include // @@ -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 diff --git a/cpp/hal/connection_type/connection_gamernium.h b/cpp/hal/connection_type/connection_gamernium.h deleted file mode 100644 index eeeb4a5d..00000000 --- a/cpp/hal/connection_type/connection_gamernium.h +++ /dev/null @@ -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 - -// -// 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 diff --git a/cpp/hal/connection_type/connection_standard.h b/cpp/hal/connection_type/connection_standard.h index fdde2784..7772347f 100644 --- a/cpp/hal/connection_type/connection_standard.h +++ b/cpp/hal/connection_type/connection_standard.h @@ -10,7 +10,6 @@ #pragma once -#include "hal/pi_defs/bpi-m2p.h" #include // @@ -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 diff --git a/cpp/hal/data_sample_bananam2p.cpp b/cpp/hal/data_sample_bananam2p.cpp deleted file mode 100644 index 8e00c15b..00000000 --- a/cpp/hal/data_sample_bananam2p.cpp +++ /dev/null @@ -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 - -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; -} \ No newline at end of file diff --git a/cpp/hal/data_sample_bananam2p.h b/cpp/hal/data_sample_bananam2p.h deleted file mode 100644 index 35f04ee6..00000000 --- a/cpp/hal/data_sample_bananam2p.h +++ /dev/null @@ -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 - -#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 &in_data, uint64_t in_timestamp) - : DataSample{in_timestamp}, data{in_data} - { - } - DataSample_BananaM2p() = default; - - ~DataSample_BananaM2p() override = default; - - private: - array data = {0}; -}; \ No newline at end of file diff --git a/cpp/hal/data_sample_raspberry.h b/cpp/hal/data_sample_raspberry.h index a0b5e1e7..9951d661 100644 --- a/cpp/hal/data_sample_raspberry.h +++ b/cpp/hal/data_sample_raspberry.h @@ -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; -}; \ No newline at end of file +}; diff --git a/cpp/hal/gpiobus.cpp b/cpp/hal/gpiobus.cpp index a6bf2555..1f467bfa 100644 --- a/cpp/hal/gpiobus.cpp +++ b/cpp/hal/gpiobus.cpp @@ -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 -#include #include #include #include @@ -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 diff --git a/cpp/hal/gpiobus.h b/cpp/hal/gpiobus.h index 74fb820b..7dbff55c 100644 --- a/cpp/hal/gpiobus.h +++ b/cpp/hal/gpiobus.h @@ -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 #include #include @@ -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 &) override; + int CommandHandShake(vector&) 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 }; diff --git a/cpp/hal/gpiobus_bananam2p.cpp b/cpp/hal/gpiobus_bananam2p.cpp deleted file mode 100644 index 7d42f3a5..00000000 --- a/cpp/hal/gpiobus_bananam2p.cpp +++ /dev/null @@ -1,1055 +0,0 @@ -//--------------------------------------------------------------------------- -// -// SCSI Target Emulator PiSCSI -// for Raspberry Pi (And Banana Pi) -// -// Copyright (c) 2012-2015 Ben Croston -// Copyright (C) 2022 akuker -// -// 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 -#include -#include -#include -#ifdef __linux__ -#include -#endif -#include -#include - -#include "hal/gpiobus.h" -#include "hal/gpiobus_bananam2p.h" -#include "hal/pi_defs/bpi-gpio.h" -#include "hal/sunxi_utils.h" -#include "hal/systimer.h" -#include "hal/log.h" - -#define ARRAY_SIZE(x) (sizeof(x) / (sizeof(x[0]))) - -bool GPIOBUS_BananaM2p::Init(mode_e mode) -{ - GPIO_FUNCTION_TRACE - GPIOBUS::Init(mode); - SysTimer::Init(); - - sbc_version = SBC_Version::GetSbcVersion(); - - for (auto const gpio_num : SignalTable) { - if (gpio_num == -1) { - break; - } - - int gpio_bank = SunXI::GPIO_BANK(gpio_num); - - if (std::ranges::find(gpio_banks, gpio_bank) != gpio_banks.end()) { - LOGTRACE("Duplicate bank: %d", gpio_bank) - - } else { - LOGDEBUG("New bank: %d", gpio_bank) - gpio_banks.push_back(gpio_bank); - } - } - - if (int result = sunxi_setup(); result != SETUP_OK) { - return false; - } - - InitializeGpio(); - - MakeTable(); - - // SetupSelEvent needs to be called AFTER Initialize GPIO. This function - // reconfigures the SEL signal. - if (!SetupSelEvent()) { - LOGERROR("Failed to setup SELECT poll event") - return false; - } - LOGTRACE("SetupSelEvent OK!") - - // Set drive strength to maximum - DrvConfig(3); - - return true; -} - -void GPIOBUS_BananaM2p::InitializeGpio() -{ - GPIO_FUNCTION_TRACE - - // Set pull up/pull down -#if SIGNAL_CONTROL_MODE == 0 - int pullmode = GPIO_PULLNONE; -#elif SIGNAL_CONTROL_MODE == 1 - int pullmode = GPIO_PULLUP; -#else - int pullmode = GPIO_PULLDOWN; -#endif - - // Initialize all signals - for (int i = 0; SignalTable[i] >= 0; i++) { - int j = SignalTable[i]; - PinConfig(j, GPIO_INPUT); - PullConfig(j, pullmode); - PinSetSignal(j, OFF); - } - - // Set control signals - PinConfig(BPI_PIN_ACT, GPIO_OUTPUT); - PinConfig(BPI_PIN_TAD, GPIO_OUTPUT); - PinConfig(BPI_PIN_IND, GPIO_OUTPUT); - PinConfig(BPI_PIN_DTD, GPIO_OUTPUT); - PinSetSignal(BPI_PIN_ACT, OFF); - PinSetSignal(BPI_PIN_TAD, OFF); - PinSetSignal(BPI_PIN_IND, OFF); - PinSetSignal(BPI_PIN_DTD, OFF); - - // Set the ENABLE signal - // This is used to show that the application is running - PinConfig(BPI_PIN_ENB, GPIO_OUTPUT); - PinSetSignal(BPI_PIN_ENB, ON); -} - -void GPIOBUS_BananaM2p::Cleanup() -{ - GPIO_FUNCTION_TRACE -#if defined(__x86_64__) || defined(__X86__) || defined(__aarch64__) - dummy_var--; // Need to do something to prevent Sonar from claiming this should be a const function - return; -#else - -#ifdef USE_SEL_EVENT_ENABLE - // Release SEL signal interrupt - close(selevreq.fd); -#endif // USE_SEL_EVENT_ENABLE - - // Set control signals - PinConfig(BPI_PIN_ACT, GPIO_INPUT); - PinConfig(BPI_PIN_TAD, GPIO_INPUT); - PinConfig(BPI_PIN_IND, GPIO_INPUT); - PinConfig(BPI_PIN_DTD, GPIO_INPUT); - PinSetSignal(BPI_PIN_ENB, OFF); - PinSetSignal(BPI_PIN_ACT, OFF); - PinSetSignal(BPI_PIN_TAD, OFF); - PinSetSignal(BPI_PIN_IND, OFF); - PinSetSignal(BPI_PIN_DTD, OFF); - - // Initialize all signals - for (int i = 0; SignalTable[i] >= 0; i++) { - int pin = SignalTable[i]; - PinConfig(pin, GPIO_INPUT); - PullConfig(pin, GPIO_PULLNONE); - PinSetSignal(pin, OFF); - } - - // Set drive strength back to Default (Level 1) - DrvConfig(1); - - munmap((void *)gpio_map, SunXI::BLOCK_SIZE); - munmap((void *)r_gpio_map, SunXI::BLOCK_SIZE); - -#endif -} - -void GPIOBUS_BananaM2p::Reset() -{ -#if defined(__x86_64__) || defined(__X86__) || defined(__aarch64__) - dummy_var++; - return; -#else - int i; - int j; - - // Turn off active signal - SetControl(BPI_PIN_ACT, ACT_OFF); - - // Set all signals to off - for (i = 0;; i++) { - j = SignalTable[i]; - if (j < 0) { - break; - } - - SetSignal(j, OFF); - } - - if (actmode == mode_e::TARGET) { - // Target mode - - // Set target signal to input - SetControl(BPI_PIN_TAD, TAD_IN); - SetMode(BPI_PIN_BSY, IN); - SetMode(BPI_PIN_MSG, IN); - SetMode(BPI_PIN_CD, IN); - SetMode(BPI_PIN_REQ, IN); - SetMode(BPI_PIN_IO, IN); - - // Set the initiator signal to input - SetControl(BPI_PIN_IND, IND_IN); - SetMode(BPI_PIN_SEL, IN); - SetMode(BPI_PIN_ATN, IN); - SetMode(BPI_PIN_ACK, IN); - SetMode(BPI_PIN_RST, IN); - - // Set data bus signals to input - SetControl(BPI_PIN_DTD, DTD_IN); - SetMode(BPI_PIN_DT0, IN); - SetMode(BPI_PIN_DT1, IN); - SetMode(BPI_PIN_DT2, IN); - SetMode(BPI_PIN_DT3, IN); - SetMode(BPI_PIN_DT4, IN); - SetMode(BPI_PIN_DT5, IN); - SetMode(BPI_PIN_DT6, IN); - SetMode(BPI_PIN_DT7, IN); - SetMode(BPI_PIN_DP, IN); - } else { - // Initiator mode - - // Set target signal to input - SetControl(BPI_PIN_TAD, TAD_IN); - SetMode(BPI_PIN_BSY, IN); - SetMode(BPI_PIN_MSG, IN); - SetMode(BPI_PIN_CD, IN); - SetMode(BPI_PIN_REQ, IN); - SetMode(BPI_PIN_IO, IN); - - // Set the initiator signal to output - SetControl(BPI_PIN_IND, IND_OUT); - SetMode(BPI_PIN_SEL, OUT); - SetMode(BPI_PIN_ATN, OUT); - SetMode(BPI_PIN_ACK, OUT); - SetMode(BPI_PIN_RST, OUT); - - // Set the data bus signals to output - SetControl(BPI_PIN_DTD, DTD_OUT); - SetMode(BPI_PIN_DT0, OUT); - SetMode(BPI_PIN_DT1, OUT); - SetMode(BPI_PIN_DT2, OUT); - SetMode(BPI_PIN_DT3, OUT); - SetMode(BPI_PIN_DT4, OUT); - SetMode(BPI_PIN_DT5, OUT); - SetMode(BPI_PIN_DT6, OUT); - SetMode(BPI_PIN_DT7, OUT); - SetMode(BPI_PIN_DP, OUT); - } - - // Initialize all signals - // TODO!! For now, just re-run Acquire - Acquire(); -#endif // ifdef __x86_64__ || __X86__ -} - -bool GPIOBUS_BananaM2p::SetupSelEvent() -{ -#if defined(__x86_64__) || defined(__X86__) || defined(__aarch64__) - dummy_var += 2; // Need to do something to prevent Sonar from claiming this should be a const function - return false; -#else - GPIO_FUNCTION_TRACE - int gpio_pin = BPI_PIN_SEL; - - // GPIO chip open - LOGTRACE("%s GPIO chip open [%d]", __PRETTY_FUNCTION__, gpio_pin) - std::string gpio_dev = "/dev/gpiochip0"; - if (SunXI::GPIO_BANK(gpio_pin) >= 11) { - gpio_dev = "/dev/gpiochip1"; - LOGWARN("gpiochip1 support isn't implemented yet....") - LOGWARN("THIS PROBABLY WONT WORK!") - } - - int gpio_fd = open(gpio_dev.c_str(), 0); - if (gpio_fd == -1) { - LOGERROR("Unable to open /dev/gpiochip0. Is PiSCSI or RaSCSI already running?") - return false; - } - - // Event request setting - LOGTRACE("%s Event request setting (pin sel: %d)", __PRETTY_FUNCTION__, gpio_pin) - strncpy(selevreq.consumer_label, "PiSCSI", ARRAY_SIZE(selevreq.consumer_label)); - selevreq.lineoffset = gpio_pin; - selevreq.handleflags = GPIOHANDLE_REQUEST_INPUT; -#if SIGNAL_CONTROL_MODE < 2 - selevreq.eventflags = GPIOEVENT_REQUEST_FALLING_EDGE; - LOGTRACE("%s eventflags = GPIOEVENT_REQUEST_FALLING_EDGE", __PRETTY_FUNCTION__) -#else - selevreq.eventflags = GPIOEVENT_REQUEST_RISING_EDGE; - LOGTRACE("%s eventflags = GPIOEVENT_REQUEST_RISING_EDGE", __PRETTY_FUNCTION__) -#endif // SIGNAL_CONTROL_MODE - - // Get event request - if (ioctl(gpio_fd, GPIO_GET_LINEEVENT_IOCTL, &selevreq) == -1) { - LOGERROR("selevreq.fd = %d %08X", selevreq.fd, (unsigned int)selevreq.fd) - LOGERROR("Unable to register event request. Is PiSCSI or RaSCSI already running?") - LOGERROR("[%08X] %s", errno, strerror(errno)) - close(gpio_fd); - return false; - } - - // Close GPIO chip file handle - LOGTRACE("%s Close GPIO chip file handle", __PRETTY_FUNCTION__) - close(gpio_fd); - - // epoll initialization - LOGTRACE("%s epoll initialization", __PRETTY_FUNCTION__) - epfd = epoll_create(1); - if (epfd == -1) { - LOGERROR("Unable to create the epoll event") - return false; - } - epoll_event ev = {}; - memset(&ev, 0, sizeof(ev)); - ev.events = EPOLLIN | EPOLLPRI; - ev.data.fd = selevreq.fd; - if (epoll_ctl(epfd, EPOLL_CTL_ADD, selevreq.fd, &ev) < 0) { - return false; - } - - return true; -#endif -} - -void GPIOBUS_BananaM2p::SetENB(bool ast) -{ - PinSetSignal(BPI_PIN_ENB, ast ? ENB_ON : ENB_OFF); -} - -bool GPIOBUS_BananaM2p::GetBSY() const -{ - return GetSignal(BPI_PIN_BSY); -} - -void GPIOBUS_BananaM2p::SetBSY(bool ast) -{ - if (actmode == mode_e::TARGET) { - if (ast) { - // Turn on ACTIVE signal - SetControl(BPI_PIN_ACT, ACT_ON); - - // Set Target signal to output - SetControl(BPI_PIN_TAD, TAD_OUT); - - SetMode(BPI_PIN_BSY, OUT); - SetMode(BPI_PIN_MSG, OUT); - SetMode(BPI_PIN_CD, OUT); - SetMode(BPI_PIN_REQ, OUT); - SetMode(BPI_PIN_IO, OUT); - - // Set BSY signal - SetSignal(BPI_PIN_BSY, ast); - - } else { - // Turn off the ACTIVE signal - SetControl(BPI_PIN_ACT, ACT_OFF); - - // Set the target signal to input - SetControl(BPI_PIN_TAD, TAD_IN); - - SetMode(BPI_PIN_BSY, IN); - SetMode(BPI_PIN_MSG, IN); - SetMode(BPI_PIN_CD, IN); - SetMode(BPI_PIN_REQ, IN); - SetMode(BPI_PIN_IO, IN); - } - } else { - // Set BSY signal - SetSignal(BPI_PIN_BSY, ast); - } -} - -bool GPIOBUS_BananaM2p::GetSEL() const -{ - return GetSignal(BPI_PIN_SEL); -} - -void GPIOBUS_BananaM2p::SetSEL(bool ast) -{ - if (actmode == mode_e::INITIATOR && ast) { - // Turn on ACTIVE signal - SetControl(BPI_PIN_ACT, ACT_ON); - } - - // Set SEL signal - SetSignal(BPI_PIN_SEL, ast); -} - -bool GPIOBUS_BananaM2p::GetATN() const -{ - return GetSignal(BPI_PIN_ATN); -} - -void GPIOBUS_BananaM2p::SetATN(bool ast) -{ - SetSignal(BPI_PIN_ATN, ast); -} - -bool GPIOBUS_BananaM2p::GetACK() const -{ - return GetSignal(BPI_PIN_ACK); -} - -void GPIOBUS_BananaM2p::SetACK(bool ast) -{ - SetSignal(BPI_PIN_ACK, ast); -} - -bool GPIOBUS_BananaM2p::GetACT() const -{ - return GetSignal(BPI_PIN_ACT); -} - -void GPIOBUS_BananaM2p::SetACT(bool ast) -{ - SetSignal(BPI_PIN_ACT, ast); -} - -bool GPIOBUS_BananaM2p::GetRST() const -{ - return GetSignal(BPI_PIN_RST); -} - -void GPIOBUS_BananaM2p::SetRST(bool ast) -{ - SetSignal(BPI_PIN_RST, ast); -} - -bool GPIOBUS_BananaM2p::GetMSG() const -{ - return GetSignal(BPI_PIN_MSG); -} - -void GPIOBUS_BananaM2p::SetMSG(bool ast) -{ - SetSignal(BPI_PIN_MSG, ast); -} - -bool GPIOBUS_BananaM2p::GetCD() const -{ - return GetSignal(BPI_PIN_CD); -} - -void GPIOBUS_BananaM2p::SetCD(bool ast) -{ - SetSignal(BPI_PIN_CD, ast); -} - -bool GPIOBUS_BananaM2p::GetIO() -{ - bool ast = GetSignal(BPI_PIN_IO); - - if (actmode == mode_e::INITIATOR) { - // Change the data input/output direction by IO signal - if (ast) { - SetControl(BPI_PIN_DTD, DTD_IN); - SetMode(BPI_PIN_DT0, IN); - SetMode(BPI_PIN_DT1, IN); - SetMode(BPI_PIN_DT2, IN); - SetMode(BPI_PIN_DT3, IN); - SetMode(BPI_PIN_DT4, IN); - SetMode(BPI_PIN_DT5, IN); - SetMode(BPI_PIN_DT6, IN); - SetMode(BPI_PIN_DT7, IN); - SetMode(BPI_PIN_DP, IN); - } else { - SetControl(BPI_PIN_DTD, DTD_OUT); - SetMode(BPI_PIN_DT0, OUT); - SetMode(BPI_PIN_DT1, OUT); - SetMode(BPI_PIN_DT2, OUT); - SetMode(BPI_PIN_DT3, OUT); - SetMode(BPI_PIN_DT4, OUT); - SetMode(BPI_PIN_DT5, OUT); - SetMode(BPI_PIN_DT6, OUT); - SetMode(BPI_PIN_DT7, OUT); - SetMode(BPI_PIN_DP, OUT); - } - } - - return ast; -} - -void GPIOBUS_BananaM2p::SetIO(bool ast) -{ - if (actmode == mode_e::TARGET) { - // Change the data input/output direction by IO signal - if (ast) { - SetControl(BPI_PIN_DTD, DTD_OUT); - SetMode(BPI_PIN_DT0, OUT); - SetMode(BPI_PIN_DT1, OUT); - SetMode(BPI_PIN_DT2, OUT); - SetMode(BPI_PIN_DT3, OUT); - SetMode(BPI_PIN_DT4, OUT); - SetMode(BPI_PIN_DT5, OUT); - SetMode(BPI_PIN_DT6, OUT); - SetMode(BPI_PIN_DT7, OUT); - SetMode(BPI_PIN_DP, OUT); - - SetDAT(0); - SetSignal(BPI_PIN_IO, ast); - - } else { - SetControl(BPI_PIN_DTD, DTD_IN); - SetMode(BPI_PIN_DT0, IN); - SetMode(BPI_PIN_DT1, IN); - SetMode(BPI_PIN_DT2, IN); - SetMode(BPI_PIN_DT3, IN); - SetMode(BPI_PIN_DT4, IN); - SetMode(BPI_PIN_DT5, IN); - SetMode(BPI_PIN_DT6, IN); - SetMode(BPI_PIN_DT7, IN); - SetMode(BPI_PIN_DP, IN); - } - } else { - SetSignal(BPI_PIN_IO, ast); - } -} - -bool GPIOBUS_BananaM2p::GetREQ() const -{ - return GetSignal(BPI_PIN_REQ); -} - -void GPIOBUS_BananaM2p::SetREQ(bool ast) -{ - SetSignal(BPI_PIN_REQ, ast); -} - -uint8_t GPIOBUS_BananaM2p::GetDAT() -{ - GPIO_FUNCTION_TRACE - - Acquire(); - uint32_t data = - ((GetSignal(BPI_PIN_DT0) ? 0x01 : 0x00) << 0) | ((GetSignal(BPI_PIN_DT1) ? 0x01 : 0x00) << 1) | - ((GetSignal(BPI_PIN_DT2) ? 0x01 : 0x00) << 2) | ((GetSignal(BPI_PIN_DT3) ? 0x01 : 0x00) << 3) | - ((GetSignal(BPI_PIN_DT4) ? 0x01 : 0x00) << 4) | ((GetSignal(BPI_PIN_DT5) ? 0x01 : 0x00) << 5) | - ((GetSignal(BPI_PIN_DT6) ? 0x01 : 0x00) << 6) | - ((GetSignal(BPI_PIN_DT7) ? 0x01 : 0x00) << 7); // NOSONAR: GCC 10 doesn't support shift operations on std::byte - - return (uint8_t)(data & 0xFF); -} - -void GPIOBUS_BananaM2p::SetDAT(uint8_t dat) -{ - GPIO_FUNCTION_TRACE - - array gpio_reg_values = {0}; - - for (size_t gpio_num = 0; gpio_num < pintbl.size(); gpio_num++) { - bool value; - if (gpio_num < 8) { - // data bits - value = !(dat & (1 << gpio_num)); // NOSONAR: GCC 10 doesn't support shift operations on std::byte - } else { - // parity bit - value = (__builtin_parity(dat) == 1); - } - - if (value) { - uint32_t this_gpio = pintbl[gpio_num]; - int bank = SunXI::GPIO_BANK(this_gpio); - int offset = SunXI::GPIO_NUM(this_gpio); - gpio_reg_values[bank] |= (1 << offset); - } - } - - sunxi_set_all_gpios(gpio_data_masks, gpio_reg_values); -} - -//--------------------------------------------------------------------------- -// -// Signal table -// -//--------------------------------------------------------------------------- -const array GPIOBUS_BananaM2p::SignalTable = {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, BPI_PIN_SEL, - BPI_PIN_ATN, BPI_PIN_RST, BPI_PIN_ACK, BPI_PIN_BSY, BPI_PIN_MSG, - BPI_PIN_CD, BPI_PIN_IO, BPI_PIN_REQ, -1}; - -//--------------------------------------------------------------------------- -// -// Create work table -// -//--------------------------------------------------------------------------- -void GPIOBUS_BananaM2p::MakeTable(void) -{ - for (auto this_gpio : pintbl) { - int bank = SunXI::GPIO_BANK(this_gpio); - int offset = (SunXI::GPIO_NUM(this_gpio)); - - gpio_data_masks[bank] |= (1 << offset); - } -} - -bool GPIOBUS_BananaM2p::GetDP() const -{ - return GetSignal(BPI_PIN_DP); -} - -void GPIOBUS_BananaM2p::SetControl(int pin, bool ast) -{ - GPIO_FUNCTION_TRACE - PinSetSignal(pin, ast); -} - -// Set direction -int GPIOBUS_BananaM2p::GetMode(int pin) -{ - GPIO_FUNCTION_TRACE - - uint32_t regval = 0; - int bank = SunXI::GPIO_BANK(pin); - int index = SunXI::GPIO_CFG_INDEX(pin); - int offset = SunXI::GPIO_CFG_OFFSET(pin); - - volatile SunXI::sunxi_gpio_t *pio = &(pio_map->gpio_bank[bank]); - /* DK, for PL and PM */ - if (bank >= 11) { - bank -= 11; - pio = &(r_pio_map->gpio_bank[bank]); - } - - regval = pio->CFG[0 + index]; - - // Extract the CFG field - regval &= (0x7 << offset); // 0xf? - // Shift it down to the LSB - regval >>= offset; - return (int)regval; -} - -// Set direction -void GPIOBUS_BananaM2p::SetMode(int pin, int mode) -{ - GPIO_FUNCTION_TRACE - int direction = mode; - - uint32_t regval = 0; - int bank = SunXI::GPIO_BANK(pin); // gpio >> 5 - int index = SunXI::GPIO_CFG_INDEX(pin); // (gpio & 0x1F) >> 3 - int offset = SunXI::GPIO_CFG_OFFSET(pin); // ((gpio & 0x1F) & 0x7) << 2 - LOGTRACE("%s gpio(%d) bank(%d) index(%d) offset(%d) dir(%s)", __PRETTY_FUNCTION__, pin, bank, index, offset, - (GPIO_INPUT == direction) ? "IN" - : (GPIO_IRQ_IN == direction) ? "IRQ" - : "OUT") - - volatile SunXI::sunxi_gpio_t *pio = &(pio_map->gpio_bank[bank]); - /* DK, for PL and PM */ - if (bank >= 11) { - bank -= 11; - pio = &(r_pio_map->gpio_bank[bank]); - } - - regval = pio->CFG[0 + index]; - - // Clear the cfg field - regval &= ~(0x7 << offset); // 0xf? - if (GPIO_INPUT == direction) { - regval |= (((uint32_t)SunXI::gpio_configure_values_e::gpio_input) << offset); - } else if (GPIO_OUTPUT == direction) { - regval |= (((uint32_t)SunXI::gpio_configure_values_e::gpio_output) << offset); - } else if (GPIO_IRQ_IN == direction) { - regval |= (((uint32_t)SunXI::gpio_configure_values_e::gpio_interupt) << offset); - } else { - LOGERROR("line:%d gpio number error %d", __LINE__, pin) - } - pio->CFG[0 + index] = regval; -} - -bool GPIOBUS_BananaM2p::GetSignal(int pin) const -{ - GPIO_FUNCTION_TRACE - int gpio_num = pin; - - uint32_t regval = 0; - int bank = SunXI::GPIO_BANK(gpio_num); // gpio >> 5 - int num = SunXI::GPIO_NUM(gpio_num); // gpio & 0x1F - - regval = (signals[bank] >> num) & 0x1; - return regval != 0; -} - -void GPIOBUS_BananaM2p::SetSignal(int pin, bool ast) -{ - GPIO_FUNCTION_TRACE - int gpio_num = pin; - -#if SIGNAL_CONTROL_MODE == 0 - // True : 0V - // False : Open collector output (disconnect from bus) - int sunxi_gpio_state = (ast == true) ? SunXI::HIGH : SunXI::LOW; -#elif SIGNAL_CONTROL_MODE == 1 - // True : 0V -> (CONVERT) -> 0V - // False : 3.3V -> (CONVERT) -> Open collector output - LOGWARN("%s:%d THIS LOGIC NEEDS TO BE VALIDATED/TESTED", __PRETTY_FUNCTION__, __LINE__) - int sunxi_gpio_state = (ast == true) ? SunXI::HIGH : SunXI::LOW; -#elif SIGNAL_CONTROL_MODE == 2 - // True : 3.3V -> (CONVERT) -> 0V - // False : 0V -> (CONVERT) -> Open collector output - LOGWARN("%s:%d THIS LOGIC NEEDS TO BE VALIDATED/TESTED", __PRETTY_FUNCTION__, __LINE__) - int sunxi_gpio_state = (ast == true) ? SunXI::LOW : SunXI::HIGH; -#endif // SIGNAL_CONTROL_MODE - - LOGTRACE("gpio(%d) sunxi_state(%d)", gpio_num, sunxi_gpio_state) - - int bank = SunXI::GPIO_BANK(gpio_num); // gpio >> 5 - int num = SunXI::GPIO_NUM(gpio_num); // gpio & 0x1F - - volatile SunXI::sunxi_gpio_t *pio = &(pio_map->gpio_bank[bank]); - - /* DK, for PL and PM */ - if (bank >= 11) { - LOGTRACE("bank > 11") - bank -= 11; - pio = &(r_pio_map->gpio_bank[bank]); - } - - if (sunxi_gpio_state == SunXI::HIGH) - pio->DAT = pio->DAT & ~(1 << num); - else - pio->DAT = pio->DAT | (1 << num); -} - -void GPIOBUS_BananaM2p::DisableIRQ() -{ - *tmr_ctrl = 0b00; -} - -void GPIOBUS_BananaM2p::EnableIRQ() -{ - *tmr_ctrl = 0b11; -} - -void GPIOBUS_BananaM2p::PinConfig(int pin, int mode) -{ - GPIO_FUNCTION_TRACE - int gpio_num = pin; - int sunxi_direction = (mode == GPIO_INPUT) ? SunXI::INPUT : SunXI::OUTPUT; - - sunxi_setup_gpio(gpio_num, sunxi_direction, -1); -} - -void GPIOBUS_BananaM2p::PullConfig(int pin, int mode) -{ - GPIO_FUNCTION_TRACE -#if defined(__x86_64__) || defined(__X86__) || defined(__aarch64__) - dummy_var++; // Need to do something to prevent Sonar from claiming this should be a const function - (void)pin; - (void)mode; - return; -#else - - // Note: this will throw an exception if an invalid pin is specified - int gpio_num = pin; - int pull_up_down_state = 0; - - switch (mode) { - case GPIO_PULLNONE: - pull_up_down_state = SunXI::PUD_OFF; - break; - case GPIO_PULLUP: - pull_up_down_state = SunXI::PUD_UP; - break; - case GPIO_PULLDOWN: - pull_up_down_state = SunXI::PUD_DOWN; - break; - default: - LOGERROR("%s INVALID PIN MODE", __PRETTY_FUNCTION__); - return; - } - - uint32_t regval = 0; - int bank = SunXI::GPIO_BANK(gpio_num); // gpio >> 5 - int index = SunXI::GPIO_PUL_INDEX(gpio_num); // (gpio & 0x1f) >> 4 - int offset = SunXI::GPIO_PUL_OFFSET(gpio_num); // (gpio) & 0x0F) << 1 - LOGTRACE("%s gpio(%d) bank(%d) index(%d) offset(%d)", __PRETTY_FUNCTION__, gpio_num, bank, index, offset) - - volatile SunXI::sunxi_gpio_t *pio = &(pio_map->gpio_bank[bank]); - /* DK, for PL and PM */ - if (bank >= 11) { - bank -= 11; - pio = &(r_pio_map->gpio_bank[bank]); - } - - regval = *(&pio->PULL[0] + index); - regval &= ~(3 << offset); - regval |= pull_up_down_state << offset; - pio->PULL[0 + index] = regval; -#endif -} - -void GPIOBUS_BananaM2p::PinSetSignal(int pin, bool ast) -{ - GPIO_FUNCTION_TRACE - int gpio_num = pin; - - int sunxi_gpio_state = (ast == true) ? SunXI::HIGH : SunXI::LOW; - sunxi_output_gpio(gpio_num, sunxi_gpio_state); -} - -void GPIOBUS_BananaM2p::DrvConfig(uint32_t drive) -{ - GPIO_FUNCTION_TRACE - - for (auto pin : SignalTable) { - if (pin == -1) { - continue; - } - - LOGTRACE("Configuring GPIO %d to drive strength %d", pin, drive) - - uint32_t regval = 0; - int bank = SunXI::GPIO_BANK(pin); // gpio >> 5 - int index = SunXI::GPIO_DRV_INDEX(pin); // (gpio & 0x1F) >> 3 - int offset = SunXI::GPIO_DRV_OFFSET(pin); // ((gpio & 0x1F) & 0x7) << 2 - LOGTRACE("%s gpio(%d) bank(%d) index(%d) offset(%d)", __PRETTY_FUNCTION__, pin, bank, index, offset) - - volatile SunXI::sunxi_gpio_t *pio = &(pio_map->gpio_bank[bank]); - /* DK, for PL and PM */ - if (bank >= 11) { - bank -= 11; - pio = &(r_pio_map->gpio_bank[bank]); - } - - // Get current register value - regval = pio->DRV[0 + index]; - // Clear the DRV value for that gpio - regval &= ~(0x7 << offset); // 0xf? - // Set the new DRV strength - regval |= (drive & 0b11) << offset; - // Save back to the register - pio->DRV[0 + index] = regval; - } - - // #endif // if __arm__ -} - -uint32_t GPIOBUS_BananaM2p::Acquire() -{ - GPIO_FUNCTION_TRACE - - for (auto bank : gpio_banks) { - volatile SunXI::sunxi_gpio_t *pio = &(pio_map->gpio_bank[bank]); - /* DK, for PL and PM */ - if (bank >= 11) { - pio = &(r_pio_map->gpio_bank[bank - 11]); - } - - uint32_t regval = pio->DAT; - -#if SIGNAL_CONTROL_MODE < 2 - // Invert if negative logic (internal processing is unified to positive logic) - regval = ~regval; -#endif // SIGNAL_CONTROL_MODE - signals[bank] = regval; - } - // TODO: This should do something someday.... - return 0; -} - -int GPIOBUS_BananaM2p::sunxi_setup(void) -{ - GPIO_FUNCTION_TRACE -#if defined(__x86_64__) || defined(__X86__) || defined(__aarch64__) - dummy_var++; // Need to do something to prevent Sonar from claiming this should be a const function - return SunXI::SETUP_MMAP_FAIL; -#else - int mem_fd; - uint8_t *gpio_mem; - - // mmap the GPIO memory registers - if ((mem_fd = open("/dev/mem", O_RDWR | O_SYNC)) < 0) { - LOGERROR("Error: Unable to open /dev/mem. Are you running as root?") - LOGDEBUG("errno: [%08X] %s", errno, strerror(errno)); - return SunXI::SETUP_DEVMEM_FAIL; - } - - if ((gpio_mem = (uint8_t *)malloc(SunXI::BLOCK_SIZE + (SunXI::PAGE_SIZE - 1))) == NULL) { - LOGERROR("Error: Unable to allocate gpio memory. Are you running as root?") - LOGDEBUG("errno: [%08X] %s", errno, strerror(errno)); - return SunXI::SETUP_DEVMEM_FAIL; - } - - if ((uint32_t)gpio_mem % SunXI::PAGE_SIZE) - gpio_mem += SunXI::PAGE_SIZE - ((uint32_t)gpio_mem % SunXI::PAGE_SIZE); - - gpio_map = (uint32_t *)mmap((caddr_t)gpio_mem, SunXI::BLOCK_SIZE, PROT_READ | PROT_WRITE, MAP_SHARED | MAP_FIXED, - mem_fd, SunXI::SUNXI_GPIO_BASE); - if ((void *)gpio_map == MAP_FAILED) { - LOGERROR("Error: Unable to map gpio memory. Are you running as root?") - LOGDEBUG("errno: [%08X] %s", errno, strerror(errno)); - return SunXI::SETUP_MMAP_FAIL; - } - pio_map = (volatile SunXI::sunxi_gpio_reg *)(gpio_map + (SunXI::SUNXI_GPIO_REG_OFFSET >> 2)); - LOGTRACE("gpio_mem[%p] gpio_map[%p] pio_map[%p]", gpio_mem, gpio_map, pio_map) - // R_PIO GPIO LMN - r_gpio_map = (uint32_t *)mmap((caddr_t)0, SunXI::BLOCK_SIZE, PROT_READ | PROT_WRITE, MAP_SHARED, mem_fd, - SunXI::SUNXI_R_GPIO_BASE); - if ((void *)r_gpio_map == MAP_FAILED) { - LOGERROR("Error: Unable to map r_gpio memory. Are you running as root?") - LOGDEBUG("errno: [%08X] %s", errno, strerror(errno)); - return SunXI::SETUP_MMAP_FAIL; - } - r_pio_map = (volatile SunXI::sunxi_gpio_reg *)(r_gpio_map + (SunXI::SUNXI_R_GPIO_REG_OFFSET >> 2)); - LOGTRACE("r_gpio_map[%p] r_pio_map[%p]", r_gpio_map, r_pio_map) - - tmr_ctrl = gpio_map + ((SunXI::TMR_REGISTER_BASE - SunXI::SUNXI_GPIO_BASE) >> 2); - // LOGINFO("tmr_ctrl offset: %08X value: %08X", (TMR_REGISTER_BASE - SUNXI_GPIO_BASE), *tmr_ctrl); - - close(mem_fd); - return SETUP_OK; -#endif -} - -void GPIOBUS_BananaM2p::sunxi_setup_gpio(int pin, int direction, int pud) -{ - GPIO_FUNCTION_TRACE -#if defined(__x86_64__) || defined(__X86__) || defined(__aarch64__) - dummy_var++; // Need to do something to prevent Sonar from claiming this should be a const function - (void)pin; - (void)direction; - (void)pud; - return; -#else - uint32_t regval = 0; - int bank = SunXI::GPIO_BANK(pin); // gpio >> 5 - int index = SunXI::GPIO_CFG_INDEX(pin); // (gpio & 0x1F) >> 3 - int offset = SunXI::GPIO_CFG_OFFSET(pin); // ((gpio & 0x1F) & 0x7) << 2 - LOGTRACE("%s gpio(%d) bank(%d) index(%d) offset(%d)", __PRETTY_FUNCTION__, pin, bank, index, offset) - - volatile SunXI::sunxi_gpio_t *pio = &(pio_map->gpio_bank[bank]); - /* DK, for PL and PM */ - if (bank >= 11) { - bank -= 11; - pio = &(r_pio_map->gpio_bank[bank]); - } - - if (pud != -1) { - set_pullupdn(pin, pud); - } - regval = *(&pio->CFG[0 + index]); - regval &= ~(0x7 << offset); // 0xf? - if (SunXI::INPUT == direction) { - pio->CFG[0 + index] = regval; - } else if (SunXI::OUTPUT == direction) { - regval |= (1 << offset); - pio->CFG[0 + index] = regval; - } else { - LOGERROR("line:%d gpio number error %d", __LINE__, pin) - } -#endif -} - -void GPIOBUS_BananaM2p::sunxi_output_gpio(int pin, int value) -{ - GPIO_FUNCTION_TRACE - if (pin < 0) { - LOGWARN("Invalid GPIO Num") - return; - } - int bank = SunXI::GPIO_BANK(pin); // gpio >> 5 - int num = SunXI::GPIO_NUM(pin); // gpio & 0x1F - - LOGTRACE("%s gpio(%d) bank(%d) num(%d) value(%d)", __PRETTY_FUNCTION__, pin, bank, num, value) - volatile SunXI::sunxi_gpio_t *pio = &(pio_map->gpio_bank[bank]); - - /* DK, for PL and PM */ - if (bank >= 11) { - bank -= 11; - pio = &(r_pio_map->gpio_bank[bank]); - } - - if (value == 0) - pio->DAT = pio->DAT & ~(1 << num); - else - pio->DAT = pio->DAT | (1 << num); -} - -void GPIOBUS_BananaM2p::sunxi_set_all_gpios(array &mask, array &value) -{ - GPIO_FUNCTION_TRACE - for (size_t bank = 0; bank < mask.size(); bank++) { - if (mask[bank] == 0) { - continue; - } - - volatile SunXI::sunxi_gpio_t *pio; - if (bank < 11) { - pio = &(pio_map->gpio_bank[bank]); - } else { - pio = &(r_pio_map->gpio_bank[bank - 11]); - } - - uint32_t reg_val = pio->DAT; - reg_val &= ~mask[bank]; - reg_val |= value[bank]; - pio->DAT = reg_val; - } -} - -int GPIOBUS_BananaM2p::sunxi_input_gpio(int pin) const -{ - GPIO_FUNCTION_TRACE - uint32_t regval = 0; - int bank = SunXI::GPIO_BANK(pin); // gpio >> 5 - int num = SunXI::GPIO_NUM(pin); // gpio & 0x1F - - LOGTRACE("%s gpio(%d) bank(%d) num(%d)", __PRETTY_FUNCTION__, pin, bank, num) - volatile SunXI::sunxi_gpio_t *pio = &(pio_map->gpio_bank[bank]); - /* DK, for PL and PM */ - if (bank >= 11) { - bank -= 11; - pio = &(r_pio_map->gpio_bank[bank]); - } - - regval = pio->DAT; - regval = regval >> num; - regval &= 1; - return regval; -} - -void GPIOBUS_BananaM2p::set_pullupdn(int pin, int pud) -{ - GPIO_FUNCTION_TRACE - int clk_offset = SunXI::PULLUPDNCLK_OFFSET + (pin / 32); - int shift = (pin % 32); - -#ifdef BPI - if (bpi_found == 1) { - gpio = *(pinTobcm_BP + pin); - return sunxi_set_pullupdn(pin, pud); - } -#endif - if (pud == SunXI::PUD_DOWN) - *(gpio_map + SunXI::PULLUPDN_OFFSET) = (*(gpio_map + SunXI::PULLUPDN_OFFSET) & ~3) | SunXI::PUD_DOWN; - else if (pud == SunXI::PUD_UP) - *(gpio_map + SunXI::PULLUPDN_OFFSET) = (*(gpio_map + SunXI::PULLUPDN_OFFSET) & ~3) | SunXI::PUD_UP; - else // pud == PUD_OFF - *(gpio_map + SunXI::PULLUPDN_OFFSET) = *(gpio_map + SunXI::PULLUPDN_OFFSET) & ~3; - - SunXI::short_wait(); - *(gpio_map + clk_offset) = 1 << shift; - SunXI::short_wait(); - *(gpio_map + SunXI::PULLUPDN_OFFSET) = *(gpio_map + SunXI::PULLUPDN_OFFSET) & ~3; - *(gpio_map + clk_offset) = 0; -} diff --git a/cpp/hal/gpiobus_bananam2p.h b/cpp/hal/gpiobus_bananam2p.h deleted file mode 100644 index a404763f..00000000 --- a/cpp/hal/gpiobus_bananam2p.h +++ /dev/null @@ -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 - -//--------------------------------------------------------------------------- -// -// 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 GetSample(uint64_t timestamp) override - { - Acquire(); - return make_unique(signals, timestamp); - } - - bool SetupSelEvent(); - - volatile uint32_t *gpio_map = nullptr; - - // Timer control register - volatile uint32_t *tmr_ctrl; - array 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 SignalTable; - - void InitializeGpio(); - std::vector 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 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 &mask, array &value); - - array 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 -}; diff --git a/cpp/hal/gpiobus_factory.cpp b/cpp/hal/gpiobus_factory.cpp index a6fa6901..a9351a56 100644 --- a/cpp/hal/gpiobus_factory.cpp +++ b/cpp/hal/gpiobus_factory.cpp @@ -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 -#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 #include using namespace std; unique_ptr GPIOBUS_Factory::Create(BUS::mode_e mode) { - unique_ptr return_ptr; + unique_ptr 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(); - } else if (SBC_Version::IsRaspberryPi()) { - spdlog::trace("Creating GPIOBUS_Raspberry"); - return_ptr = make_unique(); + if (SBC_Version::IsRaspberryPi()) { + if (getuid()) { + spdlog::error("GPIO bus access requires root permissions. Are you running as root?"); + return nullptr; + } + + bus = make_unique(); } else { - spdlog::trace("Creating Virtual GPIOBUS"); - return_ptr = make_unique(); + bus = make_unique(); } - 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; } diff --git a/cpp/hal/gpiobus_raspberry.cpp b/cpp/hal/gpiobus_raspberry.cpp index 1fdd9ea3..5b6f77f7 100644 --- a/cpp/hal/gpiobus_raspberry.cpp +++ b/cpp/hal/gpiobus_raspberry.cpp @@ -15,10 +15,10 @@ // //--------------------------------------------------------------------------- +#include #include "hal/gpiobus_raspberry.h" #include "hal/gpiobus.h" #include "hal/systimer.h" -#include "hal/log.h" #include #include #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; } diff --git a/cpp/hal/gpiobus_raspberry.h b/cpp/hal/gpiobus_raspberry.h index b0f7fd17..a79df0e5 100644 --- a/cpp/hal/gpiobus_raspberry.h +++ b/cpp/hal/gpiobus_raspberry.h @@ -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 diff --git a/cpp/hal/gpiobus_virtual.cpp b/cpp/hal/gpiobus_virtual.cpp index 1e15b338..136dae24 100644 --- a/cpp/hal/gpiobus_virtual.cpp +++ b/cpp/hal/gpiobus_virtual.cpp @@ -6,8 +6,6 @@ // Powered by XM6 TypeG Technology. // Copyright (C) 2016-2020 GIMONS // -// [ GPIO-SCSI bus ] -// //--------------------------------------------------------------------------- #include "hal/gpiobus_virtual.h" diff --git a/cpp/hal/gpiobus_virtual.h b/cpp/hal/gpiobus_virtual.h index 0fba1cd0..85e00c79 100644 --- a/cpp/hal/gpiobus_virtual.h +++ b/cpp/hal/gpiobus_virtual.h @@ -5,7 +5,6 @@ // // Powered by XM6 TypeG Technology. // Copyright (C) 2016-2020 GIMONS -// [ GPIO-SCSI bus ] // //--------------------------------------------------------------------------- diff --git a/cpp/hal/pi_defs/bpi-gpio.h b/cpp/hal/pi_defs/bpi-gpio.h deleted file mode 100644 index 89541fe8..00000000 --- a/cpp/hal/pi_defs/bpi-gpio.h +++ /dev/null @@ -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; diff --git a/cpp/hal/pi_defs/bpi-m2p.h b/cpp/hal/pi_defs/bpi-m2p.h deleted file mode 100755 index 096fd260..00000000 --- a/cpp/hal/pi_defs/bpi-m2p.h +++ /dev/null @@ -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; diff --git a/cpp/hal/sbc_version.cpp b/cpp/hal/sbc_version.cpp index 99971b41..caebbedf 100644 --- a/cpp/hal/sbc_version.cpp +++ b/cpp/hal/sbc_version.cpp @@ -10,26 +10,18 @@ //--------------------------------------------------------------------------- #include "sbc_version.h" -#include "log.h" +#include #include #include #include -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> SBC_Version::m_proc_device_tree_mapping = { +// TODO Is there a better way to detect the Pi type than relying on strings? +const map> 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(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 buf; fread(buf.data(), 1, buf.size(), fp) == buf.size()) { + if (array 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 diff --git a/cpp/hal/sbc_version.h b/cpp/hal/sbc_version.h index 36922b5a..c51100e4 100644 --- a/cpp/hal/sbc_version.h +++ b/cpp/hal/sbc_version.h @@ -15,6 +15,8 @@ #include #include +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> m_proc_device_tree_mapping; + static const map> 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); }; diff --git a/cpp/hal/sunxi_utils.cpp b/cpp/hal/sunxi_utils.cpp deleted file mode 100644 index f4b150a1..00000000 --- a/cpp/hal/sunxi_utils.cpp +++ /dev/null @@ -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 -#include - -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()); -} diff --git a/cpp/hal/sunxi_utils.h b/cpp/hal/sunxi_utils.h deleted file mode 100644 index 14e7d8f7..00000000 --- a/cpp/hal/sunxi_utils.h +++ /dev/null @@ -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 -#ifndef __arm__ -#include -#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 -}; \ No newline at end of file diff --git a/cpp/hal/systimer.cpp b/cpp/hal/systimer.cpp index 21dc7b22..c2b4e7b8 100644 --- a/cpp/hal/systimer.cpp +++ b/cpp/hal/systimer.cpp @@ -12,31 +12,25 @@ //--------------------------------------------------------------------------- #include "hal/systimer.h" -#include "hal/systimer_allwinner.h" #include "hal/systimer_raspberry.h" #include -#include #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 SysTimer::systimer_ptr; +using namespace std; + +unique_ptr SysTimer::systimer_ptr; void SysTimer::Init() { - spdlog::trace(__PRETTY_FUNCTION__); - if (!initialized) { if (SBC_Version::IsRaspberryPi()) { systimer_ptr = make_unique(); is_raspberry = true; - } else if (SBC_Version::IsBananaPi()) { - systimer_ptr = make_unique(); - 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) { diff --git a/cpp/hal/systimer_allwinner.cpp b/cpp/hal/systimer_allwinner.cpp deleted file mode 100644 index 077dba57..00000000 --- a/cpp/hal/systimer_allwinner.cpp +++ /dev/null @@ -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 - -#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) - ; -} diff --git a/cpp/hal/systimer_allwinner.h b/cpp/hal/systimer_allwinner.h deleted file mode 100644 index 8378e1ac..00000000 --- a/cpp/hal/systimer_allwinner.h +++ /dev/null @@ -1,106 +0,0 @@ -//--------------------------------------------------------------------------- -// -// SCSI Target Emulator PiSCSI -// for Raspberry Pi -// -// Copyright (C) 2022 akuker -// -// [ High resolution timer ] -// -//--------------------------------------------------------------------------- -#pragma once - -#include "systimer.h" -#include -#include - -//=========================================================================== -// -// 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; -}; diff --git a/cpp/hal/systimer_raspberry.cpp b/cpp/hal/systimer_raspberry.cpp index 249642cb..8814ea02 100644 --- a/cpp/hal/systimer_raspberry.cpp +++ b/cpp/hal/systimer_raspberry.cpp @@ -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 maxclock = {32, 0, 0x00030004, 8, 0, 4, 0, 0}; + const array 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) ; } diff --git a/cpp/scsidump/scsidump_core.cpp b/cpp/scsidump/scsidump_core.cpp index 9df536ca..971d79b6 100644 --- a/cpp/scsidump/scsidump_core.cpp +++ b/cpp/scsidump/scsidump_core.cpp @@ -119,6 +119,9 @@ void ScsiDump::ParseArguments(span 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(); diff --git a/cpp/scsiloop/scsiloop_gpio.cpp b/cpp/scsiloop/scsiloop_gpio.cpp index 8032eadf..97d53192 100644 --- a/cpp/scsiloop/scsiloop_gpio.cpp +++ b/cpp/scsiloop/scsiloop_gpio.cpp @@ -7,6 +7,7 @@ // //--------------------------------------------------------------------------- +#include #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()); } }