[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH rc5 25/32] hw/avr: Add limited support for some Arduino boards
From: |
Aleksandar Markovic |
Subject: |
[PATCH rc5 25/32] hw/avr: Add limited support for some Arduino boards |
Date: |
Fri, 7 Feb 2020 02:57:53 +0100 |
From: Philippe Mathieu-Daudé <address@hidden>
Arduino boards are build with AVR chipsets. Add some of these
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
[AM: Remove word 'Atmel' from filenames and all elements of code]
Suggested-by: Aleksandar Markovic <address@hidden>
Signed-off-by: Philippe Mathieu-Daudé <address@hidden>
Signed-off-by: Richard Henderson <address@hidden>
Signed-off-by: Aleksandar Markovic <address@hidden>
Reviewed-by: Igor Mammedov <address@hidden>
Reviewed-by: Joaquin de Andres <address@hidden>
---
hw/avr/arduino.c | 151 +++++++++++++++++++++++++++++++++++++++++++++++++++
MAINTAINERS | 6 ++
hw/Kconfig | 1 +
hw/avr/Kconfig | 4 ++
hw/avr/Makefile.objs | 1 +
5 files changed, 163 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 0000000..00d67c9
--- /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 "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;
+};
+
+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 5eedee9..fae2bb6 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -925,6 +925,12 @@ F: hw/timer/avr_timer16.c
F: include/hw/misc/avr_power.h
F: hw/misc/avr_power.c
+Arduino
+M: Philippe Mathieu-Daudé <address@hidden>
+R: Sarah Harris <address@hidden>
+S: Maintained
+F: hw/avr/arduino.c
+
CRIS Machines
-------------
Axis Dev88
diff --git a/hw/Kconfig b/hw/Kconfig
index ecf491b..f80dff3 100644
--- a/hw/Kconfig
+++ b/hw/Kconfig
@@ -43,6 +43,7 @@ source watchdog/Kconfig
# arch Kconfig
source arm/Kconfig
source alpha/Kconfig
+source avr/Kconfig
source cris/Kconfig
source hppa/Kconfig
source i386/Kconfig
diff --git a/hw/avr/Kconfig b/hw/avr/Kconfig
index 9e6527e..d31298c 100644
--- a/hw/avr/Kconfig
+++ b/hw/avr/Kconfig
@@ -3,3 +3,7 @@ config AVR_ATMEGA_MCU
select AVR_TIMER16
select AVR_USART
select AVR_POWER
+
+config ARDUINO
+ select AVR_ATMEGA_MCU
+ select UNIMP
diff --git a/hw/avr/Makefile.objs b/hw/avr/Makefile.objs
index af0fdde..4dca064 100644
--- a/hw/avr/Makefile.objs
+++ b/hw/avr/Makefile.objs
@@ -1,2 +1,3 @@
obj-y += boot.o
obj-$(CONFIG_AVR_ATMEGA_MCU) += atmega.o
+obj-$(CONFIG_ARDUINO) += arduino.o
--
2.7.4
- [PATCH] !fixup "target/avr: Add defintions of AVR core types", (continued)
[PATCH rc5 18/32] target/avr: Add support for disassembling via option '-d in_asm', Aleksandar Markovic, 2020/02/06
[PATCH rc5 12/32] target/avr: Add instruction translation - Branch Instructions, Aleksandar Markovic, 2020/02/06
[PATCH rc5 17/32] target/avr: Initialize TCG register variables, Aleksandar Markovic, 2020/02/06
[PATCH rc5 30/32] .travis.yml: Run the AVR acceptance tests, Aleksandar Markovic, 2020/02/06
[PATCH rc5 27/32] tests/machine-none: Add AVR support, Aleksandar Markovic, 2020/02/06
[PATCH rc5 23/32] hw/avr: Add support for loading ELF/raw binaries, Aleksandar Markovic, 2020/02/06
[PATCH rc5 25/32] hw/avr: Add limited support for some Arduino boards,
Aleksandar Markovic <=
[PATCH rc5 22/32] target/avr: Register AVR support with the rest of QEMU, Aleksandar Markovic, 2020/02/06
[PATCH rc5 28/32] tests/boot-serial: Test some Arduino boards (AVR based), Aleksandar Markovic, 2020/02/06
[PATCH rc5 32/32] target/avr: Add section into QEMU documentation, Aleksandar Markovic, 2020/02/06
[PATCH rc5 29/32] tests/acceptance: Test the Arduino MEGA2560 board, Aleksandar Markovic, 2020/02/06
[PATCH rc5 10/32] target/avr: Add instruction translation - Register definitions, Aleksandar Markovic, 2020/02/06
[PATCH rc5 31/32] target/avr: Simplify sections in MAINTAINERS file, Aleksandar Markovic, 2020/02/06
[PATCH rc5 09/32] target/avr: Add instruction helpers, Aleksandar Markovic, 2020/02/06
[PATCH rc5 21/32] hw/misc: avr: Add limited support for power reduction device, Aleksandar Markovic, 2020/02/06
[PATCH rc5 11/32] target/avr: Add instruction translation - Arithmetic and Logic Instructions, Aleksandar Markovic, 2020/02/06
[PATCH rc5 26/32] target/avr: Update build system, Aleksandar Markovic, 2020/02/06