4 * Copyright (c) 2019-2020 Philippe Mathieu-Daudé
6 * This work is licensed under the terms of the GNU GPLv2 or later.
7 * See the COPYING file in the top-level directory.
8 * SPDX-License-Identifier: GPL-2.0-or-later
11 /* TODO: Implement the use of EXTRAM */
13 #include "qemu/osdep.h"
14 #include "qapi/error.h"
15 #include "hw/boards.h"
18 #include "qom/object.h"
20 struct ArduinoMachineState
{
22 MachineState parent_obj
;
26 typedef struct ArduinoMachineState ArduinoMachineState
;
28 struct ArduinoMachineClass
{
30 MachineClass parent_class
;
35 typedef struct ArduinoMachineClass ArduinoMachineClass
;
37 #define TYPE_ARDUINO_MACHINE \
38 MACHINE_TYPE_NAME("arduino")
39 DECLARE_OBJ_CHECKERS(ArduinoMachineState
, ArduinoMachineClass
,
40 ARDUINO_MACHINE
, TYPE_ARDUINO_MACHINE
)
42 static void arduino_machine_init(MachineState
*machine
)
44 ArduinoMachineClass
*amc
= ARDUINO_MACHINE_GET_CLASS(machine
);
45 ArduinoMachineState
*ams
= ARDUINO_MACHINE(machine
);
47 object_initialize_child(OBJECT(machine
), "mcu", &ams
->mcu
, amc
->mcu_type
);
48 object_property_set_uint(OBJECT(&ams
->mcu
), "xtal-frequency-hz",
49 amc
->xtal_hz
, &error_abort
);
50 sysbus_realize(SYS_BUS_DEVICE(&ams
->mcu
), &error_abort
);
52 if (machine
->firmware
) {
53 if (!avr_load_firmware(&ams
->mcu
.cpu
, machine
,
54 &ams
->mcu
.flash
, machine
->firmware
)) {
60 static void arduino_machine_class_init(ObjectClass
*oc
, void *data
)
62 MachineClass
*mc
= MACHINE_CLASS(oc
);
64 mc
->init
= arduino_machine_init
;
66 mc
->min_cpus
= mc
->default_cpus
;
67 mc
->max_cpus
= mc
->default_cpus
;
73 static void arduino_duemilanove_class_init(ObjectClass
*oc
, void *data
)
75 MachineClass
*mc
= MACHINE_CLASS(oc
);
76 ArduinoMachineClass
*amc
= ARDUINO_MACHINE_CLASS(oc
);
78 /* https://www.arduino.cc/en/Main/ArduinoBoardDuemilanove */
79 mc
->desc
= "Arduino Duemilanove (ATmega168)",
81 amc
->mcu_type
= TYPE_ATMEGA168_MCU
;
82 amc
->xtal_hz
= 16 * 1000 * 1000;
85 static void arduino_uno_class_init(ObjectClass
*oc
, void *data
)
87 MachineClass
*mc
= MACHINE_CLASS(oc
);
88 ArduinoMachineClass
*amc
= ARDUINO_MACHINE_CLASS(oc
);
90 /* https://store.arduino.cc/arduino-uno-rev3 */
91 mc
->desc
= "Arduino UNO (ATmega328P)";
93 amc
->mcu_type
= TYPE_ATMEGA328_MCU
;
94 amc
->xtal_hz
= 16 * 1000 * 1000;
97 static void arduino_mega_class_init(ObjectClass
*oc
, void *data
)
99 MachineClass
*mc
= MACHINE_CLASS(oc
);
100 ArduinoMachineClass
*amc
= ARDUINO_MACHINE_CLASS(oc
);
102 /* https://www.arduino.cc/en/Main/ArduinoBoardMega */
103 mc
->desc
= "Arduino Mega (ATmega1280)";
105 amc
->mcu_type
= TYPE_ATMEGA1280_MCU
;
106 amc
->xtal_hz
= 16 * 1000 * 1000;
109 static void arduino_mega2560_class_init(ObjectClass
*oc
, void *data
)
111 MachineClass
*mc
= MACHINE_CLASS(oc
);
112 ArduinoMachineClass
*amc
= ARDUINO_MACHINE_CLASS(oc
);
114 /* https://store.arduino.cc/arduino-mega-2560-rev3 */
115 mc
->desc
= "Arduino Mega 2560 (ATmega2560)";
116 mc
->alias
= "mega2560";
117 amc
->mcu_type
= TYPE_ATMEGA2560_MCU
;
118 amc
->xtal_hz
= 16 * 1000 * 1000; /* CSTCE16M0V53-R0 */
121 static const TypeInfo arduino_machine_types
[] = {
123 .name
= MACHINE_TYPE_NAME("arduino-duemilanove"),
124 .parent
= TYPE_ARDUINO_MACHINE
,
125 .class_init
= arduino_duemilanove_class_init
,
127 .name
= MACHINE_TYPE_NAME("arduino-uno"),
128 .parent
= TYPE_ARDUINO_MACHINE
,
129 .class_init
= arduino_uno_class_init
,
131 .name
= MACHINE_TYPE_NAME("arduino-mega"),
132 .parent
= TYPE_ARDUINO_MACHINE
,
133 .class_init
= arduino_mega_class_init
,
135 .name
= MACHINE_TYPE_NAME("arduino-mega-2560-v3"),
136 .parent
= TYPE_ARDUINO_MACHINE
,
137 .class_init
= arduino_mega2560_class_init
,
139 .name
= TYPE_ARDUINO_MACHINE
,
140 .parent
= TYPE_MACHINE
,
141 .instance_size
= sizeof(ArduinoMachineState
),
142 .class_size
= sizeof(ArduinoMachineClass
),
143 .class_init
= arduino_machine_class_init
,
148 DEFINE_TYPES(arduino_machine_types
)