misc: Point to correct simavr include dirs
[simavr] / simavr / sim / sim_interrupts.h
1 /*
2         sim_interrupts.h
3
4         Copyright 2008-2012 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_INTERRUPTS_H__
23 #define __SIM_INTERRUPTS_H__
24
25 #include "sim_avr_types.h"
26 #include "sim_irq.h"
27
28 #ifdef __cplusplus
29 extern "C" {
30 #endif
31
32 // interrupt vector for the IO modules
33 typedef struct avr_int_vector_t {
34         uint8_t                 vector;                 // vector number, zero (reset) is reserved
35         avr_regbit_t    enable;                 // IO register index for the "interrupt enable" flag for this vector
36         avr_regbit_t    raised;                 // IO register index for the register where the "raised" flag is (optional)
37
38         avr_irq_t               irq;                    // raised to 1 when queued, to zero when called
39         uint8_t                 pending : 1,    // 1 while scheduled in the fifo
40                                         trace : 1,              // only for debug of a vector
41                                         raise_sticky : 1;       // 1 if the interrupt flag (= the raised regbit) is not cleared
42                                                                                 // by the hardware when executing the interrupt routine (see TWINT)
43 } avr_int_vector_t;
44
45 // interrupt vectors, and their enable/clear registers
46 typedef struct  avr_int_table_t {
47         avr_int_vector_t * vector[64];
48         uint8_t                 vector_count;
49         uint8_t                 pending_wait;   // number of cycles to wait for pending
50         avr_int_vector_t * pending[64]; // needs to be >= vectors and a power of two
51         uint8_t                 pending_w,
52                                         pending_r;      // fifo cursors
53 } avr_int_table_t, *avr_int_table_p;
54
55 /*
56  * Interrupt Helper Functions
57  */
58 // register an interrupt vector. It's only needed if you want to use the "r_raised" flags
59 void
60 avr_register_vector(
61                 struct avr_t *avr,
62                 avr_int_vector_t * vector);
63 // raise an interrupt (if enabled). The interrupt is latched and will be called later
64 // return non-zero if the interrupt was raised and is now pending
65 int
66 avr_raise_interrupt(
67                 struct avr_t * avr,
68                 avr_int_vector_t * vector);
69 // return non-zero if the AVR core has any pending interrupts
70 int
71 avr_has_pending_interrupts(
72                 struct avr_t * avr);
73 // return nonzero if a specific interrupt vector is pending
74 int
75 avr_is_interrupt_pending(
76                 struct avr_t * avr,
77                 avr_int_vector_t * vector);
78 // clear the "pending" status of an interrupt
79 void
80 avr_clear_interrupt(
81                 struct avr_t * avr,
82                 avr_int_vector_t * vector);
83 // called by the core at each cycle to check whether an interrupt is pending
84 void
85 avr_service_interrupts(
86                 struct avr_t * avr);
87
88 // clear the interrupt (inc pending) if "raised" flag is 1
89 int
90 avr_clear_interrupt_if(
91                 struct avr_t * avr,
92                 avr_int_vector_t * vector,
93                 uint8_t old);
94
95 // return the IRQ that is raised when the vector is enabled and called/cleared
96 // this allows tracing of pending interrupts
97 avr_irq_t *
98 avr_get_interrupt_irq(
99                 struct avr_t * avr,
100                 uint8_t v);
101
102 // reset the interrupt table and the fifo
103 void
104 avr_interrupt_reset(
105                 struct avr_t * avr );
106
107 #ifdef __cplusplus
108 };
109 #endif
110
111 #endif /* __SIM_INTERRUPTS_H__ */