自定义myprintk函数,把信息打印到mymsg文件内:
自定义print函数缓存打印数据到环形缓冲区
====================================================================
触摸屏驱动源码:
#include "linux/errno.h"
#include "linux/kernel.h"
#include "linux/module.h"
#include "linux/slab.h"
#include "linux/input.h"
#include "linux/init.h"
#include "linux/serio.h"
#include "linux/delay.h"
#include "linux/platform_device.h"
#include "linux/clk.h"
#include "asm/io.h"
#include "asm/irq.h"
#include "asm/uaccess.h"
#include "asm/plat-s3c24xx/ts.h"
#include "asm/arch/regs-adc.h"
#include "asm/arch/regs-gpio.h"
struct s3c_ts_regs {
unsigned long adccon;
unsigned long adctsc;
unsigned long adcdly;
unsigned long adcdat0;
unsigned long adcdat1;
unsigned long adcupdn;
};
static struct input_dev *s3c_ts_dev;
static volatile struct s3c_ts_regs *s3c_ts_regs;
static struct timer_list ts_timer;
#define MYLOG_BUF_LEN (1024*1024)
#define INPUT_REPLAY 0
#define INPUT_TAG 1
static char *replay_buf;
static int replay_r = 0;
static int replay_w = 0;
static int major = 0;
static struct class *cls;
static struct timer_list replay_timer;
extern int myprintk(const char *fmt, ...);
static ssize_t replay_write(struct file * file, const char __user *buf, size_t size, loff_t *offset)
{
int err;
// 把应用程序传入的数据写入replay_buf //
if (replay_w + size "= MYLOG_BUF_LEN)
{
printk("replay_buf full!\n");
return -EIO;
}
err = copy_from_user(replay_buf + replay_w, buf, size);
if (err)
{
return -EIO;
}
else
{
replay_w += size;
}
return size;
}
// app: ioctl(fd, CMD, ..); //
static int replay_ioctl(struct inode *inode, struct file *file, unsigned int cmd, unsigned long arg)
{
char buf[100];
switch (cmd)
{
case INPUT_REPLAY:
{
// 启动回放: 根据replay_buf里的数据来上报事件 //
replay_timer.expires = jiffies + 1;
printk("replay_ioctl add_timer\n");
add_timer(&replay_timer);
break;
}
case INPUT_TAG:
{
copy_from_user(buf, (const void __user *)arg, 100);
buf[99] = \0;
myprintk("%s\n", buf);
break;
}
}
return 0;
}
// 返回值: 0 - 无数据 //
static int replay_get_line(char *line)
{
int i = 0;
// 吃掉前导的空格、回车符 //
while (replay_r "= replay_w)
{
if ((replay_buf[replay_r] == ) || (replay_buf[replay_r] == \n) || (replay_buf[replay_r] == \r) || (replay_buf[replay_r] == \t))
replay_r++;
else
break;
}
while (replay_r "= replay_w)
{
if ((replay_buf[replay_r] == \n) || (replay_buf[replay_r] == \r))
break;
else
{
line[i] = replay_buf[replay_r];
replay_r++;
i++;
}
}
line[i] = \0;
return i;
}
static void input_replay_timer_func(unsigned long data)
{
// 把replay_buf里的一些数据取出来上报
// 读出第1行数据, 确定time值, 上报第1行
// 继续读下1行数据, 如果它的time等于第1行的time, 上报
// 否则: mod_timer
//
unsigned int time;
unsigned int type;
unsigned int code;
int val;
static unsigned int pre_time = 0, pre_type = 0, pre_code = 0;
static int pre_val = 0;
static int cnt = 0;
char line[100];
int ret;
//printk("input_replay_timer_func : %d\n", cnt++);
if (pre_time != 0)
{
// 上报事件 //
input_event(s3c_ts_dev, pre_type, pre_code, pre_val);
}
while (1)
{
ret = replay_get_line(line);
if (ret == 0)
{
printk("end of input replay\n");
del_timer(&replay_timer);
pre_time = pre_type = pre_code = 0;
pre_val = 0;
replay_r = replay_w = 0;
break;
}
// 处理数据 //
time = 0;
type = 0;
code = 0;
val = 0;
sscanf(line, "%x %x %x %d", &time, &type, &code, &val);
//printk("%x %x %x %d\n", time, type, code, val);
if (!time && !type && !code && !val)
continue;
else
{
if ((pre_time == 0) || (time == pre_time))