- 论坛徽章:
- 0
|
Step 1. led_driver.c
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
MODULE_LICENSE("Dual BSD/GPL");/* declare the license of the module ,it is necessary */
/* before is some decription of the model,not necessary */
MODULE_AUTHOR("j wei");
MODULE_DESCRIPTION("This is an example of programming driver!");
// GPIO_LED DEVICE MAJOR
#define GPIO_LED_MAJOR 97 //定义设备号
static struct file_operations gpio_ctl_fops={
owner: THIS_MODULE,
};
#define LED1_ON( ) __raw_writel(__raw_readl(S3C2410_GPFDAT) & (~0x10), S3C2410_GPFDAT)
#define LED2_ON( ) __raw_writel(__raw_readl(S3C2410_GPFDAT) & (~0x20), S3C2410_GPFDAT)
#define LED3_ON( ) __raw_writel(__raw_readl(S3C2410_GPFDAT) & (~0x40), S3C2410_GPFDAT)
#define LED4_ON( ) __raw_writel(__raw_readl(S3C2410_GPFDAT) & (~0x80), S3C2410_GPFDAT)
#define LED1_OFF( ) __raw_writel(__raw_readl(S3C2410_GPFDAT) | 0x10, S3C2410_GPFDAT)
#define LED2_OFF( ) __raw_writel(__raw_readl(S3C2410_GPFDAT) | 0x20, S3C2410_GPFDAT)
#define LED3_OFF( ) __raw_writel(__raw_readl(S3C2410_GPFDAT) | 0x40, S3C2410_GPFDAT)
#define LED4_OFF( ) __raw_writel(__raw_readl(S3C2410_GPFDAT) | 0x80, S3C2410_GPFDAT)
static void LedSet ( unsigned char led )
{
unsigned char LedStatus;
LedStatus = led;
if ( LedStatus & 1)
LED1_ON();
else
LED1_OFF();
if ( LedStatus & 2)
LED2_ON();
else
LED2_OFF();
if ( LedStatus & 4)
LED3_ON();
else
LED3_OFF();
if ( LedStatus & 8)
LED4_ON();
else
LED4_OFF();
}
static void LedDisp ( void )
{
LedSet(0x08);
mdelay(1000);
LedSet(0x04);
mdelay(1000);
LedSet(0x02);
mdelay(1000);
LedSet(0x01) ;
mdelay(1000);
LedSet(0x00);
mdelay(1000);
LedSet(0x01) ;
mdelay(1000);
LedSet(0x02);
mdelay(1000);
LedSet(0x04);
mdelay(1000);
LedSet(0x08);
mdelay(1000);
LedSet(0x00);
mdelay(1000);
}
static int __init gpio_init(void)
{
int err=0;
int arg=5;
__raw_writel(0x5500, S3C2410_GPFCON); //GPFCON = 0x5500;
__raw_writel(0xff, S3C2410_GPFUP); //GPFUP = 0xff ;
printk("gpio_init\n");
err=register_chrdev(GPIO_LED_MAJOR,"gpio",&gpio_ctl_fops);
if(errStep 2. Makefile
obj-m := led_driver.oKERNELDIR ?= /usr/src/kernels/linux-2.6.8.1-zzmPWD := $(shell pwd)all: $(MAKE) -C $(KERNELDIR) M=$(PWD)clean: rm -rf *.o *~ core .depend .*.cmd *.ko *.mod.c .tmp_versions
step 3. make、loading board、insmod (see attachments)
you will find the LED circularly turn on... Cheer!
![]()
![]()
![]()
本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u2/74310/showart_1091878.html |
|