• <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 天下 閱讀(1356) 評論(0)  編輯 收藏 引用 所屬分類: kernel & Driver

            <2025年6月>
            25262728293031
            1234567
            891011121314
            15161718192021
            22232425262728
            293012345

            導航

            統計

            常用鏈接

            留言簿(4)

            隨筆分類(378)

            隨筆檔案(329)

            鏈接

            最新隨筆

            搜索

            最新評論

            青青草国产精品久久| 青青草国产成人久久91网| 久久久午夜精品| 中文字幕久久波多野结衣av| 国产欧美久久久精品影院| 亚洲精品乱码久久久久久按摩 | 久久婷婷五月综合97色直播| 四虎影视久久久免费| 国产精品久久久久久福利69堂| 国产成人精品久久一区二区三区av | 久久久这里只有精品加勒比| 精品久久久久久成人AV| 久久WWW免费人成一看片| 97久久精品无码一区二区天美| 国产69精品久久久久观看软件 | 97精品依人久久久大香线蕉97| 久久久久国产一级毛片高清板| 99久久国语露脸精品国产| 久久久久亚洲AV成人网人人网站| 99久久综合狠狠综合久久止| 精品国际久久久久999波多野| 区亚洲欧美一级久久精品亚洲精品成人网久久久久 | 久久国产综合精品五月天| 久久精品蜜芽亚洲国产AV| 久久久精品人妻一区二区三区四 | 国产婷婷成人久久Av免费高清| 99久久国产综合精品女同图片 | 久久精品国产亚洲AV电影| 国产成人久久AV免费| 久久精品免费观看| 东方aⅴ免费观看久久av| 国产精品9999久久久久| 亚洲国产成人久久综合碰| 伊人色综合九久久天天蜜桃| MM131亚洲国产美女久久| 欧美日韩精品久久免费| 久久中文娱乐网| 久久综合丁香激情久久| 狠狠色婷婷久久一区二区| 久久99精品久久久久久水蜜桃| 色综合久久久久无码专区|