|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?注册
x
我在s3c2410开发板上写一个驱动程序(mizi linux2.4.18,有mmu),但受到端口地址设置问题的困扰。我怀疑端口设置不对,写了一个虚拟地址映射的测试程序,但设置结果仍然不对,能否帮我分析一下原因。另外在我的开发板上模块使用printk不能输出,不知是什么原因,只好把测试信息返回给用户程序,也请大家帮我分析一下。谢谢!
驱动程序simple.c:
#define __KERNEL__
#define MODULE
#include <linux/fs.h>
#include <asm/uaccess.h>
#include <asm/hardware.h>
#include <asm/arch/S3C2410.h>
#include <asm/io.h>
#include <linux/vmalloc.h>
#include <linux/module.h>
#define IO_MAJOR 50
#define LEN 32
int dev;
//把寄存器数值转换成二进制数字符串,用于返回给用户程序
int getstring(unsigned num, char *s){
int i;
s = s + LEN;
*s-- = '\0';
for (i = 0; i < LEN; i++){
*s-- = '0' + (num & 1);
num = num >> 1;
}
}
int gpio_open(struct inode *inode, struct file *filp)
{
long rGPGCON;
MOD_INC_USE_COUNT;
(void *)(rGPGCON) = ioremap(GPGCON, 0x20);
*(volatile unsigned long *)(rGPGCON) &= ~0xa;
*(volatile unsigned long *)(rGPGCON) |= 5; //0101
iounmap(rGPGCON);
return 0;
};
int gpio_release(struct inode *inode, struct file *filp)
{
MOD_DEC_USE_COUNT;
return 0;
};
ssize_t gpio_read(struct file *file, char *buf, size_t count, loff_t * ppos)
{
char res[33];
long connum;
long rGPGCON;
(void *)(rGPGCON) = ioremap(GPGCON, 0x20);
connum = *(volatile unsigned long *)(rGPGCON);
getstring(connum, res);
*(volatile unsigned long *)(rGPGCON) += 1;
copy_to_user(buf, res, strlen(res)+1);
return strlen(res)+1;
}
static struct file_operations gpio_fops =
{
open: gpio_open,
read: gpio_read,
release: gpio_release,
};
int __init gpio_init(void)
{
dev = register_chrdev(IO_MAJOR, "simple", &gpio_fops);
if (dev < 0)
{
printk("register error\n");
}
return dev;
}
int __exit gpio_close(void)
{
unregister_chrdev(dev, "simple");
return 0;
}
module_init(gpio_init);
module_exit(gpio_close);
用户程序simpletest.c:
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <fcntl.h>
#include <stdio.h>
#include <string.h>
#define LOCALLEN 40
int main()
{
int simpledevice, i;
char s[LOCALLEN+1];
s[0] = '\0';
simpledevice = open("/dev/simple", O_RDONLY);
if (simpledevice < 0){
printf("Can't open the device file dev %i\n", simpledevice);
return -1;
}
for (i = 1; i <= 10; i++){
read(simpledevice, s, LOCALLEN);
printf("the length is %i\n", strlen(s));
printf("the result is %s\n", s);
sleep(2);
}
close(simpledevice);
return 0;
}
Makefile:
CC = /usr/local/arm/2.95.3/bin/arm-linux-gcc
LD = /usr/local/arm/2.95.3/bin/arm-linux-ld
INCLUDELDIR = /usr/ws-350/usr/src/kernel/include
LINUXDIR = /usr/ws-350/usr/src/kernel/include/linux
KERNELDIR = /usr/ws-350/usr/src/kernel
NOWFLAG = -I$(INCLUDELDIR) -I$(LINUXDIR) -I$(KERNELDIR)
all: cl simple.o simpletest.o
simple.o: simple.c
$(CC) $(NOWFLAG) -c simple.c simple.o
simpletest.o: simpletest.c
$(CC) simpletest.c -o simpletest.o
cl:
-rm -f *.o
|
|