Added a typedef for IO addresses
[simavr] / simavr / sim / sim_io.h
1 /*
2         sim_io.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 #ifndef __SIM_IO_H__
23 #define __SIM_IO_H__
24
25 #include "sim_avr.h"
26
27 /*
28  * used by the ioports to implement their own features
29  * see avr_eeprom.* for an example, and avr_ioctl().
30  */
31 #define AVR_IOCTL_DEF(_a,_b,_c,_d) \
32         (((_a) << 24)|((_b) << 16)|((_c) << 8)|((_d)))
33
34 /*
35  * IO module base struct
36  * Modules uses that as their first member in their own struct
37  */
38 typedef struct avr_io_t {
39         struct avr_io_t *       next;
40         avr_t *                         avr;            // avr we are attached to
41         const char *            kind;           // pretty name, for debug
42
43         uint32_t                        irq_ioctl_get;  // used to get irqs from this module
44         int                                     irq_count;      // number of (optional) irqs
45         struct avr_irq_t *      irq;            // optional external IRQs
46         // called at every instruction
47         void (*run)(struct avr_io_t *io);
48         // called at reset time
49         void (*reset)(struct avr_io_t *io);
50         // called externally. allow access to io modules and so on
51         int (*ioctl)(struct avr_io_t *io, uint32_t ctl, void *io_param);
52 } avr_io_t;
53
54 /*
55  * IO modules helper functions
56  */
57
58 // registers an IO module, so it's run(), reset() etc are called
59 // this is called by the AVR core init functions, you /could/ register an external
60 // one after instanciation, for whatever purpose...
61 void avr_register_io(avr_t *avr, avr_io_t * io);
62 // register a callback for when IO register "addr" is read
63 void avr_register_io_read(avr_t *avr, avr_io_addr_t addr, avr_io_read_t read, void * param);
64 // register a callback for when the IO register is written. callback has to set the memory itself
65 void avr_register_io_write(avr_t *avr, avr_io_addr_t addr, avr_io_write_t write, void * param);
66 // call every IO modules until one responds to this
67 int avr_ioctl(avr_t *avr, uint32_t ctl, void * io_param);
68 // get the specific irq for a module, check AVR_IOCTL_IOPORT_GETIRQ for example
69 struct avr_irq_t * avr_io_getirq(avr_t * avr, uint32_t ctl, int index);
70
71 #endif /* __SIM_IO_H__ */