Menu Close

of Functions For Finding Parent Nodes and Child Nodes Demo

This article provides the code for testing the of functions used for finding parent and child nodes.

For related subjects, please refer to the SOC Table of Contents.

 

The functions we will be testing in chronological order in this section are:

  • of_find_node_by_name
  • of_find_node_by_type

The code to be inserted into the corresponding section is as follows:

        // 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 Textbook and Training Project

Related Articles

Leave a Reply

Your email address will not be published.

Leave the field below empty!