栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > C/C++/C#

C语言高级

C/C++/C# 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

C语言高级

1.struct devices{

u32 num_resources;

struct resources *resources;

const struct platform_device_id *id_entry

}

为什么为什么不直接用一个resources数组,而是用一个数组大小值和一个指针?

因为数组定义时要指定数组大小。用数据就直接写死了,如果直接写死,数组大小不够用,数组太大造成内核内存浪费。这样做,可以用kzmollc来申请内存资源,申请后填充,填充后把地址放到*resources.

结构体中用指针干嘛的?

const struct platform_device_id *id_entry这个指针会指向一个数组,比如这里就会指向一个设备id表数组。

2.struct s3c24xx_led_platdata *pdata = dev_get_platdata(&dev->dev);

集大成者,数据的传输

3.kernel/kernel/drivers/base/platform.c

static int platform_match(struct device *dev, struct device_driver *drv)

{
    struct platform_device *pdev = to_platform_device(dev);
    struct platform_driver *pdrv = to_platform_driver(drv);

为什么这边传参是struct device *dev, struct device_driver *drv,

而不是struct platform_device *pdev,struct platform_driver *pdrv

因为struct bus_type {

int (*match)(struct device *dev, struct device_driver *drv);

因为不知道bus_type不知道要去定义什么类型的bus(有可能platform bus,有可能是usb bus,有可能是pci)

4.结构体,结构体指针数组,二重指针

static struct platform_device mini2440_led1 = {
    .name        = "s3c24xx_led",
    .id        = 1,
    .dev        = {
        .platform_data    = &mini2440_led1_pdata,
    },
};

static struct platform_device *mini2440_devices[] __initdata = {
    &s3c_device_ohci,
    &s3c_device_wdt,
    &s3c_device_i2c0,
    &s3c_device_rtc,
    &s3c_device_usbgadget,
    &mini2440_device_eth,
    &mini2440_led1,
    &mini2440_led2,
    &mini2440_led3,
    &mini2440_led4,

}

用一个指针结构体数组将mini2440_led1,mini2440_led2,mini2440_led3,mini2440_led4组织起来。

然后下面肯定要用一个for循环,对指针数组遍历。

platform_add_devices(mini2440_devices, ARRAY_SIZE(mini2440_devices));

int platform_add_devices(struct platform_device **devs, int num)
{
    int i, ret = 0;

    for (i = 0; i < num; i++) {
        ret = platform_device_register(devs[i]);
        if (ret) {
            while (--i >= 0)
                platform_device_unregister(devs[i]);
            break;
        }
    }

    return ret;
}

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/869386.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号