大家好,
开发环境:linux2.6.35+imx287处理器
本人参照网上的adc驱动模板,写了个LRADC0单通道的电池电压采集代码,编译成lradc0.ko后,insmod可以加载成功,在/dev下可以看见设备节点,但是一执行测试代码,系统就抱死,卡主不动了,通过调试串口输入任何按键都没反应,包括ctrl+z或者ctrl+c,都没有反应。
附上驱动代码和测试代码,请各位帮忙分析下,给点思路,本人是新手:
驱动代码:
#include <linux/module.h>
#include <linux/err.h>
#include <linux/platform_device.h>
#include <linux/power_supply.h>
#include <linux/jiffies.h>
#include <linux/io.h>
#include <linux/sched.h>
#include <linux/clk.h>
#include <mach/ddi_bc.h>
//#include "ddi_bc_internal.h"
#include <linux/regulator/consumer.h>
#include <linux/regulator/driver.h>
#include <mach/regulator.h>
#include <mach/regs-power.h>
#include <mach/hardware.h>
#include <mach/irqs.h>
#include <mach/clock.h>
#include <linux/delay.h>
#include <linux/proc_fs.h>
#include <linux/interrupt.h>
#include <asm/fiq.h>
#include <mach/mx28.h>
#include <mach/regs-lradc.h>
#include <linux/miscdevice.h>
#include <asm/uaccess.h>
#define DEVICE_NAME "lradc0"
static struct clk *adc_clock;
static void __iomem *base_addr;
static wait_queue_head_t adc_waitqueue;
struct resource *lradc_ch0_irq;
DECLARE_MUTEX(adc_lock);
EXPORT_SYMBOL(adc_lock);
static volatile int is_read_ok = 0;
static volatile int adc_data;
static int lradc0_open(struct inode *inode, struct file *file);
static ssize_t lradc0_read(struct file *filp, char *buffer, size_t count, loff_t *ppos);
static int lradc0_close(struct inode *inode, struct file *filp);
static struct file_operations lradc0_fops =
{
.owner = THIS_MODULE,
.open = lradc0_open,
.read = lradc0_read,
.release = lradc0_close,
};
static struct miscdevice adc_miscdev =
{
.minor = MISC_DYNAMIC_MINOR,
.name = DEVICE_NAME,
.fops = &lradc0_fops,
};
static irqreturn_t lradc0_irq(int irq, void *dev_id)
{
if(!is_read_ok)
{
adc_data = readl(base_addr +HW_LRADC_CHn(0)) & 0x3ffff;
is_read_ok = 1;
wake_up_interruptible(&adc_waitqueue);
}