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
相关推荐
tianyuanwo1 天前
QEMU 虚拟化入门:从“软件模拟一台电脑”到 KVM 时代的基础设施组件
运维·qemu·虚拟化
刘大望3 天前
不用买开发板:用 QEMU 走通嵌入式 Linux 全流程(二)读懂启动日志
linux内核·qemu·arm64·嵌入式linux
刘大望4 天前
不用买开发板:用 QEMU 走通嵌入式 Linux 全流程(八)用 U-Boot 引导自己构建的内核
qemu·u-boot·嵌入式linux·启动流程
刘大望5 天前
不用买开发板:用 QEMU 走通嵌入式 Linux 全流程(三)存储与网络实地验证
linux·qemu·嵌入式linux·alpine
tyustli13 天前
TF-M Secure 启动文件
qemu·tf-m·startup·mps2-an521·启动文件
tyustli14 天前
TF-M BL2 和 TFM_S 的配置和编译
qemu·tf-m·bl2·mps2-an521·tfm_s
tyustli15 天前
TF-M BL2 RAM 布局
qemu·tf-m·bl2·mps2-an521
tyustli18 天前
TF-M 使用 make 构建
qemu·make·mcuboot·tf-m·mps2-an521
张一西2 个月前
QEMU 模拟器学习(二)之 USB 设备之BOT & UAS协议
qemu·uas·bot
张一西2 个月前
QEMU 模拟器学习(二)之 USB 设备模拟与协议学习
qemu·usb·uas·bot