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
dc89bcb1
Commit
dc89bcb1
authored
Feb 04, 2015
by
Federico Vaga
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
lib: channel range is now 0, 4
Signed-off-by:
Federico Vaga
<
federico.vaga@cern.ch
>
parent
8ed2f344
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
48 additions
and
40 deletions
+48
-40
fmctdc-lib.c
lib/fmctdc-lib.c
+19
-13
fmctdc-lib.h
lib/fmctdc-lib.h
+6
-6
fmc-tdc-tstamp.c
tools/fmc-tdc-tstamp.c
+23
-21
No files found.
lib/fmctdc-lib.c
View file @
dc89bcb1
...
...
@@ -280,7 +280,7 @@ int fmctdc_set_termination(struct fmctdc_board *userb, unsigned int channel,
if
(
channel
>=
FMCTDC_NUM_CHANNELS
)
return
-
EINVAL
;
snprintf
(
attr
,
sizeof
(
attr
),
"ft-ch%d/termination"
,
channel
);
snprintf
(
attr
,
sizeof
(
attr
),
"ft-ch%d/termination"
,
channel
+
1
);
val
=
on
?
1
:
0
;
return
fmctdc_sysfs_set
(
b
,
attr
,
&
val
);
...
...
@@ -304,7 +304,7 @@ int fmctdc_get_termination(struct fmctdc_board *userb, unsigned int channel)
if
(
channel
>=
FMCTDC_NUM_CHANNELS
)
return
-
EINVAL
;
snprintf
(
attr
,
sizeof
(
attr
),
"ft-ch%d/termination"
,
channel
);
snprintf
(
attr
,
sizeof
(
attr
),
"ft-ch%d/termination"
,
channel
+
1
);
ret
=
fmctdc_sysfs_get
(
b
,
attr
,
&
val
);
if
(
ret
)
...
...
@@ -350,18 +350,19 @@ int fmctdc_set_acquisition(struct fmctdc_board *userb, int on)
/**
* It opens the zio control channel of a TDC board
* @param[in] b TDC board instance token
* @param[in] channel channel to open
* @param[in] channel channel to open
[0, 4]
* @return a file descriptor, otherwise -1 and errno is set appropriately
*/
static
int
__fmctdc_open_channel
(
struct
__fmctdc_board
*
b
,
unsigned
int
channel
)
{
char
fname
[
128
];
if
(
b
->
fdc
[
channel
-
1
]
<=
0
)
{
if
(
b
->
fdc
[
channel
]
<=
0
)
{
snprintf
(
fname
,
sizeof
(
fname
),
"%s-%d-0-ctrl"
,
b
->
devbase
,
channel
-
1
);
b
->
fdc
[
channel
-
1
]
=
open
(
fname
,
O_RDONLY
|
O_NONBLOCK
);
channel
);
b
->
fdc
[
channel
]
=
open
(
fname
,
O_RDONLY
|
O_NONBLOCK
);
}
return
b
->
fdc
[
channel
-
1
];
return
b
->
fdc
[
channel
];
}
...
...
@@ -374,6 +375,7 @@ static int __fmctdc_open_channel(struct __fmctdc_board *b, unsigned int channel)
int
fmctdc_fileno_channel
(
struct
fmctdc_board
*
userb
,
unsigned
int
channel
)
{
__define_board
(
b
,
userb
);
return
__fmctdc_open_channel
(
b
,
channel
);
}
...
...
@@ -381,7 +383,7 @@ int fmctdc_fileno_channel(struct fmctdc_board *userb, unsigned int channel)
/**
* this "read" behaves like the system call and obeys O_NONBLOCK
* @param[in] userb TDC board instance token
* @param[in] channel channel to use
* @param[in] channel channel to use
[0, 4]
* @param[out] t array of time-stamps
* @param[in] n number of elements to save in the array
* @param[in] flags tune the behaviour of the function.
...
...
@@ -524,6 +526,7 @@ int fmctdc_get_time(struct fmctdc_board *userb, struct fmctdc_time *t)
int
fmctdc_set_host_time
(
struct
fmctdc_board
*
userb
)
{
__define_board
(
b
,
userb
);
return
__fmctdc_command
(
b
,
FT_CMD_SET_HOST_TIME
);
}
...
...
@@ -537,6 +540,7 @@ int fmctdc_set_host_time(struct fmctdc_board *userb)
int
fmctdc_wr_mode
(
struct
fmctdc_board
*
userb
,
int
on
)
{
__define_board
(
b
,
userb
);
if
(
on
)
__fmctdc_command
(
b
,
FT_CMD_WR_ENABLE
);
else
...
...
@@ -554,6 +558,7 @@ int fmctdc_wr_mode(struct fmctdc_board *userb, int on)
extern
int
fmctdc_check_wr_mode
(
struct
fmctdc_board
*
userb
)
{
__define_board
(
b
,
userb
);
if
(
__fmctdc_command
(
b
,
FT_CMD_WR_QUERY
)
==
0
)
return
0
;
return
errno
;
...
...
@@ -576,12 +581,13 @@ int fmctdc_reference_set(struct fmctdc_board *userb,
uint32_t
ch_ref
=
ch_reference
;
char
path
[
64
];
if
(
ch_target
>=
FMCTDC_NUM_CHANNELS
||
ch_ref
>=
FMCTDC_NUM_CHANNELS
)
{
if
(
ch_target
>=
FMCTDC_NUM_CHANNELS
||
ch_ref
erence
>=
FMCTDC_NUM_CHANNELS
)
{
errno
=
EINVAL
;
return
-
1
;
}
snprintf
(
path
,
sizeof
(
path
),
"ft-ch%d/diff-reference"
,
ch_target
+
1
);
ch_ref
++
;
ch_ref
++
;
/* for the driver channel interval is [1, 5] */
return
fmctdc_sysfs_set
(
b
,
path
,
&
ch_ref
);
}
...
...
@@ -608,14 +614,14 @@ int fmctdc_reference_get(struct fmctdc_board *userb, unsigned int ch_target)
err
=
fmctdc_sysfs_get
(
b
,
path
,
&
ch_ref
);
if
(
err
)
return
-
1
;
return
ch_ref
-
1
;
return
ch_ref
-
1
;
/* For the driver channel interval is [1, 5]*/
}
/**
* It removes all samples from the channel buffer
* @param[in] userb TDC board instance token
* @param[in] channel target channel [
1, 5
]
* @param[in] channel target channel [
0, 4
]
* @return 0 on success, otherwise -1 and errno is set appropriately
*/
int
fmctdc_flush
(
struct
fmctdc_board
*
userb
,
unsigned
int
channel
)
...
...
@@ -645,7 +651,7 @@ int fmctdc_flush(struct fmctdc_board *userb, unsigned int channel)
}
while
(
i
>
0
);
/* Flush ZIO buffer */
snprintf
(
path
,
sizeof
(
path
),
"ft-ch%d/chan0/buffer/flush"
,
channel
);
snprintf
(
path
,
sizeof
(
path
),
"ft-ch%d/chan0/buffer/flush"
,
channel
+
1
);
err
=
fmctdc_sysfs_set
(
b
,
path
,
&
channel
);
if
(
err
)
{
return
err
;
...
...
lib/fmctdc-lib.h
View file @
dc89bcb1
...
...
@@ -16,12 +16,12 @@
#include <stdint.h>
enum
fmctdc_channel
{
FMCTDC_CH_1
=
1
,
FMCTDC_CH_2
=
2
,
FMCTDC_CH_3
=
3
,
FMCTDC_CH_4
=
4
,
FMCTDC_CH_5
=
5
,
FMCTDC_CH_LAST
=
5
,
FMCTDC_CH_1
=
0
,
FMCTDC_CH_2
,
FMCTDC_CH_3
,
FMCTDC_CH_4
,
FMCTDC_CH_5
,
FMCTDC_CH_LAST
=
4
,
FMCTDC_NUM_CHANNELS
=
5
};
...
...
tools/fmc-tdc-tstamp.c
View file @
dc89bcb1
...
...
@@ -119,7 +119,8 @@ int main(int argc, char **argv)
exit
(
1
);
}
memset
(
ref
,
0
,
sizeof
(
ref
));
for
(
i
=
0
;
i
<
FMCTDC_NUM_CHANNELS
;
++
i
)
ref
[
i
]
=
-
1
;
/* Parse Options */
while
((
opt
=
getopt
(
argc
,
argv
,
"hwns:d:"
))
!=
-
1
)
{
...
...
@@ -140,21 +141,21 @@ int main(int argc, char **argv)
break
;
case
'd'
:
sscanf
(
optarg
,
"%i,%i"
,
&
a
,
&
b
);
if
(
a
<
1
||
a
>
FMCTDC_NUM_CHANNELS
)
{
if
(
a
<
0
||
a
>
FMCTDC_CH_LAST
)
{
fprintf
(
stderr
,
"%s: invalid reference channel %d
\n
"
,
argv
[
0
],
a
);
help
(
argv
[
0
]);
exit
(
EXIT_FAILURE
);
}
if
(
b
<
0
||
b
>
FMCTDC_
NUM_CHANNELS
)
{
if
(
b
<
0
||
b
>
FMCTDC_
CH_LAST
)
{
fprintf
(
stderr
,
"%s: invalid target channel %d
\n
"
,
argv
[
0
],
b
);
help
(
argv
[
0
]);
exit
(
EXIT_FAILURE
);
}
ref
[
b
-
1
]
=
a
;
ref
[
b
]
=
a
;
break
;
}
}
...
...
@@ -188,27 +189,28 @@ int main(int argc, char **argv)
fmctdc_close
(
brd
);
exit
(
EXIT_FAILURE
);
}
channels
[
ch
-
FMCTDC_CH_1
]
=
fmctdc_fileno_channel
(
brd
,
ch
);
channels
[
ch
]
=
fmctdc_fileno_channel
(
brd
,
ch
);
chan_count
++
;
optind
++
;
}
/* If there are not channels, then dump them all */
if
(
!
chan_count
)
{
for
(
i
=
FMCTDC_CH_1
;
i
<=
FMCTDC_CH_LAST
;
i
++
)
{
channels
[
i
-
FMCTDC_CH_1
]
=
for
(
i
=
0
;
i
<
FMCTDC_NUM_CHANNELS
;
i
++
)
{
channels
[
i
]
=
fmctdc_fileno_channel
(
brd
,
i
);
ret
=
fmctdc_reference_set
(
brd
,
i
,
ref
[
i
-
1
]);
ret
=
fmctdc_reference_set
(
brd
,
i
,
ref
[
i
]);
if
(
ret
)
{
fprintf
(
stderr
,
"%s: cannot set reference mode
\n
"
,
argv
[
0
]);
"%s: cannot set reference mode
: %s
\n
"
,
argv
[
0
]
,
fmctdc_strerror
(
errno
)
);
fprintf
(
stderr
,
"%s: continue in normal mode
\n
"
,
argv
[
0
]);
"%s: continue in normal mode: %s
\n
"
,
argv
[
0
],
fmctdc_strerror
(
errno
));
ref
[
i
]
=
-
1
;
}
}
chan_count
=
FMCTDC_NUM_CHANNELS
;
chan_count
=
i
;
}
...
...
@@ -219,8 +221,8 @@ int main(int argc, char **argv)
/* Prepare the list of channel to observe */
FD_ZERO
(
&
rfds
);
for
(
i
=
FMCTDC_CH_1
;
i
<=
FMCTDC_CH_LAST
;
i
++
)
{
fd
=
channels
[
i
-
FMCTDC_CH_1
];
for
(
i
=
0
;
i
<=
FMCTDC_CH_LAST
;
i
++
)
{
fd
=
channels
[
i
];
if
(
fd
<
0
)
{
fprintf
(
stderr
,
"Can't open channel %d
\n
"
,
i
);
exit
(
EXIT_FAILURE
);
...
...
@@ -242,8 +244,8 @@ int main(int argc, char **argv)
}
/* Now we can read the timestamp */
for
(
i
=
FMCTDC_CH_1
;
i
<=
FMCTDC_CH_LAST
;
i
++
)
{
fd
=
channels
[
i
-
FMCTDC_CH_1
];
for
(
i
=
0
;
i
<=
FMCTDC_CH_LAST
;
i
++
)
{
fd
=
channels
[
i
];
if
(
fd
<
0
)
continue
;
...
...
@@ -253,7 +255,7 @@ int main(int argc, char **argv)
byte_read
=
fmctdc_read
(
brd
,
i
,
&
ts
,
1
,
nblock
?
O_NONBLOCK
:
0
);
if
(
byte_read
>
0
)
{
dump
(
i
,
&
ts
,
fmt_wr
,
!!
ref
[
i
-
1
]
);
dump
(
i
,
&
ts
,
fmt_wr
,
ref
[
i
]
<
0
?
0
:
1
);
ts_prev
[
i
]
=
ts
;
n
++
;
...
...
@@ -262,9 +264,9 @@ int main(int argc, char **argv)
}
/* Restore default time-stamping */
for
(
i
=
FMCTDC_CH_1
;
i
<=
FMCTDC_CH_LAST
;
i
++
)
{
if
(
channels
[
i
-
FMCTDC_CH_1
]
>
0
)
fmctdc_reference_clear
(
brd
,
i
);
for
(
i
=
0
;
i
<=
FMCTDC_CH_LAST
;
i
++
)
{
if
(
channels
[
i
]
>
0
)
fmctdc_reference_clear
(
brd
,
-
1
);
}
fmctdc_close
(
brd
);
...
...
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