4 Copyright 2008-2012 Michel Pollet <buserror@gmail.com>
6 This file is part of simavr.
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.
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.
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/>.
22 #ifndef __SIM_INTERRUPTS_H__
23 #define __SIM_INTERRUPTS_H__
25 #include "sim_avr_types.h"
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)
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
43 // interrupt vectors, and their enable/clear registers
44 typedef struct avr_int_table_t {
45 avr_int_vector_t * vector[64];
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
50 pending_r; // fifo cursors
51 } avr_int_table_t, *avr_int_table_p;
54 * Interrupt Helper Functions
56 // register an interrupt vector. It's only needed if you want to use the "r_raised" flags
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
66 avr_int_vector_t * vector);
67 // return non-zero if the AVR core has any pending interrupts
69 avr_has_pending_interrupts(
71 // return nonzero if a specific interrupt vector is pending
73 avr_is_interrupt_pending(
75 avr_int_vector_t * vector);
76 // clear the "pending" status of an interrupt
80 avr_int_vector_t * vector);
81 // called by the core at each cycle to check whether an interrupt is pending
83 avr_service_interrupts(
86 // clear the interrupt (inc pending) if "raised" flag is 1
88 avr_clear_interrupt_if(
90 avr_int_vector_t * vector,
93 // return the IRQ that is raised when the vector is enabled and called/cleared
94 // this allows tracing of pending interrupts
96 avr_get_interrupt_irq(
100 // reset the interrupt table and the fifo
103 struct avr_t * avr );
109 #endif /* __SIM_INTERRUPTS_H__ */