新聞中心

EEPW首頁 > 嵌入式系統(tǒng) > 設(shè)計應(yīng)用 > Linux下CPLD驅(qū)動程序

Linux下CPLD驅(qū)動程序

作者: 時間:2012-05-25 來源:網(wǎng)絡(luò) 收藏

static unsigned cpld_drv_poll(struct file *file, poll_table *wait)
{
unsigned int mask = 0;
poll_wait(file, eint1_waitq, wait); //不會立即休眠
if (ev_eint1)
mask |= POLLIN | POLLRDNORM; //若產(chǎn)生中斷,mask賦值,表示有數(shù)據(jù)可讀
return mask;
}

static int cpld_drv_fasync (int fd, struct file *filp, int on)
{
//printk(driver: cpld_drv_fasyncn);
return fasync_helper (fd, filp, on, eint1_async);
}

int cpld_drv_close(struct inode *inode, struct file *file)
{
free_irq(IRQ_EINT1, 1); //釋放中斷
return 0;
}

static struct file_operations cpld_drv_fops = {
.owner = THIS_MODULE,
.write = cpld_drv_write,
.read = cpld_drv_read,
.open = cpld_drv_open,
.release = cpld_drv_close,
.poll = cpld_drv_poll,
.fasync = cpld_drv_fasync,
};

int major;
static int cpld_drv_init(void)
{
major = register_chrdev(0, cpld_drv, cpld_drv_fops); //注冊設(shè)備
cpld_class = class_create(THIS_MODULE, cplddrv); //創(chuàng)建類
cpld_class_dev = device_create(cpld_class, NULL, MKDEV(major, 0), NULL, cpld_drv); //自動創(chuàng)建設(shè)備文件 /dev/cpld_drv
cpld_data = (volatile unsigned long *)ioremap(0x08000000,4); //映射物理地址到虛擬地址
gpfcon = (volatile unsigned long *)ioremap(0x56000050, 8); //映射GPF寄存器物理地址到虛擬地址
gpfdat = gpfcon+1;
*gpfcon =~((0x30) | (0x3(2*2)));
*gpfcon |=((0x10) | (0x01(2*2))); //設(shè)置GPF0、2為輸出
*gpfdat |=0x1; //將使能位置1,加載驅(qū)動時不輸出PWM
printk(cpld_drv initialized!n);
return 0;
}

static void cpld_drv_exit(void)
{
*gpfdat |=0x1; //將使能位置1,卸載驅(qū)動后不輸出PWM
unregister_chrdev(major, cpld_drv); //注銷驅(qū)動
device_unregister(cpld_class_dev); //注銷設(shè)備
class_destroy(cpld_class); //注銷類
iounmap(cpld_data); //取消映射
iounmap(gpfcon);
}

module_init(cpld_drv_init);
module_exit(cpld_drv_exit);

MODULE_LICENSE(GPL);

linux操作系統(tǒng)文章專題:linux操作系統(tǒng)詳解(linux不再難懂)

上一頁 1 2 下一頁

關(guān)鍵詞: 驅(qū)動程序 CPLD Linux

評論


相關(guān)推薦

技術(shù)專區(qū)

關(guān)閉