📄 led_scheduler.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/tqueue.h>#include <linux/interrupt.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 tq_struct led_task; /* global: initialized to zero */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; } current->state = TASK_UNINTERRUPTIBLE; schedule_timeout(1 + 100*HZ /1000); schedule_task(&led_task);}/* * 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; led_task.routine = led_light; led_task.data = (void*) &led_data; led_task.sync = 0; schedule_task(&led_task); 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]; return;}#endif /* MODULE */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -