Commit 2a4950ae28f13d711de99936e9a35263ad2ce6d8
authorMichel Pollet <buserror@gmail.com>
Fri, 24 Jul 2015 15:25:11 +0000 (16:25 +0100)
committerMichel Pollet <buserror@gmail.com>
Fri, 24 Jul 2015 15:25:11 +0000 (16:25 +0100)
the mega8/16/32 don't have ADCSRB, this lead to a crash when we tried to
register a callback on it.

Signed-off-by: Michel Pollet <buserror@gmail.com>
simavr/sim/avr_adc.c

index ad64b9e81af4199c19a85aad8e35bffe872a6efb..3508bd0f0ffb7df2bcd929e7a87f62222c89c5e5 100644 (file)
@@ -343,7 +343,9 @@ void avr_adc_init(avr_t * avr, avr_adc_t * p)
        avr_io_setirqs(&p->io, AVR_IOCTL_ADC_GETIRQ, ADC_IRQ_COUNT, NULL);
 
        avr_register_io_write(avr, p->r_adcsra, avr_adc_write_adcsra, p);
-       avr_register_io_write(avr, p->r_adcsrb, avr_adc_write_adcsrb, p);
+       // some ADCs don't have ADCSRB (atmega8/16/32)
+       if (p->r_adcsrb)
+               avr_register_io_write(avr, p->r_adcsrb, avr_adc_write_adcsrb, p);
        avr_register_io_read(avr, p->r_adcl, avr_adc_read_l, p);
        avr_register_io_read(avr, p->r_adch, avr_adc_read_h, p);
 }