Menu Close

测试用于查找节点的 of 函数

此文章将提供可以用于测试查找节点用的 of 函数成功运行的代码。

相关参考文章:SOC 教学教案

 

将测试的函数如下:

  • of_find_node_by_name
  • of_find_node_by_type
  • of_find_compatible_node
  • of_find_matching_node_and_match
  • of_find_node_by_path

模版相应部分将填入的代码如下:

        // of_find_node_by_name

        struct device_node *test_ofnbn;

        test_ofnbn = of_find_node_by_name(NULL, "test_node2");

        if(NULL == &test_ofnbn){
               printk(KERN_ERR "Node was not found via of_find_node_by_name \r\n");
        }

        if(NULL != &test_ofnbn){
               printk(KERN_ERR "Node was successfully found via of_find_node_by_name \r\n");
               printk(KERN_ERR "Node name is:  %s \r\n", test_ofnbn->name);
        }

        printk(KERN_ERR "\r\n");



        // of_find_node_by_type

        struct device_node *test_ofnbt;

        test_ofnbt = of_find_node_by_type(NULL, "test_device_type1");

        if(NULL == &test_ofnbt){
               printk(KERN_ERR "Node was not found via of_find_node_by_type \r\n");
        }

        if(NULL != &test_ofnbt){
               printk(KERN_ERR "Node was successfully found via of_find_node_by_type \r\n");
               printk(KERN_ERR "Node name is:  %s \r\n", test_ofnbt->name);
        }

        printk(KERN_ERR "\r\n");



        // of_find_compatible_node

        struct device_node *test_ofcndn;

        test_ofcndn = of_find_compatible_node(NULL, "test_device_type1", "fii,fii-dt-driver");

        if(NULL == &test_ofcndn){
               printk(KERN_ERR "Node was not found via of_find_compatible_node \r\n");
        }

        if(NULL != &test_ofcndn){
               printk(KERN_ERR "Node was successfully found via of_find_compatible_node \r\n");
               printk(KERN_ERR "Node name is:  %s \r\n", test_ofcndn->name);
        }

        printk(KERN_ERR "\r\n");



        // of_find_matching_node_and_match

        const struct of_device_id *test_np;

        struct device_node *test_dn;

        test_dn = of_find_matching_node_and_match(NULL, of_match_fii_dt_driver, &test_np);

        if(NULL == &test_dn){
               printk(KERN_ERR "Node was not found via of_find_matching_node_and_match \r\n");
        }

        if(NULL != &test_dn){
               printk(KERN_ERR "Node was successfully found via of_find_matching_node_and_match \r\n");
               printk(KERN_ERR "Node name is:  %s \r\n", test_dn->name);
        }

        printk(KERN_ERR "\r\n");



        // of_find_node_by_path

        struct device_node *test_ofnbp;

        test_ofnbp = of_find_node_by_path("/test_node1");

        if(NULL == &test_ofnbp){
               printk(KERN_ERR "Node was not found via of_find_node_by_path \r\n");
        }

        if(NULL != &test_ofnbp){
               printk(KERN_ERR "Node was successfully found via of_find_node_by_path \r\n");
               printk(KERN_ERR "Node name is:  %s \r\n", test_ofnbp->name);
        }
Posted in 教材与教案

发表评论

相关链接