[Armadeus-commitlog] SF.net SVN: armadeus: [804] trunk/target/linux/modules/fpga/fpgaaccess
Brought to you by:
sszy
|
From: <th...@us...> - 2008-05-08 12:56:53
|
Revision: 804
http://armadeus.svn.sourceforge.net/armadeus/?rev=804&view=rev
Author: thom25
Date: 2008-05-08 05:56:44 -0700 (Thu, 08 May 2008)
Log Message:
-----------
allow 32bits access
Modified Paths:
--------------
trunk/target/linux/modules/fpga/fpgaaccess/fpgaaccess.c
trunk/target/linux/modules/fpga/fpgaaccess/fpgaregs.c
Modified: trunk/target/linux/modules/fpga/fpgaaccess/fpgaaccess.c
===================================================================
--- trunk/target/linux/modules/fpga/fpgaaccess/fpgaaccess.c 2008-05-08 12:00:06 UTC (rev 803)
+++ trunk/target/linux/modules/fpga/fpgaaccess/fpgaaccess.c 2008-05-08 12:56:44 UTC (rev 804)
@@ -32,17 +32,20 @@
ssize_t fpgaaccess_read(struct file *fildes, char __user *buff,
size_t count, loff_t *offp){
struct fpgaaccess_dev *sdev = fildes->private_data;
- u16 data=0;
+ u32 data=0;
if(*offp >= FPGA_SIZE || ((*offp)%2 != 0)){ /* offset must be pair */
return 0;
}
- if(count != 2) /* only one word can be wrote (two bytes)*/
- count = 2;
+ if(count > 4) /* 32bits max*/
+ count = 4;
- data = ioread16(sdev->fpga_virtual_base_address + *offp);
-
+ if (count == 2)
+ data = ioread16(sdev->fpga_virtual_base_address + *offp);
+ else
+ data = ioread32(sdev->fpga_virtual_base_address + *offp);
+
/* return data for user */
if(copy_to_user(buff,&data,count)){
printk(KERN_WARNING "read : copy to user data error\n");
@@ -54,21 +57,24 @@
ssize_t fpgaaccess_write(struct file *fildes, const char __user *
buff,size_t count, loff_t *offp){
struct fpgaaccess_dev *sdev = fildes->private_data;
- u16 data=0;
+ u32 data=0;
if(*offp >= FPGA_SIZE || ((*offp)%2 != 0)){ /* offset must be pair */
return 0;
}
- if(count != 2) /* only one word can be wrote (two bytes)*/
- count = 2;
+ if(count > 4) /* 32 bits max)*/
+ count = 4;
if(copy_from_user(&data,buff,count)){
printk(KERN_WARNING "write : copy from user error\n");
return -EFAULT;
}
- iowrite16(data,sdev->fpga_virtual_base_address + *offp);
+ if (count == 2)
+ iowrite16(data,sdev->fpga_virtual_base_address + *offp);
+ else
+ iowrite32(data,sdev->fpga_virtual_base_address + *offp);
return count;
}
Modified: trunk/target/linux/modules/fpga/fpgaaccess/fpgaregs.c
===================================================================
--- trunk/target/linux/modules/fpga/fpgaaccess/fpgaregs.c 2008-05-08 12:00:06 UTC (rev 803)
+++ trunk/target/linux/modules/fpga/fpgaaccess/fpgaregs.c 2008-05-08 12:56:44 UTC (rev 804)
@@ -1,5 +1,5 @@
/************************************************************************
- * a program to write/read values on fpga address map
+ * a program to write/read 16/32bits values on fpga address map
* 7 april 2008
* fpgaregs.c
*
@@ -42,50 +42,66 @@
#include <string.h>
+#define WORD_ACCESS (2)
+#define LONG_ACCESS (4)
+
+void displayResult(char* text, unsigned int accesstype, unsigned int value, unsigned int address)
+{
+ if( accesstype == WORD_ACCESS )
+ printf("%s %04x at %08x\n",text, (unsigned short)value,address);
+ else
+ printf("%s %08x at %08x\n",text, value,address);
+}
+
+
int main(int argc, char *argv[])
{
- unsigned int address;
- unsigned short value;
- int retval, error = 0;
- int ffpga;
-
- if((argc < 2) || (argc > 3)){
- perror("invalid arguments number\nfpgaregs fpga_reg_add [value].\n Ex: fpgaregs 0x10 0x0008");
+ unsigned short address;
+ unsigned int value ;
+ int retval, error = EXIT_SUCCESS;
+ int ffpga, accesstype = LONG_ACCESS;
+
+ if((argc < 3) || (argc > 4)){
+ printf("invalid arguments number\nfpgaregs [w,l] fpga_reg_add [value].\n\tw: word access, l: long access\n\
+\tEx: fpgaregs w 0x10 0x1234, fpgaregs l 0x10 0x12345678\n");
exit(EXIT_FAILURE);
}
ffpga=open("/dev/fpgaaccess",O_RDWR);
if(ffpga<0){
- perror("can't open file /dev/fpgaaccess\n");
+ printf("can't open file /dev/fpgaaccess\n");
exit(EXIT_FAILURE);
}
- address = (unsigned int)strtol(argv[1], (char **)NULL, 16);
+ address = (unsigned int)strtol(argv[2], (char **)NULL, 16);
- if(argc<2){
- perror("invalid command line");
+ if(argc<3){
+ printf("invalid command line");
}
- else {
+ else {
+ if( *(argv[1]) == 'w' )
+ accesstype = WORD_ACCESS;
+
/* write value at address */
- if(argc == 3){
- value = strtol(argv[2], (char **)NULL, 16);
- retval = pwrite(ffpga,(void *)&value,2,address);
+ if(argc == 4){
+ value = strtoul(argv[3], (char **)NULL, 16);
+ retval = pwrite(ffpga,(void *)&value,accesstype,address);
if(retval<0){
- perror("write error\n");
+ printf("write error\n");
error = EXIT_FAILURE;
}
else
- printf("Wrote %04x at %08x\n",value,address);
+ displayResult("Write", accesstype, value, address);
/* read address value */
- }else if(argc == 2){
- retval = pread(ffpga,(void *)&value,2,address);
+ }else if(argc == 3){
+ retval = pread(ffpga,(void *)&value,accesstype,address);
if(retval<0){
perror("Read error\n");
error = EXIT_FAILURE;
}
else
- printf("Read %04x at %08x\n",value,address);
+ displayResult("Read", accesstype, value, address);
}
}
close(ffpga);
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|