Hi,

i tested gpioow on beaglebone black a few days ago, and when i was lazy
to fix the 'cables' my sensors were attached to, console was spammed
over night by some of the sensors.
i found the hotplug spam+disappearing sensors annoying.

if i read gpioctl(8) correctly, i should be able to pass these flags like
"gpioctl gpio1 attach gpioow 16 0x01 [flags]" ?

yet untested diff below showing what i think i'm missing,
and for which any input would be much appreciated by those familiar with
gpioow(4)i/sensors frsmrwork, or anyone w/comments generally :)

-Artturi


diff --git sys/dev/onewire/onewire.c sys/dev/onewire/onewire.c
index 679bcd90e85..263f65ab674 100644
--- sys/dev/onewire/onewire.c
+++ sys/dev/onewire/onewire.c
@@ -434,8 +434,11 @@ onewire_scan(struct onewire_softc *sc)
         * scanning. This allows to find out later which devices
         * have been disappeared.
         */
-       TAILQ_FOREACH(d, &sc->sc_devs, d_list)
+       TAILQ_FOREACH(d, &sc->sc_devs, d_list) {
+               if (sc->sc_flags & ONEWIRE_NO_DETACH)
+                       break;
                d->d_present = 0;
+       }
 
        /*
         * Reset the bus. If there's no presence pulse don't search
@@ -497,3 +500,11 @@ out:
                }
        }
 }
+
+int
+onewire_quirks(void *arg)
+{
+       struct onewire_softc *sc = arg;
+
+       return (sc->sc_flags & ONEWIRE_TIMESTAMP);
+}
diff --git sys/dev/onewire/onewirevar.h sys/dev/onewire/onewirevar.h
index ab3776f50bf..673e0d7e7b2 100644
--- sys/dev/onewire/onewirevar.h
+++ sys/dev/onewire/onewirevar.h
@@ -51,6 +51,7 @@ void          onewire_write_block(void *, const void *, int);
 int            onewire_triplet(void *, int);
 void           onewire_matchrom(void *, u_int64_t);
 int            onewire_search(void *, u_int64_t *, int, u_int64_t);
+int            onewire_quirks(void *);
 
 #define ONEWIRE_NOWAIT         0x0001
 
@@ -60,6 +61,8 @@ struct onewirebus_attach_args {
        int                     oba_flags;
 #define        ONEWIRE_SCAN_NOW                0x0001
 #define        ONEWIRE_NO_PERIODIC_SCAN        0x0002
+#define        ONEWIRE_NO_DETACH               0x0004
+#define        ONEWIRE_TIMESTAMP               0x0008
 };
 
 int    onewirebus_print(void *, const char *);
diff --git sys/dev/onewire/owtemp.c sys/dev/onewire/owtemp.c
index e883dbb17a9..e21862889e3 100644
--- sys/dev/onewire/owtemp.c
+++ sys/dev/onewire/owtemp.c
@@ -26,6 +26,7 @@
 #include <sys/kernel.h>
 #include <sys/rwlock.h>
 #include <sys/sensors.h>
+#include <sys/time.h>
 
 #include <dev/onewire/onewiredevs.h>
 #include <dev/onewire/onewirereg.h>
@@ -50,8 +51,10 @@ struct owtemp_softc {
 
        void *                  sc_onewire;
        u_int64_t               sc_rom;
+       time_t                  sc_timestamp;
 
        struct ksensor          sc_sensor;
+       struct ksensor          *sc_sensor_td;
        struct ksensordev       sc_sensordev;
        struct sensor_task      *sc_sensortask;
        struct rwlock           sc_lock;
@@ -104,12 +107,25 @@ owtemp_attach(struct device *parent, struct device *self, 
void *aux)
        snprintf(sc->sc_sensor.desc, sizeof(sc->sc_sensor.desc), "sn %012llx",
            ONEWIRE_ROM_SN(oa->oa_rom));
 
+       if (onewire_quirks(sc->sc_onewire) & ONEWIRE_TIMESTAMP) {
+               sc->sc_sensor_td = malloc(sizeof(struct onewire_device),
+                   M_DEVBUF, M_NOWAIT);
+               if (sc->sc_sensor_td) {
+                       sc->sc_sensor_td->type = SENSOR_TIMEDELTA;
+                       strlcpy(sc->sc_sensor_td->desc, "LastUpdate",
+                           sizeof(sc->sc_sensor_td->desc));
+               }
+       }
+       sc_timestamp = 0;
+
        sc->sc_sensortask = sensor_task_register(sc, owtemp_update, 5);
        if (sc->sc_sensortask == NULL) {
                printf(": unable to register update task\n");
                return;
        }
        sensor_attach(&sc->sc_sensordev, &sc->sc_sensor);
+       if (sc->sc_sensor_td)
+               sensor_attach(&sc->sc_sensordev, sc->sc_sensor_td);
        sensordev_install(&sc->sc_sensordev);
 
        rw_init(&sc->sc_lock, sc->sc_dev.dv_xname);
@@ -146,6 +162,13 @@ owtemp_update(void *arg)
 
        rw_enter_write(&sc->sc_lock);
        onewire_lock(sc->sc_onewire, 0);
+
+       /* Update timedelta of last successful reading */
+       if (sc->sc_sensor_td != NULL && sc_timestamp != 0) {
+               sc->sc_sensor_td->value = time_second - sc->sc_timestamp;
+               sc->sc_sensor_td->value *= 1000000000LL;
+       }
+
        if (onewire_reset(sc->sc_onewire) != 0)
                goto done;
        onewire_matchrom(sc->sc_onewire, sc->sc_rom);
@@ -196,6 +219,8 @@ owtemp_update(void *arg)
                        }
                }
                sc->sc_sensor.value = 273150000 + val;
+               if (sc->sc_sensor_td != NULL)
+                       sc->sc_timestamp = time_second;
        }
 
 done:

Reply via email to