From 60a7455a9d05396d3ca4277c4b4d6757d06f5fc4 Mon Sep 17 00:00:00 2001 From: mstroh76 Date: Sun, 10 Nov 2024 19:02:13 +0100 Subject: [PATCH 1/4] #294 --- VERSION | 2 +- version.h | 4 +-- wiringPi/wiringPi.c | 70 +++++++++++++++++++++++++++++++++++++++++---- 3 files changed, 68 insertions(+), 8 deletions(-) diff --git a/VERSION b/VERSION index c8cfe39..2c07333 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -3.10 +3.11 diff --git a/version.h b/version.h index 8ef452a..3aef435 100644 --- a/version.h +++ b/version.h @@ -1,3 +1,3 @@ -#define VERSION "3.10" +#define VERSION "3.11" #define VERSION_MAJOR 3 -#define VERSION_MINOR 10 +#define VERSION_MINOR 11 diff --git a/wiringPi/wiringPi.c b/wiringPi/wiringPi.c index bc00369..31dbdb7 100644 --- a/wiringPi/wiringPi.c +++ b/wiringPi/wiringPi.c @@ -73,6 +73,7 @@ #include #include #include +#include #include "softPwm.h" #include "softTone.h" @@ -222,13 +223,19 @@ const char* gpiomem_global = "/dev/mem"; const char* gpiomem_BCM = "/dev/gpiomem"; const char* gpiomem_RP1 = "/dev/gpiomem0"; const int gpiomem_RP1_Size = 0x00030000; -// PCIe Memory access, static define - maybe needed to detect in future +// PCIe memory access, need to detect path / PCIe address //dmesg: rp1 0000:01:00.0: bar1 len 0x400000, start 0x1f00000000, end 0x1f003fffff, flags, 0x40200 -const char* pciemem_RP1_path = "/sys/bus/pci/devices/0000:01:00.0"; -const char* pciemem_RP1 = "/sys/bus/pci/devices/0000:01:00.0/resource1"; +const char* pcie_path = "/sys/bus/pci/devices"; +//const char* pciemem_RP1_path = "/sys/bus/pci/devices/0000:01:00.0"; +//const char* pciemem_RP1 = "/sys/bus/pci/devices/0000:01:00.0/resource1"; +char pciemem_RP1[512] = { '\0' }; +const char* pciemem_RP1_bar = "resource1"; const int pciemem_RP1_Size = 0x00400000; -const unsigned short pciemem_RP1_Ventor= 0x1de4; -const unsigned short pciemem_RP1_Device= 0x0001; +//const unsigned short pciemem_RP1_Ventor= 0x1de4; +//const unsigned short pciemem_RP1_Device= 0x0001; +const char* pciemem_RP1_Ventor= "0x1de4"; +const char* pciemem_RP1_Device= "0x0001"; + static volatile unsigned int GPIO_PADS ; static volatile unsigned int GPIO_CLOCK_ADR ; @@ -2992,6 +2999,57 @@ int wiringPiUserLevelAccess(void) } +int CheckPCIeFileContent(const char* pcieaddress, const char* filename, const char* content) { + char file_path[512]; + int Found = 0; + + snprintf(file_path, sizeof(file_path), "%s/%s/%s", pcie_path, pcieaddress, filename); + printf("Open file: %s\n", file_path); + FILE *device_file = fopen(file_path, "r"); + if (device_file != NULL) { + char buffer[64]; + if (fgets(buffer, sizeof(buffer), device_file) != NULL) { + printf(" %s: %s", filename, buffer); + if (strstr(buffer, content) != NULL) { + Found = 1; + printf(" >> correct\n"); + } else { + printf(" >> wrong\n"); + } + } + fclose(device_file); + } else { + perror("fopen"); + } + return Found; +} + + +void GetRP1Memory() { + + pciemem_RP1[0] = '\0'; + DIR *dir = opendir(pcie_path); + struct dirent *entry; + + if (dir == NULL) { + perror("opendir"); + return; + } + while ((entry = readdir(dir)) != NULL) { + if (entry->d_type == DT_LNK) { + if (CheckPCIeFileContent(entry->d_name, "device", pciemem_RP1_Device) && + CheckPCIeFileContent(entry->d_name, "vendor", pciemem_RP1_Ventor)) { + snprintf(pciemem_RP1, sizeof(pciemem_RP1), "%s/%s/%s", pcie_path, entry->d_name, pciemem_RP1_bar); + printf("RP1 device memory found at '%s'\n", pciemem_RP1); + break; + } + } + } + + closedir(dir); +} + + int wiringPiGlobalMemoryAccess(void) { const char* gpiomemGlobal; @@ -3001,6 +3059,7 @@ int wiringPiGlobalMemoryAccess(void) piBoard(); if (PI_MODEL_5 == RaspberryPiModel) { + GetRP1Memory(pciemem_RP1, sizeof(pciemem_RP1)); gpiomemGlobal = pciemem_RP1; MMAP_size = pciemem_RP1_Size; BaseAddr = 0x00000000; @@ -3109,6 +3168,7 @@ int wiringPiSetup (void) const char* gpiomemModule = gpiomem_BCM; if (PI_MODEL_5 == model) { + GetRP1Memory(); gpiomemGlobal = pciemem_RP1; gpiomemModule = gpiomem_RP1; From 6bb7ef9fc3ce955465bfeeed6c53145cc993ae00 Mon Sep 17 00:00:00 2001 From: mstroh76 Date: Sun, 5 Jan 2025 10:45:22 +0100 Subject: [PATCH 2/4] Year to 2025 --- gpio/gpio.1 | 2 +- gpio/gpio.c | 6 +++--- wiringPi/test/Makefile | 6 +++--- .../{wiringpi_test7_version.c => wiringpi_test0_version.c} | 0 wiringPi/wiringPi.c | 2 +- 5 files changed, 8 insertions(+), 8 deletions(-) rename wiringPi/test/{wiringpi_test7_version.c => wiringpi_test0_version.c} (100%) diff --git a/gpio/gpio.1 b/gpio/gpio.1 index bf5864a..4d76671 100644 --- a/gpio/gpio.1 +++ b/gpio/gpio.1 @@ -282,7 +282,7 @@ Please report bugs to https://github.com/WiringPi/WiringPi/issues .SH COPYRIGHT -Copyright (c) 2012-2024 Gordon Henderson and contributors +Copyright (c) 2012-2025 Gordon Henderson and contributors .br This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. diff --git a/gpio/gpio.c b/gpio/gpio.c index a563b24..3fc97a3 100644 --- a/gpio/gpio.c +++ b/gpio/gpio.c @@ -2,7 +2,7 @@ * gpio.c: * Swiss-Army-Knife, Set-UID command-line interface to the Raspberry * Pi's GPIO. - * Copyright (c) 2012-2024 Gordon Henderson and contributors + * Copyright (c) 2012-2025 Gordon Henderson and contributors *********************************************************************** * This file is part of wiringPi: * https://github.com/WiringPi/WiringPi/ @@ -842,7 +842,7 @@ static void doVersion (char *argv []) wiringPiVersion (&vMaj, &vMin) ; printf ("gpio version: %d.%d\n", vMaj, vMin) ; - printf ("Copyright (c) 2012-2024 Gordon Henderson and contributors\n") ; + printf ("Copyright (c) 2012-2025 Gordon Henderson and contributors\n") ; printf ("This is free software with ABSOLUTELY NO WARRANTY.\n") ; printf ("For details type: %s -warranty\n", argv [0]) ; printf ("\n") ; @@ -955,7 +955,7 @@ int main (int argc, char *argv []) if (strcasecmp (argv [1], "-warranty") == 0) { printf ("gpio version: %s\n", VERSION) ; - printf ("Copyright (c) 2012-2024 Gordon Henderson and contributors\n") ; + printf ("Copyright (c) 2012-2025 Gordon Henderson and contributors\n") ; printf ("\n") ; printf (" This program is free software; you can redistribute it and/or modify\n") ; printf (" it under the terms of the GNU Leser General Public License as published\n") ; diff --git a/wiringPi/test/Makefile b/wiringPi/test/Makefile index 7c379a7..bb87910 100644 --- a/wiringPi/test/Makefile +++ b/wiringPi/test/Makefile @@ -3,7 +3,7 @@ CFLAGS = -Wall LDFLAGS = # Need BCM19 <-> BCM26, +PWM: BCM12 <-> BCM13, BCM18 <-> BCM17 connected (1kOhm) -tests = wiringpi_test1_sysfs wiringpi_test2_sysfs wiringpi_test3_device_wpi wiringpi_test4_device_phys wiringpi_test5_default wiringpi_test6_isr wiringpi_test7_version wiringpi_test8_pwm wiringpi_test9_pwm +tests = wiringpi_test0_version wiringpi_test1_sysfs wiringpi_test2_sysfs wiringpi_test3_device_wpi wiringpi_test4_device_phys wiringpi_test5_default wiringpi_test6_isr wiringpi_test8_pwm wiringpi_test9_pwm # Need XO hardware xotests = wiringpi_xotest_test1_spi wiringpi_i2c_test1_pcf8574 wiringpi_test8_pwm wiringpi_test9_pwm @@ -31,8 +31,8 @@ wiringpi_test5_default: wiringpi_test6_isr: ${CC} ${CFLAGS} wiringpi_test6_isr.c -o wiringpi_test6_isr -lwiringPi -wiringpi_test7_version: - ${CC} ${CFLAGS} wiringpi_test7_version.c -o wiringpi_test7_version -lwiringPi +wiringpi_test0_version: + ${CC} ${CFLAGS} wiringpi_test0_version.c -o wiringpi_test0_version -lwiringPi wiringpi_test8_pwm: ${CC} ${CFLAGS} wiringpi_test8_pwm.c -o wiringpi_test8_pwm -lwiringPi diff --git a/wiringPi/test/wiringpi_test7_version.c b/wiringPi/test/wiringpi_test0_version.c similarity index 100% rename from wiringPi/test/wiringpi_test7_version.c rename to wiringPi/test/wiringpi_test0_version.c diff --git a/wiringPi/wiringPi.c b/wiringPi/wiringPi.c index 31dbdb7..1267081 100644 --- a/wiringPi/wiringPi.c +++ b/wiringPi/wiringPi.c @@ -1,7 +1,7 @@ /* * wiringPi: * Arduino look-a-like Wiring library for the Raspberry Pi - * Copyright (c) 2012-2024 Gordon Henderson and contributors + * Copyright (c) 2012-2025 Gordon Henderson and contributors * Additional code for pwmSetClock by Chris Hall * * Thanks to code samples from Gert Jan van Loo and the From 3f3c8d186720036560ce1c9139ce2ff9142b4dfb Mon Sep 17 00:00:00 2001 From: mstroh76 Date: Sun, 5 Jan 2025 12:41:03 +0100 Subject: [PATCH 3/4] #294 output rp1 scan only if debug is activated --- wiringPi/wiringPi.c | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/wiringPi/wiringPi.c b/wiringPi/wiringPi.c index 1267081..50d20fe 100644 --- a/wiringPi/wiringPi.c +++ b/wiringPi/wiringPi.c @@ -3004,22 +3004,22 @@ int CheckPCIeFileContent(const char* pcieaddress, const char* filename, const ch int Found = 0; snprintf(file_path, sizeof(file_path), "%s/%s/%s", pcie_path, pcieaddress, filename); - printf("Open file: %s\n", file_path); + if (wiringPiDebug) { printf("Open: %s ->", file_path); } FILE *device_file = fopen(file_path, "r"); if (device_file != NULL) { - char buffer[64]; - if (fgets(buffer, sizeof(buffer), device_file) != NULL) { - printf(" %s: %s", filename, buffer); - if (strstr(buffer, content) != NULL) { - Found = 1; - printf(" >> correct\n"); - } else { - printf(" >> wrong\n"); - } + char buffer[64]; + if (fgets(buffer, sizeof(buffer), device_file) != NULL) { + if (wiringPiDebug) { printf(" %s", buffer); } + if (strstr(buffer, content) != NULL) { + Found = 1; + if (wiringPiDebug) { printf(" >> correct\n"); } + } else { + if (wiringPiDebug) { printf(" >> wrong\n"); } } - fclose(device_file); + } + fclose(device_file); } else { - perror("fopen"); + if (wiringPiDebug) { perror("fopen"); }; } return Found; } @@ -3032,7 +3032,7 @@ void GetRP1Memory() { struct dirent *entry; if (dir == NULL) { - perror("opendir"); + if (wiringPiDebug) { perror("opendir"); }; return; } while ((entry = readdir(dir)) != NULL) { @@ -3040,7 +3040,7 @@ void GetRP1Memory() { if (CheckPCIeFileContent(entry->d_name, "device", pciemem_RP1_Device) && CheckPCIeFileContent(entry->d_name, "vendor", pciemem_RP1_Ventor)) { snprintf(pciemem_RP1, sizeof(pciemem_RP1), "%s/%s/%s", pcie_path, entry->d_name, pciemem_RP1_bar); - printf("RP1 device memory found at '%s'\n", pciemem_RP1); + if (wiringPiDebug) { printf("RP1 device memory found at '%s'\n", pciemem_RP1); } break; } } From c154cbcc1d1a69537c1182ff99c61b80adbb9cf9 Mon Sep 17 00:00:00 2001 From: mstroh76 Date: Sun, 5 Jan 2025 14:52:55 +0100 Subject: [PATCH 4/4] #301 v3.12 --- VERSION | 2 +- version.h | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/VERSION b/VERSION index 2c07333..e4fba21 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -3.11 +3.12 diff --git a/version.h b/version.h index 3aef435..225bee7 100644 --- a/version.h +++ b/version.h @@ -1,3 +1,3 @@ -#define VERSION "3.11" +#define VERSION "3.12" #define VERSION_MAJOR 3 -#define VERSION_MINOR 11 +#define VERSION_MINOR 12