在线看毛片网站电影-亚洲国产欧美日韩精品一区二区三区,国产欧美乱夫不卡无乱码,国产精品欧美久久久天天影视,精品一区二区三区视频在线观看,亚洲国产精品人成乱码天天看,日韩久久久一区,91精品国产91免费

<menu id="6qfwx"><li id="6qfwx"></li></menu>
    1. <menu id="6qfwx"><dl id="6qfwx"></dl></menu>

      <label id="6qfwx"><ol id="6qfwx"></ol></label><menu id="6qfwx"></menu><object id="6qfwx"><strike id="6qfwx"><noscript id="6qfwx"></noscript></strike></object>
        1. <center id="6qfwx"><dl id="6qfwx"></dl></center>

            新聞中心

            EEPW首頁(yè) > 嵌入式系統(tǒng) > 設(shè)計(jì)應(yīng)用 > 基于AT91RM9200的I/O驅(qū)動(dòng)程序(linux)

            基于AT91RM9200的I/O驅(qū)動(dòng)程序(linux)

            作者: 時(shí)間:2016-11-13 來(lái)源:網(wǎng)絡(luò) 收藏
            #include <linux/config.h>

            #include
            #include
            #include
            #include
            #include
            #include
            #include
            #include
            #include
            #include
            #include
            #include
            #include
            #include
            #include
            #include /* get ioctl stuff for gpio */
            //#include "at91_gpio.h"

            本文引用地址:http://www.biyoush.com/article/201611/316434.htm

            #defineDRIVER_NAME"key_led" //device name
            #defineDRIVER_VERSION"1.00" //driver version
            #defineDRIVER_MAJOR33

            static devfs_handle_t devfs_handle, devfs_keyled_dir;
            static ssize_t io_read(struct file*, char*, size_t, loff_t* );
            static ssize_t io_write(struct file*, const char*, size_t, loff_t* );
            //static int can0_ioctl(struct inode *, struct file *, unsigned int, unsigned long);
            static int io_open(struct inode*,struct file*);
            static int io_release(struct inode*,struct file*);
            struct file_operations io_fops = {
            //owner: THIS_MODULE,
            //ioctl: gpio_ioctl,
            write:io_write,
            read: io_read,
            open: io_open,
            release: io_release,
            };

            void delay(int count)
            {
            int temp,i;
            for(i=0;ifor(temp=0;temp<10000;temp++)
            {
            ;
            }
            }

            void io_int(void)
            {
            unsigned char temp;
            AT91_SYS->PIOA_PER =AT91C_PIO_PA17|AT91C_PIO_PA18|AT91C_PIO_PA19|AT91C_PIO_PA20|AT91C_PIO_PA21|AT91C_PIO_PA22;//enable the peripheral control
            AT91_SYS->PIOA_OER=AT91C_PIO_PA17|AT91C_PIO_PA18|AT91C_PIO_PA19|AT91C_PIO_PA20|AT91C_PIO_PA21|AT91C_PIO_PA22;//output enable
            AT91_SYS->PIOA_IFDR=AT91C_PIO_PA17|AT91C_PIO_PA18|AT91C_PIO_PA19|AT91C_PIO_PA20|AT91C_PIO_PA21|AT91C_PIO_PA22;
            AT91_SYS->PIOA_CODR=AT91C_PIO_PA17|AT91C_PIO_PA18|AT91C_PIO_PA19|AT91C_PIO_PA20|AT91C_PIO_PA21|AT91C_PIO_PA22;
            AT91_SYS->PIOA_IDR=AT91C_PIO_PA17|AT91C_PIO_PA18|AT91C_PIO_PA19|AT91C_PIO_PA20|AT91C_PIO_PA21|AT91C_PIO_PA22;//disable the interrupt
            AT91_SYS->PIOA_MDER=AT91C_PIO_PA17|AT91C_PIO_PA18|AT91C_PIO_PA19|AT91C_PIO_PA20|AT91C_PIO_PA21|AT91C_PIO_PA22;
            AT91_SYS->PIOA_PPUER=AT91C_PIO_PA17|AT91C_PIO_PA18|AT91C_PIO_PA19|AT91C_PIO_PA20|AT91C_PIO_PA21|AT91C_PIO_PA22;
            AT91_SYS->PIOA_OWER=AT91C_PIO_PA17|AT91C_PIO_PA18|AT91C_PIO_PA19|AT91C_PIO_PA20|AT91C_PIO_PA21|AT91C_PIO_PA22;//enable write the PIO_ODSR for PA22
            for(temp=0;temp<5;temp++)
            {
            AT91_SYS->PIOA_ODSR=0;//PA22 should goto low now
            delay(1000);
            AT91_SYS->PIOA_ODSR=AT91C_PIO_PA17|AT91C_PIO_PA18|AT91C_PIO_PA19|AT91C_PIO_PA20|AT91C_PIO_PA21|AT91C_PIO_PA22;//PA22 should be high now
            delay(1000);
            }
            printk("Init the LED over,and begine to init the keyn");
            //////////////////////////init the led over,begine to init the KEY
            AT91_SYS->PMC_PCER=0xffffffff;
            AT91_SYS->PIOB_PER=0xfffe|AT91C_PIO_PB16|AT91C_PIO_PB17|AT91C_PIO_PB18|AT91C_PIO_PB28|AT91C_PIO_PB29;//enable the peripheral control
            AT91_SYS->PIOB_ODR=0xfffe|AT91C_PIO_PB16|AT91C_PIO_PB17|AT91C_PIO_PB18|AT91C_PIO_PB28|AT91C_PIO_PB29;//disable the output
            AT91_SYS->PIOB_IFER=0xfffe|AT91C_PIO_PB16|AT91C_PIO_PB17|AT91C_PIO_PB18|AT91C_PIO_PB28|AT91C_PIO_PB29;//enable the filter
            AT91_SYS->PIOB_CODR=0xfffe|AT91C_PIO_PB16|AT91C_PIO_PB17|AT91C_PIO_PB18|AT91C_PIO_PB28|AT91C_PIO_PB29;//clean the output reg
            AT91_SYS->PIOB_IDR=0xfffe|AT91C_PIO_PB16|AT91C_PIO_PB17|AT91C_PIO_PB18|AT91C_PIO_PB28|AT91C_PIO_PB29;//disable the interrupt
            AT91_SYS->PIOB_MDDR=0xfffe|AT91C_PIO_PB16|AT91C_PIO_PB17|AT91C_PIO_PB18|AT91C_PIO_PB28|AT91C_PIO_PB29;//enable the multidriver
            AT91_SYS->PIOB_PPUDR=0xfffe|AT91C_PIO_PB16|AT91C_PIO_PB17|AT91C_PIO_PB18|AT91C_PIO_PB28|AT91C_PIO_PB29;//disable the pullup
            AT91_SYS->PIOB_OWDR=0xfffe|AT91C_PIO_PB16|AT91C_PIO_PB17|AT91C_PIO_PB18|AT91C_PIO_PB28|AT91C_PIO_PB29;//disable the output write


            }
            void keyled_init(void)
            {
            if(register_chrdev(DRIVER_MAJOR,DRIVER_NAME,&io_fops))
            {printk("Can not register keyled driver as major device 33n");
            return;
            }
            else
            printk("nRegisterd the keyled driver as major device 33 successn");
            //devfs_keyled_dir = devfs_mk_dir(NULL, DRIVER_NAME, NULL);
            devfs_handle = devfs_register(devfs_keyled_dir, DRIVER_NAME,
            DEVFS_FL_DEFAULT,
            DRIVER_MAJOR, 0, S_IFCHR | S_IRUSR | S_IWUSR,
            &io_fops, NULL);

            io_int();
            printk("nKeyled driver V0.1 write by Simon Liun");
            return;
            }

            static int io_open(struct inode* inode,struct file* file)
            {
            MOD_INC_USE_COUNT;
            return 0;
            }

            static int io_release(struct inode* inode,struct file* file)
            {
            MOD_DEC_USE_COUNT;
            return 0;
            }

            static ssize_t io_read(struct file * file ,char * buff,size_t count,loff_t * offp)
            {
            int i;
            unsigned long temp,key_temp;
            unsigned char key_data[4];
            temp=AT91_SYS->PIOB_PDSR;
            //printk("%dn",temp);
            key_temp=temp;
            //temp=temp >>13;
            key_data[0]=(unsigned char)(key_temp&0xfe);
            temp=temp>>8;
            key_temp=temp;
            key_data[1]=(unsigned char)(key_temp& 0xff);
            temp=temp>>8;
            key_temp=temp;
            key_data[2]=(unsigned char)(key_temp& 0x7);
            temp=temp>>8;
            key_temp=temp;
            key_data[3]=(unsigned char)(key_temp& 0x30);
            copy_to_user(buff,&key_data[0],4);
            //printk("nthe key data is n");
            //for(i=0;i<4;i++)
            //printk("%4d",key_data[i]);
            return 4;
            //return 0;
            }

            ssize_t io_write(struct file* file, const char* ch, size_t count, loff_t* offp )
            {
            unsigned char led_data;
            unsigned long temp;
            copy_from_user(&led_data,ch,1);
            temp=led_data;
            temp=(temp<<17);
            temp=(temp &(AT91C_PIO_PA17|AT91C_PIO_PA18|AT91C_PIO_PA19|AT91C_PIO_PA20|AT91C_PIO_PA21|AT91C_PIO_PA22));
            AT91_SYS->PIOA_ODSR= temp;
            return 1;
            }



            評(píng)論


            技術(shù)專(zhuān)區(qū)

            關(guān)閉