Skip to content

Commit

Permalink
Merge pull request #292 from nicehorse06/master
Browse files Browse the repository at this point in the history
Fix bottom-half processing by transitioning to workqueue
  • Loading branch information
jserv authored Feb 17, 2025
2 parents a035231 + 3682d9e commit eccaa3b
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions examples/bottomhalf.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include <linux/printk.h>
#include <linux/init.h>
#include <linux/version.h>
#include <linux/workqueue.h>

#if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 10, 0)
#define NO_GPIO_REQUEST_ARRAY
Expand Down Expand Up @@ -42,16 +43,17 @@ static struct gpio buttons[] = {
{ 18, GPIOF_IN, "LED 1 OFF BUTTON" },
};

/* Tasklet containing some non-trivial amount of processing */
static void bottomhalf_tasklet_fn(unsigned long data)
/* Workqueue function containing some non-trivial amount of processing */
static void bottomhalf_work_fn(struct work_struct *work)
{
pr_info("Bottom half tasklet starts\n");
pr_info("Bottom half workqueue starts\n");
/* do something which takes a while */
mdelay(500);
pr_info("Bottom half tasklet ends\n");
msleep(500);

pr_info("Bottom half workqueue ends\n");
}

static DECLARE_TASKLET_OLD(buttontask, bottomhalf_tasklet_fn);
static DECLARE_WORK(bottomhalf_work, bottomhalf_work_fn);

/* interrupt function triggered when a button is pressed */
static irqreturn_t button_isr(int irq, void *data)
Expand All @@ -63,8 +65,7 @@ static irqreturn_t button_isr(int irq, void *data)
gpio_set_value(leds[0].gpio, 0);

/* Do the rest at leisure via the scheduler */
tasklet_schedule(&buttontask);

schedule_work(&bottomhalf_work);
return IRQ_HANDLED;
}

Expand Down

0 comments on commit eccaa3b

Please sign in to comment.