Character device led-timer (timer)

Source: Internet
Author: User

Led_timer.c

# Include <Linux/fs. h>
# Include <Linux/module. h>
# Include <Linux/errno. h>
# Include <Linux/kernel. h>
# Include <Linux/init. h>
# Include <Linux/cdev. h>
# Include <Linux/ioport. h>
# Include <Linux/PCI. h>
# Include <ASM/uaccess. h>
# Include <ASM/IO. h>

Static volatile unsigned long * gpfcon; // = (volatile unsigned long x) 0x56000050;
Static volatile unsigned long * gpfdat; // = (volatile unsigned long x) 0x56000054;

Static struct timer_list led_timer;

VoidLed_timer_function(Unsigned long data)
{
Static int cur_val = 0;
 
If (cur_val)
{
Cur_val = 0;
* Gpfdat & = ~ (1 <4 );
}
Else
{
Cur_val = 1;
* Gpfdat | = (1 <4 );
}

 Mod_timer(& Led_timer, jiffies + 50);/* 50*10 Ms = 500 ms = 0.5 s */
}

Int led_timer_init (void)
{
Gpfcon = ioremap (0x56000050, 8);/* obtain the virtual address */
Gpfdat = gpfcon + 1;

* Gpfcon & = ~ (0x3 <(4*2 ));
* Gpfcon | = (0x1 <(4*2 ));;

Init_timer (& led_timer );
Led_timer.function = led_timer_function;
Led_timer.expires = jiffies + 50;
Add_timer (& led_timer );
}

Void led_timer_exit (void)
{
 Del_timer(& Led_timer );
Iounmap (gpfcon );
}

Module_init (led_timer_init );
Module_exit (led_timer_exit );

Module_license ("GPL ");

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.