新聞中心

EEPW首頁 > 嵌入式系統(tǒng) > 設(shè)計應(yīng)用 > 應(yīng)用調(diào)試-----輸入模擬器之編寫測試模擬功能

應(yīng)用調(diào)試-----輸入模擬器之編寫測試模擬功能

作者: 時間:2016-11-21 來源:網(wǎng)絡(luò) 收藏
自定義myprintk函數(shù),把信息打印到mymsg文件內(nèi):
自定義print函數(shù)緩存打印數(shù)據(jù)到環(huán)形緩沖區(qū)
====================================================================
觸摸屏驅(qū)動源碼:
#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;
// 把應(yīng)用程序傳入的數(shù)據(jù)寫入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:
{
// 啟動回放: 根據(jù)replay_buf里的數(shù)據(jù)來上報事件 //
replay_timer.expires = jiffies + 1;
printk("replay_ioctl add_timern");
add_timer(&replay_timer);
break;
}
case INPUT_TAG:
{
copy_from_user(buf, (const void __user *)arg, 100);
buf[99] =