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

📄 helloworldbit_rpxcllf.c.txt

📁 这是《嵌入式linux-硬件、软件与接口》一书对应的所有linux方面实例的源代码
💻 TXT
字号:
/*
 * helloworld_bit_rpxcllf v1.0 11/03/01
 * www.embeddedlinuxinterfacing.com
 *
 * The original location of this code is
 * http://www.embeddedlinuxinterfacing.com/chapters/09/
 *
 * 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
 */

/* helloworld_bit_rpxcllf
 * This device driver demonstrates MPC860 I/O and memory controller
 * register configuration. PA0 is configured as an output pin 
 * then toggled. CS5 is configured for non burst variable-latency I/O, 
 * 8 bus with longest read/write delays at memory address 
 * 0x80000000. After memory controller configuration, accesses to
 * 0x8000000 result in CS5 assertion. Use this device driver and a 
 * fast oscilloscope to capture PA0 and memory signals. 
 */


/*
powerpc-linux-gcc -O2 -D__KERNEL__ -DMODULE -I/usr/src/powerpc-linux/include -c helloworldbit_rpxcllf.c  -o /tftpboot/powerpc-rootfs/tmp/helloworldbit_rpxcllf.o
*/


#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/init.h>
#include <linux/proc_fs.h>
#include <asm/uaccess.h>
#include <asm/io.h>

#include <asm/8xx_immap.h>

#define MODULE_VERSION "1.0"
#define MODULE_NAME "helloworldbit_rpxcllf"

volatile immap_t *immap;
static void *io_base;

/* references
 * see section 34.2 Port A MPC860 PowerQUICC User's Manual
 *    section 16.5 General-Purpose Chip-Select Machine (GPCM)
 */

#define EXPANSIONPORT          0x80000000
#define EXPANSIONPORTLEN       16

#define PA0                    0x8000 /* PA0 bit in registers */

/*
 * init_helloworldbit
 * This function configures the PAPAR and PADIR MPC860 registers for PA0 
 * output.  Then configures the BR5 and OR5 so /CS5 operations are slow 
 * as possible Using a scope or logic probe, load and unload this module
 * to check /CS5 and PA0 operation
 */
static int __init init_helloworldbit(void)
{
  unsigned char i;

/* get immap value */
  immap = (immap_t *)(mfspr(IMMR) & 0xFFFF0000);

/* sets up CS5 for memory at 0x80000000, MPC man Table 16.4.1 BRx Register */
  immap->im_memctl.memc_br5 = 0x80000401; 

/* sets up CS5 for memory at 0x80000000, MPC man Table 16.4.2 ORx Register */
  immap->im_memctl.memc_or5 = 0x80000FF6; /* CS5 slowest */

  io_base = ioremap_nocache(EXPANSIONPORT, EXPANSIONPORTLEN);

  i = readb(io_base);    /* toggle CS5 and RD */
  writeb(0xAA, io_base); /* toggle CS5 and WR */

  immap->im_ioport.iop_papar &= ~PA0; /* set PA0 to general I/O */
  immap->im_ioport.iop_padir |=  PA0; /* set PA0 as output */

  immap->im_ioport.iop_padat &= ~PA0; /* clear PA0, toggle for bit test */
  immap->im_ioport.iop_padat |=  PA0; /* set   PA0, toggle for bit test */

/* print out register values */
  printk("immr    = 0x%08X\n",immap);
  printk("io_base = 0x%08X\n", io_base);
  printk("BR5     = 0x%08X\n",immap->im_memctl.memc_br5);
  printk("OR5     = 0x%08X\n",immap->im_memctl.memc_or5);
  printk("PAPAR   = 0x%04X\n",immap->im_ioport.iop_papar);
  printk("PADIR   = 0x%04X\n",immap->im_ioport.iop_padir);

/* everything initialized */
  printk(KERN_INFO "%s %s initialized\n",MODULE_NAME, MODULE_VERSION);
  return 0;
}

/*
 * cleanup_helloworldbit
 *   This function makes PA0 an input and releases io_base;
 */
static void __exit cleanup_helloworldbit(void)
{

  unsigned char i;
  /* toggle /CS5 again for testing */
  i = readb(io_base);    /* toggle CS5 and RD */
  writeb(0xAA, io_base); /* toggle CS5 and WR */

  immap->im_ioport.iop_padat &= ~PA0; /* clear PA0, toggle for bit test */
  immap->im_ioport.iop_padat |=  PA0; /* set   PA0, toggle for bit test */


  immap->im_ioport.iop_padir &= ~PA0; /* set PA0 as input */


/* release the ioremap */ 
  iounmap(io_base);
  
  printk(KERN_INFO "%s %s removed\n", MODULE_NAME, MODULE_VERSION);
}

module_init(init_helloworldbit);
module_exit(cleanup_helloworldbit);

MODULE_AUTHOR("Craig Hollabaugh");
MODULE_DESCRIPTION("helloworldbit for RPX-CLLF");

EXPORT_NO_SYMBOLS;

⌨️ 快捷键说明

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