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/>.
34 avr_io_t * port = avr->io_port;
36 while (port && res == -1) {
38 res = port->ioctl(port, ctl, io_param);
49 io->next = avr->io_port;
61 avr_io_addr_t a = AVR_DATA_TO_IO(addr);
62 if (avr->io[a].r.param || avr->io[a].r.c) {
63 if (avr->io[a].r.param != param || avr->io[a].r.c != readp) {
65 "Error: avr_register_io_read(): Already registered, refusing to override.\n");
67 "Error: avr_register_io_read(%04x : %p/%p): %p/%p\n", a,
68 avr->io[a].r.c, avr->io[a].r.param, readp, param);
72 avr->io[a].r.param = param;
73 avr->io[a].r.c = readp;
84 for (int i = 0; i < avr->io_shared_io[io].used; i++) {
85 avr_io_write_t c = avr->io_shared_io[io].io[i].c;
87 c(avr, addr, v, avr->io_shared_io[io].io[i].param);
92 avr_register_io_write(
95 avr_io_write_t writep,
98 avr_io_addr_t a = AVR_DATA_TO_IO(addr);
101 * Verifying that some other piece of code is not installed to watch write
102 * on this address. If there is, this code installs a "dispatcher" callback
103 * instead to handle multiple clients, otherwise, it continues as usual
105 if (avr->io[a].w.param || avr->io[a].w.c) {
106 if (avr->io[a].w.param != param || avr->io[a].w.c != writep) {
107 // if the muxer not already installed, allocate a new slot
108 if (avr->io[a].w.c != _avr_io_mux_write) {
109 int no = avr->io_shared_io_count++;
110 if (avr->io_shared_io_count > 4) {
112 "Error: avr_register_io_write(): Too many shared IO registers.\n");
116 "Note: avr_register_io_write(%04x): Installing muxer on register.\n", addr);
117 avr->io_shared_io[no].used = 1;
118 avr->io_shared_io[no].io[0].param = avr->io[a].w.param;
119 avr->io_shared_io[no].io[0].c = avr->io[a].w.c;
120 avr->io[a].w.param = (void*)no;
121 avr->io[a].w.c = _avr_io_mux_write;
123 int no = (int)avr->io[a].w.param;
124 int d = avr->io_shared_io[no].used++;
125 if (avr->io_shared_io[no].used > 4) {
127 "Error: avr_register_io_write(): Too many callbacks on %04x.\n", addr);
130 avr->io_shared_io[no].io[d].param = param;
131 avr->io_shared_io[no].io[d].c = writep;
135 avr->io[a].w.param = param;
136 avr->io[a].w.c = writep;
145 avr_io_t * port = avr->io_port;
147 if (port->irq && port->irq_ioctl_get == ctl && port->irq_count > index)
148 return port->irq + index;
161 avr_io_addr_t a = AVR_DATA_TO_IO(addr);
162 if (avr->io[a].irq == NULL) {
163 avr->io[a].irq = avr_alloc_irq(&avr->irq_pool, 0, 9, NULL /* TODO: names*/);
164 // mark the pin ones as filtered, so they only are raised when changing
165 for (int i = 0; i < 8; i++)
166 avr->io[a].irq[i].flags |= IRQ_FLAG_FILTERED;
168 return index < 9 ? avr->io[a].irq + index : NULL;
178 // allocate this module's IRQ
179 io->irq_count = count;
180 io->irq = irqs ? irqs :
181 avr_alloc_irq(&io->avr->irq_pool, 0,
182 count, NULL /* TODO: names*/);
183 io->irq_ioctl_get = ctl;
193 avr_free_irq(io->irq, io->irq_count);
195 io->irq_ioctl_get = 0;
204 avr_io_t * port = avr->io_port;
206 avr_io_t * next = port->next;
207 avr_deallocate_io(port);