Commit 22acc120 authored by Harald Geyer's avatar Harald Geyer Committed by Jonathan Cameron

iio: dht11: Improve reliability - be more tolerant about missing start bits

Instead of guessing where the data starts, we now just try to decode from
every possible start position. This causes no additional overhead if we
properly received the full preamble and only costs a few extra CPU cycles
in the case where the preamble is corrupted. This is much more efficient
than to return an error to userspace and start over again.
Signed-off-by: default avatarHarald Geyer <harald@ccbib.org>
Signed-off-by: default avatarJonathan Cameron <jic23@kernel.org>
parent c984b9cb
...@@ -161,7 +161,7 @@ static int dht11_read_raw(struct iio_dev *iio_dev, ...@@ -161,7 +161,7 @@ static int dht11_read_raw(struct iio_dev *iio_dev,
int *val, int *val2, long m) int *val, int *val2, long m)
{ {
struct dht11 *dht11 = iio_priv(iio_dev); struct dht11 *dht11 = iio_priv(iio_dev);
int ret, timeres; int ret, timeres, offset;
mutex_lock(&dht11->lock); mutex_lock(&dht11->lock);
if (dht11->timestamp + DHT11_DATA_VALID_TIME < ktime_get_real_ns()) { if (dht11->timestamp + DHT11_DATA_VALID_TIME < ktime_get_real_ns()) {
...@@ -208,11 +208,14 @@ static int dht11_read_raw(struct iio_dev *iio_dev, ...@@ -208,11 +208,14 @@ static int dht11_read_raw(struct iio_dev *iio_dev,
if (ret < 0) if (ret < 0)
goto err; goto err;
ret = dht11_decode(dht11, offset = DHT11_EDGES_PREAMBLE +
dht11->num_edges == DHT11_EDGES_PER_READ ? dht11->num_edges - DHT11_EDGES_PER_READ;
DHT11_EDGES_PREAMBLE : for (; offset >= 0; --offset) {
DHT11_EDGES_PREAMBLE - 2, ret = dht11_decode(dht11, offset, timeres);
timeres); if (!ret)
break;
}
if (ret) if (ret)
goto err; goto err;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment