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
5b2c4cac
Commit
5b2c4cac
authored
Oct 03, 2012
by
Miguel Gómez Sexto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
lib: close file after reading and use CHAN enumeration to select read channel
Signed-off-by:
Miguel Gomez
<
magomez@igalia.com
>
parent
8c05f03c
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
63 additions
and
18 deletions
+63
-18
libtdc.c
lib/libtdc.c
+62
-17
test.c
lib/test.c
+1
-1
No files found.
lib/libtdc.c
View file @
5b2c4cac
...
...
@@ -288,11 +288,25 @@ int tdc_clear_dacapo_flag(struct tdc_board *b)
return
__tdc_sysfs_set
(
b
,
"clear_dacapo_flag"
,
1
);
}
static
int
__tdc_chan_to_decimal
(
int
chan
)
{
int
ret
=
-
1
;
while
(
chan
>
0
)
{
chan
=
chan
>>
1
;
ret
++
;
}
return
ret
;
}
static
int
__tdc_valid_channel
(
struct
tdc_board
*
b
,
int
chan
)
{
if
(
chan
<
0
||
chan
>
4
)
{
int
chan_dec
;
chan_dec
=
__tdc_chan_to_decimal
(
chan
);
if
(
chan_dec
<
0
||
chan_dec
>
4
)
{
fprintf
(
stderr
,
"%s: Invalid channel: %i
\n
"
,
__func__
,
chan
);
__func__
,
chan
_dec
);
errno
=
EINVAL
;
return
0
;
}
...
...
@@ -304,9 +318,9 @@ static int __tdc_valid_channel(struct tdc_board *b, int chan)
return
0
;
}
if
(
!
(
b
->
chan_config
&
(
1
<<
chan
))
)
{
if
(
!
(
b
->
chan_config
&
chan
)
)
{
fprintf
(
stderr
,
"%s: Channel not enabled: %i
\n
"
,
__func__
,
chan
);
__func__
,
chan
_dec
);
errno
=
EINVAL
;
return
0
;
}
...
...
@@ -317,26 +331,50 @@ static int __tdc_valid_channel(struct tdc_board *b, int chan)
static
int
__tdc_open_file
(
struct
tdc_board
*
b
,
int
chan
)
{
char
fname
[
128
];
int
chan_dec
;
chan_dec
=
__tdc_chan_to_decimal
(
chan
);
sprintf
(
fname
,
"%s-%i-0-ctrl"
,
b
->
devbase
,
chan_dec
);
/* open file */
if
(
b
->
ctrl
[
chan
]
<=
0
)
{
sprintf
(
fname
,
"%s-%i-0-ctrl"
,
b
->
devbase
,
chan
);
b
->
ctrl
[
chan
]
=
open
(
fname
,
O_RDONLY
|
O_NONBLOCK
);
if
(
b
->
ctrl
[
chan_dec
]
<=
0
)
{
b
->
ctrl
[
chan_dec
]
=
open
(
fname
,
O_RDONLY
|
O_NONBLOCK
);
}
if
(
b
->
ctrl
[
chan
]
<
0
)
if
(
b
->
ctrl
[
chan
_dec
]
<
0
)
fprintf
(
stderr
,
"%s: Error opening file: %s
\n
"
,
__func__
,
fname
);
return
b
->
ctrl
[
chan
];
}
static
int
__tdc_close_file
(
struct
tdc_board
*
b
,
int
chan
)
{
int
ret
;
int
chan_dec
;
chan_dec
=
__tdc_chan_to_decimal
(
chan
);
ret
=
close
(
b
->
ctrl
[
chan_dec
]);
if
(
ret
)
{
char
fname
[
128
];
sprintf
(
fname
,
"%s-%i-0-ctrl"
,
b
->
devbase
,
chan_dec
);
fprintf
(
stderr
,
"%s: Error closing file: %s
\n
"
,
__func__
,
fname
);
return
-
1
;
}
b
->
ctrl
[
chan
]
=
-
1
;
return
0
;
}
int
tdc_read
(
struct
tdc_board
*
b
,
int
chan
,
struct
tdc_time
*
t
,
int
n
,
int
flags
)
{
struct
zio_control
ctrl
;
int
fd
,
i
,
j
;
fd_set
set
;
int
ret
=
0
;
if
(
!
__tdc_valid_channel
(
b
,
chan
))
return
-
1
;
...
...
@@ -362,26 +400,33 @@ int tdc_read(struct tdc_board *b, int chan, struct tdc_time *t,
/* some bytes read but not complete structure */
if
(
j
>
0
)
{
errno
=
EIO
;
return
-
1
;
ret
=
-
1
;
break
;
}
/* from here on, an error was returned */
/* real error, so exit */
if
(
errno
!=
EAGAIN
)
return
-
1
;
if
(
errno
!=
EAGAIN
)
{
ret
=
-
1
;
break
;
}
/* EAGAIN: if we can't block, return elements read */
if
(
flags
==
O_NONBLOCK
)
return
i
;
if
(
flags
==
O_NONBLOCK
)
{
ret
=
i
;
break
;
}
/* blocking read */
FD_ZERO
(
&
set
);
FD_SET
(
fd
,
&
set
);
if
(
select
(
fd
+
1
,
&
set
,
NULL
,
NULL
,
NULL
)
<
0
)
return
-
1
;
continue
;
if
(
select
(
fd
+
1
,
&
set
,
NULL
,
NULL
,
NULL
)
<
0
)
{
ret
=
-
1
;
break
;
}
}
return
i
;
__tdc_close_file
(
b
,
chan
);
return
ret
;
}
lib/test.c
View file @
5b2c4cac
...
...
@@ -155,7 +155,7 @@ int main(int argc, char **argv)
tdc_start_acquisition
(
b
);
for
(
i
=
0
;
i
<
100
;
i
++
)
{
/* this should be a blocking read */
res
=
tdc_read
(
b
,
0
,
&
t
,
1
,
0
);
res
=
tdc_read
(
b
,
CHAN
0
,
&
t
,
1
,
0
);
if
(
res
==
1
)
{
printf
(
"Got sample: utc %"
PRIu64
" ticks %"
PRIu64
" bins %"
PRIu64
" dacapo %i
\n
"
,
t
.
utc
,
t
.
ticks
,
t
.
bins
,
t
.
da_capo
);
...
...
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