zoukankan      html  css  js  c++  java
  • linux of函数实例

    / {
        wanghb {
            gpio = <129>;
            gpios = <129 130 131>;
            args = "wanghbargs";
                compatible = "wanghbcompatible";
            child1@0x1000012{
                args = "child1"; 
                gpios = <120>;
            };
            child2@0x1000012{
                args = "child2"; 
                gpios = <121>;
            };
        };
        
        
        zmm@0x120000{
            args = "zmm";
            gpios = <120>;
        };
    };

    主要来练习 of_find_node_by_path, of_find_node_by_name,of_property_read_u32_array ,of_property_read_string ,of_property_count_elems_of_size , of_get_next_child ,of_get_parent 函数

    #include <linux/of.h>
    #include <linux/device.h>
    #include <linux/platform_device.h>
    #include <linux/err.h>
    #include <linux/errno.h>
    #include <linux/list.h>
    #include <linux/init.h>
    #include <linux/module.h>
    #include <linux/kernel.h>
    
    
    struct device_node * utils_find_node_by_path(char * node_path)
    {
        struct device_node * node = NULL;
        node  = of_find_node_by_path(node_path);
        if(node != NULL)
        {
            printk(KERN_INFO "[success find device_node ,%s]
    ",node_path);
        }
        else
        {
            printk(KERN_INFO "[could not find device_node ,%s]
    ",node_path);
        }
        return node;
    }
    struct device_node * utils_find_node_by_name(char * node_name)
    {
        struct device_node * node = NULL;
        node  = of_find_node_by_name(NULL,node_name);
        if(node != NULL)
        {
            printk(KERN_INFO "[success find device_node ,%s]
    ",node_name);
        }
        else
        {
            printk(KERN_INFO "[could not find device_node ,%s]
    ",node_name);
        }
        return node;
    }
    static int __init test_module_init(void)
    {
        
        struct device_node *  wanghb = NULL;
        struct device_node *  zmm = NULL;
        struct device_node *  parent = NULL;
        struct device_node *  child = NULL;
        struct property *     wanghb_args = NULL;
        u32 value_array[10] = {0};
        u32 size = 0;
        const char * string ;
        const char * string1 ;
        const char * string2 ;
        god_bless();
        wanghb  = utils_find_node_by_path("/wanghb");
        wanghb  = utils_find_node_by_name("wanghb");
        zmm     = utils_find_node_by_path("/zmm@0x120000");
        zmm     = utils_find_node_by_name("zmm@0x120000");
        zmm     = utils_find_node_by_name("zmm");
        printk(KERN_INFO "====================================================================================");
        wanghb_args = of_find_property(wanghb,"args",NULL);
        printk(KERN_INFO "[wanghb_args value : %s, name :%s]
    ",(char*)wanghb_args->value,(char*)wanghb_args->name);
        wanghb_args = of_find_property(wanghb,"compatible",NULL);
        printk(KERN_INFO "[compatible value : %s, name :%s]
    ",(char*)wanghb_args->value,(char*)wanghb_args->name);
        
        of_property_read_string(wanghb,"args",&string);
        printk(KERN_INFO "[args : %s, ]
    ",string);
        
        of_property_read_string(wanghb,"compatible",&string);
        printk(KERN_INFO "[compatible : %s, ]
    ",string);
        
        of_property_read_u32_array(wanghb,"gpio",value_array,1);
        printk(KERN_INFO "[gpio : %d]
    ",value_array[0]);
        
        of_property_read_u32_array(wanghb,"gpios",value_array,3);
        printk(KERN_INFO "[gpio [0]: %d ,gpio [1]: %d ,gpio [2]: %d ]
    ",value_array[0],value_array[1],value_array[2]);
        
        size = of_property_count_elems_of_size(wanghb, "gpios", sizeof(u32));
        printk(KERN_INFO "[size : %d]
    ",size);
        
        child = of_get_next_child(wanghb,NULL);
        if(child)
        {
            of_property_read_string(child,"args",&string1);
            printk(KERN_INFO "[args : %s]
    ",string1);
            
            child = of_get_next_child(child,child);
            of_property_read_string(child,"args",&string2);
            printk(KERN_INFO "[args : %s]
    ",string2);
        }
        else
        {
            printk(KERN_ERR "[could not find childnode ]
    ");
        }
        
        parent = of_get_parent(child);
        of_property_read_string(parent,"args",&string);
        printk(KERN_INFO "[parentargs : %s]
    ",string);
        
        printk(KERN_INFO "====================================================================================");
        return 0;
    }
    
    static void test_module_exit(void)
    {
    }
    module_init(test_module_init);
    module_exit(test_module_exit);
    
    MODULE_AUTHOR("wanghb");
    MODULE_LICENSE("GPL");

    结果如下:

  • 相关阅读:
    java的构造方法 this 重载
    容器,组件,面板
    首先定义一个5X8的二维数组,然后使用随机数填充满。借助Arrays的方法对二维数组进行排序。
    首先创建一个长度是5的数组,并填充随机数。首先用选择法正排序,然后再对其使用冒泡法倒排序
    创建一个长度是5的数组,并填充随机数。使用for循环或者while循环,对这个数组实现反转效果
    寻找某两个数相除,其结果 离黄金分割点 0.618最近,分母和分子不能同时为偶数 * 分母和分子 取值范围在[1-20]
    密码的自动生成器:密码由大写字母/小写字母/数字组成,生成12位随机密码
    vue倒计时:天时分秒
    tbody设置超出固定的高度出现滚动条,没超出不显示。
    获取某个日期的当前周一的时间
  • 原文地址:https://www.cnblogs.com/coversky/p/14987846.html
Copyright © 2011-2022 走看看