linux-iio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCHv2 1/3] iio: dht11: Improve reliability - be more tolerant about missing start bits
@ 2016-01-17 16:13 Harald Geyer
  2016-01-17 16:13 ` [PATCHv2 2/3] iio: dht11: Simplify decoding algorithm Harald Geyer
                   ` (2 more replies)
  0 siblings, 3 replies; 8+ messages in thread
From: Harald Geyer @ 2016-01-17 16:13 UTC (permalink / raw)
  To: linux-iio, Jonathan Cameron, Jonathan Bell
  Cc: Richard Weinberger, Harald Geyer

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: Harald Geyer <harald@ccbib.org>
---
No changes since V1, but compile tested the entire series patch by patch
additionally to test the whole series with DHT11 and DHT22 on an
imx233-olinuxino board.

 drivers/iio/humidity/dht11.c | 15 +++++++++------
 1 file changed, 9 insertions(+), 6 deletions(-)

diff --git a/drivers/iio/humidity/dht11.c b/drivers/iio/humidity/dht11.c
index 1165b1c..1ca284a 100644
--- a/drivers/iio/humidity/dht11.c
+++ b/drivers/iio/humidity/dht11.c
@@ -161,7 +161,7 @@ static int dht11_read_raw(struct iio_dev *iio_dev,
 			int *val, int *val2, long m)
 {
 	struct dht11 *dht11 = iio_priv(iio_dev);
-	int ret, timeres;
+	int ret, timeres, offset;
 
 	mutex_lock(&dht11->lock);
 	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,
 		if (ret < 0)
 			goto err;
 
-		ret = dht11_decode(dht11,
-				   dht11->num_edges == DHT11_EDGES_PER_READ ?
-					DHT11_EDGES_PREAMBLE :
-					DHT11_EDGES_PREAMBLE - 2,
-				timeres);
+		offset = DHT11_EDGES_PREAMBLE +
+				dht11->num_edges - DHT11_EDGES_PER_READ;
+		for (; offset >= 0; --offset) {
+			ret = dht11_decode(dht11, offset, timeres);
+			if (!ret)
+				break;
+		}
+
 		if (ret)
 			goto err;
 	}
-- 
2.1.4


^ permalink raw reply related	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2016-04-10 16:40 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-01-17 16:13 [PATCHv2 1/3] iio: dht11: Improve reliability - be more tolerant about missing start bits Harald Geyer
2016-01-17 16:13 ` [PATCHv2 2/3] iio: dht11: Simplify decoding algorithm Harald Geyer
2016-01-24 16:59   ` Jonathan Cameron
2016-01-17 16:13 ` [PATCHv2 3/3] iio: dht11: Improve logging Harald Geyer
2016-01-24 16:59   ` Jonathan Cameron
2016-04-10 15:22     ` Harald Geyer
2016-04-10 16:40       ` Jonathan Cameron
2016-01-24 16:58 ` [PATCHv2 1/3] iio: dht11: Improve reliability - be more tolerant about missing start bits Jonathan Cameron

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).