Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
F
FMC TDC 1ns 5cha - Software
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
image/svg+xml
Discourse
Discourse
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Projects
FMC TDC 1ns 5cha - Software
Commits
12497f73
Commit
12497f73
authored
Jul 22, 2015
by
Federico Vaga
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
tools: optimize code
Signed-off-by:
Federico Vaga
<
federico.vaga@cern.ch
>
parent
146d18ad
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
41 additions
and
71 deletions
+41
-71
fmc-tdc-tstamp.c
tools/fmc-tdc-tstamp.c
+41
-71
No files found.
tools/fmc-tdc-tstamp.c
View file @
12497f73
...
...
@@ -56,7 +56,8 @@ void dump(unsigned int ch, struct fmctdc_time *ts, int diff_mode)
uint64_t
ns
;
double
s
,
hz
;
fprintf
(
stdout
,
"channel %d | channel seq %-12u | board seq %-12u
\n
ts "
,
fprintf
(
stdout
,
"channel %d | channel seq %-12u | board seq %-12u
\n
ts "
,
ch
,
ts
->
seq_id
,
ts
->
gseq_id
);
dump_timestamp
(
*
ts
);
fprintf
(
stdout
,
"
\n
"
);
...
...
@@ -65,7 +66,8 @@ void dump(unsigned int ch, struct fmctdc_time *ts, int diff_mode)
fmctdc_ts_sub
(
&
ts_tmp
,
&
ts_prev
[
ch
]);
if
(
diff_mode
)
{
fprintf
(
stdout
,
" refer to board seq %-12u
\n
"
,
ts
->
ref_gseq_id
);
fprintf
(
stdout
,
" refer to board seq %-12u
\n
"
,
ts
->
ref_gseq_id
);
return
;
}
...
...
@@ -101,19 +103,6 @@ static void help(char *name)
FMCTDC_CH_1
,
FMCTDC_CH_LAST
);
}
static
void
tstamp_flush
(
struct
fmctdc_board
*
brd
,
int
ch
,
int
flush
)
{
int
ret
;
if
(
!
flush
)
return
;
ret
=
fmctdc_flush
(
brd
,
ch
);
if
(
ret
)
fprintf
(
stderr
,
"fmc-tdc-tstamp: failed to flush channel %d: %s
\n
"
,
ch
,
fmctdc_strerror
(
errno
));
}
static
void
termination_handler
(
int
signum
)
{
...
...
@@ -136,6 +125,7 @@ int main(int argc, char **argv)
char
opt
;
fd_set
rfds
;
struct
sigaction
new_action
,
old_action
;
int
ch_valid
[
FMCTDC_NUM_CHANNELS
]
=
{
0
,
1
,
2
,
3
,
4
};
/* Set up the structure to specify the new action. */
new_action
.
sa_handler
=
termination_handler
;
...
...
@@ -159,7 +149,7 @@ int main(int argc, char **argv)
ref
[
i
]
=
-
1
;
/* Parse Options */
while
((
opt
=
getopt
(
argc
,
argv
,
"hwns:d:frm:l:"
))
!=
-
1
)
{
while
((
opt
=
getopt
(
argc
,
argv
,
"hwns:d:frm:l:
c:
"
))
!=
-
1
)
{
switch
(
opt
)
{
case
'h'
:
case
'?'
:
...
...
@@ -212,6 +202,15 @@ int main(int argc, char **argv)
}
ref
[
b
]
=
a
;
break
;
case
'c'
:
if
(
chan_count
>=
FMCTDC_NUM_CHANNELS
)
{
fprintf
(
stderr
,
"%s: too many channels, maximum %d
\n
"
,
argv
[
0
],
FMCTDC_NUM_CHANNELS
);
break
;
}
sscanf
(
optarg
,
"%i"
,
&
ch_valid
[
chan_count
++
]);
break
;
}
}
if
(
optind
>=
argc
)
{
...
...
@@ -236,16 +235,29 @@ int main(int argc, char **argv)
/* Open Channels from command line */
memset
(
channels
,
0
,
sizeof
(
channels
));
while
(
optind
<
argc
)
{
ch
=
atoi
(
argv
[
optind
]);
if
(
ch
<
FMCTDC_CH_1
||
ch
>
FMCTDC_CH_LAST
)
{
fprintf
(
stderr
,
"%s: invalid channel.
\n
"
,
argv
[
0
]);
fmctdc_close
(
brd
);
exit
(
EXIT_FAILURE
);
if
(
!
chan_count
)
chan_count
=
FMCTDC_NUM_CHANNELS
;
for
(
i
=
0
;
i
<
chan_count
;
i
++
)
{
ch
=
ch_valid
[
i
];
if
(
flush
)
{
ret
=
fmctdc_flush
(
brd
,
ch
);
if
(
ret
)
fprintf
(
stderr
,
"fmc-tdc-tstamp: failed to flush channel %d: %s
\n
"
,
ch
,
fmctdc_strerror
(
errno
));
}
channels
[
ch
]
=
fmctdc_fileno_channel
(
brd
,
ch
);
tstamp_flush
(
brd
,
ch
,
flush
);
ret
=
fmctdc_reference_set
(
brd
,
ch
,
ref
[
ch
]);
if
(
ret
)
{
fprintf
(
stderr
,
"%s: cannot set reference mode: %s
\n
"
,
argv
[
0
],
fmctdc_strerror
(
errno
));
fprintf
(
stderr
,
"%s: continue in normal mode: %s
\n
"
,
argv
[
0
],
fmctdc_strerror
(
errno
));
ref
[
ch
]
=
-
1
;
}
/* set buffer mode */
ret
=
fmctdc_set_buffer_mode
(
brd
,
ch
,
bufmode
);
...
...
@@ -262,62 +274,20 @@ int main(int argc, char **argv)
"%s: chan %d: cannot set buffer lenght: %s. Use default
\n
"
,
argv
[
0
],
ch
,
fmctdc_strerror
(
errno
));
}
if
(
!
read
)
ret
=
fmctdc_channel_enable
(
brd
,
i
);
ret
=
fmctdc_channel_enable
(
brd
,
ch
);
if
(
ret
)
fprintf
(
stderr
,
"%s: chan %d: cannot enable acquisition: %s.
\n
"
,
argv
[
0
],
i
,
fmctdc_strerror
(
errno
));
chan_count
++
;
optind
++
;
}
/* If there are not channels, then dump them all */
if
(
!
chan_count
)
{
for
(
i
=
0
;
i
<
FMCTDC_NUM_CHANNELS
;
i
++
)
{
tstamp_flush
(
brd
,
ch
,
flush
);
channels
[
i
]
=
fmctdc_fileno_channel
(
brd
,
i
);
ret
=
fmctdc_reference_set
(
brd
,
i
,
ref
[
i
]);
if
(
ret
)
{
fprintf
(
stderr
,
"%s: cannot set reference mode: %s
\n
"
,
argv
[
0
],
fmctdc_strerror
(
errno
));
fprintf
(
stderr
,
"%s: continue in normal mode: %s
\n
"
,
argv
[
0
],
fmctdc_strerror
(
errno
));
ref
[
i
]
=
-
1
;
}
/* set buffer mode */
ret
=
fmctdc_set_buffer_mode
(
brd
,
i
,
bufmode
);
if
(
ret
)
{
fprintf
(
stderr
,
"%s: chan %d: cannot set buffer mode: %s. Use default
\n
"
,
argv
[
0
],
i
,
fmctdc_strerror
(
errno
));
}
/* set buffer lenght */
ret
=
fmctdc_set_buffer_len
(
brd
,
i
,
buflen
);
if
(
ret
)
{
fprintf
(
stderr
,
"%s: chan %d: cannot set buffer lenght: %s. Use default
\n
"
,
argv
[
0
],
i
,
fmctdc_strerror
(
errno
));
}
if
(
!
read
)
ret
=
fmctdc_channel_enable
(
brd
,
i
);
if
(
ret
)
fprintf
(
stderr
,
"%s: chan %d: cannot enable acquisition: %s.
\n
"
,
argv
[
0
],
i
,
fmctdc_strerror
(
errno
));
}
chan_count
=
i
;
}
/* Read Time-Stamps */
n
=
0
;
while
((
n
<
n_samples
||
n_samples
<=
0
)
&&
(
!
stop
))
{
/* Check for pending signal */
nfds
=
0
;
...
...
@@ -346,8 +316,8 @@ int main(int argc, char **argv)
}
/* Now we can read the timestamp */
for
(
i
=
0
;
i
<
=
FMCTDC_CH_LAST
;
i
++
)
{
fd
=
channels
[
i
];
for
(
i
=
0
;
i
<
chan_count
;
i
++
)
{
fd
=
channels
[
ch_valid
[
i
]
];
if
(
fd
<
0
)
continue
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment