I'm using pigpio bit-banging script (download, GitHub) that interprets the pulse durations generated by the DH22 Temperature/Humidity sensor. It sets a 200 ms pigpio watchdog to the GPIO pin and attaches a callback, passing the tick count and new level.
Here's a generic example:
def cbf(gpio, level, tick):
print(gpio, level, tick)
pi.set_watchdog(22, 1000) # 1000 ms watchdog on GPIO 22
cb1 = pi.callback(22, pigpio.EITHER_EDGE, cbf)
For the next 1000 milliseconds, a transition in either direction on pin 22 will result in a call to cbf()
, passing the new level and the tick number (microseconds).
If I understand correctly, in pigpio one can set up one watchdog per GPIO pin, so there could in principle be many running at the same time.
My question is what are these watchdogs? Are they CPU threads, or are they running in the GPIO electronics itself, or something else? Like real dogs, can they compete, conflict, or collide (say two watchdogged GPIO pins experience edges at exactly the same time), or do they get along nicely with each other?
This is from pigpio.c
and may be of some help:
int gpioSetWatchdog(unsigned gpio, unsigned timeout)
{
DBG(DBG_USER, "gpio=%d timeout=%d", gpio, timeout);
CHECK_INITED;
if (gpio > PI_MAX_USER_GPIO)
SOFT_ERROR(PI_BAD_USER_GPIO, "bad gpio (%d)", gpio);
if (timeout > PI_MAX_WDOG_TIMEOUT)
SOFT_ERROR(PI_BAD_WDOG_TIMEOUT,
"gpio %d, bad timeout (%d)", gpio, timeout);
gpioAlert[gpio].wdTick = systReg[SYST_CLO];
gpioAlert[gpio].wdSteadyUs = timeout*1000;
if (timeout) wdogBits |= (1<<gpio);
else wdogBits &= (~(1<<gpio));
return 0;