From 29bbd99b0e0dc1f45c815dbd29d015a8ace50808 Mon Sep 17 00:00:00 2001 From: Maurus Erni Date: Tue, 25 Apr 2017 13:50:01 +0200 Subject: [PATCH 1/5] Adding flag to disable alerts (polling of GPIOs) --- pigpio.c | 9 ++++++--- pigpio.h | 1 + pigpiod.c | 4 ++++ 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/pigpio.c b/pigpio.c index 8310e31..fac0daa 100644 --- a/pigpio.c +++ b/pigpio.c @@ -8115,10 +8115,13 @@ int initInitialise(void) if (pthread_attr_setstacksize(&pthAttr, STACK_SIZE)) SOFT_ERROR(PI_INIT_FAILED, "pthread_attr_setstacksize failed (%m)"); - if (pthread_create(&pthAlert, &pthAttr, pthAlertThread, &i)) - SOFT_ERROR(PI_INIT_FAILED, "pthread_create alert failed (%m)"); + if (!(gpioCfg.ifFlags & PI_DISABLE_ALERT)) + { + if (pthread_create(&pthAlert, &pthAttr, pthAlertThread, &i)) + SOFT_ERROR(PI_INIT_FAILED, "pthread_create alert failed (%m)"); - pthAlertRunning = 1; + pthAlertRunning = 1; + } if (!(gpioCfg.ifFlags & PI_DISABLE_FIFO_IF)) { diff --git a/pigpio.h b/pigpio.h index 192006a..cb1d76d 100644 --- a/pigpio.h +++ b/pigpio.h @@ -846,6 +846,7 @@ typedef void *(gpioThreadFunc_t) (void *); #define PI_DISABLE_FIFO_IF 1 #define PI_DISABLE_SOCK_IF 2 #define PI_LOCALHOST_SOCK_IF 4 +#define PI_DISABLE_ALERT 8 /* memAllocMode */ diff --git a/pigpiod.c b/pigpiod.c index 989cf07..8323380 100644 --- a/pigpiod.c +++ b/pigpiod.c @@ -217,6 +217,10 @@ static void initOpts(int argc, char *argv[]) ifFlags |= PI_LOCALHOST_SOCK_IF; break; + case 'm': + ifFlags |= PI_DISABLE_ALERT; + break; + case 'n': addr = checkAddr(optarg); if (addr && (numSockNetAddr Date: Fri, 19 May 2017 10:01:51 +0200 Subject: [PATCH 2/5] Fixing command line arguments for new option -m --- command.c | 2 +- pigpio.3 | 2 +- pigpio.c | 2 +- pigpio.h | 2 +- pigpio.py | 2 +- pigpiod.c | 3 ++- 6 files changed, 7 insertions(+), 6 deletions(-) diff --git a/command.c b/command.c index 82e1c74..573f59f 100644 --- a/command.c +++ b/command.c @@ -442,7 +442,7 @@ static errInfo_t errInfo[]= {PI_BAD_PATHNAME , "can't open pathname"}, {PI_NO_HANDLE , "no handle available"}, {PI_BAD_HANDLE , "unknown handle"}, - {PI_BAD_IF_FLAGS , "ifFlags > 3"}, + {PI_BAD_IF_FLAGS , "ifFlags > 4"}, {PI_BAD_CHANNEL , "DMA channel not 0-14"}, {PI_BAD_SOCKET_PORT , "socket port not 1024-30000"}, {PI_BAD_FIFO_COMMAND , "unknown fifo command"}, diff --git a/pigpio.3 b/pigpio.3 index e33dde6..b866a98 100644 --- a/pigpio.3 +++ b/pigpio.3 @@ -9796,7 +9796,7 @@ A 16-bit word value. .br #define PI_BAD_HANDLE -25 // unknown handle .br -#define PI_BAD_IF_FLAGS -26 // ifFlags > 3 +#define PI_BAD_IF_FLAGS -26 // ifFlags > 4 .br #define PI_BAD_CHANNEL -27 // DMA channel not 0-14 .br diff --git a/pigpio.c b/pigpio.c index fac0daa..7e34f44 100644 --- a/pigpio.c +++ b/pigpio.c @@ -13328,7 +13328,7 @@ int gpioCfgInterfaces(unsigned ifFlags) CHECK_NOT_INITED; - if (ifFlags > 7) + if (ifFlags > 15) SOFT_ERROR(PI_BAD_IF_FLAGS, "bad ifFlags (%X)", ifFlags); gpioCfg.ifFlags = ifFlags; diff --git a/pigpio.h b/pigpio.h index cb1d76d..b8a95bb 100644 --- a/pigpio.h +++ b/pigpio.h @@ -6143,7 +6143,7 @@ after this command is issued. #define PI_BAD_PATHNAME -23 // can't open pathname #define PI_NO_HANDLE -24 // no handle available #define PI_BAD_HANDLE -25 // unknown handle -#define PI_BAD_IF_FLAGS -26 // ifFlags > 3 +#define PI_BAD_IF_FLAGS -26 // ifFlags > 4 #define PI_BAD_CHANNEL -27 // DMA channel not 0-14 #define PI_BAD_PRIM_CHANNEL -27 // DMA primary channel not 0-14 #define PI_BAD_SOCKET_PORT -28 // socket port not 1024-32000 diff --git a/pigpio.py b/pigpio.py index 517943f..bf45e05 100644 --- a/pigpio.py +++ b/pigpio.py @@ -712,7 +712,7 @@ _errors=[ [_PI_BAD_PATHNAME , "can't open pathname"], [PI_NO_HANDLE , "no handle available"], [PI_BAD_HANDLE , "unknown handle"], - [_PI_BAD_IF_FLAGS , "ifFlags > 3"], + [_PI_BAD_IF_FLAGS , "ifFlags > 4"], [_PI_BAD_CHANNEL , "DMA channel not 0-14"], [_PI_BAD_SOCKET_PORT , "socket port not 1024-30000"], [_PI_BAD_FIFO_COMMAND , "unknown fifo command"], diff --git a/pigpiod.c b/pigpiod.c index 8323380..d680b3b 100644 --- a/pigpiod.c +++ b/pigpiod.c @@ -103,6 +103,7 @@ void usage() " -k, disable socket interface, default enabled\n" \ " -l, localhost socket only default local+remote\n" \ " -n IP addr, allow address, name or dotted, default allow all\n" \ + " -m, disable alerts default enabled\n" \ " -p value, socket port, 1024-32000, default 8888\n" \ " -s value, sample rate, 1, 2, 4, 5, 8, or 10, default 5\n" \ " -t value, clock peripheral, 0=PWM 1=PCM, default PCM\n" \ @@ -162,7 +163,7 @@ static void initOpts(int argc, char *argv[]) uint32_t addr; int64_t mask; - while ((opt = getopt(argc, argv, "a:b:c:d:e:fgkln:p:s:t:x:vV")) != -1) + while ((opt = getopt(argc, argv, "a:b:c:d:e:fgkln:mp:s:t:x:vV")) != -1) { switch (opt) { From 32727085fc7fe8c8e0d546201aa317f86efe7e59 Mon Sep 17 00:00:00 2001 From: TheRaspyDev Date: Fri, 19 May 2017 10:14:06 +0200 Subject: [PATCH 3/5] Resolve merge conflict --- pigpio.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/pigpio.c b/pigpio.c index a4391a7..81af8af 100644 --- a/pigpio.c +++ b/pigpio.c @@ -8140,10 +8140,13 @@ int initInitialise(void) if (pthread_attr_setstacksize(&pthAttr, STACK_SIZE)) SOFT_ERROR(PI_INIT_FAILED, "pthread_attr_setstacksize failed (%m)"); - if (pthread_create(&pthAlert, &pthAttr, pthAlertThread, &i)) - SOFT_ERROR(PI_INIT_FAILED, "pthread_create alert failed (%m)"); + if (!(gpioCfg.ifFlags & PI_DISABLE_ALERT)) + { + if (pthread_create(&pthAlert, &pthAttr, pthAlertThread, &i)) + SOFT_ERROR(PI_INIT_FAILED, "pthread_create alert failed (%m)"); - pthAlertRunning = PI_THREAD_STARTED; + pthAlertRunning = PI_THREAD_STARTED; + } if (!(gpioCfg.ifFlags & PI_DISABLE_FIFO_IF)) { From 2c9a00a2f995d760e9685abb43ec584b5a44de5c Mon Sep 17 00:00:00 2001 From: TheRaspyDev Date: Fri, 19 May 2017 10:24:19 +0200 Subject: [PATCH 4/5] Fixing ifFlags check for additional flag --- pigpio.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pigpio.c b/pigpio.c index 81af8af..7c130e5 100644 --- a/pigpio.c +++ b/pigpio.c @@ -13380,7 +13380,7 @@ int gpioCfgInterfaces(unsigned ifFlags) CHECK_NOT_INITED; - if (ifFlags > 7) + if (ifFlags > 15) SOFT_ERROR(PI_BAD_IF_FLAGS, "bad ifFlags (%X)", ifFlags); gpioCfg.ifFlags = ifFlags; From 847c0818467c3ef15bde8cf7c6f6cac979359f69 Mon Sep 17 00:00:00 2001 From: joan Date: Sun, 4 Feb 2018 09:10:22 +0000 Subject: [PATCH 5/5] Changes by tateu --- pigpio.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/pigpio.c b/pigpio.c index 7c130e5..8328d3a 100644 --- a/pigpio.c +++ b/pigpio.c @@ -6292,7 +6292,10 @@ static void * pthAlertThread(void *x) { stickInited = 1; numSamples = 0; - pthAlertRunning = PI_THREAD_RUNNING; + if (!(gpioCfg.ifFlags & PI_DISABLE_ALERT)) + { + pthAlertRunning = PI_THREAD_RUNNING; + } } } } @@ -8474,7 +8477,11 @@ int gpioInitialise(void) runState = PI_RUNNING; - while (pthAlertRunning != PI_THREAD_RUNNING) myGpioDelay(1000); + if (!(gpioCfg.ifFlags & PI_DISABLE_ALERT)) + { + while (pthAlertRunning != PI_THREAD_RUNNING) myGpioDelay(1000); + } + } return status;