介绍
你在使用hexo写文章的时候是不是还在
hexo new
hexo g
hexo d
这样写文章不仅效率慢而且管理起来也不方便
hexon是一个带有git的hexo图形化界面
这是它的github链接
Pinctrl 子系统
GPIO 子系统
层次结构
背景
在早期的嵌入设备和计算机系统中
思想
技术细节
例子
// LED抽象类
class LED {
public:
virtual void turnOn() = 0;
virtual void turnOff() = 0;
};
// GPIO LED 实现
class GPIO_LED : public LED {
private:
int pin;
public:
GPIO_LED(int gpioPin) : pin(gpioPin) {}
void turnOn() override {
// GPIO设置为高电平
}
void turnOff() override {
// GPIO设置为低电平
}
};
随着硬件设备的复杂性增加
通过这种模型
思想
技术细节
struct platform_device
和 struct platform_driver
是关键数据结构// 定义平台设备的结构
struct platform_device {
// 设备的名称<span class="bd-box"><h-char class="bd bd-beg"><h-inner>,</h-inner></h-char></span>用于匹配驱动
const char *name;
int id;
bool id_auto;
struct device dev;
u32 num_resources;
// 指向资源数组的指针<span class="bd-box"><h-char class="bd bd-beg"><h-inner>,</h-inner></h-char></span>资源包括内存区域<span class="bd-box"><h-char class="bd bd-beg"><h-inner>、</h-inner></h-char></span>IRQ等
struct resource *resource;
/* 其他字段省略 */
};
// 定义平台驱动的结构
struct platform_driver {
// 探测函数<span class="bd-box"><h-char class="bd bd-beg"><h-inner>,</h-inner></h-char></span>当设备被发现时调用<span class="bd-box"><h-char class="bd bd-beg"><h-inner>,</h-inner></h-char></span>负责初始化设备
int (*probe)(struct platform_device *);
// 移除设备时调用<span class="bd-box"><h-char class="bd bd-beg"><h-inner>,</h-inner></h-char></span>用于清理资源
int (*remove)(struct platform_device *);
void (*shutdown)(struct platform_device *);
int (*suspend)(struct platform_device *, pm_message_t state);
int (*resume)(struct platform_device *);
// 内嵌的通用设备驱动结构<span class="bd-box"><h-char class="bd bd-beg"><h-inner>,</h-inner></h-char></span>包含了驱动信息如驱动名称<span class="bd-box"><h-char class="bd bd-beg"><h-inner>、</h-inner></h-char></span>所有者等
struct device_driver driver;
const struct platform_device_id *id_table;
/* 其他字段省略 */
};
例子
static struct platform_device led_device = {
.name = "led",
.id = -1,
.dev = {
.platform_data = &gpio_pin_number, // 假设这个GPIO引脚号作为平台数据
},
};
static struct platform_driver led_driver = {
.probe = led_probe,
.remove = led_remove,
.driver = {
.name = "led",
.owner = THIS_MODULE,
},
};
static int led_probe(struct platform_device *pdev)
{
// 获取设备的GPIO引脚信息并初始化LED
return 0;
}
static int led_remove(struct platform_device *pdev)
{
// 清理LED相关的资源
return 0;
}
技术细节
led_probe
函数在匹配成功后初始化LEDled_remove
函数在设备卸载时清理资源平台设备与驱动的匹配过程大致如下
设备注册
struct platform_device
platform_bus
驱动注册
struct platform_driver
设备树解析
匹配尝试
compatible
属性与驱动的of_match_table
是否匹配成功匹配
probe
方法probe
方法将接收到匹配的struct device
struct platform_device
资源分配
probe
方法中设备绑定
probe
方法成功失败处理
probe
方法失败背景
随着SoC
思想
技术细节
例子
/ {
leds {
compatible = "gpio-led";
gpios = <&gpio 17 GPIO_ACTIVE_HIGH>; // 假设LED连接到GPIO17
label = "led";
};
};
static int led_probe(struct platform_device *pdev)
{
struct device_node *node = pdev->dev.of_node;
int gpio;
if (of_property_read_u32(node, "gpios", &gpio))
return -ENODEV;
// 使用GPIO进行LED操作
return 0;
}
设备树描述了硬件配置
进化意义
这个过程展示了操作系统在面对越来越复杂的硬件环境时