Many more changes, timed callbacks etc
[simavr] / simavr / sim / sim_interrupts.h
1 /*
2         sim_interrupts.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_INTERUPTS_H__
23 #define __SIM_INTERUPTS_H__
24
25 #include "sim_avr.h"
26
27 // interrupt vector for the IO modules
28 typedef struct avr_int_vector_t {
29         uint8_t vector;         // vector number, zero (reset) is reserved
30
31         avr_regbit_t enable;    // IO register index for the "interrupt enable" flag for this vector
32         avr_regbit_t raised;    // IO register index for the register where the "raised" flag is (optional)
33
34         uint8_t                 trace;          // only for debug of a vector
35 } avr_int_vector_t;
36
37
38 /*
39  * Interrupt Helper Functions
40  */
41 // register an interrupt vector. It's only needed if you want to use the "r_raised" flags
42 void avr_register_vector(avr_t *avr, avr_int_vector_t * vector);
43 // raise an interrupt (if enabled). The interrupt is latched and will be called later
44 // return non-zero if the interrupt was raised and is now pending
45 int avr_raise_interrupt(avr_t * avr, avr_int_vector_t * vector);
46 // return non-zero if the AVR core has any pending interrupts
47 int avr_has_pending_interrupts(avr_t * avr);
48 // return nonzero if a specific interrupt vector is pending
49 int avr_is_interrupt_pending(avr_t * avr, avr_int_vector_t * vector);
50 // clear the "pending" status of an interrupt
51 void avr_clear_interrupt(avr_t * avr, int v);
52 // called by the core at each cycle to check whether an interrupt is pending
53 void avr_service_interrupts(avr_t * avr);
54
55 #endif /* __SIM_INTERUPTS_H__ */