Commit 764f2799 authored by Federico Vaga's avatar Federico Vaga

Merge branch 'release/v4.0.0'

parents d0189bcd 41b666d2
# SPDX-FileCopyrightText: 2021 CERN (home.cern)
#
# SPDX-License-Identifier: CC0-1.0
*.o
~*
*.a
......@@ -10,3 +14,4 @@ __pycache__
compile_commands.json
\#*\#
.depend
.clangd
# SPDX-FileCopyrightText: 2021 CERN (home.cern)
#
# SPDX-License-Identifier: CC0-1.0
stages:
- static-analysis
- build
reuse:
stage: static-analysis
image:
name: fsfe/reuse:latest
entrypoint: [""]
script:
- reuse lint
cppcheck:
stage: static-analysis
image:
name: gitlab-registry.cern.ch/coht/common-containers/static-analysis:latest
before_script:
- git clone -b v1.4.0 --depth 1 https://ohwr.org/project/zio.git ~/git/zio
- export ZIO=~/git/zio
- git clone -b v5.0.0 --depth 1 https://gitlab.cern.ch/coht/fmc-adc-100m14b4cha.git ~/git/fmc-adc-100m14b4cha
- export FMCADC100M=~/git/fmc-adc-100m14b4cha/software
script:
- make cppcheck
flawfinder:
stage: static-analysis
image:
name: gitlab-registry.cern.ch/coht/common-containers/static-analysis:latest
script:
- make flawfinder
# allow failures because we do not have have a better mechanism than readlink yet
allow_failure: true
documentation:
stage: build
image:
name: gitlab-registry.cern.ch/coht/common-containers/documentation:latest
before_script:
- git clone -b v1.4.0 --depth 1 https://ohwr.org/project/zio.git ~/git/zio
- export ZIO=~/git/zio
- git clone -b v5.0.0 --depth 1 https://gitlab.cern.ch/coht/fmc-adc-100m14b4cha.git ~/git/fmc-adc-100m14b4cha
- export FMCADC100M=~/git/fmc-adc-100m14b4cha/software
script:
- make -C lib
- LD_LIBRARY_PATH=$PWD/lib make -C doc html
build-centos-7:
stage: build
variables:
LINUX: /usr/src/kernels/*/
image:
name: gitlab-registry.cern.ch/coht/common-containers/build-centos-7:latest
before_script:
- git clone -b v1.4.0 --depth 1 https://ohwr.org/project/zio.git ~/git/zio
- export ZIO=~/git/zio
- git clone -b v5.0.0 --depth 1 https://gitlab.cern.ch/coht/fmc-adc-100m14b4cha.git ~/git/fmc-adc-100m14b4cha
- export FMCADC100M=~/git/fmc-adc-100m14b4cha/software
script:
- make
..
SPDX-License-Identifier: CC-0.0
SPDX-License-Identifier: CC0-1.0
SPDX-FileCopyrightText: 2019 CERN
=========
Changelog
=========
4.0.0 - 2021-09-10
==================
Added
-----
- the adc-acq tool uses VMALLOC by default
- tst: regression test for spec45t digital noise
Changed
-------
- the minimum required version for the fmc-adc-100m driver is v6.0.0
- the library converts offset microVolts to fmc-adc-100m raw values
- tst: improve tests
3.0.0 - 2020-12-10
==================
Added
......
This diff is collapsed.
Creative Commons Legal Code
CC0 1.0 Universal
CREATIVE COMMONS CORPORATION IS NOT A LAW FIRM AND DOES NOT PROVIDE
LEGAL SERVICES. DISTRIBUTION OF THIS DOCUMENT DOES NOT CREATE AN
ATTORNEY-CLIENT RELATIONSHIP. CREATIVE COMMONS PROVIDES THIS
INFORMATION ON AN "AS-IS" BASIS. CREATIVE COMMONS MAKES NO WARRANTIES
REGARDING THE USE OF THIS DOCUMENT OR THE INFORMATION OR WORKS
PROVIDED HEREUNDER, AND DISCLAIMS LIABILITY FOR DAMAGES RESULTING FROM
THE USE OF THIS DOCUMENT OR THE INFORMATION OR WORKS PROVIDED
HEREUNDER.
Statement of Purpose
The laws of most jurisdictions throughout the world automatically confer
exclusive Copyright and Related Rights (defined below) upon the creator
and subsequent owner(s) (each and all, an "owner") of an original work of
authorship and/or a database (each, a "Work").
Certain owners wish to permanently relinquish those rights to a Work for
the purpose of contributing to a commons of creative, cultural and
scientific works ("Commons") that the public can reliably and without fear
of later claims of infringement build upon, modify, incorporate in other
works, reuse and redistribute as freely as possible in any form whatsoever
and for any purposes, including without limitation commercial purposes.
These owners may contribute to the Commons to promote the ideal of a free
culture and the further production of creative, cultural and scientific
works, or to gain reputation or greater distribution for their Work in
part through the use and efforts of others.
For these and/or other purposes and motivations, and without any
expectation of additional consideration or compensation, the person
associating CC0 with a Work (the "Affirmer"), to the extent that he or she
is an owner of Copyright and Related Rights in the Work, voluntarily
elects to apply CC0 to the Work and publicly distribute the Work under its
terms, with knowledge of his or her Copyright and Related Rights in the
Work and the meaning and intended legal effect of CC0 on those rights.
1. Copyright and Related Rights. A Work made available under CC0 may be
protected by copyright and related or neighboring rights ("Copyright and
Related Rights"). Copyright and Related Rights include, but are not
limited to, the following:
i. the right to reproduce, adapt, distribute, perform, display,
communicate, and translate a Work;
ii. moral rights retained by the original author(s) and/or performer(s);
iii. publicity and privacy rights pertaining to a person's image or
likeness depicted in a Work;
iv. rights protecting against unfair competition in regards to a Work,
subject to the limitations in paragraph 4(a), below;
v. rights protecting the extraction, dissemination, use and reuse of data
in a Work;
vi. database rights (such as those arising under Directive 96/9/EC of the
European Parliament and of the Council of 11 March 1996 on the legal
protection of databases, and under any national implementation
thereof, including any amended or successor version of such
directive); and
vii. other similar, equivalent or corresponding rights throughout the
world based on applicable law or treaty, and any national
implementations thereof.
2. Waiver. To the greatest extent permitted by, but not in contravention
of, applicable law, Affirmer hereby overtly, fully, permanently,
irrevocably and unconditionally waives, abandons, and surrenders all of
Affirmer's Copyright and Related Rights and associated claims and causes
of action, whether now known or unknown (including existing as well as
future claims and causes of action), in the Work (i) in all territories
worldwide, (ii) for the maximum duration provided by applicable law or
treaty (including future time extensions), (iii) in any current or future
medium and for any number of copies, and (iv) for any purpose whatsoever,
including without limitation commercial, advertising or promotional
purposes (the "Waiver"). Affirmer makes the Waiver for the benefit of each
member of the public at large and to the detriment of Affirmer's heirs and
successors, fully intending that such Waiver shall not be subject to
revocation, rescission, cancellation, termination, or any other legal or
equitable action to disrupt the quiet enjoyment of the Work by the public
as contemplated by Affirmer's express Statement of Purpose.
3. Public License Fallback. Should any part of the Waiver for any reason
be judged legally invalid or ineffective under applicable law, then the
Waiver shall be preserved to the maximum extent permitted taking into
account Affirmer's express Statement of Purpose. In addition, to the
extent the Waiver is so judged Affirmer hereby grants to each affected
person a royalty-free, non transferable, non sublicensable, non exclusive,
irrevocable and unconditional license to exercise Affirmer's Copyright and
Related Rights in the Work (i) in all territories worldwide, (ii) for the
maximum duration provided by applicable law or treaty (including future
time extensions), (iii) in any current or future medium and for any number
of copies, and (iv) for any purpose whatsoever, including without
limitation commercial, advertising or promotional purposes (the
"License"). The License shall be deemed effective as of the date CC0 was
applied by Affirmer to the Work. Should any part of the License for any
reason be judged legally invalid or ineffective under applicable law, such
partial invalidity or ineffectiveness shall not invalidate the remainder
of the License, and in such case Affirmer hereby affirms that he or she
will not (i) exercise any of his or her remaining Copyright and Related
Rights in the Work or (ii) assert any associated claims and causes of
action with respect to the Work, in either case contrary to Affirmer's
express Statement of Purpose.
4. Limitations and Disclaimers.
a. No trademark or patent rights held by Affirmer are waived, abandoned,
surrendered, licensed or otherwise affected by this document.
b. Affirmer offers the Work as-is and makes no representations or
warranties of any kind concerning the Work, express, implied,
statutory or otherwise, including without limitation warranties of
title, merchantability, fitness for a particular purpose, non
infringement, or the absence of latent or other defects, accuracy, or
the present or absence of errors, whether or not discoverable, all to
the greatest extent permissible under applicable law.
c. Affirmer disclaims responsibility for clearing rights of other persons
that may apply to the Work or any use thereof, including without
limitation any person's Copyright and Related Rights in the Work.
Further, Affirmer disclaims responsibility for obtaining any necessary
consents, permissions or other rights required for any use of the
Work.
d. Affirmer understands and acknowledges that Creative Commons is not a
party to this document and has no duty or obligation with respect to
this CC0 or use of the Work.
This diff is collapsed.
GNU LESSER GENERAL PUBLIC LICENSE
Version 3, 29 June 2007
Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
This version of the GNU Lesser General Public License incorporates
the terms and conditions of version 3 of the GNU General Public
License, supplemented by the additional permissions listed below.
0. Additional Definitions.
As used herein, "this License" refers to version 3 of the GNU Lesser
General Public License, and the "GNU GPL" refers to version 3 of the GNU
General Public License.
"The Library" refers to a covered work governed by this License,
other than an Application or a Combined Work as defined below.
An "Application" is any work that makes use of an interface provided
by the Library, but which is not otherwise based on the Library.
Defining a subclass of a class defined by the Library is deemed a mode
of using an interface provided by the Library.
A "Combined Work" is a work produced by combining or linking an
Application with the Library. The particular version of the Library
with which the Combined Work was made is also called the "Linked
Version".
The "Minimal Corresponding Source" for a Combined Work means the
Corresponding Source for the Combined Work, excluding any source code
for portions of the Combined Work that, considered in isolation, are
based on the Application, and not on the Linked Version.
The "Corresponding Application Code" for a Combined Work means the
object code and/or source code for the Application, including any data
and utility programs needed for reproducing the Combined Work from the
Application, but excluding the System Libraries of the Combined Work.
1. Exception to Section 3 of the GNU GPL.
You may convey a covered work under sections 3 and 4 of this License
without being bound by section 3 of the GNU GPL.
2. Conveying Modified Versions.
If you modify a copy of the Library, and, in your modifications, a
facility refers to a function or data to be supplied by an Application
that uses the facility (other than as an argument passed when the
facility is invoked), then you may convey a copy of the modified
version:
a) under this License, provided that you make a good faith effort to
ensure that, in the event an Application does not supply the
function or data, the facility still operates, and performs
whatever part of its purpose remains meaningful, or
b) under the GNU GPL, with none of the additional permissions of
this License applicable to that copy.
3. Object Code Incorporating Material from Library Header Files.
The object code form of an Application may incorporate material from
a header file that is part of the Library. You may convey such object
code under terms of your choice, provided that, if the incorporated
material is not limited to numerical parameters, data structure
layouts and accessors, or small macros, inline functions and templates
(ten or fewer lines in length), you do both of the following:
a) Give prominent notice with each copy of the object code that the
Library is used in it and that the Library and its use are
covered by this License.
b) Accompany the object code with a copy of the GNU GPL and this license
document.
4. Combined Works.
You may convey a Combined Work under terms of your choice that,
taken together, effectively do not restrict modification of the
portions of the Library contained in the Combined Work and reverse
engineering for debugging such modifications, if you also do each of
the following:
a) Give prominent notice with each copy of the Combined Work that
the Library is used in it and that the Library and its use are
covered by this License.
b) Accompany the Combined Work with a copy of the GNU GPL and this license
document.
c) For a Combined Work that displays copyright notices during
execution, include the copyright notice for the Library among
these notices, as well as a reference directing the user to the
copies of the GNU GPL and this license document.
d) Do one of the following:
0) Convey the Minimal Corresponding Source under the terms of this
License, and the Corresponding Application Code in a form
suitable for, and under terms that permit, the user to
recombine or relink the Application with a modified version of
the Linked Version to produce a modified Combined Work, in the
manner specified by section 6 of the GNU GPL for conveying
Corresponding Source.
1) Use a suitable shared library mechanism for linking with the
Library. A suitable mechanism is one that (a) uses at run time
a copy of the Library already present on the user's computer
system, and (b) will operate properly with a modified version
of the Library that is interface-compatible with the Linked
Version.
e) Provide Installation Information, but only if you would otherwise
be required to provide such information under section 6 of the
GNU GPL, and only to the extent that such information is
necessary to install and execute a modified version of the
Combined Work produced by recombining or relinking the
Application with a modified version of the Linked Version. (If
you use option 4d0, the Installation Information must accompany
the Minimal Corresponding Source and Corresponding Application
Code. If you use option 4d1, you must provide the Installation
Information in the manner specified by section 6 of the GNU GPL
for conveying Corresponding Source.)
5. Combined Libraries.
You may place library facilities that are a work based on the
Library side by side in a single library together with other library
facilities that are not Applications and are not covered by this
License, and convey such a combined library under terms of your
choice, if you do both of the following:
a) Accompany the combined library with a copy of the same work based
on the Library, uncombined with any other library facilities,
conveyed under the terms of this License.
b) Give prominent notice with the combined library that part of it
is a work based on the Library, and explaining where to find the
accompanying uncombined form of the same work.
6. Revised Versions of the GNU Lesser General Public License.
The Free Software Foundation may publish revised and/or new versions
of the GNU Lesser General Public License from time to time. Such new
versions will be similar in spirit to the present version, but may
differ in detail to address new problems or concerns.
Each version is given a distinguishing version number. If the
Library as you received it specifies that a certain numbered version
of the GNU Lesser General Public License "or any later version"
applies to it, you have the option of following the terms and
conditions either of that published version or of any later version
published by the Free Software Foundation. If the Library as you
received it does not specify a version number of the GNU Lesser
General Public License, you may choose any version of the GNU Lesser
General Public License ever published by the Free Software Foundation.
If the Library as you received it specifies that a proxy can decide
whether future versions of the GNU Lesser General Public License shall
apply, that proxy's public statement of acceptance of any version is
permanent authorization for you to choose that version for the
Library.
# SPDX-FileCopyrightText: 2021 CERN (home.cern)
#
# SPDX-License-Identifier: CC0-1.0
# include parent_common.mk for buildsystem's defines
#use absolute path for REPO_PARENT
REPO_PARENT ?= $(shell /bin/pwd)/..
......@@ -7,18 +11,15 @@ DIRS = lib tools
CPPCHECK ?= cppcheck
all clean modules install modules_install: $(DIRS)
all clean install cppcheck flawfinder: $(DIRS)
clean: TARGET = clean
modules: TARGET = modules
install: TARGET = install
modules_install: TARGET = modules_install
cppcheck: TARGET = cppcheck
flawfinder: TARGET = flawfinder
tools: lib
$(DIRS):
$(MAKE) -C $@ $(TARGET)
cppcheck:
$(CPPCHECK) --enable=all ./
.PHONY: all clean modules install modules_install $(DIRS)
.PHONY: all clean install cppcheck flawfinder $(DIRS)
# SPDX-FileCopyrightText: 2021 CERN (home.cern)
#
# SPDX-License-Identifier: CC0-1.0
-include Makefile.specific
all:
......
# SPDX-License-Identifier: LGPL-3.0-or-later
# Copyright CERN 2014
from ctypes import c_int
from ctypes import c_uint
from ctypes import c_uint32
......@@ -225,6 +228,9 @@ class PyAdcTimestamp(Structure):
("ticks", c_ulong),
("bins", c_ulong)]
def to_ns_approx(self):
return self.secs * 1e9 + self.ticks * 8
def libadc_create():
"""
Initialize the libadc C library
......@@ -574,12 +580,11 @@ class PyFmcAdc100m14b4ch(PyAdcAbstract):
ADC_CONF_100M14B4CHA_BUF_KMALLOC = 0
ADC_CONF_100M14B4CHA_BUF_VMALLOC = 1
ADC_CONF_100M14B4CHA_BUF_TYPE = 0
ADC_CONF_100M14B4CHA_TRG_SW_EN = 1
ADC_CONF_100M14B4CHA_ACQ_MSHOT_MAX = 2
ADC_CONF_100M14B4CHA_BUF_SIZE_KB = 3
ADC_CONF_100M14B4CHA_TRG_ALT_EN = 4
__ADC_CONF_100M14B4CHA_LAST_INDEX = 5
ADC_CONF_100M14B4CHA_TRG_SW_EN = 0
ADC_CONF_100M14B4CHA_ACQ_MSHOT_MAX = 1
ADC_CONF_100M14B4CHA_BUF_SIZE_KB = 2
ADC_CONF_100M14B4CHA_TRG_ALT_EN = 3
__ADC_CONF_100M14B4CHA_LAST_INDEX = 4
ADC_CONF_100M14B4CHA_FSM_STATE_IDLE = 1
ADC_CONF_100M14B4CHA_FSM_STATE_PRE = 2
......
#!/usr/bin/env python
# Copyright (c) 2013-2021 CERN (home.cern)
# SPDX-License-Identifier: CC0-1.0
from distutils.core import setup
......
# SPDX-FileCopyrightText: 2021 CERN (home.cern)
#
# SPDX-License-Identifier: CC0-1.0
doxygen-lib-output/
*.log
_build
......
# SPDX-FileCopyrightText: 2021 CERN (home.cern)
#
# SPDX-License-Identifier: CC0-1.0
# Minimal makefile for Sphinx documentation
#
......
# Copyright (c) 2013-2021 CERN (home.cern)
# SPDX-License-Identifier: CC0-1.0
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
#
......
# Copyright (c) 2013-2021 CERN (home.cern)
# SPDX-License-Identifier: CC0-1.0
PROJECT_NAME = "Generic ADC Library - GAL"
PROJECT_NUMBER = $(GIT_VERSION)
PROJECT_BRIEF = "Generic ADC Library API"
......
.. Copyright (c) 2013-2021 CERN (home.cern)
SPDX-License-Identifier: CC-BY-SA-4.0
Welcome to the ADC library documentation!
==============================================
......
# Copyright (c) 2013-2021 CERN (home.cern)
# SPDX-License-Identifier: CC-BY-SA-4.0
graph layers {
user [label="User Programs"];
api [label="ADC API", shape=box];
......
.. Copyright (c) 2013-2021 CERN (home.cern)
SPDX-License-Identifier: CC-BY-SA-4.0
The Library API
================
......
.. Copyright (c) 2013-2021 CERN (home.cern)
SPDX-License-Identifier: CC-BY-SA-4.0
The Library For Developers
============================
......
.. Copyright (c) 2013-2021 CERN (home.cern)
SPDX-License-Identifier: CC-BY-SA-4.0
The Library For Users
=======================
......@@ -296,13 +299,10 @@ Today, within this context, the ``route_to`` options does not have any meaning
since the specifc parameters for this card are global, so there is no need for
any routing mechanism.
Following some special values defined for this board.
.. doxygenenum:: adc_configuration_100m14b4cha_channel_range
The :ref:`zero offset<lib:usr:cfg:ac>` value is valid only within a *session*.
Every time you invoke :cpp:func:`adc_open()` this particular offset get
reset.
Among the FMC ADC 100M 14bit 4 Channel specificity, it is worth remembering that
this card does not have hardware support for the zero-offset. Hence, the
:ref:`zero offset<lib:usr:cfg:ac>` value is valid only within a *session*. Every
time you invoke :cpp:func:`adc_open()` this particular offset get reset.
Acquisition
-----------
......
.. Copyright (c) 2013-2021 CERN (home.cern)
SPDX-License-Identifier: CC-BY-SA-4.0
The Python Module: PyAdcLib
===========================
......
# SPDX-License-Identifier: LGPL-3.0-or-later
# Copyright CERN 2014
docutils==0.12
Sphinx==1.4.9
sphinx_rtd_theme
......
.. Copyright (c) 2013-2021 CERN (home.cern)
SPDX-License-Identifier: CC-BY-SA-4.0
The ``adc-acq`` Tools
========================
......
.. Copyright (c) 2013-2021 CERN (home.cern)
SPDX-License-Identifier: CC-BY-SA-4.0
The Example Tools
====================
......
# This is not a kbuild Makefile. It is a plain Makefile so it can be copied
# SPDX-FileCopyrightText: 2021 CERN (home.cern)
#
# SPDX-License-Identifier: CC0-1.0
# If it exists includes Makefile.specific. In this Makefile, you should put
# specific Makefile code that you want to run before this. For example,
......@@ -10,6 +12,9 @@ IGNORE_CPU_SUFFIX := y
REPO_PARENT ?=
-include $(REPO_PARENT)/parent_common.mk
DESTDIR ?= /usr/local
ZIO ?= $(HOME)/git/zio
ZIO_ABS ?= $(abspath $(ZIO) )
......@@ -17,7 +22,12 @@ GIT_VERSION := $(shell git describe --dirty --long --tags)
ZIO_GIT_VERSION := $(shell cd $(ZIO_ABS); git describe --dirty --long --tags)
FMCADC_100MS_4CH_14BIT_GIT_VERSION := $(shell cd $(FMCADC100M); git describe --dirty --long --tags)
SO_VERSION_XYZ := $(shell echo $(GIT_VERSION) | grep -o -E "[0-9]+\.[0-9]+\.[0-9]")
SO_VERSION_X := $(shell echo $(SO_VERSION_XYZ) | cut -d "." -f 1)
LIBS = libadc.so
LIBS_XYZ = $(LIBS).$(SO_VERSION_XYZ)
LIB = libadc.a
LOBJ := route.o
LOBJ += init.o
......@@ -41,8 +51,9 @@ LDFLAGS = -L. -ladc
CC ?= $(CROSS_COMPILE)gcc
CPPCHECK ?= cppcheck
FLAWFINDER ?= flawfinder
modules all: $(LIB) $(LIBS)
all: $(LIB) $(LIBS_XYZ)
%: %.c $(LIB)
......@@ -51,18 +62,27 @@ modules all: $(LIB) $(LIBS)
$(LIB): $(LOBJ)
$(AR) r $@ $^
$(LIBS): $(LIB)
$(LIBS_XYZ): $(LIB)
$(CC) -shared -o $@ -Wl,--whole-archive,-soname,$@ $^ -Wl,--no-whole-archive
cppcheck:
$(CPPCHECK) --enable=all ./
$(CPPCHECK) -q -I$(ZIO_ABS)/include -I$(FMCADC100M)/kernel -I. --suppress=unusedFunction --suppress=missingIncludeSystem --enable=all *.c *.h --error-exitcode=1
flawfinder:
$(FLAWFINDER) -SQDC --error-level=4 .
clean:
rm -f $(LIB) $(LIBS) .depend *.o *~
rm -f $(LIB) $(LIBS_XYZ) .depend *.o *~
.depend: Makefile $(wildcard *.c *.h ../*.h)
$(CC) $(CFLAGS) -M $(LOBJ:.o=.c) -o $@
install modules_install:
install: $(LIBS_XYZ) $(LIB)
install -d $(DESTDIR)/lib
install -m 644 $(LIB) $(DESTDIR)/lib
install -m 755 $(LIBS_XYZ) $(DESTDIR)/lib
ln -sf $(LIBS_XYZ) $(DESTDIR)/lib/$(LIBS).$(SO_VERSION_X)
ln -sf $(LIBS).$(SO_VERSION_X) $(DESTDIR)/lib/$(LIBS)
-include .depend
// SPDX-License-Identifier: LGPL-3.0-or-later
// Copyright CERN 2013
#define _GNU_SOURCE
#include <stdio.h>
#include <stdint.h>
......@@ -319,15 +321,12 @@ static int adc_genfake_fill_buffer(struct adc_dev *dev,
int samplesize = buf->samplesize;
int i, datalen = samplesize * buf->nsamples;
uint8_t datum;
clock_gettime(CLOCK_REALTIME, &tp);
srand(tp.tv_nsec);
srandom(tp.tv_nsec);
for (i=0; i < datalen; i += sizeof(datum)) {
datum = rand() % 256;
sprintf(buf->data + i, "%c", datum);
}
for (i = 0; i < datalen; i++)
((char *)buf->data)[i] = random() % 256;
return 0;
}
......
// SPDX-License-Identifier: LGPL-3.0-or-later
/*
* ZIO-specific configuration (mostly device-independent)
*
* Copyright (C) 2016 CERN (www.cern.ch)
* Author: Federico Vaga <federico.vaga@cern.ch>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* version 2 as published by the Free Software Foundation or, at your
* option, any later version.
*
*
* This header hold all the specificity for the FMC ADC 100M module
*/
......
/*It depends on the header fmcadc-lib.h. Include this file after fmcadc-lib.h*/
#define fmcadc_dev adc_dev
#define fmcadc_buffer adc_buffer
#define fmcadc_timestamp adc_timestamp
#define fmcadc_conf adc_conf
#define __fmcadc_dev_zio __adc_dev_zio
#define fmcadc_board_type adc_board_type
#define fmcadc_operations adc_operations
#define fmcadc_gid adc_gid
#define __fmcadc_genfake_conf __adc_genfake_conf
#define __fmcadc_dev_genfake __adc_dev_genfake
#define __FMCADC_ERRNO_START __ADC_ERRNO_START
#define FMCADC_ENOP ADC_ENOP
#define FMCADC_ENOCAP ADC_ENOCAP
#define FMCADC_ENOCFG ADC_ENOCFG
#define FMCADC_ENOGET ADC_ENOGET
#define FMCADC_ENOSET ADC_ENOSET
#define FMCADC_ENOCHAN ADC_ENOCHAN
#define FMCADC_ENOMASK ADC_ENOMASK
#define FMCADC_EDISABLED ADC_EDISABLED
#define FMCADC_CONF_TRG_SOURCE ADC_CONF_TRG_SOURCE
#define FMCADC_CONF_TRG_SOURCE_CHAN ADC_CONF_TRG_SOURCE_CHAN
#define FMCADC_CONF_TRG_THRESHOLD ADC_CONF_TRG_THRESHOLD
#define FMCADC_CONF_TRG_POLARITY ADC_CONF_TRG_POLARITY
#define FMCADC_CONF_TRG_DELAY ADC_CONF_TRG_DELAY
#define FMCADC_CONF_TRG_THRESHOLD_FILTER ADC_CONF_TRG_THRESHOLD_FILTER
#define __FMCADC_CONF_TRG_ATTRIBUTE_LAST_INDEX __ADC_CONF_TRG_ATTRIBUTE_LAST_INDEX
#define FMCADC_CONF_ACQ_N_SHOTS ADC_CONF_ACQ_N_SHOTS
#define FMCADC_CONF_ACQ_POST_SAMP ADC_CONF_ACQ_POST_SAMP
#define FMCADC_CONF_ACQ_PRE_SAMP ADC_CONF_ACQ_PRE_SAMP
#define FMCADC_CONF_ACQ_DECIMATION ADC_CONF_ACQ_DECIMATION
#define FMCADC_CONF_ACQ_FREQ_HZ ADC_CONF_ACQ_FREQ_HZ
#define FMCADC_CONF_ACQ_N_BITS ADC_CONF_ACQ_N_BITS
#define __FMCADC_CONF_ACQ_ATTRIBUTE_LAST_INDEX __ADC_CONF_ACQ_ATTRIBUTE_LAST_INDEX
#define FMCADC_CONF_CHN_RANGE ADC_CONF_CHN_RANGE
#define FMCADC_CONF_CHN_TERMINATION ADC_CONF_CHN_TERMINATION
#define FMCADC_CONF_CHN_OFFSET ADC_CONF_CHN_OFFSET
#define FMCADC_CONF_CHN_SATURATION ADC_CONF_CHN_SATURATION
#define __FMCADC_CONF_CHN_ATTRIBUTE_LAST_INDEX __ADC_CONF_CHN_ATTRIBUTE_LAST_INDEX
#define FMCADC_CONF_BRD_STATUS ADC_CONF_BRD_STATUS
#define FMCADC_CONF_BRD_MAX_FREQ_HZ ADC_CONF_BRD_MAX_FREQ_HZ
#define FMCADC_CONF_BRD_MIN_FREQ_HZ ADC_CONF_BRD_MIN_FREQ_HZ
#define FMCADC_CONF_BRD_STATE_MACHINE_STATUS ADC_CONF_BRD_STATE_MACHINE_STATUS
#define FMCADC_CONF_BRD_N_CHAN ADC_CONF_BRD_N_CHAN
#define FMCADC_CONF_UTC_TIMING_BASE_S ADC_CONF_UTC_TIMING_BASE_S
#define FMCADC_CONF_UTC_TIMING_BASE_T ADC_CONF_UTC_TIMING_BASE_T
#define FMCADC_CONF_UTC_TIMING_BASE_B ADC_CONF_UTC_TIMING_BASE_B
#define __FMCADC_CONF_BRD_ATTRIBUTE_LAST_INDEX __ADC_CONF_BRD_ATTRIBUTE_LAST_INDEX
#define FMCADC_CONF_TYPE_TRG ADC_CONF_TYPE_TRG
#define FMCADC_CONF_TYPE_ACQ ADC_CONF_TYPE_ACQ
#define FMCADC_CONF_TYPE_CHN ADC_CONF_TYPE_CHN
#define FMCADC_CONT_TYPE_BRD ADC_CONT_TYPE_BRD
#define __FMCADC_CONF_TYPE_LAST_INDEX __ADC_CONF_TYPE_LAST_INDEX
#define __FMCADC_CONF_LEN __ADC_CONF_LEN
#define FMCADC_F_USERMASK ADC_F_USERMASK //found as FMCSDC_F_USERMASK was it a mistake?
#define FMCADC_F_FLUSH ADC_F_FLUSH
#define FMCADC_F_VERBOSE ADC_F_VERBOSE
static inline int fmcadc_init(void)
{
return adc_init();
}
static inline void fmcadc_exit(void)
{
return adc_exit();
}
static inline char *fmcadc_strerror(int errnum)
{
return adc_strerror(errnum);
}
static inline char *fmcadc_get_driver_type(struct fmcadc_dev *dev)
{
return adc_get_driver_type(dev);
}
static inline struct fmcadc_dev *fmcadc_open(char *name, unsigned int dev_id,
unsigned long totalsamples,
unsigned int nbuffer,
unsigned long flags)
{
return adc_open(name, dev_id, totalsamples, nbuffer, flags);
}
static inline struct fmcadc_dev *fmcadc_open_by_lun(char *name, int lun,
unsigned long totalsamples,
unsigned int nbuffer,
unsigned long flags)
{
return adc_open_by_lun(name, lun, totalsamples, nbuffer, flags);
}
static inline int fmcadc_close(struct fmcadc_dev *dev)
{
return adc_close(dev);
}
static inline int fmcadc_acq_start(struct fmcadc_dev *dev,
unsigned int flags,
struct timeval *timeout)
{
return adc_acq_start(dev, flags, timeout);
}
static inline int fmcadc_acq_poll(struct fmcadc_dev *dev, unsigned int flags,
struct timeval *timeout)
{
return adc_acq_poll(dev, flags, timeout);
}
static inline int fmcadc_acq_stop(struct fmcadc_dev *dev, unsigned int flags)
{
return adc_acq_stop(dev, flags);
}
static inline int fmcadc_reset_conf(struct fmcadc_dev *dev, unsigned int flags,
struct adc_conf *conf)
{
return adc_reset_conf(dev, flags, conf);
}
static inline int fmcadc_apply_config(struct fmcadc_dev *dev, unsigned int flags,
struct adc_conf *conf)
{
return adc_apply_config(dev, flags, conf);
}
static inline int fmcadc_retrieve_config(struct fmcadc_dev *dev,
struct adc_conf *conf)
{
return adc_retrieve_config(dev, conf);
}
static inline int fmcadc_set_param(struct fmcadc_dev *dev, char *name,
char *sptr, int *iptr)
{
return adc_set_param(dev, name, sptr, iptr);
}
static inline int fmcadc_get_param(struct fmcadc_dev *dev, char *name,
char *sptr, int *iptr)
{
return adc_get_param(dev, name, sptr, iptr);
}
static inline struct adc_buffer *fmcadc_request_buffer(struct fmcadc_dev *dev,
int nsamples,
void *(*alloc_fn)(size_t),
unsigned int flags)
{
return adc_request_buffer(dev, nsamples, alloc_fn, flags);
}
static inline int fmcadc_fill_buffer(struct fmcadc_dev *dev,
struct adc_buffer *buf,
unsigned int flags,
struct timeval *timeout)
{
return adc_fill_buffer(dev, buf, flags, timeout);
}
static inline struct fmcadc_timestamp *fmcadc_tstamp_buffer(struct adc_buffer *buf,
struct fmcadc_timestamp *ts)
{
return adc_tstamp_buffer(buf, ts);
}
static inline int fmcadc_release_buffer(struct fmcadc_dev *dev,
struct adc_buffer *buf,
void (*free_fn)(void *))
{
return adc_release_buffer(dev, buf, free_fn);
}
static inline void fmcadc_set_conf_mask(struct adc_conf *conf,
unsigned int conf_index)
{
return adc_set_conf_mask(conf, conf_index);
}
static inline void fmcadc_set_conf(struct adc_conf *conf,
unsigned int conf_index, uint32_t val)
{
return adc_set_conf(conf, conf_index, val);
}
static inline int fmcadc_get_conf(struct adc_conf *conf,
unsigned int conf_index,
uint32_t *val)
{
return adc_get_conf(conf, conf_index, val);
}
// SPDX-License-Identifier: LGPL-3.0-or-later
/*
* Copyright CERN 2013
* Author: Federico Vaga <federico.vaga@gmail.com>
......
// SPDX-License-Identifier: LGPL-3.0-or-later
/*
* Copyright CERN 2013
* Author: Federico Vaga <federico.vaga@gmail.com>
......@@ -33,6 +34,7 @@ extern "C" {
#define ADC_OFF_AC_RESTORE_S 1037
#define ADC_OFF_AC_RESTORE_R 1038
#define ADC_ENOFLAGS 1039
#define ADC_EDRVVERSION 1040
/**
* Opaque type. any instance of this should be used as token
......@@ -185,7 +187,8 @@ enum adc_configuration_acquisition {
enum adc_configuration_channel {
ADC_CONF_CHN_RANGE = 0, /**< Volt range */
ADC_CONF_CHN_TERMINATION, /**< channel Termination */
ADC_CONF_CHN_OFFSET, /**< signal offset */
ADC_CONF_CHN_OFFSET, /**< signal offset [uV]. Depending on board
this value could be approximated */
ADC_CONF_CHN_SATURATION, /**< saturation value */
ADC_CONF_CHN_GAIN, /**< signal gain */
__ADC_CONF_CHN_ATTRIBUTE_LAST_INDEX, /**< It represents the the last
......
// SPDX-License-Identifier: LGPL-3.0-or-later
/*
* The ADC library for the specific card
*
* Copyright (C) 2013 CERN (www.cern.ch)
* Author: Federico Vaga <federico.vaga@gmail.com>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* version 2 as published by the Free Software Foundation or, at your
* option, any later version.
*/
#define _GNU_SOURCE
#include <stdio.h>
......@@ -103,16 +99,16 @@ struct adc_dev *adc_zio_open(const struct adc_board_type *b,
/* Open char devices */
if (chan == ~0) {
sprintf(fname, "%s-%u-i-ctrl", fa->devbase, fa->cset);
snprintf(fname, sizeof(fname), "%s-%u-i-ctrl", fa->devbase, fa->cset);
fa->fdc = open(fname, O_RDONLY);
sprintf(fname, "%s-%u-i-data", fa->devbase, fa->cset);
snprintf(fname, sizeof(fname), "%s-%u-i-data", fa->devbase, fa->cset);
fa->fdd = open(fname, O_RDONLY);
} else {
sprintf(fname, "%s-%u-%d-ctrl",
fa->devbase, fa->cset, fa->chan);
snprintf(fname, sizeof(fname), "%s-%u-%d-ctrl",
fa->devbase, fa->cset, fa->chan);
fa->fdc = open(fname, O_RDONLY);
sprintf(fname, "%s-%u-%d-data",
fa->devbase, fa->cset, fa->chan);
snprintf(fname, sizeof(fname), "%s-%u-%d-data",
fa->devbase, fa->cset, fa->chan);
fa->fdd = open(fname, O_RDONLY);
}
......
// SPDX-License-Identifier: LGPL-3.0-or-later
// Copyright CERN 2014
#define _GNU_SOURCE
#include <stdio.h>
#include <stdint.h>
......
// SPDX-License-Identifier: LGPL-3.0-or-later
/*
* All the boards in the library
*
* Copyright (C) 2013 CERN (www.cern.ch)
* Author: Federico Vaga <federico.vaga@gmail.com>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* version 2 as published by the Free Software Foundation or, at your
* option, any later version.
*/
#include <stdio.h>
#include <string.h>
......
// SPDX-License-Identifier: LGPL-3.0-or-later
/*
* ZIO-wide buffer management (device-independent)
*
* Copyright (C) 2013 CERN (www.cern.ch)
* Author: Federico Vaga <federico.vaga@gmail.com>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* version 2 as published by the Free Software Foundation or, at your
* option, any later version.
*/
#include <stdint.h>
#include <stdio.h>
......@@ -81,7 +77,7 @@ static int adc_zio_read_data(struct __adc_dev_zio *fa,
fa->fdd, mapoffset & ~pagemask);
if (buf->mapaddr == MAP_FAILED)
return -1;
buf->data = buf->mapaddr + (mapoffset & pagemask);
buf->data = (char *)buf->mapaddr + (mapoffset & pagemask);
return 0;
}
......
// SPDX-License-Identifier: LGPL-3.0-or-later
/*
* ZIO-specific configuration (mostly device-independent)
*
* Copyright (C) 2013 CERN (www.cern.ch)
* Author: Federico Vaga <federico.vaga@gmail.com>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* version 2 as published by the Free Software Foundation or, at your
* option, any later version.
*/
#include <stdint.h>
#include <stdio.h>
......@@ -37,7 +33,7 @@ static int __adc_zio_sysfs_set(struct __adc_dev_zio *fa, char *name,
int fd, ret, len;
snprintf(pathname, sizeof(pathname), "%s/%s", fa->sysbase, name);
len = sprintf(newval, "%s\n", val);
len = snprintf(newval, sizeof(newval), "%s\n", val);
fd = open(pathname, O_WRONLY);
if (fd < 0)
......@@ -83,8 +79,8 @@ int adc_zio_set_param(struct adc_dev *dev, char *name,
int len;
if (sptr)
return __adc_zio_sysfs_set(fa, name, sptr, strlen(sptr + 2));
len = sprintf(istr, "%i", *iptr);
return __adc_zio_sysfs_set(fa, name, sptr, strlen(sptr) + 2);
len = snprintf(istr, sizeof(istr), "%i", *iptr);
return __adc_zio_sysfs_set(fa, name, istr, len + 2);
}
......@@ -116,46 +112,39 @@ static int adc_zio_sysfs_get(struct __adc_dev_zio *fa, char *name,
uint32_t *resp)
{
struct adc_dev *dev = (void *)&fa->gid; /* hack: back and forth.. */
int ret;
int err;
int val;
ret = adc_zio_get_param(dev, name, NULL, &val);
if (!ret) {
*resp = val; /* different type */
return 0;
err = adc_zio_get_param(dev, name, NULL, &val);
if (err) {
if (fa->flags & ADC_FLAG_VERBOSE)
fprintf(stderr, "lib-fmcadc: Error reading %s (%s)\n",
name, strerror(errno));
return err;
}
if (!(fa->flags & ADC_FLAG_VERBOSE))
return ret;
/* verbose tail */
if (ret)
fprintf(stderr, "lib-fmcadc: Error reading %s (%s)\n",
name, strerror(errno));
else
*resp = val; /* different type */
if (fa->flags & ADC_FLAG_VERBOSE)
fprintf(stderr, "lib-fmcadc: %08x %5i <- %s\n",
(int)*resp, (int)*resp, name);
return ret;
(int)*resp, (int)*resp, name);
return 0;
}
int adc_zio_sysfs_set(struct __adc_dev_zio *fa, char *name,
uint32_t *value)
{
struct adc_dev *dev = (void *)&fa->gid; /* hack: back and forth.. */
int ret;
int err;
int val = *value; /* different type */
ret = adc_zio_set_param(dev, name, NULL, &val);
if (!ret)
return 0;
if (!(fa->flags & ADC_FLAG_VERBOSE))
return ret;
/* verbose tail */
if (ret)
err = adc_zio_set_param(dev, name, NULL, &val);
if (err && fa->flags & ADC_FLAG_VERBOSE)
fprintf(stderr, "lib-fmcadc: Error writing %s (%s)\n",
name, strerror(errno));
else
if (!err && fa->flags & ADC_FLAG_VERBOSE)
fprintf(stderr, "lib-fmcadc: %08x %5i -> %s\n",
(int)*value, (int)*value, name);
return ret;
return err;
}
......@@ -225,28 +214,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%u/ch%u-vref", fa->cset, ch);
snprintf(path, sizeof(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%u/ch%u-50ohm-term", fa->cset, ch);
snprintf(path, sizeof(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%u/ch%u-offset", fa->cset, ch);
snprintf(path, sizeof(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%u/ch%u-saturation", fa->cset, ch);
snprintf(path, sizeof(path), "cset%u/ch%u-saturation", fa->cset, ch);
if (direction)
return adc_zio_sysfs_set(fa, path, value);
else
......
// SPDX-License-Identifier: LGPL-3.0-or-later
/*
* The ADC library for the specific card
*
* Copyright (C) 2013 CERN (www.cern.ch)
* Author: Federico Vaga <federico.vaga@gmail.com>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* version 2 as published by the Free Software Foundation or, at your
* option, any later version.
*/
#define _GNU_SOURCE
#include <stdio.h>
......@@ -38,6 +33,10 @@
#define ADC_CONF_GET 0
#define ADC_CONF_SET 1
/**
* This is for internal use. It uses the offset raw value
*/
#define __ADC_CONF_CHN_OFFSET_ZERO 200
......@@ -85,9 +84,9 @@ static typeof(adc_get_param) *adc_param[] = {
* ADC internal data
*/
struct adc_100m14b4cha {
/**< keep track of all zero-offset values for each range
/**< keep track of all zero-offset values (raw values) for each range
(100mV 1V 10V) */
int32_t offset_zero[FA100M14B4C_NCHAN][ADC_CONF_100M14B4CHA_CHN_RANGE_N];
uint32_t offset_zero[FA100M14B4C_NCHAN][ADC_CONF_100M14B4CHA_CHN_RANGE_N];
};
static int adc_100m14b4cha_offset_zero_set(struct adc_dev *dev);
......@@ -145,6 +144,7 @@ static int adc_100m14b4cha_buffer_resize(struct adc_dev *dev,
}
#define BUF_SIZE 128
#define FMCADC_100MS_4CH_14BIT_MIN_VERSION 6
static bool adc_100m14b4cha_is_driver_compatible(void)
{
int fd;
......@@ -160,11 +160,14 @@ static bool adc_100m14b4cha_is_driver_compatible(void)
ret = read(fd, buf, BUF_SIZE);
if (ret <= 0)
goto out;
ret = sscanf(buf, "v%d.%d", &maj, &min);
ret = sscanf(buf, "v%u.%u", &maj, &min);
if (ret != 2)
goto out;
ret = sscanf(FMCADC_100MS_4CH_14BIT_GIT_VERSION, "v%d.%d",
if (maj < FMCADC_100MS_4CH_14BIT_MIN_VERSION)
goto out;
ret = sscanf(FMCADC_100MS_4CH_14BIT_GIT_VERSION, "v%u.%u",
&ref_maj, &ref_min);
if (ret != 2)
goto out;
......@@ -182,6 +185,16 @@ out:
}
#undef BUF_SIZE
static void adc_100m14b4cha_init_data(struct adc_100m14b4cha *adcdata)
{
int i, k;
/* zero-offset 0.000V corresponds to 0x8000 */
for (i = 0; i < FA100M14B4C_NCHAN; ++i)
for (k = 0; k < ADC_CONF_100M14B4CHA_CHN_RANGE_N; ++k)
adcdata->offset_zero[i][k] = 0x8000;
}
/**
* @copydoc adc_open
* @param[in] b the board type description
......@@ -203,7 +216,7 @@ static struct adc_dev *adc_100m14b4cha_open(const struct adc_board_type *b,
int err, bits;
if (!adc_100m14b4cha_is_driver_compatible()) {
errno = EPERM;
errno = ADC_EDRVVERSION;
return NULL;
}
......@@ -225,8 +238,7 @@ static struct adc_dev *adc_100m14b4cha_open(const struct adc_board_type *b,
fa->priv = malloc(sizeof(struct adc_100m14b4cha));
if (!fa->priv)
return NULL;
memset(fa->priv, 0, sizeof(struct adc_100m14b4cha));
adc_100m14b4cha_init_data(fa->priv);
err = adc_100m14b4cha_offset_zero_set(dev);
if (err)
goto err;
......@@ -362,7 +374,6 @@ static int adc_100m14b4cha_config_brd(struct adc_dev *adc,
} else {
return adc_get_param(adc, "temperature",
NULL, (int *)value);
return 0;
}
case ADC_CONF_UTC_TIMING_BASE_S:
if (direction) {
......@@ -454,6 +465,23 @@ static int adc_100m14b4cha_config_acq(struct adc_dev *adc,
}
}
/**
* FMC-ADC-100M14B4CH offset volt reference
*/
#define ADC_100M14B4CHA_DAC_VREF_uV 5000000LL
/**
* Convert offset value from microVolt to raw
* @param[in] offset value in micro Volt
*
* @return offset raw value
*/
static uint32_t __offset_uv_to_raw(uint32_t value_uv)
{
int32_t value_uv_s = (int32_t)value_uv;
return (0x8000LL * (value_uv_s + ADC_100M14B4CHA_DAC_VREF_uV))/ADC_100M14B4CHA_DAC_VREF_uV;
}
#define ADC_100M14B4CHA_MAX_CHN_SRC FA100M14B4C_NCHAN
/**
......@@ -482,19 +510,25 @@ static int adc_100m14b4cha_config_chn(struct adc_dev *adc,
switch (index) {
case ADC_CONF_CHN_RANGE:
sprintf(path, "cset%u/ch%u-vref", fa->cset, source);
snprintf(path, sizeof(path), "cset%u/ch%u-vref",
fa->cset, source);
break;
case ADC_CONF_CHN_TERMINATION:
sprintf(path, "cset%u/ch%u-50ohm-term", fa->cset, source);
snprintf(path, sizeof(path), "cset%u/ch%u-50ohm-term",
fa->cset, source);
break;
case ADC_CONF_CHN_OFFSET:
sprintf(path, "cset%u/ch%u-offset", fa->cset, source);
snprintf(path, sizeof(path), "cset%u/ch%u-offset",
fa->cset, source);
*value = __offset_uv_to_raw(*value);
break;
case __ADC_CONF_CHN_OFFSET_ZERO:
sprintf(path, "cset%u/ch%u-offset-zero", fa->cset, source);
snprintf(path, sizeof(path), "cset%u/ch%u-offset-zero",
fa->cset, source);
break;
case ADC_CONF_CHN_SATURATION:
sprintf(path, "cset%u/ch%u-saturation", fa->cset, source);
snprintf(path, sizeof(path), "cset%u/ch%u-saturation",
fa->cset, source);
break;
default:
errno = ADC_ENOCAP;
......@@ -593,8 +627,8 @@ static int adc_100m14b4cha_config_trg_ext(struct adc_dev *adc,
tmp |= FA100M14B4C_TRG_POL_EXT;
else
tmp &= ~FA100M14B4C_TRG_POL_EXT;
err = adc_set_param(adc, "cset0/trigger/polarity",
NULL, &tmp);
return adc_set_param(adc, "cset0/trigger/polarity",
NULL, &tmp);
} else {
*value = !!(tmp & FA100M14B4C_TRG_POL_EXT);
}
......@@ -664,13 +698,13 @@ static int adc_100m14b4cha_config_trg_thr(struct adc_dev *adc,
}
break;
case ADC_CONF_TRG_THR_DELAY:
sprintf(path, "cset0/trigger/ch%u-delay", source);
snprintf(path, sizeof(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%u-threshold", source);
snprintf(path, sizeof(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%u-hysteresis", source);
snprintf(path, sizeof(path), "cset0/trigger/ch%u-hysteresis", source);
return adc_param[direction](adc, path, NULL, (int *)value);
default:
errno = ADC_ENOCAP;
......@@ -719,15 +753,15 @@ static int adc_100m14b4cha_config_trg_tim(struct adc_dev *adc,
case ADC_CONF_TRG_TIM_SECONDS:
/* FIXME we need 64bit values to configure it completely */
tmp = 0;
sprintf(path, "cset0/trigger/trg-time-su");
snprintf(path, sizeof(path), "cset0/trigger/trg-time-su");
err = adc_param[direction](adc, path, NULL, (int *)&tmp);
if (err)
return err;
sprintf(path, "cset0/trigger/trg-time-sl");
snprintf(path, sizeof(path), "cset0/trigger/trg-time-sl");
return adc_param[direction](adc, path, NULL, (int *)value);
case ADC_CONF_TRG_TIM_NANO_SECONDS:
tmp = __nanoseconds_to_ticks(*value);
sprintf(path, "cset0/trigger/trg-time-t");
snprintf(path, sizeof(path), "cset0/trigger/trg-time-t");
return adc_param[direction](adc, path, NULL, (int *)&tmp);
default:
errno = ADC_ENOCAP;
......@@ -918,7 +952,7 @@ static int adc_100m14b4cha_trigger_fire(struct adc_dev *dev)
int fd, ret;
snprintf(pathname, sizeof(pathname),
"/sys/kernel/debug/fmc-adc-100m.%d.auto/trigger_software",
"/sys/kernel/debug/fmc-adc-100m.%u.auto/trigger_software",
fa->dev_id);
fd = open(pathname, O_WRONLY);
if (fd < 0)
......@@ -1114,7 +1148,7 @@ static int __cfg_offac_apply(struct adc_dev *dev,
unsigned long flags)
{
int err, trgsrc = FA100M14B4C_TRG_SRC_SW, i;
uint32_t offset = 0;
uint32_t offset = 0x8000;
/* zero-offset needs to be cleard always */
for (i = 0; i < FA100M14B4C_NCHAN; ++i) {
......@@ -1140,46 +1174,6 @@ static int __cfg_offac_apply(struct adc_dev *dev,
return 0;
}
/**
* It converts an hardware value to uV
* @param[in] val value to be converted (hardware format)
* @param[in] range switch configuration read from the hardware
*
* @return uV value
*/
static int32_t __convert_hw_to_uv(int32_t val, unsigned int range)
{
int32_t result_int, result_frac, range_uV, factor;
switch (range) {
case ADC_CONF_100M14B4CHA_CHN_RANGE_10V_CAL:
case ADC_CONF_100M14B4CHA_CHN_RANGE_10V:
/* 10V */
range_uV = 10000000;
break;
case ADC_CONF_100M14B4CHA_CHN_RANGE_100mV_CAL:
case ADC_CONF_100M14B4CHA_CHN_RANGE_100mV:
/* 100mV */
range_uV = 100000;
break;
case ADC_CONF_100M14B4CHA_CHN_RANGE_1V_CAL:
case ADC_CONF_100M14B4CHA_CHN_RANGE_1V:
case ADC_CONF_100M14B4CHA_CHN_RANGE_OPEN_DRAIN:
/* 1V */
range_uV = 1000000;
break;
default:
fprintf(stderr, "Invalid switch configuration 0x%x\n", range);
return 0;
}
factor = (range_uV / BIT(14));
result_int = ((val >> 2) * factor);
result_frac = ((val & 0x3) * 10) * (factor / 1000);
return result_int + result_frac;
}
static int __offz_rng_idx_get(enum adc_configuration_100m14b4cha_channel_range range)
{
int idx = 0;
......@@ -1299,7 +1293,6 @@ static int adc_100m14b4cha_offac_sw_avg_man(struct adc_dev *dev,
for (i = 0; i < FA100M14B4C_NCHAN; ++i) {
int range = __offz_rng_idx_get(ranges[i]);
offset[i] = __convert_hw_to_uv(offset[i], ranges[i]);
adcdata->offset_zero[i][range] = offset[i];
}
......@@ -1352,10 +1345,8 @@ static int adc_100m14b4cha_offac_sw_avg_auto(struct adc_dev *dev,
* to the DAC. For this reason we do not need to revert
* that value: the offset sign measured it is fine
*/
for (k = 0; k < FA100M14B4C_NCHAN; ++k) {
offset[k] = __convert_hw_to_uv(offset[k], range);
for (k = 0; k < FA100M14B4C_NCHAN; ++k)
adcdata->offset_zero[k][i] = offset[k];
}
}
out:
......
// SPDX-License-Identifier: LGPL-3.0-or-later
/*
* Copyright CERN 2013, GNU GPL 2 or later.
* Copyright CERN 2013
* Author: Alessandro Rubini
*/
#include <stdio.h>
......
// SPDX-License-Identifier: LGPL-3.0-or-later
/*
* Routing public functions to device-specific code
*
* Copyright (C) 2018 CERN (www.cern.ch)
* Author: Federico Vaga <federico.vaga@cern.ch>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* version 2 as published by the Free Software Foundation or, at your
* option, any later version.
*/
#include <errno.h>
......
// SPDX-License-Identifier: LGPL-3.0-or-later
/*
* Initializing and cleaning up the adc library
*
* Copyright (C) 2013 CERN (www.cern.ch)
* Author: Federico Vaga <federico.vaga@gmail.com>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* version 2 as published by the Free Software Foundation or, at your
* option, any later version.
*/
#include <errno.h>
#include <string.h>
......@@ -40,6 +36,7 @@ static struct adc_errors {
{ADC_OFF_AC_RESTORE_S, "Offset auto-clear: cannot store configuration"},
{ADC_OFF_AC_RESTORE_R, "Offset auto-clear: cannot restore configuration"},
{ADC_ENOFLAGS, "Unsupported flags"},
{ADC_EDRVVERSION, "Incompatible driver version"},
{ 0, }
};
......
// SPDX-License-Identifier: LGPL-3.0-or-later
/*
* Routing public functions to device-specific code
*
* Copyright (C) 2013 CERN (www.cern.ch)
* Author: Federico Vaga <federico.vaga@gmail.com>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* version 2 as published by the Free Software Foundation or, at your
* option, any later version.
*/
#include <stdio.h>
......
......@@ -40,7 +40,7 @@ def adc_simple():
adc = PyFmcAdc100m14b4ch(pytest.adc_id)
for ch in range(4):
conf = PyAdcConf(PyAdcConf.ADC_CONF_TYPE_CHN, ch)
conf.value_set(PyAdcConf.ADC_CONF_CHN_RANGE, 0x45)
conf.value_set(PyAdcConf.ADC_CONF_CHN_RANGE, adc.ADC_CONF_100M14B4CHA_CHN_RANGE_10V)
conf.value_set(PyAdcConf.ADC_CONF_CHN_TERMINATION, 0)
conf.value_set(PyAdcConf.ADC_CONF_CHN_OFFSET, 0)
conf.value_set(PyAdcConf.ADC_CONF_CHN_SATURATION, 0x7FFF)
......
......@@ -60,16 +60,26 @@ class TestAdcAcquisitionPattern(object):
buf = adc_simple_pattern.request_buffer(nsamples, None, 0)
adc_simple_pattern.acq_start(PyFmcAdc100m14b4ch.ADC_F_FLUSH,
timeval(0, 0))
sleep_time = 0.5 + 1e-8 * (pre_samples + post_samples)
for n in range(nshots):
time.sleep(0.5 + 1e-8 * (pre_samples + post_samples))
time.sleep(sleep_time)
adc_simple_pattern.trigger_fire()
pattern = adc_simple_pattern.pattern_data
prev_ts = None
for n in range(nshots):
adc_simple_pattern.acq_poll(0, timeval(10, 0))
adc_simple_pattern.fill_buffer(buf, 0, timeval(10, 0))
assert buf.contents.nsamples == nsamples
last_ts = buf.contents.tstamp
if prev_ts is not None:
assert last_ts.to_ns_approx() > prev_ts.to_ns_approx()
delta = last_ts.to_ns_approx() - prev_ts.to_ns_approx()
assert delta > (sleep_time - 0.005) * 1e9
assert delta < (sleep_time + 0.005) * 1e9
prev_ts = last_ts
for chan in range(4):
for s in range(nsamples):
sample = abs(buf.contents.get_sample(chan, s) >> 2)
......
......@@ -80,7 +80,7 @@ class TestAdcGetterSetterChannel(object):
adc100m14b4cha.retrieve_config(conf_rb)
assert conf.value_get(PyAdcConf.ADC_CONF_CHN_TERMINATION) == conf_rb.value_get(PyAdcConf.ADC_CONF_CHN_TERMINATION)
@pytest.mark.parametrize("offset", range(-5000000, 5000000 + 1, 100000))
@pytest.mark.parametrize("offset", range(-5000000, 4999999 + 1, 100000))
@pytest.mark.parametrize("channel", range(4))
def test_adc_offset(self, adc100m14b4cha, offset, channel):
"""Test that we can read/write offset on all channels"""
......@@ -94,7 +94,7 @@ class TestAdcGetterSetterChannel(object):
adc100m14b4cha.retrieve_config(conf_rb)
assert conf.value_get(PyAdcConf.ADC_CONF_CHN_OFFSET) == conf_rb.value_get(PyAdcConf.ADC_CONF_CHN_OFFSET)
@pytest.mark.parametrize("offset", [-5000001, 5000001])
@pytest.mark.parametrize("offset", [-5000001, 5000000])
@pytest.mark.parametrize("channel", range(4))
def test_adc_offset_invalid(self, adc100m14b4cha, offset, channel):
"""Test that we can read/write offset on all channels"""
......
"""
SPDX-License-Identifier: GPL-3.0-or-later
SPDX-FileCopyrightText: 2020 CERN
"""
import pytest
import time
from PyAdcLib import PyAdcConf, PyFmcAdc100m14b4ch, timeval
import numpy as np
import matplotlib.pyplot as plt
@pytest.fixture(scope="function")
def adc_simple_triangle(adc_simple):
yield adc_simple
def digital_noise_plot(raw_data, index, chan_err, vref):
# convert signed data to mV (numpy array)
plot_data = np.array(raw_data)
# plot and store
f1, a1 = plt.subplots()
if vref == PyFmcAdc100m14b4ch.ADC_CONF_100M14B4CHA_CHN_RANGE_1V:
bit_scale = 0.5 / (1 << 15)
elif vref == PyFmcAdc100m14b4ch.ADC_CONF_100M14B4CHA_CHN_RANGE_10V:
bit_scale = 5.0 / (1 << 15)
else:
bit_scale = 1 # raw
volt_data = [data * bit_scale for data in raw_data]
for ch in range(0,4):
a1.plot(volt_data[ch::4], label='CH'+str(ch + 1) + (" WARN" if ch == chan_err else ""))
a1.set_xlabel('sample number')
a1.set_ylabel('Volt')
a1.legend()
f1.savefig("/tmp/digital_noise_plot.png", dpi=300)
plt.show()
def digital_noise_report(buf, index, chan_err, vref):
message = "Unexpected value on channel {:d}\n".format(chan_err)
if index > 1:
for chan in range(4):
prev = buf.contents.get_sample(chan, index - 1)
samp = buf.contents.get_sample(chan, index)
diff = abs(samp - prev)
message += "chan {:d}, sample {:d}: h{:x} = abs(h{:x} - h{:x}) = abs(b{:b} - b{:b})\n".format(chan,
index,
diff,
prev,
samp,
prev,
samp)
subset = buf.contents.data[:buf.contents.nsamples * 4]
message += str(subset)
digital_noise_plot(subset, index, chan_err, vref)
return message
class TestAdcRegressions(object):
@pytest.mark.parametrize("vref", [PyFmcAdc100m14b4ch.ADC_CONF_100M14B4CHA_CHN_RANGE_1V,
PyFmcAdc100m14b4ch.ADC_CONF_100M14B4CHA_CHN_RANGE_10V,
])
@pytest.mark.parametrize("termination", [0, 1])
@pytest.mark.parametrize("nshots, post_samples", [(10, 2045), (1, 4000)])
def test_adc_digital_noise(self, adc_simple_triangle, nshots, post_samples, vref, termination):
""" With the v5 release we noticed some digital noise on the acquired signal.
This test uses a sawtooth signal to check that the noise is between
define boundaries. If it exceed, then we have a problem.
A function generator must be configured to produce a triangle signal
(simpler to process) on all channels. Expected configuration: 1Vpp, 100kHz"""
for ch in range(4):
conf = PyAdcConf(PyAdcConf.ADC_CONF_TYPE_CHN, ch)
conf.value_set(PyAdcConf.ADC_CONF_CHN_TERMINATION, termination)
conf.value_set(PyAdcConf.ADC_CONF_CHN_RANGE, vref)
adc_simple_triangle.apply_config(conf, 0)
conf = PyAdcConf(PyAdcConf.ADC_CONF_TYPE_ACQ, 0)
conf.value_set(PyAdcConf.ADC_CONF_ACQ_PRE_SAMP, 0)
conf.value_set(PyAdcConf.ADC_CONF_ACQ_POST_SAMP, post_samples)
conf.value_set(PyAdcConf.ADC_CONF_ACQ_N_SHOTS, nshots)
adc_simple_triangle.apply_config(conf, 0)
buf = adc_simple_triangle.request_buffer(post_samples, None, 0)
adc_simple_triangle.acq_start(PyFmcAdc100m14b4ch.ADC_F_FLUSH,
timeval(0, 0))
sleep_time = 0.5 + 1e-8 * post_samples
for n in range(nshots):
time.sleep(sleep_time)
adc_simple_triangle.trigger_fire()
for n in range(nshots):
adc_simple_triangle.acq_poll(0, timeval(10, 0))
adc_simple_triangle.fill_buffer(buf, 0, timeval(10, 0))
assert buf.contents.nsamples == post_samples
for chan in range(4):
prev_s = None
for i in range(post_samples):
sample = buf.contents.get_sample(chan, i) >> 2
if prev_s is not None:
# TODO improve future sample computarion (just rule of thumb number now)
assert abs(sample - prev_s) < 50, digital_noise_report(buf, i, chan, vref)
prev_s = sample
adc_simple_triangle.release_buffer(buf, None)
# SPDX-FileCopyrightText: 2021 CERN (home.cern)
#
# SPDX-License-Identifier: CC0-1.0
adc-acq
example
# SPDX-FileCopyrightText: 2021 CERN (home.cern)
#
# SPDX-License-Identifier: CC0-1.0
# If it exists includes Makefile.specific. In this Makefile, you should put
# specific Makefile code that you want to run before this. For example,
# build a particular environment.
......@@ -20,29 +24,32 @@ LDFLAGS = -L$(LIBADC)
LDLIBS += -Wl,-Bstatic -ladc
LDLIBS += -Wl,-Bdynamic -lrt
DEMOS := adc-acq
DEMOS += example
PROGS := adc-acq
DEMOS := example
CPPCHECK ?= cppcheck
FLAWFINDER ?= flawfinder
all: demo
all: demo progs
demo: $(DEMOS)
install:
progs: $(PROGS)
install: progs
install -d $(DESTDIR)/bin
install -D $(DEMOS) $(DESTDIR)/bin
install -m 755 $(PROGS) $(DESTDIR)/bin
%: %.c $(LIBADC)/libadc.a
$(CC) $(CFLAGS) $^ -o $@ $(LDFLAGS) $(LDLIBS)
cppcheck:
$(CPPCHECK) --enable=all ./
$(CPPCHECK) -q -I../lib --enable=all --suppress=missingIncludeSystem *.c --error-exitcode=1
# make nothing for modules_install, but avoid errors
modules_install:
flawfinder:
$(FLAWFINDER) -SQDC --error-level=4 .
clean:
rm -f $(DEMOS) *.o *~
rm -f $(DEMOS) $(PROGS) *.o *~
.PHONY: all, clean
This diff is collapsed.
// SPDX-License-Identifier: GPL-3.0-or-later
/* Copyright 2013 CERN
* Author: Federico Vaga <federico.vaga@cern.ch>
* License: GPLv2
*
* This is an example program that shows the different part of the library
* in action.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment