1
0
mirror of https://git.FreeBSD.org/src.git synced 2025-01-12 14:29:28 +00:00

ow_temp: Update the temperature visible via the sysctl atomically, rather

than using it as temporary calculation space.
This commit is contained in:
Gavin Atkinson 2016-12-22 00:09:53 +00:00
parent 3c175909e7
commit 716911af3e
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=310381

View File

@ -137,7 +137,7 @@ ow_temp_event_thread(void *arg)
struct ow_temp_softc *sc;
uint8_t scratch[8 + 1];
uint8_t crc;
int retries, rv;
int retries, rv, tmp;
sc = arg;
pause("owtstart", device_get_unit(sc->dev) * hz / 100); // 10ms stagger
@ -166,14 +166,14 @@ ow_temp_event_thread(void *arg)
* Formula from DS18S20 datasheet, page 6
* DS18S20 datasheet says count_per_c is 16, DS1820 does not
*/
sc->temp = (int16_t)((scratch[0] & 0xfe) |
tmp = (int16_t)((scratch[0] & 0xfe) |
(scratch[1] << 8)) << 3;
sc->temp += 16 - scratch[6] - 4; /* count_per_c == 16 */
tmp += 16 - scratch[6] - 4; /* count_per_c == 16 */
} else
sc->temp = (int16_t)(scratch[0] | (scratch[1] << 8)) << 3;
tmp = (int16_t)(scratch[0] | (scratch[1] << 8)) << 3;
} else
sc->temp = (int16_t)(scratch[0] | (scratch[1] << 8));
sc->temp = sc->temp * 1000 / 16 + 273150;
tmp = (int16_t)(scratch[0] | (scratch[1] << 8));
sc->temp = tmp * 1000 / 16 + 273150;
break;
}
sc->bad_crc++;