2013-10-08 实验之定时器控制Led等闪烁
2013-10-08 15:20
399 查看
实验描述:定时器控制Led等1s闪烁
注意事项:定时器的添加,更新,删除
内核版本:Linux 2.6.38
开发板: Mini 6410
驱动程序
注意事项:定时器的添加,更新,删除
内核版本:Linux 2.6.38
开发板: Mini 6410
驱动程序
#include <linux/init.h> #include <linux/module.h> #include <linux/device.h> #include <linux/kdev_t.h> #include <linux/timer.h> #include <asm/io.h> #include <linux/fs.h> /* Kernel Version: Linux 2.6.38 Arm Version: Mini 6410 */ #define MyPrintk printk static struct timer_list timer_leds; static dev_t Leds_Major ; static char * DEVICE_NAME = "TimerLeds"; volatile unsigned long *gpkcon0 = NULL; volatile unsigned long *gpkdat = NULL; static int current_state = 1; static struct class *leds_class; void leds_ctl(unsigned long value) { if( current_state == 1){ *gpkdat &= ~((1<<4) | (1<<5) | (1<<6) | (1<<7)) ; }else{ *gpkdat |= (1<<4) | (1<<5) | (1<<6) | (1<<7) ; } timer_leds.data++; MyPrintk (KERN_EMERG "timer count: %lu ,value:%lu\n", timer_leds.data, value); current_state = ~current_state; if (timer_leds.data <= 10 ){ mod_timer(&timer_leds, jiffies + HZ); } } static struct file_operations s3c64XX_leds_fops = { .owner = THIS_MODULE, }; static int myleds_init(void) { Leds_Major = register_chrdev(Leds_Major,DEVICE_NAME , &s3c64XX_leds_fops); if(Leds_Major < 0){ MyPrintk (KERN_EMERG "Sorry, Can not register the leds device!\n"); } MyPrintk (KERN_EMERG " Register the timer leds device\n"); leds_class = class_create(THIS_MODULE, "TimerLeds"); device_create(leds_class, NULL , MKDEV(Leds_Major, 0), NULL, "TimerLeds"); gpkcon0 = (volatile unsigned long *)ioremap(0x7F008800,12); gpkdat = gpkcon0 + 2; init_timer(&timer_leds); timer_leds.expires = jiffies + HZ; timer_leds.data = 0; timer_leds.function = leds_ctl; *gpkcon0 &= ~( (0xF<<4*4) | (0xF<<5*4) | (0xF<<6*4) | (0xF<<7*4)); *gpkcon0 |= ( (0x1<<4*4) |(0x1<<5*4) | (0x1<<6*4) | (0x1<<7*4)); *gpkdat |= (1<<4) | (1<<5) | (1<<6) | (1<<7) ; add_timer(&timer_leds); MyPrintk (KERN_EMERG "Timer Start\n"); return 0; } static void myleds_exit(void) { del_timer(&timer_leds); unregister_chrdev(Leds_Major, DEVICE_NAME); device_destroy(leds_class, MKDEV(Leds_Major, 0)); class_destroy(leds_class); iounmap(gpkcon0); MyPrintk (KERN_EMERG "Timer Leds Linux Byebye\n"); } module_init(myleds_init); module_exit(myleds_exit); MODULE_LICENSE("GPL");
相关文章推荐
- Arduino 实验2 - 控制LED闪烁
- CC2530学习路线-基础实验-定时器控制LED灯亮灭(3)
- 4、定时器T1通过查询方式控制LED1周期性闪烁(轮训方式)
- 定时器 T1 通过查询方式控制 LED1 周期性闪烁
- 定时器0控制LED的闪烁时间;计数器1来控制数码管的显示
- 用定时器T0的中断控制8位LED闪烁
- 用定时器T0的中断控制8位LED闪烁
- 【iCore1S 双核心板_ARM】例程七:通用定时器实验——定时点亮LED
- WINCE 定时器0控制LED驱动源码
- 定时器查询法和定时器中断法实现LED闪烁
- (一)GPIO 编程实验 LED 流水灯控制
- 1:51单片机LED闪烁实验
- 嵌入式成长轨迹51 【Zigbee项目】【CC2430基础实验】【在PC用串口控制LED】
- arm7 力天电子lpc2148 GPIO之二单路LED控制实验
- Zigbee之旅(二):第一个CC2430程序——LED灯闪烁实验(转)
- 1.3.第二个实验—让LED闪烁
- AndroidThings学习笔记--pwm控制Led闪烁
- LPC2124--GPIO按键控制LED灯的闪烁
- BeagleBone Black板第四课:简单LED控制实验
- 树莓派控制led灯闪烁