- 论坛徽章:
- 0
|
数据没写进去,写入和读出的地址定义的是一样的。现在改变写入的值根本就不影响读出的值,读出的值老是524288.运行测试程序的时候用printk观察,是能够进入驱动的每一个函数的,当写的时候,会进入fops里的写函数,读的时候,也会进入fops里的读函数,只是读出来的东西不受写的东西的影响,我怀疑是根本就没写进去。(今天我在jtag那边往dsp写数据了,用自己的驱动再来读,读出来的还是524288这个值,这是8左移16位得到的值,我再用驱动往dsp写,然后用jtag读,发现驱动根本就没有写进去)
工作平台:arm-linux,at91rm9200+linux-2.4.27-vrs1/*This file is for communication about ARM(AT91RM9200) and DSP(TMS320c6713),used arm's EBI_SMC2 and dsp's HPI !
Kernel: linux-2.4.27-vrs1
Date: 2009.3.12
#ifndef __KERNEL__
#define __KERNEL__
#endif
#ifndef MODULE
#define MODULE
#endif
#include <linux/module.h>
#include <linux/init.h>
#include <linux/ioport.h>
#include <linux/types.h>
#include <linux/kernel.h>
#include <linux/fs.h>
#include <linux/slab.h>
#include <linux/mm.h>
#include <asm-arm/io.h>
#include <asm/uaccess.h>
#include <asm-arm/arch-at91rm9200/AT91RM9200.h>
#include <asm-arm/arch-at91rm9200/AT91RM9200_SYS.h>
#include <asm/arch/hardware.h>
#include <linux/interrupt.h>
#include "ATMEL9200.h"
#define HPI_PHYSICAL_BASEADDR 0x30000000L //NCS2 select the HPI
#define HPI_PHYSICAL_size 0x20L
#define readbuffersize 45 /*the size of read from DSP one time*/
#define writebuffersize 33 /*the size of write to DSP one time*/
#define datasourceaddr 0x0003f900 /*arm read data from this address in dsp */
#define datatargetaddr 0x0003f900 /*arm write data to this address in dsp*/
typedef volatile unsigned short int hpi_reg;
hpi_reg *tmpaddr,*hpi_vbase;
AT91PS_SYS AT91_SYS;
ssize_t hpi_write (struct file *file, const char *buf, size_t count,loff_t * offp)
{
hpi_reg ret = 0;
hpi_reg i = 0;
PDEBUG("Start write operation !\n");
tmpaddr=hpi_vbase+0x00;mb(); //写控制寄存器为0x0
*tmpaddr=0x0;mb();
tmpaddr=hpi_vbase+0x02;mb();
*tmpaddr=0x0;mb();
tmpaddr=hpi_vbase+0x04;mb(); //写地址寄存器为0x3f900
*tmpaddr=0x3;mb();
tmpaddr=hpi_vbase+0x06;mb();
*tmpaddr=0xf900;mb();
while (i < writebuffersize)
{
tmpaddr=hpi_vbase+0x08;mb(); //循环写数据寄存器
*tmpaddr=*buf++;mb();
tmpaddr=hpi_vbase+0x0a;mb();
*tmpaddr=*buf++;mb();
i++;
}
return 0;
}
ssize_t hpi_read (struct file * file, char *buf, size_t count,loff_t *offp)
{
hpi_reg ret,i=0;
PDEBUG("go into read function !\n");
tmpaddr=hpi_vbase+0x00;mb(); / /写控制寄存器为0x0
*tmpaddr=0x0;mb();
tmpaddr=hpi_vbase+0x02;mb();
*tmpaddr=0x0;mb();
tmpaddr=hpi_vbase+0x04;mb(); //写地址寄存器为0x3f900
*tmpaddr=0x3;mb();
tmpaddr=hpi_vbase+0x06;mb();
*tmpaddr=0xf900;mb();
while (i < readbuffersize)
{ tmpaddr=hpi_vbase+0x18;mb(); //循环读数据寄存器
*buf++ = *tmpaddr;mb ();
tmpaddr=hpi_vbase+0x1a;mb();
*buf++ = *tmpaddr;mb ();
i++;
}
PDEBUG("leave out read function !\n");
return 0;
}
int hpi_open (struct inode *inode, struct file *file)
{MOD_INC_USE_COUNT;
return 0;}
int hpi_release (struct inode *inode, struct file *file)
{MOD_DEC_USE_COUNT;
return 0;}
static struct file_operations hpi_fops = {
owner: THIS_MODULE,
open: hpi_open,
read: hpi_read,
write: hpi_write,
release:hpi_release
};
static int __init hpi_init (void)
{
int ret;
AT91_SYS->EBI_SMC2_CSR[2] = 0x2200328f;
if (!request_mem_region (HPI_PHYSICAL_BASEADDR,HPI_PHYSICAL_size, "HPI"))
{printk ("Error request mem \n");}
else
{PDEBUG ("request mem success!\n");}
hpi_vbase = (hpi_reg *) ioremap_nocache (HPI_PHYSICAL_BASEADDR, HPI_PHYSICAL_size); //这句有什么讲究?对得到的地址进行操作没达到预期的效果printk ("HPI:Vbase_addr Reg address:%X \n", hpi_vbase);
ret = register_chrdev (254, "HPI", &hpi_fops);
if (ret == 0 || ret > 0)
printk ("hpi device installed success.\nThe major number is 254\n");
return 0;
}
static void __exit hpi_exit (void)
{
unregister_chrdev (254, "HPI");
release_mem_region (HPI_PHYSICAL_BASEADDR, HPI_PHYSICAL_size);
printk ("HPI device uninstalled.\n");
}
module_init (hpi_init);
module_exit (hpi_exit);
这是我在无赖的情况下把原来的程序几次精简出来的,也做了写改动,以前读写映射过来的地址都是用的包装函数readw和writew,不过得到的结果和现在贴出来的代码得到的是一样的。同样的操作方法,在不带操作系统的情况下是可以用axd+jtag进行读写的,读写结果正确,以带了操作系统就不行了,大家帮我看看,太感谢大家了!
[ 本帖最后由 yjz98 于 2009-3-20 09:39 编辑 ] |
|