hw/riscv/esp32c3: added the TWAI peripheral to the ESP32-C3 machine state and updated the machine initialization function to realize and connect the TWAI device

This commit is contained in:
Yuan Yu
2025-07-31 11:22:29 +08:00
parent 6e13d72071
commit b5b69aea8a
+10
View File
@@ -49,6 +49,7 @@
#include "hw/misc/esp32c3_jtag.h"
#include "hw/dma/esp32c3_gdma.h"
#include "hw/display/esp_rgb.h"
#include "hw/net/can/esp32c3_twai.h"
#define ESP32C3_IO_WARNING 0
@@ -88,6 +89,7 @@ struct Esp32C3MachineState {
ESP32C3RtcCntlState rtccntl;
ESP32C3UsbJtagState jtag;
ESPRgbState rgb;
Esp32C3TWAIState twai;
};
/* Fake register used by ESP-IDF application to determine whether the code is running on real hardware or on QEMU */
@@ -421,6 +423,7 @@ static void esp32c3_machine_init(MachineState *machine)
object_initialize_child(OBJECT(machine), "rtccntl", &ms->rtccntl, TYPE_ESP32C3_RTC_CNTL);
object_initialize_child(OBJECT(machine), "jtag", &ms->jtag, TYPE_ESP32C3_JTAG);
object_initialize_child(OBJECT(machine), "rgb", &ms->rgb, TYPE_ESP_RGB);
object_initialize_child(OBJECT(machine), "twai", &ms->twai, TYPE_ESP32C3_TWAI);
/* Realize all the I/O peripherals we depend on */
@@ -646,6 +649,13 @@ static void esp32c3_machine_init(MachineState *machine)
memory_region_add_subregion_overlap(sys_mem, DR_REG_FRAMEBUF_BASE, mr, 0);
memory_region_add_subregion_overlap(sys_mem, esp32c3_memmap[ESP32C3_MEMREGION_FRAMEBUF].base, &ms->rgb.vram, 0);
}
/* TWAI peripheral realization */
sysbus_realize(SYS_BUS_DEVICE(&ms->twai), &error_fatal);
MemoryRegion *twai_mr = sysbus_mmio_get_region(SYS_BUS_DEVICE(&ms->twai), 0);
memory_region_add_subregion_overlap(sys_mem, DR_REG_TWAI_BASE, twai_mr, 0);
sysbus_connect_irq(SYS_BUS_DEVICE(&ms->twai), 0,
qdev_get_gpio_in(DEVICE(&ms->intmatrix), ETS_TWAI_INTR_SOURCE));
}