本文主要是介绍09_gpiochipLinux内核模块,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
01_basicLinux内核模块-CSDN博客文章浏览阅读318次,点赞3次,收藏3次。环境ID=ubuntuMakefilemodules:clean:basic.creturn 0;运行效果。https://blog.csdn.net/m0_37132481/article/details/136157384my_gpiochip.c
#include <linux/kernel.h>
#include <linux/module.h>#include <linux/gpio/driver.h>#define TAG "HELLO# "static int my_gpiochip_gpio_request(struct gpio_chip *chip, unsigned int offset)
{printk(TAG "%s called\n", __func__);return 0;
}
static int my_gpiochip_gpio_direction_in(struct gpio_chip *chip, unsigned int offset)
{printk(TAG "%s called\n", __func__);return 0;
}
static int my_gpiochip_gpio_get(struct gpio_chip *chip, unsigned int offset)
{printk(TAG "%s called\n", __func__);return 0;
}
static int my_gpiochip_gpio_direction_out(struct gpio_chip *chip, unsigned offset, int value)
{printk(TAG "%s called\n", __func__);return 0;
}
static void my_gpiochip_gpio_set(struct gpio_chip *chip, unsigned int offset, int value)
{printk(TAG "%s called\n", __func__);
}static struct gpio_chip my_gpiochip_gpio_chip = {.label = "my_gpiochip",.owner = THIS_MODULE,.request = my_gpiochip_gpio_request,.direction_input = my_gpiochip_gpio_direction_in,.get = my_gpiochip_gpio_get,.direction_output = my_gpiochip_gpio_direction_out,.set = my_gpiochip_gpio_set,.can_sleep = 1,.ngpio = 100,.base = -1,
};static int my_gpiochip_init(void)
{printk(TAG "%s called\n", __func__);gpiochip_add(&my_gpiochip_gpio_chip);return 0;
}
static void my_gpiochip_exit(void)
{gpiochip_remove(&my_gpiochip_gpio_chip);printk(TAG "%s called\n", __func__);
}module_init(my_gpiochip_init);
module_exit(my_gpiochip_exit);
MODULE_LICENSE("GPL");
效果
gpio chip注册后,base由内核确定为512
这篇关于09_gpiochipLinux内核模块的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!