misc: Made (most) of the headers c++ friendly
[simavr] / simavr / sim / sim_hex.h
1 /*
2         sim_hex.h
3
4         Copyright 2008, 2009 Michel Pollet <buserror@gmail.com>
5
6         This file is part of simavr.
7
8         simavr is free software: you can redistribute it and/or modify
9         it under the terms of the GNU General Public License as published by
10         the Free Software Foundation, either version 3 of the License, or
11         (at your option) any later version.
12
13         simavr is distributed in the hope that it will be useful,
14         but WITHOUT ANY WARRANTY; without even the implied warranty of
15         MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16         GNU General Public License for more details.
17
18         You should have received a copy of the GNU General Public License
19         along with simavr.  If not, see <http://www.gnu.org/licenses/>.
20  */
21
22
23 #ifndef __SIM_HEX_H___
24 #define __SIM_HEX_H___
25
26 #include <stdint.h>
27
28 #ifdef __cplusplus
29 extern "C" {
30 #endif
31
32 // parses a hex text string 'src' of at max 'maxlen' characters, decodes it into 'buffer'
33 int read_hex_string(const char * src, uint8_t * buffer, int maxlen);
34
35 // a .hex file chunk (base address + size)
36 struct ihex_chunk_t {
37         uint32_t baseaddr;      // offset it started at in the .hex file
38         uint8_t * data;         // read data
39         uint32_t size;          // read data size
40 };
41
42 /*
43  * Read a .hex file, detects the various different chunks in it from their starting
44  * addresses and fills up the chunks passed as arguments up to max_chunks.
45  * Returns the number of chunks found, or -1 if an error occurs.
46  */
47 int read_ihex_chunks(const char * fname, struct ihex_chunk_t * chunks, int max_chunks);
48
49 // reads IHEX file 'fname', puts it's decoded size in *'dsize' and returns
50 // a newly allocated buffer with the binary data (or NULL, if error)
51 uint8_t * read_ihex_file(const char * fname, uint32_t * dsize, uint32_t * start);
52
53 // hex dump from pointer 'b' for 'l' bytes with string prefix 'w'
54 void hdump(const char *w, uint8_t *b, size_t l);
55
56 #ifdef __cplusplus
57 };
58 #endif
59
60 #endif /* __SIM_HEX_H___ */