qemu:gpio使用

ops/2024/10/19 21:40:28/

文章目录

  • 定义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.ppmy.cn/ops/101226.html

相关文章

运维有必要学编程吗?应该学哪种编程语言?

在以往的观念中,运维的工作内容是不涉及编程、开发的,因此以前也没用学编程的需求。然而随着互联网的发展和变化,现如今,运维也需要开始接触开发,接触编程了。 当然有很多运维朋友,本身是不认可的。可&…

SSRF 302跳转攻击redis写入ssh公钥实现远程登录

目录 SSRF漏洞 SSRF攻击Redis 302跳转 漏洞复现: index.html: index.php: 攻击步骤: 1.生成ssh公钥数据: 2.用SSH公钥数据伪造Redis数据: 3.在自己的服务器上写302跳转: 4.最后尝试在.ssh目录下登录&#…

EasyExcel冲突问题,java.lang.NosuchFieldError: Factory

我在项目中使用EasyExcel,本以为是一个简单的导出功能,应该很快。但是问题出现了,导出的时候报错 com.alibaba.excel.exception.ExcelGenerateException Create breakpoint java.lang.NosuchFieldError: Factory at com.alibaba.excel.write.ExcelBuilderImpl.<init>(…

数组算法排序实现

重写 Array.filter() javascript复制代码Array.prototype.myFilter function(callback, thisArg) {const result [];for (let i 0; i < this.length; i) {if (callback.call(thisArg, this[i], i, this)) {result.push(this[i]);}}return result; }; ​ // 测试 const a…

JAVA面试题--ES

ElasticSearch Lucene创建索引原理 Lucene是基于倒排索引原理来实现的 首先&#xff0c;将原文档进行分词处理&#xff0c;形成一个个单独的单词&#xff0c; 然后取出标点符号以及停词&#xff0c;形成词元&#xff0c; 再将词元做一些语言相关的处理&#xff0c;比如变成…

37-RPC HTTP区别是什么

‌RPC和HTTP的主要区别在于它们的通信方式、数据传输格式、应用场景、状态管理以及性能上。‌ ‌通信方式‌&#xff1a; ‌RPC‌&#xff08;远程过程调用&#xff09;是一种进程间通信方式&#xff0c;允许一个程序调用远程服务器上的函数或方法&#xff0c;就像调用本地函数…

【YOLO系列】目标检测简介

目录 一、目标检测是什么&#xff1f;二、关键概念和步骤三、类别四、应用场景五、技术挑战 一、目标检测是什么&#xff1f; 目标检测是计算机视觉领域中的一项重要任务&#xff0c;主要是在图像或视频中确定特定目标的位置和类别。目标检测算法不仅要识别图像中的对象属于哪…

[数据集][目标检测]电力场景输电线防震锤检测数据集VOC+YOLO格式2721张2类别

数据集格式&#xff1a;Pascal VOC格式YOLO格式(不包含分割路径的txt文件&#xff0c;仅仅包含jpg图片以及对应的VOC格式xml文件和yolo格式txt文件) 图片数量(jpg文件个数)&#xff1a;2721 标注数量(xml文件个数)&#xff1a;2721 标注数量(txt文件个数)&#xff1a;2721 标注…