Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <linux/interrupt.h>
- #include <linux/err.h>
- #include <linux/irq.h>
- #include <linux/clk.h>
- #include <linux/list.h>
- #include <linux/kthread.h>
- #include <linux/init_task.h>
- #include <linux/sched.h>
- #include <linux/rtmutex.h>
- #include <linux/hrtimer.h>
- #include <linux/delay.h>
- #include <linux/gpio.h>
- MODULE_LICENSE( "GPL" );
- static struct task_struct *thread_10ms;
- static int bus_rt_timer_thread(void *arg) {
- bool led_state = false;
- if (gpio_request(62, "LED"))
- {
- printk( "+ error requesting LED GPIO" );
- return -1;
- }
- gpio_direction_output(62, 0);
- ktime_t timeout = ktime_get();
- while(!kthread_should_stop()) {
- led_state = !led_state;
- gpio_set_value(62, led_state);
- timeout = ktime_add_us(timeout, 250000);
- __set_current_state(TASK_UNINTERRUPTIBLE);
- schedule_hrtimeout_range(&timeout, 100, HRTIMER_MODE_ABS);
- }
- gpio_direction_output(62, 0);
- gpio_free(62);
- return 0;
- }
- int __init bus_timer_interrupt_init(void) {
- struct sched_param param = { .sched_priority = MAX_RT_PRIO - 1 };
- thread_10ms = kthread_create(bus_rt_timer_thread, NULL, "bus_10ms");
- if (IS_ERR(thread_10ms)) {
- printk(KERN_ERR "RT Failed to create RT thread\n");
- return -ESRCH;
- }
- sched_setscheduler(thread_10ms, SCHED_FIFO, ¶m);
- wake_up_process(thread_10ms);
- return 0;
- }
- void __exit bus_timer_interrupt_exit(void) {
- kthread_stop(thread_10ms);
- printk(KERN_INFO "RT Thread removed.\n");
- }
- module_init( bus_timer_interrupt_init );
- module_exit( bus_timer_interrupt_exit );
Advertisement
Add Comment
Please, Sign In to add comment