From f4d247822cc09a3be6e4b5ac032313f23372128a Mon Sep 17 00:00:00 2001 From: Max Schwarz Date: Thu, 5 Feb 2015 23:18:26 +0100 Subject: [PATCH] sim_core + sim_regbit: use 16 bit integers for IO addresses This is necessary on the larger ATmegas (e.g. ATmega2560). --- simavr/sim/sim_core.c | 6 +++--- simavr/sim/sim_regbit.h | 16 ++++++++-------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/simavr/sim/sim_core.c b/simavr/sim/sim_core.c index e58b86f..afdb239 100644 --- a/simavr/sim/sim_core.c +++ b/simavr/sim/sim_core.c @@ -162,7 +162,7 @@ uint8_t avr_core_watch_read(avr_t *avr, uint16_t addr) * if it's an IO register (> 31) also (try to) call any callback that was * registered to track changes to that register. */ -static inline void _avr_set_r(avr_t * avr, uint8_t r, uint8_t v) +static inline void _avr_set_r(avr_t * avr, uint16_t r, uint8_t v) { REG_TOUCH(avr, r); @@ -173,7 +173,7 @@ static inline void _avr_set_r(avr_t * avr, uint8_t r, uint8_t v) SREG(); } if (r > 31) { - uint8_t io = AVR_DATA_TO_IO(r); + avr_io_addr_t io = AVR_DATA_TO_IO(r); if (avr->io[io].w.c) avr->io[io].w.c(avr, r, v, avr->io[io].w.param); else @@ -225,7 +225,7 @@ static inline uint8_t _avr_get_ram(avr_t * avr, uint16_t addr) READ_SREG_INTO(avr, avr->data[R_SREG]); } else if (addr > 31 && addr < 31 + MAX_IOs) { - uint8_t io = AVR_DATA_TO_IO(addr); + avr_io_addr_t io = AVR_DATA_TO_IO(addr); if (avr->io[io].r.c) avr->data[addr] = avr->io[io].r.c(avr, addr, avr->io[io].r.param); diff --git a/simavr/sim/sim_regbit.h b/simavr/sim/sim_regbit.h index 82df38d..63cc1a2 100644 --- a/simavr/sim/sim_regbit.h +++ b/simavr/sim/sim_regbit.h @@ -42,7 +42,7 @@ extern "C" { */ static inline uint8_t avr_regbit_set(avr_t * avr, avr_regbit_t rb) { - uint8_t a = rb.reg; + uint16_t a = rb.reg; uint8_t m; if (!a) @@ -54,7 +54,7 @@ static inline uint8_t avr_regbit_set(avr_t * avr, avr_regbit_t rb) static inline uint8_t avr_regbit_setto(avr_t * avr, avr_regbit_t rb, uint8_t v) { - uint8_t a = rb.reg; + uint16_t a = rb.reg; uint8_t m; if (!a) @@ -69,7 +69,7 @@ static inline uint8_t avr_regbit_setto(avr_t * avr, avr_regbit_t rb, uint8_t v) */ static inline uint8_t avr_regbit_setto_raw(avr_t * avr, avr_regbit_t rb, uint8_t v) { - uint8_t a = rb.reg; + uint16_t a = rb.reg; uint8_t m; if (!a) @@ -81,7 +81,7 @@ static inline uint8_t avr_regbit_setto_raw(avr_t * avr, avr_regbit_t rb, uint8_t static inline uint8_t avr_regbit_get(avr_t * avr, avr_regbit_t rb) { - uint8_t a = rb.reg; + uint16_t a = rb.reg; if (!a) return 0; //uint8_t m = rb.mask << rb.bit; @@ -95,7 +95,7 @@ static inline uint8_t avr_regbit_get(avr_t * avr, avr_regbit_t rb) */ static inline uint8_t avr_regbit_from_value(avr_t * avr, avr_regbit_t rb, uint8_t value) { - uint8_t a = rb.reg; + uint16_t a = rb.reg; if (!a) return 0; return (value >> rb.bit) & rb.mask; @@ -106,7 +106,7 @@ static inline uint8_t avr_regbit_from_value(avr_t * avr, avr_regbit_t rb, uint8_ */ static inline uint8_t avr_regbit_get_raw(avr_t * avr, avr_regbit_t rb) { - uint8_t a = rb.reg; + uint16_t a = rb.reg; if (!a) return 0; //uint8_t m = rb.mask << rb.bit; @@ -115,7 +115,7 @@ static inline uint8_t avr_regbit_get_raw(avr_t * avr, avr_regbit_t rb) static inline uint8_t avr_regbit_clear(avr_t * avr, avr_regbit_t rb) { - uint8_t a = (rb.reg); + uint16_t a = rb.reg; uint8_t m = rb.mask << rb.bit; avr_core_watch_write(avr, a, avr->data[a] & ~m); return avr->data[a]; @@ -133,7 +133,7 @@ static inline uint8_t avr_regbit_get_array(avr_t * avr, avr_regbit_t *rb, int co int i; for (i = 0; i < count; i++, rb++) if (rb->reg) { - uint8_t a = (rb->reg); + uint16_t a = rb->reg; res |= ((avr->data[a] >> rb->bit) & rb->mask) << i; } return res; -- 2.39.5