[Armadeus-commitlog] SF.net SVN: armadeus:[1237] trunk/target/linux/debug/fpgaregs/fpgaregs.c
Brought to you by:
sszy
|
From: <Fa...@us...> - 2009-04-22 17:07:39
|
Revision: 1237
http://armadeus.svn.sourceforge.net/armadeus/?rev=1237&view=rev
Author: FabM
Date: 2009-04-22 17:07:15 +0000 (Wed, 22 Apr 2009)
Log Message:
-----------
[BUILDROOT] fpgaregs : check address conformity. ticket #44
Modified Paths:
--------------
trunk/target/linux/debug/fpgaregs/fpgaregs.c
Modified: trunk/target/linux/debug/fpgaregs/fpgaregs.c
===================================================================
--- trunk/target/linux/debug/fpgaregs/fpgaregs.c 2009-04-22 11:49:17 UTC (rev 1236)
+++ trunk/target/linux/debug/fpgaregs/fpgaregs.c 2009-04-22 17:07:15 UTC (rev 1237)
@@ -55,70 +55,81 @@
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);
+ 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 short address;
- unsigned int value;
- int ffpga, accesstype = LONG_ACCESS;
- void* ptr_fpga;
+ unsigned short address;
+ unsigned int value;
+ int ffpga, accesstype = LONG_ACCESS;
+ void* ptr_fpga;
- 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");
- return -1;
- }
+ 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");
+ return -1;
+ }
- ffpga=open("/dev/mem",O_RDWR|O_SYNC);
- if(ffpga<0){
- printf("can't open file /dev/mem\n");
- return -1;
- }
+ ffpga=open("/dev/mem",O_RDWR|O_SYNC);
+ if(ffpga<0){
+ printf("can't open file /dev/mem\n");
+ return -1;
+ }
- ptr_fpga = mmap (0, 8192, PROT_READ|PROT_WRITE, MAP_SHARED, ffpga, FPGA_ADDRESS);
- if (ptr_fpga == MAP_FAILED)
- {
- printf ("mmap failed\n");
- return -1;
- }
+ ptr_fpga = mmap (0, 8192, PROT_READ|PROT_WRITE, MAP_SHARED, ffpga, FPGA_ADDRESS);
+ if (ptr_fpga == MAP_FAILED)
+ {
+ printf ("mmap failed\n");
+ return -1;
+ }
- address = (unsigned int)strtol(argv[2], (char **)NULL, 16);
+ address = (unsigned int)strtol(argv[2], (char **)NULL, 16);
- if(argc<3){
- printf("invalid command line");
- }
- else {
- if( *(argv[1]) == 'w' )
- accesstype = WORD_ACCESS;
-
- /* write value at address */
- if(argc == 4){
- value = strtoul(argv[3], (char **)NULL, 16);
- if (accesstype == WORD_ACCESS)
- *(unsigned short*)(ptr_fpga+(address)) = (unsigned short)value;
- else
- *(unsigned int*)(ptr_fpga+(address)) = (unsigned int)value;
+ if(argc<3){
+ printf("invalid command line");
+ }
+ else {
+ if( *(argv[1]) == 'w' )
+ accesstype = WORD_ACCESS;
+ if(accesstype == WORD_ACCESS){
+ if(address%2 != 0){
+ printf("Can't read word in even address (%d)\n",address);
+ return -1;
+ }
+ }else{ /* LONG_ACCESS */
+ if(address%4 != 0){
+ printf("Can't read long in no-4-multiple address (%d)\n",address);
+ return -1;
+ }
+ }
- displayResult("Write", accesstype, value, address);
-
- /* read address value */
- }else if(argc == 3){
- if (accesstype == WORD_ACCESS)
- value = *(unsigned short*)(ptr_fpga+(address));
- else
- value = *(unsigned int*)(ptr_fpga+(address));
-
- displayResult("Read", accesstype, value, address);
- }
- }
- close(ffpga);
- return 0;
+ /* write value at address */
+ if(argc == 4){
+ value = strtoul(argv[3], (char **)NULL, 16);
+ if (accesstype == WORD_ACCESS)
+ *(unsigned short*)(ptr_fpga+(address)) = (unsigned short)value;
+ else
+ *(unsigned int*)(ptr_fpga+(address)) = (unsigned int)value;
+
+ displayResult("Write", accesstype, value, address);
+
+ /* read address value */
+ }else if(argc == 3){
+ if (accesstype == WORD_ACCESS)
+ value = *(unsigned short*)(ptr_fpga+(address));
+ else
+ value = *(unsigned int*)(ptr_fpga+(address));
+
+ displayResult("Read", accesstype, value, address);
+ }
+ }
+ close(ffpga);
+ return 0;
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|