[ create a new paste ] login | about

Link: http://codepad.org/hvftBntn    [ raw code | fork ]

paulocezar.ufg - C, pasted on Sep 27:
/* 
 *  flash.c - Blink keyboard leds until the module is unloaded.
 */


#include <linux/module.h>
#include <linux/init.h>
#include <linux/tty.h>				/* For fg_console, MAX_NR_CONSOLES */
#include <linux/kd.h>				/* For KDSETLED */
#include <linux/vt.h>
#include <linux/console_struct.h>	/* For vc_cons */

MODULE_DESCRIPTION("Example module illustrating the use of Keyboard LEDs.");
MODULE_AUTHOR("Daniele Paolo Scarpazza");
MODULE_LICENSE("GPL");

extern int fg_console;
struct timer_list my_timer;
struct tty_driver *my_driver;
char kbledstatus = 0;

#define BLINK_DELAY   HZ/5
#define ALL_LEDS_ON   0x07
#define RESTORE_LEDS  0xFF

static void my_timer_func(unsigned long ptr)
{
	int *pstatus = (int *)ptr;

	if (*pstatus == ALL_LEDS_ON)
	{

#ifdef MODULE_DEBUG
		printk( KERN_NOTICE "Todos os leds estao acesos!\n");
#endif		
		*pstatus = RESTORE_LEDS;
	}
	else
	{
		*pstatus = ALL_LEDS_ON;
	}
	
	((my_driver->ops)->ioctl) (vc_cons[fg_console].d->vc_tty, NULL, KDSETLED, *pstatus);

	my_timer.expires = jiffies + BLINK_DELAY;
	add_timer(&my_timer);
}

static int __init kbleds_init(void)
{
	int i;
	
#ifdef MODULE_DEBUG
	printk(KERN_INFO "Iniciando o modulo em modo de DEBUG\n");
#endif

	printk(KERN_INFO "kbleds: loading\n");
	printk(KERN_INFO "kbleds: fgconsole is %x\n", fg_console);
	
	for (i = 0; i < MAX_NR_CONSOLES; i++)
	{
		if (!vc_cons[i].d) break;
		
		printk(KERN_INFO "poet_atkm: console[%i/%i] #%i, tty %lx\n", i,
								  MAX_NR_CONSOLES, vc_cons[i].d->vc_num,
						          (unsigned long)vc_cons[i].d->vc_tty);
	}
	printk(KERN_INFO "kbleds: finished scanning consoles\n");

	my_driver = vc_cons[fg_console].d->vc_tty->driver;
	printk(KERN_INFO "kbleds: tty driver magic %x\n", my_driver->magic);

#ifdef MODULE_DEBUG
	printk( KERN_NOTICE "Criando timer..\n");
#endif			
	init_timer(&my_timer);
#ifdef MODULE_DEBUG
	printk( KERN_NOTICE "Timer criado.\n");
#endif		
	
	my_timer.function = my_timer_func;
	my_timer.data = (unsigned long)&kbledstatus;
	my_timer.expires = jiffies + BLINK_DELAY;
	add_timer(&my_timer);
	
#ifdef MODULE_DEBUG
	printk( KERN_NOTICE "Modulo Inicializado com sucesso!\n");
#endif		
	
	return 0;
}

static void __exit kbleds_cleanup(void)
{
	
	printk(KERN_INFO "kbleds: unloading...\n");

#ifdef MODULE_DEBUG
	printk(KERN_INFO "Finalizando o modulo...\n");
#endif

	del_timer(&my_timer);
	
#ifdef MODULE_DEBUG
	printk( KERN_NOTICE "Timer deletado.\n");
#endif		
	
	((my_driver->ops)->ioctl) (vc_cons[fg_console].d->vc_tty, NULL, KDSETLED,
			    RESTORE_LEDS);
}

module_init(kbleds_init);
module_exit(kbleds_cleanup);


Create a new paste based on this one


Comments: