📄 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_PMC 0xFFFFFC00 /* PMC controller base address */#define PMC_MEM_LEN 0x70 #define PMC_PCER_OFF 0x10 #define PMC_PCSR_OFF 0x18#define AT91C_BASE_PIOB 0xFFFFF600 /* PIO-B base address */#define PIO_MEM_LEN 0xB0#define PIO_PER_OFF 0x00#define PIO_OER_OFF 0x10#define PIO_SODR_OFF 0x30#define PIO_CODR_OFF 0x34#define PIO_ODSR_OFF 0x38/* * Prototypes */static int __init led_init (void );struct timer_list led_timer;static int led_data; /*1: light 0:dis-light */static void *pmc_base, *piob_base;void led_light(void* data){ if(led_data == 1) /*turn on led*/ { writel (AT91C_PIO_PB12, piob_base + PIO_CODR_OFF); led_data = 0; } else /*turn off led*/ { writel (AT91C_PIO_PB12, piob_base + PIO_SODR_OFF); led_data = 1; } init_timer(&led_timer); led_timer.function = (void (*)(unsigned long))led_light; led_timer.data = (unsigned long)&led_data; led_timer.expires = TIMER_INTERVAL * HZ /1000; mod_timer(&led_timer, jiffies + TIMER_INTERVAL * HZ/1000); }/* * Initialize the driver - Register the character device */static int __init led_init(void){ unsigned int i; /* get the remmapped controller base address register */ pmc_base = ioremap_nocache(AT91C_BASE_PMC, PMC_MEM_LEN); /* enable PIOB power */ writel (1 << AT91C_ID_PIOB, pmc_base + PMC_PCER_OFF); i = readl(pmc_base + PMC_PCSR_OFF); printk ("pmc_base = 0x%08X\n", (int) pmc_base); printk ("PCSR = 0x%08X\n", i); iounmap (pmc_base); /* set PB12 output */ piob_base = ioremap_nocache(AT91C_BASE_PIOB, PIO_MEM_LEN); writel (AT91C_PIO_PB12, piob_base + PIO_PER_OFF); writel (AT91C_PIO_PB12, piob_base + PIO_OER_OFF); printk ("piob_base = 0x%08X\n", (int) piob_base); writel (AT91C_PIO_PB12, piob_base + PIO_CODR_OFF); led_data = 1; init_timer(&led_timer); led_timer.function = (void(*)(unsigned long))led_light; led_timer.data = (unsigned long)&led_data; led_timer.expires = jiffies + TIMER_INTERVAL * HZ /1000; add_timer(&led_timer); return 0;}/****************************** **** Module Declarations ***** **************************** */#ifdef MODULE/* * Cleanup - unregister the appropriate file from /proc */static void __exit cleanup_led_module (void){ /*turn off led */ writel (AT91C_PIO_PB12, piob_base + PIO_SODR_OFF); iounmap (piob_base); debugk ("iounmap: piob_base = 0x%08x\n", (int) piob_base); del_timer(&led_timer); return;}module_init(led_init);module_exit(cleanup_led_module);MODULE_AUTHOR("Himai");MODULE_DESCRIPTION("led driver for HM901ESP");#endif /* MODULE */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -