驱动开发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");

现象 :

相关推荐
sukalot15 小时前
windows显示驱动开发-多监视器管理器(三)
windows·驱动开发
王廷胡_白嫖帝2 天前
1. Linux 驱动开发前景
linux·运维·驱动开发
默 语2 天前
AI驱动软件测试全流程自动化:从理论到实践的深度探索
运维·人工智能·驱动开发·ai·自动化·ai技术·测试全流程
casdfxx3 天前
捡到h3开发板,做了个视频小车。
驱动开发
人生苦短,菜的抠脚3 天前
Linux 内核IIO sensor驱动
linux·驱动开发
玉树临风江流儿3 天前
Linux驱动开发实战指南-上
linux·驱动开发
cellurw4 天前
Day64 设备树与GPIO子系统驱动开发实践
驱动开发
玉树临风江流儿4 天前
Linux驱动开发总结速记
linux·运维·驱动开发
A-花开堪折4 天前
Qemu 嵌入式Linux驱动开发
linux·运维·驱动开发
算力魔方AIPC4 天前
Spec-Kit+Copilot打造AI规格驱动开发
人工智能·驱动开发·copilot