]> git.feebdaed.xyz Git - linuxyz.git/commitdiff
ranamed to gpio irqsk
authorseantywork <seantywork@gmail.com>
Wed, 28 May 2025 13:12:26 +0000 (14:12 +0100)
committerseantywork <seantywork@gmail.com>
Wed, 28 May 2025 13:12:26 +0000 (14:12 +0100)
kgpio-irqsock/2506-04.xyz.md [new file with mode: 0644]
kgpio-irqsock/Makefile [new file with mode: 0644]
kgpio-irqsock/ins.conf [new file with mode: 0644]
kgpio-irqsock/ins.sh [new file with mode: 0755]
kgpio-irqsock/kgpio_irqsk.c [new file with mode: 0644]
ksock-gpio/2506-04.xyz.md [deleted file]
ksock-gpio/Makefile [deleted file]
ksock-gpio/ins.conf [deleted file]
ksock-gpio/ins.sh [deleted file]
ksock-gpio/ksock_gpio.c [deleted file]

diff --git a/kgpio-irqsock/2506-04.xyz.md b/kgpio-irqsock/2506-04.xyz.md
new file mode 100644 (file)
index 0000000..4287ca8
--- /dev/null
@@ -0,0 +1 @@
+#
\ No newline at end of file
diff --git a/kgpio-irqsock/Makefile b/kgpio-irqsock/Makefile
new file mode 100644 (file)
index 0000000..b13b4c0
--- /dev/null
@@ -0,0 +1,6 @@
+obj-m := kgpio_irqsk.o
+
+all:
+       make -C /lib/modules/$(shell uname -r)/build M=$(shell pwd) modules
+clean:
+       make -C /lib/modules/$(shell uname -r)/build M=$(shell pwd) clean
\ No newline at end of file
diff --git a/kgpio-irqsock/ins.conf b/kgpio-irqsock/ins.conf
new file mode 100644 (file)
index 0000000..e4b27ce
--- /dev/null
@@ -0,0 +1,2 @@
+CTLOUT=GPIO17
+CTLIN=GPIO27
\ No newline at end of file
diff --git a/kgpio-irqsock/ins.sh b/kgpio-irqsock/ins.sh
new file mode 100755 (executable)
index 0000000..904c5d0
--- /dev/null
@@ -0,0 +1,31 @@
+#!/bin/bash 
+
+source ./ins.conf
+
+CTLOUT_LINE=$(cat /sys/kernel/debug/gpio | grep $CTLOUT) 
+CTLIN_LINE=$(cat /sys/kernel/debug/gpio | grep $CTLIN)
+
+
+if [[ "$CTLOUT_LINE" == "" ]]
+then 
+    echo "couldn't find $CTLOUT"
+    exit 1
+fi
+
+if [[ "$CTLIN_LINE" == "" ]]
+then 
+    echo "couldn't find $CTLIN"
+    exit 1
+fi
+
+CTLOUT_LINE=$(echo $CTLOUT_LINE | cut -d "-" -f 2)
+CTLOUT_LINE=$(echo $CTLOUT_LINE | cut -d " " -f 1)
+
+CTLIN_LINE=$(echo $CTLIN_LINE | cut -d "-" -f 2)
+CTLIN_LINE=$(echo $CTLIN_LINE | cut -d " " -f 1)
+
+echo "CTL OUT: $CTLOUT = $CTLOUT_LINE"
+echo "CTL IN : $CTLIN = $CTLIN_LINE"
+
+insmod kgpio_irqsk.ko gpio_ctl_o=$CTLOUT_LINE gpio_ctl_i=$CTLIN_LINE
+
diff --git a/kgpio-irqsock/kgpio_irqsk.c b/kgpio-irqsock/kgpio_irqsk.c
new file mode 100644 (file)
index 0000000..8b25fa9
--- /dev/null
@@ -0,0 +1,120 @@
+#include <linux/init.h>
+#include <linux/module.h>
+#include <linux/kernel.h>
+#include <linux/ip.h>
+#include <linux/tcp.h>
+#include <linux/udp.h>
+#include <linux/string.h>
+#include <linux/gpio.h>
+#include <linux/interrupt.h>
+#include <linux/workqueue.h>
+#include <linux/sched.h>
+#include <linux/time.h>
+#include <linux/delay.h>
+
+static DECLARE_WAIT_QUEUE_HEAD(this_wq);
+
+static int condition = 0;
+
+static struct work_struct job;
+
+static int gpio_ctl_o;
+static int gpio_ctl_i;
+
+module_param(gpio_ctl_o, int, 0664);
+module_param(gpio_ctl_i, int, 0664);
+
+static unsigned int gpio_ctl_i_irq;
+
+static void job_handler(struct work_struct* work){
+
+
+    printk(KERN_INFO "waitqueue handler: %s\n", __FUNCTION__);
+
+    msleep(5000);
+
+       gpio_set_value(gpio_ctl_o, IRQF_TRIGGER_RISING);
+
+    printk(KERN_INFO "up after 5000ms\n");
+
+    condition = 1;
+
+    wake_up_interruptible(&this_wq);
+
+
+}
+
+static irqreturn_t gpio_irq_handler(int irq, void *dev_id) {
+       printk("gpio irqsk: interrupt was triggered and ISR was called\n");
+       return IRQ_HANDLED;
+}
+
+static int __init ksock_gpio_init(void) {
+
+       if(gpio_request(gpio_ctl_o, "gpio-ctl-o")) {
+               printk("gpio irqsk: can't allocate gpio_ctl_o: %d\n", gpio_ctl_o);
+               return -1;
+       }
+
+
+       if(gpio_request(gpio_ctl_i, "gpio-ctl-i")) {
+               printk("gpio irqsk: can't allocate gpio_ctl_i: %d\n", gpio_ctl_i);
+               gpio_free(gpio_ctl_o);
+               return -1;
+       }
+
+       if(gpio_direction_output(gpio_ctl_o, IRQF_TRIGGER_NONE)) {
+               printk("gpio irqsk: can't set gpio_ctl_o to output\n");
+               gpio_free(gpio_ctl_o);
+               gpio_free(gpio_ctl_i);
+               return -1;
+       }
+
+       if(gpio_direction_input(gpio_ctl_i)) {
+               printk("gpio irqsk: can't set gpio_ctl_i to input\n");
+               gpio_free(gpio_ctl_o);
+               gpio_free(gpio_ctl_i);
+               return -1;
+       }
+
+       gpio_ctl_i_irq = gpio_to_irq(gpio_ctl_i);
+
+       if(request_irq(gpio_ctl_i_irq, gpio_irq_handler, IRQF_TRIGGER_RISING, "gpio_ctl_i_irq", NULL) != 0) {
+               printk("gpio irqsk: can't request interrupt\n");
+               gpio_free(gpio_ctl_o);
+               gpio_free(gpio_ctl_i);
+               return -1;
+       }
+
+
+       printk("gpio irqsk: gpio_ctl_i to IRQ %d\n", gpio_ctl_i_irq);
+
+       printk("gpio irqsk: module is initialized into the kernel\n");
+
+    INIT_WORK(&job, job_handler);
+
+    schedule_work(&job);
+
+    printk(KERN_INFO "putting to sleep: %s\n", __FUNCTION__);
+
+    wait_event_interruptible(this_wq, condition != 0);
+
+    printk(KERN_INFO "woken up\n");
+
+
+       return 0;
+
+}
+
+static void __exit ksock_gpio_exit(void) {
+
+       gpio_free(gpio_ctl_o);
+       gpio_free(gpio_ctl_i);
+       free_irq(gpio_ctl_i_irq, NULL);
+       printk("gpio irqsk: module is removed from the kernel\n");
+}
+
+module_init(ksock_gpio_init);
+module_exit(ksock_gpio_exit);
+
+MODULE_LICENSE("GPL");
\ No newline at end of file
diff --git a/ksock-gpio/2506-04.xyz.md b/ksock-gpio/2506-04.xyz.md
deleted file mode 100644 (file)
index 4287ca8..0000000
+++ /dev/null
@@ -1 +0,0 @@
-#
\ No newline at end of file
diff --git a/ksock-gpio/Makefile b/ksock-gpio/Makefile
deleted file mode 100644 (file)
index 4b0458b..0000000
+++ /dev/null
@@ -1,6 +0,0 @@
-obj-m := ksock_gpio.o
-
-all:
-       make -C /lib/modules/$(shell uname -r)/build M=$(shell pwd) modules
-clean:
-       make -C /lib/modules/$(shell uname -r)/build M=$(shell pwd) clean
\ No newline at end of file
diff --git a/ksock-gpio/ins.conf b/ksock-gpio/ins.conf
deleted file mode 100644 (file)
index e4b27ce..0000000
+++ /dev/null
@@ -1,2 +0,0 @@
-CTLOUT=GPIO17
-CTLIN=GPIO27
\ No newline at end of file
diff --git a/ksock-gpio/ins.sh b/ksock-gpio/ins.sh
deleted file mode 100755 (executable)
index f291406..0000000
+++ /dev/null
@@ -1,31 +0,0 @@
-#!/bin/bash 
-
-source ./ins.conf
-
-CTLOUT_LINE=$(cat /sys/kernel/debug/gpio | grep $CTLOUT) 
-CTLIN_LINE=$(cat /sys/kernel/debug/gpio | grep $CTLIN)
-
-
-if [[ "$CTLOUT_LINE" == "" ]]
-then 
-    echo "couldn't find $CTLOUT"
-    exit 1
-fi
-
-if [[ "$CTLIN_LINE" == "" ]]
-then 
-    echo "couldn't find $CTLIN"
-    exit 1
-fi
-
-CTLOUT_LINE=$(echo $CTLOUT_LINE | cut -d "-" -f 2)
-CTLOUT_LINE=$(echo $CTLOUT_LINE | cut -d " " -f 1)
-
-CTLIN_LINE=$(echo $CTLIN_LINE | cut -d "-" -f 2)
-CTLIN_LINE=$(echo $CTLIN_LINE | cut -d " " -f 1)
-
-echo "CTL OUT: $CTLOUT = $CTLOUT_LINE"
-echo "CTL IN : $CTLIN = $CTLIN_LINE"
-
-insmod ksock_gpio.ko gpio_ctl_o=$CTLOUT_LINE gpio_ctl_i=$CTLIN_LINE
-
diff --git a/ksock-gpio/ksock_gpio.c b/ksock-gpio/ksock_gpio.c
deleted file mode 100644 (file)
index f0f3582..0000000
+++ /dev/null
@@ -1,120 +0,0 @@
-#include <linux/init.h>
-#include <linux/module.h>
-#include <linux/kernel.h>
-#include <linux/ip.h>
-#include <linux/tcp.h>
-#include <linux/udp.h>
-#include <linux/string.h>
-#include <linux/gpio.h>
-#include <linux/interrupt.h>
-#include <linux/workqueue.h>
-#include <linux/sched.h>
-#include <linux/time.h>
-#include <linux/delay.h>
-
-static DECLARE_WAIT_QUEUE_HEAD(this_wq);
-
-static int condition = 0;
-
-static struct work_struct job;
-
-static int gpio_ctl_o;
-static int gpio_ctl_i;
-
-module_param(gpio_ctl_o, int, 0664);
-module_param(gpio_ctl_i, int, 0664);
-
-static unsigned int gpio_ctl_i_irq;
-
-static void job_handler(struct work_struct* work){
-
-
-    printk(KERN_INFO "waitqueue handler: %s\n", __FUNCTION__);
-
-    msleep(5000);
-
-       gpio_set_value(gpio_ctl_o, IRQF_TRIGGER_RISING);
-
-    printk(KERN_INFO "up after 5000ms\n");
-
-    condition = 1;
-
-    wake_up_interruptible(&this_wq);
-
-
-}
-
-static irqreturn_t gpio_irq_handler(int irq, void *dev_id) {
-       printk("sock gpio: interrupt was triggered and ISR was called\n");
-       return IRQ_HANDLED;
-}
-
-static int __init ksock_gpio_init(void) {
-
-       if(gpio_request(gpio_ctl_o, "gpio-ctl-o")) {
-               printk("sock gpio: can't allocate gpio_ctl_o: %d\n", gpio_ctl_o);
-               return -1;
-       }
-
-
-       if(gpio_request(gpio_ctl_i, "gpio-ctl-i")) {
-               printk("sock gpio: can't allocate gpio_ctl_i: %d\n", gpio_ctl_i);
-               gpio_free(gpio_ctl_o);
-               return -1;
-       }
-
-       if(gpio_direction_output(gpio_ctl_o, IRQF_TRIGGER_NONE)) {
-               printk("sock gpio: can't set gpio_ctl_o to output\n");
-               gpio_free(gpio_ctl_o);
-               gpio_free(gpio_ctl_i);
-               return -1;
-       }
-
-       if(gpio_direction_input(gpio_ctl_i)) {
-               printk("sock gpio: can't set gpio_ctl_i to input\n");
-               gpio_free(gpio_ctl_o);
-               gpio_free(gpio_ctl_i);
-               return -1;
-       }
-
-       gpio_ctl_i_irq = gpio_to_irq(gpio_ctl_i);
-
-       if(request_irq(gpio_ctl_i_irq, gpio_irq_handler, IRQF_TRIGGER_RISING, "gpio_ctl_i_irq", NULL) != 0) {
-               printk("sock gpio: can't request interrupt\n");
-               gpio_free(gpio_ctl_o);
-               gpio_free(gpio_ctl_i);
-               return -1;
-       }
-
-
-       printk("sock gpio: gpio_ctl_i to IRQ %d\n", gpio_ctl_i_irq);
-
-       printk("sock gpio: module is initialized into the kernel\n");
-
-    INIT_WORK(&job, job_handler);
-
-    schedule_work(&job);
-
-    printk(KERN_INFO "putting to sleep: %s\n", __FUNCTION__);
-
-    wait_event_interruptible(this_wq, condition != 0);
-
-    printk(KERN_INFO "woken up\n");
-
-
-       return 0;
-
-}
-
-static void __exit ksock_gpio_exit(void) {
-
-       gpio_free(gpio_ctl_o);
-       gpio_free(gpio_ctl_i);
-       free_irq(gpio_ctl_i_irq, NULL);
-       printk("sock gpio: module is removed from the kernel\n");
-}
-
-module_init(ksock_gpio_init);
-module_exit(ksock_gpio_exit);
-
-MODULE_LICENSE("GPL");
\ No newline at end of file