中文字幕 另类精品,亚洲欧美一区二区蜜桃,日本在线精品视频免费,孩交精品乱子片免费

<sup id="3hn2b"></sup>

    1. <sub id="3hn2b"><ol id="3hn2b"></ol></sub><legend id="3hn2b"></legend>

      1. <xmp id="3hn2b"></xmp>

      2. 新聞中心

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

        Linux下CPLD驅(qū)動(dòng)程序

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

        ========================================================================== */
        /* */
        /* Filename.c */
        /* (c) 2001 Author Zhang Haibo */
        /* */
        /* Description driver program with interrupt and poll */
        /* */
        /* ========================================================================== */

        本文引用地址:http://www.antipu.com.cn/article/148984.htm

        #include linux/device.h>
        #include linux/module.h>
        #include linux/kernel.h>
        #include linux/fs.h>
        #include linux/init.h>
        #include linux/delay.h>
        #include asm/uaccess.h>
        #include linux/types.h>
        #include linux/errno.h>
        #include linux/mm.h>
        #include linux/sched.h>
        #include linux/cdev.h>
        #include linux/kdev_t.h>
        #include asm/system.h>
        #include linux/poll.h>
        #include linux/irq.h>
        #include asm/irq.h>
        #include asm/io.h>
        #include linux/interrupt.h>
        #include mach/regs-gpio.h>
        #include mach/hardware.h>
        #include linux/gpio.h>

        static struct class *cpld_class; //自動(dòng)創(chuàng)建設(shè)備文件時(shí)需要先創(chuàng)建類
        static struct class_device *cpld_class_dev; //再創(chuàng)建驅(qū)動(dòng)
        static DECLARE_WAIT_QUEUE_HEAD(eint1_waitq); //將中斷放入等待隊(duì)列
        static struct fasync_struct *eint1_async; //
        static volatile int ev_eint1 = 0; //中斷標(biāo)志,為1表示中斷發(fā)生,在中斷服務(wù)程序里置1
        volatile unsigned long *cpld_data = NULL; //的物理地址映射的虛擬地址指針 0x08000000
        volatile unsigned long *gpfcon = NULL; //GPF控制寄存器
        volatile unsigned long *gpfdat = NULL; //GPF數(shù)據(jù)寄存器,0位為使能位

        static irqreturn_t eint1_irq(int irq, void *dev_id) //中斷服務(wù)程序
        {
        ev_eint1 = 1; //中斷標(biāo)志位置1
        *gpfdat = ~(12); //進(jìn)入中斷GPF2清0
        wake_up_interruptible(eint1_waitq); //喚醒休眠的進(jìn)程
        kill_fasync (eint1_async, SIGIO, POLL_IN); //產(chǎn)生中斷后,驅(qū)動(dòng)向應(yīng)用程序發(fā)送信號(hào)
        return IRQ_RETVAL(IRQ_HANDLED);
        }

        static int cpld_drv_open(struct inode *inode, struct file *file)
        {
        request_irq(IRQ_EINT1, eint1_irq, IRQ_TYPE_EDGE_FALLING, EINT1, 1);//注冊(cè)中斷:中斷號(hào),中斷程序入口,中斷方式,中斷名,代號(hào)
        return 0;
        }

        static ssize_t cpld_drv_write(struct file *file, const char __user *buf, size_t count, loff_t * ppos)
        {
        int val;
        *gpfdat =~(10); //使能位置0,使能產(chǎn)生PWM,計(jì)數(shù)器開始計(jì)數(shù)
        copy_from_user(val, buf, count); //產(chǎn)生PWM的值從用戶空間傳入
        iowrite16(val,cpld_data); //寫入
        return 0;
        }

        static ssize_t cpld_drv_read(struct file *file, const char __user *buf, size_t count, loff_t * ppos)
        {
        int val;
        wait_event_interruptible(eint1_waitq, ev_eint1); //若無中斷產(chǎn)生,即ev_eint1=0,則休眠
        val=ioread16(cpld_data); //若中斷產(chǎn)生,則從CPLD讀取數(shù)據(jù),即編碼器值
        copy_to_user(buf,val,count); //將讀取值傳遞到用戶空間
        ev_eint1 = 0; //中斷標(biāo)志清0
        *gpfdat |= (12); //中斷讀數(shù)后,GPF2置1
        return 0;
        }

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

        上一頁 1 2 下一頁

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

        評(píng)論


        相關(guān)推薦

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

        關(guān)閉