Skip to content

Commit

Permalink
Replace USE_SEL_EVENT_ENABLE by __linux__
Browse files Browse the repository at this point in the history
  • Loading branch information
uweseimet committed Feb 1, 2024
1 parent 5b37ab2 commit 7c8ee8b
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 62 deletions.
56 changes: 3 additions & 53 deletions cpp/buses/rpi_bus.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ bool RpiBus::Init(bool target)
gpfsel[3] = gpio[GPIO_FSEL_3];

// Initialize SEL signal interrupt
#ifdef USE_SEL_EVENT_ENABLE
#ifdef __linux__
fd = open("/dev/gpiochip0", 0);
if (fd == -1) {
error("Unable to open /dev/gpiochip0. If s2p is running, please shut it down first.");
Expand Down Expand Up @@ -182,56 +182,6 @@ bool RpiBus::Init(bool target)
ev.events = EPOLLIN | EPOLLPRI;
ev.data.fd = selevreq.fd;
epoll_ctl(epfd, EPOLL_CTL_ADD, selevreq.fd, &ev);
#else
// Edge detection setting
#if SIGNAL_CONTROL_MODE == 2
gpio[GPIO_AREN_0] = 1 << PIN_SEL;
#else
gpio[GPIO_AFEN_0] = 1 << PIN_SEL;
#endif

// Clear event - GPIO Pin Event Detect Status
gpio[GPIO_EDS_0] = 1 << PIN_SEL;

#ifdef __linux__
// Register interrupt handler
setIrqFuncAddress(IrqHandler);
#endif

// GPIO interrupt setting
if (pi_type == 4) {
// GIC Invalid
gicd[GICD_CTLR] = 0;

// Route all interupts to core 0
for (int i = 0; i < 8; i++) {
gicd[GICD_ICENABLER0 + i] = 0xffffffff;
gicd[GICD_ICPENDR0 + i] = 0xffffffff;
gicd[GICD_ICACTIVER0 + i] = 0xffffffff;
}
for (int i = 0; i < 64; i++) {
gicd[GICD_IPRIORITYR0 + i] = 0xa0a0a0a0;
gicd[GICD_ITARGETSR0 + i] = 0x01010101;
}

// Set all interrupts as level triggers
for (int i = 0; i < 16; i++) {
gicd[GICD_ICFGR0 + i] = 0;
}

// GIC Invalid
gicd[GICD_CTLR] = 1;

// Enable CPU interface for core 0
gicc[GICC_PMR] = 0xf0;
gicc[GICC_CTLR] = 1;

// Enable interrupts
gicd[GICD_ISENABLER0 + (GIC_GPIO_IRQ / 32)] = 1 << (GIC_GPIO_IRQ % 32);
} else {
// Enable interrupts
irpctl[IRPT_ENB_IRQ_2] = (1 << (GPIO_IRQ % 32));
}
#endif

// Create work table
Expand All @@ -247,7 +197,7 @@ bool RpiBus::Init(bool target)
void RpiBus::CleanUp()
{
// Release SEL signal interrupt
#ifdef USE_SEL_EVENT_ENABLE
#ifdef __linux__
close(selevreq.fd);
#endif

Expand Down Expand Up @@ -335,7 +285,7 @@ void RpiBus::Reset()

bool RpiBus::WaitForSelection()
{
#ifndef USE_SEL_EVENT_ENABLE
#ifndef __linux__
Acquire();
if (!GetSEL()) {
const timespec ts = { .tv_sec = 0, .tv_nsec = 0};
Expand Down
10 changes: 1 addition & 9 deletions cpp/buses/rpi_bus.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,6 @@

#pragma once

// Configurable settings
#ifdef __linux__
// Check SEL signal by event instead of polling
#define USE_SEL_EVENT_ENABLE
#endif

// Not having to disable IRQs would ease porting to Pis which other interrupt hardware like maybe the Pi 5.
// Currently IRQs are disabled in target mode but enabled in initiator mode.
//#define NO_IRQ_DISABLE
Expand All @@ -26,8 +20,6 @@

#ifdef __linux__
#include <linux/gpio.h>
#endif
#ifdef USE_SEL_EVENT_ENABLE
#include <sys/epoll.h>
#endif
#include "gpio_bus.h"
Expand Down Expand Up @@ -157,7 +149,7 @@ class RpiBus : public GpioBus
// GPIO input level
volatile uint32_t *level = nullptr;

#ifdef USE_SEL_EVENT_ENABLE
#ifdef __linux__
// SEL signal event request
struct gpioevent_request selevreq = { };
// epoll file descriptor
Expand Down

0 comments on commit 7c8ee8b

Please sign in to comment.