LLeader(94125943) 20:48:49 我编写的LED驱动,其中寄存器的配置在ADS调试时没有问题。但是在linux操作系统里面,不能驱动,程序如下,请高手指教: /*#define MODULE*/ #include <linux/kernel.h> #include <linux/module.h>
#include <asm/uaccess.h>
#include <linux/mm.h> #include <linux/ioport.h>
#include <asm/io.h> #include <linux/ioport.h>
#include <linux/fs.h> #include <linux/wrapper.h>
#define DRAM_MEM_MAJOR 231 #define DEVICE_NAME "device_led" #define SUCCESS 0
static int Device_Open = 0;
int dram_mem_init(void); static int device_open(struct inode *,struct file *); static int device_release(struct inode *,struct file *); static ssize_t device_write(struct file *,const char *,size_t,loff_t *); int init_module(void); void cleanup_module(void);
struct file_operations dram_mem_ops = { read: device_read, write: device_write, open: device_open, release: device_release, };
static int Major;
unsigned long virt_addr0; unsigned long virt_addr1; unsigned long virt_addr2; int dram_mem_init(void) {
virt_addr0 = (unsigned long)ioremap((unsigned long)0x56000050,0x4); *(unsigned long *)virt_addr0&= 0x00ff;//娓呴浂 *(unsigned long *)virt_addr0|= 0x5500;//杈撳嚭鏈夋晥 virt_addr1 = (unsigned long)ioremap((unsigned long)0x56000054,0x4); *(unsigned long *)virt_addr1=0x0; virt_addr2 = (unsigned long)ioremap((unsigned long)0x56000058,0x4); *(unsigned long *)virt_addr2&= 0x0f;//IO浣胯兘 Major = register_chrdev(DRAM_MEM_MAJOR,DEVICE_NAME,&dram_mem_ops); if(Major <0) { iounmap((void *)virt_addr0); iounmap((void *)virt_addr1); iounmap((void *)virt_addr2); printk("DRAM_MEM init_module:failed with %d
",Major); return Major; } Major = DRAM_MEM_MAJOR; printk("DRAM_MEM_MAJOR registred: Major = %d
" ,Major); return 0; }
static int device_open(struct inode * inode,struct file *file) { if(Device_Open) { return -EBUSY; } Device_Open++; MOD_INC_USE_COUNT; return SUCCESS; }
static int device_release(struct inode * inode,struct file *file) { Device_Open --; MOD_DEC_USE_COUNT;
return 0; }
#ifdef MODULE int init_module() {
return dram_mem_init(); }
void cleanup_module() { int ret; iounmap((void *)virt_addr0); iounmap((void *)virt_addr1); iounmap((void *)virt_addr2);
ret = unregister_chrdev(Major,DEVICE_NAME); if(ret < 0) { printk("unregister_chrdev:error %d
",ret); } } #endif |