qemu:gpio使用

文章目录

定义gpio_in

qdev_init_gpio_in_named

qdev_get_gpio_in_named

定义

c 复制代码
/**
 * qdev_init_gpio_in_named() - create an array of input GPIO lines
 * @dev: device to add array to
 * @handler: a &typedef qemu_irq_handler function to call when GPIO is set
 * @name: Name of the GPIO input (must be unique for this device)
 * @n: Number of GPIO lines in this input set
 *
 * Like qdev_init_gpio_in_named_with_opaque(), but the opaque pointer
 * passed to the handler is @dev (which is the most commonly desired behaviour).
 */
static inline void qdev_init_gpio_in_named(DeviceState *dev,
                                           qemu_irq_handler handler,
                                           const char *name, int n)

使用

c 复制代码
qdev_init_gpio_in_named(DEVICE(obj), FUNCTION_PROCESS_GPIO_PIN_IN(3,11), "gpio_pin_in_3_11", 1);

DEVICE(obj):
FUNCTION_PROCESS_GPIO_PIN_IN(3,11):handler函数
"gpio_pin_in_3_11":引脚名称
1:此引脚线个数

验证

进入到monitor模式 telnet 127.0.0.1 12345

查看设备信息 info qtree

bash 复制代码
  dev: dev01, id ""
    gpio-in "gpio_pin_in_4_25" 1
    gpio-in "gpio_pin_in_4_24" 1
    gpio-in "gpio_pin_in_3_20" 1
    gpio-in "gpio_pin_in_3_11" 1
    mmio 0000000025040000/0000000000010000

定义gpio_out

结构体添加irq

c 复制代码
typedef struct  {
    SysBusDevice parent_obj;
    MemoryRegion iomem;
    qemu_irq irq_out[32];
} ;

初始化irq

c 复制代码
sysbus_init_irq(SYS_BUS_DEVICE(dev), &s->irq_out[i]);

定义

c 复制代码
/**
 * qdev_init_gpio_out_named: create an array of named output GPIO lines
 * @dev: Device to create output GPIOs for
 * @pins: Pointer to qemu_irq or qemu_irq array for the GPIO lines
 * @name: Name to give this array of GPIO lines
 * @n: Number of GPIO lines to create
 *
 * Like qdev_init_gpio_out(), but creates an array of GPIO output lines
 * with a name. Code using the device can then connect these GPIO lines
 * using qdev_connect_gpio_out_named().
 */
void qdev_init_gpio_out_named(DeviceState *dev, qemu_irq *pins,
                              const char *name, int n);

使用

c 复制代码
qdev_init_gpio_out_named(dev, &s->irq_out[11], "gpio_pinout_3_11", 1);

将gpio_in与gpio_out联合起来

定义

c 复制代码
/**
 * qdev_connect_gpio_out_named: Connect one of a device's named output
 *                              GPIO lines
 * @dev: Device whose GPIO to connect
 * @name: Name of the output GPIO array
 * @n: Number of the anonymous output GPIO line (which must be in range)
 * @input_pin: qemu_irq to connect the output line to
 *
 * For anonymous output GPIO lines, use qdev_connect_gpio_out().
 */
void qdev_connect_gpio_out_named(DeviceState *dev, const char *name, int n,
                                 qemu_irq input_pin);

使用

c 复制代码
qdev_connect_gpio_out_named(gpio_out_dev, "gpio_pinout_3_11", 0, 
	qdev_get_gpio_in_named(gpio_in_dev, "gpio_pin_in_3_11", 0));

gpio_out_dev:gpio线输出的设备,对接irq
"gpio_pinout_3_11":gpio线输出线的名字
0:gpio线输出线的index

gpio_in_dev:gpio线输入的设备,对接handler函数
"gpio_pin_in_3_11":gpio线输入线的名字
0:gpio线输入线的index
相关推荐
公西雒12 天前
关于在GitLab的CI/CD中用docker buildx本地化多架构打包dotnet应用的问题
ci/cd·docker·gitlab·qemu·dotnet
ywang_wnlo1 个月前
【Kenel】基于 QEMU 的 Linux 内核编译和安装
linux·qemu·kernel
ywang_wnlo1 个月前
【Kernel】基于 QEMU 的 Linux 内核编译和安装
linux·qemu·kernel
plmm烟酒僧1 个月前
qemu模拟arm64环境-构建6.1内核以及debian12
linux·debian·qemu·虚拟机·香橙派·aarch64
思禾2 个月前
Qemu开发ARM篇-3、qemu运行uboot演示
linux·arm开发·qemu·uboot
张世争2 个月前
rtems 5.3 qemu realview_pbx_a9 环境搭建:生成 rtems arm 工具链
qemu·rtems·realview_pbx_a9
百里杨3 个月前
QEMU中GDB远程串行协议
qemu·gdb·risc-v·riscv·difftest
Eloudy4 个月前
一键编译并启动一个 ARM Linux qemu 虚拟机
arm·qemu·linux kernel
Eloudy4 个月前
基于 systemc-2.3.1的virtual device 接入 qemu-arm
qemu·systemc·tlm