altos: Remove unused ao_adc_get from ao_adc_stm.c
[fw/altos] / ao-tools / lib / ao-hex.h
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 #ifndef _AO_HEX_H_
20 #define _AO_HEX_H_
21
22 #include <stdint.h>
23 #include <stdbool.h>
24 #include <stdio.h>
25
26 #define AO_HEX_RECORD_NORMAL                    0x00
27 #define AO_HEX_RECORD_EOF                       0x01
28 #define AO_HEX_RECORD_EXTENDED_ADDRESS_4        0x02
29 #define AO_HEX_RECORD_EXTENDED_ADDRESS_8        0x04
30 #define AO_HEX_RECORD_SYMBOL                    0xfe
31
32 /* Intel hex file format data
33  */
34 struct ao_hex_record {
35         uint8_t length;
36         uint16_t address;
37         uint8_t type;
38         uint8_t checksum;
39         uint8_t data[0];
40 };
41
42 struct ao_hex_file {
43         int                     nrecord;
44         struct ao_hex_record    *records[0];
45 };
46
47 struct ao_hex_image {
48         uint32_t        address;
49         uint32_t        length;
50         uint8_t         data[0];
51 };
52
53 struct ao_sym {
54         unsigned        addr;
55         char            *name;
56         bool            required;
57         bool            found;
58 };
59
60 struct ao_hex_file *
61 ao_hex_file_read(FILE *file, char *name);
62
63 void
64 ao_hex_file_free(struct ao_hex_file *hex);
65
66 struct ao_hex_image *
67 ao_hex_image_create(struct ao_hex_file *hex);
68
69 void
70 ao_hex_image_free(struct ao_hex_image *image);
71
72 struct ao_hex_image *
73 ao_hex_load(char *filename, struct ao_sym **symbols, int *num_symbols);
74
75 struct ao_hex_image *
76 ao_hex_image_cat(struct ao_hex_image *a, struct ao_hex_image *b);
77
78 int
79 ao_hex_image_equal(struct ao_hex_image *a, struct ao_hex_image *b);
80
81 bool
82 ao_hex_save(FILE *file, struct ao_hex_image *image,
83             struct ao_sym *symbols, int num_symbols);
84
85 #endif /* _AO_HEX_H_ */