Hammer LED Driver Module

this is an example kernel module that will blink the onboard LED connected to GPIO F0 ([[media:ledblink.tar.gz|source]])

Usage
NOTE: If trying to make against kernel 2.6.29 change #include of arch/arm/regs-gpio to
 * 1) tar zxvf ledblink.tar.gz
 * 2) cd ledblink
 * 1) include 
 * 1) make KERNEL_SRC=/home/foo/bar/hammer/linux-2.6.22

NOTE: for more information about the contents and function of the included Makefile please see the The Linux Kernel Module Programming Guide

this will generate the ledblink.ko file which can be transfer to your hammer and loaded using the insmod command LED Blink Module Loaded Dec 31 17:10:05 Hammer user.info kernel: LED Blink Module Loaded
 * 1) insmod ledblink.ko

to remove the module use the rmmod command LED Blink Module Unloaded Dec 31 17:10:20 Hammer user.info kernel: LED Blink Module Unloaded
 * 1) rmmod ledblink.ko

Source Code
NOTE: this source makes reference to the HZ kernel value and also to "jiffies", for more information on these see the Kernel_Timer_Systems documentation /*  *  ledblink.c - basic led blinking kernel module * *	Copyright (c) 2008 TinCanTools *	David Anders  * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA * */
 * 1) include 	/* Needed by all modules */
 * 2) include 	/* Needed for KERN_INFO */
 * 3) include 	/* Needed for kernel timer */
 * 4) include 	/* Needed for GPIO defines */
 * 5) include 		/* Needed for s3c2410 functions */

static int blinkinterval = HZ / 2; static struct timer_list blink_timer;

static void led_blink(unsigned long dummy) {

/* the LED is active(on) when low(0) */ if (s3c2410_gpio_getpin(S3C2410_GPF0) == 0)	/* check the current value of GPIO F0 */ s3c2410_gpio_setpin(S3C2410_GPF0, 1);	/* turn LED off */

else s3c2410_gpio_setpin(S3C2410_GPF0, 0);	/* turn LED on */

mod_timer (&blink_timer, jiffies + blinkinterval); /* restart the timer */

}

int init_module(void) {

s3c2410_gpio_cfgpin(S3C2410_GPF0, S3C2410_GPIO_OUTPUT);	/* set the GPIO line F0 to an output */ s3c2410_gpio_setpin(S3C2410_GPF0, 1); /* make sure the LED starts in the off setting */

printk(KERN_INFO "LED Blink Module Loaded\n");

init_timer (&blink_timer); blink_timer.function = led_blink; mod_timer (&blink_timer, jiffies + blinkinterval);

/* 	 * A non 0 return means init_module failed; module can't be loaded. */	return 0; }

void cleanup_module(void) {	s3c2410_gpio_setpin(S3C2410_GPF0, 1);	/* make sure the LED is off when exiting */

del_timer_sync(&blink_timer);		/* sync and delete the timer before exiting */ printk(KERN_INFO "LED Blink Module Unloaded\n"); }

MODULE_LICENSE("GPL");