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

现象 :

相关推荐
charlie11451419118 小时前
嵌入式Linux驱动开发——新 API 字符设备驱动完整教程 - 从设备结构体到应用测试
linux·运维·驱动开发
长安第一美人1 天前
RT-Thread 工业屏驱动开发实战:UART 串口屏协议解析 + 数据实时刷新 + 设备驱动框架完整实现
驱动开发·嵌入式硬件·rt-thread·工业控制·uart通信·串口屏驱动
不怕犯错,就怕不做2 天前
RK3562的CPU如何降频及关闭硬件编解码
linux·驱动开发·嵌入式硬件
可可西里_X_back2 天前
Linux学习(二)- 驱动开发步骤
linux·驱动开发·学习
云天AI实战派2 天前
AI 智能体/API 调用故障排查指南:实时语音、Codex 权限与 Spec 驱动开发全流程修复手册
人工智能·驱动开发·chatgpt·api·codex
小猪写代码2 天前
Linux 驱动开发
驱动开发
小猪写代码2 天前
字符设备驱动开发基础实验
驱动开发
l1t2 天前
DeepSeek总结的使用 eBPF 和硬件断点跟踪 PostgreSQL
数据库·驱动开发·postgresql
高翔·权衡之境3 天前
缓存一致性——多核系统的默契之约
驱动开发·嵌入式硬件·安全·缓存·系统安全·信息与通信
charlie1145141913 天前
嵌入式Linux驱动开发——驱动错误处理模式 - 当资源分配失败时该怎么办
linux·运维·驱动开发