乡下人产国偷v产偷v自拍,国产午夜片在线观看,婷婷成人亚洲综合国产麻豆,久久综合给合久久狠狠狠9

  • <output id="e9wm2"></output>
    <s id="e9wm2"><nobr id="e9wm2"><ins id="e9wm2"></ins></nobr></s>

    • 分享

      tq2440 time0 led 定時(shí)器控制led閃爍 驅(qū)動(dòng)

       漢江秋月夜 2012-10-31

      tq2440 time0 led 定時(shí)器控制led閃爍 驅(qū)動(dòng)  

      2012-07-15 13:15:46|  分類: ARM |字號(hào) 訂閱

      /*************************************************************
      基于tq2440開發(fā)板,內(nèi)核2.6.30

      功能
      能實(shí)現(xiàn)定時(shí)器0 的中斷函數(shù)。
      定時(shí)器的中斷讓led 閃爍

      2012年7月15日13:14:02

      **************************************************************/

      #include <linux/miscdevice.h>
      #include <linux/delay.h>
      #include <linux/kernel.h>
      #include <linux/module.h>
      #include <linux/init.h>
      #include <linux/mm.h>
      #include <linux/fs.h>
      #include <linux/types.h>
      #include <linux/delay.h>
      #include <linux/moduleparam.h>
      #include <linux/slab.h>
      #include <linux/errno.h>
      #include <linux/ioctl.h>
      #include <linux/cdev.h>
      #include <linux/string.h>
      #include <linux/list.h>
      #include <linux/pci.h>
      #include <linux/poll.h>
      #include <linux/interrupt.h>
      #include <linux/platform_device.h>
      #include <linux/irq.h>
      #include <linux/interrupt.h>
      #include <linux/clk.h>

      #include <mach/regs-gpio.h>
      #include <mach/hardware.h>

      #include <asm/irq.h>
      #include <asm/uaccess.h>
      #include <asm/atomic.h>
      #include <asm/unistd.h>

      #include <plat/regs-timer.h>

      #define DEVICE_NAME "driver_time"


      volatile unsigned long *gpbcon = NULL;
      volatile unsigned long *gpbdat = NULL;

      volatile unsigned long *tcfg0 = NULL; //用來設(shè)置預(yù)分頻
      volatile unsigned long *tcfg1 = NULL; //用來設(shè)置分頻
      volatile unsigned long *tcon  = NULL; //定時(shí)器控制器
      volatile unsigned long *tcntb0 = NULL; //計(jì)數(shù)緩沖寄存器
      volatile unsigned long *tcmpb0 = NULL; //比較緩沖寄存器
      volatile unsigned long *tcnto0 = NULL; //計(jì)數(shù)觀察寄存器


      volatile unsigned long *gpfcon = NULL;
      volatile unsigned long *gpfdat = NULL;
      volatile unsigned long *srcpnd = NULL;
      volatile unsigned long *intmask = NULL;
      volatile unsigned long *intpnd = NULL;
      volatile unsigned long *intoffset = NULL;



      static irqreturn_t irq_interrupt(int irq, int dev_id)
      {
      //*gpbcon &=~(3<<0*2);
      //*gpbcon |= (2<<0*2); //設(shè)置b0 為 tout0
      static unsigned int irq_count;
      irq_count++;
      printk("in irq_interrupt   %d\n",irq_count);

      if(irq_count%2)
      *gpbdat &= ~((1<<5) );
      else
      *gpbdat |= ((1<<5) );
      return IRQ_RETVAL(IRQ_HANDLED);
      }

      // ------------------- OPEN ------------------------
      ssize_t drive_open (struct inode * inode ,struct file * file)
      {
      *gpbcon &= ~((0x3<<(5*2)) | (0x3<<(6*2)) | (0x3<<(7*2)) | (0x3<<(8*2)));//清零
      *gpbcon |=   ((0x1<<(5*2)) | (0x1<<(6*2)) | (0x1<<(7*2)) | (0x1<<(8*2)));//設(shè)置成輸出
      request_irq(IRQ_TIMER0, irq_interrupt, IRQ_TYPE_EDGE_FALLING, "TIME0", NULL);
      printk("-----------------drive open ok----------------\n");
      return 0;


      }


      // ------------------- RELEASE/CLOSE ---------------
      ssize_t drive_release (struct inode  * inode ,struct file * file)
      {
      free_irq(IRQ_TIMER0, NULL);
      printk("-----------------drive close ok----------------\n");
      return 0;
      }


      // ------------------- READ ------------------------
      ssize_t drive_read (struct file * file ,char * buf, size_t count, loff_t * f_ops)
      {
      printk("-----------------drive read ok----------------\n");
      //copy_to_user( buf,(const void *)press_cnt,sizeof(press_cnt) );
      return 0;
      }


      // ------------------- WRITE -----------------------
      ssize_t drive_write (struct file * file ,const char * buf, size_t count, loff_t * f_ops)
      {
      printk("-----------------drive write ok----------------\n");
      return 0;
      }

      // ------------------- IOCTL -----------------------
      ssize_t drive_ioctl (struct inode * inode ,struct file * file, unsigned int cmd, unsigned long arg)
      {
      struct clk *clk_p;
      unsigned int pclk;
      unsigned int tcnt;
      printk("-----------------drive ioctl ok----------------\n");

      //定時(shí)器時(shí)鐘頻率=pclk /( 預(yù)分頻器的值+1) / 分頻器
      //62.5k
      *tcfg0 &= ~0xff; //定時(shí)器0預(yù)分配清零
      *tcfg0 |=(50-1); //預(yù)分頻 50

      *tcfg1 &= ~0xf; //定時(shí)器0 mux 輸入分頻清零
      *tcfg1 |=3; //mux 分頻 16

      clk_p = clk_get(NULL, "pclk"); 
             pclk = clk_get_rate(clk_p);
      tcnt = (pclk/50/16)/10;  
      printk("pclk =  %d\n",pclk);
      printk("tcnt =  %d\n",tcnt);
      *tcntb0 &=0x0000; //16位寄存器
      *tcmpb0 &=0x0000;
      *tcntb0 |= 1000;
      *tcmpb0|=500;

      //*tcon &=0x0;
      // printk("tcon=%d\n",*tcon);
      printk("tcntb0=%d\n",*tcntb0);
      printk("tcmpb0=%d\n",*tcmpb0);
       
      *tcon &= ~0x1f; //清零
      // printk("tcon=%d\n",*tcon);
      msleep(10);
      //第一次必須手動(dòng)更新
             *tcon |= 0xb;  //關(guān)閉死區(qū)、自動(dòng)重載、關(guān)反相器、手動(dòng)更新TCNTB0&TCMPB0、啟動(dòng)定時(shí)器0
      //1011
      //printk("tcon=%d\n",*tcon);
      msleep(10);
      *tcon &= ~2;  //清除定時(shí)器0的手動(dòng)更新位
       
      //printk("tcon=%d\n",*tcon);
      printk("tcfg0=%d\n",*tcfg0);
      printk("tcfg1=%d\n",*tcfg1);
      printk("tcntb0=%d\n",*tcntb0);
      printk("tcmpb0=%d\n",*tcmpb0);
      printk("tcon=%d\n",*tcon);
       
      return 0;
      }


      // -------------------------------------------------

      static struct file_operations drive_ops ={

      .owner = THIS_MODULE,
      .open   = drive_open,
      .read   = drive_read,
      .write   = drive_write,
      .ioctl   = drive_ioctl,
      .release = drive_release,
      };


      static struct miscdevice misc = {
      .minor = MISC_DYNAMIC_MINOR,
      .name = DEVICE_NAME,
      .fops = &drive_ops,
      };


      static int __init init_drive(void)  
      {
      int ret;
      ret = misc_register(&misc);

      gpbcon = (volatile unsigned long *)ioremap(0x56000010,32);
      gpbdat = (volatile unsigned long *)ioremap(0x56000014, 32);

      tcfg0    = (volatile unsigned long *)ioremap(0x51000000, 4);
      tcfg1    = (volatile unsigned long *)ioremap(0x51000004, 4);
      tcon     = (volatile unsigned long *)ioremap(0x51000008, 4);
      tcntb0  = (volatile unsigned long *)ioremap(0x5100000c, 4);
      tcmpb0 = (volatile unsigned long *)ioremap(0x51000010, 4);
      tcnto0  = (volatile unsigned long *)ioremap(0x51000014, 4);

      gpfcon = (volatile unsigned long *)ioremap(0x56000050, 4);
      gpfdat = (volatile unsigned long *)ioremap(0x56000054, 4);
      srcpnd = (volatile unsigned long *)ioremap(0x4a000000, 4);
      intmask= (volatile unsigned long *)ioremap(0x4a000008, 4);
      intpnd  = (volatile unsigned long *)ioremap(0x4a000010, 4);
      intoffset=(volatile unsigned long *)ioremap(0x4a000014, 4);
      printk("-----------------drive button init ok----------------\n");
      return 0;
      }

      static void __exit exit_drive(void)
      {
      *tcon &=~1;
      misc_deregister(&misc);
      printk("-----------------drive button exit ok----------------\n");
      }



      module_init(init_drive);
      module_exit(exit_drive);
      MODULE_LICENSE("GPL");



      //-----------------------------應(yīng)用程序----------------------------------------------


      #include <stdio.h>
      #include <string.h>
      #include <stdlib.h>

      #include <fcntl.h>      // open() close()
      #include <unistd.h>     // read() write()

      #define DEVICE_NAME "/dev/driver_time"

      //------------------------------------- main ---------------------------------------------
      int main(int argc, char **argv)
      {
      int fd,ret;



             fd = open(DEVICE_NAME, O_RDWR);
       
      if (fd == -1)
      {
      printf("can't open device mknod %s c zhu ci \n",DEVICE_NAME);
      return 0;
      }
      ioctl(fd, 1);
      while(1)
      {

      ;
      }


              // close 
      ret = close(fd);

              return 0;
      }// end main




      分享到:        
      閱讀(41)| 評(píng)論(0)| 轉(zhuǎn)載 (0) |舉報(bào)

        本站是提供個(gè)人知識(shí)管理的網(wǎng)絡(luò)存儲(chǔ)空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點(diǎn)。請(qǐng)注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購買等信息,謹(jǐn)防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)點(diǎn)擊一鍵舉報(bào)。
        轉(zhuǎn)藏 分享 獻(xiàn)花(0

        0條評(píng)論

        發(fā)表

        請(qǐng)遵守用戶 評(píng)論公約

        類似文章 更多