zoukankan      html  css  js  c++  java
  • 查看 各种寄存器值的 内核模块 C语言

    #include <linux/kernel.h>
    #include <linux/module.h>
    #include <linux/types.h>
    #include <linux/fs.h>
    #include <linux/errno.h>
    #include <linux/init.h>
    #include <linux/cdev.h>
    #include <linux/delay.h>
    #include <linux/poll.h>
    #include <asm/uaccess.h>
    #include <asm-arm/arch-s3c2410/gpio.h>
    #include <linux/device.h>

    #include <linux/init.h>
    #include <linux/module.h>
    #include <linux/kernel.h>
    #include <linux/sched.h>
    #include <linux/interrupt.h>
    #include <linux/irq.h>
    #include <linux/err.h>
    #include <linux/clk.h>

    #include <asm/system.h>
    #include <asm/mach-types.h>

    #include <asm/io.h>
    #include <asm/arch/map.h>
    #include <asm/plat-s3c/regs-timer.h>
    #include <asm-arm/arch-s3c2410/regs-mem.h>
    #include <asm/arch/regs-irq.h>
    #include <asm/mach/time.h>

    #include <asm/plat-s3c24xx/clock.h>
    #include <asm/plat-s3c24xx/cpu.h>
    #include <asm-arm/arch-s3c2410/irqs.h>
    #include <asm/io.h>    //__raw_writel

    #include "../hs_timer/hs_timer.h"
    #include "../ct_def/ct_def.h"

    MODULE_LICENSE("Dual BSD/GPL");
    #define DEVICE_NAME          "hstimertst222"

    struct hmi_test_dev
    {
     struct cdev cdev;
    };
    struct hmi_test_dev dev;
    static int hmi_timertest_major;
    TIMERID test_timer;
    TIMERID test_timer2;
    TIMERID test_timer3;
    TIMERID test_timer4;
    TIMERID test_timer5;
    TIMERID test_timer6;
    TIMERID test_timer7;
    /*
    S3C2410_GPF0
    S3C2410_GPF1
    S3C2410_GPF2
    S3C2410_GPF3
    S3C2410_GPF4
    S3C2410_GPF5
    S3C2410_GPF6
    S3C2410_GPG0
    S3C2410_GPF0_INP
    S3C2410_GPF1_INP
    S3C2410_GPF2_INP
    S3C2410_GPF3_INP
    S3C2410_GPF4_INP
    S3C2410_GPF5_INP
    S3C2410_GPF6_INP
    S3C2410_GPG0_INP

    S3C2410_GPE4
    S3C2410_GPE3
    S3C2410_GPE2
    S3C2410_GPE1
    S3C2410_GPE0
    S3C2410_GPB10
    S3C2410_GPB7
    S3C2410_GPB9
    S3C2410_GPF7
    S3C2410_GPB8
    S3C2410_GPE4_OUTP
    S3C2410_GPE3_OUTP
    S3C2410_GPE2_OUTP
    S3C2410_GPE1_OUTP
    S3C2410_GPE0_OUTP
    S3C2410_GPB10_OUTP
    S3C2410_GPB7_OUTP
    S3C2410_GPB9_OUTP
    S3C2410_GPF7_OUTP
    S3C2410_GPB8_OUTP
    */

    //void init_kbd_queue(void)
    //{
    // local_irq_disable();
    // currLoc = 0;
    // currLen = 0;
    // local_irq_enable();
    //}
    //s3c2410_gpio_cfgpin(S3C2410_GPF0, S3C2410_GPF0_OUTP);
    //s3c2410_gpio_pullup(S3C2410_GPF0, 1);
    //s3c2410_gpio_setpin(S3C2410_GPF0, 0);

    void test_timer_hook(INT32U parm)
    {
     static int i=0;
     if(i==0)
     {
      s3c2410_gpio_setpin(S3C2410_GPG8, 1);
      i = 1;
     }
     else
     {
      s3c2410_gpio_setpin(S3C2410_GPG8, 0);
      i =0;
     }
     Start_HS_timer_ignore_irqs (test_timer);
    }

    void test_timer_hook2(INT32U parm)
    {
     static int i=0;
     if(i==0)
     {
      s3c2410_gpio_setpin(S3C2410_GPB1, 1);
      i = 1;
     }
     else
     {
      s3c2410_gpio_setpin(S3C2410_GPB1, 0);
      i =0;
     }
     udelay(10);
     Start_HS_timer_ignore_irqs (test_timer2);
    }

    void test_timer_hook3(INT32U parm)
    {
     Start_HS_timer_ignore_irqs (test_timer3);
    }


    int using_flag = 0;
    static int timertest_open (struct inode* inode, struct file* file)
    {
     if (!try_module_get(THIS_MODULE))
            return -EBUSY;
     return SUCCESS;
    }

    static int  timertest_release (struct inode* inode, struct file* file)
    {
     
     module_put(THIS_MODULE);
     return SUCCESS;
    }

    static const struct file_operations hmi_hstest_fops = {
     .owner = THIS_MODULE,
     .open = timertest_open,
     .release = timertest_release,
    };

    void hmi_hstimertst_setup_cdev(dev_t devno)
    {
     int err;
     cdev_init(&dev.cdev, &hmi_hstest_fops);
     dev.cdev.owner = THIS_MODULE;
     dev.cdev.ops = &hmi_hstest_fops;
     err = cdev_add(&dev.cdev,devno,1);
     if(err)
      printk(KERN_NOTICE "Error %d adding hmi_buttons ",err);
    }

    struct class *timertest_class;
    struct device* timertest_device;

    static int __init timertest_init(void)
    {
     int ret;
     dev_t devno;
     struct clk * clk_p;
     unsigned long pclk;

     unsigned long tcon;
    // unsigned long tcnt;
     unsigned long tcfg1;
     unsigned long tcfg0;
     unsigned int register_buf;
      
     clk_p = clk_get(NULL, "pclk");
     pclk = clk_get_rate(clk_p);
     printk("pclk : %ld \n",pclk);

     tcon  = __raw_readl(S3C2410_TCON);
     tcfg1  = __raw_readl(S3C2410_TCFG1);
     tcfg0  = __raw_readl(S3C2410_TCFG0);
     printk("S3C2410_TCFG0 : %x  S3C2410_TCFG1 : %x  TCON: %x \n",tcfg0,tcfg1,tcon);
     register_buf=__raw_readl(S3C2410_INTMOD);
     printk("S3C2410_INTMOD : %x\n",register_buf);

     register_buf=__raw_readl(S3C2410_INTMSK);
    printk("S3C2410_INTMSK : %x\n",register_buf);
     register_buf=__raw_readl(S3C2410_INTSUBMSK);
    printk("S3C2410_INTSUBMSK : %x\n",register_buf);
     register_buf=__raw_readl(S3C2410_TCNTO(4) );
    printk("S3C2410_TCNTO: %x\n",register_buf);
     register_buf=__raw_readl( S3C2410_TCNTB(4) );
    printk(" S3C2410_TCNTB(4): %x\n",register_buf);


     register_buf=__raw_readl( S3C2410_BANKCON0);
    printk(" S3C2410_BANKCON0: %x\n",register_buf);
     register_buf=__raw_readl( S3C2410_BANKCON1 );
    printk(" S3C2410_BANKCON1: %x\n",register_buf);
     register_buf=__raw_readl( S3C2410_BANKCON2 );
    printk(" S3C2410_BANKCON2: %x\n",register_buf);
     register_buf=__raw_readl( S3C2410_BANKCON3);
    printk(" S3C2410_BANKCON3: %x\n",register_buf);
     register_buf=__raw_readl( S3C2410_BANKCON4 );
    printk(" S3C2410_BANKCON4: %x\n",register_buf);
     register_buf=__raw_readl( S3C2410_BANKCON5 );
    printk(" S3C2410_BANKCON5: %x\n",register_buf);
     register_buf=__raw_readl( S3C2410_BANKCON6 );
    printk(" S3C2410_BANKCON6: %x\n",register_buf);
     register_buf=__raw_readl( S3C2410_BANKCON7 );
    printk(" S3C2410_BANKCON7: %x\n",register_buf);
     register_buf=__raw_readl( S3C2410_BWSCON);
    printk(" S3C2410_BWSCON: %x\n",register_buf);
     register_buf=__raw_readl( S3C2410_REFRESH);
    printk(" S3C2410_REFRESH: %x\n",register_buf);
     register_buf=__raw_readl(S3C2410_BANKSIZE);
    printk(" S3C2410_BANKSIZE: %x\n",register_buf);
     register_buf = 0xb2;
     __raw_writel(register_buf,S3C2410_BANKSIZE);
     register_buf=__raw_readl( S3C2410_MRSRB6);
    printk(" S3C2410_MRSRB6: %x\n",register_buf);
     register_buf=__raw_readl(S3C2410_MRSRB7);
    printk(" S3C2410_MRSRB7: %x\n",register_buf);


     register_buf=__raw_readl(S3C2410_PRIORITY);
     printk("S3C2410_PRIORITY : %x\n",register_buf);
     //register_buf = 0x12807f;
     //__raw_writel(register_buf,S3C2410_PRIORITY);

     ret = alloc_chrdev_region(&devno,0,1,DEVICE_NAME); //申请设备号
     if(ret < 0)
     {
      return ret;
     }
     hmi_timertest_major = MAJOR(devno);
     hmi_hstimertst_setup_cdev(devno);

     timertest_class = class_create(THIS_MODULE, DEVICE_NAME);
       if(IS_ERR(timertest_class))
     {
      cdev_del(&dev.cdev); //删除cdev结构体和cdev设备
      unregister_chrdev_region(MKDEV(hmi_timertest_major,0),1);//释放设备号
         printk("Err: failed in creating class.\n");
         return -1;
       }
     timertest_device = device_create(timertest_class,NULL,devno,DEVICE_NAME);
     if (IS_ERR(timertest_device))
     {
      cdev_del(&dev.cdev); //删除cdev结构体和cdev设备
      unregister_chrdev_region(MKDEV(hmi_timertest_major,0),1);//释放设备号
      printk(KERN_ERR "buttons_add: device_create failed\n");
      return -1;
     }
    //  test_timer = Register_HS_timer (1000, test_timer_hook, 0, 0);
     if (test_timer == NULL_TIMER_ID)
     {
      cdev_del(&dev.cdev); //删除cdev结构体和cdev设备
      unregister_chrdev_region(MKDEV(hmi_timertest_major,0),1);//释放设备号
      return -1;
     }
    //  test_timer2 = Register_HS_timer (10000, test_timer_hook2, 0, 0);
     if (test_timer2 == NULL_TIMER_ID)
     {
      printk("test_timer2 err !!");
      return -1;
     }
    //  test_timer3 = Register_HS_timer (10000, test_timer_hook3, 0, 0);
     if (test_timer3 == NULL_TIMER_ID)
     {
      printk("test_timer3 err !!");
      return -1;
     }
    //test_timer4 = Register_HS_timer (10000, test_timer_hook3, 0, 0);
    //test_timer5 = Register_HS_timer (10000, test_timer_hook3, 0, 0);
    //test_timer6 = Register_HS_timer (10000, test_timer_hook3, 0, 0);
    //test_timer7 = Register_HS_timer (10000, test_timer_hook3, 0, 0);
    //SetTicks_HS_timer (test_timer4, 1000);
    //SetTicks_HS_timer (test_timer5, 100);
    //SetTicks_HS_timer (test_timer6,150);
    //SetTicks_HS_timer (test_timer7, 300);
     s3c2410_gpio_cfgpin(S3C2410_GPG8, S3C2410_GPG8_OUTP);
     s3c2410_gpio_pullup(S3C2410_GPG8, 1);
     s3c2410_gpio_setpin(S3C2410_GPG8, 0);
      s3c2410_gpio_cfgpin(S3C2410_GPB1, S3C2410_GPB1_OUTP);
     s3c2410_gpio_pullup(S3C2410_GPB1, 1);
     s3c2410_gpio_setpin(S3C2410_GPB1, 0);
    // SetTicks_HS_timer (test_timer, 100/* 1000000 /187500*/);
    // Start_HS_timer (test_timer);
    // SetTicks_HS_timer (test_timer2, 50 * 1000000 /187500);
    // Start_HS_timer (test_timer2);
    // SetTicks_HS_timer (test_timer3, 10* 1000000 /187500);
    // Start_HS_timer (test_timer3);

    //Start_HS_timer (test_timer4);
    //Start_HS_timer (test_timer5);
    //Start_HS_timer (test_timer6);
    //Start_HS_timer (test_timer7);
     return 0;
    }

    static void __exit timertest_exit(void)
    {
     device_destroy(timertest_class, MKDEV(hmi_timertest_major, 0));
       class_destroy(timertest_class);
    // UnRegister_HS_timer(test_timer);
    // UnRegister_HS_timer(test_timer3);
    // UnRegister_HS_timer(test_timer2);
     cdev_del(&dev.cdev); //删除cdev结构体和cdev设备
     unregister_chrdev_region(MKDEV(hmi_timertest_major,0),1);//释放设备号
    }

    module_init(timertest_init);
    module_exit(timertest_exit);

  • 相关阅读:
    叉姐的魔法训练(第十课)---- 幽默大师卫冕战
    叉姐的魔法训练(第⑨课)---- 幽默大师职业赛
    叉姐的魔法训练(第八课)---- 幽默术
    叉姐的魔法训练(第七课)---- 在沙漠中的长途旅行
    叉姐的魔法训练(第六课)---- 暴雨术入门
    叉姐的魔法训练(第五课)---- 如何成为一名合格的小学生
    叉姐的魔法训练(第四课)---- 风系魔法的基本要领
    叉姐的魔法训练(第三课)---- 火球术入门
    叉姐的魔法训练(第二课)---- 冰系魔法入门
    叉姐的魔法训练(第一课)---- 初级魔法练习
  • 原文地址:https://www.cnblogs.com/leaven/p/1798776.html
Copyright © 2011-2022 走看看