4 Copyright 2008, 2009 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/>.
26 #include "avr_extint.h"
29 static void avr_extint_irq_notify(struct avr_irq_t * irq, uint32_t value, void * param)
31 avr_extint_t * p = (avr_extint_t *)param;
32 avr_t * avr = p->io.avr;
34 uint8_t mode = avr_regbit_get_array(avr, p->eint[irq->irq].isc, 2);
35 int up = !irq->value && value;
36 int down = irq->value && !value;
43 avr_raise_interrupt(avr, &p->eint[irq->irq].vector);
47 avr_raise_interrupt(avr, &p->eint[irq->irq].vector);
51 avr_raise_interrupt(avr, &p->eint[irq->irq].vector);
56 static void avr_extint_reset(avr_io_t * port)
58 avr_extint_t * p = (avr_extint_t *)port;
60 for (int i = 0; i < EXTINT_COUNT; i++) {
61 avr_irq_register_notify(p->io.irq + i, avr_extint_irq_notify, p);
63 if (p->eint[i].port_ioctl) {
64 avr_irq_t * irq = avr_io_getirq(p->io.avr,
65 p->eint[i].port_ioctl, p->eint[i].port_pin);
67 avr_connect_irq(irq, p->io.irq + i);
72 static const char * irq_names[EXTINT_COUNT] = {
73 [EXTINT_IRQ_OUT_INT0] = "<int0",
74 [EXTINT_IRQ_OUT_INT1] = "<int1",
75 [EXTINT_IRQ_OUT_INT2] = "<int2",
76 [EXTINT_IRQ_OUT_INT3] = "<int3",
77 [EXTINT_IRQ_OUT_INT4] = "<int4",
78 [EXTINT_IRQ_OUT_INT5] = "<int5",
79 [EXTINT_IRQ_OUT_INT6] = "<int6",
80 [EXTINT_IRQ_OUT_INT7] = "<int7",
83 static avr_io_t _io = {
85 .reset = avr_extint_reset,
86 .irq_names = irq_names,
89 void avr_extint_init(avr_t * avr, avr_extint_t * p)
93 avr_register_io(avr, &p->io);
94 for (int i = 0; i < EXTINT_COUNT; i++)
95 avr_register_vector(avr, &p->eint[i].vector);
97 // allocate this module's IRQ
98 avr_io_setirqs(&p->io, AVR_IOCTL_EXTINT_GETIRQ(), EXTINT_COUNT, NULL);