The machine state will be used to host the SOC and board level devices like the LED matrix and devices to handle to pushbuttons A and B.
Signed-off-by: Steffen Görtz <cont...@steffen-goertz.de> --- hw/arm/microbit.c | 38 ++++++++++++++++++++++++-------------- include/hw/arm/microbit.h | 29 +++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+), 14 deletions(-) create mode 100644 include/hw/arm/microbit.h diff --git a/hw/arm/microbit.c b/hw/arm/microbit.c index 467cfbda23..8f3c446f52 100644 --- a/hw/arm/microbit.c +++ b/hw/arm/microbit.c @@ -14,22 +14,11 @@ #include "hw/arm/arm.h" #include "exec/address-spaces.h" -#include "hw/arm/nrf51_soc.h" - -typedef struct { - MachineState parent; - - NRF51State nrf51; -} MICROBITMachineState; - -#define TYPE_MICROBIT_MACHINE "microbit" - -#define MICROBIT_MACHINE(obj) \ - OBJECT_CHECK(MICROBITMachineState, obj, TYPE_MICROBIT_MACHINE) +#include "hw/arm/microbit.h" static void microbit_init(MachineState *machine) { - MICROBITMachineState *s = g_new(MICROBITMachineState, 1); + MicrobitMachineState *s = MICROBIT_MACHINE(machine); MemoryRegion *system_memory = get_system_memory(); Object *soc; @@ -45,10 +34,31 @@ static void microbit_init(MachineState *machine) NRF51_SOC(soc)->flash_size); } + static void microbit_machine_init(MachineClass *mc) { mc->desc = "BBC micro:bit"; mc->init = microbit_init; mc->max_cpus = 1; } -DEFINE_MACHINE("microbit", microbit_machine_init); + +static void microbit_machine_init_class_init(ObjectClass *oc, void *data) +{ + MachineClass *mc = MACHINE_CLASS(oc); + microbit_machine_init(mc); +} + +static const TypeInfo microbit_machine_info = { + .name = TYPE_MICROBIT_MACHINE, + .parent = TYPE_MACHINE, + .instance_size = sizeof(MicrobitMachineState), + .class_init = microbit_machine_init_class_init, +}; + +static void microbit_machine_types(void) +{ + type_register_static(µbit_machine_info); +} + +type_init(microbit_machine_types) + diff --git a/include/hw/arm/microbit.h b/include/hw/arm/microbit.h new file mode 100644 index 0000000000..89f0c6bc07 --- /dev/null +++ b/include/hw/arm/microbit.h @@ -0,0 +1,29 @@ +/* + * BBC micro:bit machine + * + * Copyright 2018 Joel Stanley <j...@jms.id.au> + * Copyright 2018 Steffen Görtz <cont...@steffen-goertz.de> + * + * This code is licensed under the GPL version 2 or later. See + * the COPYING file in the top-level directory. + */ +#ifndef MICROBIT_H +#define MICROBIT_H + +#include "qemu/osdep.h" +#include "hw/qdev-core.h" +#include "hw/arm/nrf51_soc.h" +#include "hw/display/led_matrix.h" + +#define TYPE_MICROBIT_MACHINE MACHINE_TYPE_NAME("microbit") +#define MICROBIT_MACHINE(obj) \ + OBJECT_CHECK(MicrobitMachineState, (obj), TYPE_MICROBIT_MACHINE) + +typedef struct MicrobitMachineState { + /*< private >*/ + MachineState parent_obj; + + NRF51State nrf51; +} MicrobitMachineState; + +#endif -- 2.18.0