总结如下:
1.自己新添加的设备驱动,默认没有读写权限。
需修改设备权限才能正常访问。
2.android下的应用程序需要使用静态编译(实际上也可以使用动态库
)
关于android下c程序使用动态库的方法请参考
http://www.linuxidc.com/Linux/2011-04/34404.htm我拷贝了driver/char下面的mini6410_pwm.c 存为mini6410_timer.c
然后改DEVICE_NAME为 timer 并改了一些函数名称
代码如下
然后我在jni下 调用 open("/dev/timer"); 返回错误
另 :在adb shell 查看dev文件夹 中是可以看到/dev/timer的
sys/class/misc/下timer也有 说明设备注册成功 ,但为何无法打开?
我表示粉郁闷
复制代码- #include <linux/module.h>
- #include <linux/kernel.h>
- #include <linux/fs.h>
- #include <linux/init.h>
- #include <linux/delay.h>
- #include <linux/poll.h>
- #include <asm/irq.h>
- #include <asm/io.h>
- #include <linux/interrupt.h>
- #include <asm/uaccess.h>
- #include <mach/hardware.h>
- #include <plat/regs-timer.h>
- #include <mach/regs-irq.h>
- #include <asm/mach/time.h>
- #include <linux/clk.h>
- #include <linux/cdev.h>
- #include <linux/device.h>
- #include <linux/miscdevice.h>
- #include <mach/map.h>
- #include <mach/regs-clock.h>
- #include <mach/regs-gpio.h>
- #include <plat/gpio-cfg.h>
- #include <mach/gpio-bank-e.h>
- #include <mach/gpio-bank-f.h>
- #include <mach/gpio-bank-k.h>
- #define DEVICE_NAME "timer"
- #define TIMER_IOCTL_SET_FREQ 1
- #define TIMER_IOCTL_STOP 0
- static struct semaphore lock;
- /* freq: pclk/50/16/65536 ~ pclk/50/16
- * if pclk = 50MHz, freq is 1Hz to 62500Hz
- * human ear : 20Hz~ 20000Hz
- */
- static void timer_Set_Freq( unsigned long freq )
- {
- unsigned long tcon;
- unsigned long tcnt;
- unsigned long tcfg1;
- unsigned long tcfg0;
- struct clk *clk_p;
- unsigned long pclk;
- unsigned tmp;
- tmp = readl(S3C64XX_GPFCON);
- tmp &= ~(0x3U << 28);
- tmp |= (0x2U << 28);
- writel(tmp, S3C64XX_GPFCON);
- tcon = __raw_readl(S3C_TCON);
- tcfg1 = __raw_readl(S3C_TCFG1);
- tcfg0 = __raw_readl(S3C_TCFG0);
- //prescaler = 50
- tcfg0 &= ~S3C_TCFG_PRESCALER0_MASK;
- tcfg0 |= (50 - 1);
- //mux = 1/16
- tcfg1 &= ~S3C_TCFG1_MUX0_MASK;
- tcfg1 |= S3C_TCFG1_MUX0_DIV16;
- __raw_writel(tcfg1, S3C_TCFG1);
- __raw_writel(tcfg0, S3C_TCFG0);
- clk_p = clk_get(NULL, "pclk");
- pclk = clk_get_rate(clk_p);
- tcnt = (pclk/50/16)/freq;
-
- __raw_writel(tcnt, S3C_TCNTB(0));
- __raw_writel(tcnt/2, S3C_TCMPB(0));
-
- tcon &= ~0x1f;
- tcon |= 0xb; //disable deadzone, auto-reload, inv-off, update TCNTB0&TCMPB0, start timer 0
- __raw_writel(tcon, S3C_TCON);
-
- tcon &= ~2; //clear manual update bit
- __raw_writel(tcon, S3C_TCON);
- }
- void timer_Stop( void )
- {
- unsigned tmp;
- tmp = readl(S3C64XX_GPFCON);
- tmp &= ~(0x3U << 28);
- writel(tmp, S3C64XX_GPFCON);
- }
- static int s3c64xx_timer_open(struct inode *inode, struct file *file)
- {
- if (!down_trylock(&lock))
- return 0;
- else
- return -EBUSY;
- }
- static int s3c64xx_timer_close(struct inode *inode, struct file *file)
- {
- up(&lock);
- return 0;
- }
- static long s3c64xx_timer_ioctl(struct file *filep, unsigned int cmd, unsigned long arg)
- {
- switch (cmd) {
- case TIMER_IOCTL_SET_FREQ:
- if (arg == 0)
- return -EINVAL;
- timer_Set_Freq(arg);
- break;
- case TIMER_IOCTL_STOP:
- default:
- timer_Stop();
- break;
- }
- return 0;
- }
- static struct file_operations dev_fops = {
- .owner = THIS_MODULE,
- .open = s3c64xx_timer_open,
- .release = s3c64xx_timer_close,
- .unlocked_ioctl = s3c64xx_timer_ioctl,
- };
- static struct miscdevice misc = {
- .minor = MISC_DYNAMIC_MINOR,
- .name = DEVICE_NAME,
- .fops = &dev_fops,
- };
- static int __init dev_init(void)
- {
- int ret;
- init_MUTEX(&lock);
- ret = misc_register(&misc);
- printk (DEVICE_NAME"\tinitialized\n");
- return ret;
- }
- static void __exit dev_exit(void)
- {
- misc_deregister(&misc);
- }
- module_init(dev_init);
- module_exit(dev_exit);
- MODULE_LICENSE("GPL");
- MODULE_AUTHOR("FriendlyARM Inc.");
- MODULE_DESCRIPTION("S3C6410 Timer Driver liyongliu");
|
makefile与Kconfig都已修改
[ 此帖被odanobunaga在2011-09-19 12:38重新编辑 ]