From de7b0e404c28136d77832e3145e7ce947ce8a38d Mon Sep 17 00:00:00 2001 From: Konstantin Begun Date: Wed, 10 May 2017 23:54:52 +0100 Subject: [PATCH] cores: Add support for Analog Comparator --- simavr/cores/sim_90usb162.c | 19 +++++++++++++++++++ simavr/cores/sim_mega128.c | 26 ++++++++++++++++++++++++++ simavr/cores/sim_mega1280.c | 27 +++++++++++++++++++++++++++ simavr/cores/sim_mega1281.c | 27 +++++++++++++++++++++++++++ simavr/cores/sim_mega128rfa1.c | 27 +++++++++++++++++++++++++++ simavr/cores/sim_mega128rfr2.c | 27 +++++++++++++++++++++++++++ simavr/cores/sim_mega169.c | 27 +++++++++++++++++++++++++++ simavr/cores/sim_mega2560.c | 26 ++++++++++++++++++++++++++ simavr/cores/sim_megax.c | 1 + simavr/cores/sim_megax.h | 26 ++++++++++++++++++++++++++ simavr/cores/sim_megax4.c | 1 + simavr/cores/sim_megax4.h | 26 ++++++++++++++++++++++++++ simavr/cores/sim_megax8.c | 1 + simavr/cores/sim_megax8.h | 25 +++++++++++++++++++++++++ simavr/cores/sim_tiny13.c | 23 +++++++++++++++++++++++ simavr/cores/sim_tiny2313.c | 23 ++++++++++++++++++++++- simavr/cores/sim_tinyx4.c | 1 + simavr/cores/sim_tinyx4.h | 25 +++++++++++++++++++++++++ simavr/cores/sim_tinyx5.c | 1 + simavr/cores/sim_tinyx5.h | 22 ++++++++++++++++++++++ 20 files changed, 380 insertions(+), 1 deletion(-) diff --git a/simavr/cores/sim_90usb162.c b/simavr/cores/sim_90usb162.c index bd3f136..9a45d15 100644 --- a/simavr/cores/sim_90usb162.c +++ b/simavr/cores/sim_90usb162.c @@ -31,6 +31,7 @@ #include "avr_timer.h" #include "avr_spi.h" #include "avr_usb.h" +#include "avr_acomp.h" void usb162_init(struct avr_t * avr); void usb162_reset(struct avr_t * avr); @@ -50,6 +51,7 @@ const struct mcu_t { avr_timer_t timer0,timer1; avr_spi_t spi; avr_usb_t usb; + avr_acomp_t acomp; } mcu_usb162 = { .core = { .mmcu = "at90usb162", @@ -212,6 +214,22 @@ const struct mcu_t { .usb_com_vect=USB_COM_vect, .usb_gen_vect=USB_GEN_vect, }, + .acomp = { + .r_acsr = ACSR, + .acis = { AVR_IO_REGBIT(ACSR, ACIS0), AVR_IO_REGBIT(ACSR, ACIS1) }, + .acic = AVR_IO_REGBIT(ACSR, ACIC), + .aco = AVR_IO_REGBIT(ACSR, ACO), + .acbg = AVR_IO_REGBIT(ACSR, ACBG), + .disabled = AVR_IO_REGBIT(ACSR, ACD), + + .timer_name = '1', + + .ac = { + .enable = AVR_IO_REGBIT(ACSR, ACIE), + .raised = AVR_IO_REGBIT(ACSR, ACI), + .vector = ANALOG_COMP_vect, + } + } }; static avr_t * make() @@ -240,6 +258,7 @@ void usb162_init(struct avr_t * avr) avr_timer_init(avr, &mcu->timer1); avr_spi_init(avr, &mcu->spi); avr_usb_init(avr, &mcu->usb); + avr_acomp_init(avr, &mcu->acomp); } void usb162_reset(struct avr_t * avr) diff --git a/simavr/cores/sim_mega128.c b/simavr/cores/sim_mega128.c index 4236b67..3b11f2a 100644 --- a/simavr/cores/sim_mega128.c +++ b/simavr/cores/sim_mega128.c @@ -31,6 +31,7 @@ #include "avr_timer.h" #include "avr_spi.h" #include "avr_twi.h" +#include "avr_acomp.h" void m128_init(struct avr_t * avr); void m128_reset(struct avr_t * avr); @@ -50,6 +51,7 @@ const struct mcu_t { avr_extint_t extint; avr_ioport_t porta, portb, portc, portd, porte, portf, portg; avr_uart_t uart0,uart1; + avr_acomp_t acomp; avr_adc_t adc; avr_timer_t timer0,timer1,timer2,timer3; avr_spi_t spi; @@ -89,6 +91,29 @@ const struct mcu_t { AVR_UARTX_DECLARE(0, 0, 0), AVR_UARTX_DECLARE(1, 0, 0), + .acomp = { + .mux_inputs = 8, + .mux = { AVR_IO_REGBIT(ADMUX, MUX0), AVR_IO_REGBIT(ADMUX, MUX1), + AVR_IO_REGBIT(ADMUX, MUX2) }, + .aden = AVR_IO_REGBIT(ADCSRA, ADEN), + .acme = AVR_IO_REGBIT(SFIOR, ACME), + + .r_acsr = ACSR, + .acis = { AVR_IO_REGBIT(ACSR, ACIS0), AVR_IO_REGBIT(ACSR, ACIS1) }, + .acic = AVR_IO_REGBIT(ACSR, ACIC), + .aco = AVR_IO_REGBIT(ACSR, ACO), + .acbg = AVR_IO_REGBIT(ACSR, ACBG), + .disabled = AVR_IO_REGBIT(ACSR, ACD), + + .timer_name = '1', + + .ac = { + .enable = AVR_IO_REGBIT(ACSR, ACIE), + .raised = AVR_IO_REGBIT(ACSR, ACI), + .vector = ANALOG_COMP_vect, + } + }, + .adc = { .r_admux = ADMUX, .mux = { AVR_IO_REGBIT(ADMUX, MUX0), AVR_IO_REGBIT(ADMUX, MUX1), @@ -421,6 +446,7 @@ void m128_init(struct avr_t * avr) avr_ioport_init(avr, &mcu->portg); avr_uart_init(avr, &mcu->uart0); avr_uart_init(avr, &mcu->uart1); + avr_acomp_init(avr, &mcu->acomp); avr_adc_init(avr, &mcu->adc); avr_timer_init(avr, &mcu->timer0); avr_timer_init(avr, &mcu->timer1); diff --git a/simavr/cores/sim_mega1280.c b/simavr/cores/sim_mega1280.c index 84a26a8..cff44a1 100644 --- a/simavr/cores/sim_mega1280.c +++ b/simavr/cores/sim_mega1280.c @@ -31,6 +31,7 @@ #include "avr_timer.h" #include "avr_spi.h" #include "avr_twi.h" +#include "avr_acomp.h" void m1280_init(struct avr_t * avr); void m1280_reset(struct avr_t * avr); @@ -54,6 +55,7 @@ const struct mcu_t { avr_ioport_t porta, portb, portc, portd, porte, portf, portg, porth, portj, portk, portl; avr_uart_t uart0,uart1; avr_uart_t uart2,uart3; + avr_acomp_t acomp; avr_adc_t adc; avr_timer_t timer0,timer1,timer2,timer3,timer4,timer5; avr_spi_t spi; @@ -106,6 +108,30 @@ const struct mcu_t { AVR_UARTX_DECLARE(2, PRR1, PRUSART2), AVR_UARTX_DECLARE(3, PRR1, PRUSART3), + .acomp = { + .mux_inputs = 16, + .mux = { AVR_IO_REGBIT(ADMUX, MUX0), AVR_IO_REGBIT(ADMUX, MUX1), + AVR_IO_REGBIT(ADMUX, MUX2), AVR_IO_REGBIT(ADCSRB, MUX5) }, + .pradc = AVR_IO_REGBIT(PRR0, PRADC), + .aden = AVR_IO_REGBIT(ADCSRA, ADEN), + .acme = AVR_IO_REGBIT(ADCSRB, ACME), + + .r_acsr = ACSR, + .acis = { AVR_IO_REGBIT(ACSR, ACIS0), AVR_IO_REGBIT(ACSR, ACIS1) }, + .acic = AVR_IO_REGBIT(ACSR, ACIC), + .aco = AVR_IO_REGBIT(ACSR, ACO), + .acbg = AVR_IO_REGBIT(ACSR, ACBG), + .disabled = AVR_IO_REGBIT(ACSR, ACD), + + .timer_name = '1', + + .ac = { + .enable = AVR_IO_REGBIT(ACSR, ACIE), + .raised = AVR_IO_REGBIT(ACSR, ACI), + .vector = ANALOG_COMP_vect, + } + }, + .adc = { .r_admux = ADMUX, .mux = { AVR_IO_REGBIT(ADMUX, MUX0), AVR_IO_REGBIT(ADMUX, MUX1), @@ -652,6 +678,7 @@ void m1280_init(struct avr_t * avr) avr_uart_init(avr, &mcu->uart1); avr_uart_init(avr, &mcu->uart2); avr_uart_init(avr, &mcu->uart3); + avr_acomp_init(avr, &mcu->acomp); avr_adc_init(avr, &mcu->adc); avr_timer_init(avr, &mcu->timer0); avr_timer_init(avr, &mcu->timer1); diff --git a/simavr/cores/sim_mega1281.c b/simavr/cores/sim_mega1281.c index 7c534d1..3bf28a0 100644 --- a/simavr/cores/sim_mega1281.c +++ b/simavr/cores/sim_mega1281.c @@ -31,6 +31,7 @@ #include "avr_timer.h" #include "avr_spi.h" #include "avr_twi.h" +#include "avr_acomp.h" void m1281_init(struct avr_t * avr); void m1281_reset(struct avr_t * avr); @@ -50,6 +51,7 @@ const struct mcu_t { avr_extint_t extint; avr_ioport_t porta, portb, portc, portd, porte, portf, portg; avr_uart_t uart0,uart1; + avr_acomp_t acomp; avr_adc_t adc; avr_timer_t timer0,timer1,timer2,timer3; avr_spi_t spi; @@ -96,6 +98,30 @@ const struct mcu_t { AVR_UARTX_DECLARE(0, PRR0, PRUSART0), AVR_UARTX_DECLARE(1, PRR1, PRUSART1), + .acomp = { + .mux_inputs = 8, + .mux = { AVR_IO_REGBIT(ADMUX, MUX0), AVR_IO_REGBIT(ADMUX, MUX1), + AVR_IO_REGBIT(ADMUX, MUX2) }, + .pradc = AVR_IO_REGBIT(PRR0, PRADC), + .aden = AVR_IO_REGBIT(ADCSRA, ADEN), + .acme = AVR_IO_REGBIT(ADCSRB, ACME), + + .r_acsr = ACSR, + .acis = { AVR_IO_REGBIT(ACSR, ACIS0), AVR_IO_REGBIT(ACSR, ACIS1) }, + .acic = AVR_IO_REGBIT(ACSR, ACIC), + .aco = AVR_IO_REGBIT(ACSR, ACO), + .acbg = AVR_IO_REGBIT(ACSR, ACBG), + .disabled = AVR_IO_REGBIT(ACSR, ACD), + + .timer_name = '1', + + .ac = { + .enable = AVR_IO_REGBIT(ACSR, ACIE), + .raised = AVR_IO_REGBIT(ACSR, ACI), + .vector = ANALOG_COMP_vect, + } + }, + .adc = { .r_admux = ADMUX, .mux = { AVR_IO_REGBIT(ADMUX, MUX0), AVR_IO_REGBIT(ADMUX, MUX1), @@ -460,6 +486,7 @@ void m1281_init(struct avr_t * avr) avr_ioport_init(avr, &mcu->portg); avr_uart_init(avr, &mcu->uart0); avr_uart_init(avr, &mcu->uart1); + avr_acomp_init(avr, &mcu->acomp); avr_adc_init(avr, &mcu->adc); avr_timer_init(avr, &mcu->timer0); avr_timer_init(avr, &mcu->timer1); diff --git a/simavr/cores/sim_mega128rfa1.c b/simavr/cores/sim_mega128rfa1.c index 6f433ee..5fa6141 100644 --- a/simavr/cores/sim_mega128rfa1.c +++ b/simavr/cores/sim_mega128rfa1.c @@ -33,6 +33,7 @@ #include "avr_timer.h" #include "avr_spi.h" #include "avr_twi.h" +#include "avr_acomp.h" void m128rfa1_init(struct avr_t * avr); void m128rfa1_reset(struct avr_t * avr); @@ -52,6 +53,7 @@ const struct mcu_t { avr_extint_t extint; avr_ioport_t portb, portd, porte, portf, portg; avr_uart_t uart0,uart1; + avr_acomp_t acomp; avr_adc_t adc; avr_timer_t timer0,timer1,timer2,timer3; avr_spi_t spi; @@ -104,6 +106,30 @@ const struct mcu_t { AVR_UARTX_DECLARE(0, PRR0, PRUSART0), AVR_UARTX_DECLARE(1, PRR1, PRUSART1), + .acomp = { + .mux_inputs = 8, + .mux = { AVR_IO_REGBIT(ADMUX, MUX0), AVR_IO_REGBIT(ADMUX, MUX1), + AVR_IO_REGBIT(ADMUX, MUX2), AVR_IO_REGBIT(ADCSRB, MUX5) }, + .pradc = AVR_IO_REGBIT(PRR0, PRADC), + .aden = AVR_IO_REGBIT(ADCSRA, ADEN), + .acme = AVR_IO_REGBIT(ADCSRB, ACME), + + .r_acsr = ACSR, + .acis = { AVR_IO_REGBIT(ACSR, ACIS0), AVR_IO_REGBIT(ACSR, ACIS1) }, + .acic = AVR_IO_REGBIT(ACSR, ACIC), + .aco = AVR_IO_REGBIT(ACSR, ACO), + .acbg = AVR_IO_REGBIT(ACSR, ACBG), + .disabled = AVR_IO_REGBIT(ACSR, ACD), + + .timer_name = '1', + + .ac = { + .enable = AVR_IO_REGBIT(ACSR, ACIE), + .raised = AVR_IO_REGBIT(ACSR, ACI), + .vector = ANALOG_COMP_vect, + } + }, + .adc = { .r_admux = ADMUX, .mux = { AVR_IO_REGBIT(ADMUX, MUX0), AVR_IO_REGBIT(ADMUX, MUX1), @@ -487,6 +513,7 @@ void m128rfa1_init(struct avr_t * avr) avr_ioport_init(avr, &mcu->portg); avr_uart_init(avr, &mcu->uart0); avr_uart_init(avr, &mcu->uart1); + avr_acomp_init(avr, &mcu->acomp); avr_adc_init(avr, &mcu->adc); avr_timer_init(avr, &mcu->timer0); avr_timer_init(avr, &mcu->timer1); diff --git a/simavr/cores/sim_mega128rfr2.c b/simavr/cores/sim_mega128rfr2.c index c69907d..1eb844b 100644 --- a/simavr/cores/sim_mega128rfr2.c +++ b/simavr/cores/sim_mega128rfr2.c @@ -33,6 +33,7 @@ #include "avr_timer.h" #include "avr_spi.h" #include "avr_twi.h" +#include "avr_acomp.h" void m128rfr2_init(struct avr_t * avr); void m128rfr2_reset(struct avr_t * avr); @@ -78,6 +79,7 @@ const struct mcu_t { avr_extint_t extint; avr_ioport_t portb, portd, porte, portf, portg; avr_uart_t uart0,uart1; + avr_acomp_t acomp; avr_adc_t adc; avr_timer_t timer0,timer1,timer2,timer3; avr_spi_t spi; @@ -130,6 +132,30 @@ const struct mcu_t { AVR_UARTX_DECLARE(0, PRR0, PRUSART0), AVR_UARTX_DECLARE(1, PRR1, PRUSART1), + .acomp = { + .mux_inputs = 8, + .mux = { AVR_IO_REGBIT(ADMUX, MUX0), AVR_IO_REGBIT(ADMUX, MUX1), + AVR_IO_REGBIT(ADMUX, MUX2), AVR_IO_REGBIT(ADCSRB, MUX5) }, + .pradc = AVR_IO_REGBIT(PRR0, PRADC), + .aden = AVR_IO_REGBIT(ADCSRA, ADEN), + .acme = AVR_IO_REGBIT(ADCSRB, ACME), + + .r_acsr = ACSR, + .acis = { AVR_IO_REGBIT(ACSR, ACIS0), AVR_IO_REGBIT(ACSR, ACIS1) }, + .acic = AVR_IO_REGBIT(ACSR, ACIC), + .aco = AVR_IO_REGBIT(ACSR, ACO), + .acbg = AVR_IO_REGBIT(ACSR, ACBG), + .disabled = AVR_IO_REGBIT(ACSR, ACD), + + .timer_name = '1', + + .ac = { + .enable = AVR_IO_REGBIT(ACSR, ACIE), + .raised = AVR_IO_REGBIT(ACSR, ACI), + .vector = ANALOG_COMP_vect, + } + }, + .adc = { .r_admux = ADMUX, .mux = { AVR_IO_REGBIT(ADMUX, MUX0), AVR_IO_REGBIT(ADMUX, MUX1), @@ -496,6 +522,7 @@ void m128rfr2_init(struct avr_t * avr) avr_ioport_init(avr, &mcu->portg); avr_uart_init(avr, &mcu->uart0); avr_uart_init(avr, &mcu->uart1); + avr_acomp_init(avr, &mcu->acomp); avr_adc_init(avr, &mcu->adc); avr_timer_init(avr, &mcu->timer0); avr_timer_init(avr, &mcu->timer1); diff --git a/simavr/cores/sim_mega169.c b/simavr/cores/sim_mega169.c index c72e96e..81c5319 100644 --- a/simavr/cores/sim_mega169.c +++ b/simavr/cores/sim_mega169.c @@ -14,6 +14,7 @@ #include "avr_timer.h" #include "avr_spi.h" #include "avr_twi.h" +#include "avr_acomp.h" void m169p_init(struct avr_t * avr); void m169p_reset(struct avr_t * avr); @@ -37,6 +38,7 @@ const struct mcu_t { avr_extint_t extint; avr_ioport_t porta, portb, portc, portd, porte, portf, portg; avr_uart_t uart0; + avr_acomp_t acomp; avr_adc_t adc; avr_timer_t timer0,timer1,timer2; avr_spi_t spi; @@ -79,6 +81,30 @@ const struct mcu_t { AVR_UARTX_DECLARE(0, PRR, PRUSART0), + .acomp = { + .mux_inputs = 8, + .mux = { AVR_IO_REGBIT(ADMUX, MUX0), AVR_IO_REGBIT(ADMUX, MUX1), + AVR_IO_REGBIT(ADMUX, MUX2) }, + .pradc = AVR_IO_REGBIT(PRR, PRADC), + .aden = AVR_IO_REGBIT(ADCSRA, ADEN), + .acme = AVR_IO_REGBIT(ADCSRB, ACME), + + .r_acsr = ACSR, + .acis = { AVR_IO_REGBIT(ACSR, ACIS0), AVR_IO_REGBIT(ACSR, ACIS1) }, + .acic = AVR_IO_REGBIT(ACSR, ACIC), + .aco = AVR_IO_REGBIT(ACSR, ACO), + .acbg = AVR_IO_REGBIT(ACSR, ACBG), + .disabled = AVR_IO_REGBIT(ACSR, ACD), + + .timer_name = '1', + + .ac = { + .enable = AVR_IO_REGBIT(ACSR, ACIE), + .raised = AVR_IO_REGBIT(ACSR, ACI), + .vector = ANALOG_COMP_vect, + } + }, + .adc = { .r_admux = ADMUX, .mux = { AVR_IO_REGBIT(ADMUX, MUX0), AVR_IO_REGBIT(ADMUX, MUX1), @@ -322,6 +348,7 @@ void m169p_init(struct avr_t * avr) avr_ioport_init(avr, &mcu->portg); avr_uart_init(avr, &mcu->uart0); + avr_acomp_init(avr, &mcu->acomp); avr_adc_init(avr, &mcu->adc); avr_timer_init(avr, &mcu->timer0); avr_timer_init(avr, &mcu->timer1); diff --git a/simavr/cores/sim_mega2560.c b/simavr/cores/sim_mega2560.c index 8e09e71..fc3812e 100644 --- a/simavr/cores/sim_mega2560.c +++ b/simavr/cores/sim_mega2560.c @@ -32,6 +32,7 @@ #include "avr_timer.h" #include "avr_spi.h" #include "avr_twi.h" +#include "avr_acomp.h" void m2560_init(struct avr_t * avr); void m2560_reset(struct avr_t * avr); @@ -55,6 +56,7 @@ const struct mcu_t { avr_ioport_t porta, portb, portc, portd, porte, portf, portg, porth, portj, portk, portl; avr_uart_t uart0,uart1; avr_uart_t uart2,uart3; + avr_acomp_t acomp; avr_adc_t adc; avr_timer_t timer0,timer1,timer2,timer3,timer4,timer5; avr_spi_t spi; @@ -108,6 +110,30 @@ const struct mcu_t { AVR_UARTX_DECLARE(2, PRR1, PRUSART2), AVR_UARTX_DECLARE(3, PRR1, PRUSART3), + .acomp = { + .mux_inputs = 16, + .mux = { AVR_IO_REGBIT(ADMUX, MUX0), AVR_IO_REGBIT(ADMUX, MUX1), + AVR_IO_REGBIT(ADMUX, MUX2), AVR_IO_REGBIT(ADCSRB, MUX5) }, + .pradc = AVR_IO_REGBIT(PRR0, PRADC), + .aden = AVR_IO_REGBIT(ADCSRA, ADEN), + .acme = AVR_IO_REGBIT(ADCSRB, ACME), + + .r_acsr = ACSR, + .acis = { AVR_IO_REGBIT(ACSR, ACIS0), AVR_IO_REGBIT(ACSR, ACIS1) }, + .acic = AVR_IO_REGBIT(ACSR, ACIC), + .aco = AVR_IO_REGBIT(ACSR, ACO), + .acbg = AVR_IO_REGBIT(ACSR, ACBG), + .disabled = AVR_IO_REGBIT(ACSR, ACD), + + .timer_name = '1', + + .ac = { + .enable = AVR_IO_REGBIT(ACSR, ACIE), + .raised = AVR_IO_REGBIT(ACSR, ACI), + .vector = ANALOG_COMP_vect, + } + }, + .adc = { .r_admux = ADMUX, .mux = { AVR_IO_REGBIT(ADMUX, MUX0), AVR_IO_REGBIT(ADMUX, MUX1), diff --git a/simavr/cores/sim_megax.c b/simavr/cores/sim_megax.c index c9077fa..2af1e53 100644 --- a/simavr/cores/sim_megax.c +++ b/simavr/cores/sim_megax.c @@ -38,6 +38,7 @@ void mx_init(struct avr_t * avr) avr_ioport_init(avr, &mcu->portc); avr_ioport_init(avr, &mcu->portd); avr_uart_init(avr, &mcu->uart); + avr_acomp_init(avr, &mcu->acomp); avr_adc_init(avr, &mcu->adc); avr_timer_init(avr, &mcu->timer0); avr_timer_init(avr, &mcu->timer1); diff --git a/simavr/cores/sim_megax.h b/simavr/cores/sim_megax.h index 81c26f5..2036394 100644 --- a/simavr/cores/sim_megax.h +++ b/simavr/cores/sim_megax.h @@ -33,6 +33,8 @@ #include "avr_timer.h" #include "avr_spi.h" #include "avr_twi.h" +#include "avr_acomp.h" + void mx_init(struct avr_t * avr); void mx_reset(struct avr_t * avr); @@ -48,6 +50,7 @@ struct mcu_t { avr_extint_t extint; avr_ioport_t portb, portc, portd; avr_uart_t uart; + avr_acomp_t acomp; avr_adc_t adc; avr_timer_t timer0,timer1,timer2; avr_spi_t spi; @@ -102,6 +105,29 @@ const struct mcu_t SIM_CORENAME = { //no PRUSART, upe=PE, no reg/bit name index, 'C' in RX/TX vector names AVR_UART_DECLARE(0, 0, PE, , C), + .acomp = { + .mux_inputs = 8, + .mux = { AVR_IO_REGBIT(ADMUX, MUX0), AVR_IO_REGBIT(ADMUX, MUX1), + AVR_IO_REGBIT(ADMUX, MUX2) }, + .aden = AVR_IO_REGBIT(ADCSRA, ADEN), + .acme = AVR_IO_REGBIT(SFIOR, ACME), + + .r_acsr = ACSR, + .acis = { AVR_IO_REGBIT(ACSR, ACIS0), AVR_IO_REGBIT(ACSR, ACIS1) }, + .acic = AVR_IO_REGBIT(ACSR, ACIC), + .aco = AVR_IO_REGBIT(ACSR, ACO), + .acbg = AVR_IO_REGBIT(ACSR, ACBG), + .disabled = AVR_IO_REGBIT(ACSR, ACD), + + .timer_name = '1', + + .ac = { + .enable = AVR_IO_REGBIT(ACSR, ACIE), + .raised = AVR_IO_REGBIT(ACSR, ACI), + .vector = ANA_COMP_vect, + } + }, + .adc = { .r_admux = ADMUX, .mux = { AVR_IO_REGBIT(ADMUX, MUX0), AVR_IO_REGBIT(ADMUX, MUX1), diff --git a/simavr/cores/sim_megax4.c b/simavr/cores/sim_megax4.c index 2d12208..15e87d8 100644 --- a/simavr/cores/sim_megax4.c +++ b/simavr/cores/sim_megax4.c @@ -37,6 +37,7 @@ void mx4_init(struct avr_t * avr) avr_ioport_init(avr, &mcu->portd); avr_uart_init(avr, &mcu->uart0); avr_uart_init(avr, &mcu->uart1); + avr_acomp_init(avr, &mcu->acomp); avr_adc_init(avr, &mcu->adc); avr_timer_init(avr, &mcu->timer0); avr_timer_init(avr, &mcu->timer1); diff --git a/simavr/cores/sim_megax4.h b/simavr/cores/sim_megax4.h index 2688692..10384b7 100644 --- a/simavr/cores/sim_megax4.h +++ b/simavr/cores/sim_megax4.h @@ -34,6 +34,7 @@ #include "avr_timer.h" #include "avr_spi.h" #include "avr_twi.h" +#include "avr_acomp.h" void mx4_init(struct avr_t * avr); void mx4_reset(struct avr_t * avr); @@ -49,6 +50,7 @@ struct mcu_t { avr_extint_t extint; avr_ioport_t porta, portb, portc, portd; avr_uart_t uart0,uart1; + avr_acomp_t acomp; avr_adc_t adc; avr_timer_t timer0,timer1,timer2; avr_timer_t timer3; @@ -131,6 +133,30 @@ const struct mcu_t SIM_CORENAME = { AVR_UARTX_DECLARE(0, PRR0, PRUSART0), AVR_UARTX_DECLARE(1, PRR0, PRUSART1), + .acomp = { + .mux_inputs = 8, + .mux = { AVR_IO_REGBIT(ADMUX, MUX0), AVR_IO_REGBIT(ADMUX, MUX1), + AVR_IO_REGBIT(ADMUX, MUX2) }, + .pradc = AVR_IO_REGBIT(PRR0, PRADC), + .aden = AVR_IO_REGBIT(ADCSRA, ADEN), + .acme = AVR_IO_REGBIT(ADCSRB, ACME), + + .r_acsr = ACSR, + .acis = { AVR_IO_REGBIT(ACSR, ACIS0), AVR_IO_REGBIT(ACSR, ACIS1) }, + .acic = AVR_IO_REGBIT(ACSR, ACIC), + .aco = AVR_IO_REGBIT(ACSR, ACO), + .acbg = AVR_IO_REGBIT(ACSR, ACBG), + .disabled = AVR_IO_REGBIT(ACSR, ACD), + + .timer_name = '1', + + .ac = { + .enable = AVR_IO_REGBIT(ACSR, ACIE), + .raised = AVR_IO_REGBIT(ACSR, ACI), + .vector = ANALOG_COMP_vect, + } + }, + .adc = { // .disabled = AVR_IO_REGBIT(PRR0,PRADC), .r_admux = ADMUX, diff --git a/simavr/cores/sim_megax8.c b/simavr/cores/sim_megax8.c index 46a3519..ba84d00 100644 --- a/simavr/cores/sim_megax8.c +++ b/simavr/cores/sim_megax8.c @@ -35,6 +35,7 @@ void mx8_init(struct avr_t * avr) avr_ioport_init(avr, &mcu->portc); avr_ioport_init(avr, &mcu->portd); avr_uart_init(avr, &mcu->uart); + avr_acomp_init(avr, &mcu->acomp); avr_adc_init(avr, &mcu->adc); avr_timer_init(avr, &mcu->timer0); avr_timer_init(avr, &mcu->timer1); diff --git a/simavr/cores/sim_megax8.h b/simavr/cores/sim_megax8.h index f9661ab..c4e1994 100644 --- a/simavr/cores/sim_megax8.h +++ b/simavr/cores/sim_megax8.h @@ -34,6 +34,7 @@ #include "avr_timer.h" #include "avr_spi.h" #include "avr_twi.h" +#include "avr_acomp.h" void mx8_init(struct avr_t * avr); void mx8_reset(struct avr_t * avr); @@ -49,6 +50,7 @@ struct mcu_t { avr_extint_t extint; avr_ioport_t portb,portc,portd; avr_uart_t uart; + avr_acomp_t acomp; avr_adc_t adc; avr_timer_t timer0,timer1,timer2; avr_spi_t spi; @@ -120,6 +122,29 @@ const struct mcu_t SIM_CORENAME = { //PRR/PRUSART0, upe=UPE, reg/bit name index=0, no 'C' in RX/TX vector names AVR_UART_DECLARE(PRR, PRUSART0, UPE, 0, ), + .acomp = { + .mux_inputs = 8, + .mux = { AVR_IO_REGBIT(ADMUX, MUX0), AVR_IO_REGBIT(ADMUX, MUX1), + AVR_IO_REGBIT(ADMUX, MUX2) }, + .pradc = AVR_IO_REGBIT(PRR, PRADC), + .aden = AVR_IO_REGBIT(ADCSRA, ADEN), + .acme = AVR_IO_REGBIT(ADCSRB, ACME), + + .r_acsr = ACSR, + .acis = { AVR_IO_REGBIT(ACSR, ACIS0), AVR_IO_REGBIT(ACSR, ACIS1) }, + .acic = AVR_IO_REGBIT(ACSR, ACIC), + .aco = AVR_IO_REGBIT(ACSR, ACO), + .acbg = AVR_IO_REGBIT(ACSR, ACBG), + .disabled = AVR_IO_REGBIT(ACSR, ACD), + + .timer_name = '1', + + .ac = { + .enable = AVR_IO_REGBIT(ACSR, ACIE), + .raised = AVR_IO_REGBIT(ACSR, ACI), + .vector = ANALOG_COMP_vect, + } + }, .adc = { .r_admux = ADMUX, .mux = { AVR_IO_REGBIT(ADMUX, MUX0), AVR_IO_REGBIT(ADMUX, MUX1), diff --git a/simavr/cores/sim_tiny13.c b/simavr/cores/sim_tiny13.c index 469926c..34b439e 100644 --- a/simavr/cores/sim_tiny13.c +++ b/simavr/cores/sim_tiny13.c @@ -28,6 +28,7 @@ #include "avr_ioport.h" #include "avr_timer.h" #include "avr_adc.h" +#include "avr_acomp.h" #define _AVR_IO_H_ #define __ASSEMBLER__ @@ -44,6 +45,7 @@ static const struct mcu_t { avr_extint_t extint; avr_ioport_t portb; avr_timer_t timer0; + avr_acomp_t acomp; avr_adc_t adc; } mcu = { .core = { @@ -119,6 +121,26 @@ static const struct mcu_t { } } }, + + .acomp = { + .mux_inputs = 4, + .mux = { AVR_IO_REGBIT(ADMUX, MUX0), AVR_IO_REGBIT(ADMUX, MUX1) }, + .aden = AVR_IO_REGBIT(ADCSRA, ADEN), + .acme = AVR_IO_REGBIT(ADCSRB, ACME), + + .r_acsr = ACSR, + .acis = { AVR_IO_REGBIT(ACSR, ACIS0), AVR_IO_REGBIT(ACSR, ACIS1) }, + .aco = AVR_IO_REGBIT(ACSR, ACO), + .acbg = AVR_IO_REGBIT(ACSR, ACBG), + .disabled = AVR_IO_REGBIT(ACSR, ACD), + + .ac = { + .enable = AVR_IO_REGBIT(ACSR, ACIE), + .raised = AVR_IO_REGBIT(ACSR, ACI), + .vector = ANA_COMP_vect, + } + }, + .adc = { .r_admux = ADMUX, .mux = { AVR_IO_REGBIT(ADMUX, MUX0), @@ -185,6 +207,7 @@ static void init(struct avr_t * avr) avr_extint_init(avr, &mcu->extint); avr_ioport_init(avr, &mcu->portb); avr_timer_init(avr, &mcu->timer0); + avr_acomp_init(avr, &mcu->acomp); avr_adc_init(avr, &mcu->adc); } diff --git a/simavr/cores/sim_tiny2313.c b/simavr/cores/sim_tiny2313.c index 6cb8366..537401b 100644 --- a/simavr/cores/sim_tiny2313.c +++ b/simavr/cores/sim_tiny2313.c @@ -26,6 +26,7 @@ #include "avr_ioport.h" #include "avr_uart.h" #include "avr_timer.h" +#include "avr_acomp.h" static void init(struct avr_t * avr); static void reset(struct avr_t * avr); @@ -45,6 +46,7 @@ static const struct mcu_t { avr_ioport_t porta, portb, portd; avr_uart_t uart; avr_timer_t timer0,timer1; + avr_acomp_t acomp; } mcu = { .core = { .mmcu = "attiny2313", @@ -178,7 +180,25 @@ static const struct mcu_t { } } } - } + }, + + .acomp = { + .r_acsr = ACSR, + .acis = { AVR_IO_REGBIT(ACSR, ACIS0), AVR_IO_REGBIT(ACSR, ACIS1) }, + .acic = AVR_IO_REGBIT(ACSR, ACIC), + .aco = AVR_IO_REGBIT(ACSR, ACO), + .acbg = AVR_IO_REGBIT(ACSR, ACBG), + .disabled = AVR_IO_REGBIT(ACSR, ACD), + + .timer_name = '1', + + .ac = { + .enable = AVR_IO_REGBIT(ACSR, ACIE), + .raised = AVR_IO_REGBIT(ACSR, ACI), + .vector = ANA_COMP_vect, + } + }, + }; static avr_t * make() @@ -204,6 +224,7 @@ static void init(struct avr_t * avr) avr_uart_init(avr, &mcu->uart); avr_timer_init(avr, &mcu->timer0); avr_timer_init(avr, &mcu->timer1); + avr_acomp_init(avr, &mcu->acomp); } static void reset(struct avr_t * avr) diff --git a/simavr/cores/sim_tinyx4.c b/simavr/cores/sim_tinyx4.c index 33d44c6..510c4c0 100644 --- a/simavr/cores/sim_tinyx4.c +++ b/simavr/cores/sim_tinyx4.c @@ -33,6 +33,7 @@ void tx4_init(struct avr_t * avr) avr_extint_init(avr, &mcu->extint); avr_ioport_init(avr, &mcu->porta); avr_ioport_init(avr, &mcu->portb); + avr_acomp_init(avr, &mcu->acomp); avr_adc_init(avr, &mcu->adc); avr_timer_init(avr, &mcu->timer0); avr_timer_init(avr, &mcu->timer1); diff --git a/simavr/cores/sim_tinyx4.h b/simavr/cores/sim_tinyx4.h index 3ee8929..f19617a 100644 --- a/simavr/cores/sim_tinyx4.h +++ b/simavr/cores/sim_tinyx4.h @@ -31,6 +31,7 @@ #include "avr_ioport.h" #include "avr_adc.h" #include "avr_timer.h" +#include "avr_acomp.h" void tx4_init(struct avr_t * avr); void tx4_reset(struct avr_t * avr); @@ -44,6 +45,7 @@ struct mcu_t { avr_watchdog_t watchdog; avr_extint_t extint; avr_ioport_t porta, portb; + avr_acomp_t acomp; avr_adc_t adc; avr_timer_t timer0, timer1; }; @@ -88,6 +90,29 @@ const struct mcu_t SIM_CORENAME = { }, .r_pcint = PCMSK1, }, + .acomp = { + .mux_inputs = 8, + .mux = { AVR_IO_REGBIT(ADMUX, MUX0), AVR_IO_REGBIT(ADMUX, MUX1), + AVR_IO_REGBIT(ADMUX, MUX2) }, + .pradc = AVR_IO_REGBIT(PRR, PRADC), + .aden = AVR_IO_REGBIT(ADCSRA, ADEN), + .acme = AVR_IO_REGBIT(ADCSRB, ACME), + + .r_acsr = ACSR, + .acis = { AVR_IO_REGBIT(ACSR, ACIS0), AVR_IO_REGBIT(ACSR, ACIS1) }, + .acic = AVR_IO_REGBIT(ACSR, ACIC), + .aco = AVR_IO_REGBIT(ACSR, ACO), + .acbg = AVR_IO_REGBIT(ACSR, ACBG), + .disabled = AVR_IO_REGBIT(ACSR, ACD), + + .timer_name = '1', + + .ac = { + .enable = AVR_IO_REGBIT(ACSR, ACIE), + .raised = AVR_IO_REGBIT(ACSR, ACI), + .vector = ANA_COMP_vect, + } + }, .adc = { .r_admux = ADMUX, .mux = { AVR_IO_REGBIT(ADMUX, MUX0), AVR_IO_REGBIT(ADMUX, MUX1), diff --git a/simavr/cores/sim_tinyx5.c b/simavr/cores/sim_tinyx5.c index d698caa..28776db 100644 --- a/simavr/cores/sim_tinyx5.c +++ b/simavr/cores/sim_tinyx5.c @@ -32,6 +32,7 @@ void tx5_init(struct avr_t * avr) avr_watchdog_init(avr, &mcu->watchdog); avr_extint_init(avr, &mcu->extint); avr_ioport_init(avr, &mcu->portb); + avr_acomp_init(avr, &mcu->acomp); avr_adc_init(avr, &mcu->adc); avr_timer_init(avr, &mcu->timer0); avr_timer_init(avr, &mcu->timer1); diff --git a/simavr/cores/sim_tinyx5.h b/simavr/cores/sim_tinyx5.h index cc88196..37d9f77 100644 --- a/simavr/cores/sim_tinyx5.h +++ b/simavr/cores/sim_tinyx5.h @@ -31,6 +31,7 @@ #include "avr_ioport.h" #include "avr_adc.h" #include "avr_timer.h" +#include "avr_acomp.h" void tx5_init(struct avr_t * avr); void tx5_reset(struct avr_t * avr); @@ -44,6 +45,7 @@ struct mcu_t { avr_watchdog_t watchdog; avr_extint_t extint; avr_ioport_t portb; + avr_acomp_t acomp; avr_adc_t adc; avr_timer_t timer0, timer1; }; @@ -79,6 +81,26 @@ const struct mcu_t SIM_CORENAME = { }, .r_pcint = PCMSK, }, + .acomp = { + .mux_inputs = 4, + .mux = { AVR_IO_REGBIT(ADMUX, MUX0), AVR_IO_REGBIT(ADMUX, MUX1), + AVR_IO_REGBIT(ADMUX, MUX2), AVR_IO_REGBIT(ADMUX, MUX3) }, + .pradc = AVR_IO_REGBIT(PRR, PRADC), + .aden = AVR_IO_REGBIT(ADCSRA, ADEN), + .acme = AVR_IO_REGBIT(ADCSRB, ACME), + + .r_acsr = ACSR, + .acis = { AVR_IO_REGBIT(ACSR, ACIS0), AVR_IO_REGBIT(ACSR, ACIS1) }, + .aco = AVR_IO_REGBIT(ACSR, ACO), + .acbg = AVR_IO_REGBIT(ACSR, ACBG), + .disabled = AVR_IO_REGBIT(ACSR, ACD), + + .ac = { + .enable = AVR_IO_REGBIT(ACSR, ACIE), + .raised = AVR_IO_REGBIT(ACSR, ACI), + .vector = ANA_COMP_vect, + } + }, .adc = { .r_admux = ADMUX, .mux = { AVR_IO_REGBIT(ADMUX, MUX0), AVR_IO_REGBIT(ADMUX, MUX1), -- 2.39.5