On 1/24/20 1:51 AM, Philippe Mathieu-Daudé wrote: > Arduino boards are build with AVR chipsets. > Add some of the popular boards: > > - Arduino Duemilanove > - Arduino Uno > - Arduino Mega > > For more information: > https://www.arduino.cc/en/Main/Products > https://store.arduino.cc/arduino-genuino/most-popular > > Reviewed-by: Igor Mammedov <imamm...@redhat.com> > Signed-off-by: Philippe Mathieu-Daudé <f4...@amsat.org> > Message-Id: <20200120220107.17825-15-f4...@amsat.org> > Signed-off-by: Richard Henderson <richard.hender...@linaro.org> > --- > rc2: > - Use avr_load_firmware (Aleksandar) > - No default machine on AVR (Richard) > - Add entry in MAINTAINERS (Michael is still the maintainer of hw/avr/) > --- > hw/avr/arduino.c | 151 +++++++++++++++++++++++++++++++++++++++++++ > MAINTAINERS | 6 ++ > hw/avr/Kconfig | 4 ++ > hw/avr/Makefile.objs | 1 + > 4 files changed, 162 insertions(+) > create mode 100644 hw/avr/arduino.c > > diff --git a/hw/avr/arduino.c b/hw/avr/arduino.c > new file mode 100644 > index 0000000000..2fb2e96ffe > --- /dev/null > +++ b/hw/avr/arduino.c > @@ -0,0 +1,151 @@ > +/* > + * QEMU Arduino boards > + * > + * Copyright (c) 2019 Philippe Mathieu-Daudé > + * > + * This work is licensed under the terms of the GNU GPLv2 or later. > + * See the COPYING file in the top-level directory. > + * SPDX-License-Identifier: GPL-2.0-or-later > + */ > + > +/* TODO: Implement the use of EXTRAM */ > + > +#include "qemu/osdep.h" > +#include "qapi/error.h" > +#include "hw/boards.h" > +#include "atmel_atmega.h" > +#include "boot.h" > + > +typedef struct ArduinoMachineState { > + /*< private >*/ > + MachineState parent_obj; > + /*< public >*/ > + AtmegaMcuState mcu; > +} ArduinoMachineState; > + > +typedef struct ArduinoMachineClass { > + /*< private >*/ > + MachineClass parent_class; > + /*< public >*/ > + const char *mcu_type; > + uint64_t xtal_hz; > +} ArduinoMachineClass; > + > +#define TYPE_ARDUINO_MACHINE \ > + MACHINE_TYPE_NAME("arduino") > +#define ARDUINO_MACHINE(obj) \ > + OBJECT_CHECK(ArduinoMachineState, (obj), TYPE_ARDUINO_MACHINE) > +#define ARDUINO_MACHINE_CLASS(klass) \ > + OBJECT_CLASS_CHECK(ArduinoMachineClass, (klass), > TYPE_ARDUINO_MACHINE) > +#define ARDUINO_MACHINE_GET_CLASS(obj) \ > + OBJECT_GET_CLASS(ArduinoMachineClass, (obj), TYPE_ARDUINO_MACHINE) > + > +static void arduino_machine_init(MachineState *machine) > +{ > + ArduinoMachineClass *amc = ARDUINO_MACHINE_GET_CLASS(machine); > + ArduinoMachineState *ams = ARDUINO_MACHINE(machine); > + > + sysbus_init_child_obj(OBJECT(machine), "mcu", &ams->mcu, > sizeof(ams->mcu), > + amc->mcu_type); > + object_property_set_uint(OBJECT(&ams->mcu), amc->xtal_hz, > + "xtal-frequency-hz", &error_abort); > + object_property_set_bool(OBJECT(&ams->mcu), true, "realized", > + &error_abort); > + > + if (machine->firmware) { > + if (!avr_load_firmware(&ams->mcu.cpu, machine, > + &ams->mcu.flash, machine->firmware)) { > + exit(1); > + } > + } > +} > + > +static void arduino_machine_class_init(ObjectClass *oc, void *data) > +{ > + MachineClass *mc = MACHINE_CLASS(oc); > + > + mc->init = arduino_machine_init; > + mc->default_cpus = 1; > + mc->min_cpus = mc->default_cpus; > + mc->max_cpus = mc->default_cpus; > + mc->no_floppy = 1; > + mc->no_cdrom = 1; > + mc->no_parallel = 1; > +} > + > +static void arduino_duemilanove_class_init(ObjectClass *oc, void *data) > +{ > + MachineClass *mc = MACHINE_CLASS(oc); > + ArduinoMachineClass *amc = ARDUINO_MACHINE_CLASS(oc); > + > + /* https://www.arduino.cc/en/Main/ArduinoBoardDuemilanove */ > + mc->desc = "Arduino Duemilanove (ATmega168)", > + mc->alias = "2009"; > + amc->mcu_type = TYPE_ATMEGA168_MCU; > + amc->xtal_hz = 16 * 1000 * 1000; > +};
Hi! According to the page this board could be used with Atmega328 too. Maybe you can define both? The rest of this patch looks good to me, so: Reviewed-by: Joaquin de Andres <m...@xcancerberox.com.ar> > + > +static void arduino_uno_class_init(ObjectClass *oc, void *data) > +{ > + MachineClass *mc = MACHINE_CLASS(oc); > + ArduinoMachineClass *amc = ARDUINO_MACHINE_CLASS(oc); > + > + /* https://store.arduino.cc/arduino-uno-rev3 */ > + mc->desc = "Arduino UNO (ATmega328P)"; > + mc->alias = "uno"; > + amc->mcu_type = TYPE_ATMEGA328_MCU; > + amc->xtal_hz = 16 * 1000 * 1000; > +}; > + > +static void arduino_mega_class_init(ObjectClass *oc, void *data) > +{ > + MachineClass *mc = MACHINE_CLASS(oc); > + ArduinoMachineClass *amc = ARDUINO_MACHINE_CLASS(oc); > + > + /* https://www.arduino.cc/en/Main/ArduinoBoardMega */ > + mc->desc = "Arduino Mega (ATmega1280)"; > + mc->alias = "mega"; > + amc->mcu_type = TYPE_ATMEGA1280_MCU; > + amc->xtal_hz = 16 * 1000 * 1000; > +}; > + > +static void arduino_mega2560_class_init(ObjectClass *oc, void *data) > +{ > + MachineClass *mc = MACHINE_CLASS(oc); > + ArduinoMachineClass *amc = ARDUINO_MACHINE_CLASS(oc); > + > + /* https://store.arduino.cc/arduino-mega-2560-rev3 */ > + mc->desc = "Arduino Mega 2560 (ATmega2560)"; > + mc->alias = "mega2560"; > + amc->mcu_type = TYPE_ATMEGA2560_MCU; > + amc->xtal_hz = 16 * 1000 * 1000; /* CSTCE16M0V53-R0 */ > +}; > + > +static const TypeInfo arduino_machine_types[] = { > + { > + .name = MACHINE_TYPE_NAME("arduino-duemilanove"), > + .parent = TYPE_ARDUINO_MACHINE, > + .class_init = arduino_duemilanove_class_init, > + }, { > + .name = MACHINE_TYPE_NAME("arduino-uno"), > + .parent = TYPE_ARDUINO_MACHINE, > + .class_init = arduino_uno_class_init, > + }, { > + .name = MACHINE_TYPE_NAME("arduino-mega"), > + .parent = TYPE_ARDUINO_MACHINE, > + .class_init = arduino_mega_class_init, > + }, { > + .name = MACHINE_TYPE_NAME("arduino-mega-2560-v3"), > + .parent = TYPE_ARDUINO_MACHINE, > + .class_init = arduino_mega2560_class_init, > + }, { > + .name = TYPE_ARDUINO_MACHINE, > + .parent = TYPE_MACHINE, > + .instance_size = sizeof(ArduinoMachineState), > + .class_size = sizeof(ArduinoMachineClass), > + .class_init = arduino_machine_class_init, > + .abstract = true, > + } > +}; > + > +DEFINE_TYPES(arduino_machine_types) > diff --git a/MAINTAINERS b/MAINTAINERS > index 066515ac8e..07c8912489 100644 > --- a/MAINTAINERS > +++ b/MAINTAINERS > @@ -904,6 +904,12 @@ F: hw/misc/atmel_power.c > F: include/hw/misc/atmel_power.h > F: tests/acceptance/machine_avr6.py > > +Arduino > +M: Philippe Mathieu-Daudé <f4...@amsat.org> > +S: Maintained > +F: hw/avr/arduino.c > +F: hw/avr/atmel_atmega.* > + > CRIS Machines > ------------- > Axis Dev88 > diff --git a/hw/avr/Kconfig b/hw/avr/Kconfig > index da3b10afec..59d9649d27 100644 > --- a/hw/avr/Kconfig > +++ b/hw/avr/Kconfig > @@ -3,3 +3,7 @@ config ATMEL_ATMEGA_MCU > select ATMEL_TIMER16 > select ATMEL_USART > select ATMEL_POWER > + > +config ARDUINO > + select ATMEL_ATMEGA_MCU > + select UNIMP > diff --git a/hw/avr/Makefile.objs b/hw/avr/Makefile.objs > index 1f73fd5469..c8a131923c 100644 > --- a/hw/avr/Makefile.objs > +++ b/hw/avr/Makefile.objs > @@ -1,2 +1,3 @@ > obj-y += boot.o > obj-$(CONFIG_ATMEL_ATMEGA_MCU) += atmel_atmega.o > +obj-$(CONFIG_ARDUINO) += arduino.o >