pax_global_header 0000666 0000000 0000000 00000000064 13156247624 0014524 g ustar 00root root 0000000 0000000 52 comment=9ed2c4602675bfd27ae422c1922b582e2542486c
list-master/ 0000775 0000000 0000000 00000000000 13156247624 0013334 5 ustar 00root root 0000000 0000000 list-master/.gitmodules 0000664 0000000 0000000 00000000164 13156247624 0015512 0 ustar 00root root 0000000 0000000 [submodule "mock-turtle-sw"]
path = mock-turtle-sw
url = git@ohwr.org:hdl-core-lib/mock-turtle/mock-turtle-sw.git
list-master/CHANGELOG 0000664 0000000 0000000 00000000000 13156247624 0014534 0 ustar 00root root 0000000 0000000 list-master/CONTRIBUTING.md 0000664 0000000 0000000 00000001303 13156247624 0015562 0 ustar 00root root 0000000 0000000 The project is based on the Mock Turtle infrastructure. On top of the
Mock Turtle we have the White Rabbit Trigger Distribution.
The project is made of:
- two real-time applications running on the Mock Turtle CPUs
- one library which provide the application's abstraction to communicate with
the real-time applications.
- a set of command line tools for the White Rabbit Trigger Distribution
configuration
RULES
=====
The master branch is protected so you need special permission to touch it.
Do you development on your own branch and push it.
In the project we are following the Linux kernel code style.
All the functions, defines, structures, enumeraters exported should use
the `wrtd_` prefix.
list-master/LICENSE 0000664 0000000 0000000 00000077327 13156247624 0014361 0 ustar 00root root 0000000 0000000 GNU GENERAL PUBLIC LICENSE
Version 3, 29 June 2007
Copyright (C) 2007 Free Software Foundation, Inc.
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
Preamble
The GNU General Public License is a free, copyleft license for
software and other kinds of works.
The licenses for most software and other practical works are designed
to take away your freedom to share and change the works. By contrast,
the GNU General Public License is intended to guarantee your freedom to
share and change all versions of a program--to make sure it remains free
software for all its users. We, the Free Software Foundation, use the
GNU General Public License for most of our software; it applies also to
any other work released this way by its authors. You can apply it to
your programs, too.
When we speak of free software, we are referring to freedom, not
price. Our General Public Licenses are designed to make sure that you
have the freedom to distribute copies of free software (and charge for
them if you wish), that you receive source code or can get it if you
want it, that you can change the software or use pieces of it in new
free programs, and that you know you can do these things.
To protect your rights, we need to prevent others from denying you
these rights or asking you to surrender the rights. Therefore, you have
certain responsibilities if you distribute copies of the software, or if
you modify it: responsibilities to respect the freedom of others.
For example, if you distribute copies of such a program, whether
gratis or for a fee, you must pass on to the recipients the same
freedoms that you received. You must make sure that they, too, receive
or can get the source code. And you must show them these terms so they
know their rights.
Developers that use the GNU GPL protect your rights with two steps:
(1) assert copyright on the software, and (2) offer you this License
giving you legal permission to copy, distribute and/or modify it.
For the developers' and authors' protection, the GPL clearly explains
that there is no warranty for this free software. For both users' and
authors' sake, the GPL requires that modified versions be marked as
changed, so that their problems will not be attributed erroneously to
authors of previous versions.
Some devices are designed to deny users access to install or run
modified versions of the software inside them, although the manufacturer
can do so. This is fundamentally incompatible with the aim of
protecting users' freedom to change the software. The systematic
pattern of such abuse occurs in the area of products for individuals to
use, which is precisely where it is most unacceptable. Therefore, we
have designed this version of the GPL to prohibit the practice for those
products. If such problems arise substantially in other domains, we
stand ready to extend this provision to those domains in future versions
of the GPL, as needed to protect the freedom of users.
Finally, every program is threatened constantly by software patents.
States should not allow patents to restrict development and use of
software on general-purpose computers, but in those that do, we wish to
avoid the special danger that patents applied to a free program could
make it effectively proprietary. To prevent this, the GPL assures that
patents cannot be used to render the program non-free.
The precise terms and conditions for copying, distribution and
modification follow.
TERMS AND CONDITIONS
0. Definitions.
"This License" refers to version 3 of the GNU General Public License.
"Copyright" also means copyright-like laws that apply to other kinds of
works, such as semiconductor masks.
"The Program" refers to any copyrightable work licensed under this
License. Each licensee is addressed as "you". "Licensees" and
"recipients" may be individuals or organizations.
To "modify" a work means to copy from or adapt all or part of the work
in a fashion requiring copyright permission, other than the making of an
exact copy. The resulting work is called a "modified version" of the
earlier work or a work "based on" the earlier work.
A "covered work" means either the unmodified Program or a work based
on the Program.
To "propagate" a work means to do anything with it that, without
permission, would make you directly or secondarily liable for
infringement under applicable copyright law, except executing it on a
computer or modifying a private copy. Propagation includes copying,
distribution (with or without modification), making available to the
public, and in some countries other activities as well.
To "convey" a work means any kind of propagation that enables other
parties to make or receive copies. Mere interaction with a user through
a computer network, with no transfer of a copy, is not conveying.
An interactive user interface displays "Appropriate Legal Notices"
to the extent that it includes a convenient and prominently visible
feature that (1) displays an appropriate copyright notice, and (2)
tells the user that there is no warranty for the work (except to the
extent that warranties are provided), that licensees may convey the
work under this License, and how to view a copy of this License. If
the interface presents a list of user commands or options, such as a
menu, a prominent item in the list meets this criterion.
1. Source Code.
The "source code" for a work means the preferred form of the work
for making modifications to it. "Object code" means any non-source
form of a work.
A "Standard Interface" means an interface that either is an official
standard defined by a recognized standards body, or, in the case of
interfaces specified for a particular programming language, one that
is widely used among developers working in that language.
The "System Libraries" of an executable work include anything, other
than the work as a whole, that (a) is included in the normal form of
packaging a Major Component, but which is not part of that Major
Component, and (b) serves only to enable use of the work with that
Major Component, or to implement a Standard Interface for which an
implementation is available to the public in source code form. A
"Major Component", in this context, means a major essential component
(kernel, window system, and so on) of the specific operating system
(if any) on which the executable work runs, or a compiler used to
produce the work, or an object code interpreter used to run it.
The "Corresponding Source" for a work in object code form means all
the source code needed to generate, install, and (for an executable
work) run the object code and to modify the work, including scripts to
control those activities. However, it does not include the work's
System Libraries, or general-purpose tools or generally available free
programs which are used unmodified in performing those activities but
which are not part of the work. For example, Corresponding Source
includes interface definition files associated with source files for
the work, and the source code for shared libraries and dynamically
linked subprograms that the work is specifically designed to require,
such as by intimate data communication or control flow between those
subprograms and other parts of the work.
The Corresponding Source need not include anything that users
can regenerate automatically from other parts of the Corresponding
Source.
The Corresponding Source for a work in source code form is that
same work.
2. Basic Permissions.
All rights granted under this License are granted for the term of
copyright on the Program, and are irrevocable provided the stated
conditions are met. This License explicitly affirms your unlimited
permission to run the unmodified Program. The output from running a
covered work is covered by this License only if the output, given its
content, constitutes a covered work. This License acknowledges your
rights of fair use or other equivalent, as provided by copyright law.
You may make, run and propagate covered works that you do not
convey, without conditions so long as your license otherwise remains
in force. You may convey covered works to others for the sole purpose
of having them make modifications exclusively for you, or provide you
with facilities for running those works, provided that you comply with
the terms of this License in conveying all material for which you do
not control copyright. Those thus making or running the covered works
for you must do so exclusively on your behalf, under your direction
and control, on terms that prohibit them from making any copies of
your copyrighted material outside their relationship with you.
Conveying under any other circumstances is permitted solely under
the conditions stated below. Sublicensing is not allowed; section 10
makes it unnecessary.
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
No covered work shall be deemed part of an effective technological
measure under any applicable law fulfilling obligations under article
11 of the WIPO copyright treaty adopted on 20 December 1996, or
similar laws prohibiting or restricting circumvention of such
measures.
When you convey a covered work, you waive any legal power to forbid
circumvention of technological measures to the extent such circumvention
is effected by exercising rights under this License with respect to
the covered work, and you disclaim any intention to limit operation or
modification of the work as a means of enforcing, against the work's
users, your or third parties' legal rights to forbid circumvention of
technological measures.
4. Conveying Verbatim Copies.
You may convey verbatim copies of the Program's source code as you
receive it, in any medium, provided that you conspicuously and
appropriately publish on each copy an appropriate copyright notice;
keep intact all notices stating that this License and any
non-permissive terms added in accord with section 7 apply to the code;
keep intact all notices of the absence of any warranty; and give all
recipients a copy of this License along with the Program.
You may charge any price or no price for each copy that you convey,
and you may offer support or warranty protection for a fee.
5. Conveying Modified Source Versions.
You may convey a work based on the Program, or the modifications to
produce it from the Program, in the form of source code under the
terms of section 4, provided that you also meet all of these conditions:
a) The work must carry prominent notices stating that you modified
it, and giving a relevant date.
b) The work must carry prominent notices stating that it is
released under this License and any conditions added under section
7. This requirement modifies the requirement in section 4 to
"keep intact all notices".
c) You must license the entire work, as a whole, under this
License to anyone who comes into possession of a copy. This
License will therefore apply, along with any applicable section 7
additional terms, to the whole of the work, and all its parts,
regardless of how they are packaged. This License gives no
permission to license the work in any other way, but it does not
invalidate such permission if you have separately received it.
d) If the work has interactive user interfaces, each must display
Appropriate Legal Notices; however, if the Program has interactive
interfaces that do not display Appropriate Legal Notices, your
work need not make them do so.
A compilation of a covered work with other separate and independent
works, which are not by their nature extensions of the covered work,
and which are not combined with it such as to form a larger program,
in or on a volume of a storage or distribution medium, is called an
"aggregate" if the compilation and its resulting copyright are not
used to limit the access or legal rights of the compilation's users
beyond what the individual works permit. Inclusion of a covered work
in an aggregate does not cause this License to apply to the other
parts of the aggregate.
6. Conveying Non-Source Forms.
You may convey a covered work in object code form under the terms
of sections 4 and 5, provided that you also convey the
machine-readable Corresponding Source under the terms of this License,
in one of these ways:
a) Convey the object code in, or embodied in, a physical product
(including a physical distribution medium), accompanied by the
Corresponding Source fixed on a durable physical medium
customarily used for software interchange.
b) Convey the object code in, or embodied in, a physical product
(including a physical distribution medium), accompanied by a
written offer, valid for at least three years and valid for as
long as you offer spare parts or customer support for that product
model, to give anyone who possesses the object code either (1) a
copy of the Corresponding Source for all the software in the
product that is covered by this License, on a durable physical
medium customarily used for software interchange, for a price no
more than your reasonable cost of physically performing this
conveying of source, or (2) access to copy the
Corresponding Source from a network server at no charge.
c) Convey individual copies of the object code with a copy of the
written offer to provide the Corresponding Source. This
alternative is allowed only occasionally and noncommercially, and
only if you received the object code with such an offer, in accord
with subsection 6b.
d) Convey the object code by offering access from a designated
place (gratis or for a charge), and offer equivalent access to the
Corresponding Source in the same way through the same place at no
further charge. You need not require recipients to copy the
Corresponding Source along with the object code. If the place to
copy the object code is a network server, the Corresponding Source
may be on a different server (operated by you or a third party)
that supports equivalent copying facilities, provided you maintain
clear directions next to the object code saying where to find the
Corresponding Source. Regardless of what server hosts the
Corresponding Source, you remain obligated to ensure that it is
available for as long as needed to satisfy these requirements.
e) Convey the object code using peer-to-peer transmission, provided
you inform other peers where the object code and Corresponding
Source of the work are being offered to the general public at no
charge under subsection 6d.
A separable portion of the object code, whose source code is excluded
from the Corresponding Source as a System Library, need not be
included in conveying the object code work.
A "User Product" is either (1) a "consumer product", which means any
tangible personal property which is normally used for personal, family,
or household purposes, or (2) anything designed or sold for incorporation
into a dwelling. In determining whether a product is a consumer product,
doubtful cases shall be resolved in favor of coverage. For a particular
product received by a particular user, "normally used" refers to a
typical or common use of that class of product, regardless of the status
of the particular user or of the way in which the particular user
actually uses, or expects or is expected to use, the product. A product
is a consumer product regardless of whether the product has substantial
commercial, industrial or non-consumer uses, unless such uses represent
the only significant mode of use of the product.
"Installation Information" for a User Product means any methods,
procedures, authorization keys, or other information required to install
and execute modified versions of a covered work in that User Product from
a modified version of its Corresponding Source. The information must
suffice to ensure that the continued functioning of the modified object
code is in no case prevented or interfered with solely because
modification has been made.
If you convey an object code work under this section in, or with, or
specifically for use in, a User Product, and the conveying occurs as
part of a transaction in which the right of possession and use of the
User Product is transferred to the recipient in perpetuity or for a
fixed term (regardless of how the transaction is characterized), the
Corresponding Source conveyed under this section must be accompanied
by the Installation Information. But this requirement does not apply
if neither you nor any third party retains the ability to install
modified object code on the User Product (for example, the work has
been installed in ROM).
The requirement to provide Installation Information does not include a
requirement to continue to provide support service, warranty, or updates
for a work that has been modified or installed by the recipient, or for
the User Product in which it has been modified or installed. Access to a
network may be denied when the modification itself materially and
adversely affects the operation of the network or violates the rules and
protocols for communication across the network.
Corresponding Source conveyed, and Installation Information provided,
in accord with this section must be in a format that is publicly
documented (and with an implementation available to the public in
source code form), and must require no special password or key for
unpacking, reading or copying.
7. Additional Terms.
"Additional permissions" are terms that supplement the terms of this
License by making exceptions from one or more of its conditions.
Additional permissions that are applicable to the entire Program shall
be treated as though they were included in this License, to the extent
that they are valid under applicable law. If additional permissions
apply only to part of the Program, that part may be used separately
under those permissions, but the entire Program remains governed by
this License without regard to the additional permissions.
When you convey a copy of a covered work, you may at your option
remove any additional permissions from that copy, or from any part of
it. (Additional permissions may be written to require their own
removal in certain cases when you modify the work.) You may place
additional permissions on material, added by you to a covered work,
for which you have or can give appropriate copyright permission.
Notwithstanding any other provision of this License, for material you
add to a covered work, you may (if authorized by the copyright holders of
that material) supplement the terms of this License with terms:
a) Disclaiming warranty or limiting liability differently from the
terms of sections 15 and 16 of this License; or
b) Requiring preservation of specified reasonable legal notices or
author attributions in that material or in the Appropriate Legal
Notices displayed by works containing it; or
c) Prohibiting misrepresentation of the origin of that material, or
requiring that modified versions of such material be marked in
reasonable ways as different from the original version; or
d) Limiting the use for publicity purposes of names of licensors or
authors of the material; or
e) Declining to grant rights under trademark law for use of some
trade names, trademarks, or service marks; or
f) Requiring indemnification of licensors and authors of that
material by anyone who conveys the material (or modified versions of
it) with contractual assumptions of liability to the recipient, for
any liability that these contractual assumptions directly impose on
those licensors and authors.
All other non-permissive additional terms are considered "further
restrictions" within the meaning of section 10. If the Program as you
received it, or any part of it, contains a notice stating that it is
governed by this License along with a term that is a further
restriction, you may remove that term. If a license document contains
a further restriction but permits relicensing or conveying under this
License, you may add to a covered work material governed by the terms
of that license document, provided that the further restriction does
not survive such relicensing or conveying.
If you add terms to a covered work in accord with this section, you
must place, in the relevant source files, a statement of the
additional terms that apply to those files, or a notice indicating
where to find the applicable terms.
Additional terms, permissive or non-permissive, may be stated in the
form of a separately written license, or stated as exceptions;
the above requirements apply either way.
8. Termination.
You may not propagate or modify a covered work except as expressly
provided under this License. Any attempt otherwise to propagate or
modify it is void, and will automatically terminate your rights under
this License (including any patent licenses granted under the third
paragraph of section 11).
However, if you cease all violation of this License, then your
license from a particular copyright holder is reinstated (a)
provisionally, unless and until the copyright holder explicitly and
finally terminates your license, and (b) permanently, if the copyright
holder fails to notify you of the violation by some reasonable means
prior to 60 days after the cessation.
Moreover, your license from a particular copyright holder is
reinstated permanently if the copyright holder notifies you of the
violation by some reasonable means, this is the first time you have
received notice of violation of this License (for any work) from that
copyright holder, and you cure the violation prior to 30 days after
your receipt of the notice.
Termination of your rights under this section does not terminate the
licenses of parties who have received copies or rights from you under
this License. If your rights have been terminated and not permanently
reinstated, you do not qualify to receive new licenses for the same
material under section 10.
9. Acceptance Not Required for Having Copies.
You are not required to accept this License in order to receive or
run a copy of the Program. Ancillary propagation of a covered work
occurring solely as a consequence of using peer-to-peer transmission
to receive a copy likewise does not require acceptance. However,
nothing other than this License grants you permission to propagate or
modify any covered work. These actions infringe copyright if you do
not accept this License. Therefore, by modifying or propagating a
covered work, you indicate your acceptance of this License to do so.
10. Automatic Licensing of Downstream Recipients.
Each time you convey a covered work, the recipient automatically
receives a license from the original licensors, to run, modify and
propagate that work, subject to this License. You are not responsible
for enforcing compliance by third parties with this License.
An "entity transaction" is a transaction transferring control of an
organization, or substantially all assets of one, or subdividing an
organization, or merging organizations. If propagation of a covered
work results from an entity transaction, each party to that
transaction who receives a copy of the work also receives whatever
licenses to the work the party's predecessor in interest had or could
give under the previous paragraph, plus a right to possession of the
Corresponding Source of the work from the predecessor in interest, if
the predecessor has it or can get it with reasonable efforts.
You may not impose any further restrictions on the exercise of the
rights granted or affirmed under this License. For example, you may
not impose a license fee, royalty, or other charge for exercise of
rights granted under this License, and you may not initiate litigation
(including a cross-claim or counterclaim in a lawsuit) alleging that
any patent claim is infringed by making, using, selling, offering for
sale, or importing the Program or any portion of it.
11. Patents.
A "contributor" is a copyright holder who authorizes use under this
License of the Program or a work on which the Program is based. The
work thus licensed is called the contributor's "contributor version".
A contributor's "essential patent claims" are all patent claims
owned or controlled by the contributor, whether already acquired or
hereafter acquired, that would be infringed by some manner, permitted
by this License, of making, using, or selling its contributor version,
but do not include claims that would be infringed only as a
consequence of further modification of the contributor version. For
purposes of this definition, "control" includes the right to grant
patent sublicenses in a manner consistent with the requirements of
this License.
Each contributor grants you a non-exclusive, worldwide, royalty-free
patent license under the contributor's essential patent claims, to
make, use, sell, offer for sale, import and otherwise run, modify and
propagate the contents of its contributor version.
In the following three paragraphs, a "patent license" is any express
agreement or commitment, however denominated, not to enforce a patent
(such as an express permission to practice a patent or covenant not to
sue for patent infringement). To "grant" such a patent license to a
party means to make such an agreement or commitment not to enforce a
patent against the party.
If you convey a covered work, knowingly relying on a patent license,
and the Corresponding Source of the work is not available for anyone
to copy, free of charge and under the terms of this License, through a
publicly available network server or other readily accessible means,
then you must either (1) cause the Corresponding Source to be so
available, or (2) arrange to deprive yourself of the benefit of the
patent license for this particular work, or (3) arrange, in a manner
consistent with the requirements of this License, to extend the patent
license to downstream recipients. "Knowingly relying" means you have
actual knowledge that, but for the patent license, your conveying the
covered work in a country, or your recipient's use of the covered work
in a country, would infringe one or more identifiable patents in that
country that you have reason to believe are valid.
If, pursuant to or in connection with a single transaction or
arrangement, you convey, or propagate by procuring conveyance of, a
covered work, and grant a patent license to some of the parties
receiving the covered work authorizing them to use, propagate, modify
or convey a specific copy of the covered work, then the patent license
you grant is automatically extended to all recipients of the covered
work and works based on it.
A patent license is "discriminatory" if it does not include within
the scope of its coverage, prohibits the exercise of, or is
conditioned on the non-exercise of one or more of the rights that are
specifically granted under this License. You may not convey a covered
work if you are a party to an arrangement with a third party that is
in the business of distributing software, under which you make payment
to the third party based on the extent of your activity of conveying
the work, and under which the third party grants, to any of the
parties who would receive the covered work from you, a discriminatory
patent license (a) in connection with copies of the covered work
conveyed by you (or copies made from those copies), or (b) primarily
for and in connection with specific products or compilations that
contain the covered work, unless you entered into that arrangement,
or that patent license was granted, prior to 28 March 2007.
Nothing in this License shall be construed as excluding or limiting
any implied license or other defenses to infringement that may
otherwise be available to you under applicable patent law.
12. No Surrender of Others' Freedom.
If conditions are imposed on you (whether by court order, agreement or
otherwise) that contradict the conditions of this License, they do not
excuse you from the conditions of this License. If you cannot convey a
covered work so as to satisfy simultaneously your obligations under this
License and any other pertinent obligations, then as a consequence you may
not convey it at all. For example, if you agree to terms that obligate you
to collect a royalty for further conveying from those to whom you convey
the Program, the only way you could satisfy both those terms and this
License would be to refrain entirely from conveying the Program.
13. Use with the GNU Affero General Public License.
Notwithstanding any other provision of this License, you have
permission to link or combine any covered work with a work licensed
under version 3 of the GNU Affero General Public License into a single
combined work, and to convey the resulting work. The terms of this
License will continue to apply to the part which is the covered work,
but the special requirements of the GNU Affero General Public License,
section 13, concerning interaction through a network will apply to the
combination as such.
14. Revised Versions of this License.
The Free Software Foundation may publish revised and/or new versions of
the GNU 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
Program specifies that a certain numbered version of the GNU General
Public License "or any later version" applies to it, you have the
option of following the terms and conditions either of that numbered
version or of any later version published by the Free Software
Foundation. If the Program does not specify a version number of the
GNU General Public License, you may choose any version ever published
by the Free Software Foundation.
If the Program specifies that a proxy can decide which future
versions of the GNU General Public License can be used, that proxy's
public statement of acceptance of a version permanently authorizes you
to choose that version for the Program.
Later license versions may give you additional or different
permissions. However, no additional obligations are imposed on any
author or copyright holder as a result of your choosing to follow a
later version.
15. Disclaimer of Warranty.
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
16. Limitation of Liability.
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
SUCH DAMAGES.
17. Interpretation of Sections 15 and 16.
If the disclaimer of warranty and limitation of liability provided
above cannot be given local legal effect according to their terms,
reviewing courts shall apply local law that most closely approximates
an absolute waiver of all civil liability in connection with the
Program, unless a warranty or assumption of liability accompanies a
copy of the Program in return for a fee.
END OF TERMS AND CONDITIONS list-master/Makefile 0000664 0000000 0000000 00000000455 13156247624 0015000 0 ustar 00root root 0000000 0000000
.PHONY: all clean modules install modules_install clean_all
.PHONY: gitmodules prereq prereq_install prereq_install_warn prereq_clean
DIRS = mock-turtle-sw lib tools rt/fd rt/tdc unittest
all clean modules install modules_install: gitmodules
for d in $(DIRS); do $(MAKE) -C $$d $@ || exit 1; done
list-master/README.md 0000664 0000000 0000000 00000000337 13156247624 0014616 0 ustar 00root root 0000000 0000000 White Rabbit Trigger Distribution - WRTD
The aim of the project is to provide a system that is able to receive triggers
from some external source and destribute these triggers to remote nodes over
the white rabbit network.
list-master/doc/ 0000775 0000000 0000000 00000000000 13156247624 0014101 5 ustar 00root root 0000000 0000000 list-master/doc/.gitignore 0000664 0000000 0000000 00000000011 13156247624 0016061 0 ustar 00root root 0000000 0000000 doxy-wrtd list-master/doc/Makefile 0000664 0000000 0000000 00000001034 13156247624 0015537 0 ustar 00root root 0000000 0000000 GIT_VERSION = $(shell cd $(src); git describe --dirty --long --tags)
O ?= doxy-wrtd
# Build the documentation with or without the internals details
ifdef SHOW_INTERNALS
EXCLUDE_FILES = ""
BRIEF = "API Documentation - With Internals"
else
EXCLUDE_FILES = "../lib/libwrtd-internal.h"
BRIEF = "API Documentation"
endif
all: doxygen
doxygen:
GIT_VERSION=$(GIT_VERSION) EXCLUDE_FILES=$(EXCLUDE_FILES) BRIEF=$(BRIEF) \
OUTPUT=$(O) doxygen ./doxygen-wrtd-config
clean:
rm -rf $(O)
# Latex stuff
rm -f *.dvi *.aux *.out *.log *.backup
list-master/doc/dictionary.md 0000664 0000000 0000000 00000000300 13156247624 0016561 0 ustar 00root root 0000000 0000000 Dictionary
==========
The main purpose of this dictionary is to explain the
White-Rabbit Trigger-Distribution terminology.
channel
dead time
delay
input
output
pulse
trigger
trigger condition list-master/doc/doxygen-wrtd-config 0000664 0000000 0000000 00000001070 13156247624 0017720 0 ustar 00root root 0000000 0000000 PROJECT_NAME = "White Rabbit Trigger Distribution - Software"
PROJECT_NUMBER = $(GIT_VERSION)
PROJECT_BRIEF = $(BRIEF)
PROJECT_LOGO =
OUTPUT_DIRECTORY = $(OUTPUT)
CREATE_SUBDIRS = YES
TAB_SIZE = 8
OPTIMIZE_OUTPUT_FOR_C = YES
EXTRACT_STATIC = YES
CASE_SENSE_NAMES = YES
WARN_NO_PARAMDOC = YES
INPUT = ../lib ../include/wrtd-common.h
RECURSIVE = YES
EXCLUDE = $(EXCLUDE_FILES)
GENERATE_HTML = YES
GENERATE_LATEX = YES
list-master/include/ 0000775 0000000 0000000 00000000000 13156247624 0014757 5 ustar 00root root 0000000 0000000 list-master/include/wrtd-common.h 0000664 0000000 0000000 00000034505 13156247624 0017405 0 ustar 00root root 0000000 0000000 /*
* Copyright (C) 2014-2016 CERN (www.cern.ch)
* Author: Tomasz Wlostowski
* Author: Federico Vaga
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*/
#ifndef __WRTD_COMMON_H
#define __WRTD_COMMON_H
#define WRTD_IN_RT_ID 0x347D0000
#define WRTD_OUT_RT_ID 0x347D0001
/* WR Node CPU Core indices */
#define WRTD_CPU_TDC 0 /* Core 0 controls the TDC mezzanine */
#define WRTD_CPU_FD 1 /* Core 1 controls the FD mezzanine */
#define WRTD_IN_MAX 2
#define WRTD_IN_TDC_CONTROL 0
#define WRTD_IN_FD_CONTROL 1
#define WRTD_OUT_MAX 4
#define WRTD_OUT_TDC_CONTROL 0
#define WRTD_OUT_FD_CONTROL 1
#define WRTD_OUT_TDC_LOGGING 2
#define WRTD_OUT_FD_LOGGING 3
#define WRTD_REMOTE_IN_MAX 1
#define WRTD_REMOTE_IN_FD 0
#define WRTD_REMOTE_OUT_MAX 1
#define WRTD_REMOTE_OUT_TDC 0
/* Command and log message IDs */
#define WRTD_CMD_TDC_CHAN_ENABLE 0x1
#define WRTD_CMD_TDC_CHAN_SET_DEAD_TIME 0x2
#define WRTD_CMD_TDC_CHAN_SET_DELAY 0x3
#define WRTD_CMD_TDC_CHAN_GET_STATE 0x4
#define WRTD_CMD_TDC_CHAN_ARM 0x5
#define WRTD_CMD_TDC_CHAN_SET_MODE 0x7
#define WRTD_CMD_TDC_CHAN_SET_SEQ 0x8
#define WRTD_CMD_TDC_CHAN_ASSIGN_TRIGGER 0x9
#define WRTD_CMD_TDC_CHAN_SET_FLAGS 0xa
#define WRTD_CMD_TDC_CHAN_SET_TIMEBASE_OFFSET 0xb
#define WRTD_CMD_TDC_PING 0xc
#define WRTD_CMD_TDC_SOFTWARE_TRIGGER 0xd
#define WRTD_CMD_TDC_CHAN_SET_LOG_LEVEL 0xe
#define WRTD_CMD_TDC_CHAN_RESET_COUNTERS 0xf
#define WRTD_CMD_TDC_BASE_TIME 0x10
#define WRTD_CMD_TDC_VERSION 0x11
#define WRTD_CMD_FD_TRIG_ENABLE 0x10
#define WRTD_CMD_FD_TRIG_REMOVE 0x11
#define WRTD_CMD_FD_TRIG_ASSIGN 0x12
#define WRTD_CMD_FD_TRIG_GET_BY_ID 0x13
#define WRTD_CMD_FD_TRIG_GET_STATE 0x14
#define WRTD_CMD_FD_TRIG_SET_COND_DELAY 0x15
#define WRTD_CMD_FD_TRIG_SET_DELAY 0x16
#define WRTD_CMD_FD_TRIG_RESET_COUNTERS 0x17
#define WRTD_CMD_FD_CHAN_ENABLE 0x1
#define WRTD_CMD_FD_READ_HASH 0x2
#define WRTD_CMD_FD_CHAN_GET_STATE 0x3
#define WRTD_CMD_FD_CHAN_SET_WIDTH 0x4
#define WRTD_CMD_FD_CHAN_SET_MODE 0x5
#define WRTD_CMD_FD_SOFTWARE_TRIGGER 0x6
#define WRTD_CMD_FD_CHAN_ARM 0x7
#define WRTD_CMD_FD_CHAN_SET_LOG_LEVEL 0x8
#define WRTD_CMD_FD_CHAN_RESET_COUNTERS 0x9
#define WRTD_CMD_FD_PING 0xa
#define WRTD_CMD_FD_BASE_TIME 0xb
#define WRTD_CMD_FD_CHAN_DEAD_TIME 0xc
#define WRTD_CMD_FD_VERSION 0xd
#define WRTD_REP_ACK_ID 0x100
#define WRTD_REP_STATE 0x101
#define WRTD_REP_NACK 0x102
#define WRTD_REP_TRIGGER_HANDLE 0x103
#define WRTD_REP_HASH_ENTRY 0x104
#define WRTD_REP_TIMESTAMP 0x105
#define WRTD_REP_LOG_MESSAGE 0x106
#define WRTD_REP_BASE_TIME_ID 0x107
#define WRTD_REP_VERSION 0x108
#define TDC_NUM_CHANNELS 5
#define TDC_TRIGGER_COALESCE_LIMIT 5
#define FD_NUM_CHANNELS 4
#define FD_HASH_ENTRIES 64
#define FD_MAX_QUEUE_PULSES 16
enum wrtd_in_actions {
WRTD_IN_ACTION_SW_TRIG = __RT_ACTION_RECV_STANDARD_NUMBER,
WRTD_IN_ACTION_LOG,
};
enum wrtd_out_actions {
WRTD_OUT_ACTION_SW_TRIG = __RT_ACTION_RECV_STANDARD_NUMBER,
WRTD_OUT_ACTION_TRIG_IDX,
WRTD_OUT_ACTION_TRIG_FRE,
WRTD_OUT_ACTION_TRIG_ADD,
WRTD_OUT_ACTION_TRIG_DEL,
WRTD_OUT_ACTION_LOG,
WRTD_OUT_ACTION_DISABLE,
};
enum wrtd_in_variables_indexes {
IN_VAR_CHAN_ENABLE = 0,
IN_VAR_DEVICE_TIME_S,
IN_VAR_DEVICE_TIME_T,
IN_VAR_DEVICE_SENT_PACK,
IN_VAR_DEVICE_DEAD_TIME,
IN_VAR_DEVICE_CHAN_ENABLE,
__WRTD_IN_VAR_MAX,
};
enum wrtd_in_structures_indexes {
IN_STRUCT_DEVICE = 0,
IN_STRUCT_CHAN_0,
IN_STRUCT_CHAN_1,
IN_STRUCT_CHAN_2,
IN_STRUCT_CHAN_3,
IN_STRUCT_CHAN_4,
__WRTD_IN_STRUCT_MAX,
};
enum wrtd_out_variables_indexes {
OUT_VAR_DEVICE_TIME_S=0,
OUT_VAR_DEVICE_TIME_T,
__WRTD_OUT_VAR_MAX,
};
enum wrtd_out_structures_indexes {
OUT_STRUCT_DEVICE = 0,
OUT_STRUCT_CHAN_0,
OUT_STRUCT_CHAN_1,
OUT_STRUCT_CHAN_2,
OUT_STRUCT_CHAN_3,
__WRTD_OUT_STRUCT_MAX,
};
/**
* availables trigger mode
*/
enum wrtd_trigger_mode {
WRTD_TRIGGER_MODE_SINGLE = 1, /**< In SINGLE mode, the input/output will
trigger only on the 1st pulse/trigger
message after arming.*/
WRTD_TRIGGER_MODE_AUTO = 2, /**< In AUTO mode, the input/output will
trigger on every pulse/trigger message.*/
};
/**
* This enum is used in list_input_state / list_output_state
* structures to pass state information
*/
enum wrtd_io_flags {
WRTD_ENABLED = (1 << 0), /*!< I/O is enabled */
WRTD_TRIGGER_ASSIGNED = (1 << 1), /*!< I/O is has a trigger assigned */
WRTD_LAST_VALID = (1 << 2), /*!< I/O processed at least one pulse.
It's timestamp/ID is in the "last"
field. */
WRTD_ARMED = (1 << 3), /*!< I/O is armed */
WRTD_TRIGGERED = (1 << 4), /*!< I/O has triggered */
WRTD_NO_WR = (1 << 5), /*!< I/O has no WR timing */
};
/**
* Log level flag description
*/
enum wrtd_log_level {
WRTD_LOG_NOTHING = 0, /**< disable logging */
WRTD_LOG_RAW = (1 << 0), /**< Input only: log all pulses coming to
the TDC input */
WRTD_LOG_SENT = (1 << 1), /**< Input only: log all sent triggers */
WRTD_LOG_PROMISC = (1 << 2), /**< Output only: promiscious mode -
log all trigger messages received
from WR network */
WRTD_LOG_FILTERED = (1 << 3), /**< Output only: log all trigger
messages that have been assigned
to the output */
WRTD_LOG_EXECUTED = (1 << 4), /**< Output only: log all triggers
executed on the output */
WRTD_LOG_MISSED = (1 << 5), /**< Output only: log all triggers
missed by the output */
WRTD_LOG_ALL = 0xff, /**< all events will be logged */
};
/**
* Possible causes for missed trigger
*/
enum wrtd_log_miss_reason {
WRTD_MISS_DEAD_TIME = 0, /**< trigger during dead time period */
WRTD_MISS_OVERFLOW = 1, /**< too many trigger events, trigger queue
overflow */
WRTD_MISS_NO_WR = 2, /**< No White-Rabbit network */
WRTD_MISS_TIMEOUT = 3, /**< timeout for trigger generation */
};
#define HASH_ENT_EMPTY (0 << 0)
#define HASH_ENT_DIRECT (1 << 0)
#define HASH_ENT_CONDITION (1 << 1)
#define HASH_ENT_CONDITIONAL (1 << 2)
#define HASH_ENT_DISABLED (1 << 3)
/**
* White-Rabbit Time-Stamp format
*/
struct wr_timestamp {
uint64_t seconds;
uint32_t ticks;
uint32_t frac;
};
/**
* Trigger identifier
*/
struct wrtd_trig_id {
uint32_t system; /**< Unique ID of the WRTD to identify a domain. */
uint32_t source_port; /**< System-wide unique ID to intentify the
input port the trigger comes from. */
uint32_t trigger; /**< System-wide unique ID of a particular trigger
pulse*/
};
/**
* Trigger event. It is shared between the user-space and the
* real time application. Those end-point use this structure to share
* information.
* It should have 32bit fields to avoid toubles with the muck turtle
* bit swapping. If not possible on user space you must fix the bit swapping
* manually where necessary.
*/
struct wrtd_trigger_entry {
struct wr_timestamp ts; /**< when it fired */
struct wrtd_trig_id id; /**< which trigger */
uint32_t seq; /**< its sequence number */
};
/**
* Log event descriptor
*/
struct wrtd_log_entry {
uint32_t type; /**< type of logging */
uint32_t seq; /**< log sequence number */
int channel; /**< channel that generate the logging message */
struct wrtd_trig_id id; /**< trigger id associated with the log event */
struct wr_timestamp ts; /**< when the log message was sent from
the RT application*/
enum wrtd_log_miss_reason miss_reason; /**< trigger failure reason.
It is valid only when type
is WRTD_LOG_MISSED */
};
#ifdef WRNODE_RT
struct wrtd_trigger_message {
struct rmq_message_addr hdr;
uint32_t transmit_seconds;
uint32_t transmit_cycles;
int count;
struct wrtd_trigger_entry triggers[TDC_TRIGGER_COALESCE_LIMIT];
uint32_t pad; // stupid Etherbone for some reasons drops the last entry on TX
};
#endif
#ifdef WRNODE_RT
static inline void ts_add(struct wr_timestamp *a, const struct wr_timestamp *b)
{
a->frac += b->frac;
if(a->frac >= 4096)
{
a->frac -= 4096;
a->ticks ++;
}
a->ticks += b->ticks;
if(a->ticks >= 125000000)
{
a->ticks -= 125000000;
a->seconds++;
}
a->seconds += b->seconds;
}
static inline void ts_sub(struct wr_timestamp *a, const struct wr_timestamp *b)
{
a->frac -= b->frac;
if(a->frac < 0)
{
a->frac += 4096;
a->ticks --;
}
a->ticks -= b->ticks;
if(a->ticks < 0)
{
a->ticks += 125000000;
a->seconds--;
}
a->seconds -= b->seconds;
if(a->seconds == -1)
{
a->seconds = 0;
a->ticks -= 125000000;
}
}
#endif
/**
* Structure describing state of each TDC channel
* All fields must be 32bit (do not use enum because there are no guarantee)
*/
struct wrtd_in_channel_config {
struct wrtd_trig_id id; /**< Currently assigned trigger ID */
struct wr_timestamp delay; /**< Trigger delay, added to each timestamp */
struct wr_timestamp timebase_offset; /* Internal time base offset. Used
to compensate the TDC-to-WR
timebase lag. Not exposed to the
public, set from the internal
calibration data of the TDC
driver. */
uint32_t flags; /**< Channel flags (enum trtl_io_flags) */
uint32_t log_level; /**< Log level (enum trtl_log_level) */
uint32_t mode; /**< Triggering mode (enum wrtd_triger_mode) */
};
struct wrtd_in_channel_stats {
struct wr_timestamp last_tagged; /**< Timestamp of the last tagged
pulse */
struct wrtd_trigger_entry last_sent; /**< Last transmitted trigger */
uint32_t total_pulses; /**< Total tagged pulses */
uint32_t sent_pulses; /**< Total sent pulses */
uint32_t miss_no_timing; /**< Total missed pulses (no WR) */
uint32_t seq;
};
/* Structure describing state of each TDC channel*/
struct wrtd_in_channel {
int n;
struct wrtd_in_channel_stats stats;
struct wrtd_in_channel_config config;
};
struct wrtd_in {
uint32_t dead_time; /**< TDC dead time, in 8ns ticks */
};
enum wrtd_out_state_machine_steps {
OUT_ST_IDLE = 0,
OUT_ST_ARMED,
OUT_ST_TEST_PENDING,
OUT_ST_CONDITION_HIT,
};
/**
* Rule defining the behaviour of a trigger output upon reception of a
* trigger message with matching ID
*/
struct lrt_output_rule {
uint32_t delay_cycles; /**< Delay to add to the timestamp enclosed
within the trigger message */
uint16_t delay_frac;
uint16_t state; /**< State of the rule (empty, disabled,
conditional action, condition, etc.) */
uint32_t cond_ptr; /**< index pointing do the condition trigger */
uint32_t latency_worst; /**< Worst-case latency (in 8ns ticks)*/
uint32_t latency_avg_sum; /**< Average latency accumulator and
number of samples */
uint32_t latency_avg_nsamples;
uint32_t hits; /**< Number of times the rule has successfully produced
a pulse */
uint32_t misses; /**< Number of times the rule has missed a pulse
(for any reason) */
};
/* Structure describing a single pulse in the Fine Delay software output queue */
struct pulse_queue_entry {
/* Trigger that produced the pulse */
struct wrtd_trigger_entry trig;
/* Origin timestamp cycles count (for latency statistics) */
int origin_cycles;
/* Rule that produced the pulse */
struct lrt_output_rule *rule;
};
/* Pulse FIFO for a single Fine Delay output */
struct lrt_pulse_queue {
struct pulse_queue_entry data[FD_MAX_QUEUE_PULSES];
int head, tail, count;
};
struct wrtd_out_trigger {
unsigned int flags;
struct wrtd_trig_id id; /**< trigger identifier */
struct lrt_output_rule ocfg[FD_NUM_CHANNELS]; /**< specific rule
for each channel*/
};
#define ENTRY_FLAG_VALID (1 << 0)
struct wrtd_out_channel_stats {
uint32_t hits;
uint32_t miss_timeout;
uint32_t miss_deadtime;
uint32_t miss_overflow;
uint32_t miss_no_timing;
struct wrtd_trigger_entry last_executed; /**< Last enqueued trigger
(i.e. the last one that
entered the output queue) */
struct wrtd_trigger_entry last_enqueued; /**< Last timestamp value
written to output config */
struct wr_timestamp last_programmed; /**< Last timestamp value written
to output config */
struct wrtd_trigger_entry last_lost;
};
/**
* Channel configuration parameters. It is shared between the user-space and the
* real time application. Those end-point use this structure to share
* information.
* It should have 32bit fields to avoid toubles with the muck turtle
* bit swapping. If not possible on user space you must fix the bit swapping
* manually where necessary.
*/
struct wrtd_out_channel_config {
uint32_t state; /**< Arm state */
uint32_t mode; /**< Trigger mode */
uint32_t flags; /**< Flags (logging, etc) */
uint32_t log_level; /**< Current logging level */
uint32_t dead_time; /**< Dead time (8ns cycles) */
uint32_t width_cycles; /**< Pulse width (8ns cycles) */
};
struct wrtd_out_channel_private {
uint32_t idle; /**< Idle flag */
struct lrt_pulse_queue queue; /**< Output pulse queue */
struct lrt_output_rule *pending_trig; /**< Pending conditonal trigger */
struct wr_timestamp prev_pulse; /**< Last enqueued trigger + delay
(for dead time checking). */
};
struct wrtd_out_channel {
uint32_t base_addr;
uint32_t n;
struct wrtd_out_channel_stats stats;
struct wrtd_out_channel_config config;
struct wrtd_out_channel_private priv;
};
struct wrtd_out {
uint32_t counter_loopback;
uint32_t counter_etherbone;
struct wrtd_trigger_entry last_received;
};
/**
* Hash function, returing the hash table index corresponding to a given
* trigger ID
*/
static inline int wrtd_hash_func(struct wrtd_trig_id *id)
{
int h = 0;
h += id->system * 10291;
h += id->source_port * 10017;
h += id->trigger * 3111;
return h & (FD_HASH_ENTRIES - 1); // hash table size must be a power of 2
}
#endif
list-master/lib/ 0000775 0000000 0000000 00000000000 13156247624 0014102 5 ustar 00root root 0000000 0000000 list-master/lib/Makefile 0000664 0000000 0000000 00000002002 13156247624 0015534 0 ustar 00root root 0000000 0000000 # 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.
-include Makefile.specific
TRTL ?= ../mock-turtle-sw
LIBTDC ?= ../fmc-tdc-sw/lib
LIBFD ?= ../fine-delay-sw/lib
LIBS = libwrtd.so
LIB = libwrtd.a
LOBJ := libwrtd-internal.o
LOBJ += libwrtd-common.o
LOBJ += libwrtd-logging.o
LOBJ += libwrtd-input.o
LOBJ += libwrtd-output.o
CFLAGS += -Wall -ggdb -O2 -fPIC -I. -I../include -I$(TRTL)/include -I$(TRTL)/lib -I$(LIBFD) -I$(LIBTDC) -I$(LIBFD)/../kernel
CFLAGS += -Werror
CFLAGS += $(EXTRACFLAGS)
LDLIBS += -L. -lwrtd
modules all: $(LIB) $(LIBS)
%: %.c $(LIB)
$(CC) $(CFLAGS) $(LDFLAGS) $*.c $(LDLIBS) -o $@
$(LIB): $(LOBJ)
ar r $@ $^
$(LIBS): $(LIB)
$(CC) -shared -o $@ -Wl,--whole-archive,-soname,$@ $^ -Wl,--no-whole-archive
clean:
rm -f $(LIB) .depend *.o *~
.depend: Makefile $(wildcard *.c *.h)
$(CC) $(CFLAGS) -M $(LOBJ:.o=.c) -o $@
install modules_install:
-include .depend
list-master/lib/libwrtd-common.c 0000664 0000000 0000000 00000020724 13156247624 0017210 0 ustar 00root root 0000000 0000000 /*
* Copyright (C) 2014-2016 CERN (www.cern.ch)
* Author: Federico Vaga
* inspired by a draft of Tomasz Wlostowski
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*/
#include
#include
#include
#include
#include
static const uint32_t application_id[] = {
0x115790de,
};
const char *wrtd_errors[] = {
"Received an invalid answer from white-rabbit-node-code CPU",
"Cannot read channel/trigger state",
"You are using an invalid binary",
"Invalid dead time value",
"Invalid delay value",
"Invalid trigger identifier",
"Invalid channel number",
"Function not yet implemented",
"Received an invalid trigger entry",
"Received an invalid hash entry",
"Received an invalid hash chain",
"Received an invalid trigger handle",
"Trigger not found",
"No trigger condition",
"Invalid pulse width",
"Invalid input real-time application version",
"Invalid output real-time application version"
};
/**
* It returns a string messages corresponding to a given error code. If
* it is not a libwrtd error code, it will run trtl_strerror()
* @param[in] err error code
* @return a message error
*/
const char *wrtd_strerror(int err)
{
if (err < EWRTD_INVALID_ANSWER_ACK || err >= __EWRTD_MAX_ERROR_NUMBER)
return trtl_strerror(err);
return wrtd_errors[err - EWRTD_INVALID_ANSWER_ACK];
}
/**
* It initializes the WRTD library. It must be called before doing
* anything else. If you are going to load/unload WRTD devices, then
* you have to un-load (wrtd_exit()) e reload (wrtd_init()) the library.
*
* This library is based on the libmockturtle, so internally, this function also
* run trtl_init() in order to initialize the WRNC library.
* @return 0 on success, otherwise -1 and errno is appropriately set
*/
int wrtd_init()
{
int err;
err = trtl_init();
if (err)
return err;
return 0;
}
/**
* It releases the resources allocated by wrtd_init(). It must be called when
* you stop to use this library. Then, you cannot use functions from this
* library.
*/
void wrtd_exit()
{
trtl_exit();
}
/**
* Check if the RT-app running version is compatible with the current
* library
* @param[in] dev device token
* @return 1 if the version is correct, 0 otherwise and errno is
* appropriately set
*/
int wrtd_version_is_valid(struct wrtd_node *dev)
{
struct trtl_rt_version version;
int err;
errno = 0;
err = wrtd_in_version(dev, &version);
if (err)
return 0;
if (version.rt_id != WRTD_IN_RT_ID) {
errno = EWRTD_INVALID_IN_APP;
return 0;
}
err = wrtd_out_version(dev, &version);
if (err)
return 0;
if (version.rt_id != WRTD_OUT_RT_ID) {
errno = EWRTD_INVALID_IN_APP;
return 0;
}
return 1;
}
/**
* It opens and initialize the configuration for the given device
* @param[in] device_id device identifier
* @param[in] is_lun 1 if device_id is a LUN
* @return It returns an anonymous wrtd_node structure on success.
* On error, NULL is returned, and errno is set appropriately.
*/
static struct wrtd_node *wrtd_open(uint32_t device_id, unsigned int is_lun)
{
struct wrtd_desc *wrtd;
int err;
wrtd = malloc(sizeof(struct wrtd_desc));
if (!wrtd)
return NULL;
if (is_lun)
wrtd->trtl = trtl_open_by_lun(device_id);
else
wrtd->trtl = trtl_open_by_fmc(device_id);
if (!wrtd->trtl)
goto out;
wrtd->dev_id = device_id;
/* Logging interface is always in share mode */
err = trtl_hmq_share_set(wrtd->trtl, TRTL_HMQ_OUTCOMING,
WRTD_OUT_FD_LOGGING, 1);
if (err)
goto out;
err = trtl_hmq_share_set(wrtd->trtl, TRTL_HMQ_OUTCOMING,
WRTD_OUT_TDC_LOGGING, 1);
if (err)
goto out;
return (struct wrtd_node *)wrtd;
out:
free(wrtd);
return NULL;
}
/**
* Open a WRTD node device using FMC ID
* @param[in] device_id FMC device identificator
* @return It returns an anonymous wrtd_node structure on success.
* On error, NULL is returned, and errno is set appropriately.
*/
struct wrtd_node *wrtd_open_by_fmc(uint32_t device_id)
{
return wrtd_open(device_id, 0);
}
/**
* Open a WRTD node device using LUN
* @param[in] lun an integer argument to select the device or
* negative number to take the first one found.
* @return It returns an anonymous wrtd_node structure on success.
* On error, NULL is returned, and errno is set appropriately.
*/
struct wrtd_node *wrtd_open_by_lun(int lun)
{
return wrtd_open(lun, 1);
}
/**
* It closes a WRTD device opened with one of the following function:
* wrtd_open_by_lun(), wrtd_open_by_fmc()
* @param[in] dev device token
*/
void wrtd_close(struct wrtd_node *dev)
{
struct wrtd_desc *wrtd = (struct wrtd_desc *)dev;
trtl_close(wrtd->trtl);
free(wrtd);
dev = NULL;
}
/**
* It returns the WRNC token in order to allows users to run
* functions from the WRNC library
* @param[in] dev device token
* @return the WRNC token
*/
struct trtl_dev *wrtd_get_trtl_dev(struct wrtd_node *dev)
{
struct wrtd_desc *wrtd = (struct wrtd_desc *)dev;
return (struct trtl_dev *)wrtd->trtl;
}
/**
* It restarts both real-time applications
* @param[in] dev device token
* @return 0 on success, -1 on error and errno is set appropriately
*/
int wrtd_cpu_restart(struct wrtd_node *dev)
{
struct wrtd_desc *wrtd = (struct wrtd_desc *)dev;
int err;
err = trtl_cpu_disable(wrtd->trtl,WRTD_CPU_TDC);
if (err)
return err;
err = trtl_cpu_disable(wrtd->trtl,WRTD_CPU_FD);
if (err)
return err;
err = trtl_cpu_enable(wrtd->trtl,WRTD_CPU_TDC);
if (err)
return err;
return trtl_cpu_enable(wrtd->trtl,WRTD_CPU_FD);
}
/**
* It loads a set of real-time applications for TDC and FD
* @param[in] dev device token
* @param[in] rt_tdc path to the TDC application
* @param[in] rt_fd path to the Fine Delay application
*/
int wrtd_load_application(struct wrtd_node *dev, char *rt_tdc,
char *rt_fd)
{
struct wrtd_desc *wrtd = (struct wrtd_desc *)dev;
uint32_t reg_old;
int err;
if (!rt_tdc || !rt_fd) {
errno = EWRTD_INVALID_BINARY;
return -1;
}
err = trtl_cpu_reset_get(wrtd->trtl, ®_old);
if (err)
return err;
/* Keep the CPUs in reset state */
err = trtl_cpu_reset_set(wrtd->trtl,
(1 << WRTD_CPU_TDC) | (1 << WRTD_CPU_FD));
if (err)
return err;
/* Program CPUs application */
err = trtl_cpu_load_application_file(wrtd->trtl, WRTD_CPU_TDC, rt_tdc);
if (err)
return err;
err = trtl_cpu_load_application_file(wrtd->trtl, WRTD_CPU_FD, rt_fd);
if (err)
return err;
/* Re-enable the CPUs */
err = trtl_cpu_reset_set(wrtd->trtl, reg_old);
if (err)
return err;
return 0;
}
/**
* It converts the white rabbit time stamp to a pico seconds
* @param[in] ts time-stamp
* @param[out] pico pico-seconds
*/
void wrtd_ts_to_pico(struct wr_timestamp *ts, uint64_t *pico)
{
uint64_t p;
p = ts->frac * 8000 / 4096;
p += (uint64_t) ts->ticks * 8000LL;
p += ts->seconds * (1000ULL * 1000ULL * 1000ULL * 1000ULL);
*pico = p;
}
/**
* It converts a pico seconds integer into a white rabbit time stamp
* @param[in] pico pico-seconds
* @param[out] ts time-stamp
*/
void wrtd_pico_to_ts(uint64_t *pico, struct wr_timestamp *ts)
{
uint64_t p = *pico;
ts->seconds = p / (1000ULL * 1000ULL * 1000ULL * 1000ULL);
p %= (1000ULL * 1000ULL * 1000ULL * 1000ULL);
ts->ticks = p / 8000;
p %= 8000;
ts->frac = p * 4096 / 8000;
}
/**
* It converts a white rabbit time stamp to seconds and pico-seconds
* @param[in] ts time-stamp
* @param[out] sec seconds
* @param[out] pico pico-seconds
*/
void wrtd_ts_to_sec_pico(struct wr_timestamp *ts, uint64_t *sec, uint64_t *pico)
{
*sec = ts->seconds;
*pico = ts->frac * 8000 / 4096;
*pico += (uint64_t) ts->ticks * 8000LL;
}
/**
* It converts a white rabbit time stamp to seconds and pico-seconds
* @param[in] sec seconds
* @param[in] pico pico-seconds
* @param[out] ts time-stamp
*/
void wrtd_sec_pico_to_ts(uint64_t sec, uint64_t pico, struct wr_timestamp *ts)
{
ts->seconds = sec;
ts->ticks = pico / 8000;
ts->frac = (pico % 8000) * 4096 / 8000;
}
list-master/lib/libwrtd-input.c 0000664 0000000 0000000 00000052317 13156247624 0017062 0 ustar 00root root 0000000 0000000 /*
* Copyright (C) 2014-2016 CERN (www.cern.ch)
* Author: Federico Vaga
* inspired by a draft of Tomasz Wlostowski
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*/
#include
#include
#include
#include "libwrtd-internal.h"
static const struct trtl_proto_header wrtd_in_hdr_sync = {
.slot_io = (WRTD_IN_TDC_CONTROL << 4) | (WRTD_OUT_TDC_CONTROL & 0xF),
.flags = TRTL_PROTO_FLAG_SYNC,
};
/**
* Internal helper to send and recevie synchronous messages to/from the TDC
*/
static inline int wrtd_in_send_and_receive_sync(struct wrtd_desc *wrtd,
struct trtl_msg *msg)
{
struct trtl_hmq *hmq;
int err;
hmq = trtl_hmq_open(wrtd->trtl, WRTD_IN_TDC_CONTROL, TRTL_HMQ_INCOMING);
if (!hmq)
return -1;
/* Send the message and get answer */
err = trtl_hmq_send_and_receive_sync(hmq, WRTD_OUT_TDC_CONTROL, msg,
WRTD_DEFAULT_TIMEOUT);
trtl_hmq_close(hmq);
return err < 0 ? err : 0; /* Ignore timeout */
}
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/* * * * * * * * * * PROTOTYPEs IMPLEMENTATION * * * * * * * * * */
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/*
* FIXME
* Most of the function's code below can be optimized by using memcpy()
* or similar operations. For the time being, I'm leaving it like this
* because data structures are shared with the real-time applications
*/
/**
* It retreives the current status of a given input channel
* @param[in] dev device token
* @param[in] input index (0-based) of the input channel
* @param[out] state the current status of a channel
* @return 0 on success, -1 on error and errno is set appropriately
*/
int wrtd_in_state_get(struct wrtd_node *dev, unsigned int input,
struct wrtd_input_state *state)
{
struct wrtd_desc *wrtd = (struct wrtd_desc *)dev;
int err;
struct wrtd_in_channel chan;
struct trtl_structure_tlv tlv = {
.index = IN_STRUCT_CHAN_0 + input,
.size = sizeof(struct wrtd_in_channel),
.structure = &chan,
};
uint32_t variables[] = {IN_VAR_DEVICE_SENT_PACK, 0,
IN_VAR_DEVICE_DEAD_TIME, 0};
struct trtl_proto_header hdr = wrtd_in_hdr_sync;
if (input >= TDC_NUM_CHANNELS) {
errno = EWRTD_INVALID_CHANNEL;
return -1;
}
if (state == NULL) {
errno = ENOMEM;
return -1;
}
err = trtl_rt_structure_get(wrtd->trtl, &hdr, &tlv, 1);
if (err)
return err;
hdr.len = ARRAY_SIZE(variables);
err = trtl_rt_variable_get(wrtd->trtl, &hdr, variables, 2);
if (err)
return err;
/* Convert to state structure */
state->input = chan.n;
state->assigned_id = chan.config.id;
state->delay = chan.config.delay;
wrtd_timestamp_endianess_fix(&state->delay);
state->tdc_timebase_offset = chan.config.timebase_offset;
wrtd_timestamp_endianess_fix(&state->tdc_timebase_offset);
state->last_tagged_pulse = chan.stats.last_tagged;
wrtd_timestamp_endianess_fix(&state->last_tagged_pulse);
state->flags = chan.config.flags;
state->log_level = chan.config.log_level;
state->mode = chan.config.mode;
state->tagged_pulses = chan.stats.total_pulses;
state->sent_triggers = chan.stats.sent_pulses;
state->last_sent = chan.stats.last_sent;
wrtd_timestamp_endianess_fix(&state->last_sent.ts);
state->dead_time.seconds = 0;
state->dead_time.frac = 0;
state->dead_time.ticks = variables[3] * 2;
wrtd_timestamp_endianess_fix(&state->dead_time);
state->sent_packets = variables[1];
return 0;
}
/**
* Hardware enable/disable a WRTD input channel.
* @param[in] dev pointer to open node device.
* @param[in] input index (0-based) of the input channel
* @param[in] enable 1 to enable the input, 0 disables it.
* @return 0 on success, -1 on error and errno is set appropriately
*/
int wrtd_in_enable(struct wrtd_node *dev, unsigned int input, int enable)
{
struct wrtd_desc *wrtd = (struct wrtd_desc *)dev;
struct wrtd_in_channel chan;
struct trtl_structure_tlv tlv = {
.index = IN_STRUCT_CHAN_0 + input,
.size = sizeof(struct wrtd_in_channel),
.structure = &chan,
};
uint32_t variables[] = {IN_VAR_DEVICE_CHAN_ENABLE, 0};
struct trtl_proto_header hdr = wrtd_in_hdr_sync;
int err;
if (input >= TDC_NUM_CHANNELS) {
errno = EWRTD_INVALID_CHANNEL;
return -1;
}
err = trtl_rt_structure_get(wrtd->trtl, &hdr, &tlv, 1);
if (err)
return err;
hdr.len = ARRAY_SIZE(variables);
err = trtl_rt_variable_get(wrtd->trtl, &hdr, variables, 1);
if (err)
return err;
if (enable) {
variables[1] |= (1 << input);
chan.config.flags |= WRTD_ENABLED;
} else {
variables[1] &= ~(1 << input);
chan.config.flags &= ~WRTD_ENABLED;
}
err = trtl_rt_structure_set(wrtd->trtl, &hdr, &tlv, 1);
if (err)
return err;
hdr.len = ARRAY_SIZE(variables);
return trtl_rt_variable_set(wrtd->trtl, &hdr, variables, 1);
}
/**
* Assign (unassign) a trigger ID to a given WRTD input. Passing a NULL trig_id
* un-assigns the current trigger (the input will be tagging pulses and
* logging them, but they will not be sent as triggers to the WR network).
* @param[in] dev device token
* @param[in] input index (0-based) of the input channel
* @param[in] trig_id the trigger to be sent upon reception of a pulse on the
* given input.
* @return 0 on success, -1 on error and errno is set appropriately
*/
int wrtd_in_trigger_assign(struct wrtd_node *dev, unsigned int input,
struct wrtd_trig_id *trig_id)
{
struct wrtd_desc *wrtd = (struct wrtd_desc *)dev;
struct wrtd_in_channel chan;
struct trtl_structure_tlv tlv = {
.index = IN_STRUCT_CHAN_0 + input,
.size = sizeof(struct wrtd_in_channel),
.structure = &chan,
};
struct trtl_proto_header hdr = wrtd_in_hdr_sync;
int err;
if (input >= TDC_NUM_CHANNELS) {
errno = EWRTD_INVALID_CHANNEL;
return -1;
}
err = trtl_rt_structure_get(wrtd->trtl, &hdr, &tlv, 1);
if (err)
return err;
if (trig_id) {
chan.config.id = *trig_id;
chan.config.flags |= WRTD_TRIGGER_ASSIGNED;
chan.config.flags &= ~WRTD_LAST_VALID;
} else {
memset(&chan.config.id, 0, sizeof(struct wrtd_trig_id));
chan.config.flags &= ~WRTD_TRIGGER_ASSIGNED;
}
return trtl_rt_structure_set(wrtd->trtl, &hdr, &tlv, 1);
}
/**
* It un-assign the trigger on an input channel. It is just an helper that
* internally use wrtd_in_trigger_unassign()
* @param[in] dev device token
* @param[in] input index (0-based) of the input channel
* @return 0 on success, -1 on error and errno is set appropriately
*/
int wrtd_in_trigger_unassign(struct wrtd_node *dev,
unsigned int input)
{
return wrtd_in_trigger_assign(dev, input, NULL);
}
/**
* Set trigger mode for a given WRTD input. Note that the input must be armed
* by calling wrtd_in_arm() at least once before it can send triggers.
*
* The mode can be single shot or continuous. Single shot means the input will
* trigger on the first incoming pulse and will ignore the subsequent pulses
* until re-armed.
*
* @param[in] dev device token
* @param[in] input (0-based) of the input channel
* @param[in] mode triggering mode.
* @return 0 on success, -1 on error and errno is set appropriately
*/
int wrtd_in_trigger_mode_set(struct wrtd_node *dev, unsigned int input,
enum wrtd_trigger_mode mode)
{
struct wrtd_desc *wrtd = (struct wrtd_desc *)dev;
struct wrtd_in_channel chan;
struct trtl_structure_tlv tlv = {
.index = IN_STRUCT_CHAN_0 + input,
.size = sizeof(struct wrtd_in_channel),
.structure = &chan,
};
struct trtl_proto_header hdr = wrtd_in_hdr_sync;
int err;
if (input >= TDC_NUM_CHANNELS) {
errno = EWRTD_INVALID_CHANNEL;
return -1;
}
err = trtl_rt_structure_get(wrtd->trtl, &hdr, &tlv, 1);
if (err)
return err;
chan.config.mode = mode;
return trtl_rt_structure_set(wrtd->trtl, &hdr, &tlv, 1);
}
/**
* It generates a software trigger at a given TAI value. The TAI value that
* you provide to this function (trigger->ts) is considered as a delay
* from the current time. The current time means the time when the real-time
* application receive the software trigger command
* @param[in] dev device token
* @param[in] trigger trigger to enumlate
* @return 0 on success, -1 on error and errno is set appropriately
*/
int wrtd_in_trigger_software(struct wrtd_node *dev,
struct wrtd_trigger_entry *trigger)
{
struct wrtd_desc *wrtd = (struct wrtd_desc *)dev;
struct wrtd_trigger_entry ltrig = *trigger;
struct trtl_msg msg;
struct trtl_proto_header hdr = {
.msg_id = WRTD_IN_ACTION_SW_TRIG,
.slot_io = (WRTD_IN_TDC_CONTROL << 4) |
(WRTD_OUT_TDC_CONTROL & 0xF),
.flags = TRTL_PROTO_FLAG_SYNC,
.len = sizeof(struct wrtd_trigger_entry) / 4,
};
int err;
if (trigger == NULL) {
errno = EWRTD_INVALID_TRIG_ID;
return -1;
}
memset(&msg, 0, sizeof(struct trtl_msg));
wrtd_timestamp_endianess_fix(<rig.ts);
trtl_message_pack(&msg, &hdr, <rig);
/* Send the message and get answer */
err = wrtd_in_send_and_receive_sync(wrtd, &msg);
if (err)
return err;
trtl_message_unpack(&msg, &hdr, NULL);
if (hdr.msg_id != RT_ACTION_SEND_ACK)
return -1;
return 0;
}
/**
* Arm (disarm) a WRTD input for triggering. By arming the input, you are making
* it ready to accept/send triggers
* @param[in] dev device token
* @param[in] input index (0-based) of input channel
* @param[in] armed 1 arms the input, 0 disarms the input.
* @return 0 on success, -1 on error and errno is set appropriately
*/
int wrtd_in_arm(struct wrtd_node *dev, unsigned int input, int armed)
{
struct wrtd_desc *wrtd = (struct wrtd_desc *)dev;
struct wrtd_in_channel chan;
struct trtl_structure_tlv tlv = {
.index = IN_STRUCT_CHAN_0 + input,
.size = sizeof(struct wrtd_in_channel),
.structure = &chan,
};
struct trtl_proto_header hdr = wrtd_in_hdr_sync;
int err;
if (input >= TDC_NUM_CHANNELS) {
errno = EWRTD_INVALID_CHANNEL;
return -1;
}
err = trtl_rt_structure_get(wrtd->trtl, &hdr, &tlv, 1);
if (err)
return err;
if (armed)
chan.config.flags |= WRTD_ARMED;
else
chan.config.flags &= ~WRTD_ARMED;
chan.config.flags &= ~WRTD_TRIGGERED;
return trtl_rt_structure_set(wrtd->trtl, &hdr, &tlv, 1);
}
/**
* Set the dead time (the minimum gap between input pulses, below which
* the TDC ignores the subsequent pulses; limits maximum input pulse rate,
* 16 ns granularity)
* @param[in] dev device token
* @param[in] input index (0-based) of input channel
* @param[in] dead_time_ps dead time in pico-seconds [80000000, 160000000000]
* @return 0 on success, -1 on error and errno is set appropriately
*/
int wrtd_in_dead_time_set(struct wrtd_node *dev, unsigned int input,
uint64_t dead_time_ps)
{
struct wrtd_desc *wrtd = (struct wrtd_desc *)dev;
uint32_t variables[] = {IN_VAR_DEVICE_DEAD_TIME, 0};
struct trtl_proto_header hdr = wrtd_in_hdr_sync;
uint32_t dead_time_cycles;
if (input >= TDC_NUM_CHANNELS) {
errno = EWRTD_INVALID_CHANNEL;
return -1;
}
/* Convert dead-times in cycles/ticks */
dead_time_cycles = dead_time_ps / 16000;
if(dead_time_cycles < 5000 || dead_time_cycles > 10000000 ) {
errno = EWRTD_INVALID_DEAD_TIME;
return -1;
}
variables[1] = dead_time_cycles; // FIXME wrong API
return trtl_rt_variable_set(wrtd->trtl, &hdr, variables, 1);
}
/**
* Set the offset (for compensating cable delays), in 10 ps steps.
* @param[in] dev device token
* @param[in] input index (0-based) of input channel
* @param[in] delay_ps delay in pico-seconds
* @return 0 on success, -1 on error and errno is set appropriately
*/
int wrtd_in_delay_set(struct wrtd_node *dev, unsigned int input,
uint64_t delay_ps)
{
struct wrtd_desc *wrtd = (struct wrtd_desc *)dev;
struct wrtd_in_channel chan;
struct trtl_structure_tlv tlv = {
.index = IN_STRUCT_CHAN_0 + input,
.size = sizeof(struct wrtd_in_channel),
.structure = &chan,
};
struct trtl_proto_header hdr = wrtd_in_hdr_sync;
struct wr_timestamp t;
int err;
if (input >= TDC_NUM_CHANNELS) {
errno = EWRTD_INVALID_CHANNEL;
return -1;
}
err = trtl_rt_structure_get(wrtd->trtl, &hdr, &tlv, 1);
if (err)
return err;
wrtd_pico_to_ts(&delay_ps, &t);
memcpy(&chan.config.delay, &t, sizeof(struct wr_timestamp));
return trtl_rt_structure_set(wrtd->trtl, &hdr, &tlv, 1);
}
/**
* Set the time offset on a given input channel. The time offset is between
* the White-Rabbit timescale and the ACAM TDC timescale. This information
* is only known by the TDC driver which has access the calibration data
* on the TDC eeprom. So, it is necessary to inform the RealTime application
* about this offset as soon as the RealTime application start to run.
* @param[in] dev device token
* @param[in] input index (0-based) of input channel
* @param[in] offset time offset in pico seconds
* @return 0 on success, -1 on error and errno is set appropriately
*/
int wrtd_in_timebase_offset_set(struct wrtd_node *dev, unsigned int input,
uint64_t offset)
{
struct wrtd_desc *wrtd = (struct wrtd_desc *)dev;
struct wrtd_in_channel chan;
struct trtl_structure_tlv tlv = {
.index = IN_STRUCT_CHAN_0 + input,
.size = sizeof(struct wrtd_in_channel),
.structure = &chan,
};
struct trtl_proto_header hdr = wrtd_in_hdr_sync;
struct wr_timestamp t;
int err;
if (input >= TDC_NUM_CHANNELS) {
errno = EWRTD_INVALID_CHANNEL;
return -1;
}
err = trtl_rt_structure_get(wrtd->trtl, &hdr, &tlv, 1);
if (err)
return err;
wrtd_pico_to_ts(&offset, &t);
memcpy(&chan.config.timebase_offset, &t, sizeof(struct wr_timestamp));
return trtl_rt_structure_set(wrtd->trtl, &hdr, &tlv, 1);
}
/**
* Reset all counters on a given input channel
* @param[in] dev device token
* @param[in] input index (0-based) of input channel
* @return 0 on success, -1 on error and errno is set appropriately
*/
int wrtd_in_counters_reset(struct wrtd_node *dev, unsigned int input)
{
struct wrtd_desc *wrtd = (struct wrtd_desc *)dev;
struct wrtd_in_channel chan;
struct trtl_structure_tlv tlv = {
.index = IN_STRUCT_CHAN_0 + input,
.size = sizeof(struct wrtd_in_channel),
.structure = &chan,
};
struct trtl_proto_header hdr = wrtd_in_hdr_sync;
int err;
if (input >= TDC_NUM_CHANNELS) {
errno = EWRTD_INVALID_CHANNEL;
return -1;
}
err = trtl_rt_structure_get(wrtd->trtl, &hdr, &tlv, 1);
if (err)
return err;
chan.stats.total_pulses = 0;
chan.stats.sent_pulses = 0;
chan.stats.miss_no_timing = 0;
chan.config.flags &= ~WRTD_LAST_VALID;
return trtl_rt_structure_set(wrtd->trtl, &hdr, &tlv, 1);
}
/**
* Check the enable status on a trigger input.
* @param[in] dev device token
* @param[in] input index (0-based) of input channel
* @param[out] enable 1 if it is enabled, 0 otherwise
* @return 0 on success, -1 on error and errno is set appropriately
*/
int wrtd_in_is_enabled(struct wrtd_node *dev, unsigned int input,
unsigned int *enable)
{
struct wrtd_desc *wrtd = (struct wrtd_desc *)dev;
struct wrtd_in_channel chan;
struct trtl_structure_tlv tlv = {
.index = IN_STRUCT_CHAN_0 + input,
.size = sizeof(struct wrtd_in_channel),
.structure = &chan,
};
struct trtl_proto_header hdr = wrtd_in_hdr_sync;
int err;
if (input >= TDC_NUM_CHANNELS) {
errno = EWRTD_INVALID_CHANNEL;
return -1;
}
err = trtl_rt_structure_get(wrtd->trtl, &hdr, &tlv, 1);
if (err)
return err;
*enable = !!(chan.config.flags & WRTD_ENABLED);
return 0;
}
/**
* Check the armed status on a trigger input.
* @param[in] dev device token
* @param[in] input index (0-based) of input channel
* @param[out] armed 1 if it is enabled, 0 otherwise
* @return 0 on success, -1 on error and errno is set appropriately
*/
int wrtd_in_is_armed(struct wrtd_node *dev, unsigned int input,
unsigned int *armed)
{
struct wrtd_desc *wrtd = (struct wrtd_desc *)dev;
struct wrtd_in_channel chan;
struct trtl_structure_tlv tlv = {
.index = IN_STRUCT_CHAN_0 + input,
.size = sizeof(struct wrtd_in_channel),
.structure = &chan,
};
struct trtl_proto_header hdr = wrtd_in_hdr_sync;
int err;
if (input >= TDC_NUM_CHANNELS) {
errno = EWRTD_INVALID_CHANNEL;
return -1;
}
err = trtl_rt_structure_get(wrtd->trtl, &hdr, &tlv, 1);
if (err)
return err;
*armed = !!(chan.config.flags & WRTD_ARMED);
return 0;
}
/**
* Check the trigger assigned status on a trigger input.
* @param[in] dev device token
* @param[in] input index (0-based) of input channel
* @param[out] armed 1 if it is enabled, 0 otherwise
* @return 0 on success, -1 on error and errno is set appropriately
*/
int wrtd_in_has_trigger(struct wrtd_node *dev, unsigned int input,
unsigned int *assigned)
{
struct wrtd_desc *wrtd = (struct wrtd_desc *)dev;
struct wrtd_in_channel chan;
struct trtl_structure_tlv tlv = {
.index = IN_STRUCT_CHAN_0 + input,
.size = sizeof(struct wrtd_in_channel),
.structure = &chan,
};
struct trtl_proto_header hdr = wrtd_in_hdr_sync;
int err;
if (input >= TDC_NUM_CHANNELS) {
errno = EWRTD_INVALID_CHANNEL;
return -1;
}
err = trtl_rt_structure_get(wrtd->trtl, &hdr, &tlv, 1);
if (err)
return err;
*assigned = !!(chan.config.flags & WRTD_TRIGGER_ASSIGNED);
return 0;
}
/**
* Get the dead time (the minimum gap between input pulses, below which
* the TDC ignores the subsequent pulses; limits maximum input pulse rate,
* 16 ns granularity)
* @param[in] dev device token
* @param[in] input index (0-based) of input channel
* @param[out] dead_time_ps dead time in pico-seconds
* @return 0 on success, -1 on error and errno is set appropriately
*
* @todo to be implemented
*/
int wrtd_in_dead_time_get(struct wrtd_node *dev, unsigned int input,
uint64_t *dead_time_ps)
{
struct wrtd_desc *wrtd = (struct wrtd_desc *)dev;
uint32_t variables[] = {IN_VAR_DEVICE_DEAD_TIME, 0};
struct trtl_proto_header hdr = wrtd_in_hdr_sync;
int err;
if (input >= TDC_NUM_CHANNELS) {
errno = EWRTD_INVALID_CHANNEL;
return -1;
}
err = trtl_rt_variable_get(wrtd->trtl, &hdr, variables, 1);
if (err)
return err;
*dead_time_ps = variables[1] * 16000;
return 0;
}
/**
* Get the offset (for compensating cable delays), in 10 ps steps.
* @param[in] dev device token
* @param[in] input index (0-based) of input channel
* @param[out] delay_ps delay in pico-seconds
* @return 0 on success, -1 on error and errno is set appropriately
*
* @todo to be implemented
*/
int wrtd_in_delay_get(struct wrtd_node *dev, unsigned int input,
uint64_t *delay_ps)
{
struct wrtd_desc *wrtd = (struct wrtd_desc *)dev;
struct wrtd_in_channel chan;
struct trtl_structure_tlv tlv = {
.index = IN_STRUCT_CHAN_0 + input,
.size = sizeof(struct wrtd_in_channel),
.structure = &chan,
};
struct trtl_proto_header hdr = wrtd_in_hdr_sync;
int err;
if (input >= TDC_NUM_CHANNELS) {
errno = EWRTD_INVALID_CHANNEL;
return -1;
}
err = trtl_rt_structure_get(wrtd->trtl, &hdr, &tlv, 1);
if (err)
return err;
wrtd_ts_to_pico(&chan.config.delay, delay_ps);
return 0;
}
/**
* Get/set the Sequence ID counter (counting up at every pulse)
* @param[in] dev device token
* @param[in] input index (0-based) of input channel
* @return 0 on success, -1 on error and errno is set appropriately
*/
int wrtd_in_seq_counter_set(struct wrtd_node *dev, unsigned int input,
unsigned int value)
{
struct wrtd_desc *wrtd = (struct wrtd_desc *)dev;
struct wrtd_in_channel chan;
struct trtl_structure_tlv tlv = {
.index = IN_STRUCT_CHAN_0 + input,
.size = sizeof(struct wrtd_in_channel),
.structure = &chan,
};
struct trtl_proto_header hdr = wrtd_in_hdr_sync;
int err;
if (input >= TDC_NUM_CHANNELS) {
errno = EWRTD_INVALID_CHANNEL;
return -1;
}
err = trtl_rt_structure_get(wrtd->trtl, &hdr, &tlv, 1);
if (err)
return err;
chan.stats.seq = value;
return trtl_rt_structure_set(wrtd->trtl, &hdr, &tlv, 1);
}
/**
* It check if the input real-time application is alive
* @param[in] dev device token
* @return 0 on success, -1 on error and errno is set appropriately
*/
int wrtd_in_ping(struct wrtd_node *dev)
{
struct wrtd_desc *wrtd = (struct wrtd_desc *)dev;
return trtl_rt_ping(wrtd->trtl, WRTD_IN_TDC_CONTROL,
WRTD_OUT_TDC_CONTROL);
}
/**
* It gets the input base time
* @param[in] dev device token
* @param[out] ts input device base time
* @return 0 on success, -1 on error and errno is set appropriately
*/
int wrtd_in_base_time(struct wrtd_node *dev, struct wr_timestamp *ts)
{
struct wrtd_desc *wrtd = (struct wrtd_desc *)dev;
uint32_t variables[] = {IN_VAR_DEVICE_TIME_S, 0,
IN_VAR_DEVICE_TIME_T, 0};
struct trtl_proto_header hdr = wrtd_in_hdr_sync;
int err;
err = trtl_rt_variable_get(wrtd->trtl, &hdr, variables, 2);
if (err)
return err;
ts->seconds = variables[1];
ts->ticks = variables[3];
return 0;
}
/**
* It gets the output version
* @param[in] dev device token
* @param[out] version the RT application version
* @return 0 on success, -1 on error and errno is set appropriately
*/
int wrtd_in_version(struct wrtd_node *dev, struct trtl_rt_version *version)
{
struct wrtd_desc *wrtd = (struct wrtd_desc *)dev;
return trtl_rt_version_get(wrtd->trtl, version,
WRTD_IN_TDC_CONTROL, WRTD_OUT_TDC_CONTROL);
}
list-master/lib/libwrtd-internal.c 0000664 0000000 0000000 00000007060 13156247624 0017532 0 ustar 00root root 0000000 0000000 /*
* Copyright (C) 2014-2016 CERN (www.cern.ch)
* Author: Federico Vaga
* inspired by a draft of Tomasz Wlostowski
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*/
#include
#include
#include
#include
#include "libwrtd-internal.h"
/**
* It validates the answer of a synchronous message
* @param[in] msg message to validate
* @return 0 if it is valid, -1 otherwise and errno is appropriately set
*/
int wrtd_validate_acknowledge(struct trtl_msg *msg)
{
if (msg->datalen != 2 || msg->data[0] != WRTD_REP_ACK_ID) {
errno = EWRTD_INVALID_ANSWER_ACK;
return -1;
}
return 0;
}
/**
* It extracts a wr_timestamp from a given buffer (arriving from a real-time
* application)
* @param[in] buf answer of the real time application
* @param[in] offset offset of the timestamp inside the answer buffer
* @param[out] ts where write the wr_timestamp
*/
void unbag_ts(uint32_t *buf, int offset, struct wr_timestamp *ts)
{
ts->seconds = buf[offset];
ts->ticks = buf[offset + 1];
ts->frac = buf[offset + 2];
}
/**
* It compares two triggers id. The output is the same of memcmp(2)
* @param[in] id1 first id to compare
* @param[in] id2 second id to compare
* @return like memcmp(2)
*/
int wrtd_trig_id_cmp(struct wrtd_trig_id *id1, struct wrtd_trig_id *id2)
{
return memcmp(id1, id2, sizeof(struct wrtd_trig_id));
}
/*
* Internal helper to send and receive synchronous messages to/from the WRNC
*/
int wrtd_send_and_receive_sync(struct wrtd_desc *wrtd,
struct trtl_msg *msg,
enum wrtd_core core)
{
/* Send the message and get answer */
struct trtl_hmq *hmq;
unsigned int hmq_send = core ? WRTD_IN_FD_CONTROL : WRTD_IN_TDC_CONTROL;
unsigned int hmq_recv = core ? WRTD_OUT_FD_CONTROL :
WRTD_OUT_TDC_CONTROL;
int err;
hmq = trtl_hmq_open(wrtd->trtl, hmq_send, TRTL_HMQ_INCOMING);
if (!hmq)
return -1;
err = trtl_hmq_send_and_receive_sync(hmq, hmq_recv, msg,
WRTD_DEFAULT_TIMEOUT);
trtl_hmq_close(hmq);
return err < 0 ? err : 0; /* ignore timeout */
}
/**
* It performs a simple request to a given core which will only answer
* with an ACK
*/
int wrtd_trivial_request(struct wrtd_node *dev,
struct trtl_msg *request_msg,
enum wrtd_core core)
{
struct wrtd_desc *wrtd = (struct wrtd_desc *)dev;
int err;
err = wrtd_send_and_receive_sync(wrtd, request_msg, core);
if (err)
return err;
return wrtd_validate_acknowledge(request_msg);
}
/**
* The embedded core is big endian, convert it to little endian (host)
*/
void wrtd_timestamp_endianess_fix(struct wr_timestamp *ts)
{
ts->seconds = ((ts->seconds & 0xFFFFFFFF) << 32) |
((ts->seconds >> 32) & 0xFFFFFFFF);
}
void wrtd_output_rule_endianess_fix(struct lrt_output_rule *rule)
{
uint16_t tmp = rule->state;
rule->state = (rule->delay_frac & 0x00FF) << 8 |
(rule->delay_frac & 0xFF00) >> 8;
rule->delay_frac = (tmp & 0x00FF) << 8 |
(tmp & 0xFF00) >> 8;
}
list-master/lib/libwrtd-internal.h 0000664 0000000 0000000 00000002617 13156247624 0017542 0 ustar 00root root 0000000 0000000 /*
* Copyright (C) 2014 CERN (www.cern.ch)
* Author: Federico Vaga
* License: GPL v3
*/
#ifndef __LIBWRTD_INTERNAL__H__
#define __LIBWRTD_INTERNAL__H__
#include
#include
#include
/* FIXME
* Statically defined but we must find a dynamic way to determinate
* these offsets
*/
#define WRTD_TDC_DEV_ID_OFFSET 0
#define WRTD_FD_DEV_ID_OFFSET 1
/**
* Description of a White-Rabbit Trigger-Distribution device
*/
struct wrtd_desc {
struct trtl_dev *trtl; /**< WRNC device associated */
uint32_t dev_id; /**< fmc device id */
uint32_t app_id; /**< Application id */
uint32_t n_cpu; /**< Number of CPUs */
};
#define WRTD_OUT_CHANNEL_PUBLIC_SIZE (sizeof(struct wrtd_out_channel) \
- sizeof(struct wrtd_out_channel_private))
/**
* @file libwrtd-interal.c
*/
void unbag_ts(uint32_t *buf, int offset, struct wr_timestamp *ts);
int wrtd_validate_acknowledge(struct trtl_msg *msg);
int wrtd_trig_id_cmp(struct wrtd_trig_id *id1, struct wrtd_trig_id *id2);
extern int wrtd_trivial_request(struct wrtd_node *dev,
struct trtl_msg *request_msg,
enum wrtd_core core);
extern int wrtd_send_and_receive_sync(struct wrtd_desc *wrtd,
struct trtl_msg *msg,
enum wrtd_core core);
extern void wrtd_timestamp_endianess_fix(struct wr_timestamp *ts);
extern void wrtd_output_rule_endianess_fix(struct lrt_output_rule *rule);
#endif
list-master/lib/libwrtd-logging.c 0000664 0000000 0000000 00000024030 13156247624 0017340 0 ustar 00root root 0000000 0000000 /*
* Copyright (C) 2015-2016 CERN (www.cern.ch)
* Author: Federico Vaga
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*/
#include
#include
#include
#include
#include
#include
#include
/**
* It returns a human readable string that describe a given log level
* @param[in] lvl log level
* @return a string if the log level is mapped, otherwise an empty string
*/
const char *wrtd_strlogging(enum wrtd_log_level lvl)
{
switch (lvl) {
case WRTD_LOG_NOTHING:
return "off";
case WRTD_LOG_RAW:
return "raw";
case WRTD_LOG_SENT:
return "sent";
case WRTD_LOG_PROMISC:
return "promiscuous";
case WRTD_LOG_FILTERED:
return "filtered";
case WRTD_LOG_EXECUTED:
return "executed";
case WRTD_LOG_MISSED:
return "missed";
case WRTD_LOG_ALL:
return "all";
}
return "n/a";
}
/**
* It returns the full string describing the log_level in use
* @param[out] buf where write the string
* @param[in] log_level the log level to describe
*/
void wrtd_strlogging_full(char *buf, uint32_t log_level)
{
enum wrtd_log_level lvl;
if (!log_level) { /* No log level */
strcpy(buf, wrtd_strlogging(log_level));
return;
}
strcpy(buf,"");
for (lvl = 0x1; lvl <= WRTD_LOG_MISSED; lvl <<= 1) {
if (lvl & log_level) {
strcat(buf, wrtd_strlogging(lvl));
strcat(buf, " ");
}
}
}
/**
* It converts a given logging string into a log_level
* @param[in] log string log level
* @return the correspondent log level enum
*/
enum wrtd_log_level wrtd_strlogging_to_level(char *log)
{
if(!strcmp(log, "all"))
return WRTD_LOG_ALL;
if(!strcmp(log, "promiscuous"))
return WRTD_LOG_PROMISC;
if(!strcmp(log, "raw"))
return WRTD_LOG_RAW;
if(!strcmp(log, "executed"))
return WRTD_LOG_EXECUTED;
if(!strcmp(log, "missed"))
return WRTD_LOG_MISSED;
if(!strcmp(log, "sent"))
return WRTD_LOG_SENT;
if(!strcmp(log, "filtered"))
return WRTD_LOG_FILTERED;
return WRTD_LOG_NOTHING;
}
/**
* It opens the logging interface for a given divice. The default
* logging level will be applied to all device channels. You can change it
* later using wrtd_log_level_set()
* @param[in] dev device token
* @param[in] input channel number [-1, 4]. [-1] for all channels, [0,4] for a
* specific one.
* @param[in] core WRTD core to use
* @return a HMQ token on success, NULL on error and errno is set appropriately
*/
static struct trtl_hmq *wrtd_log_open(struct wrtd_node *dev,
int channel,
enum wrtd_core core)
{
struct wrtd_desc *wrtd = (struct wrtd_desc *)dev;
struct trtl_msg_filter filter = {
.operation = TRTL_MSG_FILTER_EQ,
.word_offset = 3, /* channel field */
.mask = 0xFFFF, /* entire field */
.value = channel, /* required channel */
};
struct trtl_hmq *hmq = NULL;
int err;
int n_chan = core ? FD_NUM_CHANNELS : TDC_NUM_CHANNELS;
unsigned int hmq_back_index = core ? WRTD_OUT_FD_LOGGING :
WRTD_OUT_TDC_LOGGING;
if (channel < -1 || channel >= n_chan) {
errno = EWRTD_INVALID_CHANNEL;
return NULL;
}
hmq = trtl_hmq_open(wrtd->trtl, hmq_back_index, 0);
if (!hmq)
return NULL;
if (channel > -1) {
if (core == WRTD_CORE_IN) {
/* On input side we have the header */
filter.word_offset = 6;
}
/* the user want to filter per channel */
err = trtl_hmq_filter_add(hmq, &filter);
if (err)
goto out_close;
}
return hmq;
out_close:
trtl_hmq_close(hmq);
return NULL;
}
/**
* It reads one or more log entry from a given hmq_log. The user of this
* function must check that the hmq_log used correspond to a logging interface
* @param[in] hmq_log logging HMQ.
* @param[out] log log message
* @param[in] count number of messages to read
* @param[in] poll_timeout poll(2) timeout argument. Negative means infinite.
* @return number of read messages on success (check errno if it returns less
* messages than expected), -1 on error and errno is set appropriately
*/
int wrtd_log_read(struct trtl_hmq *hmq_log, struct wrtd_log_entry *log,
int count, int poll_timeout)
{
struct trtl_proto_header hdr;
struct wrtd_log_entry *cur = log;
struct trtl_msg *msg;
struct pollfd p;
int remaining = count;
int n_read = 0, ret;
p.fd = hmq_log->fd;
p.events = POLLIN;
/* Clean up errno to be able to distinguish between error cases and
normal behaviour when the function return less messages
than expected */
errno = 0;
while (remaining) {
ret = poll(&p, 1, poll_timeout);
if (ret <= 0 || !(p.revents & POLLIN))
break;
msg = trtl_hmq_receive(hmq_log);
if (!msg)
break;
trtl_message_unpack(msg, &hdr, cur);
if (hdr.msg_id != WRTD_IN_ACTION_LOG &&
hdr.msg_id != WRTD_OUT_ACTION_LOG) {
free(msg);
errno = EWRTD_INVALID_ANSWER_STATE;
break;
}
wrtd_timestamp_endianess_fix(&cur->ts);
remaining--;
n_read++;
cur++;
free(msg);
}
return (n_read > 0 || errno == 0 ? n_read : -1);
}
/**
* It closes the logging interface
* @param[in] hmq HMQ token to close
*/
void wrtd_log_close(struct trtl_hmq *hmq)
{
trtl_hmq_close(hmq);
}
/**
* @param[in] dev device token
* @param[in] channel 0-based channel index
* @param[in] log_level log level to apply to the logging messages
* @return 0 on success, -1 on error and errno is set appropriately
*/
static int wrtd_log_level_set(struct wrtd_node *dev, unsigned int channel,
uint32_t log_level, enum wrtd_core core)
{
struct wrtd_desc *wrtd = (struct wrtd_desc *)dev;
struct trtl_structure_tlv tlv;
struct trtl_proto_header hdr;
struct wrtd_out_channel ochan;
struct wrtd_in_channel ichan;
int err;
hdr.flags = TRTL_PROTO_FLAG_SYNC;
if (core) {
if (channel >= FD_NUM_CHANNELS) {
errno = EWRTD_INVALID_CHANNEL;
return -1;
}
tlv.index = OUT_STRUCT_CHAN_0 + channel;
tlv.size = WRTD_OUT_CHANNEL_PUBLIC_SIZE;
tlv.structure = &ochan;
hdr.slot_io = (WRTD_IN_FD_CONTROL << 4) |
(WRTD_OUT_FD_CONTROL & 0xF);
/* TODO set promiscuous mode */
} else {
if (channel >= TDC_NUM_CHANNELS) {
errno = EWRTD_INVALID_CHANNEL;
return -1;
}
tlv.index = IN_STRUCT_CHAN_0 + channel;
tlv.size = sizeof(struct wrtd_in_channel);
tlv.structure = &ichan;
hdr.slot_io = (WRTD_IN_TDC_CONTROL << 4) |
(WRTD_OUT_TDC_CONTROL & 0xF);
}
err = trtl_rt_structure_get(wrtd->trtl, &hdr, &tlv, 1);
if (err)
return err;
if (core)
ochan.config.log_level = log_level;
else
ichan.config.log_level = log_level;
return trtl_rt_structure_set(wrtd->trtl, &hdr, &tlv, 1);
}
/**
* It opens the logging interface for a given divice. The default
* logging level will be applied to all device channels. You can change it
* later using wrtd_out_log_level_set()
* @param[in] dev device token
* @param[in] output channel number [-1, 3]. [-1] for all channels, [0,3] for a
* specific one.
* @return a HMQ token on success, NULL on error and errno is set appropriately
*/
struct trtl_hmq *wrtd_out_log_open(struct wrtd_node *dev, int output)
{
return wrtd_log_open(dev, output, WRTD_CORE_OUT);
}
/**
* It sets the logging level for an output channel
* @param[in] dev device token
* @param[in] output index (0-based) of output channel
* @param[in] log_level log level to apply to the logging messages
* @return 0 on success, -1 on error and errno is set appropriately
*/
int wrtd_out_log_level_set(struct wrtd_node *dev, unsigned int output,
uint32_t log_level)
{
return wrtd_log_level_set(dev, output, log_level,
WRTD_CORE_OUT);
}
/**
* It gets the logging level for an output channel
* @param[in] dev device token
* @param[in] output index (0-based) of output channel
* @param[out] log_level current log level used by the Real-Time application
* @return 0 on success, -1 on error and errno is set appropriately
*/
int wrtd_out_log_level_get(struct wrtd_node *dev, unsigned int input,
uint32_t *log_level)
{
struct wrtd_output_state state;
int err;
err = wrtd_out_state_get(dev, input, &state);
if (err)
return err;
*log_level = state.log_level;
return 0;
}
/**
* It opens the logging interface for device a given divice. The default
* logging level will be applied to all device channels. You can change it
* later using wrtd_in_log_level_set()
* @param[in] dev device token
* @param[in] lvl default logging level
* @param[in] input channel number [-1, 4]. [-1] for all channels, [0,4] for a
* specific one.
* @return a HMQ token on success, NULL on error and errno is set appropriately
*/
struct trtl_hmq *wrtd_in_log_open(struct wrtd_node *dev, int input)
{
return wrtd_log_open(dev, input, WRTD_CORE_IN);
}
/**
* It sets the logging level for an input channel
* @param[in] dev device token
* @param[in] input index (0-based) of input channel
* @param[in] log_level log level to apply to the logging messages
* @return 0 on success, -1 on error and errno is set appropriately
*/
int wrtd_in_log_level_set(struct wrtd_node *dev, unsigned int input,
uint32_t log_level)
{
return wrtd_log_level_set(dev, input, log_level, WRTD_CORE_IN);
}
/**
* It gets the logging level for an input channel
* @param[in] dev device token
* @param[in] input index (0-based) of input channel
* @param[out] log_level current log level used by the Real-Time application
* @return 0 on success, -1 on error and errno is set appropriately
*/
int wrtd_in_log_level_get(struct wrtd_node *dev, unsigned int input,
uint32_t *log_level)
{
struct wrtd_input_state state;
int err;
err = wrtd_in_state_get(dev, input, &state);
if (err)
return err;
*log_level = state.log_level;
return 0;
}
list-master/lib/libwrtd-output.c 0000664 0000000 0000000 00000077400 13156247624 0017263 0 ustar 00root root 0000000 0000000 /*
* Copyright (C) 2014-2016 CERN (www.cern.ch)
* Author: Federico Vaga
* inspired by a draft of Tomasz Wlostowski
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*/
#include
#include
#include
#include
#include
/* Basic header for synchronous messages */
static const struct trtl_proto_header hdr_base_sync = {
.slot_io = (WRTD_IN_FD_CONTROL << 4) |(WRTD_OUT_FD_CONTROL & 0xF),
.flags = TRTL_PROTO_FLAG_SYNC,
};
/*
* Internal helper to send and receive synchronous messages to/from the WRNC
*/
static inline int wrtd_out_send_and_receive_sync(struct wrtd_desc *wrtd,
struct trtl_msg *msg)
{
/* Send the message and get answer */
struct trtl_hmq *hmq;
int err;
hmq = trtl_hmq_open(wrtd->trtl, WRTD_IN_FD_CONTROL, TRTL_HMQ_INCOMING);
if (!hmq)
return -1;
err = trtl_hmq_send_and_receive_sync(hmq, WRTD_OUT_FD_CONTROL, msg,
WRTD_DEFAULT_TIMEOUT);
trtl_hmq_close(hmq);
return err < 0 ? err : 0; /* Ignore timeout */
}
/**
* It retrieves the trigger index where you can write.
* If the trigger with ID 'tid' already exists it returns its index,
* otherwise it return the first free index.
*/
static int wrtd_out_trigger_index_get(struct wrtd_desc *wrtd,
struct wrtd_trig_id *tid)
{
struct trtl_proto_header hdr = {
.msg_id = WRTD_OUT_ACTION_TRIG_IDX,
.slot_io = (WRTD_IN_FD_CONTROL << 4) |
(WRTD_OUT_FD_CONTROL & 0xF),
.flags = TRTL_PROTO_FLAG_SYNC,
.len = sizeof(struct wrtd_trig_id) / 4,
};
struct trtl_msg msg;
void *data;
int err;
memset(&msg, 0, sizeof(struct trtl_msg));
data = &msg.data[sizeof(struct trtl_proto_header) / 4];
memcpy(data, tid, sizeof(struct wrtd_trig_id));
trtl_message_header_set(&msg, &hdr);
msg.datalen = sizeof(struct trtl_proto_header) / 4 + hdr.len;
err = wrtd_out_send_and_receive_sync(wrtd, &msg);
if (err)
return -1;
trtl_message_header_get(&msg, &hdr);
if (hdr.len != 1 || hdr.msg_id == RT_ACTION_SEND_NACK) {
errno = EWRTD_NOFOUND_TRIGGER;
return -1;
}
if (hdr.msg_id != WRTD_OUT_ACTION_TRIG_IDX &&
hdr.msg_id != WRTD_OUT_ACTION_TRIG_FRE) {
errno = ETRTL_INVALID_MESSAGE;
return -1;
}
/* return the trigger index */
return msg.data[sizeof(struct trtl_proto_header) / 4];
}
static int wrtd_out_action_one_word(struct wrtd_desc *wrtd,
uint8_t msgid, uint32_t word)
{
struct trtl_proto_header hdr = {
.msg_id = msgid,
.slot_io = (WRTD_IN_FD_CONTROL << 4) |
(WRTD_OUT_FD_CONTROL & 0xF),
.flags = TRTL_PROTO_FLAG_SYNC,
.len = 1,
};
struct trtl_msg msg;
uint32_t *data;
int err;
memset(&msg, 0, sizeof(struct trtl_msg));
data = &msg.data[sizeof(struct trtl_proto_header) / 4];
data[0] = word;
trtl_message_header_set(&msg, &hdr);
msg.datalen = sizeof(struct trtl_proto_header) / 4 + hdr.len;
err = wrtd_out_send_and_receive_sync(wrtd, &msg);
if (err)
return -1;
trtl_message_header_get(&msg, &hdr);
if (hdr.msg_id != RT_ACTION_SEND_ACK) {
errno = EWRTD_INVALID_ANSWER_ACK;
return -1;
}
return 0;
}
static inline int wrtd_out_trigger_insert(struct wrtd_desc *wrtd, uint32_t tid)
{
return wrtd_out_action_one_word(wrtd, WRTD_OUT_ACTION_TRIG_ADD, tid);
}
static inline int wrtd_out_trigger_remove(struct wrtd_desc *wrtd, uint32_t tid)
{
return wrtd_out_action_one_word(wrtd, WRTD_OUT_ACTION_TRIG_DEL, tid);
}
static inline int wrtd_out_rt_disable(struct wrtd_desc *wrtd,
unsigned int output)
{
return wrtd_out_action_one_word(wrtd, WRTD_OUT_ACTION_DISABLE, output);
}
static struct trtl_structure_tlv wrtd_trigger_tlv(uint32_t index,
struct wrtd_out_trigger *trig)
{
struct trtl_structure_tlv tlv = {
.index = __WRTD_OUT_STRUCT_MAX + index,
.size = sizeof(struct wrtd_out_trigger),
.structure = trig,
};
return tlv;
}
static struct trtl_structure_tlv wrtd_channel_tlv(uint32_t index,
struct wrtd_out_channel *chan)
{
struct trtl_structure_tlv tlv = {
.index = OUT_STRUCT_CHAN_0 + index,
.size = WRTD_OUT_CHANNEL_PUBLIC_SIZE,
.structure = chan,
};
return tlv;
}
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/* * * * * * * * * * PROTOTYPEs IMPLEMENTATION * * * * * * * * * */
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/**
* It retreives the current output status of a given channel
* @param[in] dev device token
* @param[in] output index (0-based) of output channel
* @param[out] state channel status
* @return 0 on success, -1 on error and errno is set appropriately
*/
int wrtd_out_state_get(struct wrtd_node *dev, unsigned int output,
struct wrtd_output_state *state)
{
struct wrtd_desc *wrtd = (struct wrtd_desc *)dev;
struct wrtd_out out;
struct wrtd_out_channel chan;
struct trtl_structure_tlv tlv = wrtd_channel_tlv(output, &chan);
struct trtl_proto_header hdr = hdr_base_sync;
int err;
if (output >= FD_NUM_CHANNELS) {
errno = EWRTD_INVALID_CHANNEL;
return -1;
}
if (state == NULL) {
errno = ENOMEM;
return -1;
}
err = trtl_rt_structure_get(wrtd->trtl, &hdr, &tlv, 1);
if (err)
return err;
/* Copy to state structure */
state->output = chan.n;
state->executed_pulses = chan.stats.hits;
state->missed_pulses_late = chan.stats.miss_timeout;
state->missed_pulses_deadtime = chan.stats.miss_deadtime;
state->missed_pulses_overflow = chan.stats.miss_overflow;
state->missed_pulses_no_timing = chan.stats.miss_no_timing;
state->last_executed = chan.stats.last_executed;
state->last_enqueued = chan.stats.last_enqueued;
state->last_lost = chan.stats.last_lost;
wrtd_timestamp_endianess_fix(&state->last_executed.ts);
wrtd_timestamp_endianess_fix(&state->last_enqueued.ts);
wrtd_timestamp_endianess_fix(&state->last_lost.ts);
state->mode = chan.config.mode;
state->flags = chan.config.flags;
state->log_level = chan.config.log_level;
state->pulse_width.seconds = 0;
state->pulse_width.frac = 0;
state->pulse_width.ticks = chan.config.width_cycles;
state->dead_time.seconds = 0;
state->dead_time.frac = 0;
state->dead_time.ticks = chan.config.dead_time;
hdr.len = 0; /* reset len */
tlv.index = OUT_STRUCT_DEVICE;
tlv.size = sizeof(struct wrtd_out);
tlv.structure = &out;
err = trtl_rt_structure_get(wrtd->trtl, &hdr, &tlv, 1);
if (err)
return err;
state->received_messages = out.counter_etherbone;
state->received_loopback = out.counter_loopback;
state->last_received = out.last_received;
wrtd_timestamp_endianess_fix(&state->last_received.ts);
return 0;
}
/**
* It enables/disables a trigger output line
* @param[in] dev device token
* @param[in] output index (0-based) of output channel
* @param[in] enable 1 to enable the output, 0 disables it.
* @return 0 on success, -1 on error and errno is set appropriately
*/
int wrtd_out_enable(struct wrtd_node *dev, unsigned int output,
int enable)
{
struct wrtd_desc *wrtd = (struct wrtd_desc *)dev;
struct wrtd_out_channel chan;
struct trtl_structure_tlv tlv = wrtd_channel_tlv(output, &chan);
struct trtl_proto_header hdr = hdr_base_sync;
int err;
if (output >= FD_NUM_CHANNELS) {
errno = EWRTD_INVALID_CHANNEL;
return -1;
}
err = trtl_rt_structure_get(wrtd->trtl, &hdr, &tlv, 1);
if (err)
return err;
if (enable) {
chan.config.flags |= WRTD_ENABLED;
} else {
chan.config.flags &= ~(WRTD_ENABLED | WRTD_ARMED |
WRTD_TRIGGERED | WRTD_LAST_VALID);
chan.config.state = OUT_ST_IDLE;
err = wrtd_out_rt_disable(wrtd, output);
if (err)
return -1;
}
return trtl_rt_structure_set(wrtd->trtl, &hdr, &tlv, 1);
}
static int wrtd_out_trig_assign_condition_by_index(struct wrtd_node *dev,
unsigned int output,
uint32_t trig_idx,
uint32_t cond_idx)
{
struct wrtd_desc *wrtd = (struct wrtd_desc *)dev;
struct wrtd_out_trigger trig;
struct trtl_structure_tlv tlv;
struct trtl_proto_header hdr = hdr_base_sync;
int err;
if (output >= FD_NUM_CHANNELS) {
errno = EWRTD_INVALID_CHANNEL;
return -1;
}
tlv = wrtd_trigger_tlv(trig_idx, &trig);
err = trtl_rt_structure_get(wrtd->trtl, &hdr, &tlv, 1);
if (err)
return err;
wrtd_output_rule_endianess_fix(&trig.ocfg[output]);
if (!(trig.flags & ENTRY_FLAG_VALID)) {
/* If the given trigger is not valid, then skip */
errno = EINVAL;
return -1;
}
trig.ocfg[output].state &= ~HASH_ENT_DIRECT;
trig.ocfg[output].state |= HASH_ENT_CONDITIONAL;
trig.ocfg[output].cond_ptr = cond_idx;
wrtd_output_rule_endianess_fix(&trig.ocfg[output]);
err = trtl_rt_structure_set(wrtd->trtl, &hdr, &tlv, 1);
if (err)
return err;
tlv = wrtd_trigger_tlv(cond_idx, &trig);
err = trtl_rt_structure_get(wrtd->trtl, &hdr, &tlv, 1);
if (err)
return err;
wrtd_output_rule_endianess_fix(&trig.ocfg[output]);
if (!(trig.flags & ENTRY_FLAG_VALID)) {
/* If the given trigger is not valid, then skip */
errno = EINVAL;
return -1;
}
trig.ocfg[output].state &= ~HASH_ENT_DIRECT;
trig.ocfg[output].state |= HASH_ENT_CONDITION;
trig.ocfg[output].cond_ptr = -1;
wrtd_output_rule_endianess_fix(&trig.ocfg[output]);
return trtl_rt_structure_set(wrtd->trtl, &hdr, &tlv, 1);
}
/**
* It sets the given bitmaks (it means that it does OR with the current value)
*/
static int wrtd_out_flag_set(struct wrtd_node *dev, unsigned int output,
uint32_t flags)
{
struct wrtd_desc *wrtd = (struct wrtd_desc *)dev;
struct wrtd_out_channel chan;
struct trtl_structure_tlv tlv = wrtd_channel_tlv(output, &chan);
struct trtl_proto_header hdr = hdr_base_sync;
int err;
if (output >= FD_NUM_CHANNELS) {
errno = EWRTD_INVALID_CHANNEL;
return -1;
}
err = trtl_rt_structure_get(wrtd->trtl, &hdr, &tlv, 1);
if (err)
return err;
chan.config.flags |= flags;
return trtl_rt_structure_set(wrtd->trtl, &hdr, &tlv, 1);
}
/**
* It sets the given bitmaks (it means that it does AND NOT with the current
* value)
*/
static int wrtd_out_flag_clr(struct wrtd_node *dev, unsigned int output,
uint32_t flags)
{
struct wrtd_desc *wrtd = (struct wrtd_desc *)dev;
struct wrtd_out_channel chan;
struct trtl_structure_tlv tlv = wrtd_channel_tlv(output, &chan);
struct trtl_proto_header hdr = hdr_base_sync;
int err;
if (output >= FD_NUM_CHANNELS) {
errno = EWRTD_INVALID_CHANNEL;
return -1;
}
err = trtl_rt_structure_get(wrtd->trtl, &hdr, &tlv, 1);
if (err)
return err;
chan.config.flags &= ~flags;
return trtl_rt_structure_set(wrtd->trtl, &hdr, &tlv, 1);
}
static int wrtd_out_trig_assign_one(struct wrtd_node *dev, unsigned int output,
struct wrtd_trigger_handle *handle,
struct wrtd_trig_id *tid)
{
struct wrtd_desc *wrtd = (struct wrtd_desc *)dev;
struct wrtd_out_trigger trig;
struct trtl_structure_tlv tlv;
struct trtl_proto_header hdr = hdr_base_sync;
int err, ret;
handle->channel = output;
if (handle->channel >= FD_NUM_CHANNELS) {
errno = EWRTD_INVALID_CHANNEL;
return -1;
}
ret = wrtd_out_trigger_index_get(wrtd, tid);
if (ret < 0)
return ret;
handle->ptr_trig = ret;
tlv = wrtd_trigger_tlv(handle->ptr_trig, &trig);
err = trtl_rt_structure_get(wrtd->trtl, &hdr, &tlv, 1);
if (err)
return err;
trig.flags |= ENTRY_FLAG_VALID;
trig.id = *tid;
memset(&trig.ocfg[handle->channel], 0, sizeof(struct lrt_output_rule));
trig.ocfg[handle->channel].delay_cycles = 100000000 / 8000;
trig.ocfg[handle->channel].state = HASH_ENT_DISABLED;
trig.ocfg[handle->channel].state |= HASH_ENT_DIRECT;
trig.ocfg[handle->channel].cond_ptr = -1;
wrtd_output_rule_endianess_fix(&trig.ocfg[handle->channel]);
err = trtl_rt_structure_set(wrtd->trtl, &hdr, &tlv, 1);
if (err)
return err;
err = wrtd_out_trigger_insert(wrtd, handle->ptr_trig);
if (err)
return err;
return wrtd_out_flag_set(dev, handle->channel, WRTD_TRIGGER_ASSIGNED);
}
/**
* It assign a trigger to an output channel
* @param[in] dev pointer to open node device.
* @param[in] output index (0-based) of output channel
* @param[out] handle
* @param[in] trig trigger id to assign
* @param[in] condition trigger id to assign to the condition
* @return 0 on success, -1 on error and errno is set appropriately
*/
int wrtd_out_trig_assign(struct wrtd_node *dev, unsigned int output,
struct wrtd_trigger_handle *handle,
struct wrtd_trig_id *tid,
struct wrtd_trig_id *condition)
{
struct wrtd_trigger_handle tmp_handle;
int err;
if (output >= FD_NUM_CHANNELS) {
errno = EWRTD_INVALID_CHANNEL;
return -1;
}
err = wrtd_out_trig_assign_one(dev, output, handle, tid);
if (err)
return err;
if (!condition)
return 0;
err = wrtd_out_trig_assign_one(dev, output, &tmp_handle, condition);
if (err)
return err;
handle->ptr_cond = tmp_handle.ptr_trig;
return wrtd_out_trig_assign_condition_by_index(dev, output,
handle->ptr_trig,
handle->ptr_cond);
}
/**
* Un-assign a give trigger
* @param[in] dev pointer to open node device.
* @param[in] handle
* @return 0 on success, -1 on error and errno is set appropriately
*/
int wrtd_out_trig_unassign(struct wrtd_node *dev,
struct wrtd_trigger_handle *handle)
{
struct wrtd_desc *wrtd = (struct wrtd_desc *)dev;
struct wrtd_output_trigger_state triggers[256];
struct wrtd_out_trigger trig;
struct trtl_structure_tlv tlv = wrtd_trigger_tlv(handle->ptr_trig,
&trig);
struct trtl_proto_header hdr = hdr_base_sync;
struct wrtd_output_trigger_state state;
int err, cnt = 0, i;
volatile int cond;
if (handle->channel >= FD_NUM_CHANNELS) {
errno = EWRTD_INVALID_CHANNEL;
return -1;
}
err = trtl_rt_structure_get(wrtd->trtl, &hdr, &tlv, 1);
if (err)
return err;
wrtd_output_rule_endianess_fix(&trig.ocfg[handle->channel]);
cond = trig.ocfg[handle->channel].cond_ptr;
memset(&trig.ocfg[handle->channel], 0, sizeof(struct lrt_output_rule));
for (i = 0; i < FD_NUM_CHANNELS; i++)
if (trig.ocfg[i].state == HASH_ENT_EMPTY)
cnt++;
if (cnt == FD_NUM_CHANNELS)
trig.flags &= ~ENTRY_FLAG_VALID;
wrtd_output_rule_endianess_fix(&trig.ocfg[handle->channel]);
err = trtl_rt_structure_set(wrtd->trtl, &hdr, &tlv, 1);
if (err)
return err;
err = wrtd_out_trigger_remove(wrtd, handle->ptr_trig);
if (err)
return err;
err = wrtd_out_trig_get_all(dev, handle->channel, triggers, 256);
if (err < 0)
return -1;
if (err == 0){
err = wrtd_out_flag_clr(dev, handle->channel,
WRTD_TRIGGER_ASSIGNED);
} else {
err = 0;
}
if (cond < 0 || cond > FD_HASH_ENTRIES)
return err;
/* Remove also its condition */
err = wrtd_out_trig_state_get_by_index(dev, cond,
handle->channel, &state);
if (err)
return err;
return wrtd_out_trig_unassign(dev, &state.handle);
}
/**
* It retreive a given number of triggers from output device
* @param[in] dev device token
* @param[in] output index (0-based) of output channel
* @param[out] triggers list of assigned trigger
* @param[in] max_count maximum triggers to retreive
* @return number of triggers on success, -1 on error and
* errno is set appropriately
*/
int wrtd_out_trig_get_all(struct wrtd_node *dev, unsigned int output,
struct wrtd_output_trigger_state *triggers,
int max_count)
{
struct wrtd_output_trigger_state tmp;
int err = 0, i, count = 0;
if (output >= FD_NUM_CHANNELS) {
errno = EWRTD_INVALID_CHANNEL;
return -1;
}
for (i = 0; count < max_count && i < FD_HASH_ENTRIES; i++) {
err = wrtd_out_trig_state_get_by_index(dev, i, output, &tmp);
if (err) {
if (errno == EWRTD_NOFOUND_TRIGGER) {
err = 0;
continue;
} else {
break;
}
} else {
memcpy(&triggers[count], &tmp,
sizeof(struct wrtd_output_trigger_state));
count++;
}
}
/* Do not count trigger with error */
if (err)
count--;
return count > 0 ? count : err;
}
/**
* It returns a trigger state from a given handle.
* @param[in] dev pointer to open node device.
* @param[in] handle trigger where act on
* @param[out] trigger trigger status
* @return 0 on success, -1 on error and errno is set appropriately
*/
int wrtd_out_trig_state_get_by_handle(struct wrtd_node *dev,
struct wrtd_trigger_handle *handle,
struct wrtd_output_trigger_state *trigger)
{
return wrtd_out_trig_state_get_by_index(dev, handle->ptr_trig,
handle->channel, trigger);
}
/**
* It returns a trigget from a given identifier.
* Whenever is possible you should prefer wrtd_out_trig_state_get_by_handle()
* @param[in] dev device token
* @param[in] output index (0-based) of output channel
* @param[in] id identifier of the trigger to retrieve
* @param[out] trigger trigger status
* @return 0 on success, -1 on error and errno is set appropriately
*/
int wrtd_out_trig_state_get_by_id(struct wrtd_node *dev,
unsigned int output,
struct wrtd_trig_id *tid,
struct wrtd_output_trigger_state *trigger)
{
struct wrtd_desc *wrtd = (struct wrtd_desc *)dev;
int index;
index = wrtd_out_trigger_index_get(wrtd, tid);
if (index < 0) {
errno = EWRTD_NOFOUND_TRIGGER;
return -1;
}
return wrtd_out_trig_state_get_by_index(dev, index, output, trigger);
}
/**
* It returns a trigget from a given index. The index may change due to trigger
* assing and un-assing. So, before use this function you have to check the
* current trigger's indexes. Note that this is not thread safe.
* Whenever is possible you should prefer wrtd_out_trig_state_get_by_handle()
* @param[in] dev device token
* @param[in] output index (0-based) of output channel
* @param[out] trigger trigger status
* @return 0 on success, -1 on error and errno is set appropriately
*/
int wrtd_out_trig_state_get_by_index(struct wrtd_node *dev, unsigned int index,
unsigned int output,
struct wrtd_output_trigger_state *trigger)
{
struct wrtd_desc *wrtd = (struct wrtd_desc *)dev;
struct wrtd_out_trigger trig;
struct trtl_structure_tlv tlv = wrtd_trigger_tlv(index, &trig);
struct trtl_proto_header hdr = hdr_base_sync;
struct wrtd_output_trigger_state cond;
int err;
err = trtl_rt_structure_get(wrtd->trtl, &hdr, &tlv, 1);
if (err)
return err;
wrtd_output_rule_endianess_fix(&trig.ocfg[output]);
if (!(trig.flags & ENTRY_FLAG_VALID) ||
(trig.ocfg[output].state == HASH_ENT_EMPTY)) {
errno = EWRTD_NOFOUND_TRIGGER;
return -1;
}
memset(trigger, 0, sizeof(struct wrtd_output_trigger_state));
trigger->handle.channel = output;
trigger->handle.ptr_trig = index;
trigger->handle.ptr_cond = (uint32_t)trig.ocfg[output].cond_ptr;
trigger->is_conditional = (0 <= trigger->handle.ptr_cond && trigger->handle.ptr_cond <= FD_HASH_ENTRIES);
trigger->enabled = !(trig.ocfg[output].state & HASH_ENT_DISABLED);
trigger->trigger = trig.id;
trigger->delay_trig.ticks = trig.ocfg[output].delay_cycles;
trigger->delay_trig.frac = trig.ocfg[output].delay_frac;
if (trig.ocfg[output].latency_avg_nsamples) {
trigger->latency_average_us = (trig.ocfg[output].latency_avg_sum /
trig.ocfg[output].latency_avg_nsamples + 124) / 125;
} else {
trigger->latency_average_us = 0;
}
trigger->latency_worst_us = (trig.ocfg[output].latency_worst + 124)
/ 125;
trigger->executed_pulses = trig.ocfg[output].hits;
trigger->missed_pulses = trig.ocfg[output].misses;
if (!trigger->is_conditional)
return 0;
/* Get conditional trigger */
err =wrtd_out_trig_state_get_by_index(dev, trigger->handle.ptr_cond,
output, &cond);
if (err)
return err;
memcpy(&trigger->condition, &cond.trigger, sizeof(struct wrtd_trig_id));
memcpy(&trigger->delay_cond, &cond.delay_trig,
sizeof(struct wr_timestamp));
return 0;
}
static int wrtd_out_rule_delay_set(struct wrtd_node *dev,
int output,
uint32_t trig_idx,
uint64_t delay_ps)
{
struct wrtd_desc *wrtd = (struct wrtd_desc *)dev;
struct wrtd_out_trigger trig;
struct trtl_structure_tlv tlv = wrtd_trigger_tlv(trig_idx, &trig);
struct trtl_proto_header hdr = hdr_base_sync;
struct wr_timestamp t;
int err;
if (output >= FD_NUM_CHANNELS) {
errno = EWRTD_INVALID_CHANNEL;
return -1;
}
if (delay_ps > (1000 * 1000 * 1000 * 1000ULL - 1000ULL)) {
errno = EWRTD_INVALID_DELAY;
return -1;
}
err = trtl_rt_structure_get(wrtd->trtl, &hdr, &tlv, 1);
if (err)
return err;
wrtd_output_rule_endianess_fix(&trig.ocfg[output]);
if (!(trig.flags & ENTRY_FLAG_VALID)) {
errno = EWRTD_NOFOUND_TRIGGER;
return -1;
}
wrtd_pico_to_ts(&delay_ps, &t);
trig.ocfg[output].delay_cycles = t.ticks;
trig.ocfg[output].delay_frac = t.frac;
wrtd_output_rule_endianess_fix(&trig.ocfg[output]);
return trtl_rt_structure_set(wrtd->trtl, &hdr, &tlv, 1);
}
/**
* It sets the delay to apply for a given trigger
* @param[in] dev pointer to open node device.
* @param[in] handle trigger where act on
* @param[in] delay_ps delay in pico-seconds in range [0, 999999999000]
* @return 0 on success, -1 on error and errno is set appropriately
*/
int wrtd_out_trig_delay_set(struct wrtd_node *dev,
struct wrtd_trigger_handle *handle,
uint64_t delay_ps)
{
return wrtd_out_rule_delay_set (dev, handle->channel, handle->ptr_trig, delay_ps);
}
/**
* Sets the pulse width for a given output channel.
* @param[in] dev device token
* @param[in] output index (0-based) of output channel
* @param[in] width_ps pulse width in pico-seconds (from 250ns to 1s)
* @return 0 on success, -1 on error and errno is set appropriately
*/
int wrtd_out_pulse_width_set(struct wrtd_node *dev, unsigned int output,
uint64_t width_ps)
{
struct wrtd_desc *wrtd = (struct wrtd_desc *)dev;
struct wrtd_out_channel chan;
struct trtl_structure_tlv tlv = wrtd_channel_tlv(output, &chan);
struct trtl_proto_header hdr = hdr_base_sync;
int err;
if (output >= FD_NUM_CHANNELS) {
errno = EWRTD_INVALID_CHANNEL;
return -1;
}
if (width_ps < 1000ULL * 250 ||
width_ps >= 1000ULL * 1000 * 1000 * 1000) {
errno = EWRTD_INVALID_PULSE_WIDTH;
return -1;
}
err = trtl_rt_structure_get(wrtd->trtl, &hdr, &tlv, 1);
if (err)
return err;
chan.config.width_cycles = width_ps / 8000ULL;
return trtl_rt_structure_set(wrtd->trtl, &hdr, &tlv, 1);
}
/**
* It set the dead time for a given output channel. so, it applies on all
* triggers assigned to the given output channel.
*
* The function will round the value, so it may happen that you read back a
* different value. The reason is that the RT application measure the dead
* time in ticks, which are 8ns steps. So this function will internally
* convert the dead time in ticks. The function accept pico-seconds only to
* be consistent with the API.
* @param[in] dev device token
* @param[in] output index (0-based) of output channel
* @param[in] dead_time_ps dead time in pico-seconds
* @return 0 on success, -1 on error and errno is set appropriately
*/
int wrtd_out_dead_time_set(struct wrtd_node *dev, unsigned int output,
uint64_t dead_time_ps)
{
struct wrtd_desc *wrtd = (struct wrtd_desc *)dev;
struct wrtd_out_channel chan;
struct trtl_structure_tlv tlv = wrtd_channel_tlv(output, &chan);
struct trtl_proto_header hdr = hdr_base_sync;
int err;
if (output >= FD_NUM_CHANNELS) {
errno = EWRTD_INVALID_CHANNEL;
return -1;
}
err = trtl_rt_structure_get(wrtd->trtl, &hdr, &tlv, 1);
if (err)
return err;
chan.config.dead_time = dead_time_ps / 8000;
return trtl_rt_structure_set(wrtd->trtl, &hdr, &tlv, 1);
}
/**
* @param[in] dev pointer to open node device.
* @param[in] handle trigger where act on
* @param[in] delay_ps delay in pico-seconds in range [0, 999999999000]
* @return 0 on success, -1 on error and errno is set appropriately
*/
int wrtd_out_trig_condition_delay_set(struct wrtd_node *dev,
struct wrtd_trigger_handle *handle,
uint64_t delay_ps)
{
if (handle->ptr_cond == 0)
{
errno = EWRTD_NO_TRIGGER_CONDITION;
return -1;
}
return wrtd_out_rule_delay_set (dev, handle->channel, handle->ptr_cond, delay_ps);
}
/**
* @param[in] dev pointer to open node device.
* @param[in] handle trigger where act on
* @param[in] enable 1 to enable, 0 to disable
* @return 0 on success, -1 on error and errno is set appropriately
*/
int wrtd_out_trig_enable(struct wrtd_node *dev,
struct wrtd_trigger_handle *handle, int enable)
{
struct wrtd_desc *wrtd = (struct wrtd_desc *)dev;
struct wrtd_out_trigger trig;
struct trtl_structure_tlv tlv = wrtd_trigger_tlv(handle->ptr_trig,
&trig);
struct trtl_proto_header hdr = hdr_base_sync;
int err;
if (handle->channel >= FD_NUM_CHANNELS) {
errno = EWRTD_INVALID_CHANNEL;
return -1;
}
err = trtl_rt_structure_get(wrtd->trtl, &hdr, &tlv, 1);
if (err)
return err;
wrtd_output_rule_endianess_fix(&trig.ocfg[handle->channel]);
if (!(trig.flags & ENTRY_FLAG_VALID)) {
errno = EWRTD_NOFOUND_TRIGGER;
return -1;
}
if (enable)
trig.ocfg[handle->channel].state &= ~HASH_ENT_DISABLED;
else
trig.ocfg[handle->channel].state |= HASH_ENT_DISABLED;
wrtd_output_rule_endianess_fix(&trig.ocfg[handle->channel]);
return trtl_rt_structure_set(wrtd->trtl, &hdr, &tlv, 1);
}
/**
* It sets the trigger mode of a given output channel
* @param[in] dev device token
* @param[in] output index (0-based) of output channel
* @param[in] mode output mode
* @return 0 on success, -1 on error and errno is set appropriately
*/
int wrtd_out_trigger_mode_set(struct wrtd_node *dev,
unsigned int output,
enum wrtd_trigger_mode mode)
{
struct wrtd_desc *wrtd = (struct wrtd_desc *)dev;
struct wrtd_out_channel chan;
struct trtl_structure_tlv tlv = wrtd_channel_tlv(output, &chan);
struct trtl_proto_header hdr = hdr_base_sync;
int err;
if (output >= FD_NUM_CHANNELS) {
errno = EWRTD_INVALID_CHANNEL;
return -1;
}
err = trtl_rt_structure_get(wrtd->trtl, &hdr, &tlv, 1);
if (err)
return err;
chan.config.mode = mode;
chan.config.flags &= ~(WRTD_TRIGGERED | WRTD_LAST_VALID);
if (chan.config.mode == WRTD_TRIGGER_MODE_SINGLE) {
chan.config.flags &= ~WRTD_ARMED;
chan.config.state = OUT_ST_IDLE;
}
return trtl_rt_structure_set(wrtd->trtl, &hdr, &tlv, 1);
}
/**
* It arms (un-arms) a given output channel
* @param[in] dev device token
* @param[in] output index (0-based) of output channel
* @param[in] armed 1 to arm, 0 to un-arm
* @return 0 on success, -1 on error and errno is set appropriately
*/
int wrtd_out_arm(struct wrtd_node *dev, unsigned int output, int armed)
{
struct wrtd_desc *wrtd = (struct wrtd_desc *)dev;
struct wrtd_out_channel chan;
struct trtl_structure_tlv tlv = wrtd_channel_tlv(output, &chan);
struct trtl_proto_header hdr = hdr_base_sync;
int err;
if (output >= FD_NUM_CHANNELS) {
errno = EWRTD_INVALID_CHANNEL;
return -1;
}
err = trtl_rt_structure_get(wrtd->trtl, &hdr, &tlv, 1);
if (err)
return err;
chan.config.flags &= ~WRTD_TRIGGERED;
if (armed) {
chan.config.flags |= WRTD_ARMED;
chan.config.state = OUT_ST_ARMED;
} else {
chan.config.flags &= ~WRTD_ARMED;
chan.config.state = OUT_ST_IDLE;
}
return trtl_rt_structure_set(wrtd->trtl, &hdr, &tlv, 1);
}
/**
* @param[in] dev device token
* @param[in] output index (0-based) of output channel
* @return 0 on success, -1 on error and errno is set appropriately
*/
int wrtd_out_counters_reset(struct wrtd_node *dev, unsigned int output)
{
struct wrtd_desc *wrtd = (struct wrtd_desc *)dev;
struct wrtd_out_channel chan;
struct trtl_structure_tlv tlv = wrtd_channel_tlv(output, &chan);
struct trtl_proto_header hdr = hdr_base_sync;
int err;
if (output >= FD_NUM_CHANNELS) {
errno = EWRTD_INVALID_CHANNEL;
return -1;
}
err = trtl_rt_structure_get(wrtd->trtl, &hdr, &tlv, 1);
if (err)
return err;
chan.stats.miss_timeout = 0;
chan.stats.miss_deadtime = 0;
chan.stats.miss_no_timing = 0;
chan.stats.miss_overflow = 0;
chan.config.flags &= ~WRTD_LAST_VALID;
return trtl_rt_structure_set(wrtd->trtl, &hdr, &tlv, 1);
}
/**
* @param[in] dev device token
* @param[in] output index (0-based) of output channel
* @return 0 on success, -1 on error and errno is set appropriately
*/
int wrtd_out_check_triggered(struct wrtd_node *dev, unsigned int output)
{
struct wrtd_output_state st;
int err;
err = wrtd_out_state_get(dev, output, &st);
if(err)
return err;
return st.flags & WRTD_TRIGGERED ? 1 : 0;
}
/**
* Check the enable status on a trigger output.
* @param[in] dev device token
* @param[in] output index (0-based) of output channel
* @param[out] enable 1 if it is enabled, 0 otherwise
* @return 0 on success, -1 on error and errno is set appropriately
*/
int wrtd_out_is_enabled(struct wrtd_node *dev, unsigned int output,
unsigned int *enable)
{
struct wrtd_output_state state;
int err;
err = wrtd_out_state_get(dev, output, &state);
if (err)
return -1;
*enable = !!(state.flags & WRTD_ENABLED);
return 0;
}
/**
* Check the armed status on a trigger output.
* @param[in] dev device token
* @param[in] output index (0-based) of output channel
* @param[out] armed 1 if it is enabled, 0 otherwise
* @return 0 on success, -1 on error and errno is set appropriately
*/
int wrtd_out_is_armed(struct wrtd_node *dev, unsigned int output,
unsigned int *armed)
{
struct wrtd_output_state state;
int err;
err = wrtd_out_state_get(dev, output, &state);
if (err)
return -1;
*armed = !!(state.flags & WRTD_ARMED);
return 0;
}
/**
* Check the trigger assigned status on a trigger output. If you provide
* a trigger identifier then the function checks that the given trigger
* is assigned to the given channel. Otherwise it will tell you if there
* is any trigger assigned to the channel.
* @param[in] dev device token
* @param[in] output index (0-based) of output channel
* @param[in] id trigger identifier (optional)
* @param[out] armed 1 if it is enabled, 0 otherwise
* @return 0 on success, -1 on error and errno is set appropriately
*/
int wrtd_out_has_trigger(struct wrtd_node *dev, unsigned int output,
struct wrtd_trig_id *id, unsigned int *assigned)
{
struct wrtd_output_trigger_state triggers[256];
struct wrtd_output_state state;
int ret, i;
/* Set default output */
*assigned = 0;
ret = wrtd_out_state_get(dev, output, &state);
if (ret)
return -1;
if (!id) {
/* Check only if there is at least one trigger */
*assigned = !!(state.flags & WRTD_TRIGGER_ASSIGNED);
return 0;
}
/* Look for the id among all assigned trigger */
ret = wrtd_out_trig_get_all(dev, output, triggers, 256);
if (ret < 0)
return -1;
for (i = 0; i < ret; i++) {
if (wrtd_trig_id_cmp(id, &triggers[i].trigger) == 0) {
*assigned = 1;
return 0;
}
}
return 0;
}
/**
* It check if the output real-time application is alive
* @param[in] dev device token
* @return 0 on success, -1 on error and errno is set appropriately
*/
int wrtd_out_ping(struct wrtd_node *dev)
{
struct wrtd_desc *wrtd = (struct wrtd_desc *)dev;
return trtl_rt_ping(wrtd->trtl, WRTD_IN_FD_CONTROL,
WRTD_OUT_FD_CONTROL);
}
/**
* It gets the output base time
* @param[in] dev device token
* @param[out] ts output device base time
* @return 0 on success, -1 on error and errno is set appropriately
*/
int wrtd_out_base_time(struct wrtd_node *dev, struct wr_timestamp *ts)
{
struct wrtd_desc *wrtd = (struct wrtd_desc *)dev;
uint32_t variables[] = {OUT_VAR_DEVICE_TIME_S, 0,
OUT_VAR_DEVICE_TIME_T, 0};
struct trtl_proto_header hdr = hdr_base_sync;
int err;
err = trtl_rt_variable_get(wrtd->trtl, &hdr, variables, 2);
if (err)
return err;
ts->seconds = variables[1];
ts->ticks = variables[3];
return 0;
}
/**
* It gets the output version
* @param[in] dev device token
* @param[out] version the RT application version
* @return 0 on success, -1 on error and errno is set appropriately
*/
int wrtd_out_version(struct wrtd_node *dev, struct trtl_rt_version *version)
{
struct wrtd_desc *wrtd = (struct wrtd_desc *)dev;
return trtl_rt_version_get(wrtd->trtl, version,
WRTD_IN_FD_CONTROL, WRTD_OUT_FD_CONTROL);
}
list-master/lib/libwrtd.h 0000664 0000000 0000000 00000027346 13156247624 0015736 0 ustar 00root root 0000000 0000000 /*
* Copyright (C) 2014 CERN (www.cern.ch)
* Author: Federico Vaga
* inspired by a draft of Tomasz Wlostowski
* License: GPL v3
*/
#ifndef __WRTD_LIB_H__
#define __WRTD_LIB_H__
/** @file libwrtd.h */
#ifdef __cplusplus
extern "C" {
#endif
#include
#include
#include "libmockturtle.h"
/**
* @file wrtd-common.h
*/
#include "wrtd-common.h"
struct wrtd_node;
#define WRTD_DEFAULT_TIMEOUT 1000
/**
* @enum wrtd_error_list
* White Rabbit Trigger Distribution errors
*/
enum wrtd_error_list {
EWRTD_INVALID_ANSWER_ACK = 3276,
EWRTD_INVALID_ANSWER_STATE,
EWRTD_INVALID_BINARY,
EWRTD_INVALID_DEAD_TIME,
EWRTD_INVALID_DELAY,
EWRTD_INVALID_TRIG_ID,
EWRTD_INVALID_CHANNEL,
EWRTD_NO_IMPLEMENTATION,
EWRTD_INVALID_ANSWER_TRIG,
EWRTD_INVALID_ANSWER_HASH,
EWRTD_INVALID_ANSWER_HASH_CONT,
EWRTD_INVALID_ANSWER_HANDLE,
EWRTD_NOFOUND_TRIGGER,
EWRTD_NO_TRIGGER_CONDITION,
EWRTD_INVALID_PULSE_WIDTH,
EWRTD_INVALID_IN_APP,
EWRTD_INVALID_OUT_APP,
__EWRTD_MAX_ERROR_NUMBER,
};
/**
* @enum wrtd_core
* Core indexes according to their main purpose
*/
enum wrtd_core {
WRTD_CORE_IN = 0, /**< Input core that manages incoming pulses */
WRTD_CORE_OUT = 1, /**< Output core that manages pulses generation */
};
/**
* Trigger token
*/
struct wrtd_trigger_handle {
uint32_t ptr_cond; /**< trigger condition pointer */
uint32_t ptr_trig; /**< trigger pointer */
int channel; /**< channel assigned to the trigger */
};
/**
* Status description for an input channel
*/
struct wrtd_input_state {
int input; /**< Input channel index */
uint32_t flags; /**< enum list_io_flags */
uint32_t log_level; /**< enum list_log_level */
enum wrtd_trigger_mode mode; /**< Trigger mode in use */
uint32_t tagged_pulses; /**< Number of incoming pulses detected */
uint32_t sent_triggers; /**< Number of triggers sent over the
white-rabbit network */
uint32_t sent_packets; /**< Number of packets sent over the
white-rabbit network */
struct wrtd_trigger_entry last_sent; /**< Description of the last
trigger sent */
struct wrtd_trig_id assigned_id; /**< trigger assigned to this channel */
struct wr_timestamp dead_time; /**< Configured dead time */
struct wr_timestamp delay; /**< Time delay assined */
struct wr_timestamp last_tagged_pulse; /** Time stamp of the last
detected pulse*/
struct wr_timestamp tdc_timebase_offset; /**< TDC time base offset */
};
/**
* Status description for a trigger on output
*/
struct wrtd_output_trigger_state {
int is_conditional; /**< tell if the trigger is under condition or not */
int enabled; /**< tell if the trigger is enable, so it may be
generater as output */
struct wrtd_trig_id trigger; /**< Trigger identifier */
struct wrtd_trig_id condition; /**< Trigger identifier for the trigger
condition */
struct wr_timestamp delay_trig; /**< Configured trigger delay */
struct wr_timestamp delay_cond; /**< Configured trigger condition delay */
struct wrtd_trigger_handle handle;
int latency_worst_us; /**< Worst latency in micro-seconds */
int latency_average_us; /**< Average latency in micro-seconds */
uint32_t executed_pulses; /**< Number of executed pulses */
uint32_t missed_pulses; /**< Number of missed pulses */
void *private_data; /**< private pointer used by the library */
};
/**
* Status description for an output channel
*/
struct wrtd_output_state {
int output; /**< Output channel index */
uint32_t executed_pulses; /**< Number of generated pulses */
uint32_t missed_pulses_late; /**< Number of missed pulses due to: */
uint32_t missed_pulses_deadtime; /**< Number of missed pulses due to: */
uint32_t missed_pulses_overflow; /**< Number of missed pulses due to: */
uint32_t missed_pulses_no_timing; /**< Number of missed pulses due to: */
struct wrtd_trigger_entry last_executed; /**< Trigger description of the
last generated trigger */
struct wrtd_trigger_entry last_received; /**< Trigger description of the
last received trigger from
the white-rabbit network */
struct wrtd_trigger_entry last_enqueued; /**< Trigger description of
the last enqueued trigger
in the execution queue */
struct wrtd_trigger_entry last_lost; /**< Trigger description of the
last lost trigger */
uint32_t flags; /**< enum list_io_flags */
uint32_t log_level; /**< enum list_log_level */
enum wrtd_trigger_mode mode; /**< Trigger mode in use */
struct wr_timestamp dead_time; /**< Configured dead time */
struct wr_timestamp pulse_width; /**< Pulse width */
uint32_t received_messages; /**< Number of received packets from
the network */
uint32_t received_loopback;
};
/**
* @file libwrtd-common.c
*/
/**
* @defgroup dev
* Set of functions to manage the basic device and library configuration.
* @{
*/
extern int wrtd_init();
extern void wrtd_exit();
extern struct wrtd_node *wrtd_open_by_fmc(uint32_t device_id);
extern struct wrtd_node *wrtd_open_by_lun(int lun);
extern void wrtd_close(struct wrtd_node *dev);
extern struct trtl_dev *wrtd_get_trtl_dev(struct wrtd_node *dev);
extern int wrtd_load_application(struct wrtd_node *dev, char *rt_tdc,
char *rt_fd);
extern int wrtd_white_rabbit_sync(struct wrtd_node *dev,
unsigned long timeout_s);
extern int wrtd_cpu_restart(struct wrtd_node *dev);
extern int wrtd_time_get(struct wrtd_node *dev, unsigned int input,
struct wr_timestamp *current_time);
/**@}*/
/**
* @defgroup util Utilities
* Set of utilities
* @{
*/
extern int wrtd_version_is_valid(struct wrtd_node *dev);
extern const char *wrtd_strerror(int err);
extern void wrtd_ts_to_pico(struct wr_timestamp *ts, uint64_t *pico);
extern void wrtd_pico_to_ts(uint64_t *pico, struct wr_timestamp *ts);
extern void wrtd_ts_to_sec_pico(struct wr_timestamp *ts,
uint64_t *sec, uint64_t *pico);
extern void wrtd_sec_pico_to_ts(uint64_t sec, uint64_t pico,
struct wr_timestamp *ts);
/**@}*/
/**
* @defgroup log Logging
* Set of logging functions for input and output channels
* @{
*/
extern const char *wrtd_strlogging(enum wrtd_log_level lvl);
enum wrtd_log_level wrtd_strlogging_to_level(char *log);
extern void wrtd_strlogging_full(char *buf, uint32_t log_level);
extern int wrtd_log_read(struct trtl_hmq *hmq_log, struct wrtd_log_entry *log,
int count, int poll_timeout);
extern void wrtd_log_close(struct trtl_hmq *hmq);
extern struct trtl_hmq *wrtd_in_log_open(struct wrtd_node *dev, int input);
extern int wrtd_in_log_level_set(struct wrtd_node *dev, unsigned int input,
uint32_t log_level);
extern int wrtd_in_log_level_get(struct wrtd_node *dev, unsigned int input,
uint32_t *log_level);
extern int wrtd_out_log_level_set(struct wrtd_node *dev, unsigned int output,
uint32_t log_level);
extern int wrtd_out_log_level_get(struct wrtd_node *dev, unsigned int input,
uint32_t *log_level);
extern struct trtl_hmq *wrtd_out_log_open(struct wrtd_node *dev, int output);
/**@}*/
/**
* @file libwrtd-input.c
*/
/**
* @defgroup input Input Management
* Set of functions to handle input channels
* @{
*/
extern int wrtd_in_state_get(struct wrtd_node *dev, unsigned int input,
struct wrtd_input_state *state);
extern int wrtd_in_enable(struct wrtd_node *dev, unsigned int input, int enable);
extern int wrtd_in_trigger_assign(struct wrtd_node *dev, unsigned int input,
struct wrtd_trig_id *trig_id);
extern int wrtd_in_trigger_unassign(struct wrtd_node *dev, unsigned int input);
extern int wrtd_in_trigger_mode_set(struct wrtd_node *dev, unsigned int input,
enum wrtd_trigger_mode mode);
extern int wrtd_in_trigger_software(struct wrtd_node *dev,
struct wrtd_trigger_entry *trigger);
extern int wrtd_in_arm(struct wrtd_node *dev, unsigned int input, int armed);
extern int wrtd_in_dead_time_set(struct wrtd_node *dev, unsigned int input,
uint64_t dead_time_ps);
extern int wrtd_in_delay_set(struct wrtd_node *dev, unsigned int input,
uint64_t delay_ps);
extern int wrtd_in_timebase_offset_set(struct wrtd_node *dev,
unsigned int input, uint64_t offset);
extern int wrtd_in_counters_reset(struct wrtd_node *dev, unsigned int input);
extern int wrtd_in_seq_counter_set (struct wrtd_node *dev, unsigned int input,
unsigned int value);
extern int wrtd_in_is_enabled(struct wrtd_node *dev, unsigned int input,
unsigned int *enable);
extern int wrtd_in_is_armed(struct wrtd_node *dev, unsigned int input,
unsigned int *armed);
extern int wrtd_in_has_trigger(struct wrtd_node *dev, unsigned int input,
unsigned int *assigned);
extern int wrtd_in_ping(struct wrtd_node *dev);
extern int wrtd_in_base_time(struct wrtd_node *dev, struct wr_timestamp *ts);
extern int wrtd_in_version(struct wrtd_node *dev,
struct trtl_rt_version *version);
extern int wrtd_in_dead_time_get(struct wrtd_node *dev, unsigned int input,
uint64_t *dead_time_ps);
extern int wrtd_in_delay_get(struct wrtd_node *dev, unsigned int input,
uint64_t *delay_ps);
/**@}*/
/**
* @file libwrtd-output.c
*/
/**
* @defgroup output Output Management
* Set of functions to handle output channels
* @{
*/
extern int wrtd_out_state_get(struct wrtd_node *dev, unsigned int output,
struct wrtd_output_state *state);
extern int wrtd_out_enable(struct wrtd_node *dev, unsigned int output,
int enable);
extern int wrtd_out_trig_assign(struct wrtd_node *dev, unsigned int output,
struct wrtd_trigger_handle *handle,
struct wrtd_trig_id *trig,
struct wrtd_trig_id *condition);
extern int wrtd_out_trig_unassign(struct wrtd_node *dev,
struct wrtd_trigger_handle *handle);
extern int wrtd_out_trig_get_all (struct wrtd_node *dev, unsigned int output,
struct wrtd_output_trigger_state *triggers,
int max_count);
extern int wrtd_out_trig_state_get_by_index(struct wrtd_node *dev,
unsigned int index,
unsigned int output,
struct wrtd_output_trigger_state *trigger);
extern int wrtd_out_trig_state_get_by_id(struct wrtd_node *dev,
unsigned int output,
struct wrtd_trig_id *id,
struct wrtd_output_trigger_state *trigger);
extern int wrtd_out_trig_state_get_by_handle(struct wrtd_node *dev,
struct wrtd_trigger_handle *handle,
struct wrtd_output_trigger_state *state);
extern int wrtd_out_trig_delay_set(struct wrtd_node *dev,
struct wrtd_trigger_handle *handle,
uint64_t delay_ps);
extern int wrtd_out_dead_time_set(struct wrtd_node *dev, unsigned int output,
uint64_t dead_time_ps);
extern int wrtd_out_pulse_width_set(struct wrtd_node *dev, unsigned int output,
uint64_t pulse_width_ps);
extern int wrtd_out_trig_enable(struct wrtd_node *dev,
struct wrtd_trigger_handle *handle, int enable);
extern int wrtd_out_ping(struct wrtd_node *dev);
extern int wrtd_out_base_time(struct wrtd_node *dev, struct wr_timestamp *ts);
extern int wrtd_out_version(struct wrtd_node *dev,
struct trtl_rt_version *version);
extern int wrtd_out_trigger_mode_set(struct wrtd_node *dev,
unsigned int output,
enum wrtd_trigger_mode mode);
extern int wrtd_out_trig_condition_delay_set(struct wrtd_node *dev,
struct wrtd_trigger_handle *handle,
uint64_t delay_ps);
extern int wrtd_out_arm(struct wrtd_node *dev, unsigned int input, int armed);
extern int wrtd_out_counters_reset(struct wrtd_node *dev, unsigned int output);
extern int wrtd_out_check_triggered(struct wrtd_node *dev, unsigned int output);
extern int wrtd_out_is_enabled(struct wrtd_node *dev, unsigned int output,
unsigned int *enable);
extern int wrtd_out_is_armed(struct wrtd_node *dev, unsigned int output,
unsigned int *armed);
extern int wrtd_out_has_trigger(struct wrtd_node *dev, unsigned int output,
struct wrtd_trig_id *id, unsigned int *assigned);
/**@}*/
#ifdef __cplusplus
};
#endif
#endif
list-master/lib/readme.md 0000664 0000000 0000000 00000007446 13156247624 0015674 0 ustar 00root root 0000000 0000000 Library Overview {#mainpage}
================
This is the **WRTD** library documentation. Here you can find all
the information about the *White-Rabbit Trigger-Distribution* API and the main
library behavior that you need to be aware of.
If you are reading this from the doxygen documentation, then you can find
the API documentation in the usual Doxygen places. Otherwise, you can get
the API documentation directly from the source code that you can find in
the *lib* directory.
In this document we are going to provides you some clues to understand how
to use the library API.
This library is completely base on the *White-Rabbit Node-Core* library.
It uses all its features to establish the communication between the
Trigger Distribution Real Time applications. This library hides the knowledge
about the conventions (protocol) used between the Host and the Real Time
applications and it exposes a simple API for the interaction.
While reading any documentation we suggest you to read the dictionary to avoid
misinterpretation.
Overview
========
The White-Rabbit Trigger-Distribution is a system that allow its users to detect
a trigger (pulse), propagate it over the White-Rabbit network and reproduce it
on a remote machine. This library is in charge to ease the configuration of this
system. The system is based on the White-Rabbit Node-Core. There are two cores
running separately two Real Time applications: one to manage the input,
one to manage the output.
+--------------Trigger-Distribution-System-------------+
| RealTime App - - - - - - - - - RealTime App |
-\ | +-------+ ( ) +--------+ | /-
|--------|->| INPUT |--->( WhiteRabbit Network )--->| OUTPUT |--|------->|
-/ PULSE | +-------+ ( ) +--------+ | PULSE \-
| - - - - - - - - - |
+------------------------------------------------------+
Initialization
==============
To be able to use this library the first thing to do is to initialize a library
instance using wrtd_init(); form this point on you are able to use the
library API. Of course, when you finished to use the library you have to
remove this instance using wrtd_exit().
At the beginning, all communication channels are close, so before start to
communicate with the Real Time application you have to open your communication
channel. Then, close it when you have done.
Logging
=======
The WRTD Real Time applications are able to provide some logging information
about the things happening on the FPGA. This interface is read only, so
you can only read logging messages. There are only two configuration parameters:
one for the *logging level*; the other one to set the exclusivity access to the
logging interface. When the logging interface is shared, then also other users
are allowed to get the same messages.
Input
=====
The *input* Real Time application and the associated part of library manages
the detection of the incoming pulse and their correct propagation over the
white-rabbit network as trigger event.
The library allows the user to fully configure the input parameter and to get
the current status of Real Time application but also to get information about
the triggers associated to the input channels. Go directly to the API for the
list of parameters that you can set.
Output
======
The *input* Real Time application and the associated part of library manages
the pluse generation and their correct reception from the white-rabbit
network as trigger event.
The library allows the user to fully configure the output parameter and to get
the current status of Real Time application but also to get information about
the trigger associated to the output channesl. Go directly to the API for the
list of parameters that you can set.
list-master/mock-turtle-sw/ 0000775 0000000 0000000 00000000000 13156247624 0016231 5 ustar 00root root 0000000 0000000 list-master/rt/ 0000775 0000000 0000000 00000000000 13156247624 0013761 5 ustar 00root root 0000000 0000000 list-master/rt/common/ 0000775 0000000 0000000 00000000000 13156247624 0015251 5 ustar 00root root 0000000 0000000 list-master/rt/common/loop-queue.c 0000664 0000000 0000000 00000003135 13156247624 0017512 0 ustar 00root root 0000000 0000000 /*
* Shared Memory-based Loopback queue for internal trigger distribution
*
* Copyright (C) 2013-2014 CERN (www.cern.ch)
* Author: Tomasz Wlostowski
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*/
#include "mockturtle-rt.h"
#include "wrtd-common.h"
#define LOOP_QUEUE_SIZE 16
static SMEM int head, tail, count;
static SMEM struct wrtd_trigger_entry buf[16];
void loop_queue_init()
{
head = 0;
tail = 0;
count = 0;
}
void loop_queue_push(struct wrtd_trig_id *id, uint32_t seq,
struct wr_timestamp *ts)
{
if (count >= LOOP_QUEUE_SIZE)
return;
buf[head].id = *id;
buf[head].seq = seq;
buf[head].ts = *ts;
smem_atomic_add(&head, 1);
if (head >= LOOP_QUEUE_SIZE)
head = 0;
smem_atomic_add(&count, 1);
}
volatile struct wrtd_trigger_entry *loop_queue_pop(void)
{
volatile struct wrtd_trigger_entry *rv;
if (count == 0)
return NULL; /* No entry */
rv = &buf[tail];
smem_atomic_add(&tail, 1);
if(tail >= LOOP_QUEUE_SIZE)
tail = 0;
smem_atomic_sub(&count, 1);
return rv;
}
list-master/rt/common/loop-queue.h 0000664 0000000 0000000 00000002153 13156247624 0017516 0 ustar 00root root 0000000 0000000 /*
* Shared Memory-based Loopback queue for internal trigger distribution
*
* Copyright (C) 2013-2014 CERN (www.cern.ch)
* Author: Tomasz Wlostowski
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*/
#ifndef __LOOP_QUEUE_H
#define __LOOP_QUEUE_H
#include "mockturtle-rt.h"
#include "wrtd-common.h"
#define LOOP_QUEUE_SIZE 16
void loop_queue_init();
void loop_queue_push(struct wrtd_trig_id *id, uint32_t seq,
struct wr_timestamp *ts);
volatile struct wrtd_trigger_entry *loop_queue_pop(void);
#endif
list-master/rt/fd/ 0000775 0000000 0000000 00000000000 13156247624 0014352 5 ustar 00root root 0000000 0000000 list-master/rt/fd/Makefile 0000664 0000000 0000000 00000000755 13156247624 0016021 0 ustar 00root root 0000000 0000000 -include Makefile.specific
OBJS := wrtd-rt-fd.o
OBJS += ../common/loop-queue.o
OUTPUT = wrtd-rt-fd
TRTL = ../../mock-turtle-sw
EXTRA_CFLAGS += -I../../include
EXTRA_CFLAGS += -I../common
EXTRA_CFLAGS += -DLIBRT_ERROR
#EXTRA_CFLAGS += -DLIBRT_DEBUG
#EXTRA_CFLAGS += -DRTDEBUG
MOCKTURTLE_PRINTF_ENABLE := 0
LIBMOCKTURTLE_ENABLE := 1
LIBMOCKTURTLE_VARIABLE_ENABLE := 1
LIBMOCKTURTLE_STRUCT_ENABLE := 1
LIBMOCKTURTLE_DEBUG_ENABLE := 0
LIBMOCKTURTLE_32BIT_ALIGN := 1
include $(TRTL)/rt/Makefile
list-master/rt/fd/hw/ 0000775 0000000 0000000 00000000000 13156247624 0014770 5 ustar 00root root 0000000 0000000 list-master/rt/fd/hw/fd_channel_regs.h 0000664 0000000 0000000 00000011727 13156247624 0020252 0 ustar 00root root 0000000 0000000 /*
Register definitions for slave core: Fine Delay Channel WB Slave
* File : fd_channel_regs.h
* Author : auto-generated by wbgen2 from fd_channel_wishbone_slave.wb
* Created : Fri Feb 15 12:07:17 2013
* Standard : ANSI C
THIS FILE WAS GENERATED BY wbgen2 FROM SOURCE FILE fd_channel_wishbone_slave.wb
DO NOT HAND-EDIT UNLESS IT'S ABSOLUTELY NECESSARY!
*/
#ifndef __WBGEN2_REGDEFS_FD_CHANNEL_WISHBONE_SLAVE_WB
#define __WBGEN2_REGDEFS_FD_CHANNEL_WISHBONE_SLAVE_WB
#include
#if defined( __GNUC__)
#define PACKED __attribute__ ((packed))
#else
#error "Unsupported compiler?"
#endif
#ifndef __WBGEN2_MACROS_DEFINED__
#define __WBGEN2_MACROS_DEFINED__
#define WBGEN2_GEN_MASK(offset, size) (((1<<(size))-1) << (offset))
#define WBGEN2_GEN_WRITE(value, offset, size) (((value) & ((1<<(size))-1)) << (offset))
#define WBGEN2_GEN_READ(reg, offset, size) (((reg) >> (offset)) & ((1<<(size))-1))
#define WBGEN2_SIGN_EXTEND(value, bits) (((value) & (1<