Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
spec-sw
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Analyze
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
This is an archived project. Repository and other project resources are read-only.
fmc-projects
spec
spec-sw
Commits
cabba324
Commit
cabba324
authored
12 years ago
by
Alessandro Rubini
Browse files
Options
Downloads
Patches
Plain Diff
tools: introduce wr-dio-cmd
Signed-off-by:
Alessandro Rubini
<
rubini@gnudd.com
>
parent
4bfbcf06
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
tools/.gitignore
+2
-1
2 additions, 1 deletion
tools/.gitignore
tools/Makefile
+1
-0
1 addition, 0 deletions
tools/Makefile
tools/wr-dio-cmd.c
+127
-0
127 additions, 0 deletions
tools/wr-dio-cmd.c
with
130 additions
and
1 deletion
tools/.gitignore
+
2
−
1
View file @
cabba324
...
...
@@ -2,4 +2,5 @@ libspec.a
spec-cl
specmem
spec-fwloader
spec-vuart
\ No newline at end of file
spec-vuart
wr-dio-cmd
This diff is collapsed.
Click to expand it.
tools/Makefile
+
1
−
0
View file @
cabba324
...
...
@@ -6,6 +6,7 @@ LIB = libspec.a
LIBOBJ
=
speclib.o loader-ll.o
PROGS
=
spec-cl spec-fwloader spec-vuart specmem
PROGS
+=
wr-dio-cmd
all
:
$(LIB) $(PROGS)
...
...
This diff is collapsed.
Click to expand it.
tools/wr-dio-cmd.c
0 → 100644
+
127
−
0
View file @
cabba324
#include
<stdio.h>
#include
<stdlib.h>
#include
<unistd.h>
#include
<string.h>
#include
<errno.h>
#include
<sys/ioctl.h>
#include
<sys/socket.h>
#include
<arpa/inet.h>
#include
<netinet/if_ether.h>
#include
<net/if.h>
#include
<netpacket/packet.h>
#include
"wr_nic/wr-nic.h"
#include
"wr-dio.h"
char
*
prgname
;
char
c
;
struct
wr_dio_cmd
_cmd
;
struct
wr_dio_cmd
*
cmd
=
&
_cmd
;
static
int
scan_pulse
(
int
argc
,
char
**
argv
)
{
unsigned
long
frac_ns
;
int
n
;
if
(
argc
!=
4
)
{
fprintf
(
stderr
,
"%s: stamp: wrong number of arguments
\n
"
,
prgname
);
return
-
1
;
}
if
(
sscanf
(
argv
[
1
],
"%i%c"
,
&
cmd
->
channel
,
&
c
)
!=
1
||
cmd
->
channel
<
0
||
cmd
->
channel
>
4
)
{
fprintf
(
stderr
,
"%s: stamp: not a channel number
\"
%s
\"\n
"
,
prgname
,
argv
[
1
]);
return
-
1
;
}
/*
* Hairy: if we scan "%ld%lf", the 0.009999 will become 9998 micro.
* Thus, scan as integer and string, so we can count leading zeros
*/
n
=
strlen
(
argv
[
2
])
-
1
;
if
(
n
>
9
)
{
n
=
9
;
argv
[
2
][
10
]
=
'\0'
;
}
if
(
sscanf
(
argv
[
2
],
".%ld%c"
,
&
frac_ns
,
&
c
)
<
1
)
{
fprintf
(
stderr
,
"%s: stamp: not a fraction
\"
%s
\"\n
"
,
prgname
,
argv
[
2
]);
return
-
1
;
}
while
(
n
<
9
)
{
frac_ns
*=
10
;
n
++
;
}
cmd
->
t
[
1
].
tv_nsec
=
frac_ns
;
/* Same problem with the time. But now it's integer only (FIXME) */
sscanf
(
argv
[
3
],
"%ld"
,
&
cmd
->
t
[
0
].
tv_sec
);
if
(
argv
[
3
][
0
]
==
'+'
)
cmd
->
flags
|=
WR_DIO_F_REL
;
if
(
!
strcmp
(
argv
[
3
],
"now"
))
cmd
->
flags
|=
WR_DIO_F_NOW
;
return
0
;
}
int
main
(
int
argc
,
char
**
argv
)
{
int
sock
;
char
*
ifname
;
struct
ifreq
ifr
;
prgname
=
argv
[
0
];
argv
++
,
argc
--
;
if
(
argc
<
3
)
{
fprintf
(
stderr
,
"%s: use
\"
%s <netdev> <cmd> [...]
\"\n
"
,
prgname
,
prgname
);
exit
(
1
);
}
ifname
=
argv
[
0
];
argv
++
,
argc
--
;
sock
=
socket
(
PF_PACKET
,
SOCK_RAW
,
htons
(
ETH_P_ALL
));
if
(
sock
<
0
)
{
fprintf
(
stderr
,
"%s: socket(): %s
\n
"
,
prgname
,
strerror
(
errno
));
exit
(
1
);
}
memset
(
&
ifr
,
0
,
sizeof
(
ifr
));
strncpy
(
ifr
.
ifr_name
,
ifname
,
sizeof
(
ifr
.
ifr_name
));
if
(
ioctl
(
sock
,
PRIV_MEZZANINE_ID
,
&
ifr
)
<
0
/* EAGAIN is special: it means we have no ID to check yet */
&&
errno
!=
EAGAIN
)
{
fprintf
(
stderr
,
"%s: ioctl(PRIV_MEZZANINE_ID(%s)): %s
\n
"
,
prgname
,
ifname
,
strerror
(
errno
));
}
/*
* Parse the command line:
*
* pulse <ch> .<len> <seconds>.<fraction>
* pulse <ch> .<len> now
* pulse <ch> .<len> +<seconds>.<fraction>
*
* TODO: stamp <channel>
* TODO: stampm <mask>
**/
if
(
!
strcmp
(
argv
[
0
],
"pulse"
))
{
cmd
->
command
=
WR_DIO_CMD_OUT
;
if
(
scan_pulse
(
argc
,
argv
)
<
0
)
exit
(
1
);
}
ifr
.
ifr_data
=
(
void
*
)
cmd
;
if
(
ioctl
(
sock
,
PRIV_MEZZANINE_CMD
,
&
ifr
)
<
0
)
{
fprintf
(
stderr
,
"%s: ioctl(PRIV_MEZZANINE_CMD(%s)): %s
\n
"
,
prgname
,
ifname
,
strerror
(
errno
));
}
exit
(
0
);
}
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