⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 led_timer.c

📁 这是motorola公司的powerpc芯片上的嵌入式linux上的驱动程序和测试程序
💻 C
字号:
/*********************************************************************** * * (C) Copyright 2002,12 *  * Qi zhaoling  * All rights left. * * * a simple Device Driver for UT850GE led device * * Can be loaded as module * * $Id: led.c,v 1.1 2000/01/14 16:28:49 wd Exp $ * ***********************************************************************//* * 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 <asm/init.h>		/* for __initfunc		*/#include <linux/sched.h>#include <linux/fs.h>#include <linux/interrupt.h>    #include <linux/timer.h>#include <asm/8xx_immap.h>#include <asm/mpc8xx.h>static volatile iop8xx_t *iop_p = 0;   /*i/o port point of UT850GE*/#undef	DEBUG#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>#endif#ifndef KERNEL_VERSION# define KERNEL_VERSION(a,b,c)	((a)*65536+(b)*256+(c))#endif#define	DEBUG	1#define SUCCESS 0#define MAX_LED 2#define LINK_LED 0#define ALARM_LED 1static ushort  UTLed[MAX_LED] = {0x1000, 0x0800};/* * Prototypes */int led_init (void );int init_module(void);void cleanup_module(void);struct timer_list led_timer;static int led_data;  /*1: light   0:dis-light */void led_light(void* data){	volatile iop8xx_t *cp = iop_p;	if(led_data  == 1)   /*turn on led*/	{    		cp->iop_pddat &= ~UTLed[ALARM_LED];		cp->iop_pddat &= ~UTLed[LINK_LED];		led_data = 0;	}	else             /*turn off led*/	{		cp->iop_pddat |= UTLed[ALARM_LED];		cp->iop_pddat |= UTLed[LINK_LED];		led_data = 1;	}		/*del_timer(&led_timer);	init_timer(&led_timer);	led_timer.function = led_light;        led_timer.data     = (unsigned long)&led_data;        led_timer.expires  = 100 * HZ /1000;*/        /*add_timer(&led_timer);*/	mod_timer(&led_timer, jiffies + 100* HZ/1000);	}/* * Initialize the driver - Register the character device */int led_init(void){	volatile iop8xx_t *cp;		if (!iop_p) 	{		/* init i/o port ptr */		unsigned long immr;		asm( "mfspr %0,638": "=r"(immr) : );		immr &= 0xFFFF0000;		iop_p = (iop8xx_t *)&((volatile immap_t *)immr)->im_ioport;	}		cp = iop_p;	cp->iop_pdpar &= ~UTLed[LINK_LED];  	cp->iop_pddir |=  UTLed[LINK_LED];  /*set to output IO*/	cp->iop_pdpar &= ~UTLed[ALARM_LED];  	cp->iop_pddir |=  UTLed[ALARM_LED]; /*set to output IO*/	led_data = 1;		init_timer(&led_timer);	led_timer.function = led_light;	led_timer.data     = (unsigned long)&led_data;	led_timer.expires  = jiffies + 100 * HZ /1000;	add_timer(&led_timer);	return 0;}/****************************** **** Module Declarations ***** **************************** */#ifdef MODULE/* * Initialize the module */int init_module (void){	return led_init();}/* * Cleanup - unregister the appropriate file from /proc */void cleanup_module (void){        volatile iop8xx_t *cp = iop_p;	/*turn off led */        cp->iop_pddat |= UTLed[ALARM_LED];        cp->iop_pddat |= UTLed[LINK_LED];	del_timer(&led_timer);		return;}#endif	/* MODULE */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -