ao-tools: Add cc_usb_write function
[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; version 2 of the License.
7  *
8  * This program is distributed in the hope that it will be useful, but
9  * WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11  * General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License along
14  * with this program; if not, write to the Free Software Foundation, Inc.,
15  * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
16  */
17
18 #ifndef _AO_HEX_H_
19 #define _AO_HEX_H_
20
21 #include <stdint.h>
22 #include <stdbool.h>
23 #include <stdio.h>
24
25 #define AO_HEX_RECORD_NORMAL                    0x00
26 #define AO_HEX_RECORD_EOF                       0x01
27 #define AO_HEX_RECORD_EXTENDED_ADDRESS_4        0x02
28 #define AO_HEX_RECORD_EXTENDED_ADDRESS_8        0x04
29 #define AO_HEX_RECORD_SYMBOL                    0xfe
30
31 /* Intel hex file format data
32  */
33 struct ao_hex_record {
34         uint8_t length;
35         uint16_t address;
36         uint8_t type;
37         uint8_t checksum;
38         uint8_t data[0];
39 };
40
41 struct ao_hex_file {
42         int                     nrecord;
43         struct ao_hex_record    *records[0];
44 };
45
46 struct ao_hex_image {
47         uint32_t        address;
48         uint32_t        length;
49         uint8_t         data[0];
50 };
51
52 struct ao_sym {
53         unsigned        addr;
54         char            *name;
55         bool            required;
56         bool            found;
57 };
58
59 struct ao_hex_file *
60 ao_hex_file_read(FILE *file, char *name);
61
62 void
63 ao_hex_file_free(struct ao_hex_file *hex);
64
65 struct ao_hex_image *
66 ao_hex_image_create(struct ao_hex_file *hex);
67
68 void
69 ao_hex_image_free(struct ao_hex_image *image);
70
71 struct ao_hex_image *
72 ao_hex_load(char *filename, struct ao_sym **symbols, int *num_symbols);
73
74 int
75 ao_hex_image_equal(struct ao_hex_image *a, struct ao_hex_image *b);
76
77 bool
78 ao_hex_save(FILE *file, struct ao_hex_image *image,
79             struct ao_sym *symbols, int num_symbols);
80
81 #endif /* _AO_HEX_H_ */