SSM framework JDBC configuration wwwwei

2023-01-22   ES  

#include <linux/module.h>
#include <linux/init.h>
#include <linux/miscdevice.h>
#include <linux/interrupt.h>
#include <linux/fs.h>
#include <linux/io.h>

#define GPNCON 0x7F008830//ioremap使用的地址,与具体硬件相关

irqreturn_t key_int(int irq, void *dev_id)
{
	printk("key down!\n");

	return 0;
}

void key_hw_init(void)
{
	unsigned short data; 
	unsigned int *gpio_config;

	gpio_config = ioremap(GPNCON,4);
	data = readw(gpio_config);
	data &= ~0b11;
	data |= 0b10;
	writew(data,gpio_config);
}


int key_open(struct inode *node,struct file *filp)
{
	return 0;	
}

struct file_operations key_fops = 
{
	.open = key_open,	
};

struct miscdevice key_miscdev =
{
	.minor = 200,
	.name = "ok6410key",
	.fops = &key_fops,	
};

static int button_init(void)
{
	int err;
	misc_register(&key_miscdev);
	
	key_hw_init();
	if ((err = request_irq(S3C_EINT(0), key_int, IRQF_TRIGGER_FALLING, "ok6410key", 0)) < 0)
	{
		printk("err = %d\n", err);
		goto irq_err;
	}

	return 0;
irq_err:
	misc_deregister(&key_miscdev);	
	return -1;
}

static void button_exit(void)
{
	free_irq(S3C_EINT(0), 0);
	misc_deregister(&key_miscdev);	
}

module_init(button_init);
module_exit(button_exit);
MODULE_LICENSE("GPL");
MODULE_DESCRIPTION("key driver");

1.首先查看原理图,找到按键和cpu链接的位置和中断号。如下图所示,本程序以KEYINT1为例来说明按键驱动的编写方法。从图中可以看到KEYINT1与GPN0相连,使用的中断号为XEINT0。

2.查看datasheet查看找到GPN0,从中得到GPNCON的地址为0x7F008830,这个地址在ioremap的时候使用。还可以看到要将GPN0的bit[1:0]设置为10才是中断触发方式。

3.打开内核目录下的linux/arch/arm/mach-s3c64xx/include/mach/irqs.h查找外部中断0的中断号定义。在第158行找到了该定义。

source

Related Posts

[BZOJ1047] [Monocele] [haoi2007] ideal square

Caddy & GRPC (3) Add a reverse proxy plug -in to Caddy

VuForia how to play online video on iOS on iOS

record: My first generation of deep image object recognition

SSM framework JDBC configuration wwwwei

Random Posts

UE4 Packing Config file configuration

Struts 1.2.4 Learning experience! (Seven)

[Compulsory] Principles of artificial intelligence Learning Notes (1) Chapter1 Introduction

linux driver-symbol export Monkey

IOS10 adaptation problem