Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
E
EtherBone Core
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Projects
EtherBone Core
Commits
1a2e7d13
There was an error fetching the commit references. Please try again later.
Commit
1a2e7d13
authored
13 years ago
by
Wesley W. Terpstra
Browse files
Options
Downloads
Patches
Plain Diff
Add command-line support to eb-ls
parent
c4010945
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
api/tools/eb-ls.c
+109
-12
109 additions, 12 deletions
api/tools/eb-ls.c
api/tools/eb-snoop.c
+2
-2
2 additions, 2 deletions
api/tools/eb-snoop.c
with
111 additions
and
14 deletions
api/tools/eb-ls.c
+
109
−
12
View file @
1a2e7d13
...
...
@@ -25,11 +25,36 @@
*******************************************************************************
*/
#define _POSIX_C_SOURCE 200112L
/* strtoull */
#define _POSIX_C_SOURCE 200112L
/* strtoull
+ getopt
*/
#include
<unistd.h>
/* getopt */
#include
<stdio.h>
#include
<stdlib.h>
#include
<string.h>
#include
"../etherbone.h"
#include
"common.h"
static
void
help
(
void
)
{
static
char
revision
[
20
]
=
"$Rev:: $"
;
static
char
date
[
50
]
=
"$Date:: $"
;
*
strchr
(
&
revision
[
7
],
' '
)
=
0
;
*
strchr
(
&
date
[
8
],
' '
)
=
0
;
fprintf
(
stderr
,
"Usage: %s [OPTION] <proto/host/port> <address/size> <value>
\n
"
,
program
);
fprintf
(
stderr
,
"
\n
"
);
fprintf
(
stderr
,
" -a <width> acceptable address bus widths (8/16/32/64)
\n
"
);
fprintf
(
stderr
,
" -d <width> acceptable data bus widths (8/16/32/64)
\n
"
);
fprintf
(
stderr
,
" -r <retries> number of times to attempt autonegotiation (3)
\n
"
);
fprintf
(
stderr
,
" -n do not recursively explore nested buses
\n
"
);
fprintf
(
stderr
,
" -v verbose operation
\n
"
);
fprintf
(
stderr
,
" -q quiet: do not display warnings
\n
"
);
fprintf
(
stderr
,
" -h display this help and exit
\n
"
);
fprintf
(
stderr
,
"
\n
"
);
fprintf
(
stderr
,
"Report Etherbone bugs to <etherbone-core@ohwr.org>
\n
"
);
fprintf
(
stderr
,
"Version r%s (%s). Licensed under the LGPL v3.
\n
"
,
&
revision
[
7
],
&
date
[
8
]);
}
struct
bus_record
{
int
i
;
...
...
@@ -45,6 +70,7 @@ static void print_id(struct bus_record* br) {
print_id
(
br
->
parent
);
}
static
int
norecurse
;
static
void
list_devices
(
eb_user_data_t
user
,
eb_device_t
dev
,
sdwb_t
sdwb
,
eb_status_t
status
)
{
struct
bus_record
br
;
int
devices
;
...
...
@@ -141,7 +167,7 @@ static void list_devices(eb_user_data_t user, eb_device_t dev, sdwb_t sdwb, eb_s
fprintf
(
stdout
,
" dev_date: %08"
PRIx32
"
\n
"
,
des
->
dev_date
);
fprintf
(
stdout
,
" description: "
);
fwrite
(
des
->
description
,
1
,
16
,
stdout
);
fprintf
(
stdout
,
"
\n
"
);
if
(
child
&&
!
bad
)
{
if
(
!
norecurse
&&
child
&&
!
bad
)
{
br
.
bus_begin
=
des
->
wbd_begin
;
br
.
bus_end
=
des
->
wbd_end
;
eb_sdwb_scan_bus
(
dev
,
des
,
&
br
,
&
list_devices
);
...
...
@@ -154,30 +180,101 @@ static void list_devices(eb_user_data_t user, eb_device_t dev, sdwb_t sdwb, eb_s
}
}
int
main
(
int
argc
,
const
char
**
argv
)
{
int
main
(
int
argc
,
char
**
argv
)
{
long
value
;
char
*
value_end
;
int
opt
,
error
;
struct
bus_record
br
;
eb_socket_t
socket
;
eb_status_t
status
;
eb_device_t
device
;
/* Specific command-line options */
const
char
*
netaddress
;
int
attempts
;
br
.
parent
=
0
;
br
.
i
=
-
1
;
br
.
stop
=
0
;
br
.
bus_begin
=
0
;
br
.
bus_end
=
~
(
eb_address_t
)
0
;
if
(
argc
!=
2
)
{
fprintf
(
stderr
,
"Syntax: %s <protocol/host/port>
\n
"
,
argv
[
0
]);
/* Default command-line arguments */
program
=
argv
[
0
];
address_width
=
EB_ADDRX
;
data_width
=
EB_DATAX
;
attempts
=
3
;
quiet
=
0
;
verbose
=
0
;
norecurse
=
0
;
error
=
0
;
/* Process the command-line arguments */
while
((
opt
=
getopt
(
argc
,
argv
,
"a:d:r:nvqh"
))
!=
-
1
)
{
switch
(
opt
)
{
case
'a'
:
value
=
parse_width
(
optarg
);
if
(
value
<
0
)
{
fprintf
(
stderr
,
"%s: invalid address width -- '%s'
\n
"
,
program
,
optarg
);
return
1
;
}
address_width
=
value
<<
4
;
break
;
case
'd'
:
value
=
parse_width
(
optarg
);
if
(
value
<
0
)
{
fprintf
(
stderr
,
"%s: invalid data width -- '%s'
\n
"
,
program
,
optarg
);
return
1
;
}
data_width
=
value
;
break
;
case
'r'
:
value
=
strtol
(
optarg
,
&
value_end
,
0
);
if
(
*
value_end
||
value
<
0
||
value
>
100
)
{
fprintf
(
stderr
,
"%s: invalid number of retries -- '%s'
\n
"
,
program
,
optarg
);
return
1
;
}
attempts
=
value
;
break
;
case
'n'
:
norecurse
=
1
;
break
;
case
'v'
:
verbose
=
1
;
break
;
case
'q'
:
quiet
=
1
;
break
;
case
'h'
:
help
();
return
1
;
case
':'
:
case
'?'
:
error
=
1
;
break
;
default:
fprintf
(
stderr
,
"%s: bad getopt result
\n
"
,
program
);
return
1
;
}
}
if
(
error
)
return
1
;
if
(
optind
+
2
!=
argc
)
{
fprintf
(
stderr
,
"%s: expecting non-optional argument: <protocol/host/port>
\n
"
,
program
);
return
1
;
}
if
((
status
=
eb_socket_open
(
EB_ABI_CODE
,
0
,
EB_DATAX
|
EB_ADDRX
,
&
socket
))
!=
EB_OK
)
{
fprintf
(
stderr
,
"Failed to open Etherbone socket: %s
\n
"
,
eb_status
(
status
));
netaddress
=
argv
[
optind
];
if
((
status
=
eb_socket_open
(
EB_ABI_CODE
,
0
,
address_width
|
data_width
,
&
socket
))
!=
EB_OK
)
{
fprintf
(
stderr
,
"%s: failed to open Etherbone socket: %s
\n
"
,
program
,
eb_status
(
status
));
return
1
;
}
if
((
status
=
eb_device_open
(
socket
,
argv
[
1
]
,
EB_ADDRX
|
EB_DATAX
,
3
,
&
device
))
!=
EB_OK
)
{
fprintf
(
stderr
,
"
F
ailed to open Etherbone device: %s
\n
"
,
eb_status
(
status
));
if
((
status
=
eb_device_open
(
socket
,
netaddress
,
EB_ADDRX
|
EB_DATAX
,
attempts
,
&
device
))
!=
EB_OK
)
{
fprintf
(
stderr
,
"
%s: f
ailed to open Etherbone device: %s
\n
"
,
program
,
eb_status
(
status
));
return
1
;
}
...
...
@@ -185,7 +282,7 @@ int main(int argc, const char** argv) {
br
.
bus_end
>>=
(
sizeof
(
eb_address_t
)
-
(
eb_device_width
(
device
)
>>
4
))
*
8
;
if
((
status
=
eb_sdwb_scan_root
(
device
,
&
br
,
&
list_devices
))
!=
EB_OK
)
{
fprintf
(
stderr
,
"
F
ailed to scan remote device: %s
\n
"
,
eb_status
(
status
));
fprintf
(
stderr
,
"
%s: f
ailed to scan remote device: %s
\n
"
,
program
,
eb_status
(
status
));
return
1
;
}
...
...
@@ -195,12 +292,12 @@ int main(int argc, const char** argv) {
}
if
((
status
=
eb_device_close
(
device
))
!=
EB_OK
)
{
fprintf
(
stderr
,
"
F
ailed to close Etherbone device: %s
\n
"
,
eb_status
(
status
));
fprintf
(
stderr
,
"
%s: f
ailed to close Etherbone device: %s
\n
"
,
program
,
eb_status
(
status
));
return
1
;
}
if
((
status
=
eb_socket_close
(
socket
))
!=
EB_OK
)
{
fprintf
(
stderr
,
"
F
ailed to close Etherbone socket: %s
\n
"
,
eb_status
(
status
));
fprintf
(
stderr
,
"
%s: f
ailed to close Etherbone socket: %s
\n
"
,
program
,
eb_status
(
status
));
return
1
;
}
...
...
This diff is collapsed.
Click to expand it.
api/tools/eb-snoop.c
+
2
−
2
View file @
1a2e7d13
...
...
@@ -236,12 +236,12 @@ int main(int argc, char** argv) {
}
if
((
status
=
eb_socket_open
(
EB_ABI_CODE
,
port
,
address_width
|
data_width
,
&
socket
))
!=
EB_OK
)
{
fprintf
(
stderr
,
"
F
ailed to open Etherbone socket: %s
\n
"
,
eb_status
(
status
));
fprintf
(
stderr
,
"
%s: f
ailed to open Etherbone socket: %s
\n
"
,
program
,
eb_status
(
status
));
return
1
;
}
if
((
status
=
eb_socket_attach
(
socket
,
&
handler
))
!=
EB_OK
)
{
fprintf
(
stderr
,
"
F
ailed to attach slave device: %s
\n
"
,
eb_status
(
status
));
fprintf
(
stderr
,
"
%s: f
ailed to attach slave device: %s
\n
"
,
program
,
eb_status
(
status
));
return
1
;
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment