2 * Copyright © 2012 Keith Packard <keithp@keithp.com>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
19 #include <ao_ms5607.h>
35 ao_ms5607_convert(__xdata struct ao_ms5607_sample *sample,
36 __xdata struct ao_ms5607_value *value)
40 __LOCAL ao_int64_t OFF;
41 __LOCAL ao_int64_t SENS;
44 dT = sample->temp - ((int32_t) ao_ms5607_prom.tref << 8);
46 /* TEMP = 2000 + (((int64_t) dT * ao_ms5607_prom.tempsens) >> 23); */
47 ao_mul64_32_32(&a, dT, ao_ms5607_prom.tempsens);
48 ao_rshift64(&a, &a, 23);
52 /* OFF = ((int64_t) ao_ms5607_prom.off << SHIFT_OFF) + (((int64_t) ao_ms5607_prom.tco * dT) >> SHIFT_TCO);*/
54 OFF.high = ao_ms5607_prom.off >> (32 - SHIFT_OFF);
58 OFF.low = (uint32_t) ao_ms5607_prom.off << SHIFT_OFF;
59 ao_mul64_32_32(&a, ao_ms5607_prom.tco, dT);
60 ao_rshift64(&a, &a, SHIFT_TCO);
61 ao_plus64(&OFF, &OFF, &a);
64 /* SENS = ((int64_t) ao_ms5607_prom.sens << SHIFT_SENS) + (((int64_t) ao_ms5607_prom.tcs * dT) >> SHIFT_TCS); */
66 SENS.low = (uint32_t) ao_ms5607_prom.sens << SHIFT_SENS;
67 ao_mul64_32_32(&a, ao_ms5607_prom.tcs, dT);
68 ao_rshift64(&a, &a, SHIFT_TCS);
69 ao_plus64(&SENS, &SENS, &a);
74 __LOCAL int32_t TEMPM;
75 __LOCAL ao_int64_t OFF2;
76 __LOCAL ao_int64_t SENS2;
78 /* T2 = ((int64_t) dT * (int64_t) dT) >> 31; */
79 ao_mul64_32_32(&a, dT, dT);
80 T2 = (a.low >> 31) | (a.high << 1);
85 /* OFF2 = (61 * (int64_t) TEMPM * (int64_t) TEMPM) >> 4; */
86 ao_mul64_32_32(&OFF2, TEMPM, TEMPM);
87 ao_mul64_64_16(&OFF2, &OFF2, 61);
88 ao_rshift64(&OFF2, &OFF2, 4);
91 /* SENS2 = 2 * (int64_t) TEMPM * (int64_t) TEMPM; */
92 ao_mul64_32_32(&SENS2, TEMPM, TEMPM);
93 ao_lshift64(&SENS2, &SENS2, 1);
101 TEMPP2 = TEMPP * TEMPP;
103 /* OFF2 = OFF2 + 15 * TEMPP2; */
104 ao_mul64_32_32(&a, 15, TEMPP2);
105 ao_plus64(&OFF2, &OFF2, &a);
108 /* SENS2 = SENS2 + 8 * TEMPP2; */
111 ao_lshift64(&a, &a, 3);
112 ao_plus64(&SENS2, &SENS2, &a);
118 ao_minus64(&OFF, &OFF, &OFF2);
122 ao_minus64(&SENS, &SENS, &SENS2);
126 /* value->pres = ((((int64_t) sample->pres * SENS) >> 21) - OFF) >> 15; */
128 a.low = sample->pres;
129 ao_mul64(&a, &a, &SENS);
130 ao_rshift64(&a, &a, 21);
131 ao_minus64(&a, &a, &OFF);
132 ao_rshift64(&a, &a, 15);