From 5d14306e3c5586233f74d0a6080c906b9305ea81 Mon Sep 17 00:00:00 2001 From: smckown Date: Tue, 16 Sep 2008 14:17:50 +0000 Subject: [PATCH] Incorporate a BusyWait interface for allowing platforms to override the timing control necessary when bit-banging the SHT1X clock. --- tos/chips/sht11/SensirionBusyWaitC.nc | 48 +++++++++++++++++++++++++ tos/chips/sht11/SensirionSht11LogicP.nc | 10 ++++++ 2 files changed, 58 insertions(+) create mode 100644 tos/chips/sht11/SensirionBusyWaitC.nc diff --git a/tos/chips/sht11/SensirionBusyWaitC.nc b/tos/chips/sht11/SensirionBusyWaitC.nc new file mode 100644 index 00000000..61e441ad --- /dev/null +++ b/tos/chips/sht11/SensirionBusyWaitC.nc @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2008, Titanium Mirror, Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * - Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * - Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * - Neither the name of Titanium Mirror, Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED + * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, + * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE + * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/** + * This BusyWait interface is solely designed for use in providing the + * necessary 5us timing when bit-banging the SHT1X sensibus clock pin in + * SensirionSht11LogicP, which only calls BusyWait.wait() with an argument of + * 5 (us). For most microprocessors running at under 10MHz, the implementation + * need do nothing to achieve the required timing. This default implementation + * is designed for such platforms. Platforms using higher performance + * microprocessors may need to override this component with a platform-specific + * one to provide the necessary wait time. + * + * @author R. Steve McKown + */ + +module SensirionBusyWaitC { + provides interface BusyWait; +} +implementation { + async command void BusyWait.wait(uint8_t us) {} +} diff --git a/tos/chips/sht11/SensirionSht11LogicP.nc b/tos/chips/sht11/SensirionSht11LogicP.nc index ce4aa6ca..f3f02697 100644 --- a/tos/chips/sht11/SensirionSht11LogicP.nc +++ b/tos/chips/sht11/SensirionSht11LogicP.nc @@ -57,6 +57,7 @@ generic module SensirionSht11LogicP() { uses interface GeneralIO as CLOCK; uses interface GpioInterrupt as InterruptDATA; + uses interface BusyWait; uses interface Timer; uses interface Leds; @@ -240,11 +241,17 @@ implementation { call DATA.makeOutput(); call DATA.set(); call CLOCK.clr(); + call BusyWait.wait(5); call CLOCK.set(); + call BusyWait.wait(5); call DATA.clr(); + call BusyWait.wait(5); call CLOCK.clr(); + call BusyWait.wait(5); call CLOCK.set(); + call BusyWait.wait(5); call DATA.set(); + call BusyWait.wait(5); call CLOCK.clr(); } @@ -261,6 +268,7 @@ implementation { call DATA.clr(); byte = byte << 1; call CLOCK.set(); + call BusyWait.wait(5); call CLOCK.clr(); } } @@ -373,6 +381,7 @@ implementation { call DATA.makeOutput(); call DATA.clr(); call CLOCK.set(); + call BusyWait.wait(5); call CLOCK.clr(); call DATA.makeInput(); call DATA.set(); @@ -382,6 +391,7 @@ implementation { call DATA.makeOutput(); call DATA.set(); call CLOCK.set(); + call BusyWait.wait(5); call CLOCK.clr(); } -- 2.39.2