On Wed, Mar 07, 2018 at 06:26:15AM +0200, Artturi Alm wrote:
> 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
>
so this does lower the bar for owtemp(4) to be more easily usable/reliable
via sysctl(8) alone in some simple script or w/e(sensor will be there,
and w/timedelta one can decide whether to use the value or not).
besides the obvious copy-paste-bugs in the previous draft,
i missed how gpioow(4) didn't pass the flags to onewire(4) oba_flags.
diff below does work good enough for my use, and i don't care about the
inherent 5sec 'lag' on timedelta enough to make the diff any bigger.
rc.securelevel:
gpioctl gpio1 attach gpioow 16 1 12
root@av7bbb:~ # sysctl hw.sensors
hw.sensors.owtemp0.temp0=30.56 degC (sn 0000025f07aa)
hw.sensors.owtemp0.timedelta0=5.000000 secs (LastUpdate)
hw.sensors.owtemp1.temp0=30.88 degC (sn 0000025ecdb5)
hw.sensors.owtemp1.timedelta0=5.000000 secs (LastUpdate)
hw.sensors.owtemp2.temp0=30.50 degC (sn 0000025f13ad)
hw.sensors.owtemp2.timedelta0=5.000000 secs (LastUpdate)
-Artturi
diff --git sys/dev/gpio/gpioow.c sys/dev/gpio/gpioow.c
index 64d79ab0cb8..f7b7eb83e4b 100644
--- sys/dev/gpio/gpioow.c
+++ sys/dev/gpio/gpioow.c
@@ -147,6 +147,7 @@ gpioow_attach(struct device *parent, struct device *self,
void *aux)
bzero(&oba, sizeof(oba));
oba.oba_bus = &sc->sc_ow_bus;
+ oba.oba_flags = ga->ga_flags;
sc->sc_ow_dev = config_found(self, &oba, onewirebus_print);
return;
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..4c7615ab1ef 100644
--- sys/dev/onewire/owtemp.c
+++ sys/dev/onewire/owtemp.c
@@ -24,8 +24,10 @@
#include <sys/systm.h>
#include <sys/device.h>
#include <sys/kernel.h>
+#include <sys/malloc.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 +52,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 +108,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 ksensor),
+ M_DEVBUF, M_NOWAIT|M_ZERO);
+ 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->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 +163,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->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 +220,8 @@ owtemp_update(void *arg)
}
}
sc->sc_sensor.value = 273150000 + val;
+ if (sc->sc_sensor_td != NULL)
+ sc->sc_timestamp = time_second;
}
done: