驱动开发day8

任务 : 基于GPIO子系统编写LED驱动,编写应用程序进行测试设置定时器,LED每秒翻转引脚状态,并且每五秒打印一次hello world

驱动代码

cs 复制代码
#include <linux/init.h>
#include <linux/module.h>
#include <linux/of.h>
#include <linux/of_gpio.h>
#include <linux/gpio.h>

struct device_node *dnode;
struct gpio_desc *ionum;

struct timer_list mtimer;
struct timer_list timer_5;

void my_timer_fun(struct timer_list *timer)
{
    gpiod_set_value(ionum,!gpiod_get_value(ionum));
	printk("__led_timer__\n");
    mod_timer(timer,jiffies + HZ);
}

void timer_5_fun(struct timer_list *timer)
{
	printk("hello world\n");
	mod_timer(timer,jiffies + 5 * HZ);
}


static int __init my_init(void)
{
    dnode = of_find_node_by_path("/myled");
    if(dnode == NULL)
    {
        printk("of_find_node_by_path failed\n");
        return -1;
    }
    printk("of_find_node_by_path success\n");

	ionum = gpiod_get_from_of_node(dnode,"led1-gpioe",0,GPIOD_OUT_LOW,NULL);
	if(IS_ERR(ionum))
	{
		printk("gpiod_get_from_of_node failed\n");
		return -PTR_ERR(ionum);
	}
	printk("gpiod_get_from_of_node success\n");

    timer_setup(&mtimer,my_timer_fun,0);
	timer_setup(&timer_5,timer_5_fun,0);

    mtimer.expires = jiffies + HZ;
	timer_5.expires = jiffies + 5 * HZ;

    add_timer(&mtimer);
	add_timer(&timer_5);

    

	//gpiod_set_value(ionum,1);

    return 0;
}

static void __exit my_exit(void)
{
    gpiod_set_value(ionum,0);
    gpiod_put(ionum);
    del_timer(&mtimer);
	del_timer(&timer_5);
}

module_init(my_init);
module_exit(my_exit);
MODULE_LICENSE("GPL");

现象 :

相关推荐
Shang180989357261 天前
T41NQ/T41N高性能低功耗SOC芯片 软硬件资料T41NQ适用于各种AIoT应用,适用于智能安防、智能家居,机器视觉等领域方案
驱动开发·嵌入式硬件·计算机视觉·fpga开发·信息与通信·t41nq
amberman1 天前
解读 PCIe Gen6 RAS
驱动开发·fpga开发·硬件工程
逻极2 天前
AI 规范驱动开发“三剑客”深度对比:Spec-Kit、Kiro 与 OpenSpec 实战指南
人工智能·驱动开发·ai·agent
逻极2 天前
Claude Code 实战:Spec-Kit、Kiro、OpenSpec 规范驱动开发三剑客
ide·人工智能·驱动开发·ai·自动化
范纹杉想快点毕业3 天前
100道关于STM32的问题解答共十万字回答,适用入门嵌入式软件初级工程师,筑牢基础,技术积累,校招面试。
驱动开发·单片机·嵌入式硬件·fpga开发·硬件工程
进击大厂的小白3 天前
35.linux的定时器使用
驱动开发
winner88814 天前
嵌入式Linux驱动开发全流程:工具协作+核心概念拆解(从入门到理解)
linux·运维·驱动开发
Evan_ZGYF丶4 天前
深入解析CFS虚拟运行时间:Linux公平调度的核心引擎
linux·驱动开发·嵌入式·bsp
leijiwen4 天前
规则优先:AI 时代的规范驱动开发(SDD)新范式
人工智能·驱动开发
Ghost Face...4 天前
PCI总线驱动开发全解析
驱动开发