[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Qemu-devel] [PATCH] tmp105: read temperature in milli-celsius
From: |
Paolo Bonzini |
Subject: |
Re: [Qemu-devel] [PATCH] tmp105: read temperature in milli-celsius |
Date: |
Mon, 17 Feb 2014 07:13:40 -0500 (EST) |
> > @@ -78,7 +80,7 @@ static void tmp105_set_temperature(Object *obj, Visitor
> > *v, void *opaque,
> > return;
> > }
> >
> > - s->temperature = ((int16_t) (temp * 0x800 / 128000)) << 4;
> > + s->temperature = (int16_t) (temp * 256 / 1000);
>
> Did you check whether those magic 4 bits shift were for some other
> purpose such as flags possibly? CC'ing Alex Horn.
>From the data sheet, the temperature register is 9-12 bits, depending
on the configuration. So the low 4 bits will always read back as zero.
However, they are already masked away when reading the temperature in
tmp105_read:
s->buf[s->len ++] = (((uint16_t) s->temperature) >> 8);
s->buf[s->len ++] = (((uint16_t) s->temperature) >> 0) &
(0xf0 << ((~s->config >> 5) & 3)); /* R */
The equivalence of the formula can be proved as follows:
((int16_t) (temp * 0x800 / 128000)) << 4
= (int16_t) (temp * 0x8000 / 128000) & ~15
= (int16_t) (temp * (0x100 * 0x80) / (1000 * 0x80)) & ~15
= (int16_t) (temp * 0x100 / 1000) & ~15
and the AND can be removed as mentioned above.
> Since we do have a tmp105-test, we should also add a regression test for
> the getter bug.
Yeah, if only tmp105-test already tested the setter. :)
Paolo