diff --git a/pig2vcd.1 b/pig2vcd.1 index 24b5a6c..b2c64b4 100644 --- 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. diff --git a/pigpio.3 b/pigpio.3 index e33dde6..b5979ff 100644 --- 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 function is passed the GPIO, the new level, and the tick. +The callback is passed the GPIO, the new level, and the tick. + +.br + +.br + +.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 + +.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 + +.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. + +.br + .br Only one of \fBgpioSetAlertFunc\fP or \fBgpioSetAlertFuncEx\fP can be registered per GPIO. -.br - -.br -See \fBgpioSetAlertFunc\fP for further details. - -.IP "\fBint gpioSetISRFunc(unsigned user_gpio, unsigned edge, int timeout, gpioISRFunc_t f)\fP" +.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 character. +For bits 9-16 there will be two bytes per word. .br -For bits 17-32 there will be four bytes per character. +For bits 17-32 there will be four bytes per word. .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. @@ -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 -2) any notification for the GPIO has a report written to the + +.br +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" diff --git a/pigpio.c b/pigpio.c index 8310e31..bc2e646 100644 --- a/pigpio.c +++ b/pigpio.c @@ -25,7 +25,7 @@ OTHER DEALINGS IN THE SOFTWARE. For more information, please refer to */ -/* 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_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_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; ipthIdp = 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 #include #include -#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 function is passed the GPIO, the new level, and the tick. +The callback is passed the GPIO, the new 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 +. . 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. +. . +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. - -See [*gpioSetAlertFunc*] for further details. 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. -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 +In particular: + +1) any registered alert function for the GPIO will be called with + the level set to PI_TIMEOUT. + +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*/ diff --git a/pigpio.py b/pigpio.py index 517943f..3ee6349 100644 --- 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): diff --git a/pigpiod.1 b/pigpiod.1 index e7fef5a..d677a88 100644 --- 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. diff --git a/pigpiod_if.3 b/pigpiod_if.3 index 2fe7ed2..5c5cb0f 100644 --- a/pigpiod_if.3 +++ b/pigpiod_if.3 @@ -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. diff --git a/pigpiod_if.c b/pigpiod_if.c index 4219a4f..7802e57 100644 --- a/pigpiod_if.c +++ b/pigpiod_if.c @@ -25,7 +25,7 @@ OTHER DEALINGS IN THE SOFTWARE. For more information, please refer to */ -/* PIGPIOD_IF_VERSION 26 */ +/* PIGPIOD_IF_VERSION 27 */ #include #include diff --git a/pigpiod_if.h b/pigpiod_if.h index 8714eab..e296ef0 100644 --- a/pigpiod_if.h +++ b/pigpiod_if.h @@ -30,7 +30,7 @@ For more information, please refer to #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*/ diff --git a/pigpiod_if2.3 b/pigpiod_if2.3 index d0d56a7..5bb17ff 100644 --- a/pigpiod_if2.3 +++ b/pigpiod_if2.3 @@ -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. diff --git a/pigpiod_if2.c b/pigpiod_if2.c index 86b779a..d56fd61 100644 --- a/pigpiod_if2.c +++ b/pigpiod_if2.c @@ -25,7 +25,7 @@ OTHER DEALINGS IN THE SOFTWARE. For more information, please refer to */ -/* PIGPIOD_IF2_VERSION 10 */ +/* PIGPIOD_IF2_VERSION 11 */ #include #include diff --git a/pigpiod_if2.h b/pigpiod_if2.h index 73eb0e8..d8a5b8a 100644 --- a/pigpiod_if2.h +++ b/pigpiod_if2.h @@ -30,7 +30,7 @@ For more information, please refer to #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 d909863..ff7b855 100644 --- 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 diff --git a/setup.py b/setup.py index 06f11b0..226543d 100644 --- 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', diff --git a/x_pigpio.c b/x_pigpio.c index 5431301..f983687 100644 --- a/x_pigpio.c +++ b/x_pigpio.c @@ -282,15 +282,13 @@ void t4() gpioSetPWMrange(GPIO, 100); h = gpioNotifyOpen(); - e = gpioNotifyBegin(h, (1<