当前位置: 首页 > news >正文

qemu:gpio使用

文章目录

  • 定义gpio_in
    • 定义
    • 使用
    • 验证
  • 定义gpio_out
    • 结构体添加irq
    • 初始化irq
    • 定义
    • 使用
  • 将gpio_in与gpio_out联合起来
    • 定义
    • 使用

定义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" 1gpio-in "gpio_pin_in_4_24" 1gpio-in "gpio_pin_in_3_20" 1gpio-in "gpio_pin_in_3_11" 1mmio 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线输出线的indexgpio_in_dev:gpio线输入的设备,对接handler函数
"gpio_pin_in_3_11":gpio线输入线的名字
0:gpio线输入线的index

http://www.mrgr.cn/news/13255.html

相关文章:

  • 在浏览器输入URL回车之后发生了什么?
  • [Meachines] [Medium] Bastard Drupal 7 Module Services-RCE+MS15-051权限提升
  • 记录|Form1中嵌套Form2时的频闪问题解决[不同于常见的三部曲]
  • 线性二次调节器(LQR)和模型预测控制(MPC)算法对比介绍
  • TCP并发服务端的实现
  • 深度学习学习经验——长短期记忆网络(LSTM)
  • 学术好物!推荐8款写论文神器app查重率低网站
  • 网络通信---三次握手
  • 浅谈【数据结构】链表之单链表
  • 设计模式 9 装饰器模式
  • 【python】Gpt-embedding文本建模
  • 如何使用ssm实现学生就业管理系统
  • 【UE 编译】UE C++工程的编译流程、与C++编译的区别
  • C语言04--数组超详解
  • 如何使用ssm实现开放式教学评价管理系统+vue
  • 【操作系统】实验:指示灯开关控制
  • std::futrue异步操作结果的三种搭配使用
  • 【大模型系列篇】预训练模型:BERT GPT
  • zookeeper集群安装
  • 什么是YAML?学这一篇就够了