From: Sami Liedes Date: Fri, 18 Feb 2011 20:09:24 +0000 (+0200) Subject: avr_register_io_[read,write](): fail if overriding earlier registration. X-Git-Tag: v1.0a7~30 X-Git-Url: https://git.htl-mechatronik.at/public/?a=commitdiff_plain;h=b682e4b6309f42fe5b3babec0935461264bcd785;p=sx%2Fsimavr.git avr_register_io_[read,write](): fail if overriding earlier registration. The avr_register_io_*() functions do not maintain a chain of callbacks. This can be confusing if someone like me tries to use them to listen to some I/O events (for which you should use the avr_irq_* stuff). Make this more explicit by checking in the register functions if we already have a callback and failing with an error message if so. Signed-off-by: Sami Liedes --- diff --git a/simavr/sim/sim_io.c b/simavr/sim/sim_io.c index 42e8c1b..3ef9d35 100644 --- a/simavr/sim/sim_io.c +++ b/simavr/sim/sim_io.c @@ -47,6 +47,10 @@ void avr_register_io(avr_t *avr, avr_io_t * io) void avr_register_io_read(avr_t *avr, avr_io_addr_t addr, avr_io_read_t readp, void * param) { avr_io_addr_t a = AVR_DATA_TO_IO(addr); + if (avr->io[a].r.param || avr->io[a].r.c) { + fputs("Error: avr_register_io_read(): Already registered, refusing to override.\n", stderr); + exit(1); + } avr->io[a].r.param = param; avr->io[a].r.c = readp; } @@ -54,6 +58,10 @@ void avr_register_io_read(avr_t *avr, avr_io_addr_t addr, avr_io_read_t readp, v void avr_register_io_write(avr_t *avr, avr_io_addr_t addr, avr_io_write_t writep, void * param) { avr_io_addr_t a = AVR_DATA_TO_IO(addr); + if (avr->io[a].w.param || avr->io[a].w.c) { + fputs("Error: avr_register_io_write(): Already registered, refusing to override.\n", stderr); + exit(1); + } avr->io[a].w.param = param; avr->io[a].w.c = writep; }