• 华清远见上海中心22071班


    #include

    #include

    #include

    /*mynode@0x12345678{

        compatible = "hqyj,mynode";

        astring="hello 21091";

        uint  =<0xaabbccdd 0x11223344>;

        binarry=[00 0c 29 7b f9 be];

        mixed ="hello",[11 22],<0x12345678>;

     };*/

    //定义指针指向获取的设备树节点信息空间

     struct device_node *node;

     struct property *pr;

     int len,i,ret;

     u32 value;

     u32 values[2];

     const char *str;

    static int __init mycdev_init(void)

    {

        //通过路径获取设备树节点信息

        node=of_find_node_by_path("/mynode@0x12345678");

        if(node==NULL)

        {

            printk("通过路径解析设备树节点失败\n");

            return -EFAULT;

        }

        printk("成功解析到设备树节点\n");

        printk("name=%s,value=%s\n",node->properties->name,(char *)node->properties->value);

        printk("name=%s,value=%s\n",node->properties->next->name,(char *)node->properties->next->value);

        printk("name=%s,value=%#x,%#x\n",node->properties->next->next->name,__be32_to_cpup((int *)node->properties->next->next->value),__be32_to_cpup((int *)node->properties->next->next->value+1));

       

        //解析字符串

        pr=of_find_property(node,"astring",&len);

        if(pr==NULL)

        {

            printk("属性解析失败\n");

            return -EFAULT;

        }

        for(i=0;i

            printk("name=%s value=%#x\n",pr->name,*((char *)pr->value+i));

        }

        //通过键名获取32位无符号整型的值

        ret=of_property_read_u32_index(node,"uint",1,&value);

        if(ret!=0){

            printk("获取U32值失败\n");

            return -EFAULT;

        }

        printk("value=%#x\n",value);

        //获取一个U32位数组

        ret=of_property_read_variable_u32_array(node,"uint",values,2,2);

         if(ret<0){

            printk("获取U32组失败\n");

            return -EFAULT;

        }

        printk("value1=%#x %#x\n",values[0],values[1]);

        //读取字符串类型的值

        ret=of_property_read_string(node,"astring",&str);

         if(ret!=0){

            printk("读取字符串类型的值失败\n");

            return -EFAULT;

        }

        printk("str:%s\n",str);

        //获取一个U8位数组

        ret=of_property_read_variable_u32_array(node,"uint",values,2,2);

         if(ret<0){

            printk("获取U8组失败\n");

            return -EFAULT;

        }

        printk("value1=%#o %#o\n",values[0],values[1]);

       

        return 0;

    }

    static void __exit mycdev_exit(void)

    {


     

    }

    module_init(mycdev_init);

    module_exit(mycdev_exit);

    MODULE_LICENSE("GPL");

     

     

  • 相关阅读:
    当.Net撞上BI可视化,这3种“套路”你必须知道
    @vue/cli3--使用图形化界面创建项目--方法/实例
    【计算机组成原理】原码 反码 补码 移码
    HTML+CSS+JS网页表白代码大全(浪漫的html表白源代码)
    不就是Java吗 之 接口
    Android 12 intent-filter添加android:exported后任然报错解决方法
    VQA的应用(调研)
    深度学习修炼(三)卷积操作 | 边界填充、跨步、多输入输出通道、汇聚池化
    Go语言(下载、安装、环境配置、GoLand编译器安装、编写HelloWorld)
    与诈蟹的初次邂逅,你中招了没
  • 原文地址:https://blog.csdn.net/qq_60135456/article/details/128006809