misc: Point to correct simavr include dirs
[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
34 read_hex_string(
35                 const char * src,
36                 uint8_t * buffer,
37                 int maxlen);
38
39 // a .hex file chunk (base address + size)
40 typedef struct ihex_chunk_t {
41         uint32_t baseaddr;      // offset it started at in the .hex file
42         uint8_t * data;         // read data
43         uint32_t size;          // read data size
44 } ihex_chunk_t, *ihex_chunk_p;
45
46 /*
47  * Read a .hex file, detects the various different chunks in it from their starting
48  * addresses and allocate an array of ihex_chunk_t returned in 'chunks'.
49  * Returns the number of chunks found, or -1 if an error occurs.
50  */
51 int
52 read_ihex_chunks(
53                 const char * fname,
54                 ihex_chunk_p * chunks );
55
56 // reads IHEX file 'fname', puts it's decoded size in *'dsize' and returns
57 // a newly allocated buffer with the binary data (or NULL, if error)
58 uint8_t *
59 read_ihex_file(
60                 const char * fname,
61                 uint32_t * dsize,
62                 uint32_t * start);
63
64 // hex dump from pointer 'b' for 'l' bytes with string prefix 'w'
65 void
66 hdump(
67                 const char *w,
68                 uint8_t *b, size_t l);
69
70 #ifdef __cplusplus
71 };
72 #endif
73
74 #endif /* __SIM_HEX_H___ */