From: "Andreas Färber" <andreas.faerber@web.de>
To: qemu-devel@nongnu.org
Cc: alex.horn@cs.ox.ac.uk, "Andreas Färber" <andreas.faerber@web.de>,
anthony@codemonkey.ws, peter.maydell@linaro.org
Subject: [Qemu-devel] [PATCH v3 5/6] tmp105: QOM'ify
Date: Mon, 7 Jan 2013 23:42:23 +0100 [thread overview]
Message-ID: <1357598544-4804-6-git-send-email-andreas.faerber@web.de> (raw)
In-Reply-To: <1357598544-4804-1-git-send-email-andreas.faerber@web.de>
Introduce TYPE_ constant and cast macro.
Move the state struct to the new header to allow for future embedding.
Signed-off-by: Andreas Färber <andreas.faerber@web.de>
Reviewed-by: Anthony Liguori <aliguori@us.ibm.com>
---
hw/tmp105.c | 38 +++++++++++++-------------------------
hw/tmp105.h | 27 +++++++++++++++++++++++++++
2 Dateien geändert, 40 Zeilen hinzugefügt(+), 25 Zeilen entfernt(-)
diff --git a/hw/tmp105.c b/hw/tmp105.c
index ff9f28b..a16f538 100644
--- a/hw/tmp105.c
+++ b/hw/tmp105.c
@@ -22,20 +22,6 @@
#include "i2c.h"
#include "tmp105.h"
-typedef struct {
- I2CSlave i2c;
- uint8_t len;
- uint8_t buf[2];
- qemu_irq pin;
-
- uint8_t pointer;
- uint8_t config;
- int16_t temperature;
- int16_t limit[2];
- int faults;
- uint8_t alarm;
-} TMP105State;
-
static void tmp105_interrupt_update(TMP105State *s)
{
qemu_set_irq(s->pin, s->alarm ^ ((~s->config >> 2) & 1)); /* POL */
@@ -68,7 +54,7 @@ static void tmp105_alarm_update(TMP105State *s)
/* Units are 0.001 centigrades relative to 0 C. */
void tmp105_set(I2CSlave *i2c, int temp)
{
- TMP105State *s = (TMP105State *) i2c;
+ TMP105State *s = TMP105(i2c);
if (temp >= 128000 || temp < -128000) {
fprintf(stderr, "%s: values is out of range (%i.%03i C)\n",
@@ -141,17 +127,18 @@ static void tmp105_write(TMP105State *s)
static int tmp105_rx(I2CSlave *i2c)
{
- TMP105State *s = (TMP105State *) i2c;
+ TMP105State *s = TMP105(i2c);
- if (s->len < 2)
+ if (s->len < 2) {
return s->buf[s->len ++];
- else
+ } else {
return 0xff;
+ }
}
static int tmp105_tx(I2CSlave *i2c, uint8_t data)
{
- TMP105State *s = (TMP105State *) i2c;
+ TMP105State *s = TMP105(i2c);
if (s->len == 0) {
s->pointer = data;
@@ -169,10 +156,11 @@ static int tmp105_tx(I2CSlave *i2c, uint8_t data)
static void tmp105_event(I2CSlave *i2c, enum i2c_event event)
{
- TMP105State *s = (TMP105State *) i2c;
+ TMP105State *s = TMP105(i2c);
- if (event == I2C_START_RECV)
+ if (event == I2C_START_RECV) {
tmp105_read(s);
+ }
s->len = 0;
}
@@ -208,7 +196,7 @@ static const VMStateDescription vmstate_tmp105 = {
static void tmp105_reset(I2CSlave *i2c)
{
- TMP105State *s = (TMP105State *) i2c;
+ TMP105State *s = TMP105(i2c);
s->temperature = 0;
s->pointer = 0;
@@ -221,7 +209,7 @@ static void tmp105_reset(I2CSlave *i2c)
static int tmp105_init(I2CSlave *i2c)
{
- TMP105State *s = FROM_I2C_SLAVE(TMP105State, i2c);
+ TMP105State *s = TMP105(i2c);
qdev_init_gpio_out(&i2c->qdev, &s->pin, 1);
@@ -242,8 +230,8 @@ static void tmp105_class_init(ObjectClass *klass, void *data)
dc->vmsd = &vmstate_tmp105;
}
-static TypeInfo tmp105_info = {
- .name = "tmp105",
+static const TypeInfo tmp105_info = {
+ .name = TYPE_TMP105,
.parent = TYPE_I2C_SLAVE,
.instance_size = sizeof(TMP105State),
.class_init = tmp105_class_init,
diff --git a/hw/tmp105.h b/hw/tmp105.h
index 982d1c9..c21396f 100644
--- a/hw/tmp105.h
+++ b/hw/tmp105.h
@@ -17,6 +17,33 @@
#include "i2c.h"
#include "tmp105_regs.h"
+#define TYPE_TMP105 "tmp105"
+#define TMP105(obj) OBJECT_CHECK(TMP105State, (obj), TYPE_TMP105)
+
+/**
+ * TMP105State:
+ * @config: Bits 5 and 6 (value 32 and 64) determine the precision of the
+ * temperature. See Table 8 in the data sheet.
+ *
+ * @see_also: http://www.ti.com/lit/gpn/tmp105
+ */
+typedef struct TMP105State {
+ /*< private >*/
+ I2CSlave i2c;
+ /*< public >*/
+
+ uint8_t len;
+ uint8_t buf[2];
+ qemu_irq pin;
+
+ uint8_t pointer;
+ uint8_t config;
+ int16_t temperature;
+ int16_t limit[2];
+ int faults;
+ uint8_t alarm;
+} TMP105State;
+
/**
* tmp105_set:
* @i2c: dispatcher to TMP105 hardware model
--
1.7.10.4
next prev parent reply other threads:[~2013-01-07 22:42 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-01-07 22:42 [Qemu-devel] [PATCH v3 0/6] I2C libqos and tmp105 qtest support Andreas Färber
2013-01-07 22:42 ` [Qemu-devel] [PATCH v3 1/6] libqtest: Prepare I2C libqos Andreas Färber
2013-01-07 22:42 ` [Qemu-devel] [PATCH v3 2/6] tmp105: Split out I2C message constants from header Andreas Färber
2013-01-07 22:42 ` [Qemu-devel] [PATCH v3 3/6] tmp105: Fix I2C protocol bug Andreas Färber
2013-01-07 22:42 ` [Qemu-devel] [PATCH v3 4/6] tests: Add tmp105 qtest test case Andreas Färber
2013-01-07 22:42 ` Andreas Färber [this message]
2013-01-07 22:42 ` [Qemu-devel] [PATCH v3 6/6] tmp105: Add temperature QOM property Andreas Färber
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=1357598544-4804-6-git-send-email-andreas.faerber@web.de \
--to=andreas.faerber@web.de \
--cc=alex.horn@cs.ox.ac.uk \
--cc=anthony@codemonkey.ws \
--cc=peter.maydell@linaro.org \
--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).