From 480640799470b4465d62348aaf73154423ddb896 Mon Sep 17 00:00:00 2001 From: lonkaars Date: Sun, 12 May 2024 13:23:03 +0200 Subject: implement simple printf "0" or "1" > /dev/lork input + add some registers to config.h --- 1/config.h | 11 +++++++++++ 1/fopdrv.c | 20 ++++++++++++++++++-- 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/1/config.h b/1/config.h index 7302134..6326354 100644 --- a/1/config.h +++ b/1/config.h @@ -2,3 +2,14 @@ #define DRV_NAME "lork" +#include + +// values from + +typedef uint32_t ti_am335x_word_t; + +// p. 180: "Control Module" +#define TI_AM335X_CM_ADDR ((ti_am335x_word_t*) 0x44E1_0000) +// p. 1459: "conf_gpmc_a3" +#define TI_AM335X_CM_GPMC_A3_ADDR ((ti_am335x_word_t*) TI_AM3358_CM_ADDR + 0x84Ch) + diff --git a/1/fopdrv.c b/1/fopdrv.c index 2c74fea..e0ad41c 100644 --- a/1/fopdrv.c +++ b/1/fopdrv.c @@ -2,13 +2,29 @@ // driver/char/mem.c read_null (/dev/null) ssize_t fop_read(struct file *file, char __user *buf, size_t count, loff_t *ppos) { - printk("%s(, , %lu, )\n", __PRETTY_FUNCTION__, count); + printk("%s(, , %u, )\n", __PRETTY_FUNCTION__, count); return 0; } // driver/char/mem.c write_null ssize_t fop_write(struct file *file, const char __user *buf, size_t count, loff_t *ppos) { - printk("%s(, , %lu, )\n", __PRETTY_FUNCTION__, count); + printk("%s(, , %u, )\n", __PRETTY_FUNCTION__, count); + + // only allow single character as input + if (count != 1) return count; + + // copy buffer for reading (see [kernel-labs-chrdev] in ../readme.md) + char input_buf[10]; + if (copy_from_user(input_buf + *ppos, buf, count)) + return -EFAULT; + + if (input_buf[0] == '0') { + printk("TODO: TURN OFF OUTPUT\n"); + } + if (input_buf[0] == '1') { + printk("TODO: TURN ON OUTPUT\n"); + } + return count; } -- cgit v1.2.3