当前位置:   article > 正文

qemu:gpio使用

qemu:gpio使用

定义gpio_in

qdev_init_gpio_in_named
qdev_get_gpio_in_named

定义

/**
 * 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)

使用

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

  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

typedef struct  {
    SysBusDevice parent_obj;
    MemoryRegion iomem;
    qemu_irq irq_out[32];
} ;

初始化irq

sysbus_init_irq(SYS_BUS_DEVICE(dev), &s->irq_out[i]);

定义

/**
 * 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);

使用

qdev_init_gpio_out_named(dev, &s->irq_out[11], "gpio_pinout_3_11", 1);

将gpio_in与gpio_out联合起来

定义

/**
 * 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);

使用

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

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/Guff_9hys/article/detail/1021939
推荐阅读
相关标签
  

闽ICP备14008679号