SimAVR
AVR Simulator
avr_extint.h
Go to the documentation of this file.
1 /*
2  * avr_extint.h
3  *
4  * External Interrupt Handling (for INT0-3)
5  *
6  * Copyright 2008, 2009 Michel Pollet <buserror@gmail.com>
7  * Copyright 2014 Doug Szumski <d.s.szumski@gmail.com>
8  *
9  * This file is part of simavr.
10  *
11  * simavr is free software: you can redistribute it and/or modify it under the terms of the GNU
12  * General Public License as published by the Free Software Foundation, either version 3 of the
13  * License, or (at your option) any later version.
14  *
15  * simavr is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
16  * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
17  * Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License along with simavr. If not, see
20  * <http://www.gnu.org/licenses/>.
21  */
22 
28 #ifndef __AVR_EXTINT_H__
29 #define __AVR_EXTINT_H__
30 
31 #ifdef __cplusplus
32 extern "C"
33 {
34 #endif
35 
36 #include "sim_avr.h"
37 
38  enum
39  {
45  };
46 
48 #define AVR_IOCTL_EXTINT_GETIRQ() AVR_IOCTL_DEF('i','n','t',' ')
49 
56  typedef struct avr_extint_t
57  {
59 
60  struct
61  {
64 
65  uint32_t port_ioctl;
66  uint8_t port_pin;
67  } eint[EXTINT_COUNT];
68 
69  } avr_extint_t;
70 
71  void avr_extint_init (avr_t * avr, avr_extint_t * p);
72 
77 #define AVR_EXTINT_DECLARE(_index, _portname, _portpin) \
78  .eint[_index] = { \
79  .port_ioctl = AVR_IOCTL_IOPORT_GETIRQ(_portname), \
80  .port_pin = _portpin, \
81  .isc = { AVR_IO_REGBIT(EICRA, ISC##_index##0), AVR_IO_REGBIT(EICRA, ISC##_index##1) }, \
82  .vector = { \
83  .enable = AVR_IO_REGBIT(EIMSK, INT##_index), \
84  .raised = AVR_IO_REGBIT(EIFR, INTF##_index), \
85  .vector = INT##_index##_vect, \
86  }, \
87  }
88 
91 #define AVR_ASYNC_EXTINT_DECLARE(_index, _portname, _portpin) \
92  .eint[_index] = { \
93  .port_ioctl = AVR_IOCTL_IOPORT_GETIRQ(_portname), \
94  .port_pin = _portpin, \
95  .isc = { AVR_IO_REGBIT(MCUCSR, ISC##_index) }, \
96  .vector = { \
97  .enable = AVR_IO_REGBIT(GICR, INT##_index), \
98  .raised = AVR_IO_REGBIT(GIFR, INTF##_index), \
99  .vector = INT##_index##_vect, \
100  }, \
101  }
102 
103 #define AVR_EXTINT_MEGA_DECLARE(_index, _portname, _portpin, _EICR) \
104  .eint[_index] = { \
105  .port_ioctl = AVR_IOCTL_IOPORT_GETIRQ(_portname), \
106  .port_pin = _portpin, \
107  .isc = { AVR_IO_REGBIT(EICR##_EICR, ISC##_index##0), AVR_IO_REGBIT(EICR##_EICR, ISC##_index##1) }, \
108  .vector = { \
109  .enable = AVR_IO_REGBIT(EIMSK, INT##_index), \
110  .raised = AVR_IO_REGBIT(EIFR, INTF##_index), \
111  .vector = INT##_index##_vect, \
112  }, \
113  }
114 
115 #define AVR_EXTINT_TINY_DECLARE(_index, _portname, _portpin, _IFR) \
116  .eint[_index] = { \
117  .port_ioctl = AVR_IOCTL_IOPORT_GETIRQ(_portname), \
118  .port_pin = _portpin, \
119  .isc = { AVR_IO_REGBIT(MCUCR, ISC##_index##0), AVR_IO_REGBIT(MCUCR, ISC##_index##1) }, \
120  .vector = { \
121  .enable = AVR_IO_REGBIT(GIMSK, INT##_index), \
122  .raised = AVR_IO_REGBIT(_IFR, INTF##_index), \
123  .vector = INT##_index##_vect, \
124  }, \
125  }
126 
127 #ifdef __cplusplus
128 };
129 #endif
130 
131 #endif /*__AVR_EXTINT_H__*/
132 
Definition: avr_extint.h:42
uint32_t port_ioctl
ioctl to use to get port
Definition: avr_extint.h:65
Definition: avr_extint.h:44
Definition: avr_extint.h:43
avr_t * avr
Definition: run_avr.c:54
Definition: avr_extint.h:42
interrupt vector for the IO modules
Definition: sim_interrupts.h:37
Definition: avr_extint.h:41
This 'structure' is a packed representation of an IO register 'bit' (or consecutive bits)...
Definition: sim_avr_types.h:47
Definition: avr_extint.h:41
avr_regbit_t isc[2]
interrupt sense control bits
Definition: avr_extint.h:62
This module is just a "relay" for the pin change IRQ in the IO port module.
Definition: avr_extint.h:56
struct avr_extint_t avr_extint_t
This module is just a "relay" for the pin change IRQ in the IO port module.
void avr_extint_init(avr_t *avr, avr_extint_t *p)
Definition: avr_extint.c:98
Definition: avr_extint.h:40
Definition: avr_extint.h:41
struct avr_extint_t::@6 eint[EXTINT_COUNT]
avr_int_vector_t vector
interrupt vector
Definition: avr_extint.h:63
Main AVR instance.
Definition: sim_avr.h:142
IO module base struct Modules uses that as their first member in their own struct.
Definition: sim_io.h:42
avr_io_t io
Definition: avr_extint.h:58
Definition: avr_extint.h:42
uint8_t port_pin
pin number in said port
Definition: avr_extint.h:66