Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
A
adc-lib
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
adc-lib
Commits
1dc4045e
Commit
1dc4045e
authored
Aug 14, 2020
by
Federico Vaga
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'release/v2.5.1' into master
parents
61a6d23d
97531247
Hide whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
169 additions
and
100 deletions
+169
-100
Makefile
Makefile
+5
-0
Makefile
lib/Makefile
+4
-1
adc-genericfake.c
lib/adc-genericfake.c
+8
-6
adc-zio.c
lib/adc-zio.c
+22
-11
buffer-zio.c
lib/buffer-zio.c
+4
-4
config-zio.c
lib/config-zio.c
+5
-5
fmc-adc-100m14b4cha.c
lib/fmc-adc-100m14b4cha.c
+54
-22
lib.c
lib/lib.c
+1
-0
route.c
lib/route.c
+3
-1
Makefile
tools/Makefile
+4
-0
adc-acq.c
tools/adc-acq.c
+56
-47
example.c
tools/example.c
+3
-3
No files found.
Makefile
View file @
1dc4045e
...
...
@@ -5,6 +5,8 @@ REPO_PARENT ?= $(shell /bin/pwd)/..
DIRS
=
lib tools
CPPCHECK
?=
cppcheck
all clean modules install modules_install
:
$(DIRS)
clean
:
TARGET = clean
...
...
@@ -16,4 +18,7 @@ tools: lib
$(DIRS)
:
$(MAKE)
-C
$@
$(TARGET)
cppcheck
:
$(CPPCHECK)
--enable
=
all ./
.PHONY
:
all clean modules install modules_install $(DIRS)
lib/Makefile
View file @
1dc4045e
...
...
@@ -39,6 +39,7 @@ CFLAGS += $(EXTRACFLAGS)
LDFLAGS
=
-L
.
-ladc
CC
?=
$(CROSS_COMPILE)
gcc
CPPCHECK
?=
cppcheck
modules all
:
$(LIB) $(LIBS)
...
...
@@ -52,6 +53,9 @@ $(LIB): $(LOBJ)
$(LIBS)
:
$(LIB)
$(CC)
-shared
-o
$@
-Wl
,--whole-archive,-soname,
$@
$^
-Wl
,--no-whole-archive
cppcheck
:
$(CPPCHECK)
--enable
=
all ./
clean
:
rm
-f
$(LIB)
$(LIBS)
.depend
*
.o
*
~
...
...
@@ -61,4 +65,3 @@ clean:
install modules_install
:
-include
.depend
lib/adc-genericfake.c
View file @
1dc4045e
...
...
@@ -105,11 +105,12 @@ static int adc_genfake_set_param(struct adc_dev *dev, char *name,
struct
__adc_dev_genfake
,
gid
);
unsigned
int
ind
,
type
;
if
(
name
==
NULL
)
{
ind
=
fg
->
conf_index
;
type
=
fg
->
conf_type
;
}
else
sscanf
(
name
,
"%
d/%d
"
,
&
type
,
&
ind
);
sscanf
(
name
,
"%
u/%u
"
,
&
type
,
&
ind
);
switch
(
type
){
case
ADC_CONF_TYPE_BRD
:
...
...
@@ -155,13 +156,13 @@ static int adc_genfake_get_param(struct adc_dev *dev, char *name,
struct
__adc_dev_genfake
*
fg
=
container_of
(
dev
,
struct
__adc_dev_genfake
,
gid
);
unsigned
int
ind
,
type
;
if
(
name
==
NULL
)
{
ind
=
fg
->
conf_index
;
type
=
fg
->
conf_type
;
}
else
sscanf
(
name
,
"%
d/%d
"
,
&
type
,
&
ind
);
sscanf
(
name
,
"%
u/%u
"
,
&
type
,
&
ind
);
switch
(
type
)
{
case
ADC_CONF_TYPE_BRD
:
...
...
@@ -208,8 +209,9 @@ static int adc_genfake_apply_config(struct adc_dev *dev, unsigned int flags,
struct
__adc_dev_genfake
,
gid
);
int
i
,
err
,
val
;
for
(
i
=
0
;
i
<
__ADC_CONF_LEN
;
i
++
)
{
if
(
!
(
conf
->
mask
&
(
1LL
<<
i
)))
if
(
!
(
conf
->
mask
&
(
1
U
LL
<<
i
)))
continue
;
fg
->
conf_index
=
i
;
fg
->
conf_type
=
conf
->
type
;
...
...
@@ -230,7 +232,7 @@ static int adc_genfake_retrieve_config(struct adc_dev *dev,
gid
);
int
i
,
err
,
val
;
for
(
i
=
0
;
i
<
__ADC_CONF_LEN
;
i
++
)
{
if
(
!
(
conf
->
mask
&
(
1LL
<<
i
)))
if
(
!
(
conf
->
mask
&
(
1
U
LL
<<
i
)))
continue
;
fg
->
conf_index
=
i
;
fg
->
conf_type
=
conf
->
type
;
...
...
@@ -324,7 +326,7 @@ static int adc_genfake_fill_buffer(struct adc_dev *dev,
for
(
i
=
0
;
i
<
datalen
;
i
+=
sizeof
(
datum
))
{
datum
=
rand
()
%
256
;
sprintf
(
buf
->
data
+
i
,
"%c"
,
datum
);
sprintf
(
buf
->
data
+
i
,
"%c"
,
datum
);
}
return
0
;
...
...
lib/adc-zio.c
View file @
1dc4045e
...
...
@@ -38,16 +38,18 @@ static int adc_flush_input(struct __adc_dev_zio *fa)
.
fd
=
fa
->
fdc
,
.
events
=
POLLIN
|
POLLERR
,
};
int
i
;
/* Read the control until one is there; data is discarded by zio */
while
(
1
)
{
i
=
poll
(
&
p
,
1
,
0
);
int
ret
;
int
i
=
poll
(
&
p
,
1
,
0
);
if
(
i
<
0
)
return
-
1
;
if
((
p
.
revents
&
POLLIN
)
==
0
)
return
0
;
read
(
fa
->
fdc
,
&
ctrl
,
sizeof
(
ctrl
));
ret
=
read
(
fa
->
fdc
,
&
ctrl
,
sizeof
(
ctrl
));
if
(
ret
!=
sizeof
(
ctrl
))
return
-
1
;
}
}
...
...
@@ -62,17 +64,24 @@ struct adc_dev *adc_zio_open(const struct adc_board_type *b,
struct
stat
st
;
char
*
syspath
,
*
devpath
,
fname
[
128
];
int
udev_zio_dir
=
1
;
int
ret
;
/* Check if device exists by looking in sysfs */
asprintf
(
&
syspath
,
"%s/%s-%04x"
,
ZIO_SYS_PATH
,
b
->
devname
,
dev_id
);
ret
=
asprintf
(
&
syspath
,
"%s/%s-%04x"
,
ZIO_SYS_PATH
,
b
->
devname
,
dev_id
);
if
(
ret
<
0
)
goto
out_str_alloc_syspath
;
if
(
stat
(
syspath
,
&
st
))
goto
out_fa_stat
;
/* ENOENT or equivalent */
/* ZIO char devices are in /dev/zio or just /dev (older udev) */
if
(
stat
(
"/dev/zio"
,
&
st
)
<
0
)
udev_zio_dir
=
0
;
asprintf
(
&
devpath
,
"%s/%s-%04x"
,
(
udev_zio_dir
?
"/dev/zio"
:
"/dev"
),
b
->
devname
,
dev_id
);
ret
=
asprintf
(
&
devpath
,
"%s/%s-%04x"
,
(
udev_zio_dir
?
"/dev/zio"
:
"/dev"
),
b
->
devname
,
dev_id
);
if
(
ret
<
0
)
goto
out_str_alloc_devpath
;
/* Sysfs path exists, so device is there, hopefully */
fa
=
calloc
(
1
,
sizeof
(
*
fa
));
...
...
@@ -82,18 +91,19 @@ struct adc_dev *adc_zio_open(const struct adc_board_type *b,
fa
->
devbase
=
devpath
;
fa
->
cset
=
cset
;
fa
->
chan
=
chan
;
fa
->
dev_id
=
dev_id
;
/* Open char devices */
if
(
chan
==
~
0
)
{
sprintf
(
fname
,
"%s-%
d
-i-ctrl"
,
fa
->
devbase
,
fa
->
cset
);
sprintf
(
fname
,
"%s-%
u
-i-ctrl"
,
fa
->
devbase
,
fa
->
cset
);
fa
->
fdc
=
open
(
fname
,
O_RDONLY
);
sprintf
(
fname
,
"%s-%
d
-i-data"
,
fa
->
devbase
,
fa
->
cset
);
sprintf
(
fname
,
"%s-%
u
-i-data"
,
fa
->
devbase
,
fa
->
cset
);
fa
->
fdd
=
open
(
fname
,
O_RDONLY
);
}
else
{
sprintf
(
fname
,
"%s-%
d
-%d-ctrl"
,
sprintf
(
fname
,
"%s-%
u
-%d-ctrl"
,
fa
->
devbase
,
fa
->
cset
,
fa
->
chan
);
fa
->
fdc
=
open
(
fname
,
O_RDONLY
);
sprintf
(
fname
,
"%s-%
d
-%d-data"
,
sprintf
(
fname
,
"%s-%
u
-%d-data"
,
fa
->
devbase
,
fa
->
cset
,
fa
->
chan
);
fa
->
fdd
=
open
(
fname
,
O_RDONLY
);
}
...
...
@@ -125,9 +135,10 @@ out_fa_open:
free
(
fa
);
out_fa_alloc:
free
(
devpath
);
out_str_alloc_devpath:
out_fa_stat:
free
(
syspath
);
out_str_alloc_syspath:
return
NULL
;
}
...
...
lib/buffer-zio.c
View file @
1dc4045e
...
...
@@ -29,7 +29,6 @@
static
int
adc_zio_read_ctrl
(
struct
__adc_dev_zio
*
fa
,
struct
adc_buffer
*
buf
)
{
struct
zio_control
*
ctrl
;
int
i
;
i
=
read
(
fa
->
fdc
,
buf
->
metadata
,
sizeof
(
struct
zio_control
));
...
...
@@ -49,8 +48,8 @@ static int adc_zio_read_ctrl(struct __adc_dev_zio *fa,
return
-
1
;
default:
if
(
fa
->
flags
&
ADC_FLAG_VERBOSE
)
fprintf
(
stderr
,
"%s: read: %i bytes (expected %z
i
)
\n
"
,
__func__
,
i
,
sizeof
(
ctr
l
));
fprintf
(
stderr
,
"%s: read: %i bytes (expected %z
u
)
\n
"
,
__func__
,
i
,
sizeof
(
struct
zio_contro
l
));
return
-
1
;
}
}
...
...
@@ -117,10 +116,11 @@ struct adc_buffer *adc_zio_request_buffer(struct adc_dev *dev,
{
struct
__adc_dev_zio
*
fa
=
to_dev_zio
(
dev
);
struct
adc_buffer
*
buf
;
char
s
[
16
];
/* If this is the first buffer, we need to know which kind it is */
if
((
fa
->
flags
&
(
ADC_FLAG_MALLOC
|
ADC_FLAG_MMAP
))
==
0
)
{
char
s
[
16
];
adc_get_param
(
dev
,
"cset0/current_buffer"
,
s
,
NULL
);
if
(
!
strcmp
(
s
,
"vmalloc"
))
fa
->
flags
|=
ADC_FLAG_MMAP
;
...
...
lib/config-zio.c
View file @
1dc4045e
...
...
@@ -225,28 +225,28 @@ static int adc_zio_config_chn(struct __adc_dev_zio *fa, unsigned int ch,
switch
(
index
)
{
case
ADC_CONF_CHN_RANGE
:
sprintf
(
path
,
"cset%
d/ch%d
-vref"
,
fa
->
cset
,
ch
);
sprintf
(
path
,
"cset%
u/ch%u
-vref"
,
fa
->
cset
,
ch
);
if
(
direction
)
return
adc_zio_sysfs_set
(
fa
,
path
,
value
);
else
return
adc_zio_sysfs_get
(
fa
,
path
,
value
);
break
;
case
ADC_CONF_CHN_TERMINATION
:
sprintf
(
path
,
"cset%
d/ch%d
-50ohm-term"
,
fa
->
cset
,
ch
);
sprintf
(
path
,
"cset%
u/ch%u
-50ohm-term"
,
fa
->
cset
,
ch
);
if
(
direction
)
return
adc_zio_sysfs_set
(
fa
,
path
,
value
);
else
return
adc_zio_sysfs_get
(
fa
,
path
,
value
);
break
;
case
ADC_CONF_CHN_OFFSET
:
sprintf
(
path
,
"cset%
d/ch%d
-offset"
,
fa
->
cset
,
ch
);
sprintf
(
path
,
"cset%
u/ch%u
-offset"
,
fa
->
cset
,
ch
);
if
(
direction
)
return
adc_zio_sysfs_set
(
fa
,
path
,
value
);
else
return
adc_zio_sysfs_get
(
fa
,
path
,
value
);
break
;
case
ADC_CONF_CHN_SATURATION
:
sprintf
(
path
,
"cset%
d/ch%d
-saturation"
,
fa
->
cset
,
ch
);
sprintf
(
path
,
"cset%
u/ch%u
-saturation"
,
fa
->
cset
,
ch
);
if
(
direction
)
return
adc_zio_sysfs_set
(
fa
,
path
,
value
);
else
...
...
@@ -298,7 +298,7 @@ static int adc_zio_config(struct __adc_dev_zio *fa, unsigned int flags,
}
for
(
i
=
0
;
i
<
__ADC_CONF_LEN
;
++
i
)
{
if
(
!
(
conf
->
mask
&
(
1LL
<<
i
)))
if
(
!
(
conf
->
mask
&
(
1
U
LL
<<
i
)))
continue
;
/* Parameter to configure */
...
...
lib/fmc-adc-100m14b4cha.c
View file @
1dc4045e
...
...
@@ -53,7 +53,9 @@
(1LL << ADC_CONF_BRD_N_CHAN) | \
(1LL << ADC_CONF_BRD_N_TRG_EXT) | \
(1LL << ADC_CONF_BRD_N_TRG_THR) | \
(1LL << ADC_CONF_BRD_N_TRG_TIM)
(1LL << ADC_CONF_BRD_N_TRG_TIM) | \
(1LL << ADC_CONF_UTC_TIMING_BASE_S) | \
(1LL << ADC_CONF_UTC_TIMING_BASE_T)
#define ADC_100M_4CH_14BIT_CUS_MASK (1ULL << ADC_CONF_100M14B4CHA_BUF_TYPE) | \
(1ULL << ADC_CONF_100M14B4CHA_TRG_SW_EN) | \
(1ULL << ADC_CONF_100M14B4CHA_ACQ_MSHOT_MAX) | \
...
...
@@ -100,7 +102,7 @@ static int adc_100m14b4cha_buffer_resize(struct adc_dev *dev,
struct
__adc_dev_zio
*
fa
=
to_dev_zio
(
dev
);
unsigned
long
max
=
nbuffers
*
(
totalsamples
*
fa
->
samplesize
);
enum
adc_100m14b4cha_buf_type
type
;
char
str
[
3
2
];
char
str
[
3
4
];
int
err
,
val
;
err
=
adc_get_param
(
dev
,
"cset0/current_buffer"
,
str
,
NULL
);
...
...
@@ -312,7 +314,23 @@ static int adc_100m14b4cha_config_brd(struct adc_dev *adc,
*
value
=
1
;
return
0
;
}
case
ADC_CONF_UTC_TIMING_BASE_S
:
if
(
direction
)
{
errno
=
ADC_ENOSET
;
return
-
1
;
}
else
{
return
adc_get_param
(
adc
,
"cset0/tstamp-base-sl"
,
NULL
,
(
int
*
)
value
);
}
case
ADC_CONF_UTC_TIMING_BASE_T
:
if
(
direction
)
{
errno
=
ADC_ENOSET
;
return
-
1
;
}
else
{
*
value
=
1
;
return
adc_get_param
(
adc
,
"cset0/tstamp-base-t"
,
NULL
,
(
int
*
)
value
);
}
default:
errno
=
ADC_ENOCAP
;
return
-
1
;
...
...
@@ -414,19 +432,19 @@ static int adc_100m14b4cha_config_chn(struct adc_dev *adc,
switch
(
index
)
{
case
ADC_CONF_CHN_RANGE
:
sprintf
(
path
,
"cset%
d/ch%d
-vref"
,
fa
->
cset
,
source
);
sprintf
(
path
,
"cset%
u/ch%u
-vref"
,
fa
->
cset
,
source
);
break
;
case
ADC_CONF_CHN_TERMINATION
:
sprintf
(
path
,
"cset%
d/ch%d
-50ohm-term"
,
fa
->
cset
,
source
);
sprintf
(
path
,
"cset%
u/ch%u
-50ohm-term"
,
fa
->
cset
,
source
);
break
;
case
ADC_CONF_CHN_OFFSET
:
sprintf
(
path
,
"cset%
d/ch%d
-offset"
,
fa
->
cset
,
source
);
sprintf
(
path
,
"cset%
u/ch%u
-offset"
,
fa
->
cset
,
source
);
break
;
case
__ADC_CONF_CHN_OFFSET_ZERO
:
sprintf
(
path
,
"cset%
d/ch%d
-offset-zero"
,
fa
->
cset
,
source
);
sprintf
(
path
,
"cset%
u/ch%u
-offset-zero"
,
fa
->
cset
,
source
);
break
;
case
ADC_CONF_CHN_SATURATION
:
sprintf
(
path
,
"cset%
d/ch%d
-saturation"
,
fa
->
cset
,
source
);
sprintf
(
path
,
"cset%
u/ch%u
-saturation"
,
fa
->
cset
,
source
);
break
;
default:
errno
=
ADC_ENOCAP
;
...
...
@@ -475,7 +493,7 @@ static int __config_trg_enable(struct adc_dev *adc,
*
value
=
!!
(
tmp
&
mask
);
}
return
0
;
return
err
;
}
...
...
@@ -596,13 +614,13 @@ static int adc_100m14b4cha_config_trg_thr(struct adc_dev *adc,
}
break
;
case
ADC_CONF_TRG_THR_DELAY
:
sprintf
(
path
,
"cset0/trigger/ch%
d
-delay"
,
source
);
sprintf
(
path
,
"cset0/trigger/ch%
u
-delay"
,
source
);
return
adc_param
[
direction
](
adc
,
path
,
NULL
,
(
int
*
)
value
);
case
ADC_CONF_TRG_THR_THRESHOLD
:
sprintf
(
path
,
"cset0/trigger/ch%
d
-threshold"
,
source
);
sprintf
(
path
,
"cset0/trigger/ch%
u
-threshold"
,
source
);
return
adc_param
[
direction
](
adc
,
path
,
NULL
,
(
int
*
)
value
);
case
ADC_CONF_TRG_THR_HYSTERESIS
:
sprintf
(
path
,
"cset0/trigger/ch%
d
-hysteresis"
,
source
);
sprintf
(
path
,
"cset0/trigger/ch%
u
-hysteresis"
,
source
);
return
adc_param
[
direction
](
adc
,
path
,
NULL
,
(
int
*
)
value
);
default:
errno
=
ADC_ENOCAP
;
...
...
@@ -748,7 +766,7 @@ static int adc_100m14b4cha_config(struct adc_dev *adc,
}
for
(
i
=
0
;
i
<
__ADC_CONF_LEN
;
++
i
)
{
if
(
!
(
conf
->
mask
&
(
1LL
<<
i
)))
if
(
!
(
conf
->
mask
&
(
1
U
LL
<<
i
)))
continue
;
/* Parameter to configure */
...
...
@@ -853,10 +871,24 @@ static int adc_100m14b4cha_retrieve_config(struct adc_dev *dev,
*/
static
int
adc_100m14b4cha_trigger_fire
(
struct
adc_dev
*
dev
)
{
int
value
=
1
;
return
adc_set_param
(
dev
,
"cset0/trigger/sw-trg-fire"
,
NULL
,
&
value
);
struct
__adc_dev_zio
*
fa
=
to_dev_zio
(
dev
);
char
pathname
[
128
];
int
fd
,
ret
;
snprintf
(
pathname
,
sizeof
(
pathname
),
"/sys/kernel/debug/adc-100m14b-%04x/trigger_software"
,
fa
->
dev_id
);
fd
=
open
(
pathname
,
O_WRONLY
);
if
(
fd
<
0
)
return
-
1
;
ret
=
write
(
fd
,
"1"
,
1
);
close
(
fd
);
if
(
ret
<
0
)
return
-
1
;
if
(
ret
==
1
)
return
0
;
errno
=
EIO
;
return
-
1
;
}
static
int
adc_100m14b4cha_buffer_get_sample
(
struct
adc_buffer
*
buf
,
...
...
@@ -1170,13 +1202,13 @@ static int adc_100m14b4cha_offset_zero_set(struct adc_dev *dev)
static
int
adc_100m14b4cha_range_set_all
(
struct
adc_dev
*
dev
,
enum
adc_configuration_100m14b4cha_channel_range
range
)
{
int
i
,
err
;
int
i
;
for
(
i
=
0
;
i
<
FA100M14B4C_NCHAN
;
++
i
)
{
err
=
adc_100m14b4cha_config_chn
(
dev
,
i
,
ADC_CONF_CHN_RANGE
,
&
range
,
ADC_CONF_SET
);
int
err
=
adc_100m14b4cha_config_chn
(
dev
,
i
,
ADC_CONF_CHN_RANGE
,
&
range
,
ADC_CONF_SET
);
if
(
err
)
return
err
;
}
...
...
lib/lib.c
View file @
1dc4045e
...
...
@@ -133,6 +133,7 @@ int adc_get_conf(struct adc_conf *conf, unsigned int conf_index,
*
val
=
conf
->
value
[
conf_index
];
return
0
;
}
else
{
errno
=
ADC_ENOMASK
;
return
-
1
;
}
}
...
...
lib/route.c
View file @
1dc4045e
...
...
@@ -127,7 +127,7 @@ struct adc_dev *adc_open_by_lun(char *name, int lun,
ssize_t
ret
;
char
dev_id_str
[
8
];
char
path
[
PATH_MAX
];
in
t
dev_id
;
uint32_
t
dev_id
;
ret
=
snprintf
(
path
,
sizeof
(
path
),
"/dev/%s.%d"
,
"adc-100m14b"
/* FIXME: this must be generic */
,
...
...
@@ -137,6 +137,8 @@ struct adc_dev *adc_open_by_lun(char *name, int lun,
return
NULL
;
}
ret
=
readlink
(
path
,
dev_id_str
,
sizeof
(
dev_id_str
));
if
(
ret
<
0
)
return
NULL
;
if
(
sscanf
(
dev_id_str
,
"%4x"
,
&
dev_id
)
!=
1
)
{
errno
=
ENODEV
;
return
NULL
;
...
...
tools/Makefile
View file @
1dc4045e
...
...
@@ -23,6 +23,7 @@ LDLIBS += -Wl,-Bdynamic -lrt
DEMOS
:=
adc-acq
DEMOS
+=
example
CPPCHECK
?=
cppcheck
all
:
demo
...
...
@@ -35,6 +36,9 @@ install:
%
:
%.c $(LIBADC)/libadc.a
$(CC)
$(CFLAGS)
$^
-o
$@
$(LDFLAGS)
$(LDLIBS)
cppcheck
:
$(CPPCHECK)
--enable
=
all ./
# make nothing for modules_install, but avoid errors
modules_install
:
...
...
tools/adc-acq.c
View file @
1dc4045e
...
...
@@ -211,37 +211,37 @@ static void fald_acq_print_config(struct adc_dev *adc)
}
else
{
err
=
adc_get_conf
(
&
cfg_brd
,
ADC_CONF_BRD_STATUS
,
&
value
);
if
(
!
err
)
fprintf
(
stdout
,
"
\t
Status: %
d
\n
"
,
value
);
fprintf
(
stdout
,
"
\t
Status: %
u
\n
"
,
value
);
err
=
adc_get_conf
(
&
cfg_brd
,
ADC_CONF_BRD_STATE_MACHINE_STATUS
,
&
value
);
if
(
!
err
)
fprintf
(
stdout
,
"
\t
State machine: %
d
\n
"
,
value
);
fprintf
(
stdout
,
"
\t
State machine: %
u
\n
"
,
value
);
err
=
adc_get_conf
(
&
cfg_brd
,
ADC_CONF_BRD_MAX_FREQ_HZ
,
&
value
);
if
(
!
err
)
fprintf
(
stdout
,
"
\t
Max sampling frequency: %
d
\n
"
,
value
);
fprintf
(
stdout
,
"
\t
Max sampling frequency: %
u
\n
"
,
value
);
err
=
adc_get_conf
(
&
cfg_brd
,
ADC_CONF_BRD_MIN_FREQ_HZ
,
&
value
);
if
(
!
err
)
fprintf
(
stdout
,
"
\t
Min sampling frequency: %
d
\n
"
,
value
);
fprintf
(
stdout
,
"
\t
Min sampling frequency: %
u
\n
"
,
value
);
err
=
adc_get_conf
(
&
cfg_brd
,
ADC_CONF_BRD_N_CHAN
,
&
value
);
if
(
!
err
)
fprintf
(
stdout
,
"
\t
Number of channels: %
d
\n
"
,
value
);
fprintf
(
stdout
,
"
\t
Number of channels: %
u
\n
"
,
value
);
err
=
adc_get_conf
(
&
cfg_brd
,
ADC_CONF_BRD_N_TRG_EXT
,
&
value
);
if
(
!
err
)
fprintf
(
stdout
,
"
\t
Number of external triggers: %
d
\n
"
,
value
);
fprintf
(
stdout
,
"
\t
Number of external triggers: %
u
\n
"
,
value
);
err
=
adc_get_conf
(
&
cfg_brd
,
ADC_CONF_BRD_N_TRG_THR
,
&
value
);
if
(
!
err
)
fprintf
(
stdout
,
"
\t
Number of threshold triggers: %
d
\n
"
,
value
);
fprintf
(
stdout
,
"
\t
Number of threshold triggers: %
u
\n
"
,
value
);
err
=
adc_get_conf
(
&
cfg_brd
,
ADC_CONF_BRD_N_TRG_TIM
,
&
value
);
if
(
!
err
)
fprintf
(
stdout
,
"
\t
Number of timer triggers: %
d
\n
"
,
value
);
fprintf
(
stdout
,
"
\t
Number of timer triggers: %
u
\n
"
,
value
);
err
=
adc_get_conf
(
&
cfg_brd
,
ADC_CONF_UTC_TIMING_BASE_S
,
&
value
);
if
(
!
err
)
fprintf
(
stdout
,
"
\t
Time Seconds: %
d
\n
"
,
value
);
fprintf
(
stdout
,
"
\t
Time Seconds: %
u
\n
"
,
value
);
err
=
adc_get_conf
(
&
cfg_brd
,
ADC_CONF_UTC_TIMING_BASE_T
,
&
value
);
if
(
!
err
)
fprintf
(
stdout
,
"
\t
Time sub-second ticks: %
d
\n
"
,
value
);
fprintf
(
stdout
,
"
\t
Time sub-second ticks: %
u
\n
"
,
value
);
err
=
adc_get_conf
(
&
cfg_brd
,
ADC_CONF_UTC_TIMING_BASE_B
,
&
value
);
if
(
!
err
)
fprintf
(
stdout
,
"
\t
Time sub-second bins: %
d
\n
"
,
value
);
fprintf
(
stdout
,
"
\t
Time sub-second bins: %
u
\n
"
,
value
);
}
fprintf
(
stdout
,
"Acquisition Configuration
\n
"
);
...
...
@@ -256,22 +256,22 @@ static void fald_acq_print_config(struct adc_dev *adc)
}
else
{
err
=
adc_get_conf
(
&
cfg
,
ADC_CONF_ACQ_N_SHOTS
,
&
value
);
if
(
!
err
)
fprintf
(
stdout
,
"
\t
Shots: %
d
\n
"
,
value
);
fprintf
(
stdout
,
"
\t
Shots: %
u
\n
"
,
value
);
err
=
adc_get_conf
(
&
cfg
,
ADC_CONF_ACQ_PRE_SAMP
,
&
value
);
if
(
!
err
)
fprintf
(
stdout
,
"
\t
Pre samples: %
d
\n
"
,
value
);
fprintf
(
stdout
,
"
\t
Pre samples: %
u
\n
"
,
value
);
err
=
adc_get_conf
(
&
cfg
,
ADC_CONF_ACQ_POST_SAMP
,
&
value
);
if
(
!
err
)
fprintf
(
stdout
,
"
\t
Post samples: %
d
\n
"
,
value
);
fprintf
(
stdout
,
"
\t
Post samples: %
u
\n
"
,
value
);
err
=
adc_get_conf
(
&
cfg
,
ADC_CONF_ACQ_UNDERSAMPLE
,
&
value
);
if
(
!
err
)
fprintf
(
stdout
,
"
\t
Undersample (decimation): %
d
\n
"
,
value
);
fprintf
(
stdout
,
"
\t
Undersample (decimation): %
u
\n
"
,
value
);
err
=
adc_get_conf
(
&
cfg
,
ADC_CONF_ACQ_FREQ_HZ
,
&
value
);
if
(
!
err
)
fprintf
(
stdout
,
"
\t
Sampling rate: %
d
Hz
\n
"
,
value
);
fprintf
(
stdout
,
"
\t
Sampling rate: %
u
Hz
\n
"
,
value
);
err
=
adc_get_conf
(
&
cfg
,
ADC_CONF_ACQ_N_BITS
,
&
value
);
if
(
!
err
)
fprintf
(
stdout
,
"
\t
Bit per sample: %
d
\n
"
,
value
);
fprintf
(
stdout
,
"
\t
Bit per sample: %
u
\n
"
,
value
);
}
fprintf
(
stdout
,
"Channel Configuration
\n
"
);
...
...
@@ -292,16 +292,16 @@ static void fald_acq_print_config(struct adc_dev *adc)
}
else
{
err
=
adc_get_conf
(
&
cfg
,
ADC_CONF_CHN_RANGE
,
&
value
);
if
(
!
err
)
fprintf
(
stdout
,
"
\t\t
Range: %
d
\n
"
,
value
);
fprintf
(
stdout
,
"
\t\t
Range: %
u
\n
"
,
value
);
err
=
adc_get_conf
(
&
cfg
,
ADC_CONF_CHN_OFFSET
,
&
value
);
if
(
!
err
)
fprintf
(
stdout
,
"
\t\t
Offset: %
d
\n
"
,
value
);
fprintf
(
stdout
,
"
\t\t
Offset: %
u
\n
"
,
value
);
err
=
adc_get_conf
(
&
cfg
,
ADC_CONF_CHN_SATURATION
,
&
value
);
if
(
!
err
)
fprintf
(
stdout
,
"
\t\t
Saturation: %
d
\n
"
,
value
);
fprintf
(
stdout
,
"
\t\t
Saturation: %
u
\n
"
,
value
);
err
=
adc_get_conf
(
&
cfg
,
ADC_CONF_CHN_TERMINATION
,
&
value
);
if
(
!
err
)
fprintf
(
stdout
,
"
\t\t
Termination: %
d
\n
"
,
value
);
fprintf
(
stdout
,
"
\t\t
Termination: %
u
\n
"
,
value
);
}
}
...
...
@@ -323,13 +323,13 @@ static void fald_acq_print_config(struct adc_dev *adc)
}
else
{
err
=
adc_get_conf
(
&
cfg
,
ADC_CONF_TRG_EXT_ENABLE
,
&
value
);
if
(
!
err
)
fprintf
(
stdout
,
"
\t\t
Enable: %
d
\n
"
,
value
);
fprintf
(
stdout
,
"
\t\t
Enable: %
u
\n
"
,
value
);
err
=
adc_get_conf
(
&
cfg
,
ADC_CONF_TRG_EXT_POLARITY
,
&
value
);
if
(
!
err
)
fprintf
(
stdout
,
"
\t\t
Polarity: %
d
\n
"
,
value
);
fprintf
(
stdout
,
"
\t\t
Polarity: %
u
\n
"
,
value
);
err
=
adc_get_conf
(
&
cfg
,
ADC_CONF_TRG_EXT_DELAY
,
&
value
);
if
(
!
err
)
fprintf
(
stdout
,
"
\t\t
Delay: %
d
\n
"
,
value
);
fprintf
(
stdout
,
"
\t\t
Delay: %
u
\n
"
,
value
);
}
}
...
...
@@ -351,19 +351,19 @@ static void fald_acq_print_config(struct adc_dev *adc)
}
else
{
err
=
adc_get_conf
(
&
cfg
,
ADC_CONF_TRG_THR_ENABLE
,
&
value
);
if
(
!
err
)
fprintf
(
stdout
,
"
\t\t
Enable: %
d
\n
"
,
value
);
fprintf
(
stdout
,
"
\t\t
Enable: %
u
\n
"
,
value
);
err
=
adc_get_conf
(
&
cfg
,
ADC_CONF_TRG_THR_POLARITY
,
&
value
);
if
(
!
err
)
fprintf
(
stdout
,
"
\t\t
Polarity: %
d
\n
"
,
value
);
fprintf
(
stdout
,
"
\t\t
Polarity: %
u
\n
"
,
value
);
err
=
adc_get_conf
(
&
cfg
,
ADC_CONF_TRG_THR_DELAY
,
&
value
);
if
(
!
err
)
fprintf
(
stdout
,
"
\t\t
Delay: %
d
\n
"
,
value
);
fprintf
(
stdout
,
"
\t\t
Delay: %
u
\n
"
,
value
);
err
=
adc_get_conf
(
&
cfg
,
ADC_CONF_TRG_THR_THRESHOLD
,
&
value
);
if
(
!
err
)
fprintf
(
stdout
,
"
\t\t
Threshold: %
d
\n
"
,
value
);
fprintf
(
stdout
,
"
\t\t
Threshold: %
u
\n
"
,
value
);
err
=
adc_get_conf
(
&
cfg
,
ADC_CONF_TRG_THR_HYSTERESIS
,
&
value
);
if
(
!
err
)
fprintf
(
stdout
,
"
\t\t
Hysteresis: %
d
\n
"
,
value
);
fprintf
(
stdout
,
"
\t\t
Hysteresis: %
u
\n
"
,
value
);
}
}
...
...
@@ -385,13 +385,13 @@ static void fald_acq_print_config(struct adc_dev *adc)
}
else
{
err
=
adc_get_conf
(
&
cfg
,
ADC_CONF_TRG_TIM_ENABLE
,
&
value
);
if
(
!
err
)
fprintf
(
stdout
,
"
\t\t
Enable: %
d
\n
"
,
value
);
fprintf
(
stdout
,
"
\t\t
Enable: %
u
\n
"
,
value
);
err
=
adc_get_conf
(
&
cfg
,
ADC_CONF_TRG_TIM_SECONDS
,
&
value
);
if
(
!
err
)
fprintf
(
stdout
,
"
\t\t
Seconds: %
d
\n
"
,
value
);
fprintf
(
stdout
,
"
\t\t
Seconds: %
u
\n
"
,
value
);
err
=
adc_get_conf
(
&
cfg
,
ADC_CONF_TRG_TIM_NANO_SECONDS
,
&
value
);
if
(
!
err
)
fprintf
(
stdout
,
"
\t\t
Nanoseconds: %
d
\n
"
,
value
);
fprintf
(
stdout
,
"
\t\t
Nanoseconds: %
u
\n
"
,
value
);
}
}
}
...
...
@@ -410,7 +410,6 @@ static int write_file(const char *filename, int ch, int16_t *pdata,
{
FILE
*
filp
;
int
i
;
double
val
;
int
mask
=
umask
(
0
);
/* set umask to have a file with 0666 mode */
filp
=
fopen
(
filename
,
"w"
);
...
...
@@ -420,7 +419,7 @@ static int write_file(const char *filename, int ch, int16_t *pdata,
return
-
1
;
}
for
(
i
=
0
,
pdata
+=
(
ch
-
1
);
i
<
n_sample
;
++
i
,
pdata
+=
4
)
{
val
=
(
*
pdata
)
*
bit_scale
;
double
val
=
(
*
pdata
)
*
bit_scale
;
fprintf
(
filp
,
"%d %g
\n
"
,
i
,
val
);
}
if
(
fclose
(
filp
)
<
0
)
...
...
@@ -928,10 +927,12 @@ static int fald_acq_write_single(struct adc_buffer *buf)
n
=
fwrite
(
data
,
buf
->
samplesize
,
buf
->
nsamples
,
f
);
if
(
n
!=
buf
->
nsamples
)
err
++
;
fclose
(
f
);
if
(
err
)
{
fprintf
(
stderr
,
"write(%s): short write
\n
"
,
basefile
);
return
-
1
;
}
...
...
@@ -957,7 +958,7 @@ static int fald_acq_write_multiple(struct adc_buffer *buf,
/* FIXME zio control is specific. The library should provide
at least the metadata size so that automatic tools can at least
read */
sprintf
(
fname
,
"%s.%03
i
.ctrl"
,
basefile
,
shot_i
);
sprintf
(
fname
,
"%s.%03
u
.ctrl"
,
basefile
,
shot_i
);
f
=
fopen
(
fname
,
"w"
);
if
(
!
f
)
{
fprintf
(
stderr
,
"%s: %s
\n
"
,
...
...
@@ -965,13 +966,15 @@ static int fald_acq_write_multiple(struct adc_buffer *buf,
return
-
1
;
}
ctrl
=
buf
->
metadata
;
if
(
fwrite
(
ctrl
,
sizeof
(
struct
zio_control
),
1
,
f
)
!=
1
)
{
n
=
fwrite
(
ctrl
,
sizeof
(
struct
zio_control
),
1
,
f
)
fclose
(
f
);
if
(
n
!=
1
)
{
fprintf
(
stderr
,
"write(%s): short write
\n
"
,
fname
);
return
-
1
;
}
fclose
(
f
);
#endif
sprintf
(
fname
,
"%s.%03
i
.data"
,
basefile
,
shot_i
);
sprintf
(
fname
,
"%s.%03
u
.data"
,
basefile
,
shot_i
);
f
=
fopen
(
fname
,
"w"
);
if
(
!
f
)
{
fprintf
(
stderr
,
"%s: %s
\n
"
,
...
...
@@ -980,11 +983,13 @@ static int fald_acq_write_multiple(struct adc_buffer *buf,
}
data
=
buf
->
data
;
n
=
fwrite
(
data
,
buf
->
samplesize
,
buf
->
nsamples
,
f
);
fclose
(
f
);
if
(
n
!=
buf
->
nsamples
)
{
fprintf
(
stderr
,
"write(%s): short write
\n
"
,
fname
);
return
-
1
;
}
fclose
(
f
);
return
0
;
}
...
...
@@ -999,9 +1004,9 @@ static void fald_acq_plot_data(struct adc_buffer *buf, unsigned int ch)
{
int16_t
*
data
=
buf
->
data
;
char
fname
[
PATH_MAX
];
char
cmd
[
256
];
char
cmd
[
PATH_MAX
+
256
];
snprintf
(
fname
,
sizeof
(
fname
),
"/tmp/fmcadc.0x%04x.ch%
d
.dat"
,
devid
,
ch
);
snprintf
(
fname
,
sizeof
(
fname
),
"/tmp/fmcadc.0x%04x.ch%
u
.dat"
,
devid
,
ch
);
if
(
write_file
(
fname
,
ch
,
data
,
(
buf
->
nsamples
)
/
4
)
<
0
)
{
printf
(
"Cannot plot data. Write data into file %s failed.
\n
"
,
fname
);
return
;
...
...
@@ -1019,11 +1024,13 @@ static void fald_acq_plot_data(struct adc_buffer *buf, unsigned int ch)
*/
static
void
adc_acq_statistics
(
struct
adc_buffer
*
buf
,
unsigned
int
max_chan
)
{
int32_t
avg
;
int
i
,
err
;
int
i
;
fprintf
(
stdout
,
"{
\"
statistics
\"
: ["
);
for
(
i
=
0
;
i
<
max_chan
;
++
i
)
{
int
err
;
int32_t
avg
;
fprintf
(
stdout
,
"{
\"
chan
\"
: %d"
,
i
);
err
=
adc_buffer_math_avg
(
buf
,
i
,
&
avg
);
...
...
@@ -1052,7 +1059,6 @@ static void fald_acq_process_buffer(struct adc_buffer *buf,
{
struct
adc_timestamp
ts
;
uint32_t
nchan
;
int
w
;
adc_tstamp_buffer
(
buf
,
&
ts
);
...
...
@@ -1078,9 +1084,12 @@ static void fald_acq_process_buffer(struct adc_buffer *buf,
if
(
statistics
)
adc_acq_statistics
(
buf
,
nchan
);
if
(
arg_plot
)
if
(
arg_plot
)
{
int
w
;
for
(
w
=
0
;
w
<
nchan
;
++
w
)
fald_acq_plot_data
(
buf
,
w
+
1
);
}
}
/**
...
...
@@ -1162,7 +1171,7 @@ static int adc_acq_acquisition(struct adc_dev *adc,
uint32_t
nshots
,
pre
,
post
;
int
err
,
k
;
fprintf
(
stderr
,
"Acquisition %
i
\n
"
,
iteration
+
1
);
fprintf
(
stderr
,
"Acquisition %
u
\n
"
,
iteration
+
1
);
/* Stop any pending acquisition */
err
=
adc_acq_stop
(
adc
,
0
);
...
...
@@ -1185,7 +1194,7 @@ static int adc_acq_acquisition(struct adc_dev *adc,
adc_get_conf
(
cfg_acq
,
ADC_CONF_ACQ_N_SHOTS
,
&
nshots
);
for
(
k
=
0
;
k
<
nshots
;
++
k
)
{
fprintf
(
stderr
,
"shot: %i/%
i, nsamples: %d
\n
"
,
"shot: %i/%
u, nsamples: %u
\n
"
,
k
+
1
,
nshots
,
pre
+
post
);
if
(
arg_trgsw
)
{
...
...
tools/example.c
View file @
1dc4045e
...
...
@@ -196,11 +196,11 @@ static int current_config_acquisition(struct adc_dev *adc)
}
adc_get_conf
(
&
cfg
,
ADC_CONF_ACQ_N_SHOTS
,
&
sh
);
fprintf
(
stdout
,
"Number of shots: %
d
\n
"
,
sh
);
fprintf
(
stdout
,
"Number of shots: %
u
\n
"
,
sh
);
adc_get_conf
(
&
cfg
,
ADC_CONF_ACQ_POST_SAMP
,
&
po
);
fprintf
(
stdout
,
"Number of post-samples: %
d
\n
"
,
po
);
fprintf
(
stdout
,
"Number of post-samples: %
u
\n
"
,
po
);
adc_get_conf
(
&
cfg
,
ADC_CONF_ACQ_PRE_SAMP
,
&
pr
);
fprintf
(
stdout
,
"Number of pre-samples: %
d
\n
"
,
pr
);
fprintf
(
stdout
,
"Number of pre-samples: %
u
\n
"
,
pr
);
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