📄 s3c2410终端程序.txt
字号:
/*
* Copyright (C) 2004
*
This file just for ARM9-2410EP
*
* This file is subject to the terms and conditions of the GNU General Public
* License. See the file COPYING in the main directory of this archive
* for more details.
*/
#include <linux/config.h>
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/sched.h>
#include <linux/interrupt.h> /* for in_interrupt */
#include <linux/timer.h>
#include <linux/init.h>
#include <linux/delay.h> /* for udelay */
#include <linux/modversions.h>
#include <linux/version.h>
#include <asm/io.h>
#include <asm/irq.h>
#include <asm/hardware.h>
#define IRQ_SimpleINT IRQ_EINT2
#define GPIO_SimpleINT_EINT2 (GPIO_MODE_ALT0 | GPIO_PULLUP_EN |
GPIO_F2) //For ringing detect
#define SimpleINT_MAJOR 96
static long CPLD_CTL_ADDR;
嵌入式系统教学平台实验教材
----- 137 -----
static long CPLD_ID_ADDR;
static long XGPIO_IN_ADDR;
static long XGPIO_OUT_ADDR;
devfs_handle_t dev_handle; /* register handle to store device fs */
static int SimpleINT_temp_count=0;
static long ioremap_addr;
static void SimpleINT_interrupt(int nr, void *devid, struct pt_regs *regs);
void CPLD_INIT()
{
CPLD_CTL_ADDR = ioremap(0x21000000,0x0f); // This register controls some
functions in the CPLD.
CPLD_ID_ADDR = ioremap(0x22400000,0x0f); // This register contain CPLD
version information
XGPIO_IN_ADDR = ioremap(0x21800000,0x0f); // This register is XGPIO data
input register.
XGPIO_OUT_ADDR = ioremap(0x21400000,0x0f); // This register is XGPIO data
output register.
printk(" CPLD_ID is %x\n", inb(CPLD_ID_ADDR)); // Read the ID of this CPLD
printk(" CPLD_CTL is %x\n", inb(CPLD_CTL_ADDR));// Read the CPLD_CTL
outb(0x10,CPLD_CTL_ADDR); // enable the CPLD_CTL_KEY_EN
printk(" CPLD_CTL is %x\n", inb(CPLD_CTL_ADDR));
}
ssize_t SimpleINT_read (struct file * file ,char * buf, size_t count, loff_t * f_ops)
{
printk("s3c2410: SimpleINT device file-read operation!\n");
return count;
}
/*=========== SimpleINT Write =======================*/
ssize_t SimpleINT_write (struct file * file ,const char * buf, size_t count, loff_t * f_ops)
{
printk("s3c2410: SimpleINT device file-write operation!\n");
return count;
嵌入式系统教学平台实验教材
----- 138 -----
}
/*=========== SimpleINT Ioctl =======================*/
ssize_t SimpleINT_ioctl (struct inode * inode ,struct file * file,
unsigned int cmd, long data)
{
printk("s3c2410: SimpleINT device ioctl operation!\n");
return 0;
}
/*============ SimpleINT device open ==============*/
ssize_t SimpleINT_open (struct inode * inode ,struct file * file)
{
int ret;
printk("s3c2410: SimpleINT device open operation!\n");
return 0;
}
/*============ SimpleINT device close =============*/
ssize_t SimpleINT_release (struct inode * inode ,struct file * file)
{
printk("s3c2410: SimpleINT device release operation!\n");
SimpleINT_temp_count=0;
return 0;
}
struct file_operations SimpleINT_ops ={
open: SimpleINT_open,
read: SimpleINT_read,
write: SimpleINT_write,
// ioctl: SimpleINT_ioctl,
release: SimpleINT_release,
};
static void SimpleINT_interrupt(int nr, void *devid, struct pt_regs *regs)
{
SimpleINT_temp_count++;
printk("Now Key interrupt %d occur!!!\n",SimpleINT_temp_count);
SRCPND |= (1 << 2);
嵌入式系统教学平台实验教材
----- 139 -----
INTPND |= (1 << 2);
}
static int __init HW_SimpleINT_init(void)
{
int ret = -ENODEV;
int delay ;
SimpleINT_temp_count=0;
CPLD_INIT();//initialize the CPLD.
set_external_irq(IRQ_SimpleINT,EXT_FALLING_EDGE, GPIO_PULLUP_EN);
set_gpio_ctrl(GPIO_SimpleINT_EINT2);
ret = request_irq(IRQ_SimpleINT, SimpleINT_interrupt, SA_INTERRUPT,
"SimpleINT", NULL);
if (ret) {
printk(KERN_INFO "request SimpleINT IRQ failed (%d)\n", IRQ_SimpleINT);
return ret;
}
// !!!!!!!!!!!!!!!
ret = devfs_register_chrdev(SimpleINT_MAJOR, "SimpleINT", &SimpleINT_ops);
if( ret < 0 ){
printk (" s3c2410: init_module failed with %d\n", ret);
return ret;
}
else {
printk(KERN_INFO" S3c2410 SimpleINT register success!!!\n");
}
dev_handle = devfs_register( NULL, "SimpleINT", DEVFS_FL_DEFAULT,
96, 0, S_IFCHR, &SimpleINT_ops, NULL);
//!!!!!!!!!!!!!!
return ret;
}
int __init s3c2410_SimpleINT_init(void) {
int ret = -ENODEV;
嵌入式系统教学平台实验教材
----- 140 -----
ret = HW_SimpleINT_init();
if (ret)
return ret;
return 0;
}
int __init s3c2410_SimpleD_init(void) {
int ret = -ENODEV;
ret = HW_SimpleINT_init();
if (ret)
return ret;
return 0;
}
int init_module()
{
s3c2410_SimpleINT_init();
}
void cleanup_module()
{
free_irq(IRQ_SimpleINT, NULL);
devfs_unregister_chrdev( SimpleINT_MAJOR, "SimpleINT" );
devfs_unregister( dev_handle );
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -