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

📄 hpi.c

📁 ARM HPI程序。 用于ARM与DSP之间通信
💻 C
字号:
/* * Copyright (C) 2004 Gexin TECH  *                     <zhaozhenfeng@263.net> *	 This file just for GX-ARM9-2410EP     Sat Feb 7 2004 Zhen-feng Zhao <zhaozhenfeng@263.net> * * 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>#include <asm/segment.h>#include <asm/uaccess.h>#define hpi_MAJOR	98devfs_handle_t  dev_handle;     /* register handle to store device fs */static long ioremap_addr;//1st byte is offset address, 2nd byte is data low 8 bit, 3rd byte is data high 8 bit//4th byte is address low 8 bit, 5th byte is address high 8 bitchar write_buffer[3]={0,0,0};char read_buffer[3]= {0,0,0};ssize_t hpi_read (struct file * file ,char * buf, size_t count, loff_t * f_ops){ unsigned int value; char ret=1;	if (copy_from_user(read_buffer,buf,count)) //we need first byte as select 	{	ret=-1;		printk("%x\n",ret);			return ret;}			value=inw(ioremap_addr+read_buffer[0]);	read_buffer[1]=(char)(value & 0xff);	read_buffer[2]=(char)(value >>8);	copy_to_user(buf,read_buffer,count);		 		return ret;}	void dsphpi_init(void){        printk("dsphpi is initialed\n");}/*=========== HPI_DM642  Write =======================*/ssize_t hpi_write (struct file * file ,const char * buf, size_t count, loff_t * f_ops){ unsigned int value; char ret=1;	if (copy_from_user(write_buffer,buf,count)) 	{	ret=-1;		printk("%x\n",ret);			return ret;}		value=write_buffer[1]+(write_buffer[2]<<8);	outw(value,(ioremap_addr+write_buffer[0]));	return ret;}	/*=========== HPI_DM642 Ioctl =======================*/ssize_t hpi_ioctl (struct inode * inode ,struct file * file,	       	   unsigned int cmd, long data){	printk("s3c2410: device ioctl operation!\n");		}/*============ HPI_DM642 device open ==============*/ ssize_t hpi_open (struct inode * inode ,struct file * file){       // printk("open operation!\n");        dsphpi_init();	return 0;}	/*============ HPI_DM642 device close =============*/ssize_t hpi_release (struct inode  * inode ,struct file * file){//	outw(0x0000,ioremap_addr);//	printk("s3c2410: device release operation!\n");		return 0;}struct file_operations hpi_ops ={		open:		hpi_open,		read:		hpi_read,		write:		hpi_write,		ioctl:		hpi_ioctl,		release:	hpi_release,};static int __init HW_hpi_init(void){//need to set 16 bit width of data bus.    int ret = -ENODEV;    int delay ;		ret = devfs_register_chrdev(hpi_MAJOR, "hpi", &hpi_ops);  			if( ret < 0 ){		printk (" s3c2410: init_module failed with %d\n", ret);			return ret;	}	else		{		printk(" S3c2410 HPI_DM642 register success!!!\n");		}	dev_handle = devfs_register( NULL, "hpi", DEVFS_FL_DEFAULT,                        hpi_MAJOR, 0, S_IFCHR, &hpi_ops, NULL);	ioremap_addr=ioremap(0x18000000,0xff);	printk("remap address = %x\n",ioremap_addr);	//!!!!!!!!!!!!!!//***************************	//outw(0,ioremap_addr);	//***************************    return ret;}int __init s3c2410_hpi_init(void) {    int  ret = -ENODEV;    ret = HW_hpi_init();    if (ret)      return ret;    return 0;}int init_module(){	s3c2410_hpi_init();}void cleanup_module(){        devfs_unregister_chrdev( hpi_MAJOR, "hpi" );        devfs_unregister( dev_handle );}

⌨️ 快捷键说明

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