From: "Andreas Färber" <andreas.faerber@web.de>
To: qemu-devel@nongnu.org
Cc: "Andreas Färber" <andreas.faerber@web.de>, anthony@codemonkey.ws
Subject: [Qemu-devel] [PATCH for-1.4 v4 6/6] tmp105: Add temperature QOM property
Date: Wed, 16 Jan 2013 01:57:59 +0100 [thread overview]
Message-ID: <1358297879-26576-7-git-send-email-andreas.faerber@web.de> (raw)
In-Reply-To: <1358297879-26576-1-git-send-email-andreas.faerber@web.de>
This obsoletes tmp105_set() and allows for better error handling.
Signed-off-by: Andreas Färber <andreas.faerber@web.de>
---
hw/tmp105.c | 34 +++++++++++++++++++++++++++++-----
hw/tmp105.h | 15 ---------------
2 Dateien geändert, 29 Zeilen hinzugefügt(+), 20 Zeilen entfernt(-)
diff --git a/hw/tmp105.c b/hw/tmp105.c
index a16f538..3ad2d2f 100644
--- a/hw/tmp105.c
+++ b/hw/tmp105.c
@@ -21,6 +21,7 @@
#include "hw.h"
#include "i2c.h"
#include "tmp105.h"
+#include "qapi/visitor.h"
static void tmp105_interrupt_update(TMP105State *s)
{
@@ -51,15 +52,30 @@ 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);
+ int64_t temp;
+ visit_type_int(v, &temp, name, errp);
+ if (error_is_set(errp)) {
+ return;
+ }
if (temp >= 128000 || temp < -128000) {
- fprintf(stderr, "%s: values is out of range (%i.%03i C)\n",
- __FUNCTION__, temp / 1000, temp % 1000);
- exit(-1);
+ error_setg(errp, "value %" PRId64 ".%03" PRIu64 " °C is out of range",
+ temp / 1000, temp % 1000);
+ return;
}
s->temperature = ((int16_t) (temp * 0x800 / 128000)) << 4;
@@ -218,6 +234,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 +257,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
--
1.7.10.4
prev parent reply other threads:[~2013-01-16 0:58 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-01-16 0:57 [Qemu-devel] [PATCH for-1.4 v4 0/6] I2C libqos and tmp105 qtest support Andreas Färber
2013-01-16 0:57 ` [Qemu-devel] [PATCH for-1.4 v4 1/6] libqtest: Prepare I2C libqos Andreas Färber
2013-01-16 0:57 ` [Qemu-devel] [PATCH for-1.4 v4 2/6] tmp105: Split out I2C message constants from header Andreas Färber
2013-01-16 0:57 ` [Qemu-devel] [PATCH for-1.4 v4 3/6] tmp105: Fix I2C protocol bug Andreas Färber
2013-01-16 0:57 ` [Qemu-devel] [PATCH for-1.4 v4 4/6] tests: Add tmp105 qtest test case Andreas Färber
2013-01-16 0:57 ` [Qemu-devel] [PATCH for-1.4 v4 5/6] tmp105: QOM'ify Andreas Färber
2013-01-16 0:57 ` Andreas Färber [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1358297879-26576-7-git-send-email-andreas.faerber@web.de \
--to=andreas.faerber@web.de \
--cc=anthony@codemonkey.ws \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).