Menu Close

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

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

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

 

将测试的函数如下:

  • of_find_node_by_name
  • of_find_node_by_type

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

        // of_get_parent

        struct device_node *test_ogp;

        test_ogp = of_get_parent(of_find_node_by_name(NULL, "test_node2"));

        if(NULL == &test_ogp){
               printk(KERN_ERR "Parent node of test_node2 was not found via of_get_parent \r\n");
        }

        if(NULL != &test_ogp){
               printk(KERN_ERR "Parent node of test_node2 was successfully found via of_get_parent \r\n");

               printk(KERN_ERR "Node name is:  %s \r\n", test_ogp->name);
        }

        printk(KERN_ERR "\r\n");



        // of_get_next_child

        struct device_node *test_ognc;

        test_ognc = of_get_next_child(of_find_node_by_name(NULL, "test_node1"), NULL);

        if(NULL == &test_ognc){
               printk(KERN_ERR "Next child node of test_node1 was not found via of_get_next_child \r\n");
        }

        if(NULL != &test_ognc){
               printk(KERN_ERR "Next child node of test_node1 was successfully found via of_get_next_child \r\n");

               printk(KERN_ERR "Node name is:  %s \r\n", test_ognc->name);
        }

Posted in 教材与教案

发表评论

相关链接