altos: Remove 8051 address space specifiers
[fw/altos] / src / test / ao_ms5607_convert_test.c
1 /*
2  * Copyright © 2013 Keith Packard <keithp@keithp.com>
3  *
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.
8  *
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.
13  *
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.
17  */
18
19
20 #include <stdint.h>
21 #include <ao_ms5607.h>
22
23 struct ao_ms5607_prom ao_ms5607_prom = {
24         0x002c,
25         0xa6e0,
26         0x988e,
27         0x6814,
28         0x5eff,
29         0x8468,
30         0x6c86,
31         0xa271,
32 };
33
34 int32_t D1_mm = 6179630;
35 int32_t D2_mm = 8933155;
36
37 #include <ao_ms5607_convert.c>
38 #define ao_ms5607_convert ao_ms5607_convert_8051
39 #include <ao_ms5607_convert_8051.c>
40 #include <ao_int64.c>
41 #include <stdio.h>
42 #include <stdlib.h>
43
44 struct ao_ms5607_sample ao_sample = {
45         6179630,
46         8933155
47 };
48
49 int errors;
50
51 void test(int trial, struct ao_ms5607_sample *sample)
52 {
53         struct ao_ms5607_value  value, value_8051;
54
55         ao_ms5607_convert(sample, &value);
56         ao_ms5607_convert_8051(sample, &value_8051);
57         if (value.temp != value_8051.temp || value.pres != value_8051.pres) {
58                 ++errors;
59                 printf ("trial %d: %d, %d -> %d, %d (should be %d, %d)\n",
60                         trial,
61                         sample->pres, sample->temp,
62                         value_8051.pres, value_8051.temp,
63                         value.pres, value.temp);
64         }
65 }
66
67 #define TESTS   10000000
68
69 #include <stdlib.h>
70
71 static int32_t rand24(void) { return random() & 0xffffff; }
72
73 int
74 main(int argc, char **argv)
75 {
76         struct ao_ms5607_sample sample;
77         int     i, start;
78
79         if (argv[1])
80                 start = atoi(argv[1]);
81         else
82                 start = 0;
83
84         srandom(10000);
85         test(-1, &ao_sample);
86         for (i = 0; i < TESTS; i++) {
87                 sample.pres = rand24();
88                 sample.temp = rand24();
89                 if (i >= start)
90                         test(i, &sample);
91         }
92         return errors;
93 }