内核设为可抢占,内核模块为死循环时:未加锁时可抢占。。加锁时死机。。
/*************************************
NAME:EmbedSky_hello.c
COPYRIGHT:www.embedsky.net
*************************************/
#include <mach/regs-gpio.h>
#include <mach/hardware.h>
#include <linux/gpio.h>
#include <linux/poll.h>
#include <linux/interrupt.h>
#include <linux/module.h>
#include <linux/delay.h>
#include <asm/irq.h>
#include <linux/kernel.h>
#include <linux/init.h>
#include <linux/fs.h>
#include <linux/device.h>
//#include <asm/hardware.h>
//#include <asm/arch/regs-gpio.h>
//DEFINE_SPINLOCK(lock);// 加锁 加锁 加锁加锁 加锁 加锁加锁 加锁 加锁
#define DEVICE_NAME "EmbedSky-leds"
#define LED_MAJOR 231
/* 应用程序执行ioctl(fd, cmd, arg)时的第2个参数 */
#define IOCTL_LED_ON 1
#define IOCTL_LED_OFF 0
/* 用来指定LED所用的GPIO引脚 */
static unsigned long led_table[] =
{
S3C2410_GPB5,
S3C2410_GPB6,
S3C2410_GPB7,
S3C2410_GPB8,
};
static int EmbedSky_leds_open(struct inode *inode,struct file *file)
{
return 0;
}
static int EmbedSky_leds_ioctl(
struct inode *inode,
struct file *file,
unsigned int cmd,
unsigned long arg)
{
if (arg > 4)
{
return -EINVAL;
}
switch(cmd)
{
case IOCTL_LED_ON:
// 设置指定引脚的输出电平为0
s3c2410_gpio_setpin(led_table[arg], 0);
return 0;
case IOCTL_LED_OFF:
// 设置指定引脚的输出电平为1
s3c2410_gpio_setpin(led_table[arg], 1);
return 0;
default:
return -EINVAL;
}
}
static struct file_operations EmbedSky_leds_fops = {
.owner = THIS_MODULE,
.open = EmbedSky_leds_open,
.ioctl = EmbedSky_leds_ioctl,
};
static char __initdata banner[]="tq2440 led\n";
static struct class *led_class;
static int __init EmbedSky_leds_init(void)
{
printk("hello i am song da shuo");
int ret;
printk(banner);
ret=register_chrdev(LED_MAJOR,DEVICE_NAME,&EmbedSky_leds_fops);
if(ret<0)
{
printk(DEVICE_NAME"cannot register number\n");
return ret;
}
led_class=class_create(THIS_MODULE,"song");
if(IS_ERR(led_class))
{
printk("cannot class\n");
return -1;
}
device_create(led_class,NULL,MKDEV(LED_MAJOR,0),NULL,"song");
printk(DEVICE_NAME"initialized\n");
//spin_lock(lock);// 加锁加锁 加锁 加锁加锁 加锁 加锁加锁 加锁 加锁
while(1) ;// 死循环死循环死循环死循环死循环死循环
}
static void __exit EmbedSky_leds_exit(void)
{
unregister_chrdev(LED_MAJOR,DEVICE_NAME);
device_destroy(led_class,MKDEV(LED_MAJOR,0));
class_destroy(led_class);
}
module_init(EmbedSky_leds_init);
module_exit(EmbedSky_leds_exit);
MODULE_LICENSE("GPL");
MODULE_AUTHOR("www.embedsky.net");
MODULE_DESCRIPTION("GPIO control for EmbedSky SKY2440/TQ2440 Board");