Skip to content

Commit

Permalink
Further reduce Pi dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
uweseimet committed Jan 22, 2025
1 parent 5f6b4f1 commit b90396f
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 18 deletions.
5 changes: 4 additions & 1 deletion cpp/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,10 @@ SRC_SHARED_PROTOBUF := $(wildcard $(DIR_SHARED_PROTOBUF)/*.cpp)
SRC_SHARED_COMMAND := $(wildcard $(DIR_SHARED_COMMAND)/*.cpp)
SRC_SHARED_INITIATOR := $(wildcard $(DIR_SHARED_INITIATOR)/*.cpp)
SRC_BASE = $(wildcard $(DIR_BASE)/*.cpp)
SRC_BUSES = $(wildcard $(DIR_BUSES)/*.cpp)
SRC_BUSES = $(shell ls -1 $(DIR_BUSES)/*.cpp | grep -v rpi_bus.cpp)
ifdef IS_LINUX
SRC_BUSES += $(DIR_BUSES)/rpi_bus.cpp
endif
SRC_CONTROLLERS = $(wildcard $(DIR_CONTROLLERS)/*.cpp)

SRC_DISK = \
Expand Down
4 changes: 4 additions & 0 deletions cpp/buses/bus_factory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@

#include "bus_factory.h"
#include "in_process_bus.h"
#ifdef __linux__
#include "rpi_bus.h"
#endif

using namespace spdlog;

Expand All @@ -19,9 +21,11 @@ unique_ptr<Bus> BusFactory::CreateBus(bool target, bool in_process, const string
if (in_process) {
bus = make_unique<DelegatingInProcessBus>(InProcessBus::Instance(), identifier, log_signals);
}
#ifdef __linux__
else if (const auto pi_type = RpiBus::CheckForPi(); pi_type != RpiBus::PiType::UNKNOWN) {
bus = make_unique<RpiBus>(pi_type);
}
#endif
else {
bus = make_unique<DelegatingInProcessBus>(InProcessBus::Instance(), identifier, false);
}
Expand Down
12 changes: 0 additions & 12 deletions cpp/buses/rpi_bus.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,6 @@ bool RpiBus::Init(bool target)
return false;
}

#ifdef __linux__
// Event request setting
strcpy(selevreq.consumer_label, "SCSI2Pi"); // NOSONAR Using strcpy is safe
selevreq.lineoffset = PIN_SEL;
Expand All @@ -169,7 +168,6 @@ bool RpiBus::Init(bool target)
ev.events = EPOLLIN | EPOLLPRI;
ev.data.fd = selevreq.fd;
epoll_ctl(epoll_fd, EPOLL_CTL_ADD, selevreq.fd, &ev);
#endif

CreateWorkTable();

Expand All @@ -182,9 +180,7 @@ bool RpiBus::Init(bool target)
void RpiBus::CleanUp()
{
// Release SEL signal interrupt
#ifdef __linux__
close(selevreq.fd);
#endif

// Set control signals
PinSetSignal(PIN_ENB, false);
Expand Down Expand Up @@ -238,9 +234,6 @@ void RpiBus::Reset()

bool RpiBus::WaitForSelection()
{
#ifndef __linux__
return false;
#else
if (epoll_event epev; epoll_wait(epoll_fd, &epev, 1, -1) == -1) {
if (errno != EINTR) {
warn("epoll_wait failed: {}", strerror(errno));
Expand All @@ -254,7 +247,6 @@ bool RpiBus::WaitForSelection()
}
return false;
}
#endif

Acquire();

Expand Down Expand Up @@ -449,7 +441,6 @@ void RpiBus::SetSignal(int pin, bool state)

void RpiBus::DisableIRQ()
{
#ifdef __linux__
switch (pi_type) {
case PiType::PI_1:
// Stop system timer interrupt with interrupt controller
Expand All @@ -474,12 +465,10 @@ void RpiBus::DisableIRQ()
// Currently do nothing
break;
}
#endif
}

void RpiBus::EnableIRQ()
{
#ifdef __linux__
switch (pi_type) {
case PiType::PI_1:
// Restart the system timer interrupt with the interrupt controller
Expand All @@ -501,7 +490,6 @@ void RpiBus::EnableIRQ()
// Currently do nothing
break;
}
#endif
}

//---------------------------------------------------------------------------
Expand Down
6 changes: 1 addition & 5 deletions cpp/buses/rpi_bus.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,14 @@
// SCSI2Pi, SCSI device emulator and SCSI tools for the Raspberry Pi
//
// Copyright (C) 2016-2020 GIMONS
// Copyright (C) 2023-2024 Uwe Seimet
// Copyright (C) 2023-2025 Uwe Seimet
//
//---------------------------------------------------------------------------

#pragma once

#ifdef __linux__
#include <linux/gpio.h>
#include <sys/epoll.h>
#endif
#include "bus.h"

class RpiBus final : public Bus
Expand Down Expand Up @@ -110,7 +108,6 @@ class RpiBus final : public Bus
// QA7 register
volatile uint32_t *qa7_regs = nullptr;

#ifdef __linux__
// Interrupt enabled state
uint32_t irpt_enb;

Expand All @@ -126,7 +123,6 @@ class RpiBus final : public Bus
struct gpioevent_request selevreq = { };

int epoll_fd = 0;
#endif

// GIC CPU interface register
volatile uint32_t *gicc_mpr = nullptr;
Expand Down

0 comments on commit b90396f

Please sign in to comment.