📄 run_led_timer.c
字号:
/*********************************************************************** * * (C) Copyright 2004,12 * * Himai tech * All rights left. * * * a simple Device Driver for HM901ESP led device * * Can be loaded as module * * $Id: led.c,v 1.1 2004/12/15 $ * ***********************************************************************//* * Standard in kernel modules */#include <linux/kernel.h> /* We're doing kernel work */#include <linux/module.h> /* Specifically, a module */#include <asm/uaccess.h> /* for put_user */#include <linux/init.h> /* for __initfunc */#include <linux/sched.h>#include <linux/fs.h>#include <linux/interrupt.h> #include <linux/timer.h>#include <asm/io.h> /* for ioremap */#include <asm/arch/hardware.h> /* atmel RM9200 */ #include <asm/arch/pio.h>//#undef DEBUG#define DEBUG 1#ifdef DEBUG# define debugk(fmt,args...) printk(fmt ,##args)#else# define debugk(fmt,args...)#endif/* * Deal with CONFIG_MODVERSIONS */#if CONFIG_MODVERSIONS==1/* # define MODVERSIONS */# include <linux/modversions.h>#endifMODULE_LICENSE("GPL");#ifndef KERNEL_VERSION# define KERNEL_VERSION(a,b,c) ((a)*65536+(b)*256+(c))#endif#define SUCCESS 0#define TIMER_INTERVAL 300 /* timer interval ms *//* see ATMEL RM9200 datasheet */#define AT91C_BASE_RUN 0x80000000 /* run_led base address */#define RUN_MEM_LEN 0x08 /* * Prototypes */static int __init runled_init (void );struct timer_list runled_timer;static int runled_data; /*1: light 0:dis-light */static void *run_base;void runled_light(void* data){ if(runled_data == 1) /*turn on led*/ { writeb (0xfe, run_base); runled_data = 0; } else /*turn off led*/ { writeb (0xff, run_base); runled_data = 1; } init_timer(&runled_timer); runled_timer.function = (void (*)(unsigned long))runled_light; runled_timer.data = (unsigned long)&runled_data; runled_timer.expires = TIMER_INTERVAL * HZ /1000; mod_timer(&runled_timer, jiffies + TIMER_INTERVAL * HZ/1000); }/* * Initialize the driver - Register the character device */static int __init runled_init(void){ /* get the remmapped run_led port base address register */ run_base = ioremap_nocache(AT91C_BASE_RUN, RUN_MEM_LEN); runled_data = 1; init_timer(&runled_timer); runled_timer.function = (void(*)(unsigned long))runled_light; runled_timer.data = (unsigned long)&runled_data; runled_timer.expires = jiffies + TIMER_INTERVAL * HZ /1000; add_timer(&runled_timer); return 0;}/****************************** **** Module Declarations ***** **************************** */#ifdef MODULE/* * Cleanup - unregister the appropriate file from /proc */static void __exit cleanup_runled_module (void){ iounmap (run_base); del_timer(&runled_timer); return;}module_init(runled_init);module_exit(cleanup_runled_module);MODULE_AUTHOR("Himai");MODULE_DESCRIPTION("runled driver for HM901ESP");#endif /* MODULE */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -