驱动开发day8

 获取键值:通过设备树键名获取键值

驱动代码:

#include 
#include 
#include 

struct device_node *node;
struct property *pr;
int len,i,ret;
unsigned int val;
unsigned int array[2];
unsigned char string[8];
const char *str;
static int __init mycdev_init(void)
{
    node=of_find_node_by_path("/mynode@0x12345678");
    if(node==NULL)
    {
        printk("查找失败\n");
        return -EIO;
    }
    //通过键名获取32位无符号整型数
    ret=of_property_read_u32_index(node,"uint",0,&val);
    if(ret)
    {
        printk("获取32位失败\n");
        return EFAULT;
    }
    printk("value=%#x\n",val);
    //通过键名获得32位无符号数数组
    ret=of_property_read_variable_u32_array(node,"uint",array,2,2);
    if(ret<0)
    {
        printk("获取32位数组失败\n");
        return EFAULT;
    }
    printk("value=%#x, %#x\n",array[0],array[1]);
    //通过键名获得字符串
    ret=of_property_read_string(node,"astring",&str);
    if(ret)
    {
        printk("获取字符串失败\n");
        return EFAULT;
    }
    printk("value=%s\n",str);
    //通过键名获得8位无符号数
    ret=of_property_read_variable_u8_array(node,"binarry",string,2,8);
    if(ret<0)
    {
        printk("获得8位数组失败\n");
        return -EFAULT;
    }
    for(i=0;i

 驱动开发day8_第1张图片

 

你可能感兴趣的:(驱动开发)