misc: Add extern "C" blocks to headers
[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 } avr_int_vector_t;
42
43 // interrupt vectors, and their enable/clear registers
44 typedef struct  avr_int_table_t {
45         avr_int_vector_t * vector[64];
46         uint8_t                 vector_count;
47         uint8_t                 pending_wait;   // number of cycles to wait for pending
48         avr_int_vector_t * pending[64]; // needs to be >= vectors and a power of two
49         uint8_t                 pending_w,
50                                         pending_r;      // fifo cursors
51 } avr_int_table_t, *avr_int_table_p;
52
53 /*
54  * Interrupt Helper Functions
55  */
56 // register an interrupt vector. It's only needed if you want to use the "r_raised" flags
57 void
58 avr_register_vector(
59                 struct avr_t *avr,
60                 avr_int_vector_t * vector);
61 // raise an interrupt (if enabled). The interrupt is latched and will be called later
62 // return non-zero if the interrupt was raised and is now pending
63 int
64 avr_raise_interrupt(
65                 struct avr_t * avr,
66                 avr_int_vector_t * vector);
67 // return non-zero if the AVR core has any pending interrupts
68 int
69 avr_has_pending_interrupts(
70                 struct avr_t * avr);
71 // return nonzero if a specific interrupt vector is pending
72 int
73 avr_is_interrupt_pending(
74                 struct avr_t * avr,
75                 avr_int_vector_t * vector);
76 // clear the "pending" status of an interrupt
77 void
78 avr_clear_interrupt(
79                 struct avr_t * avr,
80                 avr_int_vector_t * vector);
81 // called by the core at each cycle to check whether an interrupt is pending
82 void
83 avr_service_interrupts(
84                 struct avr_t * avr);
85
86 // clear the interrupt (inc pending) if "raised" flag is 1
87 int
88 avr_clear_interrupt_if(
89                 struct avr_t * avr,
90                 avr_int_vector_t * vector,
91                 uint8_t old);
92
93 // return the IRQ that is raised when the vector is enabled and called/cleared
94 // this allows tracing of pending interrupts
95 avr_irq_t *
96 avr_get_interrupt_irq(
97                 struct avr_t * avr,
98                 uint8_t v);
99
100 // reset the interrupt table and the fifo
101 void
102 avr_interrupt_reset(
103                 struct avr_t * avr );
104
105 #ifdef __cplusplus
106 };
107 #endif
108
109 #endif /* __SIM_INTERRUPTS_H__ */