659a4979d0dc6a8ddd1e64ab29df91ce80baaa28
[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 #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                 trace;          // only for debug of a vector
40 } avr_int_vector_t;
41
42
43 /*
44  * Interrupt Helper Functions
45  */
46 // register an interrupt vector. It's only needed if you want to use the "r_raised" flags
47 void avr_register_vector(avr_t *avr, avr_int_vector_t * vector);
48 // raise an interrupt (if enabled). The interrupt is latched and will be called later
49 // return non-zero if the interrupt was raised and is now pending
50 int avr_raise_interrupt(avr_t * avr, avr_int_vector_t * vector);
51 // return non-zero if the AVR core has any pending interrupts
52 int avr_has_pending_interrupts(avr_t * avr);
53 // return nonzero if a specific interrupt vector is pending
54 int avr_is_interrupt_pending(avr_t * avr, avr_int_vector_t * vector);
55 // clear the "pending" status of an interrupt
56 void avr_clear_interrupt(avr_t * avr, int v);
57 // called by the core at each cycle to check whether an interrupt is pending
58 void avr_service_interrupts(avr_t * avr);
59
60 // clear the interrupt (inc pending) if "raised" flag is 1
61 int avr_clear_interupt_if(avr_t * avr, avr_int_vector_t * vector, uint8_t old);
62
63 // return the IRQ that is raised when the vector is enabled and called/cleared
64 // this allows tracing of pending interupts
65 avr_irq_t * avr_get_interupt_irq(avr_t * avr, uint8_t v);
66
67 #ifdef __cplusplus
68 };
69 #endif
70
71 #endif /* __SIM_INTERUPTS_H__ */