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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值