驱动获取设备树节点信息

编程入门 行业动态 更新时间:2024-10-20 05:29:57

驱动获取设备树<a href=https://www.elefans.com/category/jswz/34/1771452.html style=节点信息"/>

驱动获取设备树节点信息

mycdev.c

#include <linux/init.h>
#include <linux/module.h>
#include <linux/of.h>struct device_node *dnode; //解析得到的设备树节点对象指针
struct property *pr;
unsigned int lenth;
static int __init mycdev_init(void)
{//解析设备树节点信息dnode = of_find_node_by_name(NULL,"mynode");if(dnode == NULL){printk("解析设备树节点失败\n");return -ENXIO;}//解析uint属性pr = of_find_property(dnode,"unit",&lenth);if(pr == NULL){printk("属性解析失败\n");return -ENXIO;}printk("name=%s,value %x,%x\n",pr->name,__be32_to_cpup((u32 *)pr->value),__be32_to_cpup((u32 *)pr->value+1));pr = of_find_property(dnode,"binarry",&lenth);if(pr == NULL){printk("属性解析失败\n");return -ENXIO;}int i;for(i=0;i<lenth;i++){printk("name=%s,value=%x\n",pr->name,*((u8 *)pr->value+i));}return 0;
}
static void __exit mycdev_exit(void)
{}
module_init(mycdev_init);
module_exit(mycdev_exit);
MODULE_LICENSE("GPL");

更多推荐

驱动获取设备树节点信息

本文发布于:2023-12-03 07:31:06,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1652689.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:节点   设备   信息

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!