• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            天下

            記錄修行的印記

            韋根驅動

            #include <linux/types.h>
            #include 
            <linux/module.h>
            #include 
            <linux/init.h>
            #include 
            <linux/poll.h>
            #include 
            <linux/errno.h>
            #include 
            <linux/gpio.h>
            #include 
            <linux/interrupt.h>
            #include 
            <linux/miscdevice.h>
            #include 
            <linux/ioport.h>
            #include 
            <linux/device.h>
            #include 
            <asm/io.h>
            #include 
            <asm/irq.h>
            #include 
            <mach/irqs.h>
            #include 
            <mach/regs-gpio.h>

            #include 
            "../ioctl_new.h"

            static spinlock_t    wiegand_lock;
            static int            wiegand_in = 0;
            static int            wiegand_in_cur = 0;
            static int            wiegand_in_stime = 0;
            static int            wiegand_in1_stime = 0;
            static int            wiegand_in2_stime = 0;
            static unsigned char wiegand_data[40];
            static WIEGAND_TYPE    wiegand_mode;

            inline 
            void wiegand_delay(int microseconds)
            {
                
            int i;
                
            while (microseconds--)
                {
                    
            for (i=0; i<65; i++) __asm("NOP");
                }
            }

            static int wiegand_gettickcount(void)
            {
                
            static int __start_time = 0//second
                struct timeval tv;

                do_gettimeofday(
            &tv);

                
            if (__start_time == 0)
                    __start_time 
            = tv.tv_sec;

                
            return ((tv.tv_sec - __start_time) * 1000 + tv.tv_usec / 1000);
            }

            inline 
            void wiegand_minus_interrupt(void)
            {
                
            if (wiegand_in != WGNSTAT_RECVFULL)
                {
                    
            if (wiegand_gettickcount() - wiegand_in_stime >= 100)
                        wiegand_in_cur 
            = 0;
                    wiegand_in_stime 
            = wiegand_gettickcount();
                    wiegand_data[wiegand_in_cur
            ++= 0;
                    
            if (wiegand_in_cur >= 34)
                        wiegand_in 
            = WGNSTAT_RECVFULL;
                    
            else if (wiegand_in_cur >= 26)
                        wiegand_in 
            = WGNSTAT_RECV26;
                }
            }

            inline 
            void wiegand_plus_interrupt(void)
            {
                
            if (wiegand_in != WGNSTAT_RECVFULL)
                {
                    
            if (wiegand_gettickcount() - wiegand_in_stime >= 100)
                        wiegand_in_cur 
            = 0;
                    wiegand_in_stime 
            = wiegand_gettickcount();
                    wiegand_data[wiegand_in_cur
            ++= 1;
                    
            if (wiegand_in_cur >= 34)
                        wiegand_in 
            = WGNSTAT_RECVFULL;
                    
            else if (wiegand_in_cur >= 26)
                        wiegand_in 
            = WGNSTAT_RECV26;
                }
            }

            static irqreturn_t wiegand_minus1_interrupt(int irq, void *dev_id)
            {
                spin_lock(
            &wiegand_lock);
            //    printk("wiegand_minus1_interrupt\n");
                if (wiegand_gettickcount() - wiegand_in2_stime > 200)
                {
                    wiegand_minus_interrupt();
                    wiegand_in1_stime 
            = wiegand_in_stime;
                }
                spin_unlock(
            &wiegand_lock);
                
            return IRQ_HANDLED;
            }

            static irqreturn_t wiegand_plus1_interrupt(int irq, void *dev_id)
            {
                spin_lock(
            &wiegand_lock);
            //    printk("wiegand_plus1_interrupt\n");
                if (wiegand_gettickcount() - wiegand_in2_stime > 200)
                {
                    wiegand_plus_interrupt();
                    wiegand_in1_stime 
            = wiegand_in_stime;
                }
                spin_unlock(
            &wiegand_lock);
                
            return IRQ_HANDLED;
            }


            static int wiegand_open(struct inode * inode, struct file * filp);
            static int wiegand_release(struct inode * inode,struct file * filp);
            static ssize_t wiegand_read(struct file *flip, char *buf, size_t len, loff_t *pos);
            static ssize_t wiegand_write(struct file *flip, const char *buf, size_t len, loff_t *pos);
            static long wiegand_ioctl(struct file *file, unsigned int cmd, unsigned long arg);

            static struct file_operations wiegand_fops = {
                owner:        THIS_MODULE,
                open:        wiegand_open,
                release:    wiegand_release,
                read:        wiegand_read,
                write:        wiegand_write,
                unlocked_ioctl:        wiegand_ioctl,
            };

            static struct miscdevice wiegand_dev = {
                WIEGAND_MINOR,
                WIEGAND_MODULE_NAME,
                
            &wiegand_fops
            };

            static void config_wiegand_pins(void)
            {
                s3c2410_gpio_cfgpin(WGNIN_0, WGNIN_0_CON);
                s3c2410_gpio_cfgpin(WGNIN_1, WGNIN_1_CON);
                s3c2410_gpio_cfgpin(WGNOUT0, WGNOUT0_CON);
                s3c2410_gpio_cfgpin(WGNOUT1, WGNOUT1_CON);
            #if 0
                
            if (request_irq(WGNIN_0_IRQ_NUM, &wiegand_minus1_interrupt, 
                    IORESOURCE_IRQ 
            | IRQF_TRIGGER_RISING, 
                    WIEGAND_IRQ_MINUS, 
                    
            &wiegand_dev)         
                    
            || request_irq(WGNIN_1_IRQ_NUM, &wiegand_plus1_interrupt,  
                    IORESOURCE_IRQ 
            | IRQF_TRIGGER_RISING, 
                    WIEGAND_IRQ_PLUS, 
                    
            &wiegand_dev))
                    
                {
                    printk(
            "WIEGAND request_irq Fail\n");
                }
            #endif
            }

            static int wiegand_open(struct inode * inode, struct file * filp)
            {
                config_wiegand_pins();
                
            return 0;
            }

            static int wiegand_release(struct inode * inode,struct file * filp)
            {
            #if 0
                free_irq(WGNIN_0_IRQ_NUM, 
            &wiegand_dev);
                free_irq(WGNIN_1_IRQ_NUM, 
            &wiegand_dev);
            #endif
                
            return 0;
            }

            static ssize_t wiegand_read(struct file *flip, char *buf, size_t len, loff_t *pos)
            {
                
            int result;
                spin_lock(
            &wiegand_lock);
                
            if (wiegand_in == WGNSTAT_NONE || len > sizeof(wiegand_data) || (wiegand_gettickcount() - wiegand_in_stime > 1800))        //500
                {
                    wiegand_in 
            = WGNSTAT_NONE;
                    spin_unlock(
            &wiegand_lock);
                    
            return 0;
                }
                
            if (len > wiegand_in_cur)
                    len 
            = wiegand_in_cur;
                result 
            = copy_to_user(buf, wiegand_data, len);
                wiegand_in 
            = WGNSTAT_NONE;
                wiegand_in_cur 
            = 0;
                spin_unlock(
            &wiegand_lock);
                
            return len;
            }

            static ssize_t wiegand_write(struct file *flip, const char *buf, size_t len, loff_t *pos)
            {
                
            int i;
                
            char data[40];

                
            if (len > sizeof(data))
                    
            return 0;

                i 
            = copy_from_user(data, buf, len);
                
            for (i=0; i<len; i++)
                {
                    
            if (data[i] == 0)
                    {
                        WGNOUT0_1; wiegand_delay(wiegand_mode.dwTpw); WGNOUT0_0;
                    }
                    
            else
                    {
                        WGNOUT1_1; wiegand_delay(wiegand_mode.dwTpw); WGNOUT1_0;
                    }
                    wiegand_delay(wiegand_mode.dwTpi);
                }

                
            return len;
            }

            static long wiegand_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
            {
                
            int result = 0;
                spin_lock(
            &wiegand_lock);
                
            switch(cmd)
                {
                
            case WIEGAND_MODE_SET:
                    result 
            = copy_from_user(&wiegand_mode, (void*)arg, sizeof(WIEGAND_TYPE));
                    
            break;
                }
                spin_unlock(
            &wiegand_lock);
                
            return (result == sizeof(WIEGAND_TYPE) ? 0 : -1);
            }



            static int __init s3c2416_wiegand_init(void)
            {
                
            int ret = 0;
                
                ret 
            = misc_register(&wiegand_dev);
                
            if (ret)
                {
                    printk(
            "probuck s3c2416 WIEGAND Driver" WIEGAND_DRIVER_VERSION "Fail\n");
                    
            goto exit_sb3kt_wiegand_init;
                }
                spin_lock_init(
            &wiegand_lock);

                printk(
            "probuck s3c2416 WIEGAND Driver" WIEGAND_DRIVER_VERSION "\n");
                
            exit_sb3kt_wiegand_init:
                
            return ret;
            }

            static void __exit s3c2416_wiegand_cleanup(void)
            {
                misc_deregister(
            &wiegand_dev);
            }

            module_init(s3c2416_wiegand_init);
            module_exit(s3c2416_wiegand_cleanup);
            MODULE_LICENSE(
            "GPL");

            MODULE_DESCRIPTION(
            "s3c2416 WIEGAND Driver");
            MODULE_SUPPORTED_DEVICE(
            "s3c2416 WIEGAND");

            posted on 2014-03-21 17:33 天下 閱讀(1346) 評論(0)  編輯 收藏 引用 所屬分類: kernel & Driver

            <2012年8月>
            2930311234
            567891011
            12131415161718
            19202122232425
            2627282930311
            2345678

            導航

            統計

            常用鏈接

            留言簿(4)

            隨筆分類(378)

            隨筆檔案(329)

            鏈接

            最新隨筆

            搜索

            最新評論

            亚洲国产精品综合久久网络| 久久精品人妻一区二区三区| 伊人久久大香线蕉无码麻豆| 久久婷婷五月综合97色直播| 精品久久一区二区三区| 久久久久久亚洲精品无码| 久久久久久久综合日本| 色综合久久久久无码专区 | 国产欧美一区二区久久| 国产亚洲精午夜久久久久久| 亚洲国产精品成人久久蜜臀| 久久综合伊人77777麻豆| 久久久免费精品re6| 漂亮人妻被中出中文字幕久久 | 久久久久人妻一区精品果冻| 久久人人爽人人人人片av| 亚洲国产香蕉人人爽成AV片久久 | 亚洲精品乱码久久久久久蜜桃不卡| 精品久久久久久中文字幕| 无码国内精品久久人妻蜜桃| 国产高潮久久免费观看| 国产精品18久久久久久vr | 久久久中文字幕| 亚洲综合婷婷久久| 欧美麻豆久久久久久中文| 久久亚洲高清综合| 国产精品九九久久精品女同亚洲欧美日韩综合区 | 久久99精品久久久久久齐齐 | 久久久久国产精品麻豆AR影院| 久久国产欧美日韩精品| 国内精品伊人久久久久妇| 久久久久这里只有精品| 99久久精品无码一区二区毛片 | 久久人人爽人人爽人人片AV高清| 国产精品青草久久久久福利99 | 中文字幕久久精品| 久久人人超碰精品CAOPOREN| 伊人久久大香线焦综合四虎| 久久综合欧美成人| 精品一久久香蕉国产线看播放| 国产精品99久久久久久猫咪 |