debugging tool: raise GPF6 on event (to trigger scope)

Werner Almesberger werner at openmoko.org
Sat Nov 22 04:30:40 CET 2008


This is a little gadget that may be useful for low-level debugging.

It generates a rising edge on GPF6 (the AUX button) when a certain
trigger condition has occurred the right number of times. This can
be used to trigger an oscilloscope.

The code being debugged has to call trigger() before the event in
question. The system is controlled via sysfs files:

/sys/kernel/trigger
    write: enable the trigger and specify now many triggers will be
        ignored.
    read: read back the value that has been set.
/sys/kernel/trigger_count:
    write: reset the counter.
    read: the number of times trigger() has been called since the
        last reset.

Probably not something we want in our official branches, but it may
be handy to have around if debugging some protocol issues.

- Werner

Index: ktrack/arch/arm/plat-s3c24xx/Makefile
===================================================================
--- ktrack.orig/arch/arm/plat-s3c24xx/Makefile	2008-11-21 19:22:53.000000000 -0200
+++ ktrack/arch/arm/plat-s3c24xx/Makefile	2008-11-21 19:23:02.000000000 -0200
@@ -51,4 +51,5 @@
 				   gta02_pm_wlan.o  \
 				   neo1973_shadow.o \
 				   neo1973_pm_resume_reason.o \
-				   neo1973_memconfig.o
+				   neo1973_memconfig.o \
+				   gta02_trigger.o
Index: ktrack/arch/arm/plat-s3c24xx/gta02_trigger.c
===================================================================
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ ktrack/arch/arm/plat-s3c24xx/gta02_trigger.c	2008-11-21 19:40:23.000000000 -0200
@@ -0,0 +1,79 @@
+#include <linux/module.h>
+#include <linux/kernel.h>
+#include <linux/init.h>
+#include <linux/device.h>
+#include <linux/sysfs.h>
+#include <mach/gpio.h>
+#include <mach/regs-gpio.h>
+
+
+static int trigger_value = -1;
+static int trigger_count;
+
+
+
+void trigger(void)
+{
+	if (trigger_count++ != trigger_value)
+		return;
+	printk(KERN_ERR "TRIGGER (%d)\n", trigger_count-1);
+	gpio_direction_output(S3C2410_GPF6, 1);
+}
+
+
+static ssize_t trigger_read(struct device *dev, struct device_attribute *attr,
+    char *buf)
+{
+	return sprintf(buf, "%d\n", trigger_value);
+}
+
+
+static ssize_t trigger_write(struct device *dev, struct device_attribute *attr,
+    const char *buf, size_t count)
+{
+	long tmp;
+	char *end;
+
+	tmp = simple_strtol(buf, &end, 0);
+	if (end == buf)
+		return -EINVAL;
+	trigger_value = tmp;
+	return count;
+}
+
+
+static ssize_t trigger_count_read(struct device *dev,
+    struct device_attribute *attr, char *buf)
+{
+	return sprintf(buf, "%d\n", trigger_count);
+}
+
+
+static ssize_t trigger_count_write(struct device *dev,
+    struct device_attribute *attr, const char *buf, size_t count)
+{
+	trigger_count = 0;
+	return count;
+}
+
+
+static DEVICE_ATTR(trigger, 0644, trigger_read, trigger_write);
+static DEVICE_ATTR(trigger_count, 0644, trigger_count_read,
+    trigger_count_write);
+
+
+static int __init trigger_init(void)
+{
+	int ret;
+
+	ret = sysfs_create_file(kernel_kobj, &dev_attr_trigger.attr);
+	if (ret)
+		return ret;
+	/* @@@ we don't really care about errors here ... */
+	return sysfs_create_file(kernel_kobj, &dev_attr_trigger_count.attr);
+}
+
+
+module_init(trigger_init);
+
+EXPORT_SYMBOL_GPL(trigger);



More information about the openmoko-kernel mailing list