From 01b0fb0f3502a6ee5e6f5080076b61afb4e750e9 Mon Sep 17 00:00:00 2001 From: akuker Date: Thu, 24 Sep 2020 21:11:52 -0500 Subject: [PATCH] #27 Added skeleton code for Arbitration and Reselection phases --- src/raspberrypi/controllers/scsidev_ctrl.cpp | 131 ++++++++++++++++++- src/raspberrypi/controllers/scsidev_ctrl.h | 4 + src/raspberrypi/devices/scsi_nuvolink.cpp | 4 +- src/raspberrypi/rasdump.cpp | 2 +- 4 files changed, 134 insertions(+), 7 deletions(-) diff --git a/src/raspberrypi/controllers/scsidev_ctrl.cpp b/src/raspberrypi/controllers/scsidev_ctrl.cpp index 414e059..2a0f435 100644 --- a/src/raspberrypi/controllers/scsidev_ctrl.cpp +++ b/src/raspberrypi/controllers/scsidev_ctrl.cpp @@ -80,11 +80,9 @@ BUS::phase_t FASTCALL SCSIDEV::Process() // Get bus information ctrl.bus->Aquire(); - // Reset + // Check to see if the reset signal was asserted if (ctrl.bus->GetRST()) { -#if defined(DISK_LOG) - Log(Log::Normal, "RESET信号受信"); -#endif // DISK_LOG + LOGWARN("RESET signal received!"); // Reset the controller Reset(); @@ -192,6 +190,53 @@ void FASTCALL SCSIDEV::BusFree() } } +//--------------------------------------------------------------------------- +// +// Arbitration Phase +// +//--------------------------------------------------------------------------- +void FASTCALL SCSIDEV::Arbitration() +{ + + // TODO: See https://www.staff.uni-mainz.de/tacke/scsi/SCSI2-06.html + // DWORD id; + + ASSERT(this); + + // // Phase change + // if (ctrl.phase != BUS::reselection) { + // // invalid if IDs do not match + // id = 1 << ctrl.id; + // if ((ctrl.bus->GetDAT() & id) == 0) { + // return; + // } + + // // End if there is no valid unit + // if (!HasUnit()) { + // return; + // } + + // LOGDEBUG("Reselection phase ID=%d (with device)", ctrl.id); + + // // Phase setting + // ctrl.phase = BUS::selection; + + // // Raise BSY and respond + // ctrl.bus->SetBSY(TRUE); + // return; + // } + + // // Reselection completed + // if (!ctrl.bus->GetSEL() && ctrl.bus->GetBSY()) { + // // Message out phase if ATN=1, otherwise command phase + // if (ctrl.bus->GetATN()) { + // MsgOut(); + // } else { + // Command(); + // } + // } +} + //--------------------------------------------------------------------------- // // Selection Phase @@ -240,6 +285,53 @@ void FASTCALL SCSIDEV::Selection() } } +//--------------------------------------------------------------------------- +// +// Reselection Phase +// +//--------------------------------------------------------------------------- +void FASTCALL SCSIDEV::Reselection() +{ + // DWORD id; + + ASSERT(this); + + // // Phase change + // if (ctrl.phase != BUS::reselection) { + // // invalid if IDs do not match + // id = 1 << ctrl.id; + // if ((ctrl.bus->GetDAT() & id) == 0) { + // return; + // } + + // // End if there is no valid unit + // if (!HasUnit()) { + // return; + // } + + // LOGDEBUG("Reselection phase ID=%d (with device)", ctrl.id); + + // // Phase setting + // ctrl.phase = BUS::selection; + + // // Raise BSY and respond + // ctrl.bus->SetBSY(TRUE); + // return; + // } + + // // Reselection completed + // if (!ctrl.bus->GetSEL() && ctrl.bus->GetBSY()) { + // // Message out phase if ATN=1, otherwise command phase + // if (ctrl.bus->GetATN()) { + // MsgOut(); + // } else { + // Command(); + // } + // } +} + + + //--------------------------------------------------------------------------- // // Execution Phase @@ -2090,25 +2182,56 @@ BOOL FASTCALL SCSIDEV::XferMsg(DWORD msg) // //--------------------------------------------------------------------------- BOOL FASTCALL SCSIDEV::TransferPacketToHost(int packet_len){ + //***************************** + // BUS FREE PHASE + //***************************** + // We should already be in bus free phase when we enter this function + //***************************** + // ARBITRATION PHASE + //***************************** // Aquire the bus + // ctrl.bus->Aquire(); + // ctrl.bus->SetIO(); +// if (bus->GetBUSY()) { +// #if !defined(BAREMETAL) +// usleep(0); +// #endif // !BAREMETAL +// continue; +// } +// #endif // USE_SEL_EVENT_ENABLE + //***************************** // Reselection + //***************************** + //***************************** // Message OUT (expect a "NO OPERATION") // IF we get a DISCONNECT message, abort sending the message // Transition to MESSAGE IN and send a DISCONNECT // then go to BUS FREE + //***************************** + //***************************** // DATA IN // ... send the packet + //***************************** + //***************************** // MESSAGE OUT (expect a "NO OPERATION") + //***************************** + //***************************** // If more packets, go back to DATA IN + //***************************** + //***************************** // Else // MESSAGE IN (sends DISCONNECT) + //***************************** + //***************************** // BUS FREE + //***************************** + BusFree(); } \ No newline at end of file diff --git a/src/raspberrypi/controllers/scsidev_ctrl.h b/src/raspberrypi/controllers/scsidev_ctrl.h index 36e43ac..bf289fd 100644 --- a/src/raspberrypi/controllers/scsidev_ctrl.h +++ b/src/raspberrypi/controllers/scsidev_ctrl.h @@ -108,8 +108,12 @@ private: // Phase void FASTCALL BusFree(); // Bus free phase + void FASTCALL Arbitration(); + // Arbitration phase void FASTCALL Selection(); // Selection phase + void FASTCALL Reselection(); + // Reselection phase void FASTCALL Execute(); // Execution phase void FASTCALL MsgOut(); diff --git a/src/raspberrypi/devices/scsi_nuvolink.cpp b/src/raspberrypi/devices/scsi_nuvolink.cpp index 595c925..4ffa01e 100644 --- a/src/raspberrypi/devices/scsi_nuvolink.cpp +++ b/src/raspberrypi/devices/scsi_nuvolink.cpp @@ -485,7 +485,7 @@ int FASTCALL SCSINuvolink::ReceivePacket() if (memcmp(packet_buf, mac_addr, 6) != 0) { if (memcmp(packet_buf, bcast_addr, 6) != 0) { packet_len = 0; - return; + return -1; } } @@ -493,7 +493,7 @@ int FASTCALL SCSINuvolink::ReceivePacket() if (packet_len > 2048) { LOGDEBUG("Packet size was too big. Dropping it"); packet_len = 0; - return; + return -1; } // TransferPacket(packet_len, packet_buff); diff --git a/src/raspberrypi/rasdump.cpp b/src/raspberrypi/rasdump.cpp index aeff209..bd67d2f 100644 --- a/src/raspberrypi/rasdump.cpp +++ b/src/raspberrypi/rasdump.cpp @@ -24,7 +24,7 @@ //--------------------------------------------------------------------------- // -// 変数宣言 +// Variable Declaration // //--------------------------------------------------------------------------- GPIOBUS bus; // Bus