misc: Point to correct simavr include dirs
[simavr] / simavr / sim / sim_irq.h
1 /*
2         sim_irq.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_IRQ_H__
23 #define __SIM_IRQ_H__
24
25 #include <stdint.h>
26
27 #ifdef __cplusplus
28 extern "C" {
29 #endif
30
31 /*
32  * Internal IRQ system
33  * 
34  * This subsystem allows any piece of code to "register" a hook to be called when an IRQ is
35  * raised. The IRQ definition is up to the module defining it, for example a IOPORT pin change
36  * might be an IRQ in which case any piece of code can be notified when a pin has changed state
37  * 
38  * The notify hooks are chained, and duplicates are filtered out so you can't register a
39  * notify hook twice on one particular IRQ
40  * 
41  * IRQ calling order is not defined, so don't rely on it.
42  * 
43  * IRQ hook needs to be registered in reset() handlers, ie after all modules init() bits
44  * have been called, to prevent race condition of the initialization order.
45  */
46 struct avr_irq_t;
47
48 typedef void (*avr_irq_notify_t)(
49                 struct avr_irq_t * irq,
50                 uint32_t value,
51                 void * param);
52
53
54 enum {
55         IRQ_FLAG_NOT            = (1 << 0),     //!< change polarity of the IRQ
56         IRQ_FLAG_FILTERED       = (1 << 1),     //!< do not "notify" if "value" is the same as previous raise
57         IRQ_FLAG_ALLOC          = (1 << 2), //!< this irq structure was malloced via avr_alloc_irq
58         IRQ_FLAG_INIT           = (1 << 3), //!< this irq hasn't been used yet
59 };
60
61 /*
62  * IRQ Pool structure
63  */
64 typedef struct avr_irq_pool_t {
65         int count;                                              //!< number of irqs living in the pool
66         struct avr_irq_t ** irq;                //!< irqs belonging in this pool
67 } avr_irq_pool_t;
68
69 /*!
70  * Public IRQ structure
71  */
72 typedef struct avr_irq_t {
73         struct avr_irq_pool_t * pool;   // TODO: migration in progress
74         const char * name;
75         uint32_t                        irq;            //!< any value the user needs
76         uint32_t                        value;          //!< current value
77         uint8_t                         flags;          //!< IRQ_* flags
78         struct avr_irq_hook_t * hook;   //!< list of hooks to be notified
79 } avr_irq_t;
80
81 //! allocates 'count' IRQs, initializes their "irq" starting from 'base' and increment
82 avr_irq_t *
83 avr_alloc_irq(
84                 avr_irq_pool_t * pool,
85                 uint32_t base,
86                 uint32_t count,
87                 const char ** names /* optional */);
88 void
89 avr_free_irq(
90                 avr_irq_t * irq,
91                 uint32_t count);
92
93 //! init 'count' IRQs, initializes their "irq" starting from 'base' and increment
94 void
95 avr_init_irq(
96                 avr_irq_pool_t * pool,
97                 avr_irq_t * irq,
98                 uint32_t base,
99                 uint32_t count,
100                 const char ** names /* optional */);
101 //! 'raise' an IRQ. Ie call their 'hooks', and raise any chained IRQs, and set the new 'value'
102 void
103 avr_raise_irq(
104                 avr_irq_t * irq,
105                 uint32_t value);
106 //! this connects a "source" IRQ to a "destination" IRQ
107 void
108 avr_connect_irq(
109                 avr_irq_t * src,
110                 avr_irq_t * dst);
111 void
112 avr_unconnect_irq(
113                 avr_irq_t * src,
114                 avr_irq_t * dst);
115
116 //! register a notification 'hook' for 'irq' -- 'param' is anything that your want passed back as argument
117 void
118 avr_irq_register_notify(
119                 avr_irq_t * irq,
120                 avr_irq_notify_t notify,
121                 void * param);
122
123 void
124 avr_irq_unregister_notify(
125                 avr_irq_t * irq,
126                 avr_irq_notify_t notify,
127                 void * param);
128
129 #ifdef __cplusplus
130 };
131 #endif
132
133 #endif /* __SIM_IRQ_H__ */