diff --git a/cpp/Makefile b/cpp/Makefile index 3bdacb03..76359979 100644 --- a/cpp/Makefile +++ b/cpp/Makefile @@ -100,7 +100,6 @@ SRC_RASCSI_CORE += $(shell find ./rascsi -name '*.cpp') SRC_RASCSI_CORE += $(shell find ./controllers -name '*.cpp') SRC_RASCSI_CORE += $(shell find ./devices -name '*.cpp') SRC_RASCSI_CORE += $(shell find ./hal -name '*.cpp') -SRC_RASCSI_CORE += $(shell find ./hal/boards -name '*.cpp') SRC_RASCSI = rascsi.cpp diff --git a/cpp/bus.h b/cpp/bus.h index 52de3be4..179b40a3 100644 --- a/cpp/bus.h +++ b/cpp/bus.h @@ -13,6 +13,7 @@ #include "scsi.h" #include #include +#include "hal/board_type.h" using namespace std; @@ -45,7 +46,8 @@ public: virtual ~BUS() = default; // Basic Functions - virtual bool Init(mode_e mode) = 0; + virtual bool Init(mode_e mode, board_type::rascsi_board_type_e rascsi_type ) = 0; + virtual void Reset() = 0; virtual void Cleanup() = 0; phase_t GetPhase(); @@ -100,9 +102,9 @@ public: virtual int ReceiveHandShake(BYTE *buf, int count) = 0; virtual int SendHandShake(BYTE *buf, int count, int delay_after_bytes) = 0; - virtual bool GetSignal(int pin) const = 0; + virtual bool GetSignal(board_type::pi_physical_pin_e pin) const = 0; // Get SCSI input signal value - virtual void SetSignal(int pin, bool ast) = 0; + virtual void SetSignal(board_type::pi_physical_pin_e pin, bool ast) = 0; // Set SCSI output signal value static const int SEND_NO_DELAY = -1; // Passed into SendHandShake when we don't want to delay diff --git a/cpp/hal/board_type.h b/cpp/hal/board_type.h index 1b7938cd..15b60e93 100644 --- a/cpp/hal/board_type.h +++ b/cpp/hal/board_type.h @@ -69,7 +69,7 @@ enum class active_high_low_e : int { ACTIVE_LOW = 0, // Equivalent of "OFF" in old code }; -struct Rascsi_Board_Type { +struct Rascsi_Board_Struct { public: const std::string connect_desc; @@ -110,9 +110,19 @@ struct Rascsi_Board_Type { const pi_physical_pin_e pin_sel; // SEL }; -// extern const Rascsi_Board_Type board_type_aibom; -// extern const Rascsi_Board_Type board_type_fullspec; -// extern const Rascsi_Board_Type board_type_gamernium; -// extern const Rascsi_Board_Type board_type_standard; +typedef struct Rascsi_Board_Struct Rascsi_Board_Type; + +// Operation modes definition +enum class rascsi_board_type_e { + BOARD_TYPE_AIBOM, + BOARD_TYPE_FULLSPEC, + BOARD_TYPE_GAMERNIUM, + BOARD_TYPE_STANDARD, +}; + +extern const Rascsi_Board_Type board_definition_aibom; +extern const Rascsi_Board_Type board_definition_fullspec; +extern const Rascsi_Board_Type board_definition_gamernium; +extern const Rascsi_Board_Type board_definition_standard; } // namespace board_type \ No newline at end of file diff --git a/cpp/hal/boards/board_type_aibom.cpp b/cpp/hal/boards/board_type_aibom.cpp index a88b59c7..8a2493df 100644 --- a/cpp/hal/boards/board_type_aibom.cpp +++ b/cpp/hal/boards/board_type_aibom.cpp @@ -15,7 +15,7 @@ namespace board_type { // RaSCSI Adapter Aibom version -const Rascsi_Board_Type board_type_aibom = { +const Rascsi_Board_Type board_definition_aibom = { .connect_desc = "AIBOM PRODUCTS version", // Startup message diff --git a/cpp/hal/boards/board_type_fullspec.cpp b/cpp/hal/boards/board_type_fullspec.cpp index da412fd5..fb4035c4 100644 --- a/cpp/hal/boards/board_type_fullspec.cpp +++ b/cpp/hal/boards/board_type_fullspec.cpp @@ -13,7 +13,7 @@ namespace board_type{ // RaSCSI standard (SCSI logic, standard pin assignment) -const Rascsi_Board_Type board_type_fullspec = { +const Rascsi_Board_Type board_definition_fullspec = { .connect_desc = "FULLSPEC", // Startup message diff --git a/cpp/hal/boards/board_type_gamernium.cpp b/cpp/hal/boards/board_type_gamernium.cpp index 967c4e5a..31db7e23 100644 --- a/cpp/hal/boards/board_type_gamernium.cpp +++ b/cpp/hal/boards/board_type_gamernium.cpp @@ -15,7 +15,7 @@ namespace board_type { // RaSCSI Adapter GAMERnium.com version -const Rascsi_Board_Type board_type_gamernium = { +const Rascsi_Board_Type board_definition_gamernium = { .connect_desc = "GAMERnium.com version", // Startup message diff --git a/cpp/hal/boards/board_type_standard.cpp b/cpp/hal/boards/board_type_standard.cpp index fffa5bf2..6b39ce6b 100644 --- a/cpp/hal/boards/board_type_standard.cpp +++ b/cpp/hal/boards/board_type_standard.cpp @@ -14,7 +14,7 @@ namespace board_type { // RaSCSI standard (SCSI logic, standard pin assignment) -const Rascsi_Board_Type board_type_standard = { +const Rascsi_Board_Type board_definition_standard = { .connect_desc = "STANDARD", // Startup message diff --git a/cpp/hal/gpiobus.cpp b/cpp/hal/gpiobus.cpp index 80993a12..d01d98e9 100644 --- a/cpp/hal/gpiobus.cpp +++ b/cpp/hal/gpiobus.cpp @@ -74,11 +74,50 @@ const static int SCSI_DELAY_SEND_DATA_DAYNAPORT_US = 100; using namespace std; // Nothing SBC hardware specific should be done in this function -bool GPIOBUS::Init(mode_e mode) +bool GPIOBUS::Init(mode_e mode, board_type::rascsi_board_type_e rascsi_type) { GPIO_FUNCTION_TRACE + + // Figure out what type of board is connected. + switch (rascsi_type) { + case board_type::rascsi_board_type_e::BOARD_TYPE_AIBOM: + board = make_shared(board_type::board_definition_aibom); + break; + case board_type::rascsi_board_type_e::BOARD_TYPE_FULLSPEC: + board = make_shared(board_type::board_definition_fullspec); + break; + case board_type::rascsi_board_type_e::BOARD_TYPE_GAMERNIUM: + board = make_shared(board_type::board_definition_gamernium); + break; + case board_type::rascsi_board_type_e::BOARD_TYPE_STANDARD: + board = make_shared(board_type::board_definition_standard); + break; + } + board = make_shared(board_type::board_definition_aibom); + // Save operation mode actmode = mode; + + SignalTable[0] = board->pin_dt0; + SignalTable[1] = board->pin_dt1; + SignalTable[2] = board->pin_dt2; + SignalTable[3] = board->pin_dt3; + SignalTable[4] = board->pin_dt4; + SignalTable[5] = board->pin_dt5; + SignalTable[6] = board->pin_dt6; + SignalTable[7] = board->pin_dt7; + SignalTable[8] = board->pin_dp; + SignalTable[9] = board->pin_sel; + SignalTable[10] = board->pin_atn; + SignalTable[11] = board->pin_rst; + SignalTable[12] = board->pin_ack; + SignalTable[13] = board->pin_bsy; + SignalTable[14] = board->pin_msg; + SignalTable[15] = board->pin_cd; + SignalTable[16] = board->pin_io; + SignalTable[17] = board->pin_req; + SignalTable[18] = board_type::pi_physical_pin_e::PI_PHYS_PIN_NONE; + return true; } @@ -93,19 +132,19 @@ void GPIOBUS::Cleanup() #endif // USE_SEL_EVENT_ENABLE // Set control signals - PinSetSignal(PIN_ENB, RASCSI_PIN_OFF); - PinSetSignal(PIN_ACT, RASCSI_PIN_OFF); - PinSetSignal(PIN_TAD, RASCSI_PIN_OFF); - PinSetSignal(PIN_IND, RASCSI_PIN_OFF); - PinSetSignal(PIN_DTD, RASCSI_PIN_OFF); - PinConfig(PIN_ACT, GPIO_INPUT); - PinConfig(PIN_TAD, GPIO_INPUT); - PinConfig(PIN_IND, GPIO_INPUT); - PinConfig(PIN_DTD, GPIO_INPUT); + PinSetSignal(board->pin_enb, RASCSI_PIN_OFF); + PinSetSignal(board->pin_act, RASCSI_PIN_OFF); + PinSetSignal(board->pin_tad, RASCSI_PIN_OFF); + PinSetSignal(board->pin_ind, RASCSI_PIN_OFF); + PinSetSignal(board->pin_dtd, RASCSI_PIN_OFF); + PinConfig(board->pin_act, GPIO_INPUT); + PinConfig(board->pin_tad, GPIO_INPUT); + PinConfig(board->pin_ind, GPIO_INPUT); + PinConfig(board->pin_dtd, GPIO_INPUT); // Initialize all signals - for (int i = 0; SignalTable[i] >= 0; i++) { - int pin = SignalTable[i]; + for (int i = 0; SignalTable[i] != board_type::pi_physical_pin_e::PI_PHYS_PIN_NONE; i++) { + board_type::pi_physical_pin_e pin = SignalTable[i]; PinSetSignal(pin, RASCSI_PIN_OFF); PinConfig(pin, GPIO_INPUT); PullConfig(pin, GPIO_PULLNONE); @@ -123,15 +162,15 @@ void GPIOBUS::Reset() return; #else int i; - int j; + board_type::pi_physical_pin_e j; // Turn off active signal - SetControl(PIN_ACT, ACT_OFF); + SetControl(board->pin_act, ACT_OFF); // Set all signals to off for (i = 0;; i++) { j = SignalTable[i]; - if (j < 0) { + if (j == board_type::pi_physical_pin_e::PI_PHYS_PIN_NONE) { break; } @@ -142,60 +181,60 @@ void GPIOBUS::Reset() // Target mode // Set target signal to input - SetControl(PIN_TAD, TAD_IN); - SetMode(PIN_BSY, RASCSI_PIN_IN); - SetMode(PIN_MSG, RASCSI_PIN_IN); - SetMode(PIN_CD, RASCSI_PIN_IN); - SetMode(PIN_REQ, RASCSI_PIN_IN); - SetMode(PIN_IO, RASCSI_PIN_IN); + SetControl(board->pin_tad, TAD_IN); + SetMode(board->pin_bsy, RASCSI_PIN_IN); + SetMode(board->pin_msg, RASCSI_PIN_IN); + SetMode(board->pin_cd, RASCSI_PIN_IN); + SetMode(board->pin_req, RASCSI_PIN_IN); + SetMode(board->pin_io, RASCSI_PIN_IN); // Set the initiator signal to input - SetControl(PIN_IND, IND_IN); - SetMode(PIN_SEL, RASCSI_PIN_IN); - SetMode(PIN_ATN, RASCSI_PIN_IN); - SetMode(PIN_ACK, RASCSI_PIN_IN); - SetMode(PIN_RST, RASCSI_PIN_IN); + SetControl(board->pin_ind, IND_IN); + SetMode(board->pin_sel, RASCSI_PIN_IN); + SetMode(board->pin_atn, RASCSI_PIN_IN); + SetMode(board->pin_ack, RASCSI_PIN_IN); + SetMode(board->pin_rst, RASCSI_PIN_IN); // Set data bus signals to input - SetControl(PIN_DTD, DTD_IN); - SetMode(PIN_DT0, RASCSI_PIN_IN); - SetMode(PIN_DT1, RASCSI_PIN_IN); - SetMode(PIN_DT2, RASCSI_PIN_IN); - SetMode(PIN_DT3, RASCSI_PIN_IN); - SetMode(PIN_DT4, RASCSI_PIN_IN); - SetMode(PIN_DT5, RASCSI_PIN_IN); - SetMode(PIN_DT6, RASCSI_PIN_IN); - SetMode(PIN_DT7, RASCSI_PIN_IN); - SetMode(PIN_DP, RASCSI_PIN_IN); + SetControl(board->pin_dtd, DTD_IN); + SetMode(board->pin_dt0, RASCSI_PIN_IN); + SetMode(board->pin_dt1, RASCSI_PIN_IN); + SetMode(board->pin_dt2, RASCSI_PIN_IN); + SetMode(board->pin_dt3, RASCSI_PIN_IN); + SetMode(board->pin_dt4, RASCSI_PIN_IN); + SetMode(board->pin_dt5, RASCSI_PIN_IN); + SetMode(board->pin_dt6, RASCSI_PIN_IN); + SetMode(board->pin_dt7, RASCSI_PIN_IN); + SetMode(board->pin_dp, RASCSI_PIN_IN); } else { // Initiator mode // Set target signal to input - SetControl(PIN_TAD, TAD_IN); - SetMode(PIN_BSY, RASCSI_PIN_IN); - SetMode(PIN_MSG, RASCSI_PIN_IN); - SetMode(PIN_CD, RASCSI_PIN_IN); - SetMode(PIN_REQ, RASCSI_PIN_IN); - SetMode(PIN_IO, RASCSI_PIN_IN); + SetControl(board->pin_tad, TAD_IN); + SetMode(board->pin_bsy, RASCSI_PIN_IN); + SetMode(board->pin_msg, RASCSI_PIN_IN); + SetMode(board->pin_cd, RASCSI_PIN_IN); + SetMode(board->pin_req, RASCSI_PIN_IN); + SetMode(board->pin_io, RASCSI_PIN_IN); // Set the initiator signal to output - SetControl(PIN_IND, IND_OUT); - SetMode(PIN_SEL, RASCSI_PIN_OUT); - SetMode(PIN_ATN, RASCSI_PIN_OUT); - SetMode(PIN_ACK, RASCSI_PIN_OUT); - SetMode(PIN_RST, RASCSI_PIN_OUT); + SetControl(board->pin_ind, IND_OUT); + SetMode(board->pin_sel, RASCSI_PIN_OUT); + SetMode(board->pin_atn, RASCSI_PIN_OUT); + SetMode(board->pin_ack, RASCSI_PIN_OUT); + SetMode(board->pin_rst, RASCSI_PIN_OUT); // Set the data bus signals to output - SetControl(PIN_DTD, DTD_OUT); - SetMode(PIN_DT0, RASCSI_PIN_OUT); - SetMode(PIN_DT1, RASCSI_PIN_OUT); - SetMode(PIN_DT2, RASCSI_PIN_OUT); - SetMode(PIN_DT3, RASCSI_PIN_OUT); - SetMode(PIN_DT4, RASCSI_PIN_OUT); - SetMode(PIN_DT5, RASCSI_PIN_OUT); - SetMode(PIN_DT6, RASCSI_PIN_OUT); - SetMode(PIN_DT7, RASCSI_PIN_OUT); - SetMode(PIN_DP, RASCSI_PIN_OUT); + SetControl(board->pin_dtd, DTD_OUT); + SetMode(board->pin_dt0, RASCSI_PIN_OUT); + SetMode(board->pin_dt1, RASCSI_PIN_OUT); + SetMode(board->pin_dt2, RASCSI_PIN_OUT); + SetMode(board->pin_dt3, RASCSI_PIN_OUT); + SetMode(board->pin_dt4, RASCSI_PIN_OUT); + SetMode(board->pin_dt5, RASCSI_PIN_OUT); + SetMode(board->pin_dt6, RASCSI_PIN_OUT); + SetMode(board->pin_dt7, RASCSI_PIN_OUT); + SetMode(board->pin_dp, RASCSI_PIN_OUT); } // Initialize all signals @@ -206,46 +245,46 @@ void GPIOBUS::Reset() void GPIOBUS::SetENB(bool ast) { GPIO_FUNCTION_TRACE - PinSetSignal(PIN_ENB, ast ? ENB_ON : ENB_OFF); + PinSetSignal(board->pin_enb, ast ? ENB_ON : ENB_OFF); } bool GPIOBUS::GetBSY() const { GPIO_FUNCTION_TRACE - return GetSignal(PIN_BSY); + return GetSignal(board->pin_bsy); } void GPIOBUS::SetBSY(bool ast) { GPIO_FUNCTION_TRACE // Set BSY signal - SetSignal(PIN_BSY, ast); + SetSignal(board->pin_bsy, ast); if (actmode == mode_e::TARGET) { if (ast) { // Turn on ACTIVE signal - SetControl(PIN_ACT, ACT_ON); + SetControl(board->pin_act, ACT_ON); // Set Target signal to output - SetControl(PIN_TAD, TAD_OUT); + SetControl(board->pin_tad, TAD_OUT); - SetMode(PIN_BSY, RASCSI_PIN_OUT); - SetMode(PIN_MSG, RASCSI_PIN_OUT); - SetMode(PIN_CD, RASCSI_PIN_OUT); - SetMode(PIN_REQ, RASCSI_PIN_OUT); - SetMode(PIN_IO, RASCSI_PIN_OUT); + SetMode(board->pin_bsy, RASCSI_PIN_OUT); + SetMode(board->pin_msg, RASCSI_PIN_OUT); + SetMode(board->pin_cd, RASCSI_PIN_OUT); + SetMode(board->pin_req, RASCSI_PIN_OUT); + SetMode(board->pin_io, RASCSI_PIN_OUT); } else { // Turn off the ACTIVE signal - SetControl(PIN_ACT, ACT_OFF); + SetControl(board->pin_act, ACT_OFF); // Set the target signal to input - SetControl(PIN_TAD, TAD_IN); + SetControl(board->pin_tad, TAD_IN); - SetMode(PIN_BSY, RASCSI_PIN_IN); - SetMode(PIN_MSG, RASCSI_PIN_IN); - SetMode(PIN_CD, RASCSI_PIN_IN); - SetMode(PIN_REQ, RASCSI_PIN_IN); - SetMode(PIN_IO, RASCSI_PIN_IN); + SetMode(board->pin_bsy, RASCSI_PIN_IN); + SetMode(board->pin_msg, RASCSI_PIN_IN); + SetMode(board->pin_cd, RASCSI_PIN_IN); + SetMode(board->pin_req, RASCSI_PIN_IN); + SetMode(board->pin_io, RASCSI_PIN_IN); } } } @@ -253,7 +292,7 @@ void GPIOBUS::SetBSY(bool ast) bool GPIOBUS::GetSEL() const { GPIO_FUNCTION_TRACE - return GetSignal(PIN_SEL); + return GetSignal(board->pin_sel); } void GPIOBUS::SetSEL(bool ast) @@ -261,114 +300,114 @@ void GPIOBUS::SetSEL(bool ast) GPIO_FUNCTION_TRACE if (actmode == mode_e::INITIATOR && ast) { // Turn on ACTIVE signal - SetControl(PIN_ACT, ACT_ON); + SetControl(board->pin_act, ACT_ON); } // Set SEL signal - SetSignal(PIN_SEL, ast); + SetSignal(board->pin_sel, ast); } bool GPIOBUS::GetATN() const { GPIO_FUNCTION_TRACE - return GetSignal(PIN_ATN); + return GetSignal(board->pin_atn); } void GPIOBUS::SetATN(bool ast) { GPIO_FUNCTION_TRACE - SetSignal(PIN_ATN, ast); + SetSignal(board->pin_atn, ast); } bool GPIOBUS::GetACK() const { GPIO_FUNCTION_TRACE - return GetSignal(PIN_ACK); + return GetSignal(board->pin_ack); } void GPIOBUS::SetACK(bool ast) { GPIO_FUNCTION_TRACE - SetSignal(PIN_ACK, ast); + SetSignal(board->pin_ack, ast); } bool GPIOBUS::GetACT() const { GPIO_FUNCTION_TRACE - return GetSignal(PIN_ACT); + return GetSignal(board->pin_act); } void GPIOBUS::SetACT(bool ast) { GPIO_FUNCTION_TRACE - SetSignal(PIN_ACT, ast); + SetSignal(board->pin_act, ast); } bool GPIOBUS::GetRST() const { GPIO_FUNCTION_TRACE - return GetSignal(PIN_RST); + return GetSignal(board->pin_rst); } void GPIOBUS::SetRST(bool ast) { GPIO_FUNCTION_TRACE - SetSignal(PIN_RST, ast); + SetSignal(board->pin_rst, ast); } bool GPIOBUS::GetMSG() const { GPIO_FUNCTION_TRACE - return GetSignal(PIN_MSG); + return GetSignal(board->pin_msg); } void GPIOBUS::SetMSG(bool ast) { GPIO_FUNCTION_TRACE - SetSignal(PIN_MSG, ast); + SetSignal(board->pin_msg, ast); } bool GPIOBUS::GetCD() const { GPIO_FUNCTION_TRACE - return GetSignal(PIN_CD); + return GetSignal(board->pin_cd); } void GPIOBUS::SetCD(bool ast) { GPIO_FUNCTION_TRACE - SetSignal(PIN_CD, ast); + SetSignal(board->pin_cd, ast); } bool GPIOBUS::GetIO() { GPIO_FUNCTION_TRACE - bool ast = GetSignal(PIN_IO); + bool ast = GetSignal(board->pin_io); if (actmode == mode_e::INITIATOR) { // Change the data input/output direction by IO signal if (ast) { - SetControl(PIN_DTD, DTD_IN); - SetMode(PIN_DT0, RASCSI_PIN_IN); - SetMode(PIN_DT1, RASCSI_PIN_IN); - SetMode(PIN_DT2, RASCSI_PIN_IN); - SetMode(PIN_DT3, RASCSI_PIN_IN); - SetMode(PIN_DT4, RASCSI_PIN_IN); - SetMode(PIN_DT5, RASCSI_PIN_IN); - SetMode(PIN_DT6, RASCSI_PIN_IN); - SetMode(PIN_DT7, RASCSI_PIN_IN); - SetMode(PIN_DP, RASCSI_PIN_IN); + SetControl(board->pin_dtd, DTD_IN); + SetMode(board->pin_dt0, RASCSI_PIN_IN); + SetMode(board->pin_dt1, RASCSI_PIN_IN); + SetMode(board->pin_dt2, RASCSI_PIN_IN); + SetMode(board->pin_dt3, RASCSI_PIN_IN); + SetMode(board->pin_dt4, RASCSI_PIN_IN); + SetMode(board->pin_dt5, RASCSI_PIN_IN); + SetMode(board->pin_dt6, RASCSI_PIN_IN); + SetMode(board->pin_dt7, RASCSI_PIN_IN); + SetMode(board->pin_dp, RASCSI_PIN_IN); } else { - SetControl(PIN_DTD, DTD_OUT); - SetMode(PIN_DT0, RASCSI_PIN_OUT); - SetMode(PIN_DT1, RASCSI_PIN_OUT); - SetMode(PIN_DT2, RASCSI_PIN_OUT); - SetMode(PIN_DT3, RASCSI_PIN_OUT); - SetMode(PIN_DT4, RASCSI_PIN_OUT); - SetMode(PIN_DT5, RASCSI_PIN_OUT); - SetMode(PIN_DT6, RASCSI_PIN_OUT); - SetMode(PIN_DT7, RASCSI_PIN_OUT); - SetMode(PIN_DP, RASCSI_PIN_OUT); + SetControl(board->pin_dtd, DTD_OUT); + SetMode(board->pin_dt0, RASCSI_PIN_OUT); + SetMode(board->pin_dt1, RASCSI_PIN_OUT); + SetMode(board->pin_dt2, RASCSI_PIN_OUT); + SetMode(board->pin_dt3, RASCSI_PIN_OUT); + SetMode(board->pin_dt4, RASCSI_PIN_OUT); + SetMode(board->pin_dt5, RASCSI_PIN_OUT); + SetMode(board->pin_dt6, RASCSI_PIN_OUT); + SetMode(board->pin_dt7, RASCSI_PIN_OUT); + SetMode(board->pin_dp, RASCSI_PIN_OUT); } } @@ -378,33 +417,33 @@ bool GPIOBUS::GetIO() void GPIOBUS::SetIO(bool ast) { GPIO_FUNCTION_TRACE - SetSignal(PIN_IO, ast); + SetSignal(board->pin_io, ast); if (actmode == mode_e::TARGET) { // Change the data input/output direction by IO signal if (ast) { - SetControl(PIN_DTD, DTD_OUT); + SetControl(board->pin_dtd, DTD_OUT); SetDAT(0); - SetMode(PIN_DT0, RASCSI_PIN_OUT); - SetMode(PIN_DT1, RASCSI_PIN_OUT); - SetMode(PIN_DT2, RASCSI_PIN_OUT); - SetMode(PIN_DT3, RASCSI_PIN_OUT); - SetMode(PIN_DT4, RASCSI_PIN_OUT); - SetMode(PIN_DT5, RASCSI_PIN_OUT); - SetMode(PIN_DT6, RASCSI_PIN_OUT); - SetMode(PIN_DT7, RASCSI_PIN_OUT); - SetMode(PIN_DP, RASCSI_PIN_OUT); + SetMode(board->pin_dt0, RASCSI_PIN_OUT); + SetMode(board->pin_dt1, RASCSI_PIN_OUT); + SetMode(board->pin_dt2, RASCSI_PIN_OUT); + SetMode(board->pin_dt3, RASCSI_PIN_OUT); + SetMode(board->pin_dt4, RASCSI_PIN_OUT); + SetMode(board->pin_dt5, RASCSI_PIN_OUT); + SetMode(board->pin_dt6, RASCSI_PIN_OUT); + SetMode(board->pin_dt7, RASCSI_PIN_OUT); + SetMode(board->pin_dp, RASCSI_PIN_OUT); } else { - SetControl(PIN_DTD, DTD_IN); - SetMode(PIN_DT0, RASCSI_PIN_IN); - SetMode(PIN_DT1, RASCSI_PIN_IN); - SetMode(PIN_DT2, RASCSI_PIN_IN); - SetMode(PIN_DT3, RASCSI_PIN_IN); - SetMode(PIN_DT4, RASCSI_PIN_IN); - SetMode(PIN_DT5, RASCSI_PIN_IN); - SetMode(PIN_DT6, RASCSI_PIN_IN); - SetMode(PIN_DT7, RASCSI_PIN_IN); - SetMode(PIN_DP, RASCSI_PIN_IN); + SetControl(board->pin_dtd, DTD_IN); + SetMode(board->pin_dt0, RASCSI_PIN_IN); + SetMode(board->pin_dt1, RASCSI_PIN_IN); + SetMode(board->pin_dt2, RASCSI_PIN_IN); + SetMode(board->pin_dt3, RASCSI_PIN_IN); + SetMode(board->pin_dt4, RASCSI_PIN_IN); + SetMode(board->pin_dt5, RASCSI_PIN_IN); + SetMode(board->pin_dt6, RASCSI_PIN_IN); + SetMode(board->pin_dt7, RASCSI_PIN_IN); + SetMode(board->pin_dp, RASCSI_PIN_IN); } } } @@ -412,19 +451,19 @@ void GPIOBUS::SetIO(bool ast) bool GPIOBUS::GetREQ() const { GPIO_FUNCTION_TRACE - return GetSignal(PIN_REQ); + return GetSignal(board->pin_req); } void GPIOBUS::SetREQ(bool ast) { GPIO_FUNCTION_TRACE - SetSignal(PIN_REQ, ast); + SetSignal(board->pin_req, ast); } bool GPIOBUS::GetDP() const { GPIO_FUNCTION_TRACE - return GetSignal(PIN_DP); + return GetSignal(board->pin_dp); } //--------------------------------------------------------------------------- @@ -443,10 +482,10 @@ int GPIOBUS::CommandHandShake(BYTE *buf) DisableIRQ(); // Assert REQ signal - SetSignal(PIN_REQ, RASCSI_PIN_ON); + SetSignal(board->pin_req, RASCSI_PIN_ON); // Wait for ACK signal - bool ret = WaitSignal(PIN_ACK, RASCSI_PIN_ON); + bool ret = WaitSignal(board->pin_ack, RASCSI_PIN_ON); // Wait until the signal line stabilizes SysTimer::SleepNsec(SCSI_DELAY_BUS_SETTLE_DELAY_NS); @@ -455,7 +494,7 @@ int GPIOBUS::CommandHandShake(BYTE *buf) *buf = GetDAT(); // Disable REQ signal - SetSignal(PIN_REQ, RASCSI_PIN_OFF); + SetSignal(board->pin_req, RASCSI_PIN_OFF); // Timeout waiting for ACK assertion if (!ret) { @@ -464,7 +503,7 @@ int GPIOBUS::CommandHandShake(BYTE *buf) } // Wait for ACK to clear - ret = WaitSignal(PIN_ACK, RASCSI_PIN_OFF); + ret = WaitSignal(board->pin_ack, RASCSI_PIN_OFF); // Timeout waiting for ACK to clear if (!ret) { @@ -482,23 +521,23 @@ int GPIOBUS::CommandHandShake(BYTE *buf) // RaSCSI becomes ICD compatible by ignoring the prepended $1F byte before processing the CDB. if (*buf == 0x1F) { - SetSignal(PIN_REQ, RASCSI_PIN_ON); + SetSignal(board->pin_req, RASCSI_PIN_ON); - ret = WaitSignal(PIN_ACK, RASCSI_PIN_ON); + ret = WaitSignal(board->pin_ack, RASCSI_PIN_ON); SysTimer::SleepNsec(SCSI_DELAY_BUS_SETTLE_DELAY_NS); // Get the actual SCSI command *buf = GetDAT(); - SetSignal(PIN_REQ, RASCSI_PIN_OFF); + SetSignal(board->pin_req, RASCSI_PIN_OFF); if (!ret) { EnableIRQ(); return 0; } - WaitSignal(PIN_ACK, RASCSI_PIN_OFF); + WaitSignal(board->pin_ack, RASCSI_PIN_OFF); if (!ret) { EnableIRQ(); @@ -514,10 +553,10 @@ int GPIOBUS::CommandHandShake(BYTE *buf) int bytes_received; for (bytes_received = 1; bytes_received < command_byte_count; bytes_received++) { // Assert REQ signal - SetSignal(PIN_REQ, RASCSI_PIN_ON); + SetSignal(board->pin_req, RASCSI_PIN_ON); // Wait for ACK signal - ret = WaitSignal(PIN_ACK, RASCSI_PIN_ON); + ret = WaitSignal(board->pin_ack, RASCSI_PIN_ON); // Wait until the signal line stabilizes SysTimer::SleepNsec(SCSI_DELAY_BUS_SETTLE_DELAY_NS); @@ -526,7 +565,7 @@ int GPIOBUS::CommandHandShake(BYTE *buf) *buf = GetDAT(); // Clear the REQ signal - SetSignal(PIN_REQ, RASCSI_PIN_OFF); + SetSignal(board->pin_req, RASCSI_PIN_OFF); // Check for timeout waiting for ACK assertion if (!ret) { @@ -534,7 +573,7 @@ int GPIOBUS::CommandHandShake(BYTE *buf) } // Wait for ACK to clear - ret = WaitSignal(PIN_ACK, RASCSI_PIN_OFF); + ret = WaitSignal(board->pin_ack, RASCSI_PIN_OFF); // Check for timeout waiting for ACK to clear if (!ret) { @@ -567,10 +606,10 @@ int GPIOBUS::ReceiveHandShake(BYTE *buf, int count) if (actmode == mode_e::TARGET) { for (i = 0; i < count; i++) { // Assert the REQ signal - SetSignal(PIN_REQ, RASCSI_PIN_ON); + SetSignal(board->pin_req, RASCSI_PIN_ON); // Wait for ACK - bool ret = WaitSignal(PIN_ACK, RASCSI_PIN_ON); + bool ret = WaitSignal(board->pin_ack, RASCSI_PIN_ON); // Wait until the signal line stabilizes SysTimer::SleepNsec(SCSI_DELAY_BUS_SETTLE_DELAY_NS); @@ -579,7 +618,7 @@ int GPIOBUS::ReceiveHandShake(BYTE *buf, int count) *buf = GetDAT(); // Clear the REQ signal - SetSignal(PIN_REQ, RASCSI_PIN_OFF); + SetSignal(board->pin_req, RASCSI_PIN_OFF); // Check for timeout waiting for ACK signal if (!ret) { @@ -587,7 +626,7 @@ int GPIOBUS::ReceiveHandShake(BYTE *buf, int count) } // Wait for ACK to clear - ret = WaitSignal(PIN_ACK, RASCSI_PIN_OFF); + ret = WaitSignal(board->pin_ack, RASCSI_PIN_OFF); // Check for timeout waiting for ACK to clear if (!ret) { @@ -603,7 +642,7 @@ int GPIOBUS::ReceiveHandShake(BYTE *buf, int count) for (i = 0; i < count; i++) { // Wait for the REQ signal to be asserted - bool ret = WaitSignal(PIN_REQ, RASCSI_PIN_ON); + bool ret = WaitSignal(board->pin_req, RASCSI_PIN_ON); // Check for timeout waiting for REQ signal if (!ret) { @@ -622,13 +661,13 @@ int GPIOBUS::ReceiveHandShake(BYTE *buf, int count) *buf = GetDAT(); // Assert the ACK signal - SetSignal(PIN_ACK, RASCSI_PIN_ON); + SetSignal(board->pin_ack, RASCSI_PIN_ON); // Wait for REQ to clear - ret = WaitSignal(PIN_REQ, RASCSI_PIN_OFF); + ret = WaitSignal(board->pin_req, RASCSI_PIN_OFF); // Clear the ACK signal - SetSignal(PIN_ACK, RASCSI_PIN_OFF); + SetSignal(board->pin_ack, RASCSI_PIN_OFF); // Check for timeout waiting for REQ to clear if (!ret) { @@ -678,7 +717,7 @@ int GPIOBUS::SendHandShake(BYTE *buf, int count, int delay_after_bytes) SetDAT(*buf); // Wait for ACK to clear - bool ret = WaitSignal(PIN_ACK, RASCSI_PIN_OFF); + bool ret = WaitSignal(board->pin_ack, RASCSI_PIN_OFF); // Check for timeout waiting for ACK to clear if (!ret) { @@ -688,13 +727,13 @@ int GPIOBUS::SendHandShake(BYTE *buf, int count, int delay_after_bytes) // Already waiting for ACK to clear // Assert the REQ signal - SetSignal(PIN_REQ, RASCSI_PIN_ON); + SetSignal(board->pin_req, RASCSI_PIN_ON); // Wait for ACK - ret = WaitSignal(PIN_ACK, RASCSI_PIN_ON); + ret = WaitSignal(board->pin_ack, RASCSI_PIN_ON); // Clear REQ signal - SetSignal(PIN_REQ, RASCSI_PIN_OFF); + SetSignal(board->pin_req, RASCSI_PIN_OFF); // Check for timeout waiting for ACK to clear if (!ret) { @@ -706,7 +745,7 @@ int GPIOBUS::SendHandShake(BYTE *buf, int count, int delay_after_bytes) } // Wait for ACK to clear - WaitSignal(PIN_ACK, RASCSI_PIN_OFF); + WaitSignal(board->pin_ack, RASCSI_PIN_OFF); } else { // Get Phase uint32_t phase = Acquire() & GPIO_MCI; @@ -722,7 +761,7 @@ int GPIOBUS::SendHandShake(BYTE *buf, int count, int delay_after_bytes) SetDAT(*buf); // Wait for REQ to be asserted - bool ret = WaitSignal(PIN_REQ, RASCSI_PIN_ON); + bool ret = WaitSignal(board->pin_req, RASCSI_PIN_ON); // Check for timeout waiting for REQ to be asserted if (!ret) { @@ -737,13 +776,13 @@ int GPIOBUS::SendHandShake(BYTE *buf, int count, int delay_after_bytes) // Already waiting for REQ assertion // Assert the ACK signal - SetSignal(PIN_ACK, RASCSI_PIN_ON); + SetSignal(board->pin_ack, RASCSI_PIN_ON); // Wait for REQ to clear - ret = WaitSignal(PIN_REQ, RASCSI_PIN_OFF); + ret = WaitSignal(board->pin_req, RASCSI_PIN_OFF); // Clear the ACK signal - SetSignal(PIN_ACK, RASCSI_PIN_OFF); + SetSignal(board->pin_ack, RASCSI_PIN_OFF); // Check for timeout waiting for REQ to clear if (!ret) { @@ -809,9 +848,7 @@ void GPIOBUS::ClearSelectEvent() // Signal table // //--------------------------------------------------------------------------- -const array GPIOBUS::SignalTable = {PIN_DT0, PIN_DT1, PIN_DT2, PIN_DT3, PIN_DT4, PIN_DT5, PIN_DT6, - PIN_DT7, PIN_DP, PIN_SEL, PIN_ATN, PIN_RST, PIN_ACK, PIN_BSY, - PIN_MSG, PIN_CD, PIN_IO, PIN_REQ, -1}; +array GPIOBUS::SignalTable; //--------------------------------------------------------------------------- // @@ -822,7 +859,7 @@ void GPIOBUS::MakeTable(void) { GPIO_FUNCTION_TRACE - const array pintbl = {PIN_DT0, PIN_DT1, PIN_DT2, PIN_DT3, PIN_DT4, PIN_DT5, PIN_DT6, PIN_DT7, PIN_DP}; + [[maybe_unused]] const array pintbl = {board->pin_dt0, board->pin_dt1, board->pin_dt2, board->pin_dt3, board->pin_dt4, board->pin_dt5, board->pin_dt6, board->pin_dt7, board->pin_dp}; array tblParity; @@ -856,22 +893,23 @@ void GPIOBUS::MakeTable(void) bits |= (1 << 8); } - // Bit check - for (int j = 0; j < 9; j++) { - // Index and shift amount calculation - int index = pintbl[j] / 10; - int shift = (pintbl[j] % 10) * 3; + // TODO: THIS NEEDS TO BE MOVED DOWN TO THE BOARD_SPECIFIC REGION + // // Bit check + // for (int j = 0; j < 9; j++) { + // // Index and shift amount calculation + // int index = pintbl[j] / 10; + // int shift = (pintbl[j] % 10) * 3; - // Mask data - tblDatMsk[index][i] &= ~(0x7 << shift); + // // Mask data + // tblDatMsk[index][i] &= ~(0x7 << shift); - // Setting data - if (bits & 1) { - tblDatSet[index][i] |= (1 << shift); - } + // // Setting data + // if (bits & 1) { + // tblDatSet[index][i] |= (1 << shift); + // } - bits >>= 1; - } + // bits >>= 1; + // } } #else for (uint32_t i = 0; i < 0x100; i++) { @@ -911,7 +949,7 @@ void GPIOBUS::MakeTable(void) // Wait for signal change // //--------------------------------------------------------------------------- -bool GPIOBUS::WaitSignal(int pin, int ast) +bool GPIOBUS::WaitSignal(board_type::pi_physical_pin_e pin, int ast) { GPIO_FUNCTION_TRACE @@ -930,9 +968,15 @@ bool GPIOBUS::WaitSignal(int pin, int ast) } // Check for the signal edge - if (((signals >> pin) ^ ~ast) & 1) { + LOGWARN("THIS WONT WORK. NEEDS TO BE UPDATED"); + + if ((GetSignal(pin) ^ ~ast) & 1) { return true; } + + // if (((signals >> pin) ^ ~ast) & 1) { + // return true; + // } } while ((SysTimer::GetTimerLow() - now) < timeout); // We timed out waiting for the signal @@ -947,25 +991,43 @@ bool GPIOBUS::WaitSignal(int pin, int ast) BUS::phase_t GPIOBUS::GetPhaseRaw(uint32_t raw_data) { GPIO_FUNCTION_TRACE - // Selection Phase - if (GetPinRaw(raw_data, PIN_SEL)) { - if (GetPinRaw(raw_data, PIN_IO)) { - return BUS::phase_t::reselection; - } else { - return BUS::phase_t::selection; - } - } + (void)raw_data; + // // Selection Phase + // if (GetPinRaw(raw_data, board->pin_sel)) { + // if (GetPinRaw(raw_data, board->pin_io)) { + // return BUS::phase_t::reselection; + // } else { + // return BUS::phase_t::selection; + // } + // } - // Bus busy phase - if (!GetPinRaw(raw_data, PIN_BSY)) { - return BUS::phase_t::busfree; - } + // // Bus busy phase + // if (!GetPinRaw(raw_data, board->pin_bsy)) { + // return BUS::phase_t::busfree; + // } - // Get target phase from bus signal line - int mci = GetPinRaw(raw_data, PIN_MSG) ? 0x04 : 0x00; - mci |= GetPinRaw(raw_data, PIN_CD) ? 0x02 : 0x00; - mci |= GetPinRaw(raw_data, PIN_IO) ? 0x01 : 0x00; - return GetPhase(mci); + + LOGWARN("NOT IMPLEMENTED YET"); + return BUS::phase_t::busfree; +// // Selection Phase +// if (GetSignal(board->pin_sel)) { +// if (GetSignal(board->pin_io)) { +// return BUS::phase_t::reselection; +// } else { +// return BUS::phase_t::selection; +// } +// } + +// // Bus busy phase +// if (!GetPinRaw(raw_data, board->pin_bsy)) { +// return BUS::phase_t::busfree; +// } + +// // Get target phase from bus signal line +// int mci = GetPinRaw(raw_data, board->pin_msg) ? 0x04 : 0x00; +// mci |= GetPinRaw(raw_data, board->pin_cd) ? 0x02 : 0x00; +// mci |= GetPinRaw(raw_data, board->pin_io) ? 0x01 : 0x00; +// return GetPhase(mci); } //--------------------------------------------------------------------------- diff --git a/cpp/hal/gpiobus.h b/cpp/hal/gpiobus.h index 61f744b6..536e2266 100644 --- a/cpp/hal/gpiobus.h +++ b/cpp/hal/gpiobus.h @@ -11,9 +11,11 @@ #pragma once +#include "hal/board_type.h" #include "config.h" #include "scsi.h" #include +#include #ifdef __linux__ #include @@ -268,7 +270,8 @@ class GPIOBUS : public BUS GPIOBUS() = default; ~GPIOBUS() override = default; // Destructor - bool Init(mode_e mode = mode_e::TARGET) override; + bool Init(mode_e mode = mode_e::TARGET, board_type::rascsi_board_type_e + rascsi_type = board_type::rascsi_board_type_e::BOARD_TYPE_FULLSPEC) override; // Initialization void Reset() override; // Reset @@ -355,15 +358,15 @@ class GPIOBUS : public BUS // SCSI I/O signal control virtual void MakeTable() = 0; // Create work data - virtual void SetControl(int pin, bool ast) = 0; + virtual void SetControl(board_type::pi_physical_pin_e pin, bool ast) = 0; // Set Control Signal - virtual void SetMode(int pin, int mode) = 0; + virtual void SetMode(board_type::pi_physical_pin_e pin, int mode) = 0; // Set SCSI I/O mode - bool GetSignal(int pin) const override = 0; + bool GetSignal(board_type::pi_physical_pin_e pin) const override = 0; // Set Control Signal - void SetSignal(int pin, bool ast) override = 0; + void SetSignal(board_type::pi_physical_pin_e pin, bool ast) override = 0; // Set SCSI I/O mode - virtual bool WaitSignal(int pin, int ast) = 0; + virtual bool WaitSignal(board_type::pi_physical_pin_e pin, int ast) = 0; // Wait for a signal to change // Interrupt control virtual void DisableIRQ() = 0; @@ -372,22 +375,24 @@ class GPIOBUS : public BUS // IRQ Enabled // GPIO pin functionality settings - virtual void PinConfig(int pin, int mode) = 0; + virtual void PinConfig(board_type::pi_physical_pin_e pin, int mode) = 0; // GPIO pin direction setting - virtual void PullConfig(int pin, int mode) = 0; + virtual void PullConfig(board_type::pi_physical_pin_e pin, int mode) = 0; // GPIO pin pull up/down resistor setting - virtual void PinSetSignal(int pin, bool ast) = 0; + virtual void PinSetSignal(board_type::pi_physical_pin_e pin, bool ast) = 0; // Set GPIO output signal virtual void DrvConfig(uint32_t drive) = 0; // Set GPIO drive strength mode_e actmode = mode_e::TARGET; // Operation mode + shared_ptr board; + #if !defined(__x86_64__) && !defined(__X86__) uint32_t baseaddr = 0; // Base address #endif - static const array SignalTable; // signal table + static array SignalTable; // signal table #ifdef USE_SEL_EVENT_ENABLE struct gpioevent_request selevreq = {}; // SEL signal event request diff --git a/cpp/hal/gpiobus_allwinner.cpp b/cpp/hal/gpiobus_allwinner.cpp index d8f66cae..b439c83a 100644 --- a/cpp/hal/gpiobus_allwinner.cpp +++ b/cpp/hal/gpiobus_allwinner.cpp @@ -20,9 +20,9 @@ extern int wiringPiMode; #pragma GCC diagnostic ignored "-Wunused-variable" #pragma GCC diagnostic ignored "-Wunused-parameter" -bool GPIOBUS_Allwinner::Init(mode_e mode) +bool GPIOBUS_Allwinner::Init(mode_e mode, board_type::rascsi_board_type_e rascsi_type) { - GPIOBUS::Init(mode); + GPIOBUS::Init(mode, rascsi_type); // wiringPiSetup(); // wiringPiMode = WPI_MODE_GPIO; @@ -167,88 +167,88 @@ void GPIOBUS_Allwinner::Cleanup() void GPIOBUS_Allwinner::Reset() { -#if defined(__x86_64__) || defined(__X86__) +// #if defined(__x86_64__) || defined(__X86__) return; -#else - int i; - int j; +// #else +// int i; +// int j; - // Turn off active signal - SetControl(PIN_ACT, ACT_OFF); +// // Turn off active signal +// SetControl(PIN_ACT, ACT_OFF); - // Set all signals to off - for (i = 0;; i++) { - j = SignalTable[i]; - if (j < 0) { - break; - } +// // Set all signals to off +// for (i = 0;; i++) { +// j = SignalTable[i]; +// if (j < 0) { +// break; +// } - SetSignal(j, RASCSI_PIN_OFF); - } +// SetSignal(j, RASCSI_PIN_OFF); +// } - if (actmode == mode_e::TARGET) { - // Target mode +// if (actmode == mode_e::TARGET) { +// // Target mode - // Set target signal to input - SetControl(PIN_TAD, TAD_IN); - SetMode(PIN_BSY, RASCSI_PIN_IN); - SetMode(PIN_MSG, RASCSI_PIN_IN); - SetMode(PIN_CD, RASCSI_PIN_IN); - SetMode(PIN_REQ, RASCSI_PIN_IN); - SetMode(PIN_IO, RASCSI_PIN_IN); +// // Set target signal to input +// SetControl(PIN_TAD, TAD_IN); +// SetMode(PIN_BSY, RASCSI_PIN_IN); +// SetMode(PIN_MSG, RASCSI_PIN_IN); +// SetMode(PIN_CD, RASCSI_PIN_IN); +// SetMode(PIN_REQ, RASCSI_PIN_IN); +// SetMode(PIN_IO, RASCSI_PIN_IN); - // Set the initiator signal to input - SetControl(PIN_IND, IND_IN); - SetMode(PIN_SEL, RASCSI_PIN_IN); - SetMode(PIN_ATN, RASCSI_PIN_IN); - SetMode(PIN_ACK, RASCSI_PIN_IN); - SetMode(PIN_RST, RASCSI_PIN_IN); +// // Set the initiator signal to input +// SetControl(PIN_IND, IND_IN); +// SetMode(PIN_SEL, RASCSI_PIN_IN); +// SetMode(PIN_ATN, RASCSI_PIN_IN); +// SetMode(PIN_ACK, RASCSI_PIN_IN); +// SetMode(PIN_RST, RASCSI_PIN_IN); - // Set data bus signals to input - SetControl(PIN_DTD, DTD_IN); - SetMode(PIN_DT0, RASCSI_PIN_IN); - SetMode(PIN_DT1, RASCSI_PIN_IN); - SetMode(PIN_DT2, RASCSI_PIN_IN); - SetMode(PIN_DT3, RASCSI_PIN_IN); - SetMode(PIN_DT4, RASCSI_PIN_IN); - SetMode(PIN_DT5, RASCSI_PIN_IN); - SetMode(PIN_DT6, RASCSI_PIN_IN); - SetMode(PIN_DT7, RASCSI_PIN_IN); - SetMode(PIN_DP, RASCSI_PIN_IN); - } else { - // Initiator mode +// // Set data bus signals to input +// SetControl(PIN_DTD, DTD_IN); +// SetMode(PIN_DT0, RASCSI_PIN_IN); +// SetMode(PIN_DT1, RASCSI_PIN_IN); +// SetMode(PIN_DT2, RASCSI_PIN_IN); +// SetMode(PIN_DT3, RASCSI_PIN_IN); +// SetMode(PIN_DT4, RASCSI_PIN_IN); +// SetMode(PIN_DT5, RASCSI_PIN_IN); +// SetMode(PIN_DT6, RASCSI_PIN_IN); +// SetMode(PIN_DT7, RASCSI_PIN_IN); +// SetMode(PIN_DP, RASCSI_PIN_IN); +// } else { +// // Initiator mode - // Set target signal to input - SetControl(PIN_TAD, TAD_IN); - SetMode(PIN_BSY, RASCSI_PIN_IN); - SetMode(PIN_MSG, RASCSI_PIN_IN); - SetMode(PIN_CD, RASCSI_PIN_IN); - SetMode(PIN_REQ, RASCSI_PIN_IN); - SetMode(PIN_IO, RASCSI_PIN_IN); +// // Set target signal to input +// SetControl(PIN_TAD, TAD_IN); +// SetMode(PIN_BSY, RASCSI_PIN_IN); +// SetMode(PIN_MSG, RASCSI_PIN_IN); +// SetMode(PIN_CD, RASCSI_PIN_IN); +// SetMode(PIN_REQ, RASCSI_PIN_IN); +// SetMode(PIN_IO, RASCSI_PIN_IN); - // Set the initiator signal to output - SetControl(PIN_IND, IND_OUT); - SetMode(PIN_SEL, RASCSI_PIN_OUT); - SetMode(PIN_ATN, RASCSI_PIN_OUT); - SetMode(PIN_ACK, RASCSI_PIN_OUT); - SetMode(PIN_RST, RASCSI_PIN_OUT); +// // Set the initiator signal to output +// SetControl(PIN_IND, IND_OUT); +// SetMode(PIN_SEL, RASCSI_PIN_OUT); +// SetMode(PIN_ATN, RASCSI_PIN_OUT); +// SetMode(PIN_ACK, RASCSI_PIN_OUT); +// SetMode(PIN_RST, RASCSI_PIN_OUT); - // Set the data bus signals to output - SetControl(PIN_DTD, DTD_OUT); - SetMode(PIN_DT0, RASCSI_PIN_OUT); - SetMode(PIN_DT1, RASCSI_PIN_OUT); - SetMode(PIN_DT2, RASCSI_PIN_OUT); - SetMode(PIN_DT3, RASCSI_PIN_OUT); - SetMode(PIN_DT4, RASCSI_PIN_OUT); - SetMode(PIN_DT5, RASCSI_PIN_OUT); - SetMode(PIN_DT6, RASCSI_PIN_OUT); - SetMode(PIN_DT7, RASCSI_PIN_OUT); - SetMode(PIN_DP, RASCSI_PIN_OUT); - } +// // Set the data bus signals to output +// SetControl(PIN_DTD, DTD_OUT); +// SetMode(PIN_DT0, RASCSI_PIN_OUT); +// SetMode(PIN_DT1, RASCSI_PIN_OUT); +// SetMode(PIN_DT2, RASCSI_PIN_OUT); +// SetMode(PIN_DT3, RASCSI_PIN_OUT); +// SetMode(PIN_DT4, RASCSI_PIN_OUT); +// SetMode(PIN_DT5, RASCSI_PIN_OUT); +// SetMode(PIN_DT6, RASCSI_PIN_OUT); +// SetMode(PIN_DT7, RASCSI_PIN_OUT); +// SetMode(PIN_DP, RASCSI_PIN_OUT); +// } - // Initialize all signals - signals = 0; -#endif // ifdef __x86_64__ || __X86__ +// // Initialize all signals +// signals = 0; +// #endif // ifdef __x86_64__ || __X86__ } BYTE GPIOBUS_Allwinner::GetDAT() @@ -290,14 +290,14 @@ void GPIOBUS_Allwinner::MakeTable(void) LOGWARN("%s NOT IMPLEMENTED", __PRETTY_FUNCTION__) } -void GPIOBUS_Allwinner::SetControl(int pin, bool ast) +void GPIOBUS_Allwinner::SetControl(board_type::pi_physical_pin_e pin, bool ast) { // GPIOBUS_Allwinner::SetSignal(pin, ast); LOGWARN("%s NOT IMPLEMENTED", __PRETTY_FUNCTION__) } -void GPIOBUS_Allwinner::SetMode(int pin, int mode) +void GPIOBUS_Allwinner::SetMode(board_type::pi_physical_pin_e pin, int mode) { // LOGWARN("%s NOT IMPLEMENTED", __PRETTY_FUNCTION__) // if(mode == GPIO_INPUT){ @@ -309,14 +309,14 @@ void GPIOBUS_Allwinner::SetMode(int pin, int mode) LOGWARN("%s NOT IMPLEMENTED", __PRETTY_FUNCTION__) } -bool GPIOBUS_Allwinner::GetSignal(int pin) const +bool GPIOBUS_Allwinner::GetSignal(board_type::pi_physical_pin_e pin) const { LOGWARN("%s NOT IMPLEMENTED", __PRETTY_FUNCTION__) return false; // return (digitalRead(pin) != 0); } -void GPIOBUS_Allwinner::SetSignal(int pin, bool ast) +void GPIOBUS_Allwinner::SetSignal(board_type::pi_physical_pin_e pin, bool ast) { LOGWARN("%s NOT IMPLEMENTED", __PRETTY_FUNCTION__) // digitalWrite(pin, ast); @@ -329,7 +329,7 @@ void GPIOBUS_Allwinner::SetSignal(int pin, bool ast) // // TODO: maybe this should be moved to SCSI_Bus? //--------------------------------------------------------------------------- -bool GPIOBUS_Allwinner::WaitSignal(int pin, int ast) +bool GPIOBUS_Allwinner::WaitSignal(board_type::pi_physical_pin_e pin, int ast) { LOGERROR("%s not implemented!!", __PRETTY_FUNCTION__) @@ -370,7 +370,7 @@ void GPIOBUS_Allwinner::EnableIRQ() LOGERROR("%s not implemented!!", __PRETTY_FUNCTION__) } -void GPIOBUS_Allwinner::PinConfig(int pin, int mode) +void GPIOBUS_Allwinner::PinConfig(board_type::pi_physical_pin_e pin, int mode) { LOGERROR("%s not implemented!!", __PRETTY_FUNCTION__) @@ -383,7 +383,7 @@ void GPIOBUS_Allwinner::PinConfig(int pin, int mode) } -void GPIOBUS_Allwinner::PullConfig(int pin, int mode) +void GPIOBUS_Allwinner::PullConfig(board_type::pi_physical_pin_e pin, int mode) { // switch (mode) @@ -405,7 +405,7 @@ void GPIOBUS_Allwinner::PullConfig(int pin, int mode) } -void GPIOBUS_Allwinner::PinSetSignal(int pin, bool ast) +void GPIOBUS_Allwinner::PinSetSignal(board_type::pi_physical_pin_e pin, bool ast) { // digitalWrite(pin, ast); LOGERROR("%s not implemented!!", __PRETTY_FUNCTION__) diff --git a/cpp/hal/gpiobus_allwinner.h b/cpp/hal/gpiobus_allwinner.h index b32ffe6f..56f70375 100644 --- a/cpp/hal/gpiobus_allwinner.h +++ b/cpp/hal/gpiobus_allwinner.h @@ -30,7 +30,9 @@ class GPIOBUS_Allwinner : public GPIOBUS GPIOBUS_Allwinner() = default; ~GPIOBUS_Allwinner() override = default; // Destructor - bool Init(mode_e mode = mode_e::TARGET) override; + bool Init(mode_e mode = mode_e::TARGET, board_type::rascsi_board_type_e + rascsi_type = board_type::rascsi_board_type_e::BOARD_TYPE_FULLSPEC) override; + // Initialization void Reset() override; // Reset @@ -52,15 +54,15 @@ class GPIOBUS_Allwinner : public GPIOBUS // SCSI I/O signal control void MakeTable() override; // Create work data - void SetControl(int pin, bool ast) override; + void SetControl(board_type::pi_physical_pin_e pin, bool ast) override; // Set Control Signal - void SetMode(int pin, int mode) override; + void SetMode(board_type::pi_physical_pin_e pin, int mode) override; // Set SCSI I/O mode - bool GetSignal(int pin) const override; + bool GetSignal(board_type::pi_physical_pin_e pin) const override; // Get SCSI input signal value - void SetSignal(int pin, bool ast) override; + void SetSignal(board_type::pi_physical_pin_e pin, bool ast) override; // Set SCSI output signal value - bool WaitSignal(int pin, int ast) override; + bool WaitSignal(board_type::pi_physical_pin_e pin, int ast) override; // Wait for a signal to change // Interrupt control void DisableIRQ() override; @@ -69,11 +71,11 @@ class GPIOBUS_Allwinner : public GPIOBUS // IRQ Enabled // GPIO pin functionality settings - void PinConfig(int pin, int mode) override; + void PinConfig(board_type::pi_physical_pin_e pin, int mode) override; // GPIO pin direction setting - void PullConfig(int pin, int mode) override; + void PullConfig(board_type::pi_physical_pin_e pin, int mode) override; // GPIO pin pull up/down resistor setting - void PinSetSignal(int pin, bool ast) override; + void PinSetSignal(board_type::pi_physical_pin_e pin, bool ast) override; // Set GPIO output signal void DrvConfig(DWORD drive) override; // Set GPIO drive strength diff --git a/cpp/hal/gpiobus_raspberry.cpp b/cpp/hal/gpiobus_raspberry.cpp index 2d31fcdf..764c2a9e 100644 --- a/cpp/hal/gpiobus_raspberry.cpp +++ b/cpp/hal/gpiobus_raspberry.cpp @@ -10,52 +10,35 @@ // //--------------------------------------------------------------------------- -#include -#include -#include "hal/board_type.h" -#include "config.h" -#include "hal/gpiobus.h" #include "hal/gpiobus_raspberry.h" +#include "config.h" +#include "hal/board_type.h" +#include "hal/gpiobus.h" #include "hal/systimer.h" #include "log.h" #include "os.h" +#include #include #include #include #include #include - -const std::map GPIOBUS_Raspberry::phys_to_gpio_map = -{ - {board_type::pi_physical_pin_e::PI_PHYS_PIN_03, 2}, - {board_type::pi_physical_pin_e::PI_PHYS_PIN_05, 3}, - {board_type::pi_physical_pin_e::PI_PHYS_PIN_07, 4}, - {board_type::pi_physical_pin_e::PI_PHYS_PIN_08, 14}, - {board_type::pi_physical_pin_e::PI_PHYS_PIN_10, 15}, - {board_type::pi_physical_pin_e::PI_PHYS_PIN_11, 17}, - {board_type::pi_physical_pin_e::PI_PHYS_PIN_12, 18}, - {board_type::pi_physical_pin_e::PI_PHYS_PIN_13, 27}, - {board_type::pi_physical_pin_e::PI_PHYS_PIN_15, 22}, - {board_type::pi_physical_pin_e::PI_PHYS_PIN_16, 23}, - {board_type::pi_physical_pin_e::PI_PHYS_PIN_18, 24}, - {board_type::pi_physical_pin_e::PI_PHYS_PIN_19, 10}, - {board_type::pi_physical_pin_e::PI_PHYS_PIN_21, 9}, - {board_type::pi_physical_pin_e::PI_PHYS_PIN_22, 25}, - {board_type::pi_physical_pin_e::PI_PHYS_PIN_23, 11}, - {board_type::pi_physical_pin_e::PI_PHYS_PIN_24, 8}, - {board_type::pi_physical_pin_e::PI_PHYS_PIN_26, 7}, - {board_type::pi_physical_pin_e::PI_PHYS_PIN_27, 0}, - {board_type::pi_physical_pin_e::PI_PHYS_PIN_28, 1}, - {board_type::pi_physical_pin_e::PI_PHYS_PIN_29, 5}, - {board_type::pi_physical_pin_e::PI_PHYS_PIN_31, 6}, - {board_type::pi_physical_pin_e::PI_PHYS_PIN_32, 12}, - {board_type::pi_physical_pin_e::PI_PHYS_PIN_33, 13}, - {board_type::pi_physical_pin_e::PI_PHYS_PIN_35, 19}, - {board_type::pi_physical_pin_e::PI_PHYS_PIN_36, 16}, - {board_type::pi_physical_pin_e::PI_PHYS_PIN_37, 26}, - {board_type::pi_physical_pin_e::PI_PHYS_PIN_38, 20}, - {board_type::pi_physical_pin_e::PI_PHYS_PIN_40, 21}, +const std::map GPIOBUS_Raspberry::phys_to_gpio_map = { + {board_type::pi_physical_pin_e::PI_PHYS_PIN_03, 2}, {board_type::pi_physical_pin_e::PI_PHYS_PIN_05, 3}, + {board_type::pi_physical_pin_e::PI_PHYS_PIN_07, 4}, {board_type::pi_physical_pin_e::PI_PHYS_PIN_08, 14}, + {board_type::pi_physical_pin_e::PI_PHYS_PIN_10, 15}, {board_type::pi_physical_pin_e::PI_PHYS_PIN_11, 17}, + {board_type::pi_physical_pin_e::PI_PHYS_PIN_12, 18}, {board_type::pi_physical_pin_e::PI_PHYS_PIN_13, 27}, + {board_type::pi_physical_pin_e::PI_PHYS_PIN_15, 22}, {board_type::pi_physical_pin_e::PI_PHYS_PIN_16, 23}, + {board_type::pi_physical_pin_e::PI_PHYS_PIN_18, 24}, {board_type::pi_physical_pin_e::PI_PHYS_PIN_19, 10}, + {board_type::pi_physical_pin_e::PI_PHYS_PIN_21, 9}, {board_type::pi_physical_pin_e::PI_PHYS_PIN_22, 25}, + {board_type::pi_physical_pin_e::PI_PHYS_PIN_23, 11}, {board_type::pi_physical_pin_e::PI_PHYS_PIN_24, 8}, + {board_type::pi_physical_pin_e::PI_PHYS_PIN_26, 7}, {board_type::pi_physical_pin_e::PI_PHYS_PIN_27, 0}, + {board_type::pi_physical_pin_e::PI_PHYS_PIN_28, 1}, {board_type::pi_physical_pin_e::PI_PHYS_PIN_29, 5}, + {board_type::pi_physical_pin_e::PI_PHYS_PIN_31, 6}, {board_type::pi_physical_pin_e::PI_PHYS_PIN_32, 12}, + {board_type::pi_physical_pin_e::PI_PHYS_PIN_33, 13}, {board_type::pi_physical_pin_e::PI_PHYS_PIN_35, 19}, + {board_type::pi_physical_pin_e::PI_PHYS_PIN_36, 16}, {board_type::pi_physical_pin_e::PI_PHYS_PIN_37, 26}, + {board_type::pi_physical_pin_e::PI_PHYS_PIN_38, 20}, {board_type::pi_physical_pin_e::PI_PHYS_PIN_40, 21}, }; #ifdef __linux__ @@ -112,10 +95,10 @@ uint32_t bcm_host_get_peripheral_address() } #endif // __NetBSD__ -bool GPIOBUS_Raspberry::Init(mode_e mode) +bool GPIOBUS_Raspberry::Init(mode_e mode, board_type::rascsi_board_type_e rascsi_type) { GPIO_FUNCTION_TRACE - GPIOBUS::Init(mode); + GPIOBUS::Init(mode, rascsi_type); #if defined(__x86_64__) || defined(__X86__) @@ -219,8 +202,8 @@ bool GPIOBUS_Raspberry::Init(mode_e mode) // Initialize all signals LOGTRACE("%s Initialize all signals....", __PRETTY_FUNCTION__); - for (int i = 0; SignalTable[i] >= 0; i++) { - int j = SignalTable[i]; + for (int i = 0; SignalTable[i] != board_type::pi_physical_pin_e::PI_PHYS_PIN_NONE; i++) { + board_type::pi_physical_pin_e j = SignalTable[i]; PinSetSignal(j, RASCSI_PIN_OFF); PinConfig(j, GPIO_INPUT); PullConfig(j, pullmode); @@ -228,19 +211,19 @@ bool GPIOBUS_Raspberry::Init(mode_e mode) // Set control signals LOGTRACE("%s Set control signals....", __PRETTY_FUNCTION__); - PinSetSignal(PIN_ACT, RASCSI_PIN_OFF); - PinSetSignal(PIN_TAD, RASCSI_PIN_OFF); - PinSetSignal(PIN_IND, RASCSI_PIN_OFF); - PinSetSignal(PIN_DTD, RASCSI_PIN_OFF); - PinConfig(PIN_ACT, GPIO_OUTPUT); - PinConfig(PIN_TAD, GPIO_OUTPUT); - PinConfig(PIN_IND, GPIO_OUTPUT); - PinConfig(PIN_DTD, GPIO_OUTPUT); + PinSetSignal(board->pin_act, RASCSI_PIN_OFF); + PinSetSignal(board->pin_tad, RASCSI_PIN_OFF); + PinSetSignal(board->pin_ind, RASCSI_PIN_OFF); + PinSetSignal(board->pin_dtd, RASCSI_PIN_OFF); + PinConfig(board->pin_act, GPIO_OUTPUT); + PinConfig(board->pin_tad, GPIO_OUTPUT); + PinConfig(board->pin_ind, GPIO_OUTPUT); + PinConfig(board->pin_dtd, GPIO_OUTPUT); // Set the ENABLE signal // This is used to show that the application is running - PinSetSignal(PIN_ENB, ENB_OFF); - PinConfig(PIN_ENB, GPIO_OUTPUT); + PinSetSignal(board->pin_enb, ENB_OFF); + PinConfig( board->pin_enb, GPIO_OUTPUT); // GPFSEL backup LOGTRACE("%s GPFSEL backup....", __PRETTY_FUNCTION__); @@ -354,7 +337,7 @@ bool GPIOBUS_Raspberry::Init(mode_e mode) // Finally, enable ENABLE LOGTRACE("%s Finally, enable ENABLE....", __PRETTY_FUNCTION__); // Show the user that this app is running - SetControl(PIN_ENB, ENB_ON); + SetControl(board->pin_enb, ENB_ON); return true; #endif // ifdef __x86_64__ || __X86__ @@ -372,19 +355,19 @@ void GPIOBUS_Raspberry::Cleanup() #endif // USE_SEL_EVENT_ENABLE // Set control signals - PinSetSignal(PIN_ENB, RASCSI_PIN_OFF); - PinSetSignal(PIN_ACT, RASCSI_PIN_OFF); - PinSetSignal(PIN_TAD, RASCSI_PIN_OFF); - PinSetSignal(PIN_IND, RASCSI_PIN_OFF); - PinSetSignal(PIN_DTD, RASCSI_PIN_OFF); - PinConfig(PIN_ACT, GPIO_INPUT); - PinConfig(PIN_TAD, GPIO_INPUT); - PinConfig(PIN_IND, GPIO_INPUT); - PinConfig(PIN_DTD, GPIO_INPUT); + PinSetSignal(board->pin_enb, RASCSI_PIN_OFF); + PinSetSignal(board->pin_act, RASCSI_PIN_OFF); + PinSetSignal(board->pin_tad, RASCSI_PIN_OFF); + PinSetSignal(board->pin_ind, RASCSI_PIN_OFF); + PinSetSignal(board->pin_dtd, RASCSI_PIN_OFF); + PinConfig(board->pin_act, GPIO_INPUT); + PinConfig(board->pin_tad, GPIO_INPUT); + PinConfig(board->pin_ind, GPIO_INPUT); + PinConfig(board->pin_dtd, GPIO_INPUT); // Initialize all signals - for (int i = 0; SignalTable[i] >= 0; i++) { - int pin = SignalTable[i]; + for (int i = 0; SignalTable[i] != board_type::pi_physical_pin_e::PI_PHYS_PIN_NONE; i++) { + board_type::pi_physical_pin_e pin = SignalTable[i]; PinSetSignal(pin, RASCSI_PIN_OFF); PinConfig(pin, GPIO_INPUT); PullConfig(pin, GPIO_PULLNONE); @@ -395,93 +378,6 @@ void GPIOBUS_Raspberry::Cleanup() #endif // ifdef __x86_64__ || __X86__ } -void GPIOBUS_Raspberry::Reset() -{ - GPIO_FUNCTION_TRACE -#if defined(__x86_64__) || defined(__X86__) - return; -#else - int i; - int j; - - // Turn off active signal - SetControl(PIN_ACT, ACT_OFF); - - // Set all signals to off - for (i = 0;; i++) { - j = SignalTable[i]; - if (j < 0) { - break; - } - - SetSignal(j, RASCSI_PIN_OFF); - } - - if (actmode == mode_e::TARGET) { - // Target mode - - // Set target signal to input - SetControl(PIN_TAD, TAD_IN); - SetMode(PIN_BSY, RASCSI_PIN_IN); - SetMode(PIN_MSG, RASCSI_PIN_IN); - SetMode(PIN_CD, RASCSI_PIN_IN); - SetMode(PIN_REQ, RASCSI_PIN_IN); - SetMode(PIN_IO, RASCSI_PIN_IN); - - // Set the initiator signal to input - SetControl(PIN_IND, IND_IN); - SetMode(PIN_SEL, RASCSI_PIN_IN); - SetMode(PIN_ATN, RASCSI_PIN_IN); - SetMode(PIN_ACK, RASCSI_PIN_IN); - SetMode(PIN_RST, RASCSI_PIN_IN); - - // Set data bus signals to input - SetControl(PIN_DTD, DTD_IN); - SetMode(PIN_DT0, RASCSI_PIN_IN); - SetMode(PIN_DT1, RASCSI_PIN_IN); - SetMode(PIN_DT2, RASCSI_PIN_IN); - SetMode(PIN_DT3, RASCSI_PIN_IN); - SetMode(PIN_DT4, RASCSI_PIN_IN); - SetMode(PIN_DT5, RASCSI_PIN_IN); - SetMode(PIN_DT6, RASCSI_PIN_IN); - SetMode(PIN_DT7, RASCSI_PIN_IN); - SetMode(PIN_DP, RASCSI_PIN_IN); - } else { - // Initiator mode - - // Set target signal to input - SetControl(PIN_TAD, TAD_IN); - SetMode(PIN_BSY, RASCSI_PIN_IN); - SetMode(PIN_MSG, RASCSI_PIN_IN); - SetMode(PIN_CD, RASCSI_PIN_IN); - SetMode(PIN_REQ, RASCSI_PIN_IN); - SetMode(PIN_IO, RASCSI_PIN_IN); - - // Set the initiator signal to output - SetControl(PIN_IND, IND_OUT); - SetMode(PIN_SEL, RASCSI_PIN_OUT); - SetMode(PIN_ATN, RASCSI_PIN_OUT); - SetMode(PIN_ACK, RASCSI_PIN_OUT); - SetMode(PIN_RST, RASCSI_PIN_OUT); - - // Set the data bus signals to output - SetControl(PIN_DTD, DTD_OUT); - SetMode(PIN_DT0, RASCSI_PIN_OUT); - SetMode(PIN_DT1, RASCSI_PIN_OUT); - SetMode(PIN_DT2, RASCSI_PIN_OUT); - SetMode(PIN_DT3, RASCSI_PIN_OUT); - SetMode(PIN_DT4, RASCSI_PIN_OUT); - SetMode(PIN_DT5, RASCSI_PIN_OUT); - SetMode(PIN_DT6, RASCSI_PIN_OUT); - SetMode(PIN_DT7, RASCSI_PIN_OUT); - SetMode(PIN_DP, RASCSI_PIN_OUT); - } - - // Initialize all signals - signals = 0; -#endif // ifdef __x86_64__ || __X86__ -} - //--------------------------------------------------------------------------- // // Get data signals @@ -491,10 +387,14 @@ BYTE GPIOBUS_Raspberry::GetDAT() { GPIO_FUNCTION_TRACE uint32_t data = Acquire(); - data = ((data >> (PIN_DT0 - 0)) & (1 << 0)) | ((data >> (PIN_DT1 - 1)) & (1 << 1)) | - ((data >> (PIN_DT2 - 2)) & (1 << 2)) | ((data >> (PIN_DT3 - 3)) & (1 << 3)) | - ((data >> (PIN_DT4 - 4)) & (1 << 4)) | ((data >> (PIN_DT5 - 5)) & (1 << 5)) | - ((data >> (PIN_DT6 - 6)) & (1 << 6)) | ((data >> (PIN_DT7 - 7)) & (1 << 7)); + data = ((data >> (phys_to_gpio_map.at(board->pin_dt0) - 0)) & (1 << 0)) | + ((data >> (phys_to_gpio_map.at(board->pin_dt1) - 1)) & (1 << 1)) | + ((data >> (phys_to_gpio_map.at(board->pin_dt2) - 2)) & (1 << 2)) | + ((data >> (phys_to_gpio_map.at(board->pin_dt3) - 3)) & (1 << 3)) | + ((data >> (phys_to_gpio_map.at(board->pin_dt4) - 4)) & (1 << 4)) | + ((data >> (phys_to_gpio_map.at(board->pin_dt5) - 5)) & (1 << 5)) | + ((data >> (phys_to_gpio_map.at(board->pin_dt6) - 6)) & (1 << 6)) | + ((data >> (phys_to_gpio_map.at(board->pin_dt7) - 7)) & (1 << 7)); return (BYTE)data; } @@ -546,7 +446,12 @@ void GPIOBUS_Raspberry::MakeTable(void) { GPIO_FUNCTION_TRACE - const array pintbl = {PIN_DT0, PIN_DT1, PIN_DT2, PIN_DT3, PIN_DT4, PIN_DT5, PIN_DT6, PIN_DT7, PIN_DP}; + const array pintbl = { + phys_to_gpio_map.at(board->pin_dt0), phys_to_gpio_map.at(board->pin_dt1), phys_to_gpio_map.at(board->pin_dt2), + phys_to_gpio_map.at(board->pin_dt3), phys_to_gpio_map.at(board->pin_dt4), phys_to_gpio_map.at(board->pin_dt5), + phys_to_gpio_map.at(board->pin_dt6), phys_to_gpio_map.at(board->pin_dt7), phys_to_gpio_map.at(board->pin_dp)}; + + // PIN_DT0, PIN_DT1, PIN_DT2, PIN_DT3, PIN_DT4, PIN_DT5, PIN_DT6, PIN_DT7, PIN_DP}; array tblParity; @@ -635,7 +540,7 @@ void GPIOBUS_Raspberry::MakeTable(void) // Control signal setting // //--------------------------------------------------------------------------- -void GPIOBUS_Raspberry::SetControl(int pin, bool ast) +void GPIOBUS_Raspberry::SetControl(board_type::pi_physical_pin_e pin, bool ast) { PinSetSignal(pin, ast); } @@ -645,8 +550,10 @@ void GPIOBUS_Raspberry::SetControl(int pin, bool ast) // Input/output mode setting // //--------------------------------------------------------------------------- -void GPIOBUS_Raspberry::SetMode(int pin, int mode) +void GPIOBUS_Raspberry::SetMode(board_type::pi_physical_pin_e hw_pin, int mode) { + int pin = phys_to_gpio_map.at(hw_pin); + #if SIGNAL_CONTROL_MODE == 0 if (mode == RASCSI_PIN_OUT) { return; @@ -669,8 +576,9 @@ void GPIOBUS_Raspberry::SetMode(int pin, int mode) // Get input signal value // //--------------------------------------------------------------------------- -bool GPIOBUS_Raspberry::GetSignal(int pin) const +bool GPIOBUS_Raspberry::GetSignal(board_type::pi_physical_pin_e hw_pin) const { + int pin = phys_to_gpio_map.at(hw_pin); return (signals >> pin) & 1; } @@ -679,8 +587,10 @@ bool GPIOBUS_Raspberry::GetSignal(int pin) const // Set output signal value // //--------------------------------------------------------------------------- -void GPIOBUS_Raspberry::SetSignal(int pin, bool ast) +void GPIOBUS_Raspberry::SetSignal(board_type::pi_physical_pin_e hw_pin, bool ast) { + int pin = phys_to_gpio_map.at(hw_pin); + #if SIGNAL_CONTROL_MODE == 0 int index = pin / 10; int shift = (pin % 10) * 3; @@ -713,8 +623,9 @@ void GPIOBUS_Raspberry::SetSignal(int pin, bool ast) // // TODO: maybe this should be moved to SCSI_Bus? //--------------------------------------------------------------------------- -bool GPIOBUS_Raspberry::WaitSignal(int pin, int ast) +bool GPIOBUS_Raspberry::WaitSignal(board_type::pi_physical_pin_e hw_pin, int ast) { + int pin = phys_to_gpio_map.at(hw_pin); // Get current time uint32_t now = SysTimer::GetTimerLow(); @@ -783,8 +694,10 @@ void GPIOBUS_Raspberry::EnableIRQ() // Pin direction setting (input/output) // //--------------------------------------------------------------------------- -void GPIOBUS_Raspberry::PinConfig(int pin, int mode) +void GPIOBUS_Raspberry::PinConfig(board_type::pi_physical_pin_e hw_pin, int mode) { + int pin = phys_to_gpio_map.at(hw_pin); + // Check for invalid pin if (pin < 0) { return; @@ -800,10 +713,12 @@ void GPIOBUS_Raspberry::PinConfig(int pin, int mode) // Pin pull-up/pull-down setting // //--------------------------------------------------------------------------- -void GPIOBUS_Raspberry::PullConfig(int pin, int mode) +void GPIOBUS_Raspberry::PullConfig(board_type::pi_physical_pin_e hw_pin, int mode) { uint32_t pull; + int pin = phys_to_gpio_map.at(hw_pin); + // Check for invalid pin if (pin < 0) { return; @@ -847,8 +762,10 @@ void GPIOBUS_Raspberry::PullConfig(int pin, int mode) // Set output pin // //--------------------------------------------------------------------------- -void GPIOBUS_Raspberry::PinSetSignal(int pin, bool ast) +void GPIOBUS_Raspberry::PinSetSignal(board_type::pi_physical_pin_e hw_pin, bool ast) { + int pin = phys_to_gpio_map.at(hw_pin); + // Check for invalid pin if (pin < 0) { return; diff --git a/cpp/hal/gpiobus_raspberry.h b/cpp/hal/gpiobus_raspberry.h index 7622e231..640d610f 100644 --- a/cpp/hal/gpiobus_raspberry.h +++ b/cpp/hal/gpiobus_raspberry.h @@ -30,9 +30,11 @@ class GPIOBUS_Raspberry final : public GPIOBUS GPIOBUS_Raspberry() = default; ~GPIOBUS_Raspberry() override = default; // Destructor - bool Init(mode_e mode = mode_e::TARGET) override; - // Initialization - void Reset() override; + bool Init(mode_e mode = mode_e::TARGET, board_type::rascsi_board_type_e + rascsi_type = board_type::rascsi_board_type_e::BOARD_TYPE_FULLSPEC) override; + + // // Initialization + // void Reset() override; // Reset void Cleanup() override; // Cleanup @@ -52,15 +54,15 @@ class GPIOBUS_Raspberry final : public GPIOBUS // SCSI I/O signal control void MakeTable() override; // Create work data - void SetControl(int pin, bool ast) override; + void SetControl(board_type::pi_physical_pin_e pin, bool ast) override; // Set Control Signal - void SetMode(int pin, int mode) override; + void SetMode(board_type::pi_physical_pin_e pin, int mode) override; // Set SCSI I/O mode - bool GetSignal(int pin) const override; + bool GetSignal(board_type::pi_physical_pin_e pin) const override; // Get SCSI input signal value - void SetSignal(int pin, bool ast) override; + void SetSignal(board_type::pi_physical_pin_e pin, bool ast) override; // Set SCSI output signal value - bool WaitSignal(int pin, int ast) override; + bool WaitSignal(board_type::pi_physical_pin_e pin, int ast) override; // Wait for a signal to change // Interrupt control void DisableIRQ() override; @@ -69,11 +71,11 @@ class GPIOBUS_Raspberry final : public GPIOBUS // IRQ Enabled // GPIO pin functionality settings - void PinConfig(int pin, int mode) override; + void PinConfig(board_type::pi_physical_pin_e pin, int mode) override; // GPIO pin direction setting - void PullConfig(int pin, int mode) override; + void PullConfig(board_type::pi_physical_pin_e pin, int mode) override; // GPIO pin pull up/down resistor setting - void PinSetSignal(int pin, bool ast) override; + void PinSetSignal(board_type::pi_physical_pin_e pin, bool ast) override; // Set GPIO output signal void DrvConfig(uint32_t drive) override; // Set GPIO drive strength