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
8b486d46
Commit
8b486d46
authored
Sep 06, 2012
by
Miguel Gómez Sexto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
tdc: open and close functions added to the library.
Signed-off-by:
Miguel Gómez
<
magomez@igalia.com
>
parent
b0cd095f
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
51 additions
and
1 deletion
+51
-1
libtdc.c
lib/libtdc.c
+45
-1
test.c
lib/test.c
+6
-0
No files found.
lib/libtdc.c
View file @
8b486d46
...
...
@@ -4,6 +4,7 @@
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <errno.h>
#include "libtdc.h"
#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
...
...
@@ -49,7 +50,7 @@ int tdc_init(void)
b
->
ctrl
[
j
]
=
-
1
;
b
->
data
[
j
]
=
-
1
;
}
printf
(
"
Initialized device %s
"
,
b
->
sysbase
);
printf
(
"
Found device %s
\n
"
,
b
->
sysbase
);
}
globfree
(
&
glob_dev
);
globfree
(
&
glob_sys
);
...
...
@@ -87,10 +88,53 @@ void tdc_exit(void)
struct
tdc_board
*
tdc_open
(
int
offset
,
int
dev_id
)
{
struct
tdc_board
*
b
=
NULL
;
int
i
;
/* If we are given an offset, select the dev there */
/* If we are given an id, loop until we find it in the list */
/* If we are given an offset and an id, the id in pos offset must match */
if
(
offset
>=
tdc_nboards
)
{
errno
=
ENODEV
;
return
NULL
;
}
if
(
offset
>=
0
)
{
b
=
tdc_boards
+
offset
;
if
(
dev_id
>=
0
&&
dev_id
!=
b
->
dev_id
)
{
errno
=
EINVAL
;
return
NULL
;
}
goto
found
;
}
if
(
dev_id
<
0
)
{
errno
=
EINVAL
;
return
NULL
;
}
for
(
i
=
0
,
b
=
tdc_boards
;
i
<
tdc_nboards
;
i
++
,
b
++
)
if
(
b
->
dev_id
==
dev_id
)
goto
found
;
errno
=
ENODEV
;
return
NULL
;
found:
printf
(
"Opened device %s
\n
"
,
b
->
sysbase
);
return
b
;
}
extern
int
tdc_close
(
struct
tdc_board
*
b
)
{
int
j
;
for
(
j
=
0
;
j
<
ARRAY_SIZE
(
b
->
ctrl
);
j
++
)
{
if
(
b
->
ctrl
[
j
]
>=
0
)
close
(
b
->
ctrl
[
j
]);
b
->
ctrl
[
j
]
=
-
1
;
if
(
b
->
data
[
j
]
>=
0
)
close
(
b
->
data
[
j
]);
b
->
data
[
j
]
=
-
1
;
}
return
0
;
}
lib/test.c
View file @
8b486d46
...
...
@@ -6,6 +6,7 @@
int
main
(
int
argc
,
char
**
argv
)
{
struct
tdc_board
*
b
;
int
i
;
i
=
tdc_init
();
...
...
@@ -23,6 +24,11 @@ int main(int argc, char **argv)
argv
[
0
],
i
);
}
b
=
tdc_open
(
0
,
-
1
);
tdc_close
(
b
);
tdc_exit
();
return
0
;
}
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