diff options
author | cheloha <cheloha@cvs.openbsd.org> | 2019-08-10 18:18:28 +0000 |
---|---|---|
committer | cheloha <cheloha@cvs.openbsd.org> | 2019-08-10 18:18:28 +0000 |
commit | 68be81cf031973eb77a0331348c22e32d668f818 (patch) | |
tree | 573e504431bd9f2fc438da366be945184cf2a442 /sys/dev/gpio | |
parent | 1cfc81a82427c3e0818236632f8ec97ba19742d4 (diff) |
gpiodcf(4): tvtohz(9)+timeout_add(9) -> timeout_add_msec(9)
"looks fine" kettenis@, ok deraadt@
Diffstat (limited to 'sys/dev/gpio')
-rw-r--r-- | sys/dev/gpio/gpiodcf.c | 75 |
1 files changed, 21 insertions, 54 deletions
diff --git a/sys/dev/gpio/gpiodcf.c b/sys/dev/gpio/gpiodcf.c index 68f9aceeba0..ef4ef55ad0b 100644 --- a/sys/dev/gpio/gpiodcf.c +++ b/sys/dev/gpio/gpiodcf.c @@ -1,4 +1,4 @@ -/* $OpenBSD: gpiodcf.c,v 1.6 2017/12/30 20:46:59 guenther Exp $ */ +/* $OpenBSD: gpiodcf.c,v 1.7 2019/08/10 18:18:27 cheloha Exp $ */ /* * Copyright (c) 2008 Marc Balmer <mbalmer@openbsd.org> @@ -39,9 +39,6 @@ int gpiodcfdebug = 0; #endif #define DPRINTF(x) DPRINTFN(0, x) -#define DPERIOD1 ((long) 5 * 60) /* degrade OK -> WARN */ -#define DPERIOD2 ((long) 15 * 60) /* degrade WARN -> CRIT */ - /* max. skew of received time diff vs. measured time diff in percent. */ #define MAX_SKEW 5 @@ -83,17 +80,16 @@ struct gpiodcf_softc { }; /* - * timeouts being used in hz: - * t_bv bit value detection (150ms) - * t_sync sync (950ms) - * t_mg minute gap detection (1500ms) - * t_mgsync resync after a minute gap (450ms) - * t_sl detect signal loss (3sec) - * t_wait wait (5sec) - * t_warn degrade sensor status to warning (5min) - * t_crit degrade sensor status to critical (15min) + * timeouts used: */ -static int t_bv, t_sync, t_mg, t_sl, t_mgsync, t_wait, t_warn, t_crit; +#define T_BV 150 /* bit value detection (150ms) */ +#define T_SYNC 950 /* sync (950ms) */ +#define T_MG 1500 /* minute gap detection (1500ms) */ +#define T_MGSYNC 450 /* resync after a minute gap (450ms) */ +#define T_SL 3000 /* detect signal loss (3sec) */ +#define T_WAIT 5000 /* wait (5sec) */ +#define T_WARN 300000 /* degrade sensor status to warning (5min) +#define T_CRIT 900000 /* degrade sensor status to critical (15min) */ void gpiodcf_intr(void *); void gpiodcf_probe(void *); @@ -138,7 +134,6 @@ gpiodcf_attach(struct device *parent, struct device *self, void *aux) { struct gpiodcf_softc *sc = (struct gpiodcf_softc *)self; struct gpio_attach_args *ga = aux; - struct timeval t; int caps; if (gpio_npins(ga->ga_mask) != GPIODCF_NPINS) { @@ -199,39 +194,11 @@ gpiodcf_attach(struct device *parent, struct device *self, void *aux) sc->sc_last = 0L; sc->sc_last_tv.tv_sec = 0L; - /* convert timevals to hz */ - t.tv_sec = 0L; - t.tv_usec = 150000L; - t_bv = tvtohz(&t); - - t.tv_usec = 450000L; - t_mgsync = tvtohz(&t); - - t.tv_usec = 950000L; - t_sync = tvtohz(&t); - - t.tv_sec = 1L; - t.tv_usec = 500000L; - t_mg = tvtohz(&t); - - t.tv_sec = 3L; - t.tv_usec = 0L; - t_sl = tvtohz(&t); - - t.tv_sec = 5L; - t_wait = tvtohz(&t); - - t.tv_sec = DPERIOD1; - t_warn = tvtohz(&t); - - t.tv_sec = DPERIOD2; - t_crit = tvtohz(&t); - /* Give the receiver some slack to stabilize */ - timeout_add(&sc->sc_to, t_wait); + timeout_add_msec(&sc->sc_to, T_WAIT); /* Detect signal loss */ - timeout_add(&sc->sc_sl_to, t_wait + t_sl); + timeout_add_msec(&sc->sc_sl_to, T_WAIT + T_SL); DPRINTF(("synchronizing\n")); return; @@ -321,20 +288,20 @@ gpiodcf_probe(void *xsc) * during the next 5 minutes, the sensor state * will be degraded to SENSOR_S_WARN */ - timeout_add(&sc->sc_it_to, t_warn); + timeout_add_msec(&sc->sc_it_to, T_WARN); } sc->sc_minute = 0; } - timeout_add(&sc->sc_to, t_sync); /* resync in 950 ms */ + timeout_add_msec(&sc->sc_to, T_SYNC); /* resync in 950 ms */ /* no clock and bit detection during sync */ if (!sc->sc_sync) { /* detect bit value */ - timeout_add(&sc->sc_bv_to, t_bv); + timeout_add_msec(&sc->sc_bv_to, T_BV); } - timeout_add(&sc->sc_mg_to, t_mg); /* detect minute gap */ - timeout_add(&sc->sc_sl_to, t_sl); /* detect signal loss */ + timeout_add_msec(&sc->sc_mg_to, T_MG); /* detect minute gap */ + timeout_add_msec(&sc->sc_sl_to, T_SL); /* detect signal loss */ } /* detect the bit value */ @@ -489,7 +456,7 @@ gpiodcf_mg_probe(void *xsc) } cleanbits: - timeout_add(&sc->sc_to, t_mgsync); /* re-sync in 450 ms */ + timeout_add_msec(&sc->sc_to, T_MGSYNC); /* re-sync in 450 ms */ sc->sc_last_mg = time_second; sc->sc_tbits = 0LL; sc->sc_mask = 1LL; @@ -506,8 +473,8 @@ gpiodcf_sl_probe(void *xsc) DPRINTF(("no signal\n")); sc->sc_sync = 1; - timeout_add(&sc->sc_to, t_wait); - timeout_add(&sc->sc_sl_to, t_wait + t_sl); + timeout_add_msec(&sc->sc_to, T_WAIT); + timeout_add_msec(&sc->sc_sl_to, T_WAIT + T_SL); } /* invalidate timedelta (called in an interrupt context) */ @@ -525,7 +492,7 @@ gpiodcf_invalidate(void *xsc) * further degrade in 15 minutes if we dont receive any new * time information */ - timeout_add(&sc->sc_it_to, t_crit); + timeout_add_msec(&sc->sc_it_to, T_CRIT); } else { sc->sc_sensor.status = SENSOR_S_CRIT; sc->sc_nrecv = 0; |