From patchwork Fri Dec 14 11:34:32 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Andreas_F=C3=A4rber?= X-Patchwork-Id: 206400 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id DD8772C009A for ; Fri, 14 Dec 2012 22:53:35 +1100 (EST) Received: from localhost ([::1]:40864 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TjTpd-00078u-3q for incoming@patchwork.ozlabs.org; Fri, 14 Dec 2012 06:53:33 -0500 Received: from eggs.gnu.org ([208.118.235.92]:51729) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TjTpU-00078K-W4 for qemu-devel@nongnu.org; Fri, 14 Dec 2012 06:53:26 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TjTXk-0007cA-2r for qemu-devel@nongnu.org; Fri, 14 Dec 2012 06:35:08 -0500 Received: from mout.web.de ([212.227.17.11]:49834) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TjTXj-0007aj-Mv for qemu-devel@nongnu.org; Fri, 14 Dec 2012 06:35:03 -0500 Received: from localhost.localdomain ([84.148.45.228]) by smtp.web.de (mrweb103) with ESMTPSA (Nemesis) id 0MCImL-1Ts2GG3npR-009Cnz; Fri, 14 Dec 2012 12:34:50 +0100 From: =?UTF-8?q?Andreas=20F=C3=A4rber?= To: qemu-devel@nongnu.org Date: Fri, 14 Dec 2012 12:34:32 +0100 Message-Id: <1355484872-11283-8-git-send-email-andreas.faerber@web.de> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1355484872-11283-1-git-send-email-andreas.faerber@web.de> References: <1355484872-11283-1-git-send-email-andreas.faerber@web.de> MIME-Version: 1.0 X-Provags-ID: V02:K0:KhQBD04jE7z+obDfsK2PzvDiAnzB0tkbW9FCF+7PrLe s5iF4dqAXSTXE5aYeQZlzhX/P53El0aRSqAN8cfoeq7WZqiCGs gzXcE9a1ORwp1wBLGaA+q5Yx9Oyk3P0J+QWqj98/nPGWbfqNCc Jq8f0fzUGxK9g7tQnGU31I5oeJ5w2Q3ddmEQBB1fV0Za994gXz +RaApeVymnmjr8TQ9zZJQ== X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4.x-2.6.x [generic] X-Received-From: 212.227.17.11 Cc: Peter Maydell , Blue Swirl , Alex Horn , =?UTF-8?q?Andreas=20F=C3=A4rber?= , Anthony Liguori Subject: [Qemu-devel] [PATCH v2 7/7] tmp105: Add temperature QOM property X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org This obsoletes tmp105_set() and allows for better error handling. Signed-off-by: Andreas Färber --- hw/tmp105.c | 39 ++++++++++++++++++++++++++++++++------- hw/tmp105.h | 15 --------------- 2 Dateien geändert, 32 Zeilen hinzugefügt(+), 22 Zeilen entfernt(-) diff --git a/hw/tmp105.c b/hw/tmp105.c index a16f538..34c7d24 100644 --- a/hw/tmp105.c +++ b/hw/tmp105.c @@ -21,6 +21,7 @@ #include "hw.h" #include "i2c.h" #include "tmp105.h" +#include "qapi/qapi-visit-core.h" static void tmp105_interrupt_update(TMP105State *s) { @@ -51,18 +52,34 @@ static void tmp105_alarm_update(TMP105State *s) tmp105_interrupt_update(s); } +static void tmp105_get_temperature(Object *obj, Visitor *v, void *opaque, + const char *name, Error **errp) +{ + TMP105State *s = TMP105(obj); + int64_t value = s->temperature; + + visit_type_int(v, &value, name, errp); +} + /* Units are 0.001 centigrades relative to 0 C. */ -void tmp105_set(I2CSlave *i2c, int temp) +static void tmp105_set_temperature(Object *obj, Visitor *v, void *opaque, + const char *name, Error **errp) { - TMP105State *s = TMP105(i2c); + TMP105State *s = TMP105(obj); - if (temp >= 128000 || temp < -128000) { - fprintf(stderr, "%s: values is out of range (%i.%03i C)\n", - __FUNCTION__, temp / 1000, temp % 1000); - exit(-1); + int64_t value; + + visit_type_int(v, &value, name, errp); + if (error_is_set(errp)) { + return; + } + if (value >= 128000 || value < -128000) { + error_setg(errp, "value %" PRId64 ".%03" PRIu64 " °C is out of range", + value / 1000, value % 1000); + return; } - s->temperature = ((int16_t) (temp * 0x800 / 128000)) << 4; + s->temperature = ((int16_t) (value * 0x800 / 128000)) << 4; tmp105_alarm_update(s); } @@ -218,6 +235,13 @@ static int tmp105_init(I2CSlave *i2c) return 0; } +static void tmp105_initfn(Object *obj) +{ + object_property_add(obj, "temperature", "int", + tmp105_get_temperature, + tmp105_set_temperature, NULL, NULL, NULL); +} + static void tmp105_class_init(ObjectClass *klass, void *data) { DeviceClass *dc = DEVICE_CLASS(klass); @@ -234,6 +258,7 @@ static const TypeInfo tmp105_info = { .name = TYPE_TMP105, .parent = TYPE_I2C_SLAVE, .instance_size = sizeof(TMP105State), + .instance_init = tmp105_initfn, .class_init = tmp105_class_init, }; diff --git a/hw/tmp105.h b/hw/tmp105.h index c21396f..d218919 100644 --- a/hw/tmp105.h +++ b/hw/tmp105.h @@ -44,19 +44,4 @@ typedef struct TMP105State { uint8_t alarm; } TMP105State; -/** - * tmp105_set: - * @i2c: dispatcher to TMP105 hardware model - * @temp: temperature with 0.001 centigrades units in the range -40 C to +125 C - * - * Sets the temperature of the TMP105 hardware model. - * - * Bits 5 and 6 (value 32 and 64) in the register indexed by TMP105_REG_CONFIG - * determine the precision of the temperature. See Table 8 in the data sheet. - * - * @see_also: I2C_SLAVE macro - * @see_also: http://www.ti.com/lit/gpn/tmp105 - */ -void tmp105_set(I2CSlave *i2c, int temp); - #endif