⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 interrupt_latency_rpxcllf.c

📁 《嵌入式Linux-硬件
💻 C
字号:
/* * interrupt_latency_rpxcllf v1.0 11/25/01 * www.embeddedlinuxinterfacing.com * * The original location of this code is * http://www.embeddedlinuxinterfacing.com/chapters/11/ * * Copyright (C) 2001 by Craig Hollabaugh * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Library 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 * Library General Public License for more details. * * You should have received a copy of the GNU Library 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 *//* * interrupt_latency_rpxcllf.c is based on procfs_example.c by Erik Mouw. * For more information, please see, The Linux Kernel Procfs Guide, Erik Mouw * http://kernelnewbies.org/documents/kdoc/procfs-guide/lkprocfsguide.html *//*powerpc-linux-gcc -O2 -D__KERNEL__ -DMODULE -I/usr/src/powerpc-linux/include -c interrupt_latency_rpxcllf.c -o /tftpboot/powerpc-rootfs/tmp/interrupt_latency_rpxcllf.o*//* interrupt_latency_rpxcllf * This module measures instantanous interrupt latency of the RPX-CLLF * using PA0 and IRQ2. Configure the SIU for IRQ2 edge interrupt * generation. Configure PA0 as an output then setting PA0 causes a * rising edge that generates the interrupt. * * Section 11.5.1 of Motorola MPC860 PowerQUICC User's Manual * * After module insertion, reading /proc/interrupt_latency will assert PA0 * generating the interrupt. The interrupt handler will deassert this signal. * View on scope. An interrupt counter is included to help debug noisy a * interrupt line. */#include <linux/module.h>#include <linux/kernel.h>#include <linux/init.h>#include <linux/proc_fs.h>#include <asm/io.h>#include <linux/interrupt.h>#include <asm/irq.h>#include <asm/mpc8xx.h>#include <asm/8xx_immap.h>#include <asm/time.h>#define MODULE_VERSION "1.0"#define MODULE_NAME    "interrupt_latency_rpxcllf"volatile immap_t *immap;static void *io_base;#define PA0         0x8000#define SIEL_ED2    0x08000000int interruptcount = 0;#define INTERRUPT SIU_IRQ2struct timeval tv1, tv2; /* do_gettimeofday fills these */static struct proc_dir_entry *interrupt_latency_file;/* * function interrupt_interrupt_latency * This function is the interrupt handler for interrupt 2. It sets the tv2 * structure using do_gettimeofday. It then clears PA0. */void interrupt_interrupt_latency(int irq, void *dev_id, struct pt_regs *regs){  do_gettimeofday(&tv2);  immap->im_ioport.iop_padat |= PA0; /* deassert the interrupt signal */  interruptcount++;}/* * function proc_read_interrupt_latency * The kernel executes this function when a read operation occurs on * /proc/interrupt_latency. This function sets the tv1 structure. It asserts * PA0 which should immediately cause interrupt 2 to occur. The handler * records tv2 and deasserts PA0. This function returns the time * differential between tv2 and tv1. */static int proc_read_interrupt_latency(char *page, char **start, off_t off,                                       int count, int *eof, void *data){  int len;  do_gettimeofday(&tv1);  immap->im_ioport.iop_padat &= ~PA0; /* assert the interrupt signal */ len = sprintf(page, "Start %9i.%06i\nFinish %9i.%06i\nLatency %16i\n\Count %18i\n",(int) tv1.tv_sec, (int) tv1.tv_usec,              (int) tv2.tv_sec, (int) tv2.tv_usec,              (int) (tv2.tv_usec - tv1.tv_usec),              interruptcount);  return len;}/* * function init_interrupt_latency * This function creates the /proc directory entry interrupt_latency. It * requests interrupt 2 from Linux then configures the interrupt controller. */static int __init init_interrupt_latency(void){  unsigned long r;  int rv = 0;  interrupt_latency_file = create_proc_entry("interrupt_latency", 0444, NULL);  if(interrupt_latency_file == NULL) {    return -ENOMEM;  }  interrupt_latency_file->data = NULL;  interrupt_latency_file->read_proc = &proc_read_interrupt_latency;  interrupt_latency_file->write_proc = NULL;  interrupt_latency_file->owner = THIS_MODULE;  /* request interrupt from linux */  rv = request_8xxirq(INTERRUPT, interrupt_interrupt_latency, 0,                      "interrupt_latency",NULL);  if ( rv ) {    printk("Can't get interrupt %d\n", INTERRUPT);    goto no_interrupt_latency;  }  /* get the IMMAP register address */  immap = (immap_t *)(mfspr(IMMR) & 0xFFFF0000);  immap->im_ioport.iop_papar &= ~PA0; /* set PA0 to general I/O */  immap->im_ioport.iop_padir |=  PA0; /* set PA0 as output      */  /* set IRQ2 to edge triggering */  immap->im_siu_conf.sc_siel |= SIEL_ED2;  printk("SIEL     = 0x%08X\n",immap->im_siu_conf.sc_siel);  immap->im_ioport.iop_padat |= PA0; /* deassert the interrupt signal *//* everything initialized */  printk(KERN_INFO "%s %s initialized\n",MODULE_NAME, MODULE_VERSION);  return 0;no_interrupt_latency:  remove_proc_entry("interrupt_latency", NULL);}/* * function cleanup_interrupt_latency * This function frees interrupt 2 then removes the * /proc directory entry interrupt_latency. */static void __exit cleanup_interrupt_latency(void){  free_irq(INTERRUPT,NULL); /* free the interrupt */  remove_proc_entry("interrupt_latency", NULL);  printk(KERN_INFO "%s %s removed\n", MODULE_NAME, MODULE_VERSION);}module_init(init_interrupt_latency);module_exit(cleanup_interrupt_latency);MODULE_AUTHOR("Craig Hollabaugh");MODULE_DESCRIPTION("interrupt_latency proc module");EXPORT_NO_SYMBOLS;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -