Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <linux/init.h>
- #include <linux/module.h>
- #include <linux/kernel.h>
- #include <linux/gpio.h>
- #include <linux/kthread.h>
- #include <linux/delay.h>
- MODULE_LICENSE("GPL");
- #define LED_ON 1
- #define LED_OFF 0
- #define DELAY_TIME 1000
- static unsigned int gpioLED = 17;
- static bool ledOn = 0;
- static struct task_struct *task;
- static int flash(void *arg){
- while(!kthread_should_stop()){
- set_current_state(TASK_RUNNING);
- ledOn = !ledOn;
- set_current_state(TASK_INTERRUPTIBLE);
- msleep(DELAY_TIME);
- }
- return 0;
- }
- static int __init gpio_blink_init(void){
- if (!gpio_is_valid(gpioLED)){
- printk(KERN_INFO "GPIO_TEST: invalid LED GPIO\n");
- return -ENODEV;
- }
- gpio_request(gpioLED, "stuff");
- gpio_direction_output(gpioLED, LED_OFF);
- gpio_export(gpioLED, false);
- task = kthread_run(flash, NULL, "LED_flash_thread");
- return 0;
- }
- static void __exit gpio_blink_exit(void){
- gpio_set_value(gpioLED, LED_OFF);
- gpio_unexport(gpioLED);
- gpio_free(gpioLED);
- kthread_stop(task);
- }
- module_init(gpio_blink_init);
- module_exit(gpio_blink_exit);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement