📄 dacdev.c
字号:
/*下面是一个简单的gpio跑马灯驱动,基于FS2410处理器:*/
#ifndef __KERNEL__
#define __KERNEL__
#endif
#ifndef MODULE
#define MODULE
#endif
#include <linux/fs.h>
//#include <linux/iobuf.h>
#include <linux/major.h>
#include <asm/uaccess.h>
#include <asm/hardware.h>
#include <asm/arch-s3c2410/regs-gpio.h>
#include <asm/io.h>
#include <linux/vmalloc.h>
#include <linux/config.h>
#include <linux/init.h>
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/delay.h>#include <linux/cdev.h>
//#include "dac0832.h"
MODULE_LICENSE("GPL");
#define DAC_MAJOR 226
struct DAC_dev *DAC_devices;
static int dac_ctl_open(struct inode*, struct file*);
static int dac_ctl_ioctl(struct inode*, struct file*, unsigned int,unsigned long);int dcon1,dcon2;
static void *myadd;static void *DAC;
static struct file_operations dac_ctl_fops={
.ioctl = dac_ctl_ioctl,
.open = dac_ctl_open,
};
static int dac_ctl_open(struct inode *inode,struct file *fllp)
{
printk("open dac devices\n");
return 0;
}
static int dac_ctl_ioctl(struct inode *inode,struct file *flip,unsigned int command,unsigned long arg)
{ if(command==1) { dcon1=(arg<<8); printk("dac1=0x%x\n",dcon1); __raw_writel(dcon1, DAC); mdelay(1); __raw_writel(0x7400, myadd);//dacs1:0111 mdelay(10); __raw_writel(0x5400, myadd);//dacs1:0101 mdelay(80); __raw_writel(0x7400, myadd);//dacs1:0111 mdelay(10); __raw_writel(0x0f400, myadd); } if(command==2) { dcon2=(arg<<8); printk("dac2=0x%x\n",dcon2); __raw_writel(dcon2, DAC); mdelay(1); __raw_writel(0x0b400, myadd);//dacs2:1011 mdelay(10); __raw_writel(0x9400, myadd); //dacs2:1001 mdelay(80); __raw_writel(0x0b400, myadd); //dacs2:1011 mdelay(10); __raw_writel(0x0f400, myadd); } //cc2: //dac_opt(dcon1,dcon2); return 1;
}
//////////////////////////////////////////////////////////////////////void __exit dac_release(void)
{
printk("quit dac\n");
unregister_chrdev(DAC_MAJOR, "dac");
}/////////////////////////////////////////////////////////////////////
static int __init dac_init(void)
{
int ret; dcon1=0xc000; dcon1=0xc000; myadd=ioremap(0x3900f0e8,0x04);
DAC=ioremap(0x3900f0ec,0x04);
printk("dac_init\n");
ret = register_chrdev(DAC_MAJOR, "dac", &dac_ctl_fops);
if(ret < 0)
{
printk("fail to register\n");
return -1;
}
printk("success to register\n");
return 0;
}
module_init(dac_init);
module_exit(dac_release);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -