SimAVR
AVR Simulator
sim_interrupts.h
Go to the documentation of this file.
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 it under the terms of the GNU
9  * General Public License as published by the Free Software Foundation, either version 3 of the
10  * License, or (at your option) any later version.
11  *
12  * simavr is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
13  * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
14  * Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License along with simavr. If not, see
17  * <http://www.gnu.org/licenses/>.
18  */
19 
25 #ifndef __SIM_INTERRUPTS_H__
26 #define __SIM_INTERRUPTS_H__
27 
28 #include "sim_avr_types.h"
29 #include "sim_irq.h"
30 
31 #ifdef __cplusplus
32 extern "C"
33 {
34 #endif
35 
37  typedef struct avr_int_vector_t
38  {
39  uint8_t vector;
42 
44  uint8_t pending:1, // 1 while scheduled in the fifo
45  trace:1, // only for debug of a vector
46  raise_sticky:1;
49 
51  typedef struct avr_int_table_t
52  {
54  uint8_t vector_count;
56  uint8_t pending_w, pending_r;
58 
59  /*
60  * Interrupt Helper Functions
61  */
62 
64  void avr_register_vector (struct avr_t *avr, avr_int_vector_t * vector);
67  int avr_raise_interrupt (struct avr_t *avr, avr_int_vector_t * vector);
69  int avr_has_pending_interrupts (struct avr_t *avr);
71  int avr_is_interrupt_pending (struct avr_t *avr, avr_int_vector_t * vector);
73  void avr_clear_interrupt (struct avr_t *avr, avr_int_vector_t * vector);
75  void avr_service_interrupts (struct avr_t *avr);
76 
78  int avr_clear_interrupt_if (struct avr_t *avr, avr_int_vector_t * vector, uint8_t old);
79 
82  avr_irq_t *avr_get_interrupt_irq (struct avr_t *avr, uint8_t v);
83 
85  void avr_interrupt_init (struct avr_t *avr);
86 
88  void avr_interrupt_reset (struct avr_t *avr);
89 
90 #ifdef __cplusplus
91 };
92 #endif
93 
94 #endif /* __SIM_INTERRUPTS_H__ */
95 
struct avr_int_vector_t avr_int_vector_t
interrupt vector for the IO modules
struct avr_int_table_t * avr_int_table_p
void avr_register_vector(struct avr_t *avr, avr_int_vector_t *vector)
Register an interrupt vector. It's only needed if you want to use the "r_raised" flags.
Definition: sim_interrupts.c:51
avr_irq_t * avr_get_interrupt_irq(struct avr_t *avr, uint8_t v)
Return the IRQ that is raised when the vector is enabled and called/cleared this allows tracing of pe...
Definition: sim_interrupts.c:161
avr_irq_t irq
raised to 1 when queued, to zero when called
Definition: sim_interrupts.h:43
uint8_t pending_w
Definition: sim_interrupts.h:56
avr_t * avr
Definition: run_avr.c:54
Interrupt vectors, and their enable/clear registers.
Definition: sim_interrupts.h:51
int avr_clear_interrupt_if(struct avr_t *avr, avr_int_vector_t *vector, uint8_t old)
Clear the interrupt (inc pending) if "raised" flag is 1.
Definition: sim_interrupts.c:149
uint8_t trace
Definition: sim_interrupts.h:44
uint8_t pending
Definition: sim_interrupts.h:44
avr_int_vector_t * vector[64]
Definition: sim_interrupts.h:53
interrupt vector for the IO modules
Definition: sim_interrupts.h:37
avr_int_vector_t * pending[64]
needs to be >= vectors and a power of two
Definition: sim_interrupts.h:55
This 'structure' is a packed representation of an IO register 'bit' (or consecutive bits)...
Definition: sim_avr_types.h:47
void avr_interrupt_reset(struct avr_t *avr)
Reset the interrupt table and the fifo.
Definition: sim_interrupts.c:40
int avr_raise_interrupt(struct avr_t *avr, avr_int_vector_t *vector)
Raise an interrupt (if enabled).
Definition: sim_interrupts.c:89
uint8_t pending_r
fifo cursors
Definition: sim_interrupts.h:56
struct avr_int_table_t avr_int_table_t
Interrupt vectors, and their enable/clear registers.
void avr_clear_interrupt(struct avr_t *avr, avr_int_vector_t *vector)
Clear the "pending" status of an interrupt.
Definition: sim_interrupts.c:136
int avr_is_interrupt_pending(struct avr_t *avr, avr_int_vector_t *vector)
Return nonzero if a specific interrupt vector is pending.
Definition: sim_interrupts.c:77
avr_regbit_t raised
IO register index for the register where the "raised" flag is (optional)
Definition: sim_interrupts.h:41
avr_regbit_t enable
IO register index for the "interrupt enable" flag for this vector.
Definition: sim_interrupts.h:40
void avr_interrupt_init(struct avr_t *avr)
Initializes the interrupt table.
Definition: sim_interrupts.c:33
int avr_has_pending_interrupts(struct avr_t *avr)
Return non-zero if the AVR core has any pending interrupts.
Definition: sim_interrupts.c:70
void avr_service_interrupts(struct avr_t *avr)
Called by the core at each cycle to check whether an interrupt is pending.
Definition: sim_interrupts.c:175
Main AVR instance.
Definition: sim_avr.h:142
Public IRQ structure.
Definition: sim_irq.h:76
uint8_t vector_count
Definition: sim_interrupts.h:54
uint8_t raise_sticky
1 if the interrupt flag (= the raised regbit) is not cleared
Definition: sim_interrupts.h:44
uint8_t vector
vector number, zero (reset) is reserved
Definition: sim_interrupts.h:39