V63
authorjoan <joan@abyz.co.uk>
Sat, 13 May 2017 13:22:02 +0000 (14:22 +0100)
committerjoan <joan@abyz.co.uk>
Sat, 13 May 2017 13:22:02 +0000 (14:22 +0100)
17 files changed:
pig2vcd.1
pigpio.3
pigpio.c
pigpio.h
pigpio.py
pigpiod.1
pigpiod_if.3
pigpiod_if.c
pigpiod_if.h
pigpiod_if2.3
pigpiod_if2.c
pigpiod_if2.h
pigs.1
setup.py
x_pigpio.c
x_pigpiod_if.c
x_pigpiod_if2.c

index 24b5a6cd9a216ee35d84dcc08e6a9450792e7a75..b2c64b40271761192e41127e4faa736dce9e1c50 100644 (file)
--- a/pig2vcd.1
+++ b/pig2vcd.1
@@ -2,7 +2,7 @@
 ." Process this file with
 ." groff -man -Tascii pig2vcd.1
 ."
-.TH pig2vcd 1 2012-2015 Linux "pigpio archive"
+.TH pig2vcd 1 2012-2017 Linux "pigpio archive"
 .SH NAME
 pig2vd - A utility to convert pigpio notifications to VCD.
 
index e33dde619de363257dc738902a2bf69318213b9d..b5979ff80307bb2647478a3281aeddd9263b3543 100644 (file)
--- a/pigpio.3
+++ b/pigpio.3
@@ -2,7 +2,7 @@
 ." Process this file with
 ." groff -man -Tascii pigpio.3
 ."
-.TH pigpio 3 2012-2015 Linux "pigpio archive"
+.TH pigpio 3 2012-2017 Linux "pigpio archive"
 .SH NAME
 pigpio - A C library to manipulate the Pi's GPIO.
 
@@ -1049,12 +1049,42 @@ Returns 0 if OK, otherwise PI_BAD_USER_GPIO.
 .br
 
 .br
-One function may be registered per GPIO.
+One callback may be registered per GPIO.
+
+.br
+
+.br
+The callback is passed the GPIO, the new level, and the tick.
+
+.br
+
+.br
 
+.EX
+Parameter   Value    Meaning
 .br
 
 .br
-The function is passed the GPIO, the new level, and the tick.
+GPIO        0-31     The GPIO which has changed state
+.br
+
+.br
+level       0-2      0 = change to low (a falling edge)
+.br
+                     1 = change to high (a rising edge)
+.br
+                     2 = no level change (a watchdog timeout)
+.br
+
+.br
+tick        32 bit   The number of microseconds since boot
+.br
+                     WARNING: this wraps around from
+.br
+                     4294967295 to 0 roughly every 72 minutes
+.br
+
+.EE
 
 .br
 
@@ -1175,26 +1205,60 @@ Returns 0 if OK, otherwise PI_BAD_USER_GPIO.
 .br
 
 .br
-One function may be registered per GPIO.
+One callback may be registered per GPIO.
 
 .br
 
 .br
-The function is passed the GPIO, the new level, the tick, and
+The callback is passed the GPIO, the new level, the tick, and
 the userdata pointer.
 
 .br
 
 .br
-Only one of \fBgpioSetAlertFunc\fP or \fBgpioSetAlertFuncEx\fP can be
-registered per GPIO.
+
+.EX
+Parameter   Value    Meaning
+.br
+
+.br
+GPIO        0-31     The GPIO which has changed state
+.br
+
+.br
+level       0-2      0 = change to low (a falling edge)
+.br
+                     1 = change to high (a rising edge)
+.br
+                     2 = no level change (a watchdog timeout)
+.br
+
+.br
+tick        32 bit   The number of microseconds since boot
+.br
+                     WARNING: this wraps around from
+.br
+                     4294967295 to 0 roughly every 72 minutes
+.br
+
+.br
+userdata    pointer  Pointer to an arbitrary object
+.br
+
+.EE
 
 .br
 
 .br
 See \fBgpioSetAlertFunc\fP for further details.
 
-.IP "\fBint gpioSetISRFunc(unsigned user_gpio, unsigned edge, int timeout, gpioISRFunc_t f)\fP"
+.br
+
+.br
+Only one of \fBgpioSetAlertFunc\fP or \fBgpioSetAlertFuncEx\fP can be
+registered per GPIO.
+
+.IP "\fBint gpioSetISRFunc(unsigned gpio, unsigned edge, int timeout, gpioISRFunc_t f)\fP"
 .IP "" 4
 Registers a function to be called (a callback) whenever the specified
 GPIO interrupt occurs.
@@ -1204,13 +1268,13 @@ GPIO interrupt occurs.
 .br
 
 .EX
-user_gpio: 0-31
+   gpio: 0-53
 .br
-     edge: RISING_EDGE, FALLING_EDGE, or EITHER_EDGE
+   edge: RISING_EDGE, FALLING_EDGE, or EITHER_EDGE
 .br
-  timeout: interrupt timeout in milliseconds (<=0 to cancel)
+timeout: interrupt timeout in milliseconds (<=0 to cancel)
 .br
-        f: the callback function
+      f: the callback function
 .br
 
 .EE
@@ -1218,7 +1282,7 @@ user_gpio: 0-31
 .br
 
 .br
-Returns 0 if OK, otherwise PI_BAD_USER_GPIO, PI_BAD_EDGE,
+Returns 0 if OK, otherwise PI_BAD_GPIO, PI_BAD_EDGE,
 or PI_BAD_ISR_INIT.
 
 .br
@@ -1277,7 +1341,7 @@ interrupts happening in rapid succession may be missed by the
 kernel (i.e. this mechanism can not be used to capture several
 interrupts only a few microseconds apart).
 
-.IP "\fBint gpioSetISRFuncEx(unsigned user_gpio, unsigned edge, int timeout, gpioISRFuncEx_t f, void *userdata)\fP"
+.IP "\fBint gpioSetISRFuncEx(unsigned gpio, unsigned edge, int timeout, gpioISRFuncEx_t f, void *userdata)\fP"
 .IP "" 4
 Registers a function to be called (a callback) whenever the specified
 GPIO interrupt occurs.
@@ -1287,15 +1351,15 @@ GPIO interrupt occurs.
 .br
 
 .EX
-user_gpio: 0-31
+    gpio: 0-53
 .br
-     edge: RISING_EDGE, FALLING_EDGE, or EITHER_EDGE
+    edge: RISING_EDGE, FALLING_EDGE, or EITHER_EDGE
 .br
 timeout: interrupt timeout in milliseconds (<=0 to cancel)
+ timeout: interrupt timeout in milliseconds (<=0 to cancel)
 .br
-        f: the callback function
+       f: the callback function
 .br
- userdata: pointer to arbitrary user data
+userdata: pointer to arbitrary user data
 .br
 
 .EE
@@ -1303,7 +1367,7 @@ user_gpio: 0-31
 .br
 
 .br
-Returns 0 if OK, otherwise PI_BAD_USER_GPIO, PI_BAD_EDGE,
+Returns 0 if OK, otherwise PI_BAD_GPIO, PI_BAD_EDGE,
 or PI_BAD_ISR_INIT.
 
 .br
@@ -4136,20 +4200,31 @@ the word size in bits.
 .br
 
 .br
-For bits 1-8 there will be one byte per character.
+For bits 1-8 there will be one byte per word.
+.br
+For bits 9-16 there will be two bytes per word.
 .br
-For bits 9-16 there will be two bytes per character.
+For bits 17-32 there will be four bytes per word.
+
+.br
+
 .br
-For bits 17-32 there will be four bytes per character.
+Multi-byte transfers are made in least significant byte first order.
 
 .br
 
 .br
-E.g. to transfer 32 12-bit words buf should contain 64 bytes
+E.g. to transfer 32 11-bit words buf should contain 64 bytes
 and count should be 64.
 
 .br
 
+.br
+E.g. to transfer the 14 bit value 0x1ABC send the bytes 0xBC followed
+by 0x1A.
+
+.br
+
 .br
 The other bits in flags should be set to zero.
 
@@ -4492,16 +4567,24 @@ The watchdog may be cancelled by setting timeout to 0.
 .br
 
 .br
-If no level change has been detected for the GPIO for timeout
-milliseconds:-
+Until cancelled a timeout will be reported every timeout milliseconds
+after the last GPIO activity.
 
 .br
 
 .br
-1) any registered alert function for the GPIO is called with
+In particular:
+
+.br
+
+.br
+1) any registered alert function for the GPIO will be called with
    the level set to PI_TIMEOUT.
+
+.br
+
 .br
-2) any notification for the GPIO has a report written to the
+2) any notification for the GPIO will have a report written to the
    fifo with the flags set to indicate a watchdog timeout.
 
 .br
@@ -4568,7 +4651,21 @@ Returns 0 if OK, otherwise PI_BAD_USER_GPIO, or PI_BAD_FILTER.
 .br
 
 .br
-Note, level changes before and after the active period may
+This filter affects the GPIO samples returned to callbacks set up
+with \fBgpioSetAlertFunc\fP, \fBgpioSetAlertFuncEx\fP, \fBgpioSetGetSamplesFunc\fP,
+and \fBgpioSetGetSamplesFuncEx\fP.
+
+.br
+
+.br
+It does not affect interrupts set up with \fBgpioSetISRFunc\fP,
+\fBgpioSetISRFuncEx\fP, or levels read by \fBgpioRead\fP,
+\fBgpioRead_Bits_0_31\fP, or \fBgpioRead_Bits_32_53\fP.
+
+.br
+
+.br
+Level changes before and after the active period may
 be reported.  Your software must be designed to cope with
 such reports.
 
@@ -4604,7 +4701,21 @@ Returns 0 if OK, otherwise PI_BAD_USER_GPIO, or PI_BAD_FILTER.
 .br
 
 .br
-Note, each (stable) edge will be timestamped \fBsteady\fP microseconds
+This filter affects the GPIO samples returned to callbacks set up
+with \fBgpioSetAlertFunc\fP, \fBgpioSetAlertFuncEx\fP, \fBgpioSetGetSamplesFunc\fP,
+and \fBgpioSetGetSamplesFuncEx\fP.
+
+.br
+
+.br
+It does not affect interrupts set up with \fBgpioSetISRFunc\fP,
+\fBgpioSetISRFuncEx\fP, or levels read by \fBgpioRead\fP,
+\fBgpioRead_Bits_0_31\fP, or \fBgpioRead_Bits_32_53\fP.
+
+.br
+
+.br
+Each (stable) edge will be timestamped \fBsteady\fP microseconds
 after it was first detected.
 
 .IP "\fBint gpioSetGetSamplesFunc(gpioGetSamplesFunc_t f, uint32_t bits)\fP"
index 8310e314975247f7bcf8b06cfa9bf1d653efd0d7..bc2e64689a4db60d11f16ad4c52351ed0c90e39c 100644 (file)
--- a/pigpio.c
+++ b/pigpio.c
@@ -25,7 +25,7 @@ OTHER DEALINGS IN THE SOFTWARE.
 For more information, please refer to <http://unlicense.org/>
 */
 
-/* pigpio version 62 */
+/* pigpio version 63 */
 
 /* include ------------------------------------------------------- */
 
@@ -732,23 +732,28 @@ Assumes two counters per block.  Each counter 4 * 16 (16^4=65536)
 
 #define TICKSLOTS 50
 
-#define PI_I2C_CLOSED 0
-#define PI_I2C_OPENED 1
+#define PI_I2C_CLOSED   0
+#define PI_I2C_RESERVED 1
+#define PI_I2C_OPENED   2
 
-#define PI_SPI_CLOSED 0
-#define PI_SPI_OPENED 1
+#define PI_SPI_CLOSED   0
+#define PI_SPI_RESERVED 1
+#define PI_SPI_OPENED   2
 
-#define PI_SER_CLOSED 0
-#define PI_SER_OPENED 1
+#define PI_SER_CLOSED   0
+#define PI_SER_RESERVED 1
+#define PI_SER_OPENED   2
 
-#define PI_FILE_CLOSED 0
-#define PI_FILE_OPENED 1
+#define PI_FILE_CLOSED   0
+#define PI_FILE_RESERVED 1
+#define PI_FILE_OPENED   2
 
-#define PI_NOTIFY_CLOSED  0
-#define PI_NOTIFY_CLOSING 1
-#define PI_NOTIFY_OPENED  2
-#define PI_NOTIFY_RUNNING 3
-#define PI_NOTIFY_PAUSED  4
+#define PI_NOTIFY_CLOSED   0
+#define PI_NOTIFY_RESERVED 1
+#define PI_NOTIFY_CLOSING  2
+#define PI_NOTIFY_OPENED   3
+#define PI_NOTIFY_RUNNING  4
+#define PI_NOTIFY_PAUSED   5
 
 #define PI_WFRX_NONE     0
 #define PI_WFRX_SERIAL   1
@@ -861,6 +866,10 @@ Assumes two counters per block.  Each counter 4 * 16 (16^4=65536)
 #define PI_RUNNING  1
 #define PI_ENDING   2
 
+#define PI_THREAD_NONE    0
+#define PI_THREAD_STARTED 1
+#define PI_THREAD_RUNNING 2
+
 #define PI_MAX_PATH 512
 
 /* typedef ------------------------------------------------------- */
@@ -1251,15 +1260,15 @@ static volatile uint32_t scriptEventBits  = 0;
 
 static volatile int runState = PI_STARTING;
 
-static int pthAlertRunning  = 0;
-static int pthFifoRunning   = 0;
-static int pthSocketRunning = 0;
+static int pthAlertRunning  = PI_THREAD_NONE;
+static int pthFifoRunning   = PI_THREAD_NONE;
+static int pthSocketRunning = PI_THREAD_NONE;
 
 static gpioAlert_t      gpioAlert  [PI_MAX_USER_GPIO+1];
 
 static eventAlert_t     eventAlert [PI_MAX_EVENT+1];
 
-static gpioISR_t        gpioISR    [PI_MAX_USER_GPIO+1];
+static gpioISR_t        gpioISR    [PI_MAX_GPIO+1];
 
 static gpioGetSamples_t gpioGetSamples;
 
@@ -1280,9 +1289,6 @@ static gpioTimer_t      gpioTimer  [PI_MAX_TIMER+1];
 
 static int pwmFreq[PWM_FREQS];
 
-static pthread_mutex_t spi_main_mutex = PTHREAD_MUTEX_INITIALIZER;
-static pthread_mutex_t spi_aux_mutex = PTHREAD_MUTEX_INITIALIZER;
-
 /* reset after gpioTerminated */
 
 /* resources which must be released on gpioTerminate */
@@ -3333,7 +3339,7 @@ int i2cWriteQuick(unsigned handle, unsigned bit)
    if (handle >= PI_I2C_SLOTS)
       SOFT_ERROR(PI_BAD_HANDLE, "bad handle (%d)", handle);
 
-   if (i2cInfo[handle].state == PI_I2C_CLOSED)
+   if (i2cInfo[handle].state != PI_I2C_OPENED)
       SOFT_ERROR(PI_BAD_HANDLE, "bad handle (%d)", handle);
 
    if ((i2cInfo[handle].funcs & PI_I2C_FUNC_SMBUS_QUICK) == 0)
@@ -3366,7 +3372,7 @@ int i2cReadByte(unsigned handle)
    if (handle >= PI_I2C_SLOTS)
       SOFT_ERROR(PI_BAD_HANDLE, "bad handle (%d)", handle);
 
-   if (i2cInfo[handle].state == PI_I2C_CLOSED)
+   if (i2cInfo[handle].state != PI_I2C_OPENED)
       SOFT_ERROR(PI_BAD_HANDLE, "bad handle (%d)", handle);
 
    if ((i2cInfo[handle].funcs & PI_I2C_FUNC_SMBUS_READ_BYTE) == 0)
@@ -3396,7 +3402,7 @@ int i2cWriteByte(unsigned handle, unsigned bVal)
    if (handle >= PI_I2C_SLOTS)
       SOFT_ERROR(PI_BAD_HANDLE, "bad handle (%d)", handle);
 
-   if (i2cInfo[handle].state == PI_I2C_CLOSED)
+   if (i2cInfo[handle].state != PI_I2C_OPENED)
       SOFT_ERROR(PI_BAD_HANDLE, "bad handle (%d)", handle);
 
    if ((i2cInfo[handle].funcs & PI_I2C_FUNC_SMBUS_WRITE_BYTE) == 0)
@@ -3434,7 +3440,7 @@ int i2cReadByteData(unsigned handle, unsigned reg)
    if (handle >= PI_I2C_SLOTS)
       SOFT_ERROR(PI_BAD_HANDLE, "bad handle (%d)", handle);
 
-   if (i2cInfo[handle].state == PI_I2C_CLOSED)
+   if (i2cInfo[handle].state != PI_I2C_OPENED)
       SOFT_ERROR(PI_BAD_HANDLE, "bad handle (%d)", handle);
 
    if ((i2cInfo[handle].funcs & PI_I2C_FUNC_SMBUS_READ_BYTE_DATA) == 0)
@@ -3469,7 +3475,7 @@ int i2cWriteByteData(unsigned handle, unsigned reg, unsigned bVal)
    if (handle >= PI_I2C_SLOTS)
       SOFT_ERROR(PI_BAD_HANDLE, "bad handle (%d)", handle);
 
-   if (i2cInfo[handle].state == PI_I2C_CLOSED)
+   if (i2cInfo[handle].state != PI_I2C_OPENED)
       SOFT_ERROR(PI_BAD_HANDLE, "bad handle (%d)", handle);
 
    if ((i2cInfo[handle].funcs & PI_I2C_FUNC_SMBUS_WRITE_BYTE_DATA) == 0)
@@ -3512,7 +3518,7 @@ int i2cReadWordData(unsigned handle, unsigned reg)
    if (handle >= PI_I2C_SLOTS)
       SOFT_ERROR(PI_BAD_HANDLE, "bad handle (%d)", handle);
 
-   if (i2cInfo[handle].state == PI_I2C_CLOSED)
+   if (i2cInfo[handle].state != PI_I2C_OPENED)
       SOFT_ERROR(PI_BAD_HANDLE, "bad handle (%d)", handle);
 
    if ((i2cInfo[handle].funcs & PI_I2C_FUNC_SMBUS_READ_WORD_DATA) == 0)
@@ -3551,7 +3557,7 @@ int i2cWriteWordData(unsigned handle, unsigned reg, unsigned wVal)
    if (handle >= PI_I2C_SLOTS)
       SOFT_ERROR(PI_BAD_HANDLE, "bad handle (%d)", handle);
 
-   if (i2cInfo[handle].state == PI_I2C_CLOSED)
+   if (i2cInfo[handle].state != PI_I2C_OPENED)
       SOFT_ERROR(PI_BAD_HANDLE, "bad handle (%d)", handle);
 
    if ((i2cInfo[handle].funcs & PI_I2C_FUNC_SMBUS_WRITE_WORD_DATA) == 0)
@@ -3594,7 +3600,7 @@ int i2cProcessCall(unsigned handle, unsigned reg, unsigned wVal)
    if (handle >= PI_I2C_SLOTS)
       SOFT_ERROR(PI_BAD_HANDLE, "bad handle (%d)", handle);
 
-   if (i2cInfo[handle].state == PI_I2C_CLOSED)
+   if (i2cInfo[handle].state != PI_I2C_OPENED)
       SOFT_ERROR(PI_BAD_HANDLE, "bad handle (%d)", handle);
 
    if ((i2cInfo[handle].funcs & PI_I2C_FUNC_SMBUS_PROC_CALL) == 0)
@@ -3637,7 +3643,7 @@ int i2cReadBlockData(unsigned handle, unsigned reg, char *buf)
    if (handle >= PI_I2C_SLOTS)
       SOFT_ERROR(PI_BAD_HANDLE, "bad handle (%d)", handle);
 
-   if (i2cInfo[handle].state == PI_I2C_CLOSED)
+   if (i2cInfo[handle].state != PI_I2C_OPENED)
       SOFT_ERROR(PI_BAD_HANDLE, "bad handle (%d)", handle);
 
    if ((i2cInfo[handle].funcs & PI_I2C_FUNC_SMBUS_READ_BLOCK_DATA) == 0)
@@ -3685,7 +3691,7 @@ int i2cWriteBlockData(
    if (handle >= PI_I2C_SLOTS)
       SOFT_ERROR(PI_BAD_HANDLE, "bad handle (%d)", handle);
 
-   if (i2cInfo[handle].state == PI_I2C_CLOSED)
+   if (i2cInfo[handle].state != PI_I2C_OPENED)
       SOFT_ERROR(PI_BAD_HANDLE, "bad handle (%d)", handle);
 
    if ((i2cInfo[handle].funcs & PI_I2C_FUNC_SMBUS_WRITE_BLOCK_DATA) == 0)
@@ -3732,7 +3738,7 @@ int i2cBlockProcessCall(
    if (handle >= PI_I2C_SLOTS)
       SOFT_ERROR(PI_BAD_HANDLE, "bad handle (%d)", handle);
 
-   if (i2cInfo[handle].state == PI_I2C_CLOSED)
+   if (i2cInfo[handle].state != PI_I2C_OPENED)
       SOFT_ERROR(PI_BAD_HANDLE, "bad handle (%d)", handle);
 
    if ((i2cInfo[handle].funcs & PI_I2C_FUNC_SMBUS_PROC_CALL) == 0)
@@ -3784,7 +3790,7 @@ int i2cReadI2CBlockData(
    if (handle >= PI_I2C_SLOTS)
       SOFT_ERROR(PI_BAD_HANDLE, "bad handle (%d)", handle);
 
-   if (i2cInfo[handle].state == PI_I2C_CLOSED)
+   if (i2cInfo[handle].state != PI_I2C_OPENED)
       SOFT_ERROR(PI_BAD_HANDLE, "bad handle (%d)", handle);
 
    if ((i2cInfo[handle].funcs & PI_I2C_FUNC_SMBUS_READ_I2C_BLOCK) == 0)
@@ -3838,7 +3844,7 @@ int i2cWriteI2CBlockData(
    if (handle >= PI_I2C_SLOTS)
       SOFT_ERROR(PI_BAD_HANDLE, "bad handle (%d)", handle);
 
-   if (i2cInfo[handle].state == PI_I2C_CLOSED)
+   if (i2cInfo[handle].state != PI_I2C_OPENED)
       SOFT_ERROR(PI_BAD_HANDLE, "bad handle (%d)", handle);
 
    if ((i2cInfo[handle].funcs & PI_I2C_FUNC_SMBUS_WRITE_I2C_BLOCK) == 0)
@@ -3882,7 +3888,7 @@ int i2cWriteDevice(unsigned handle, char *buf, unsigned count)
    if (handle >= PI_I2C_SLOTS)
       SOFT_ERROR(PI_BAD_HANDLE, "bad handle (%d)", handle);
 
-   if (i2cInfo[handle].state == PI_I2C_CLOSED)
+   if (i2cInfo[handle].state != PI_I2C_OPENED)
       SOFT_ERROR(PI_BAD_HANDLE, "bad handle (%d)", handle);
 
    if ((count < 1) || (count > PI_MAX_I2C_DEVICE_COUNT))
@@ -3911,7 +3917,7 @@ int i2cReadDevice(unsigned handle, char *buf, unsigned count)
    if (handle >= PI_I2C_SLOTS)
       SOFT_ERROR(PI_BAD_HANDLE, "bad handle (%d)", handle);
 
-   if (i2cInfo[handle].state == PI_I2C_CLOSED)
+   if (i2cInfo[handle].state != PI_I2C_OPENED)
       SOFT_ERROR(PI_BAD_HANDLE, "bad handle (%d)", handle);
 
    if ((count < 1) || (count > PI_MAX_I2C_DEVICE_COUNT))
@@ -3930,6 +3936,7 @@ int i2cReadDevice(unsigned handle, char *buf, unsigned count)
 
 int i2cOpen(unsigned i2cBus, unsigned i2cAddr, unsigned i2cFlags)
 {
+   static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
    char dev[32];
    int i, slot, fd;
    uint32_t funcs;
@@ -3947,18 +3954,21 @@ int i2cOpen(unsigned i2cBus, unsigned i2cAddr, unsigned i2cFlags)
 
    slot = -1;
 
+   pthread_mutex_lock(&mutex);
+
    for (i=0; i<PI_I2C_SLOTS; i++)
    {
       if (i2cInfo[i].state == PI_I2C_CLOSED)
       {
-         i2cInfo[i].state = PI_I2C_OPENED;
          slot = i;
+         i2cInfo[slot].state = PI_I2C_RESERVED;
          break;
       }
    }
 
-   if (slot < 0)
-      SOFT_ERROR(PI_NO_HANDLE, "no I2C handles");
+   pthread_mutex_unlock(&mutex);
+
+   if (slot < 0) SOFT_ERROR(PI_NO_HANDLE, "no I2C handles");
 
    sprintf(dev, "/dev/i2c-%d", i2cBus);
 
@@ -3967,7 +3977,7 @@ int i2cOpen(unsigned i2cBus, unsigned i2cAddr, unsigned i2cFlags)
       /* try a modprobe */
 
       system("/sbin/modprobe i2c_dev");
-      system("/sbin/modprobe i2c_bcm2708");
+      system("/sbin/modprobe i2c_bcm2835");
 
       myGpioDelay(100000);
 
@@ -3994,6 +4004,7 @@ int i2cOpen(unsigned i2cBus, unsigned i2cAddr, unsigned i2cFlags)
    i2cInfo[slot].addr = i2cAddr;
    i2cInfo[slot].flags = i2cFlags;
    i2cInfo[slot].funcs = funcs;
+   i2cInfo[i].state = PI_I2C_OPENED;
 
    return slot;
 }
@@ -4480,17 +4491,20 @@ static void spiGo(
    char     *rxBuf,
    unsigned count)
 {
+   static pthread_mutex_t main_mutex = PTHREAD_MUTEX_INITIALIZER;
+   static pthread_mutex_t aux_mutex = PTHREAD_MUTEX_INITIALIZER;
+
    if (PI_SPI_FLAGS_GET_AUX_SPI(flags))
    {
-      pthread_mutex_lock(&spi_aux_mutex);
+      pthread_mutex_lock(&aux_mutex);
       spiGoA(speed, flags, txBuf, rxBuf, count);
-      pthread_mutex_unlock(&spi_aux_mutex);
+      pthread_mutex_unlock(&aux_mutex);
    }
    else
    {
-      pthread_mutex_lock(&spi_main_mutex);
+      pthread_mutex_lock(&main_mutex);
       spiGoS(speed, flags, txBuf, rxBuf, count);
-      pthread_mutex_unlock(&spi_main_mutex);
+      pthread_mutex_unlock(&main_mutex);
    }
 }
 
@@ -4627,6 +4641,7 @@ static void spiTerm(uint32_t flags)
 
 int spiOpen(unsigned spiChan, unsigned baud, unsigned spiFlags)
 {
+   static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
    int i, slot;
 
    DBG(DBG_USER, "spiChan=%d baud=%d spiFlags=0x%X",
@@ -4661,21 +4676,25 @@ int spiOpen(unsigned spiChan, unsigned baud, unsigned spiFlags)
 
    slot = -1;
 
+   pthread_mutex_lock(&mutex);
+
    for (i=0; i<PI_SPI_SLOTS; i++)
    {
       if (spiInfo[i].state == PI_SPI_CLOSED)
       {
-         spiInfo[i].state = PI_SPI_OPENED;
          slot = i;
+         spiInfo[slot].state = PI_SPI_RESERVED;
          break;
       }
    }
 
-   if (slot < 0)
-      SOFT_ERROR(PI_NO_HANDLE, "no SPI handles");
+   pthread_mutex_unlock(&mutex);
+
+   if (slot < 0) SOFT_ERROR(PI_NO_HANDLE, "no SPI handles");
 
    spiInfo[slot].speed = baud;
    spiInfo[slot].flags = spiFlags | PI_SPI_FLAGS_CHANNEL(spiChan);
+   spiInfo[slot].state = PI_SPI_OPENED;
 
    return slot;
 }
@@ -4768,6 +4787,7 @@ int spiXfer(unsigned handle, char *txBuf, char *rxBuf, unsigned count)
 
 int serOpen(char *tty, unsigned serBaud, unsigned serFlags)
 {
+   static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
    struct termios new;
    int speed;
    int fd;
@@ -4810,18 +4830,21 @@ int serOpen(char *tty, unsigned serBaud, unsigned serFlags)
 
    slot = -1;
 
+   pthread_mutex_lock(&mutex);
+
    for (i=0; i<PI_SER_SLOTS; i++)
    {
       if (serInfo[i].state == PI_SER_CLOSED)
       {
-         serInfo[i].state = PI_SER_OPENED;
          slot = i;
+         serInfo[slot].state = PI_SER_RESERVED;
          break;
       }
    }
 
-   if (slot < 0)
-      SOFT_ERROR(PI_NO_HANDLE, "no serial handles");
+   pthread_mutex_unlock(&mutex);
+
+   if (slot < 0) SOFT_ERROR(PI_NO_HANDLE, "no serial handles");
 
    if ((fd = open(tty, O_RDWR | O_NOCTTY | O_NDELAY | O_NONBLOCK)) == -1)
    {
@@ -4846,6 +4869,7 @@ int serOpen(char *tty, unsigned serBaud, unsigned serFlags)
 
    serInfo[slot].fd = fd;
    serInfo[slot].flags = serFlags;
+   serInfo[slot].state = PI_SER_OPENED;
 
    return slot;
 }
@@ -5816,7 +5840,7 @@ static void alertEmit(
 
          gpioNotify[n].state = PI_NOTIFY_CLOSED;
       }
-      else if (gpioNotify[n].state != PI_NOTIFY_CLOSED)
+      else if (gpioNotify[n].state >= PI_NOTIFY_OPENED)
       {
          bits = gpioNotify[n].bits;
 
@@ -5923,7 +5947,7 @@ static void alertEmit(
 
          if (!emit)
          {
-            if ((eTick - gpioNotify[n].lastReportTick) > 60000000)
+            if ((int)(eTick - gpioNotify[n].lastReportTick) > 60000000)
             {
                if (numSamples)
                   newLevel = sample[numSamples-1].level;
@@ -6268,6 +6292,7 @@ static void * pthAlertThread(void *x)
             {
                stickInited = 1;
                numSamples = 0;
+               pthAlertRunning = PI_THREAD_RUNNING;
             }
          }
       }
@@ -7745,9 +7770,9 @@ static void initClearGlobals(void)
    nFilterBits = 0;
    wdogBits    = 0;
 
-   pthAlertRunning  = 0;
-   pthFifoRunning   = 0;
-   pthSocketRunning = 0;
+   pthAlertRunning  = PI_THREAD_NONE;
+   pthFifoRunning   = PI_THREAD_NONE;
+   pthSocketRunning = PI_THREAD_NONE;
 
    wfc[0] = 0;
    wfc[1] = 0;
@@ -7856,7 +7881,7 @@ static void initReleaseResources(void)
 
    /* shut down running threads */
 
-   for (i=0; i<=PI_MAX_USER_GPIO; i++)
+   for (i=0; i<=PI_MAX_GPIO; i++)
    {
       if (gpioISR[i].pth)
       {
@@ -7878,25 +7903,25 @@ static void initReleaseResources(void)
       }
    }
 
-   if (pthAlertRunning)
+   if (pthAlertRunning != PI_THREAD_NONE)
    {
       pthread_cancel(pthAlert);
       pthread_join(pthAlert, NULL);
-      pthAlertRunning = 0;
+      pthAlertRunning = PI_THREAD_NONE;
    }
 
-   if (pthFifoRunning)
+   if (pthFifoRunning != PI_THREAD_NONE)
    {
       pthread_cancel(pthFifo);
       pthread_join(pthFifo, NULL);
-      pthFifoRunning = 0;
+      pthFifoRunning = PI_THREAD_NONE;
    }
 
-   if (pthSocketRunning)
+   if (pthSocketRunning != PI_THREAD_NONE)
    {
       pthread_cancel(pthSocket);
       pthread_join(pthSocket, NULL);
-      pthSocketRunning = 0;
+      pthSocketRunning = PI_THREAD_NONE;
    }
 
    /* release mmap'd memory */
@@ -8118,14 +8143,14 @@ int initInitialise(void)
    if (pthread_create(&pthAlert, &pthAttr, pthAlertThread, &i))
       SOFT_ERROR(PI_INIT_FAILED, "pthread_create alert failed (%m)");
 
-   pthAlertRunning = 1;
+   pthAlertRunning = PI_THREAD_STARTED;
 
    if (!(gpioCfg.ifFlags & PI_DISABLE_FIFO_IF))
    {
       if (pthread_create(&pthFifo, &pthAttr, pthFifoThread, &i))
          SOFT_ERROR(PI_INIT_FAILED, "pthread_create fifo failed (%m)");
 
-      pthFifoRunning = 1;
+      pthFifoRunning = PI_THREAD_STARTED;
    }
 
    if (!(gpioCfg.ifFlags & PI_DISABLE_SOCK_IF))
@@ -8182,10 +8207,10 @@ int initInitialise(void)
       if (pthread_create(&pthSocket, &pthAttr, pthSocketThread, &i))
          SOFT_ERROR(PI_INIT_FAILED, "pthread_create socket failed (%m)");
 
-      pthSocketRunning = 1;
+      pthSocketRunning = PI_THREAD_STARTED;
    }
 
-   myGpioDelay(10000);
+   myGpioDelay(1000);
 
    dmaInitCbs();
 
@@ -8193,8 +8218,6 @@ int initInitialise(void)
 
    initDMAgo((uint32_t *)dmaIn, (uint32_t)dmaIBus[0]);
 
-   myGpioDelay(20000);
-
    return PIGPIO_VERSION;
 }
 
@@ -8445,7 +8468,10 @@ int gpioInitialise(void)
    else
    {
       libInitialised = 1;
+
       runState = PI_RUNNING;
+
+      while (pthAlertRunning != PI_THREAD_RUNNING) myGpioDelay(1000);
    }
 
    return status;
@@ -11462,8 +11488,8 @@ int gpioSetISRFunc(
 
    CHECK_INITED;
 
-   if (gpio > PI_MAX_USER_GPIO)
-      SOFT_ERROR(PI_BAD_USER_GPIO, "bad gpio (%d)", gpio);
+   if (gpio > PI_MAX_GPIO)
+      SOFT_ERROR(PI_BAD_GPIO, "bad gpio (%d)", gpio);
 
    if (edge > EITHER_EDGE)
       SOFT_ERROR(PI_BAD_EDGE, "bad ISR edge (%d)", edge);
@@ -11486,8 +11512,8 @@ int gpioSetISRFuncEx(
 
    CHECK_INITED;
 
-   if (gpio > PI_MAX_USER_GPIO)
-      SOFT_ERROR(PI_BAD_USER_GPIO, "bad gpio (%d)", gpio);
+   if (gpio > PI_MAX_GPIO)
+      SOFT_ERROR(PI_BAD_GPIO, "bad gpio (%d)", gpio);
 
    if (edge > EITHER_EDGE)
       SOFT_ERROR(PI_BAD_EDGE, "bad ISR edge (%d)", edge);
@@ -11504,7 +11530,7 @@ static void closeOrphanedNotifications(int slot, int fd)
    for (i=0; i<PI_NOTIFY_SLOTS; i++)
    {
       if ((i != slot) &&
-          (gpioNotify[i].state != PI_NOTIFY_CLOSED) &&
+          (gpioNotify[i].state >= PI_NOTIFY_OPENED) &&
           (gpioNotify[i].fd == fd))
       {
          DBG(DBG_USER, "closed orphaned fd=%d (handle=%d)", fd, i);
@@ -11516,6 +11542,15 @@ static void closeOrphanedNotifications(int slot, int fd)
 
 /* ----------------------------------------------------------------------- */
 
+static void notifyMutex(int lock)
+{
+   static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
+   if (lock) pthread_mutex_lock(&mutex);
+   else      pthread_mutex_unlock(&mutex);
+}
+
+/* ----------------------------------------------------------------------- */
+
 int gpioNotifyOpenWithSize(int bufSize)
 {
    int i, slot, fd;
@@ -11527,18 +11562,21 @@ int gpioNotifyOpenWithSize(int bufSize)
 
    slot = -1;
 
+   notifyMutex(1);
+
    for (i=0; i<PI_NOTIFY_SLOTS; i++)
    {
       if (gpioNotify[i].state == PI_NOTIFY_CLOSED)
       {
-         gpioNotify[i].state = PI_NOTIFY_OPENED;
          slot = i;
+         gpioNotify[slot].state = PI_NOTIFY_RESERVED;
          break;
       }
    }
 
-   if (slot < 0)
-      SOFT_ERROR(PI_NO_HANDLE, "no handle");
+   notifyMutex(0);
+
+   if (slot < 0) SOFT_ERROR(PI_NO_HANDLE, "no handle");
 
    sprintf(name, "/dev/pigpio%d", slot);
 
@@ -11569,6 +11607,7 @@ int gpioNotifyOpenWithSize(int bufSize)
    gpioNotify[slot].pipe  = 1;
    gpioNotify[slot].max_emits  = MAX_EMITS;
    gpioNotify[slot].lastReportTick = gpioTick();
+   gpioNotify[i].state = PI_NOTIFY_OPENED;
 
    closeOrphanedNotifications(slot, fd);
 
@@ -11592,24 +11631,29 @@ static int gpioNotifyOpenInBand(int fd)
 
    slot = -1;
 
+   notifyMutex(1);
+
    for (i=0; i<PI_NOTIFY_SLOTS; i++)
    {
       if (gpioNotify[i].state == PI_NOTIFY_CLOSED)
       {
          slot = i;
+         gpioNotify[slot].state = PI_NOTIFY_RESERVED;
          break;
       }
    }
 
+   notifyMutex(0);
+
    if (slot < 0) SOFT_ERROR(PI_NO_HANDLE, "no handle");
 
-   gpioNotify[slot].state = PI_NOTIFY_OPENED;
    gpioNotify[slot].seqno = 0;
    gpioNotify[slot].bits  = 0;
    gpioNotify[slot].fd    = fd;
    gpioNotify[slot].pipe  = 0;
    gpioNotify[slot].max_emits  = MAX_EMITS;
    gpioNotify[slot].lastReportTick = gpioTick();
+   gpioNotify[slot].state = PI_NOTIFY_OPENED;
 
    closeOrphanedNotifications(slot, fd);
 
@@ -12095,6 +12139,7 @@ void gpioStopThread(pthread_t *pth)
 
 int gpioStoreScript(char *script)
 {
+   static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
    gpioScript_t *s;
    int status, slot, i;
 
@@ -12104,18 +12149,21 @@ int gpioStoreScript(char *script)
 
    slot = -1;
 
+   pthread_mutex_lock(&mutex);
+
    for (i=0; i<PI_MAX_SCRIPTS; i++)
    {
       if (gpioScript[i].state == PI_SCRIPT_FREE)
       {
-         gpioScript[i].state = PI_SCRIPT_RESERVED;
          slot = i;
+         gpioScript[slot].state = PI_SCRIPT_RESERVED;
          break;
       }
    }
 
-   if (slot < 0)
-      SOFT_ERROR(PI_NO_SCRIPT_ROOM, "no room for scripts");
+   pthread_mutex_unlock(&mutex);
+
+   if (slot < 0) SOFT_ERROR(PI_NO_SCRIPT_ROOM, "no room for scripts");
 
    s = &gpioScript[slot];
 
@@ -12136,7 +12184,6 @@ int gpioStoreScript(char *script)
       s->pthIdp = gpioStartThread(pthScript, s);
 
       status = slot;
-
    }
    else
    {
@@ -12752,6 +12799,7 @@ int fileApprove(char *filename)
 
 int fileOpen(char *file, unsigned mode)
 {
+   static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
    int fd=-1;
    int i, slot, oflag, omode;
    struct stat statbuf;
@@ -12770,18 +12818,21 @@ int fileOpen(char *file, unsigned mode)
 
    slot = -1;
 
+   pthread_mutex_lock(&mutex);
+
    for (i=0; i<PI_FILE_SLOTS; i++)
    {
       if (fileInfo[i].state == PI_FILE_CLOSED)
       {
-         fileInfo[i].state = PI_FILE_OPENED;
          slot = i;
+         fileInfo[slot].state = PI_FILE_RESERVED;
          break;
       }
    }
 
-   if (slot < 0)
-      SOFT_ERROR(PI_NO_HANDLE, "no file handles");
+   pthread_mutex_unlock(&mutex);
+
+   if (slot < 0) SOFT_ERROR(PI_NO_HANDLE, "no file handles");
 
    omode = 0;
    oflag = 0;
@@ -12839,6 +12890,7 @@ int fileOpen(char *file, unsigned mode)
 
    fileInfo[slot].fd = fd;
    fileInfo[slot].mode = mode;
+   fileInfo[slot].state = PI_FILE_OPENED;
 
    return slot;
 }
index 192006a8f1dba0c608282151b008ca174a14ed73..4df7695d01b56b10c01b826de120933ad853dd8e 100644 (file)
--- a/pigpio.h
+++ b/pigpio.h
@@ -31,7 +31,7 @@ For more information, please refer to <http://unlicense.org/>
 #include <stdint.h>
 #include <pthread.h>
 
-#define PIGPIO_VERSION 62
+#define PIGPIO_VERSION 63
 
 /*TEXT
 
@@ -1363,9 +1363,23 @@ user_gpio: 0-31
 
 Returns 0 if OK, otherwise PI_BAD_USER_GPIO.
 
-One function may be registered per GPIO.
+One callback may be registered per GPIO.
+
+The callback is passed the GPIO, the new level, and the tick.
+
+. .
+Parameter   Value    Meaning
+
+GPIO        0-31     The GPIO which has changed state
 
-The function is passed the GPIO, the new level, and the tick.
+level       0-2      0 = change to low (a falling edge)
+                     1 = change to high (a rising edge)
+                     2 = no level change (a watchdog timeout)
+
+tick        32 bit   The number of microseconds since boot
+                     WARNING: this wraps around from
+                     4294967295 to 0 roughly every 72 minutes
+. .
 
 The alert may be cancelled by passing NULL as the function.
 
@@ -1426,33 +1440,49 @@ user_gpio: 0-31
 
 Returns 0 if OK, otherwise PI_BAD_USER_GPIO.
 
-One function may be registered per GPIO.
+One callback may be registered per GPIO.
 
-The function is passed the GPIO, the new level, the tick, and
+The callback is passed the GPIO, the new level, the tick, and
 the userdata pointer.
 
-Only one of [*gpioSetAlertFunc*] or [*gpioSetAlertFuncEx*] can be
-registered per GPIO.
+. .
+Parameter   Value    Meaning
+
+GPIO        0-31     The GPIO which has changed state
+
+level       0-2      0 = change to low (a falling edge)
+                     1 = change to high (a rising edge)
+                     2 = no level change (a watchdog timeout)
+
+tick        32 bit   The number of microseconds since boot
+                     WARNING: this wraps around from
+                     4294967295 to 0 roughly every 72 minutes
+
+userdata    pointer  Pointer to an arbitrary object
+. .
 
 See [*gpioSetAlertFunc*] for further details.
+
+Only one of [*gpioSetAlertFunc*] or [*gpioSetAlertFuncEx*] can be
+registered per GPIO.
 D*/
 
 
 /*F*/
 int gpioSetISRFunc(
-   unsigned user_gpio, unsigned edge, int timeout, gpioISRFunc_t f);
+   unsigned gpio, unsigned edge, int timeout, gpioISRFunc_t f);
 /*D
 Registers a function to be called (a callback) whenever the specified
 GPIO interrupt occurs.
 
 . .
-user_gpio: 0-31
-     edge: RISING_EDGE, FALLING_EDGE, or EITHER_EDGE
-  timeout: interrupt timeout in milliseconds (<=0 to cancel)
-        f: the callback function
+   gpio: 0-53
+   edge: RISING_EDGE, FALLING_EDGE, or EITHER_EDGE
+timeout: interrupt timeout in milliseconds (<=0 to cancel)
+      f: the callback function
 . .
 
-Returns 0 if OK, otherwise PI_BAD_USER_GPIO, PI_BAD_EDGE,
+Returns 0 if OK, otherwise PI_BAD_GPIO, PI_BAD_EDGE,
 or PI_BAD_ISR_INIT.
 
 One function may be registered per GPIO.
@@ -1491,7 +1521,7 @@ D*/
 
 /*F*/
 int gpioSetISRFuncEx(
-   unsigned user_gpio,
+   unsigned gpio,
    unsigned edge,
    int timeout,
    gpioISRFuncEx_t f,
@@ -1501,14 +1531,14 @@ Registers a function to be called (a callback) whenever the specified
 GPIO interrupt occurs.
 
 . .
-user_gpio: 0-31
-     edge: RISING_EDGE, FALLING_EDGE, or EITHER_EDGE
 timeout: interrupt timeout in milliseconds (<=0 to cancel)
-        f: the callback function
- userdata: pointer to arbitrary user data
+    gpio: 0-53
+    edge: RISING_EDGE, FALLING_EDGE, or EITHER_EDGE
+ timeout: interrupt timeout in milliseconds (<=0 to cancel)
+       f: the callback function
+userdata: pointer to arbitrary user data
 . .
 
-Returns 0 if OK, otherwise PI_BAD_USER_GPIO, PI_BAD_EDGE,
+Returns 0 if OK, otherwise PI_BAD_GPIO, PI_BAD_EDGE,
 or PI_BAD_ISR_INIT.
 
 The function is passed the GPIO, the current level, the
@@ -3137,13 +3167,18 @@ The [*spiRead*], [*spiWrite*], and [*spiXfer*] functions
 transfer data packed into 1, 2, or 4 bytes according to
 the word size in bits.
 
-For bits 1-8 there will be one byte per character
-For bits 9-16 there will be two bytes per character
-For bits 17-32 there will be four bytes per character.
+For bits 1-8 there will be one byte per word
+For bits 9-16 there will be two bytes per word
+For bits 17-32 there will be four bytes per word.
 
-E.g. to transfer 32 12-bit words buf should contain 64 bytes
+Multi-byte transfers are made in least significant byte first order.
+
+E.g. to transfer 32 11-bit words buf should contain 64 bytes
 and count should be 64.
 
+E.g. to transfer the 14 bit value 0x1ABC send the bytes 0xBC followed
+by 0x1A.
+
 The other bits in flags should be set to zero.
 D*/
 
@@ -3362,12 +3397,15 @@ One watchdog may be registered per GPIO.
 
 The watchdog may be cancelled by setting timeout to 0.
 
-If no level change has been detected for the GPIO for timeout
-milliseconds:-
+Until cancelled a timeout will be reported every timeout milliseconds
+after the last GPIO activity.
+
+In particular:
+
+1) any registered alert function for the GPIO will be called with
+   the level set to PI_TIMEOUT.
 
-1) any registered alert function for the GPIO is called with
-   the level set to PI_TIMEOUT. 
-2) any notification for the GPIO has a report written to the
+2) any notification for the GPIO will have a report written to the
    fifo with the flags set to indicate a watchdog timeout.
 
 ...
@@ -3403,7 +3441,15 @@ user_gpio: 0-31
 
 Returns 0 if OK, otherwise PI_BAD_USER_GPIO, or PI_BAD_FILTER.
 
-Note, level changes before and after the active period may
+This filter affects the GPIO samples returned to callbacks set up
+with [*gpioSetAlertFunc*], [*gpioSetAlertFuncEx*], [*gpioSetGetSamplesFunc*],
+and [*gpioSetGetSamplesFuncEx*].
+
+It does not affect interrupts set up with [*gpioSetISRFunc*],
+[*gpioSetISRFuncEx*], or levels read by [*gpioRead*],
+[*gpioRead_Bits_0_31*], or [*gpioRead_Bits_32_53*].
+
+Level changes before and after the active period may
 be reported.  Your software must be designed to cope with
 such reports.
 D*/
@@ -3426,7 +3472,15 @@ user_gpio: 0-31
 
 Returns 0 if OK, otherwise PI_BAD_USER_GPIO, or PI_BAD_FILTER.
 
-Note, each (stable) edge will be timestamped [*steady*] microseconds
+This filter affects the GPIO samples returned to callbacks set up
+with [*gpioSetAlertFunc*], [*gpioSetAlertFuncEx*], [*gpioSetGetSamplesFunc*],
+and [*gpioSetGetSamplesFuncEx*].
+
+It does not affect interrupts set up with [*gpioSetISRFunc*],
+[*gpioSetISRFuncEx*], or levels read by [*gpioRead*],
+[*gpioRead_Bits_0_31*], or [*gpioRead_Bits_32_53*].
+
+Each (stable) edge will be timestamped [*steady*] microseconds
 after it was first detected.
 D*/
 
index 517943f8eba085ee727712ca963824d82d7b4865..3ee6349e982b7ef9e2940f41497c9e1d8f919191 100644 (file)
--- a/pigpio.py
+++ b/pigpio.py
@@ -299,7 +299,7 @@ import threading
 import os
 import atexit
 
-VERSION = "1.36"
+VERSION = "1.37"
 
 exceptions = True
 
@@ -390,6 +390,8 @@ SPI_RX_LSBFIRST = 1 << 15
 
 EVENT_BSC = 31
 
+_SOCK_CMD_LEN = 16
+
 # pigpio command numbers
 
 _PI_CMD_MODES= 0
@@ -848,6 +850,10 @@ _except_2 = """
 Do you have permission to access the pigpio daemon?
 Perhaps it was started with sudo pigpiod -nlocalhost"""
 
+_except_3 = """
+Can't create callback thread.
+Perhaps too many simultaneous pigpio connections."""
+
 class _socklock:
    """
    A class to store socket and lock.
@@ -971,11 +977,11 @@ def _pigpio_command(sl, cmd, p1, p2, rl=True):
     sl:= command socket and lock.
    cmd:= the command to be executed.
     p1:= command parameter 1 (if applicable).
-     p2:=  command parameter 2 (if applicable).
+    p2:= command parameter 2 (if applicable).
    """
    sl.l.acquire()
    sl.s.send(struct.pack('IIII', cmd, p1, p2, 0))
-   dummy, res = struct.unpack('12sI', sl.s.recv(16))
+   dummy, res = struct.unpack('12sI', sl.s.recv(_SOCK_CMD_LEN))
    if rl: sl.l.release()
    return res
 
@@ -998,7 +1004,7 @@ def _pigpio_command_ext(sl, cmd, p1, p2, p3, extents, rl=True):
          ext.extend(x)
    sl.l.acquire()
    sl.s.sendall(ext)
-   dummy, res = struct.unpack('12sI', sl.s.recv(16))
+   dummy, res = struct.unpack('12sI', sl.s.recv(_SOCK_CMD_LEN))
    if rl: sl.l.release()
    return res
 
@@ -1048,7 +1054,8 @@ class _callback_thread(threading.Thread):
       self.callbacks = []
       self.events = []
       self.sl.s = socket.create_connection((host, port), None)
-      self.handle = _pigpio_command(self.sl, _PI_CMD_NOIB, 0, 0)
+      self.lastLevel = _u2i(_pigpio_command(self.sl,  _PI_CMD_BR1, 0, 0))
+      self.handle = _u2i(_pigpio_command(self.sl, _PI_CMD_NOIB, 0, 0))
       self.go = True
       self.start()
 
@@ -1101,7 +1108,7 @@ class _callback_thread(threading.Thread):
    def run(self):
       """Runs the notification thread."""
 
-      lastLevel = _pigpio_command(self.control,  _PI_CMD_BR1, 0, 0)
+      lastLevel = self.lastLevel
 
       MSG_SIZ = 12
 
@@ -1743,8 +1750,8 @@ class pi():
       The watchdog may be cancelled by setting timeout to 0.
 
       Once a watchdog has been started callbacks for the GPIO
-      will be triggered whenever there has been no GPIO activity
-      for the timeout interval.
+      will be triggered every timeout interval after the last
+      GPIO activity.
 
       The callback will receive the special level TIMEOUT.
 
@@ -3753,7 +3760,14 @@ class pi():
       For bits 9-16 there will be two bytes per character. 
       For bits 17-32 there will be four bytes per character.
 
-      E.g. 32 12-bit words will be transferred in 64 bytes.
+      Multi-byte transfers are made in least significant byte
+      first order.
+
+      E.g. to transfer 32 11-bit words data should
+      contain 64 bytes.
+
+      E.g. to transfer the 14 bit value 0x1ABC send the
+      bytes 0xBC followed by 0x1A.
 
       The other bits in flags should be set to zero.
 
@@ -4064,7 +4078,13 @@ class pi():
 
       Returns 0 if OK, otherwise PI_BAD_USER_GPIO, or PI_BAD_FILTER.
 
-      Note, each (stable) edge will be timestamped [*steady*]
+      This filter affects the GPIO samples returned to callbacks set up
+      with [*callback*] and [*wait_for_edge*].
+
+      It does not affect levels read by [*read*],
+      [*read_bank_1*], or [*read_bank_2*].
+
+      Each (stable) edge will be timestamped [*steady*]
       microseconds after it was first detected.
 
       ...
@@ -4088,7 +4108,13 @@ class pi():
 
       Returns 0 if OK, otherwise PI_BAD_USER_GPIO, or PI_BAD_FILTER.
 
-      Note, level changes before and after the active period may
+      This filter affects the GPIO samples returned to callbacks set up
+      with [*callback*] and [*wait_for_edge*].
+
+      It does not affect levels read by [*read*],
+      [*read_bank_1*], or [*read_bank_2*].
+
+      Level changes before and after the active period may
       be reported.  Your software must be designed to cope with
       such reports.
 
@@ -4761,6 +4787,20 @@ class pi():
       The user supplied callback receives three parameters, the GPIO,
       the level, and the tick.
 
+      . .
+      Parameter   Value    Meaning
+
+      GPIO        0-31     The GPIO which has changed state
+
+      level       0-2      0 = change to low (a falling edge)
+                           1 = change to high (a rising edge)
+                           2 = no level change (a watchdog timeout)
+
+      tick        32 bit   The number of microseconds since boot
+                           WARNING: this wraps around from
+                           4294967295 to 0 roughly every 72 minutes
+      . .
+
       If a user callback is not specified a default tally callback is
       provided which simply counts edges.  The count may be retrieved
       by calling the tally function.  The count may be reset to zero
@@ -4946,6 +4986,9 @@ class pi():
       except struct.error:
          exception = 2
 
+      except error:
+         exception = 3
+
       else:
          exception = 0
          atexit.register(self.stop)
@@ -4962,8 +5005,10 @@ class pi():
          print(_except_a.format(s))
          if exception == 1:
              print(_except_1)
-         else:
+         elif exception == 2:
              print(_except_2)
+         else:
+             print(_except_3)
          print(_except_z)
 
    def stop(self):
index e7fef5ac7199a6370bec01e089f2cc6e6aa0ce3c..d677a88edcbcece99d3021c36f82cf4a28cee155 100644 (file)
--- a/pigpiod.1
+++ b/pigpiod.1
@@ -2,7 +2,7 @@
 ." Process this file with
 ." groff -man -Tascii pigpiod.1
 ."
-.TH pigpiod 1 2012-2015 Linux "pigpio archive"
+.TH pigpiod 1 2012-2017 Linux "pigpio archive"
 .SH NAME
 pigpiod - A utility to start the pigpio library as a daemon.
 
index 2fe7ed2a468708cb6aa1b43a1be90bad4a4f8654..5c5cb0fcfabc6b8c1f7e361733f6651cd9bd9364 100644 (file)
@@ -2,7 +2,7 @@
 ." Process this file with
 ." groff -man -Tascii pigpiod_if.3
 ."
-.TH pigpiod_if 3 2012-2015 Linux "pigpio archive"
+.TH pigpiod_if 3 2012-2017 Linux "pigpio archive"
 .SH NAME
 pigpiod_if - A C library to interface to the pigpio daemon.
 
@@ -1065,15 +1065,13 @@ The watchdog may be cancelled by setting timeout to 0.
 .br
 
 .br
-If no level change has been detected for the GPIO for timeout
-milliseconds any notification for the GPIO has a report written
-to the fifo with the flags set to indicate a watchdog timeout.
+Once a watchdog has been started callbacks for the GPIO will be
+triggered every timeout interval after the last GPIO activity.
 
 .br
 
 .br
-The \fBcallback\fP and \fBcallback_ex\fP functions interpret the flags
-and will call registered callbacks for the GPIO with level TIMEOUT.
+The callback will receive the special level PI_TIMEOUT.
 
 .IP "\fBint set_glitch_filter(unsigned user_gpio, unsigned steady)\fP"
 .IP "" 4
@@ -1107,7 +1105,15 @@ Returns 0 if OK, otherwise PI_BAD_USER_GPIO, or PI_BAD_FILTER.
 .br
 
 .br
-Note, each (stable) edge will be timestamped \fBsteady\fP microseconds
+This filter affects the GPIO samples returned to callbacks set up
+with \fBcallback\fP, \fBcallback_ex\fP and \fBwait_for_edge\fP.
+
+.br
+
+.br
+It does not affect levels read by \fBgpio_read\fP,
+\fBread_bank_1\fP, or \fBread_bank_2\fP.
+Each (stable) edge will be timestamped \fBsteady\fP microseconds
 after it was first detected.
 
 .IP "\fBint set_noise_filter(unsigned user_gpio, unsigned steady, unsigned active)\fP"
@@ -1144,7 +1150,19 @@ Returns 0 if OK, otherwise PI_BAD_USER_GPIO, or PI_BAD_FILTER.
 .br
 
 .br
-Note, level changes before and after the active period may
+This filter affects the GPIO samples returned to callbacks set up
+with \fBcallback\fP, \fBcallback_ex\fP and \fBwait_for_edge\fP.
+
+.br
+
+.br
+It does not affect levels read by \fBgpio_read\fP,
+\fBread_bank_1\fP, or \fBread_bank_2\fP.
+
+.br
+
+.br
+Level changes before and after the active period may
 be reported.  Your software must be designed to cope with
 such reports.
 
@@ -3415,6 +3433,39 @@ sets 8 bits per word.  Auxiliary SPI device only.
 
 .br
 
+.br
+The \fBspi_read\fP, \fBspi_write\fP, and \fBspi_xfer\fP functions
+transfer data packed into 1, 2, or 4 bytes according to
+the word size in bits.
+
+.br
+
+.br
+For bits 1-8 there will be one byte per word.
+.br
+For bits 9-16 there will be two bytes per word.
+.br
+For bits 17-32 there will be four bytes per word.
+
+.br
+
+.br
+Multi-byte transfers are made in least significant byte first order.
+
+.br
+
+.br
+E.g. to transfer 32 11-bit words buf should contain 64 bytes
+and count should be 64.
+
+.br
+
+.br
+E.g. to transfer the 14 bit value 0x1ABC send the bytes 0xBC followed
+by 0x1A.
+
+.br
+
 .br
 The other bits in flags should be set to zero.
 
@@ -3792,6 +3843,36 @@ pigif_duplicate_callback, or pigif_bad_callback.
 The callback is called with the GPIO, edge, and tick, whenever the
 GPIO has the identified edge.
 
+.br
+
+.br
+
+.EX
+Parameter   Value    Meaning
+.br
+
+.br
+GPIO        0-31     The GPIO which has changed state
+.br
+
+.br
+edge        0-2      0 = change to low (a falling edge)
+.br
+                     1 = change to high (a rising edge)
+.br
+                     2 = no level change (a watchdog timeout)
+.br
+
+.br
+tick        32 bit   The number of microseconds since boot
+.br
+                     WARNING: this wraps around from
+.br
+                     4294967295 to 0 roughly every 72 minutes
+.br
+
+.EE
+
 .IP "\fBint callback_ex(unsigned user_gpio, unsigned edge, CBFuncEx_t f, void *userdata)\fP"
 .IP "" 4
 This function initialises a new callback.
@@ -3828,6 +3909,36 @@ the GPIO has the identified edge.
 
 .br
 
+.EX
+Parameter   Value    Meaning
+.br
+
+.br
+GPIO        0-31     The GPIO which has changed state
+.br
+
+.br
+edge        0-2      0 = change to low (a falling edge)
+.br
+                     1 = change to high (a rising edge)
+.br
+                     2 = no level change (a watchdog timeout)
+.br
+
+.br
+tick        32 bit   The number of microseconds since boot
+.br
+                     WARNING: this wraps around from
+.br
+                     4294967295 to 0 roughly every 72 minutes
+.br
+
+.br
+userdata    pointer  Pointer to an arbitrary object
+.br
+
+.EE
+
 .IP "\fBint callback_cancel(unsigned callback_id)\fP"
 .IP "" 4
 This function cancels a callback identified by its id.
index 4219a4f239fc572d8c18af33b9c696ad342220fe..7802e579628e2dccad40ba5ed904dd060db5886c 100644 (file)
@@ -25,7 +25,7 @@ OTHER DEALINGS IN THE SOFTWARE.
 For more information, please refer to <http://unlicense.org/>
 */
 
-/* PIGPIOD_IF_VERSION 26 */
+/* PIGPIOD_IF_VERSION 27 */
 
 #include <stdio.h>
 #include <stdlib.h>
index 8714eab8a816541a33e200eef1405751919bfac1..e296ef01037f328dac305571e71bf3d51d2cbc02 100644 (file)
@@ -30,7 +30,7 @@ For more information, please refer to <http://unlicense.org/>
 
 #include "pigpio.h"
 
-#define PIGPIOD_IF_VERSION 26
+#define PIGPIOD_IF_VERSION 27
 
 /*TEXT
 
@@ -805,12 +805,10 @@ Only one watchdog may be registered per GPIO.
 
 The watchdog may be cancelled by setting timeout to 0.
 
-If no level change has been detected for the GPIO for timeout
-milliseconds any notification for the GPIO has a report written
-to the fifo with the flags set to indicate a watchdog timeout.
+Once a watchdog has been started callbacks for the GPIO will be
+triggered every timeout interval after the last GPIO activity.
 
-The [*callback*] and [*callback_ex*] functions interpret the flags
-and will call registered callbacks for the GPIO with level TIMEOUT.
+The callback will receive the special level PI_TIMEOUT.
 D*/
 
 /*F*/
@@ -830,7 +828,12 @@ user_gpio: 0-31
 
 Returns 0 if OK, otherwise PI_BAD_USER_GPIO, or PI_BAD_FILTER.
 
-Note, each (stable) edge will be timestamped [*steady*] microseconds
+This filter affects the GPIO samples returned to callbacks set up
+with [*callback*], [*callback_ex*] and [*wait_for_edge*].
+
+It does not affect levels read by [*gpio_read*],
+[*read_bank_1*], or [*read_bank_2*].
+Each (stable) edge will be timestamped [*steady*] microseconds
 after it was first detected.
 D*/
 
@@ -852,7 +855,13 @@ user_gpio: 0-31
 
 Returns 0 if OK, otherwise PI_BAD_USER_GPIO, or PI_BAD_FILTER.
 
-Note, level changes before and after the active period may
+This filter affects the GPIO samples returned to callbacks set up
+with [*callback*], [*callback_ex*] and [*wait_for_edge*].
+
+It does not affect levels read by [*gpio_read*],
+[*read_bank_1*], or [*read_bank_2*].
+
+Level changes before and after the active period may
 be reported.  Your software must be designed to cope with
 such reports.
 D*/
@@ -2194,6 +2203,22 @@ device only.
 bbbbbb defines the word size in bits (0-32).  The default (0)
 sets 8 bits per word.  Auxiliary SPI device only.
 
+The [*spi_read*], [*spi_write*], and [*spi_xfer*] functions
+transfer data packed into 1, 2, or 4 bytes according to
+the word size in bits.
+
+For bits 1-8 there will be one byte per word. 
+For bits 9-16 there will be two bytes per word. 
+For bits 17-32 there will be four bytes per word.
+
+Multi-byte transfers are made in least significant byte first order.
+
+E.g. to transfer 32 11-bit words buf should contain 64 bytes
+and count should be 64.
+
+E.g. to transfer the 14 bit value 0x1ABC send the bytes 0xBC followed
+by 0x1A.
+
 The other bits in flags should be set to zero.
 D*/
 
@@ -2428,6 +2453,20 @@ pigif_duplicate_callback, or pigif_bad_callback.
 
 The callback is called with the GPIO, edge, and tick, whenever the
 GPIO has the identified edge.
+
+. .
+Parameter   Value    Meaning
+
+GPIO        0-31     The GPIO which has changed state
+
+edge        0-2      0 = change to low (a falling edge)
+                     1 = change to high (a rising edge)
+                     2 = no level change (a watchdog timeout)
+
+tick        32 bit   The number of microseconds since boot
+                     WARNING: this wraps around from
+                     4294967295 to 0 roughly every 72 minutes
+. .
 D*/
 
 /*F*/
@@ -2449,6 +2488,21 @@ pigif_duplicate_callback, or pigif_bad_callback.
 The callback is called with the GPIO, edge, tick, and user, whenever
 the GPIO has the identified edge.
 
+. .
+Parameter   Value    Meaning
+
+GPIO        0-31     The GPIO which has changed state
+
+edge        0-2      0 = change to low (a falling edge)
+                     1 = change to high (a rising edge)
+                     2 = no level change (a watchdog timeout)
+
+tick        32 bit   The number of microseconds since boot
+                     WARNING: this wraps around from
+                     4294967295 to 0 roughly every 72 minutes
+
+userdata    pointer  Pointer to an arbitrary object
+. .
 D*/
 
 /*F*/
index d0d56a73514977dd18b674785822ed8820827739..5bb17ffcd2ecba596f8660950d218ab365ff2dcd 100644 (file)
@@ -2,7 +2,7 @@
 ." Process this file with
 ." groff -man -Tascii pigpiod_if2.3
 ."
-.TH pigpiod_if2 3 2012-2015 Linux "pigpio archive"
+.TH pigpiod_if2 3 2012-2017 Linux "pigpio archive"
 .SH NAME
 pigpiod_if2 - A C library to interface to the pigpio daemon.
 
@@ -1133,15 +1133,13 @@ The watchdog may be cancelled by setting timeout to 0.
 .br
 
 .br
-If no level change has been detected for the GPIO for timeout
-milliseconds any notification for the GPIO has a report written
-to the fifo with the flags set to indicate a watchdog timeout.
+Once a watchdog has been started callbacks for the GPIO will be
+triggered every timeout interval after the last GPIO activity.
 
 .br
 
 .br
-The \fBcallback\fP and \fBcallback_ex\fP functions interpret the flags
-and will call registered callbacks for the GPIO with level TIMEOUT.
+The callback will receive the special level PI_TIMEOUT.
 
 .IP "\fBint set_glitch_filter(int pi, unsigned user_gpio, unsigned steady)\fP"
 .IP "" 4
@@ -1177,7 +1175,19 @@ Returns 0 if OK, otherwise PI_BAD_USER_GPIO, or PI_BAD_FILTER.
 .br
 
 .br
-Note, each (stable) edge will be timestamped \fBsteady\fP microseconds
+This filter affects the GPIO samples returned to callbacks set up
+with \fBcallback\fP, \fBcallback_ex\fP and \fBwait_for_edge\fP.
+
+.br
+
+.br
+It does not affect levels read by \fBgpio_read\fP,
+\fBread_bank_1\fP, or \fBread_bank_2\fP.
+
+.br
+
+.br
+Each (stable) edge will be timestamped \fBsteady\fP microseconds
 after it was first detected.
 
 .IP "\fBint set_noise_filter(int pi, unsigned user_gpio, unsigned steady, unsigned active)\fP"
@@ -1216,7 +1226,19 @@ Returns 0 if OK, otherwise PI_BAD_USER_GPIO, or PI_BAD_FILTER.
 .br
 
 .br
-Note, level changes before and after the active period may
+This filter affects the GPIO samples returned to callbacks set up
+with \fBcallback\fP, \fBcallback_ex\fP and \fBwait_for_edge\fP.
+
+.br
+
+.br
+It does not affect levels read by \fBgpio_read\fP,
+\fBread_bank_1\fP, or \fBread_bank_2\fP.
+
+.br
+
+.br
+Level changes before and after the active period may
 be reported.  Your software must be designed to cope with
 such reports.
 
@@ -4208,11 +4230,22 @@ For bits 17-32 there will be four bytes per character.
 .br
 
 .br
-E.g. to transfer 32 12-bit words buf should contain 64 bytes
+Multi-byte transfers are made in least significant byte first order.
+
+.br
+
+.br
+E.g. to transfer 32 11-bit words buf should contain 64 bytes
 and count should be 64.
 
 .br
 
+.br
+E.g. to transfer the 14 bit value 0x1ABC send the bytes 0xBC followed
+by 0x1A.
+
+.br
+
 .br
 The other bits in flags should be set to zero.
 
@@ -5317,6 +5350,36 @@ pigif_duplicate_callback, or pigif_bad_callback.
 The callback is called with the GPIO, edge, and tick, whenever the
 GPIO has the identified edge.
 
+.br
+
+.br
+
+.EX
+Parameter   Value    Meaning
+.br
+
+.br
+GPIO        0-31     The GPIO which has changed state
+.br
+
+.br
+edge        0-2      0 = change to low (a falling edge)
+.br
+                     1 = change to high (a rising edge)
+.br
+                     2 = no level change (a watchdog timeout)
+.br
+
+.br
+tick        32 bit   The number of microseconds since boot
+.br
+                     WARNING: this wraps around from
+.br
+                     4294967295 to 0 roughly every 72 minutes
+.br
+
+.EE
+
 .IP "\fBint callback_ex(int pi, unsigned user_gpio, unsigned edge, CBFuncEx_t f, void *userdata)\fP"
 .IP "" 4
 This function initialises a new callback.
@@ -5351,6 +5414,40 @@ pigif_duplicate_callback, or pigif_bad_callback.
 The callback is called with the GPIO, edge, tick, and the userdata
 pointer, whenever the GPIO has the identified edge.
 
+.br
+
+.br
+
+.EX
+Parameter   Value    Meaning
+.br
+
+.br
+GPIO        0-31     The GPIO which has changed state
+.br
+
+.br
+edge        0-2      0 = change to low (a falling edge)
+.br
+                     1 = change to high (a rising edge)
+.br
+                     2 = no level change (a watchdog timeout)
+.br
+
+.br
+tick        32 bit   The number of microseconds since boot
+.br
+                     WARNING: this wraps around from
+.br
+                     4294967295 to 0 roughly every 72 minutes
+.br
+
+.br
+userdata    pointer  Pointer to an arbitrary object
+.br
+
+.EE
+
 .IP "\fBint callback_cancel(unsigned callback_id)\fP"
 .IP "" 4
 This function cancels a callback identified by its id.
index 86b779ab430669a3d349d07083e9ec2f67f4e5ab..d56fd61cb50a95934c1112b73fe1b6a1b23b7977 100644 (file)
@@ -25,7 +25,7 @@ OTHER DEALINGS IN THE SOFTWARE.
 For more information, please refer to <http://unlicense.org/>
 */
 
-/* PIGPIOD_IF2_VERSION 10 */
+/* PIGPIOD_IF2_VERSION 11 */
 
 #include <stdio.h>
 #include <stdlib.h>
index 73eb0e8ab19f15f379ae0f30b66410c06cdc942f..d8a5b8a7b42fca0367d22c4848c459fe9a791560 100644 (file)
@@ -30,7 +30,7 @@ For more information, please refer to <http://unlicense.org/>
 
 #include "pigpio.h"
 
-#define PIGPIOD_IF2_VERSION 10
+#define PIGPIOD_IF2_VERSION 11
 
 /*TEXT
 
@@ -879,12 +879,10 @@ Only one watchdog may be registered per GPIO.
 
 The watchdog may be cancelled by setting timeout to 0.
 
-If no level change has been detected for the GPIO for timeout
-milliseconds any notification for the GPIO has a report written
-to the fifo with the flags set to indicate a watchdog timeout.
+Once a watchdog has been started callbacks for the GPIO will be
+triggered every timeout interval after the last GPIO activity.
 
-The [*callback*] and [*callback_ex*] functions interpret the flags
-and will call registered callbacks for the GPIO with level TIMEOUT.
+The callback will receive the special level PI_TIMEOUT.
 D*/
 
 /*F*/
@@ -905,7 +903,13 @@ user_gpio: 0-31
 
 Returns 0 if OK, otherwise PI_BAD_USER_GPIO, or PI_BAD_FILTER.
 
-Note, each (stable) edge will be timestamped [*steady*] microseconds
+This filter affects the GPIO samples returned to callbacks set up
+with [*callback*], [*callback_ex*] and [*wait_for_edge*].
+
+It does not affect levels read by [*gpio_read*],
+[*read_bank_1*], or [*read_bank_2*].
+
+Each (stable) edge will be timestamped [*steady*] microseconds
 after it was first detected.
 D*/
 
@@ -929,7 +933,13 @@ user_gpio: 0-31
 
 Returns 0 if OK, otherwise PI_BAD_USER_GPIO, or PI_BAD_FILTER.
 
-Note, level changes before and after the active period may
+This filter affects the GPIO samples returned to callbacks set up
+with [*callback*], [*callback_ex*] and [*wait_for_edge*].
+
+It does not affect levels read by [*gpio_read*],
+[*read_bank_1*], or [*read_bank_2*].
+
+Level changes before and after the active period may
 be reported.  Your software must be designed to cope with
 such reports.
 D*/
@@ -2631,9 +2641,14 @@ For bits 1-8 there will be one byte per character.
 For bits 9-16 there will be two bytes per character. 
 For bits 17-32 there will be four bytes per character.
 
-E.g. to transfer 32 12-bit words buf should contain 64 bytes
+Multi-byte transfers are made in least significant byte first order.
+
+E.g. to transfer 32 11-bit words buf should contain 64 bytes
 and count should be 64.
 
+E.g. to transfer the 14 bit value 0x1ABC send the bytes 0xBC followed
+by 0x1A.
+
 The other bits in flags should be set to zero.
 D*/
 
@@ -3247,6 +3262,20 @@ pigif_duplicate_callback, or pigif_bad_callback.
 
 The callback is called with the GPIO, edge, and tick, whenever the
 GPIO has the identified edge.
+
+. .
+Parameter   Value    Meaning
+
+GPIO        0-31     The GPIO which has changed state
+
+edge        0-2      0 = change to low (a falling edge)
+                     1 = change to high (a rising edge)
+                     2 = no level change (a watchdog timeout)
+
+tick        32 bit   The number of microseconds since boot
+                     WARNING: this wraps around from
+                     4294967295 to 0 roughly every 72 minutes
+. .
 D*/
 
 /*F*/
@@ -3268,6 +3297,22 @@ pigif_duplicate_callback, or pigif_bad_callback.
 
 The callback is called with the GPIO, edge, tick, and the userdata
 pointer, whenever the GPIO has the identified edge.
+
+. .
+Parameter   Value    Meaning
+
+GPIO        0-31     The GPIO which has changed state
+
+edge        0-2      0 = change to low (a falling edge)
+                     1 = change to high (a rising edge)
+                     2 = no level change (a watchdog timeout)
+
+tick        32 bit   The number of microseconds since boot
+                     WARNING: this wraps around from
+                     4294967295 to 0 roughly every 72 minutes
+
+userdata    pointer  Pointer to an arbitrary object
+. .
 D*/
 
 /*F*/
diff --git a/pigs.1 b/pigs.1
index d909863608af7d7ff283ddac9fca7bca85ba3912..ff7b85513e14c731d13fa03e56f963d8d5efd276 100644 (file)
--- a/pigs.1
+++ b/pigs.1
@@ -2,7 +2,7 @@
 ." Process this file with
 ." groff -man -Tascii foo.1
 ."
-.TH pigs 1 2012-2015 Linux "pigpio archive"
+.TH pigs 1 2012-2017 Linux "pigpio archive"
 .SH NAME
 pigs - command line socket access to the pigpio daemon.
 
@@ -1079,6 +1079,12 @@ has been stable for at least \fBstdy\fP microseconds.  The
 level is then reported.  Level changes of less than \fBstdy\fP
 microseconds are ignored.
 
+.br
+The filter only affects callbacks (including pipe notifications).
+
+.br
+The \fBR/READ\fP, \fBBR1\fP, and \fBBR2\fP commands are not affected.
+
 .br
 Note, each (stable) edge will be timestamped \fBstdy\fP microseconds
 after it was first detected.
@@ -1160,6 +1166,12 @@ been stable for \fBstdy\fP microseconds is detected.  Level
 changes on the GPIO are then reported for \fBactv\fP microseconds
 after which the process repeats.
 
+.br
+The filter only affects callbacks (including pipe notifications).
+
+.br
+The \fBR/READ\fP, \fBBR1\fP, and \fBBR2\fP commands are not affected.
+
 .br
 Note, level changes before and after the active period may
 be reported.  Your software must be designed to cope with
@@ -3957,7 +3969,14 @@ For bits 9-16 there will be two bytes per character.
 For bits 17-32 there will be four bytes per character.
 
 .br
-E.g. 32 12-bit words will be transferred in 64 bytes.
+Multi-byte transfers are made in least significant byte first order.
+
+.br
+E.g. to transfer 32 11-bit words 64 bytes need to be sent.
+
+.br
+E.g. to transfer the 14 bit value 0x1ABC send the bytes 0xBC followed
+by 0x1A.
 
 .br
 The other bits in flags should be set to zero.
@@ -4183,11 +4202,10 @@ One watchdog may be registered per GPIO.
 The watchdog may be cancelled by setting timeout to 0.
 
 .br
-If no level change has been detected for the GPIO for timeout milliseconds:-
-
-.br
-any notification for the GPIO has a report written to the fifo with
-the flags set to indicate a watchdog timeout.
+Once a watchdog has been started monitors of the GPIO
+will be triggered every timeout interval after the last
+GPIO activity.  The watchdog expiry will be indicated by
+a special TIMEOUT value.
 
 .br
 
index 06f11b04ce04c18fc98f5c9677afcfca6867d75f..226543d7390f61158b00f48ed95ec4cf92131015 100644 (file)
--- a/setup.py
+++ b/setup.py
@@ -3,7 +3,7 @@
 from distutils.core import setup
 
 setup(name='pigpio',
-      version='1.35',
+      version='1.37',
       author='joan',
       author_email='joan@abyz.co.uk',
       maintainer='joan',
index 5431301608c47d0213d98c70a6e1ad297620b873..f98368732f5b952d80325cb1871765dd36c2a1b2 100644 (file)
@@ -282,15 +282,13 @@ void t4()
    gpioSetPWMrange(GPIO, 100);
 
    h = gpioNotifyOpen();
-   e = gpioNotifyBegin(h, (1<<GPIO));
-   CHECK(4, 1, e, 0, 0, "notify open/begin");
-
-   time_sleep(1);
 
    sprintf(p, "/dev/pigpio%d", h);
-
    f = open(p, O_RDONLY);
 
+   e = gpioNotifyBegin(h, (1<<GPIO));
+   CHECK(4, 1, e, 0, 0, "notify open/begin");
+
    gpioPWM(GPIO, 50);
    time_sleep(4);
    gpioPWM(GPIO, 0);
index cc58d2f24f47bb60436121a06150926e81bdf32d..94f2045e1ba6e1225d28fbcf19b54ebb23d7577a 100644 (file)
@@ -253,15 +253,13 @@ void t4()
    set_PWM_range(GPIO, 100);
 
    h = notify_open();
-   e = notify_begin(h, (1<<GPIO));
-   CHECK(4, 1, e, 0, 0, "notify open/begin");
-
-   time_sleep(1);
 
    sprintf(p, "/dev/pigpio%d", h);
-
    f = open(p, O_RDONLY);
 
+   e = notify_begin(h, (1<<GPIO));
+   CHECK(4, 1, e, 0, 0, "notify open/begin");
+
    set_PWM_dutycycle(GPIO, 50);
    time_sleep(4);
    set_PWM_dutycycle(GPIO, 0);
index 8747c1a8660c9e9efb098b0ed4f02461d5889291..b5a6546f7a4fb18df1aaf6414d06c0585f34f6e6 100644 (file)
@@ -257,15 +257,13 @@ void t4(int pi)
    set_PWM_range(pi, GPIO, 100);
 
    h = notify_open(pi);
-   e = notify_begin(pi, h, (1<<GPIO));
-   CHECK(4, 1, e, 0, 0, "notify open/begin");
-
-   time_sleep(1);
 
    sprintf(p, "/dev/pigpio%d", h);
-
    f = open(p, O_RDONLY);
 
+   e = notify_begin(pi, h, (1<<GPIO));
+   CHECK(4, 1, e, 0, 0, "notify open/begin");
+
    set_PWM_dutycycle(pi, GPIO, 50);
    time_sleep(4);
    set_PWM_dutycycle(pi, GPIO, 0);