From f7bc77d978bf700abc6d80fdb2da8f20b935e950 Mon Sep 17 00:00:00 2001 From: Uwe Seimet <48174652+uweseimet@users.noreply.github.com> Date: Tue, 14 Nov 2023 15:13:45 +0100 Subject: [PATCH 01/11] Add initial IDE setup (#1326) --- cpp/.clang-format | 12 -- cpp/.gitignore | 3 - cpp/.vscode/launch.json | 53 -------- cpp/.vscode/tasks.json | 19 --- cpp/launch_sudo.sh | 3 - ide_setup/README | 5 + ide_setup/eclipse_code_formatter.xml | 193 +++++++++++++++++++++++++++ 7 files changed, 198 insertions(+), 90 deletions(-) delete mode 100644 cpp/.clang-format delete mode 100644 cpp/.vscode/launch.json delete mode 100644 cpp/.vscode/tasks.json delete mode 100755 cpp/launch_sudo.sh create mode 100644 ide_setup/README create mode 100644 ide_setup/eclipse_code_formatter.xml diff --git a/cpp/.clang-format b/cpp/.clang-format deleted file mode 100644 index 7e73f97c..00000000 --- a/cpp/.clang-format +++ /dev/null @@ -1,12 +0,0 @@ -BasedOnStyle: Microsoft -IndentWidth: 4 -AlwaysBreakAfterReturnType: None -AllowShortFunctionsOnASingleLine: Empty -KeepEmptyLinesAtTheStartOfBlocks: false -BreakBeforeBraces: Linux -AlignEscapedNewlines: Left -AlignTrailingComments: True -AllowShortEnumsOnASingleLine: True -AlignConsecutiveAssignments: Consecutive -ColumnLimit: 120 -PointerAlignment: Left \ No newline at end of file diff --git a/cpp/.gitignore b/cpp/.gitignore index 4efdbaa3..6f970d2d 100644 --- a/cpp/.gitignore +++ b/cpp/.gitignore @@ -12,6 +12,3 @@ obj bin coverage generated -.project -.cproject -.settings diff --git a/cpp/.vscode/launch.json b/cpp/.vscode/launch.json deleted file mode 100644 index f3a2f763..00000000 --- a/cpp/.vscode/launch.json +++ /dev/null @@ -1,53 +0,0 @@ -{ - // Use IntelliSense to learn about possible attributes. - // Hover to view descriptions of existing attributes. - // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 - "version": "0.2.0", - "configurations": [ - { - "name": "rascsi (gdb) Launch", - "type": "cppdbg", - "request": "launch", - "program": "${workspaceFolder}/bin/fullspec/rascsi", - "args": [], - "stopAtEntry": true, - "cwd": "${workspaceFolder}", - "environment": [], - "externalConsole": false, - "MIMode": "gdb", - "targetArchitecture": "arm", - "miDebuggerPath": "${workspaceFolder}/launch_sudo.sh", - "setupCommands": [ - { - "description": "Enable pretty-printing for gdb", - "text": "-enable-pretty-printing", - "ignoreFailures": true - } - ] - }, - { - "name": "rascsi_test (gdb) Launch", - "type": "cppdbg", - "request": "launch", - "program": "${workspaceFolder}/bin/fullspec/rascsi_test", - "args": [], - "stopAtEntry": true, - "cwd": "${fileDirname}", - "environment": [], - "externalConsole": false, - "MIMode": "gdb", - "setupCommands": [ - { - "description": "Enable pretty-printing for gdb", - "text": "-enable-pretty-printing", - "ignoreFailures": true - }, - { - "description": "Set Disassembly Flavor to Intel", - "text": "-gdb-set disassembly-flavor intel", - "ignoreFailures": true - } - ] - }, - ] -} \ No newline at end of file diff --git a/cpp/.vscode/tasks.json b/cpp/.vscode/tasks.json deleted file mode 100644 index 6105ee09..00000000 --- a/cpp/.vscode/tasks.json +++ /dev/null @@ -1,19 +0,0 @@ -{ - "version": "2.0.0", - "tasks": [ - { - "type": "shell", - "label": "g++ build active file", - "command": "make", - "args": ["all", "DEBUG=1", "-j4"], - "options": { - "cwd": "${workspaceFolder}/" - }, - "problemMatcher": ["$gcc"], - "group": { - "kind": "build", - "isDefault": true - } - } - ] - } diff --git a/cpp/launch_sudo.sh b/cpp/launch_sudo.sh deleted file mode 100755 index 6ce283c1..00000000 --- a/cpp/launch_sudo.sh +++ /dev/null @@ -1,3 +0,0 @@ -# This is used for debugging. VisualStudio code will call this file when launching -# the debugger, instead of directly calling GDB. That way we can add the pkexec -sudo /usr/bin/gdb "$@" \ No newline at end of file diff --git a/ide_setup/README b/ide_setup/README new file mode 100644 index 00000000..3b0d2b6a --- /dev/null +++ b/ide_setup/README @@ -0,0 +1,5 @@ +The Eclipse code formatter configuration shall be used together with +Eclipse CDT in order to unify the formatting of the C++ code. Ensure to keep +your formatting rules up to date. + +This formatter can also be imported into Intellij IDEA. diff --git a/ide_setup/eclipse_code_formatter.xml b/ide_setup/eclipse_code_formatter.xml new file mode 100644 index 00000000..13b13d59 --- /dev/null +++ b/ide_setup/eclipse_code_formatter.xml @@ -0,0 +1,193 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + From f6d00a0e96d8856cafcd809324ebf48d90a0ff90 Mon Sep 17 00:00:00 2001 From: Uwe Seimet <48174652+uweseimet@users.noreply.github.com> Date: Tue, 14 Nov 2023 15:16:23 +0100 Subject: [PATCH 02/11] Fix error count calculation (#1356) --- cpp/devices/scsi_printer.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cpp/devices/scsi_printer.cpp b/cpp/devices/scsi_printer.cpp index 393e053e..dcb9188b 100644 --- a/cpp/devices/scsi_printer.cpp +++ b/cpp/devices/scsi_printer.cpp @@ -197,7 +197,7 @@ bool SCSIPrinter::WriteByteSequence(span buf) out.write((const char *)buf.data(), buf.size()); const bool status = out.fail(); - if (!status) { + if (status) { ++print_error_count; } From 71780449ff891a59eb0b0e3d53bf89032f29fe53 Mon Sep 17 00:00:00 2001 From: Uwe Seimet <48174652+uweseimet@users.noreply.github.com> Date: Tue, 14 Nov 2023 15:32:46 +0100 Subject: [PATCH 03/11] Move sector sizes lists from DeviceFactory to the respective devices (#1323) --- cpp/devices/device_factory.cpp | 52 ++++------------------- cpp/devices/device_factory.h | 29 +++++++++---- cpp/devices/disk.cpp | 6 +-- cpp/devices/disk.h | 14 +++---- cpp/devices/scsicd.cpp | 5 +-- cpp/devices/scsicd.h | 2 +- cpp/devices/scsihd.cpp | 6 +-- cpp/devices/scsihd.h | 2 +- cpp/devices/scsihd_nec.h | 2 +- cpp/devices/scsimo.cpp | 4 +- cpp/devices/scsimo.h | 2 +- cpp/piscsi/piscsi_core.cpp | 1 - cpp/piscsi/piscsi_core.h | 2 +- cpp/piscsi/piscsi_executor.cpp | 3 +- cpp/piscsi/piscsi_executor.h | 3 +- cpp/piscsi/piscsi_response.cpp | 69 ++++++++++++++++--------------- cpp/piscsi/piscsi_response.h | 7 ++-- cpp/test/device_factory_test.cpp | 35 ---------------- cpp/test/disk_test.cpp | 13 ++---- cpp/test/mocks.h | 12 ++++-- cpp/test/piscsi_executor_test.cpp | 10 +++-- cpp/test/scsicd_test.cpp | 24 +++++++---- cpp/test/scsihd_test.cpp | 27 ++++++++---- cpp/test/scsimo_test.cpp | 21 ++++++++-- 24 files changed, 160 insertions(+), 191 deletions(-) diff --git a/cpp/devices/device_factory.cpp b/cpp/devices/device_factory.cpp index f951d645..011a496b 100644 --- a/cpp/devices/device_factory.cpp +++ b/cpp/devices/device_factory.cpp @@ -7,7 +7,7 @@ // //--------------------------------------------------------------------------- -#include "shared/network_util.h" +#include "shared/piscsi_util.h" #include "scsihd.h" #include "scsihd_nec.h" #include "scsimo.h" @@ -20,39 +20,14 @@ using namespace std; using namespace piscsi_util; -using namespace network_util; - -DeviceFactory::DeviceFactory() -{ - sector_sizes[SCHD] = { 512, 1024, 2048, 4096 }; - sector_sizes[SCRM] = { 512, 1024, 2048, 4096 }; - sector_sizes[SCMO] = { 512, 1024, 2048, 4096 }; - sector_sizes[SCCD] = { 512, 2048}; - - extension_mapping["hd1"] = SCHD; - extension_mapping["hds"] = SCHD; - extension_mapping["hda"] = SCHD; - extension_mapping["hdn"] = SCHD; - extension_mapping["hdi"] = SCHD; - extension_mapping["nhd"] = SCHD; - extension_mapping["hdr"] = SCRM; - extension_mapping["mos"] = SCMO; - extension_mapping["iso"] = SCCD; - extension_mapping["is1"] = SCCD; - - device_mapping["bridge"] = SCBR; - device_mapping["daynaport"] = SCDP; - device_mapping["printer"] = SCLP; - device_mapping["services"] = SCHS; -} PbDeviceType DeviceFactory::GetTypeForFile(const string& filename) const { - if (const auto& it = extension_mapping.find(GetExtensionLowerCase(filename)); it != extension_mapping.end()) { + if (const auto& it = EXTENSION_MAPPING.find(GetExtensionLowerCase(filename)); it != EXTENSION_MAPPING.end()) { return it->second; } - if (const auto& it = device_mapping.find(filename); it != device_mapping.end()) { + if (const auto& it = DEVICE_MAPPING.find(filename); it != DEVICE_MAPPING.end()) { return it->second; } @@ -75,8 +50,7 @@ shared_ptr DeviceFactory::CreateDevice(PbDeviceType type, int lun if (const string ext = GetExtensionLowerCase(filename); ext == "hdn" || ext == "hdi" || ext == "nhd") { device = make_shared(lun); } else { - device = make_shared(lun, sector_sizes.find(type)->second, false, - ext == "hd1" ? scsi_level::scsi_1_ccs : scsi_level::scsi_2); + device = make_shared(lun, false, ext == "hd1" ? scsi_level::scsi_1_ccs : scsi_level::scsi_2); // Some Apple tools require a particular drive identification if (ext == "hda") { @@ -88,17 +62,17 @@ shared_ptr DeviceFactory::CreateDevice(PbDeviceType type, int lun } case SCRM: - device = make_shared(lun, sector_sizes.find(type)->second, true); + device = make_shared(lun, true, scsi_level::scsi_2); device->SetProduct("SCSI HD (REM.)"); break; case SCMO: - device = make_shared(lun, sector_sizes.find(type)->second); + device = make_shared(lun); device->SetProduct("SCSI MO"); break; case SCCD: - device = make_shared(lun, sector_sizes.find(type)->second, + device = make_shared(lun, GetExtensionLowerCase(filename) == "is1" ? scsi_level::scsi_1_ccs : scsi_level::scsi_2); device->SetProduct("SCSI CD-ROM"); break; @@ -135,15 +109,3 @@ shared_ptr DeviceFactory::CreateDevice(PbDeviceType type, int lun return device; } - -// TODO Move to respective device, which may require changes in the SCSI_HD/SCSIHD_NEC inheritance hierarchy -unordered_set DeviceFactory::GetSectorSizes(PbDeviceType type) const -{ - const auto& it = sector_sizes.find(type); - if (it != sector_sizes.end()) { - return it->second; - } - else { - return {}; - } -} diff --git a/cpp/devices/device_factory.h b/cpp/devices/device_factory.h index fef1c17d..7072980c 100644 --- a/cpp/devices/device_factory.h +++ b/cpp/devices/device_factory.h @@ -11,9 +11,7 @@ #pragma once -#include "shared/piscsi_util.h" #include -#include #include #include "generated/piscsi_interface.pb.h" @@ -27,19 +25,32 @@ class DeviceFactory public: - DeviceFactory(); + DeviceFactory() = default; ~DeviceFactory() = default; shared_ptr CreateDevice(PbDeviceType, int, const string&) const; PbDeviceType GetTypeForFile(const string&) const; - unordered_set GetSectorSizes(PbDeviceType type) const; - const auto& GetExtensionMapping() const { return extension_mapping; } + const auto& GetExtensionMapping() const { return EXTENSION_MAPPING; } private: - unordered_map> sector_sizes; + const inline static unordered_map> EXTENSION_MAPPING = { + { "hd1", SCHD }, + { "hds", SCHD }, + { "hda", SCHD }, + { "hdn", SCHD }, + { "hdi", SCHD }, + { "nhd", SCHD }, + { "hdr", SCRM }, + { "mos", SCMO }, + { "is1", SCCD }, + { "iso", SCCD } + }; - unordered_map> extension_mapping; - - unordered_map> device_mapping; + const inline static unordered_map> DEVICE_MAPPING = { + { "bridge", SCBR }, + { "daynaport", SCDP }, + { "printer", SCLP }, + { "services", SCHS } + }; }; diff --git a/cpp/devices/disk.cpp b/cpp/devices/disk.cpp index bc8b53d0..7ae8f275 100644 --- a/cpp/devices/disk.cpp +++ b/cpp/devices/disk.cpp @@ -695,7 +695,7 @@ uint32_t Disk::GetSectorSizeInBytes() const void Disk::SetSectorSizeInBytes(uint32_t size_in_bytes) { - if (DeviceFactory device_factory; !device_factory.GetSectorSizes(GetType()).contains(size_in_bytes)) { + if (!GetSupportedSectorSizes().contains(size_in_bytes)) { throw io_exception("Invalid sector size of " + to_string(size_in_bytes) + " byte(s)"); } @@ -708,9 +708,9 @@ uint32_t Disk::GetConfiguredSectorSize() const return configured_sector_size; } -bool Disk::SetConfiguredSectorSize(const DeviceFactory& device_factory, uint32_t configured_size) +bool Disk::SetConfiguredSectorSize(uint32_t configured_size) { - if (!device_factory.GetSectorSizes(GetType()).contains(configured_size)) { + if (!supported_sector_sizes.contains(configured_size)) { return false; } diff --git a/cpp/devices/disk.h b/cpp/devices/disk.h index 7364ad08..6bb54d66 100644 --- a/cpp/devices/disk.h +++ b/cpp/devices/disk.h @@ -16,7 +16,6 @@ #include "shared/scsi.h" #include "shared/piscsi_util.h" -#include "device_factory.h" #include "disk_track.h" #include "disk_cache.h" #include "interfaces/scsi_block_commands.h" @@ -35,8 +34,7 @@ class Disk : public StorageDevice, private ScsiBlockCommands unique_ptr cache; - // The supported configurable sector sizes, empty if not configurable - unordered_set sector_sizes; + unordered_set supported_sector_sizes; uint32_t configured_sector_size = 0; // Sector size shift count (9=512, 10=1024, 11=2048, 12=4096) @@ -50,7 +48,9 @@ class Disk : public StorageDevice, private ScsiBlockCommands public: - using StorageDevice::StorageDevice; + Disk(PbDeviceType type, int lun, const unordered_set& s) + : StorageDevice(type, lun), supported_sector_sizes(s) {} + ~Disk() override = default; bool Init(const param_map&) override; void CleanUp() override; @@ -64,8 +64,9 @@ public: virtual int Read(span , uint64_t); uint32_t GetSectorSizeInBytes() const; - bool IsSectorSizeConfigurable() const { return !sector_sizes.empty(); } - bool SetConfiguredSectorSize(const DeviceFactory&, uint32_t); + bool IsSectorSizeConfigurable() const { return supported_sector_sizes.size() > 1; } + const auto& GetSupportedSectorSizes() const { return supported_sector_sizes; } + bool SetConfiguredSectorSize(uint32_t); void FlushCache() override; vector GetStatistics() const override; @@ -119,7 +120,6 @@ protected: void AddCachePage(map>&, bool) const; unordered_set GetSectorSizes() const; - void SetSectorSizes(const unordered_set& sizes) { sector_sizes = sizes; } void SetSectorSizeInBytes(uint32_t); uint32_t GetSectorSizeShiftCount() const { return size_shift_count; } void SetSectorSizeShiftCount(uint32_t count) { size_shift_count = count; } diff --git a/cpp/devices/scsicd.cpp b/cpp/devices/scsicd.cpp index 200c36c3..27ab23a3 100644 --- a/cpp/devices/scsicd.cpp +++ b/cpp/devices/scsicd.cpp @@ -21,11 +21,8 @@ using namespace scsi_defs; using namespace scsi_command_util; -SCSICD::SCSICD(int lun, const unordered_set& sector_sizes, scsi_defs::scsi_level level) - : Disk(SCCD, lun), scsi_level(level) +SCSICD::SCSICD(int lun, scsi_defs::scsi_level level) : Disk(SCCD, lun, { 512, 2048 }), scsi_level(level) { - SetSectorSizes(sector_sizes); - SetReadOnly(true); SetRemovable(true); SetLockable(true); diff --git a/cpp/devices/scsicd.h b/cpp/devices/scsicd.h index db2620de..c2aaf4e3 100644 --- a/cpp/devices/scsicd.h +++ b/cpp/devices/scsicd.h @@ -25,7 +25,7 @@ class SCSICD : public Disk, private ScsiMmcCommands { public: - SCSICD(int, const unordered_set&, scsi_defs::scsi_level = scsi_level::scsi_2); + SCSICD(int, scsi_defs::scsi_level = scsi_level::scsi_2); ~SCSICD() override = default; bool Init(const param_map&) override; diff --git a/cpp/devices/scsihd.cpp b/cpp/devices/scsihd.cpp index 316c7575..09c6645a 100644 --- a/cpp/devices/scsihd.cpp +++ b/cpp/devices/scsihd.cpp @@ -19,11 +19,9 @@ using namespace scsi_command_util; -SCSIHD::SCSIHD(int lun, const unordered_set& sector_sizes, bool removable, scsi_defs::scsi_level level) - : Disk(removable ? SCRM : SCHD, lun), scsi_level(level) +SCSIHD::SCSIHD(int lun, bool removable, scsi_defs::scsi_level level, const unordered_set& sector_sizes) + : Disk(removable ? SCRM : SCHD, lun, sector_sizes), scsi_level(level) { - SetSectorSizes(sector_sizes); - SetProtectable(true); SetRemovable(removable); SetLockable(removable); diff --git a/cpp/devices/scsihd.h b/cpp/devices/scsihd.h index 8216ae2a..28a6119d 100644 --- a/cpp/devices/scsihd.h +++ b/cpp/devices/scsihd.h @@ -28,7 +28,7 @@ class SCSIHD : public Disk public: - SCSIHD(int, const unordered_set&, bool, scsi_defs::scsi_level = scsi_level::scsi_2); + SCSIHD(int, bool, scsi_defs::scsi_level, const unordered_set& = { 512, 1024, 2048, 4096 }); ~SCSIHD() override = default; void FinalizeSetup(off_t); diff --git a/cpp/devices/scsihd_nec.h b/cpp/devices/scsihd_nec.h index eec3c1be..4c2fabe2 100644 --- a/cpp/devices/scsihd_nec.h +++ b/cpp/devices/scsihd_nec.h @@ -33,7 +33,7 @@ class SCSIHD_NEC : public SCSIHD //NOSONAR The inheritance hierarchy depth is ac { public: - explicit SCSIHD_NEC(int lun) : SCSIHD(lun, { 512 }, false) {} + explicit SCSIHD_NEC(int lun) : SCSIHD(lun, false, scsi_level::scsi_1_ccs, { 512 }) {} ~SCSIHD_NEC() override = default; void Open() override; diff --git a/cpp/devices/scsimo.cpp b/cpp/devices/scsimo.cpp index 167064a1..57311be8 100644 --- a/cpp/devices/scsimo.cpp +++ b/cpp/devices/scsimo.cpp @@ -19,10 +19,8 @@ using namespace scsi_command_util; -SCSIMO::SCSIMO(int lun, const unordered_set& sector_sizes) : Disk(SCMO, lun) +SCSIMO::SCSIMO(int lun) : Disk(SCMO, lun, { 512, 1024, 2048, 4096 }) { - SetSectorSizes(sector_sizes); - // 128 MB, 512 bytes per sector, 248826 sectors geometries[512 * 248826] = { 512, 248826 }; // 230 MB, 512 bytes per block, 446325 sectors diff --git a/cpp/devices/scsimo.h b/cpp/devices/scsimo.h index 41735d3b..1ef651b8 100644 --- a/cpp/devices/scsimo.h +++ b/cpp/devices/scsimo.h @@ -26,7 +26,7 @@ class SCSIMO : public Disk { public: - SCSIMO(int, const unordered_set&); + explicit SCSIMO(int); ~SCSIMO() override = default; void Open() override; diff --git a/cpp/piscsi/piscsi_core.cpp b/cpp/piscsi/piscsi_core.cpp index 553e2297..bd491b8c 100644 --- a/cpp/piscsi/piscsi_core.cpp +++ b/cpp/piscsi/piscsi_core.cpp @@ -17,7 +17,6 @@ #include "shared/piscsi_version.h" #include "controllers/scsi_controller.h" #include "devices/device_logger.h" -#include "devices/device_factory.h" #include "devices/storage_device.h" #include "hal/gpiobus_factory.h" #include "hal/gpiobus.h" diff --git a/cpp/piscsi/piscsi_core.h b/cpp/piscsi/piscsi_core.h index 1560851d..8d8b917f 100644 --- a/cpp/piscsi/piscsi_core.h +++ b/cpp/piscsi/piscsi_core.h @@ -67,7 +67,7 @@ private: PiscsiImage piscsi_image; - PiscsiResponse response; + [[no_unique_address]] PiscsiResponse response; PiscsiService service; diff --git a/cpp/piscsi/piscsi_executor.cpp b/cpp/piscsi/piscsi_executor.cpp index d930184e..319623eb 100644 --- a/cpp/piscsi/piscsi_executor.cpp +++ b/cpp/piscsi/piscsi_executor.cpp @@ -10,7 +10,6 @@ #include "shared/piscsi_util.h" #include "shared/protobuf_util.h" #include "shared/piscsi_exceptions.h" -#include "devices/device_factory.h" #include "devices/disk.h" #include "localizer.h" #include "command_context.h" @@ -530,7 +529,7 @@ bool PiscsiExecutor::SetSectorSize(const CommandContext& context, shared_ptr(device); if (disk != nullptr && disk->IsSectorSizeConfigurable()) { - if (!disk->SetConfiguredSectorSize(device_factory, size)) { + if (!disk->SetConfiguredSectorSize(size)) { return context.ReturnLocalizedError(LocalizationKey::ERROR_BLOCK_SIZE, to_string(size)); } } diff --git a/cpp/piscsi/piscsi_executor.h b/cpp/piscsi/piscsi_executor.h index bae4fe60..6c4ea1a9 100644 --- a/cpp/piscsi/piscsi_executor.h +++ b/cpp/piscsi/piscsi_executor.h @@ -11,6 +11,7 @@ #include "hal/bus.h" #include "controllers/controller_manager.h" +#include "devices/device_factory.h" #include class DeviceFactory; @@ -60,7 +61,7 @@ private: ControllerManager& controller_manager; - const DeviceFactory device_factory; + [[no_unique_address]] const DeviceFactory device_factory; unordered_set reserved_ids; }; diff --git a/cpp/piscsi/piscsi_response.cpp b/cpp/piscsi/piscsi_response.cpp index 28e7e1a2..1f4d2fe0 100644 --- a/cpp/piscsi/piscsi_response.cpp +++ b/cpp/piscsi/piscsi_response.cpp @@ -24,26 +24,29 @@ using namespace piscsi_util; using namespace network_util; using namespace protobuf_util; -void PiscsiResponse::GetDeviceProperties(const Device& device, PbDeviceProperties& properties) const +void PiscsiResponse::GetDeviceProperties(shared_ptr device, PbDeviceProperties& properties) const { properties.set_luns(ControllerManager::GetScsiLunMax()); - properties.set_read_only(device.IsReadOnly()); - properties.set_protectable(device.IsProtectable()); - properties.set_stoppable(device.IsStoppable()); - properties.set_removable(device.IsRemovable()); - properties.set_lockable(device.IsLockable()); - properties.set_supports_file(device.SupportsFile()); - properties.set_supports_params(device.SupportsParams()); + properties.set_read_only(device->IsReadOnly()); + properties.set_protectable(device->IsProtectable()); + properties.set_stoppable(device->IsStoppable()); + properties.set_removable(device->IsRemovable()); + properties.set_lockable(device->IsLockable()); + properties.set_supports_file(device->SupportsFile()); + properties.set_supports_params(device->SupportsParams()); - if (device.SupportsParams()) { - for (const auto& [key, value] : device.GetDefaultParams()) { + if (device->SupportsParams()) { + for (const auto& [key, value] : device->GetDefaultParams()) { auto& map = *properties.mutable_default_params(); map[key] = value; } } - for (const auto& block_size : device_factory.GetSectorSizes(device.GetType())) { - properties.add_block_sizes(block_size); + shared_ptr disk = dynamic_pointer_cast(device); + if (disk != nullptr && disk->IsSectorSizeConfigurable()) { + for (const auto& sector_size : disk->GetSupportedSectorSizes()) { + properties.add_block_sizes(sector_size); + } } } @@ -52,7 +55,7 @@ void PiscsiResponse::GetDeviceTypeProperties(PbDeviceTypesInfo& device_types_inf auto type_properties = device_types_info.add_properties(); type_properties->set_type(type); const auto device = device_factory.CreateDevice(type, 0, ""); - GetDeviceProperties(*device, *type_properties->mutable_properties()); + GetDeviceProperties(device, *type_properties->mutable_properties()); } void PiscsiResponse::GetDeviceTypesInfo(PbDeviceTypesInfo& device_types_info) const @@ -67,37 +70,37 @@ void PiscsiResponse::GetDeviceTypesInfo(PbDeviceTypesInfo& device_types_info) co } } -void PiscsiResponse::GetDevice(const Device& device, PbDevice& pb_device, const string& default_folder) const +void PiscsiResponse::GetDevice(shared_ptr device, PbDevice& pb_device, const string& default_folder) const { - pb_device.set_id(device.GetId()); - pb_device.set_unit(device.GetLun()); - pb_device.set_vendor(device.GetVendor()); - pb_device.set_product(device.GetProduct()); - pb_device.set_revision(device.GetRevision()); - pb_device.set_type(device.GetType()); + pb_device.set_id(device->GetId()); + pb_device.set_unit(device->GetLun()); + pb_device.set_vendor(device->GetVendor()); + pb_device.set_product(device->GetProduct()); + pb_device.set_revision(device->GetRevision()); + pb_device.set_type(device->GetType()); GetDeviceProperties(device, *pb_device.mutable_properties()); auto status = pb_device.mutable_status(); - status->set_protected_(device.IsProtected()); - status->set_stopped(device.IsStopped()); - status->set_removed(device.IsRemoved()); - status->set_locked(device.IsLocked()); + status->set_protected_(device->IsProtected()); + status->set_stopped(device->IsStopped()); + status->set_removed(device->IsRemoved()); + status->set_locked(device->IsLocked()); - if (device.SupportsParams()) { - for (const auto& [key, value] : device.GetParams()) { + if (device->SupportsParams()) { + for (const auto& [key, value] : device->GetParams()) { SetParam(pb_device, key, value); } } - if (const auto disk = dynamic_cast(&device); disk) { - pb_device.set_block_size(device.IsRemoved()? 0 : disk->GetSectorSizeInBytes()); - pb_device.set_block_count(device.IsRemoved() ? 0: disk->GetBlockCount()); + if (const auto disk = dynamic_pointer_cast(device); disk) { + pb_device.set_block_size(device->IsRemoved()? 0 : disk->GetSectorSizeInBytes()); + pb_device.set_block_count(device->IsRemoved() ? 0: disk->GetBlockCount()); } - const auto storage_device = dynamic_cast(&device); + const auto storage_device = dynamic_pointer_cast(device); if (storage_device != nullptr) { - GetImageFile(*pb_device.mutable_file(), default_folder, device.IsReady() ? storage_device->GetFilename() : ""); + GetImageFile(*pb_device.mutable_file(), default_folder, device->IsReady() ? storage_device->GetFilename() : ""); } } @@ -191,7 +194,7 @@ void PiscsiResponse::GetDevices(const unordered_set>& { for (const auto& device : devices) { PbDevice *pb_device = server_info.mutable_devices_info()->add_devices(); - GetDevice(*device, *pb_device, default_folder); + GetDevice(device, *pb_device, default_folder); } } @@ -218,7 +221,7 @@ void PiscsiResponse::GetDevicesInfo(const unordered_setGetId() == id && d->GetLun() == lun) { - GetDevice(*d, *devices_info->add_devices(), default_folder); + GetDevice(d, *devices_info->add_devices(), default_folder); break; } } diff --git a/cpp/piscsi/piscsi_response.h b/cpp/piscsi/piscsi_response.h index b095416f..0015655c 100644 --- a/cpp/piscsi/piscsi_response.h +++ b/cpp/piscsi/piscsi_response.h @@ -47,11 +47,10 @@ private: inline static const vector EMPTY_VECTOR; - // TODO Try to get rid of this field by having the device instead of the factory providing the device data - const DeviceFactory device_factory; + [[no_unique_address]] const DeviceFactory device_factory; - void GetDeviceProperties(const Device&, PbDeviceProperties&) const; - void GetDevice(const Device&, PbDevice&, const string&) const; + void GetDeviceProperties(shared_ptr, PbDeviceProperties&) const; + void GetDevice(shared_ptr, PbDevice&, const string&) const; void GetDeviceTypeProperties(PbDeviceTypesInfo&, PbDeviceType) const; void GetAvailableImages(PbImageFilesInfo&, const string&, const string&, const string&, int) const; void GetAvailableImages(PbServerInfo&, const string&, const string&, const string&, int) const; diff --git a/cpp/test/device_factory_test.cpp b/cpp/test/device_factory_test.cpp index 0c51c194..ce74398b 100644 --- a/cpp/test/device_factory_test.cpp +++ b/cpp/test/device_factory_test.cpp @@ -39,41 +39,6 @@ TEST(DeviceFactoryTest, GetTypeForFile) EXPECT_EQ(device_factory.GetTypeForFile("test.iso.suffix"), UNDEFINED); } -TEST(DeviceFactoryTest, GetSectorSizes) -{ - DeviceFactory device_factory; - - unordered_set sector_sizes = device_factory.GetSectorSizes(SCHD); - EXPECT_EQ(4, sector_sizes.size()); - - EXPECT_TRUE(sector_sizes.contains(512)); - EXPECT_TRUE(sector_sizes.contains(1024)); - EXPECT_TRUE(sector_sizes.contains(2048)); - EXPECT_TRUE(sector_sizes.contains(4096)); - - sector_sizes = device_factory.GetSectorSizes(SCRM); - EXPECT_EQ(4, sector_sizes.size()); - - EXPECT_TRUE(sector_sizes.contains(512)); - EXPECT_TRUE(sector_sizes.contains(1024)); - EXPECT_TRUE(sector_sizes.contains(2048)); - EXPECT_TRUE(sector_sizes.contains(4096)); - - sector_sizes = device_factory.GetSectorSizes(SCMO); - EXPECT_EQ(4, sector_sizes.size()); - - EXPECT_TRUE(sector_sizes.contains(512)); - EXPECT_TRUE(sector_sizes.contains(1024)); - EXPECT_TRUE(sector_sizes.contains(2048)); - EXPECT_TRUE(sector_sizes.contains(4096)); - - sector_sizes = device_factory.GetSectorSizes(SCCD); - EXPECT_EQ(2, sector_sizes.size()); - - EXPECT_TRUE(sector_sizes.contains(512)); - EXPECT_TRUE(sector_sizes.contains(2048)); -} - TEST(DeviceFactoryTest, GetExtensionMapping) { DeviceFactory device_factory; diff --git a/cpp/test/disk_test.cpp b/cpp/test/disk_test.cpp index b0206403..f7ad298f 100644 --- a/cpp/test/disk_test.cpp +++ b/cpp/test/disk_test.cpp @@ -774,14 +774,8 @@ TEST(DiskTest, SectorSize) { MockDisk disk; - unordered_set sizes = { 512, 1024 }; - disk.SetSectorSizes(sizes); EXPECT_TRUE(disk.IsSectorSizeConfigurable()); - sizes.clear(); - disk.SetSectorSizes(sizes); - EXPECT_FALSE(disk.IsSectorSizeConfigurable()); - disk.SetSectorSizeShiftCount(9); EXPECT_EQ(9, disk.GetSectorSizeShiftCount()); EXPECT_EQ(512, disk.GetSectorSizeInBytes()); @@ -815,13 +809,12 @@ TEST(DiskTest, SectorSize) TEST(DiskTest, ConfiguredSectorSize) { - DeviceFactory device_factory; - MockSCSIHD disk(0, {}, false); + MockSCSIHD disk(0, false); - EXPECT_TRUE(disk.SetConfiguredSectorSize(device_factory, 512)); + EXPECT_TRUE(disk.SetConfiguredSectorSize(512)); EXPECT_EQ(512, disk.GetConfiguredSectorSize()); - EXPECT_FALSE(disk.SetConfiguredSectorSize(device_factory, 1234)); + EXPECT_FALSE(disk.SetConfiguredSectorSize(1234)); EXPECT_EQ(512, disk.GetConfiguredSectorSize()); } diff --git a/cpp/test/mocks.h b/cpp/test/mocks.h index fcf45cd5..cc761802 100644 --- a/cpp/test/mocks.h +++ b/cpp/test/mocks.h @@ -352,7 +352,7 @@ public: MOCK_METHOD(void, FlushCache, (), (override)); MOCK_METHOD(void, Open, (), (override)); - MockDisk() : Disk(SCHD, 0) {} + MockDisk() : Disk(SCHD, 0, { 512, 1024, 2048, 4096 }) {} ~MockDisk() override = default; }; @@ -363,10 +363,15 @@ class MockSCSIHD : public SCSIHD //NOSONAR Ignore inheritance hierarchy depth in FRIEND_TEST(ScsiHdTest, FinalizeSetup); FRIEND_TEST(ScsiHdTest, GetProductData); FRIEND_TEST(ScsiHdTest, SetUpModePages); - FRIEND_TEST(PiscsiExecutorTest, SetSectorSize); + FRIEND_TEST(ScsiHdTest, GetSectorSizes); FRIEND_TEST(ScsiHdTest, ModeSelect); + FRIEND_TEST(PiscsiExecutorTest, SetSectorSize); - using SCSIHD::SCSIHD; +public: + + MockSCSIHD(int lun, bool removable) : SCSIHD(lun, removable, scsi_level::scsi_2) {} + explicit MockSCSIHD(const unordered_set& sector_sizes) : SCSIHD(0, false, scsi_level::scsi_2, sector_sizes) {} + ~MockSCSIHD() override = default; }; class MockSCSIHD_NEC : public SCSIHD_NEC //NOSONAR Ignore inheritance hierarchy depth in unit tests @@ -382,6 +387,7 @@ class MockSCSIHD_NEC : public SCSIHD_NEC //NOSONAR Ignore inheritance hierarchy class MockSCSICD : public SCSICD //NOSONAR Ignore inheritance hierarchy depth in unit tests { + FRIEND_TEST(ScsiCdTest, GetSectorSizes); FRIEND_TEST(ScsiCdTest, SetUpModePages); FRIEND_TEST(ScsiCdTest, ReadToc); diff --git a/cpp/test/piscsi_executor_test.cpp b/cpp/test/piscsi_executor_test.cpp index d6557be4..06b218a1 100644 --- a/cpp/test/piscsi_executor_test.cpp +++ b/cpp/test/piscsi_executor_test.cpp @@ -252,8 +252,6 @@ TEST(PiscsiExecutorTest, Attach) TEST(PiscsiExecutorTest, Insert) { - DeviceFactory device_factory; - auto bus = make_shared(); ControllerManager controller_manager; auto [controller, device] = CreateDevice(SCHD); @@ -500,13 +498,17 @@ TEST(PiscsiExecutorTest, SetSectorSize) CommandContext context(command, "", ""); unordered_set sizes; - auto hd = make_shared(0, sizes, false); + auto hd = make_shared(sizes); EXPECT_FALSE(executor.SetSectorSize(context, hd, 512)); sizes.insert(512); - hd = make_shared(0, sizes, false); + hd = make_shared(sizes); EXPECT_TRUE(executor.SetSectorSize(context, hd, 0)); EXPECT_FALSE(executor.SetSectorSize(context, hd, 1)); + EXPECT_FALSE(executor.SetSectorSize(context, hd, 512)); + + sizes.insert(1024); + hd = make_shared(sizes); EXPECT_TRUE(executor.SetSectorSize(context, hd, 512)); } diff --git a/cpp/test/scsicd_test.cpp b/cpp/test/scsicd_test.cpp index fa5d8743..b4c9154f 100644 --- a/cpp/test/scsicd_test.cpp +++ b/cpp/test/scsicd_test.cpp @@ -34,10 +34,21 @@ TEST(ScsiCdTest, Inquiry) TestInquiry::Inquiry(SCCD, device_type::cd_rom, scsi_level::scsi_1_ccs, "PiSCSI SCSI CD-ROM ", 0x1f, true, "file.is1"); } +TEST(ScsiCdTest, GetSectorSizes) +{ + MockSCSICD cd(0); + + const auto& sector_sizes = cd.GetSupportedSectorSizes(); + EXPECT_EQ(2, sector_sizes.size()); + + EXPECT_TRUE(sector_sizes.contains(512)); + EXPECT_TRUE(sector_sizes.contains(2048)); +} + TEST(ScsiCdTest, SetUpModePages) { map> pages; - MockSCSICD cd(0, {}); + MockSCSICD cd(0); // Non changeable cd.SetUpModePages(pages, 0x3f, false); @@ -51,10 +62,10 @@ TEST(ScsiCdTest, SetUpModePages) TEST(ScsiCdTest, Open) { - MockSCSICD cd_iso(0, {}); - MockSCSICD cd_cue(0, {}); - MockSCSICD cd_raw(0, {}); - MockSCSICD cd_physical(0, {}); + MockSCSICD cd_iso(0); + MockSCSICD cd_cue(0); + MockSCSICD cd_raw(0); + MockSCSICD cd_physical(0); EXPECT_THROW(cd_iso.Open(), io_exception) << "Missing filename"; @@ -111,8 +122,7 @@ TEST(ScsiCdTest, Open) TEST(ScsiCdTest, ReadToc) { auto controller = make_shared(); - const unordered_set sector_sizes; - auto cd = make_shared(0, sector_sizes); + auto cd = make_shared(0); EXPECT_TRUE(cd->Init({})); controller->AddDevice(cd); diff --git a/cpp/test/scsihd_test.cpp b/cpp/test/scsihd_test.cpp index 1cdacad0..693f450b 100644 --- a/cpp/test/scsihd_test.cpp +++ b/cpp/test/scsihd_test.cpp @@ -30,14 +30,14 @@ TEST(ScsiHdTest, Inquiry) TEST(ScsiHdTest, SupportsSaveParameters) { - MockSCSIHD hd(0, {}, false); + MockSCSIHD hd(0, false); EXPECT_TRUE(hd.SupportsSaveParameters()); } TEST(ScsiHdTest, FinalizeSetup) { - MockSCSIHD hd(0, {}, false); + MockSCSIHD hd(0, false); hd.SetSectorSizeInBytes(1024); EXPECT_THROW(hd.FinalizeSetup(0), io_exception) << "Device has 0 blocks"; @@ -45,9 +45,9 @@ TEST(ScsiHdTest, FinalizeSetup) TEST(ScsiHdTest, GetProductData) { - MockSCSIHD hd_kb(0, {}, false); - MockSCSIHD hd_mb(0, {}, false); - MockSCSIHD hd_gb(0, {}, false); + MockSCSIHD hd_kb(0, false); + MockSCSIHD hd_mb(0, false); + MockSCSIHD hd_gb(0, false); const path filename = CreateTempFile(1); hd_kb.SetFilename(string(filename)); @@ -73,10 +73,23 @@ TEST(ScsiHdTest, GetProductData) remove(filename); } +TEST(ScsiHdTest, GetSectorSizes) +{ + MockSCSIHD hd(0, false); + + const auto& sector_sizes = hd.GetSupportedSectorSizes(); + EXPECT_EQ(4, sector_sizes.size()); + + EXPECT_TRUE(sector_sizes.contains(512)); + EXPECT_TRUE(sector_sizes.contains(1024)); + EXPECT_TRUE(sector_sizes.contains(2048)); + EXPECT_TRUE(sector_sizes.contains(4096)); +} + TEST(ScsiHdTest, SetUpModePages) { map> pages; - MockSCSIHD hd(0, {}, false); + MockSCSIHD hd(0, false); // Non changeable hd.SetUpModePages(pages, 0x3f, false); @@ -90,7 +103,7 @@ TEST(ScsiHdTest, SetUpModePages) TEST(ScsiHdTest, ModeSelect) { - MockSCSIHD hd(0, { 512 }, false); + MockSCSIHD hd({ 512 }); vector cmd(10); vector buf(255); diff --git a/cpp/test/scsimo_test.cpp b/cpp/test/scsimo_test.cpp index 2422c479..d38ee4a4 100644 --- a/cpp/test/scsimo_test.cpp +++ b/cpp/test/scsimo_test.cpp @@ -28,15 +28,28 @@ TEST(ScsiMoTest, Inquiry) TEST(ScsiMoTest, SupportsSaveParameters) { map> pages; - MockSCSIMO mo(0, {}); + MockSCSIMO mo(0); EXPECT_TRUE(mo.SupportsSaveParameters()); } +TEST(ScsiMoTest, GetSectorSizes) +{ + MockSCSIMO mo(0); + + const auto& sector_sizes = mo.GetSupportedSectorSizes(); + EXPECT_EQ(4, sector_sizes.size()); + + EXPECT_TRUE(sector_sizes.contains(512)); + EXPECT_TRUE(sector_sizes.contains(1024)); + EXPECT_TRUE(sector_sizes.contains(2048)); + EXPECT_TRUE(sector_sizes.contains(4096)); +} + TEST(ScsiMoTest, SetUpModePages) { map> pages; - MockSCSIMO mo(0, {}); + MockSCSIMO mo(0); // Non changeable mo.SetUpModePages(pages, 0x3f, false); @@ -51,7 +64,7 @@ TEST(ScsiMoTest, SetUpModePages) TEST(ScsiMoTest, TestAddVendorPage) { map> pages; - MockSCSIMO mo(0, {}); + MockSCSIMO mo(0); mo.SetReady(true); mo.SetUpModePages(pages, 0x21, false); @@ -122,7 +135,7 @@ TEST(ScsiMoTest, TestAddVendorPage) TEST(ScsiMoTest, ModeSelect) { - MockSCSIMO mo(0, { 1024, 2048 }); + MockSCSIMO mo(0); vector cmd(10); vector buf(255); From 7fa9abe5a3234293f71b98a96323c484237cd154 Mon Sep 17 00:00:00 2001 From: Uwe Seimet <48174652+uweseimet@users.noreply.github.com> Date: Tue, 14 Nov 2023 15:51:36 +0100 Subject: [PATCH 04/11] Remove fullspec/standard sub-folder (#1324) * Remove fullspec/standard sub-folder --- .github/workflows/cpp.yml | 2 +- cpp/Makefile | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/cpp.yml b/.github/workflows/cpp.yml index 7c3eac8c..b4fac982 100644 --- a/.github/workflows/cpp.yml +++ b/.github/workflows/cpp.yml @@ -35,7 +35,7 @@ jobs: run: make -j $(nproc) test - name: Run unit tests - run: (set -o pipefail && bin/fullspec/piscsi_test | tee piscsi_test_log.txt) + run: (set -o pipefail && bin/piscsi_test | tee piscsi_test_log.txt) - name: Upload logs uses: actions/upload-artifact@v3 diff --git a/cpp/Makefile b/cpp/Makefile index c5d0b83d..104a1585 100644 --- a/cpp/Makefile +++ b/cpp/Makefile @@ -60,8 +60,8 @@ COVERAGE_DIR = coverage COVERAGE_FILE = piscsi.dat OS_FILES = ../os_integration -OBJDIR := obj/$(shell echo $(CONNECT_TYPE) | tr '[:upper:]' '[:lower:]') -BINDIR := bin/$(shell echo $(CONNECT_TYPE) | tr '[:upper:]' '[:lower:]') +OBJDIR := obj +BINDIR := bin BIN_ALL = \ $(BINDIR)/$(PISCSI) \ From baf89dcf863ed855d003b6aaba20e6dbb0132df3 Mon Sep 17 00:00:00 2001 From: Uwe Seimet <48174652+uweseimet@users.noreply.github.com> Date: Tue, 14 Nov 2023 16:03:25 +0100 Subject: [PATCH 05/11] Use standard C++ timer for long timeouts (#1327), remove unused code (#1328) * Replace timer in WaitSignal() ' Remove unused code * Remove unused file --- cpp/hal/bus.cpp | 35 ++++++++++++---------- cpp/hal/bus.h | 7 +---- cpp/hal/data_sample.h | 1 - cpp/hal/data_sample_raspberry.cpp | 14 --------- cpp/hal/data_sample_raspberry.h | 6 +--- cpp/hal/gpiobus.cpp | 45 +++++++++-------------------- cpp/hal/gpiobus.h | 2 -- cpp/hal/gpiobus_raspberry.cpp | 11 ------- cpp/hal/gpiobus_raspberry.h | 8 ----- cpp/hal/gpiobus_virtual.cpp | 5 ---- cpp/hal/gpiobus_virtual.h | 8 ----- cpp/hal/pin_control.h | 5 +--- cpp/hal/systimer.cpp | 6 ---- cpp/hal/systimer.h | 5 ---- cpp/hal/systimer_raspberry.cpp | 10 ------- cpp/hal/systimer_raspberry.h | 2 -- cpp/test/gpiobus_raspberry_test.cpp | 13 --------- cpp/test/mocks.h | 3 -- 18 files changed, 37 insertions(+), 149 deletions(-) delete mode 100644 cpp/hal/data_sample_raspberry.cpp diff --git a/cpp/hal/bus.cpp b/cpp/hal/bus.cpp index ff2edd1b..b135342a 100644 --- a/cpp/hal/bus.cpp +++ b/cpp/hal/bus.cpp @@ -60,23 +60,28 @@ const char* BUS::GetPhaseStrRaw(phase_t current_phase) { return it != phase_str_mapping.end() ? it->second : "INVALID"; } -//--------------------------------------------------------------------------- +// Phase Table +// Reference Table 8: https://www.staff.uni-mainz.de/tacke/scsi/SCSI2-06.html +// This determines the phase based upon the Msg, C/D and I/O signals. // -// Phase Table -// Reference Table 8: https://www.staff.uni-mainz.de/tacke/scsi/SCSI2-06.html -// This determines the phase based upon the Msg, C/D and I/O signals. -// -//--------------------------------------------------------------------------- +// |MSG|C/D|I/O| Phase +// | 0 | 0 | 0 | DATA OUT +// | 0 | 0 | 1 | DATA IN +// | 0 | 1 | 0 | COMMAND +// | 0 | 1 | 1 | STATUS +// | 1 | 0 | 0 | RESERVED +// | 1 | 0 | 1 | RESERVED +// | 1 | 1 | 0 | MESSAGE OUT +// | 1 | 1 | 1 | MESSAGE IN const array BUS::phase_table = { - // | MSG|C/D|I/O | - phase_t::dataout, // | 0 | 0 | 0 | - phase_t::datain, // | 0 | 0 | 1 | - phase_t::command, // | 0 | 1 | 0 | - phase_t::status, // | 0 | 1 | 1 | - phase_t::reserved, // | 1 | 0 | 0 | - phase_t::reserved, // | 1 | 0 | 1 | - phase_t::msgout, // | 1 | 1 | 0 | - phase_t::msgin // | 1 | 1 | 1 | + phase_t::dataout, + phase_t::datain, + phase_t::command, + phase_t::status, + phase_t::reserved, + phase_t::reserved, + phase_t::msgout, + phase_t::msgin }; //--------------------------------------------------------------------------- diff --git a/cpp/hal/bus.h b/cpp/hal/bus.h index 23740fe2..17a1a805 100644 --- a/cpp/hal/bus.h +++ b/cpp/hal/bus.h @@ -68,8 +68,7 @@ class BUS : public PinControl // Operation modes definition enum class mode_e { TARGET = 0, - INITIATOR = 1, - MONITOR = 2, + INITIATOR = 1 }; static int GetCommandByteCount(uint8_t); @@ -86,7 +85,6 @@ class BUS : public PinControl // Get the string phase name, based upon the raw data static const char *GetPhaseStrRaw(phase_t current_phase); - virtual int GetMode(int pin) = 0; virtual uint32_t Acquire() = 0; virtual unique_ptr GetSample(uint64_t timestamp = 0) = 0; @@ -97,9 +95,6 @@ class BUS : public PinControl // SEL signal event polling virtual bool PollSelectEvent() = 0; - // Clear SEL signal event - virtual void ClearSelectEvent() = 0; - virtual bool GetSignal(int pin) const = 0; // Get SCSI input signal value virtual void SetSignal(int pin, bool ast) = 0; diff --git a/cpp/hal/data_sample.h b/cpp/hal/data_sample.h index c5a57e30..d7e794b0 100644 --- a/cpp/hal/data_sample.h +++ b/cpp/hal/data_sample.h @@ -31,7 +31,6 @@ class DataSample virtual bool GetREQ() const = 0; virtual bool GetACT() const = 0; virtual uint8_t GetDAT() const = 0; - virtual bool GetDP() const = 0; virtual uint32_t GetRawCapture() const = 0; diff --git a/cpp/hal/data_sample_raspberry.cpp b/cpp/hal/data_sample_raspberry.cpp deleted file mode 100644 index 9634a912..00000000 --- a/cpp/hal/data_sample_raspberry.cpp +++ /dev/null @@ -1,14 +0,0 @@ -//--------------------------------------------------------------------------- -// -// SCSI Target Emulator PiSCSI -// for Raspberry Pi -// -// Copyright (C) 2022 akuker -// -// [ SCSI Bus Monitor ] -// -//--------------------------------------------------------------------------- - -#include "shared/scsi.h" -#include "data_sample.h" - diff --git a/cpp/hal/data_sample_raspberry.h b/cpp/hal/data_sample_raspberry.h index a0b5e1e7..ee7cbc0e 100644 --- a/cpp/hal/data_sample_raspberry.h +++ b/cpp/hal/data_sample_raspberry.h @@ -74,10 +74,6 @@ class DataSample_Raspberry final : public DataSample { return GetSignal(PIN_ACT); } - bool GetDP() const override - { - return GetSignal(PIN_DP); - } uint8_t GetDAT() const override { uint8_t ret_val = 0; @@ -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 837fc6d7..397ed9cf 100644 --- a/cpp/hal/gpiobus.cpp +++ b/cpp/hal/gpiobus.cpp @@ -1,10 +1,11 @@ //--------------------------------------------------------------------------- // -// SCSI Target Emulator PiSCSI -// for Raspberry Pi +// SCSI Target Emulator PiSCSI +// for Raspberry Pi // -// Powered by XM6 TypeG Technology. -// Copyright (C) 2016-2020 GIMONS +// Powered by XM6 TypeG Technology. +// Copyright (C) 2016-2020 GIMONS +// Copyright (C) 2023 Uwe Seimet // //--------------------------------------------------------------------------- @@ -18,6 +19,7 @@ #ifdef __linux__ #include #endif +#include using namespace std; @@ -403,42 +405,23 @@ bool GPIOBUS::PollSelectEvent() #endif } -//--------------------------------------------------------------------------- -// -// Cancel SEL signal event -// -//--------------------------------------------------------------------------- -void GPIOBUS::ClearSelectEvent() -{ - GPIO_FUNCTION_TRACE -} - -//--------------------------------------------------------------------------- -// -// Wait for signal change -// -//--------------------------------------------------------------------------- bool GPIOBUS::WaitSignal(int pin, bool ast) { - // Get current time - const uint32_t now = SysTimer::GetTimerLow(); - - // Calculate timeout (3000ms) - const uint32_t timeout = 3000 * 1000; + const auto now = chrono::steady_clock::now(); + // Wait up to 3 s do { - // Immediately upon receiving a reset Acquire(); - if (GetRST()) { - return false; - } - // Check for the signal edge if (GetSignal(pin) == ast) { return true; } - } while ((SysTimer::GetTimerLow() - now) < timeout); - // We timed out waiting for the signal + // Abort on a reset + if (GetRST()) { + return false; + } + } while ((chrono::duration_cast(chrono::steady_clock::now() - now).count()) < 3); + return false; } diff --git a/cpp/hal/gpiobus.h b/cpp/hal/gpiobus.h index fe774115..0e9e8129 100644 --- a/cpp/hal/gpiobus.h +++ b/cpp/hal/gpiobus.h @@ -182,8 +182,6 @@ class GPIOBUS : public BUS // SEL signal event polling bool PollSelectEvent() override; - // Clear SEL signal event - void ClearSelectEvent() override; protected: virtual void MakeTable() = 0; diff --git a/cpp/hal/gpiobus_raspberry.cpp b/cpp/hal/gpiobus_raspberry.cpp index 44e09dfe..030413fd 100644 --- a/cpp/hal/gpiobus_raspberry.cpp +++ b/cpp/hal/gpiobus_raspberry.cpp @@ -644,17 +644,6 @@ void GPIOBUS_Raspberry::SetDAT(uint8_t dat) #endif // SIGNAL_CONTROL_MODE } -bool GPIOBUS_Raspberry::GetDP() const -{ - return GetSignal(PIN_DP); -} - -//--------------------------------------------------------------------------- -// -// Create work table -// -//--------------------------------------------------------------------------- - //--------------------------------------------------------------------------- // // Signal table diff --git a/cpp/hal/gpiobus_raspberry.h b/cpp/hal/gpiobus_raspberry.h index a79df0e5..9918fe21 100644 --- a/cpp/hal/gpiobus_raspberry.h +++ b/cpp/hal/gpiobus_raspberry.h @@ -137,8 +137,6 @@ class GPIOBUS_Raspberry : public GPIOBUS // Set REQ signal void SetREQ(bool ast) override; - bool GetDP() const override; - // Get DAT signal uint8_t GetDAT() override; // Set DAT signal @@ -174,12 +172,6 @@ class GPIOBUS_Raspberry : public GPIOBUS // Set Control Signal void SetMode(int pin, int mode) override; // Set SCSI I/O mode - int GetMode(int pin) override - { - // Not implemented (or needed for thist gpio bus type) - (void)pin; - return -1; - } bool GetSignal(int pin) const override; // Get SCSI input signal value void SetSignal(int pin, bool ast) override; diff --git a/cpp/hal/gpiobus_virtual.cpp b/cpp/hal/gpiobus_virtual.cpp index 136dae24..5648a871 100644 --- a/cpp/hal/gpiobus_virtual.cpp +++ b/cpp/hal/gpiobus_virtual.cpp @@ -372,11 +372,6 @@ void GPIOBUS_Virtual::SetREQ(bool ast) SetSignal(PIN_REQ, ast); } -bool GPIOBUS_Virtual::GetDP() const -{ - return GetSignal(PIN_DP); -} - //--------------------------------------------------------------------------- // // Get data signals diff --git a/cpp/hal/gpiobus_virtual.h b/cpp/hal/gpiobus_virtual.h index 85e00c79..991e3f85 100644 --- a/cpp/hal/gpiobus_virtual.h +++ b/cpp/hal/gpiobus_virtual.h @@ -97,8 +97,6 @@ class GPIOBUS_Virtual final : public GPIOBUS void SetREQ(bool ast) override; // Set REQ signal - bool GetDP() const override; - bool WaitREQ(bool ast) override { return WaitSignal(PIN_REQ, ast); @@ -120,12 +118,6 @@ class GPIOBUS_Virtual final : public GPIOBUS // Set Control Signal void SetMode(int pin, int mode) override; // Set SCSI I/O mode - int GetMode(int pin) override - { - // Not implemented (or needed for thist gpio bus type) - (void)pin; - return -1; - } bool GetSignal(int pin) const override; // Get SCSI input signal value void SetSignal(int pin, bool ast) override; diff --git a/cpp/hal/pin_control.h b/cpp/hal/pin_control.h index 902a5de7..d5690d89 100644 --- a/cpp/hal/pin_control.h +++ b/cpp/hal/pin_control.h @@ -52,9 +52,6 @@ class PinControl // Set ENB signal virtual void SetENB(bool ast) = 0; - // Get parity signal - virtual bool GetDP() const = 0; - // GPIO pin direction setting virtual void PinConfig(int pin, int mode) = 0; // GPIO pin pull up/down resistor setting @@ -65,4 +62,4 @@ class PinControl PinControl() = default; virtual ~PinControl() = default; -}; \ No newline at end of file +}; diff --git a/cpp/hal/systimer.cpp b/cpp/hal/systimer.cpp index c2b4e7b8..9073ed82 100644 --- a/cpp/hal/systimer.cpp +++ b/cpp/hal/systimer.cpp @@ -43,12 +43,6 @@ 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) { diff --git a/cpp/hal/systimer.h b/cpp/hal/systimer.h index 0479ec5c..b4c4822d 100644 --- a/cpp/hal/systimer.h +++ b/cpp/hal/systimer.h @@ -29,8 +29,6 @@ class PlatformSpecificTimer virtual void Init() = 0; // Get system timer low byte virtual uint32_t GetTimerLow() = 0; - // Get system timer high byte - virtual uint32_t GetTimerHigh() = 0; // Sleep for N nanoseconds virtual void SleepNsec(uint32_t nsec) = 0; // Sleep for N microseconds @@ -48,8 +46,6 @@ class SysTimer static void Init(); // Get system timer low byte static uint32_t GetTimerLow(); - // Get system timer high byte - static uint32_t GetTimerHigh(); // Sleep for N nanoseconds static void SleepNsec(uint32_t nsec); // Sleep for N microseconds @@ -57,7 +53,6 @@ class SysTimer private: static bool initialized; - static bool is_allwinnner; static bool is_raspberry; static std::unique_ptr systimer_ptr; diff --git a/cpp/hal/systimer_raspberry.cpp b/cpp/hal/systimer_raspberry.cpp index 8814ea02..76da6abf 100644 --- a/cpp/hal/systimer_raspberry.cpp +++ b/cpp/hal/systimer_raspberry.cpp @@ -92,16 +92,6 @@ uint32_t SysTimer_Raspberry::GetTimerLow() return systaddr[SYST_CLO]; } -//--------------------------------------------------------------------------- -// -// Get system timer high byte -// -//--------------------------------------------------------------------------- -uint32_t SysTimer_Raspberry::GetTimerHigh() -{ - return systaddr[SYST_CHI]; -} - //--------------------------------------------------------------------------- // // Sleep in nanoseconds diff --git a/cpp/hal/systimer_raspberry.h b/cpp/hal/systimer_raspberry.h index 809d8229..e5ba2197 100644 --- a/cpp/hal/systimer_raspberry.h +++ b/cpp/hal/systimer_raspberry.h @@ -32,8 +32,6 @@ class SysTimer_Raspberry : public PlatformSpecificTimer 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 diff --git a/cpp/test/gpiobus_raspberry_test.cpp b/cpp/test/gpiobus_raspberry_test.cpp index 5a94d670..03184557 100644 --- a/cpp/test/gpiobus_raspberry_test.cpp +++ b/cpp/test/gpiobus_raspberry_test.cpp @@ -219,16 +219,3 @@ TEST(GpiobusRaspberry, GetREQ) bus.Acquire(); EXPECT_EQ(false, bus.GetREQ()); } - -TEST(GpiobusRaspberry, GetDP) -{ - SetableGpiobusRaspberry bus; - - bus.TestSetGpios(0x00); - bus.TestSetGpioPin(PIN_DP, true); - bus.Acquire(); - EXPECT_EQ(true, bus.GetDP()); - bus.TestSetGpioPin(PIN_DP, false); - bus.Acquire(); - EXPECT_EQ(false, bus.GetDP()); -} diff --git a/cpp/test/mocks.h b/cpp/test/mocks.h index cc761802..3fefdb40 100644 --- a/cpp/test/mocks.h +++ b/cpp/test/mocks.h @@ -53,7 +53,6 @@ public: MOCK_METHOD(void, SetENB, (bool), (override)); MOCK_METHOD(uint8_t, GetDAT, (), (override)); MOCK_METHOD(void, SetDAT, (uint8_t), (override)); - MOCK_METHOD(bool, GetDP, (), (const override)); MOCK_METHOD(uint32_t, Acquire, (), (override)); MOCK_METHOD(int, CommandHandShake, (vector&), (override)); MOCK_METHOD(int, ReceiveHandShake, (uint8_t *, int), (override)); @@ -61,13 +60,11 @@ public: MOCK_METHOD(bool, GetSignal, (int), (const override)); MOCK_METHOD(void, SetSignal, (int, bool), (override)); MOCK_METHOD(bool, PollSelectEvent, (), (override)); - MOCK_METHOD(void, ClearSelectEvent, (), (override)); MOCK_METHOD(unique_ptr, GetSample, (uint64_t), (override)); MOCK_METHOD(void, PinConfig, (int, int), (override)); MOCK_METHOD(void, PullConfig, (int , int ), (override)); MOCK_METHOD(void, SetControl, (int , bool ), (override)); MOCK_METHOD(void, SetMode, (int , int ), (override)); - MOCK_METHOD(int, GetMode, (int ), (override)); MockBus() = default; ~MockBus() override = default; From 98f9292690da50e866cf6ec901334a19c2716c58 Mon Sep 17 00:00:00 2001 From: Uwe Seimet <48174652+uweseimet@users.noreply.github.com> Date: Tue, 14 Nov 2023 16:13:14 +0100 Subject: [PATCH 06/11] NetBSD compatibility: Increase daynaport minimum packet size to 128 bytes (#1334) (#1335) * NetBSD compatibility: Increase daynaport minimum packet size to 128 bytes --- cpp/devices/scsi_daynaport.cpp | 17 ++++++++++------- cpp/devices/scsi_daynaport.h | 1 + 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/cpp/devices/scsi_daynaport.cpp b/cpp/devices/scsi_daynaport.cpp index 0629ccae..7c1c390f 100644 --- a/cpp/devices/scsi_daynaport.cpp +++ b/cpp/devices/scsi_daynaport.cpp @@ -6,6 +6,7 @@ // Copyright (C) 2020 akuker // Copyright (C) 2014-2020 GIMONS // Copyright (C) 2001-2006 PI.(ytanaka@ipc-tokai.or.jp) +// Copyright (C) 2023 Uwe Seimet // // Licensed under the BSD 3-Clause License. // See LICENSE file in the project root folder. @@ -212,13 +213,15 @@ int SCSIDaynaPort::Read(cdb_t cdb, vector& buf, uint64_t) // response->flags = e_no_more_data; // } int size = rx_packet_size; - if (size < 64) { - // A frame must have at least 64 bytes (see https://github.com/PiSCSI/piscsi/issues/619) - // Note that this work-around breaks the checksum. As currently there are no known drivers - // that care for the checksum, and the Daynaport driver for the Atari expects frames of - // 64 bytes it was decided to accept the broken checksum. If a driver should pop up that - // breaks because of this, the work-around has to be re-evaluated. - size = 64; + if (size < 128) { + // A frame must have at least 64 bytes for the Atari driver, see https://github.com/PiSCSI/piscsi/issues/619, + // but also works with 128 bytes. + // The NetBSD driver requires at least 128 bytes, see https://github.com/PiSCSI/piscsi/issues/1098. + // The Mac driver is also fine with 128 bytes. + // Note that this work-around breaks the checksum. As currently there are no known drivers + // that care for the checksum it was decided to accept the broken checksum. + // If a driver should pop up that breaks because of this, the work-around has to be re-evaluated. + size = 128; } SetInt16(buf, 0, size); SetInt32(buf, 2, tap.HasPendingPackets() ? 0x10 : 0x00); diff --git a/cpp/devices/scsi_daynaport.h b/cpp/devices/scsi_daynaport.h index 94f45551..6074e081 100644 --- a/cpp/devices/scsi_daynaport.h +++ b/cpp/devices/scsi_daynaport.h @@ -6,6 +6,7 @@ // Copyright (C) 2020 akuker // Copyright (C) 2014-2020 GIMONS // Copyright (C) 2001-2006 PI.(ytanaka@ipc-tokai.or.jp) +// Copyright (C) 2023 Uwe Seimet // // Licensed under the BSD 3-Clause License. // See LICENSE file in the project root folder. From 28abbb503428ce6f640719603871b57334ab8915 Mon Sep 17 00:00:00 2001 From: Uwe Seimet <48174652+uweseimet@users.noreply.github.com> Date: Wed, 15 Nov 2023 07:36:07 +0100 Subject: [PATCH 07/11] Temporary fix for compiler issue (#1359) * Fix bookworm compiler issue * fix to Docker for workaround --------- Co-authored-by: Benjamin Krein --- cpp/piscsi/piscsi_response.h | 2 +- docker/backend/Dockerfile | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/cpp/piscsi/piscsi_response.h b/cpp/piscsi/piscsi_response.h index 0015655c..a4ab0331 100644 --- a/cpp/piscsi/piscsi_response.h +++ b/cpp/piscsi/piscsi_response.h @@ -25,7 +25,7 @@ class PiscsiResponse { public: - PiscsiResponse() = default; + PiscsiResponse() { } ~PiscsiResponse() = default; bool GetImageFile(PbImageFile&, const string&, const string&) const; diff --git a/docker/backend/Dockerfile b/docker/backend/Dockerfile index 0326aa2b..e86a1c5d 100644 --- a/docker/backend/Dockerfile +++ b/docker/backend/Dockerfile @@ -18,7 +18,7 @@ FROM debian:bullseye-slim AS runner USER root WORKDIR /home/pi -COPY --from=build /home/pi/piscsi/cpp/bin/fullspec/* /usr/local/bin/ +COPY --from=build /home/pi/piscsi/cpp/bin/* /usr/local/bin/ COPY docker/backend/piscsi_wrapper.sh /usr/local/bin/piscsi_wrapper.sh RUN chmod +x /usr/local/bin/* RUN mkdir -p /home/pi/images From ec9f83f9df60e768bfc0ffb026d9c969d252f1fa Mon Sep 17 00:00:00 2001 From: Uwe Seimet <48174652+uweseimet@users.noreply.github.com> Date: Wed, 15 Nov 2023 07:44:46 +0100 Subject: [PATCH 08/11] Improve performance when reading sectors (#1344) --- cpp/hal/gpiobus_raspberry.cpp | 27 ++++++++------------------- 1 file changed, 8 insertions(+), 19 deletions(-) diff --git a/cpp/hal/gpiobus_raspberry.cpp b/cpp/hal/gpiobus_raspberry.cpp index 030413fd..03bb9640 100644 --- a/cpp/hal/gpiobus_raspberry.cpp +++ b/cpp/hal/gpiobus_raspberry.cpp @@ -606,42 +606,31 @@ uint8_t GPIOBUS_Raspberry::GetDAT() return (uint8_t)data; } -//--------------------------------------------------------------------------- -// -// Set data signals -// -//--------------------------------------------------------------------------- void GPIOBUS_Raspberry::SetDAT(uint8_t dat) { - // Write to port + // Write to ports #if SIGNAL_CONTROL_MODE == 0 uint32_t fsel = gpfsel[0]; fsel &= tblDatMsk[0][dat]; fsel |= tblDatSet[0][dat]; - if (fsel != gpfsel[0]) { - gpfsel[0] = fsel; - gpio[GPIO_FSEL_0] = fsel; - } + gpfsel[0] = fsel; + gpio[GPIO_FSEL_0] = fsel; fsel = gpfsel[1]; fsel &= tblDatMsk[1][dat]; fsel |= tblDatSet[1][dat]; - if (fsel != gpfsel[1]) { - gpfsel[1] = fsel; - gpio[GPIO_FSEL_1] = fsel; - } + gpfsel[1] = fsel; + gpio[GPIO_FSEL_1] = fsel; fsel = gpfsel[2]; fsel &= tblDatMsk[2][dat]; fsel |= tblDatSet[2][dat]; - if (fsel != gpfsel[2]) { - gpfsel[2] = fsel; - gpio[GPIO_FSEL_2] = fsel; - } + gpfsel[2] = fsel; + gpio[GPIO_FSEL_2] = fsel; #else gpio[GPIO_CLR_0] = tblDatMsk[dat]; gpio[GPIO_SET_0] = tblDatSet[dat]; -#endif // SIGNAL_CONTROL_MODE +#endif } //--------------------------------------------------------------------------- From 70bcb78d2467ef7a22388908ecca3ce52d329508 Mon Sep 17 00:00:00 2001 From: Uwe Seimet <48174652+uweseimet@users.noreply.github.com> Date: Wed, 15 Nov 2023 07:51:21 +0100 Subject: [PATCH 09/11] Use a standard timer for the DaynaPort delay work-around (#1357) * Do not use the proprietary system timer for the DaynaPort delay work-around --- cpp/hal/bus.h | 2 +- cpp/hal/gpiobus.cpp | 9 ++++++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/cpp/hal/bus.h b/cpp/hal/bus.h index 17a1a805..506cebf3 100644 --- a/cpp/hal/bus.h +++ b/cpp/hal/bus.h @@ -54,7 +54,7 @@ const static int SCSI_DELAY_FAST_NEGATION_PERIOD_NS = 30; // The DaynaPort SCSI Link do a short delay in the middle of transfering // a packet. This is the number of uS that will be delayed between the // header and the actual data. -const static int SCSI_DELAY_SEND_DATA_DAYNAPORT_US = 100; +const static int SCSI_DELAY_SEND_DATA_DAYNAPORT_NS = 100'000; class bus_exception : public runtime_error diff --git a/cpp/hal/gpiobus.cpp b/cpp/hal/gpiobus.cpp index 397ed9cf..f0dc9cf5 100644 --- a/cpp/hal/gpiobus.cpp +++ b/cpp/hal/gpiobus.cpp @@ -15,7 +15,7 @@ #include #include #include -#include +#include #ifdef __linux__ #include #endif @@ -278,9 +278,12 @@ int GPIOBUS::SendHandShake(uint8_t *buf, int count, int delay_after_bytes) if (actmode == mode_e::TARGET) { for (i = 0; i < count; i++) { if (i == delay_after_bytes) { - spdlog::trace("DELAYING for " + to_string(SCSI_DELAY_SEND_DATA_DAYNAPORT_US) + " us after " + + spdlog::trace("DELAYING for " + to_string(SCSI_DELAY_SEND_DATA_DAYNAPORT_NS) + " ns after " + to_string(delay_after_bytes) + " bytes"); - SysTimer::SleepUsec(SCSI_DELAY_SEND_DATA_DAYNAPORT_US); + EnableIRQ(); + const timespec ts = { .tv_sec = 0, .tv_nsec = SCSI_DELAY_SEND_DATA_DAYNAPORT_NS}; + nanosleep(&ts, nullptr); + DisableIRQ(); } // Set the DATA signals From bb602040e2fd846da0ccde9a7df48fd48e1a8bd7 Mon Sep 17 00:00:00 2001 From: Uwe Seimet <48174652+uweseimet@users.noreply.github.com> Date: Thu, 16 Nov 2023 12:37:50 +0100 Subject: [PATCH 10/11] Improve BSD compile-time compatibility (#1342) --- cpp/hal/sbc_version.cpp | 2 +- cpp/piscsi/piscsi_service.cpp | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/cpp/hal/sbc_version.cpp b/cpp/hal/sbc_version.cpp index caebbedf..cd334ad3 100644 --- a/cpp/hal/sbc_version.cpp +++ b/cpp/hal/sbc_version.cpp @@ -144,7 +144,7 @@ uint32_t SBC_Version::GetPeripheralAddress(void) return address; } -#elif defined __NetBSD__ +#elif defined __NetBSD__ && (!defined(__x86_64__) || defined(__X86__)) uint32_t SBC_Version::GetPeripheralAddress(void) { char buf[1024]; diff --git a/cpp/piscsi/piscsi_service.cpp b/cpp/piscsi/piscsi_service.cpp index 4f842def..90f60774 100644 --- a/cpp/piscsi/piscsi_service.cpp +++ b/cpp/piscsi/piscsi_service.cpp @@ -42,7 +42,8 @@ string PiscsiService::Init(const callback& cb, int port) server.sin_family = PF_INET; server.sin_port = htons((uint16_t)port); server.sin_addr.s_addr = INADDR_ANY; - if (bind(service_socket, reinterpret_cast(&server), sizeof(sockaddr_in)) < 0) { //NOSONAR bit_cast is not supported by the bullseye compiler + if (bind(service_socket, reinterpret_cast(&server), //NOSONAR bit_cast is not supported by the bullseye compiler + static_cast(sizeof(sockaddr_in))) < 0) { Stop(); return "Port " + to_string(port) + " is in use, is piscsi already running?"; } From a7c71e4fbbfcaf3b370187ae23fef8c33f2058f1 Mon Sep 17 00:00:00 2001 From: Uwe Seimet <48174652+uweseimet@users.noreply.github.com> Date: Thu, 16 Nov 2023 12:40:10 +0100 Subject: [PATCH 11/11] Replace system timer by C++ standard time for timeout of 3 s (#1361) --- cpp/piscsi/piscsi_core.cpp | 28 +++++++++++++--------------- 1 file changed, 13 insertions(+), 15 deletions(-) diff --git a/cpp/piscsi/piscsi_core.cpp b/cpp/piscsi/piscsi_core.cpp index bd491b8c..2b2f6385 100644 --- a/cpp/piscsi/piscsi_core.cpp +++ b/cpp/piscsi/piscsi_core.cpp @@ -20,7 +20,6 @@ #include "devices/storage_device.h" #include "hal/gpiobus_factory.h" #include "hal/gpiobus.h" -#include "hal/systimer.h" #include "piscsi/piscsi_core.h" #include #include @@ -29,6 +28,7 @@ #include #include #include +#include using namespace std; using namespace filesystem; @@ -684,21 +684,19 @@ bool Piscsi::ShutDown(AbstractController::piscsi_shutdown_mode shutdown_mode) bool Piscsi::IsNotBusy() const { // Wait until BSY is released as there is a possibility for the - // initiator to assert it while setting the ID (for up to 3 seconds) - if (bus->GetBSY()) { - const uint32_t now = SysTimer::GetTimerLow(); + // initiator to assert it while setting the ID (for up to 3 seconds) + if (bus->GetBSY()) { + const auto now = chrono::steady_clock::now(); + while ((chrono::duration_cast(chrono::steady_clock::now() - now).count()) < 3) { + bus->Acquire(); - // Wait for 3s - while ((SysTimer::GetTimerLow() - now) < 3'000'000) { - bus->Acquire(); + if (!bus->GetBSY()) { + return true; + } + } - if (!bus->GetBSY()) { - return true; - } - } + return false; + } - return false; - } - - return true; + return true; }