Commit 667a0a09 authored by Michel Arruat's avatar Michel Arruat
Browse files

Merge branch 'devmichel'

parents 28743ec7 747bf4a2
......@@ -9,19 +9,14 @@
*TAGS
Module.symvers
modules.order
*.S
*.bin
*.elf
*.S
*.gdb
GPATH
cscope*
tools/fiptestbed/fiptestbed
tools/fiptestsurvey/fiptestsv
*.new
*.asm
*.specific
local_deliver
*.txt
tags*
tools/test
doc/doxy-masterfip
[submodule "mockturtle"]
path = mockturtle
url = git://ohwr.org/hdl-core-lib/mock-turtle/mock-turtle-sw.git
[submodule "tools/extest"]
path = tools/extest
url = ssh://git@gitlab.cern.ch:7999/cohtdrivers/extest.git
[submodule "tools/ual"]
path = tools/ual
url = ssh://git@gitlab.cern.ch:7999/cohtdrivers/ual.git
[submodule "mockturtle"]
path = mockturtle
url = ssh://git@gitlab.cern.ch:7999/coht/mockturtle.git
This diff is collapsed.
GNU LESSER GENERAL PUBLIC LICENSE
Version 3, 29 June 2007
Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
This version of the GNU Lesser General Public License incorporates
the terms and conditions of version 3 of the GNU General Public
License, supplemented by the additional permissions listed below.
0. Additional Definitions.
As used herein, "this License" refers to version 3 of the GNU Lesser
General Public License, and the "GNU GPL" refers to version 3 of the GNU
General Public License.
"The Library" refers to a covered work governed by this License,
other than an Application or a Combined Work as defined below.
An "Application" is any work that makes use of an interface provided
by the Library, but which is not otherwise based on the Library.
Defining a subclass of a class defined by the Library is deemed a mode
of using an interface provided by the Library.
A "Combined Work" is a work produced by combining or linking an
Application with the Library. The particular version of the Library
with which the Combined Work was made is also called the "Linked
Version".
The "Minimal Corresponding Source" for a Combined Work means the
Corresponding Source for the Combined Work, excluding any source code
for portions of the Combined Work that, considered in isolation, are
based on the Application, and not on the Linked Version.
The "Corresponding Application Code" for a Combined Work means the
object code and/or source code for the Application, including any data
and utility programs needed for reproducing the Combined Work from the
Application, but excluding the System Libraries of the Combined Work.
1. Exception to Section 3 of the GNU GPL.
You may convey a covered work under sections 3 and 4 of this License
without being bound by section 3 of the GNU GPL.
2. Conveying Modified Versions.
If you modify a copy of the Library, and, in your modifications, a
facility refers to a function or data to be supplied by an Application
that uses the facility (other than as an argument passed when the
facility is invoked), then you may convey a copy of the modified
version:
a) under this License, provided that you make a good faith effort to
ensure that, in the event an Application does not supply the
function or data, the facility still operates, and performs
whatever part of its purpose remains meaningful, or
b) under the GNU GPL, with none of the additional permissions of
this License applicable to that copy.
3. Object Code Incorporating Material from Library Header Files.
The object code form of an Application may incorporate material from
a header file that is part of the Library. You may convey such object
code under terms of your choice, provided that, if the incorporated
material is not limited to numerical parameters, data structure
layouts and accessors, or small macros, inline functions and templates
(ten or fewer lines in length), you do both of the following:
a) Give prominent notice with each copy of the object code that the
Library is used in it and that the Library and its use are
covered by this License.
b) Accompany the object code with a copy of the GNU GPL and this license
document.
4. Combined Works.
You may convey a Combined Work under terms of your choice that,
taken together, effectively do not restrict modification of the
portions of the Library contained in the Combined Work and reverse
engineering for debugging such modifications, if you also do each of
the following:
a) Give prominent notice with each copy of the Combined Work that
the Library is used in it and that the Library and its use are
covered by this License.
b) Accompany the Combined Work with a copy of the GNU GPL and this license
document.
c) For a Combined Work that displays copyright notices during
execution, include the copyright notice for the Library among
these notices, as well as a reference directing the user to the
copies of the GNU GPL and this license document.
d) Do one of the following:
0) Convey the Minimal Corresponding Source under the terms of this
License, and the Corresponding Application Code in a form
suitable for, and under terms that permit, the user to
recombine or relink the Application with a modified version of
the Linked Version to produce a modified Combined Work, in the
manner specified by section 6 of the GNU GPL for conveying
Corresponding Source.
1) Use a suitable shared library mechanism for linking with the
Library. A suitable mechanism is one that (a) uses at run time
a copy of the Library already present on the user's computer
system, and (b) will operate properly with a modified version
of the Library that is interface-compatible with the Linked
Version.
e) Provide Installation Information, but only if you would otherwise
be required to provide such information under section 6 of the
GNU GPL, and only to the extent that such information is
necessary to install and execute a modified version of the
Combined Work produced by recombining or relinking the
Application with a modified version of the Linked Version. (If
you use option 4d0, the Installation Information must accompany
the Minimal Corresponding Source and Corresponding Application
Code. If you use option 4d1, you must provide the Installation
Information in the manner specified by section 6 of the GNU GPL
for conveying Corresponding Source.)
5. Combined Libraries.
You may place library facilities that are a work based on the
Library side by side in a single library together with other library
facilities that are not Applications and are not covered by this
License, and convey such a combined library under terms of your
choice, if you do both of the following:
a) Accompany the combined library with a copy of the same work based
on the Library, uncombined with any other library facilities,
conveyed under the terms of this License.
b) Give prominent notice with the combined library that part of it
is a work based on the Library, and explaining where to find the
accompanying uncombined form of the same work.
6. Revised Versions of the GNU Lesser General Public License.
The Free Software Foundation may publish revised and/or new versions
of the GNU Lesser General Public License from time to time. Such new
versions will be similar in spirit to the present version, but may
differ in detail to address new problems or concerns.
Each version is given a distinguishing version number. If the
Library as you received it specifies that a certain numbered version
of the GNU Lesser General Public License "or any later version"
applies to it, you have the option of following the terms and
conditions either of that published version or of any later version
published by the Free Software Foundation. If the Library as you
received it does not specify a version number of the GNU Lesser
General Public License, you may choose any version of the GNU Lesser
General Public License ever published by the Free Software Foundation.
If the Library as you received it specifies that a proxy can decide
whether future versions of the GNU Lesser General Public License shall
apply, that proxy's public statement of acceptance of any version is
permanent authorization for you to choose that version for the
Library.
# include parent_common.mk for buildsystem's defines
# use absolute path for REPO_PARENT
CURDIR:=$(shell /bin/pwd)
REPO_PARENT ?= $(CURDIR)
export REPO_PARENT
# 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
-include $(REPO_PARENT)/parent_common.mk
.PHONY: all clean modules install modules_install clean_all local_deliver
.PHONY: gitmodules prereq prereq_install prereq_install_warn prereq_clean
TRTL ?= mockturtle/software
TRTL ?= mockturtle
all: $(TRTL) lib rt tools
DIRS = $(TRTL) lib rt tools
VERS := dev
DEST_DIR = /acc/local/L866/drv/masterfip/$(VERS)
all clean modules install modules_install:
for d in $(DIRS); do $(MAKE) -C $$d $@ || exit 1; done
local_deliver:
cp -p lib/libmasterfip.h include/masterfip-common.h \
lib/libmasterfip-diag.h local_deliver/include/masterfip
cp -p lib/libmasterfip.a local_deliver/lib
cp -p rt/ba/masterfip-rt-ba.bin local_deliver/rt/ba
cp -p rt/cmd/masterfip-rt-cmd.bin local_deliver/rt/cmd
deliver:
dsc_install lib/libmasterfip.h include/masterfip-common.h \
lib/libmasterfip-diag.h $(DEST_DIR)/include/masterfip
dsc_install lib/libmasterfip.a $(DEST_DIR)/lib
dsc_install rt/ba/masterfip-rt-ba.bin rt/cmd/masterfip-rt-cmd.bin \
/acc/local/share/firmware/fmc-masterfip/$(VERS)/mturtle-rtapp/
.PHONY: all clean modules install modules_install $(DIRS)
.PHONY: gitmodules prereq prereq_install prereq_install_warn prereq_clean
all clean modules : $(DIRS)
clean: TARGET = clean
modules: TARGET = modules
install: TARGET = install
modules_install: TARGET = modules_install
$(DIRS):
$(MAKE) -C $@ $(TARGET)
INSTALL_DIRS = lib rt tools
install modules_install : $(INSTALL_DIRS)
$(INSTALL_DIRS):
$(MAKE) -C $@ $(TARGET)
/*
* Copyright (C) 2016 CERN (www.cern.ch)
* Authors: Michel Arruat <michel.arruat@cern.ch>
* License: GPL v3
* Copyright (C) 2016-2017 CERN (www.cern.ch)
* Author: Michel Arruat <michel.arruat@cern.ch>
*
* Common definitions used by RT code and MASTERFIP lib
* SPDX-License-Identifier: LGPL-3.0-or-later
*/
#ifndef __MASTERFIP_COMMON_PRIV_H
......
/*
* Copyright (C) 2016 CERN (www.cern.ch)
* Authors: Michel Arruat <michel.arruat@cern.ch>
* License: GPL v3
* Copyright (C) 2016-2017 CERN (www.cern.ch)
* Author: Michel Arruat <michel.arruat@cern.ch>
*
* Common definitions used by RT code and MASTERFIP lib
* SPDX-License-Identifier: LGPL-3.0-or-later
*/
#ifndef __MASTERFIP_COMMON_H
......
......@@ -2,48 +2,63 @@
# specific Makefile code that you want to run before this. For example,
# build a particular environment.
-include Makefile.specific
# define REPO_PARENT to get build environment
#REPO_PARENT?=..
-include $(REPO_PARENT)/parent_common.mk
-include ../version.mk
TRTL ?= ../mockturtle
TRTL ?= ../mockturtle/software
DBG_LIB:=
LIB = libmasterfip.a
LOBJ := libmasterfip-dev.o
LOBJ += libmasterfip-errors.o
LOBJ += libmasterfip-ba-config.o
LOBJ += libmasterfip-macrocycle-config.o
LOBJ += libmasterfip-macrocycle-actions.o
LOBJ += libmasterfip-ba-runtime-actions.o
LOBJ += libmasterfip-ba-rules.o
LOBJ += libmasterfip-diag.o
LOBJ += libmasterfip-irq.o
LOBJ += libmasterfip-util.o
#CFLAGS += -Wall -ggdb -O2 -I. -I../include -I$(TRTL)/include -I$(TRTL)/lib $(EXTRACFLAGS)
CFLAGS += -Wall -ggdb $(DBG_LIB) -I. -I../include -I$(TRTL)/lib -I$(TRTL)/include $(EXTRACFLAGS)
CFLAGS += -DMFIP_GIT_VERSION=$(MFIP_GIT_VERSION)
CFLAGS += -DMFIP_LIB_VERSION=$(MFIP_LIB_VERSION)
CFLAGS += -DMFIP_RT_VERSION=$(MFIP_RT_VERSION)
CFLAGS += -DMFIP_FPGA_VERSION=$(MFIP_FPGA_VERSION)
#LDLIBS += -L. -L$(TRTL)/lib -lwrtd
LIB = libmasterfip.a
LOBJS := libmasterfip-dev.o
LOBJS += libmasterfip-errors.o
LOBJS += libmasterfip-ba-config.o
LOBJS += libmasterfip-macrocycle-config.o
LOBJS += libmasterfip-macrocycle-actions.o
LOBJS += libmasterfip-ba-runtime-actions.o
LOBJS += libmasterfip-ba-rules.o
LOBJS += libmasterfip-diag.o
LOBJS += libmasterfip-irq.o
LOBJS += libmasterfip-util.o
SRCS := libmasterfip-errors.c
SRCS += libmasterfip-ba-config.c
SRCS += libmasterfip-macrocycle-config.c
SRCS += libmasterfip-macrocycle-actions.c
SRCS += libmasterfip-ba-runtime-actions.c
SRCS += libmasterfip-ba-rules.c
SRCS += libmasterfip-diag.c
SRCS += libmasterfip-irq.c
SRCS += libmasterfip-util.c
modules all: $(LIB)
clean:
$(RM) *.{o,so,a}
cleanall:
$(RM) *.{$(ALL_CPUS_COMMAS)}.{o,so,a}
%: %.c $(LIB)
$(CC) $(CFLAGS) $(LDFLAGS) $*.c $(LDLIBS) -o $@
$(CC) $(CFLAGS) $*.c $(LDFLAGS) -o $@
$(LIB): $(LOBJ)
$(LIB): $(LOBJS)
ar r $@ $^
clean:
rm -f $(LIB) .depend *.o *~
.depend: Makefile $(wildcard *.c *.h)
$(CC) $(CFLAGS) -M $(LOBJ:.o=.c) -o $@
$(CC) $(CFLAGS) -M $(LOBJS.o=.c) -o $@
install modules_install:
# use default instalation rule for libs
install: install_libs_global
-include .depend
# use default instalation rule for libs
install: install_prog_global
/*
* Copyright (C) 2016 CERN (www.cern.ch)
* Authors: Michel Arruat <michel.arruat@cern.ch>
* License: GPL v3
* Copyright (C) 2016-2017 CERN (www.cern.ch)
* Author: Michel Arruat <michel.arruat@cern.ch>
*
* Interface to the CERN MasterFIP
* SPDX-License-Identifier: LGPL-3.0-or-later
*/
#include <stdint.h>
......@@ -58,7 +57,7 @@ int mstrfip_version_get(struct mstrfip_dev *dev, struct mstrfip_version *vers)
/* Send the message and get answer */
err = trtl_hmq_send_and_receive_sync(mstrfip->hmq_cpu1_cmd,
MSTRFIP_HMQ_O_RESP_CPU1_CMD, &msg, MSTRFIP_DEFAULT_TIMEOUT);
memset(vers, sizeof(struct mstrfip_version), 0);
memset(vers, 0, sizeof(struct mstrfip_version));
if (err < 0)
return -1;
/* fill in vers output parameter */
......@@ -77,6 +76,7 @@ static int mstrfip_check_version_consistency(struct mstrfip_desc *mstrfip)
{
int res;
struct mstrfip_version *vers = &mstrfip->vers;
uint32_t msk;
res = mstrfip_version_get((struct mstrfip_dev *)mstrfip, vers);
if (res) {
......@@ -84,7 +84,7 @@ static int mstrfip_check_version_consistency(struct mstrfip_desc *mstrfip)
- MSTRFIP_ERROR_CODE_OFFSET],
MSTRFIP_DYNAMIC_ERR_MSG_SZ,
"%s() reading version from HW failed preventing "
"from checking if the HW is proplerly configured: %s",
"from checking if the HW runs the right bitstream: %s",
__func__, strerror(errno));
mstrfip->current_error = MSTRFIP_INVALID_HW_VERS;
return -1;
......@@ -102,9 +102,13 @@ static int mstrfip_check_version_consistency(struct mstrfip_desc *mstrfip)
mstrfip->current_error = MSTRFIP_INVALID_HW_VERS;
return -1;
}
/* check fpga and RT app version */
if ( (vers->rt_version != mstrfip->ref_rt_version) ||
(vers->fpga_version != mstrfip->ref_fpga_version) ) {
/*
* check RT and fpga version against expected versions
* patch number is ignored
*/
msk = 0xFFFF00; /* ignore patch number */
if ( ((vers->rt_version & msk) != (mstrfip->ref_rt_version & msk)) ||
((vers->fpga_version & msk) != (mstrfip->ref_fpga_version &msk)) ) {
snprintf(mstrfip_errors[MSTRFIP_INVALID_HW_VERS
- MSTRFIP_ERROR_CODE_OFFSET],
MSTRFIP_DYNAMIC_ERR_MSG_SZ,
......@@ -142,7 +146,9 @@ int mstrfip_rtapp_reset(struct mstrfip_dev *dev)
/* check HW version */
err = mstrfip_check_version_consistency(mstrfip);
return mstrfip->current_error;
if (err)
errno = mstrfip->current_error;
return err;
}
/**
......@@ -159,8 +165,10 @@ int mstrfip_hw_response_time_get(struct mstrfip_dev *dev, int agent_count,
struct mstrfip_desc *mstrfip = (struct mstrfip_desc *)dev;
int i;
if (mstrfip->current_error)
return mstrfip->current_error;
if (mstrfip->current_error) {
errno = mstrfip->current_error;
return -1;
}
if (mstrfip->ba.seg.present_nb == 0) {
/*
......@@ -192,8 +200,10 @@ int mstrfip_hw_speed_get(struct mstrfip_dev *dev, enum mstrfip_bitrate *bitrate)
struct mstrfip_hw_speed_trtlmsg *hw_speed;
int err;
if (mstrfip->current_error)
return mstrfip->current_error;
if (mstrfip->current_error) {
errno = mstrfip->current_error;
return -1;
}
/*
* Sequence: send a sync message to get the HW configuration bitrate
......@@ -230,8 +240,10 @@ int mstrfip_hw_cfg_set(struct mstrfip_dev *dev, struct mstrfip_hw_cfg *cfg)
int err;
uint32_t tr_ns;
if (mstrfip->current_error)
return mstrfip->current_error;
if (mstrfip->current_error) {
errno = mstrfip->current_error;
return -1;
}
if (mstrfip->ba.bitrate == MSTRFIP_BITRATE_UNDEFINED) {
err = mstrfip_hw_speed_get(dev, &mstrfip->ba.bitrate);
......
/*
* Copyright (C) 2016 CERN (www.cern.ch)
* License: GPL v3
* Copyright (C) 2016-2017 CERN (www.cern.ch)
* Author: Michel Arruat <michel.arruat@cern.ch>
*
* SPDX-License-Identifier: LGPL-3.0-or-later
*/
#include <stdlib.h>
......
/*
* Copyright (C) 2016 CERN (www.cern.ch)
* Authors: Michel Arruat <michel.arruat@cern.ch>
* License: GPL v3
* Copyright (C) 2016-2017 CERN (www.cern.ch)
* Author: Michel Arruat <michel.arruat@cern.ch>
*
* Interface to the CERN MasterFIP
* SPDX-License-Identifier: LGPL-3.0-or-later
*/
#include <stdint.h>
......
/*
* Copyright (C) 2016 CERN (www.cern.ch)
* License: GPL v3
* Copyright (C) 2016-2017 CERN (www.cern.ch)
* Author: Michel Arruat <michel.arruat@cern.ch>
*
* SPDX-License-Identifier: LGPL-3.0-or-later
*/
#include <stdlib.h>
......
/*
* Copyright (C) 2016 CERN (www.cern.ch)
* License: GPL v3
* Copyright (C) 2016-2017 CERN (www.cern.ch)
* Author: Michel Arruat <michel.arruat@cern.ch>
*
* SPDX-License-Identifier: LGPL-3.0-or-later
*/
#include <stdint.h>
......
/*
* Copyright (C) 2016 CERN (www.cern.ch)
* Authors: Michel Arruat <michel.arruat@cern.ch>
* License: GPL v3
* Copyright (C) 2016-2017 CERN (www.cern.ch)
* Author: Michel Arruat <michel.arruat@cern.ch>
*
* Interface to the CERN MasterFIP
* SPDX-License-Identifier: LGPL-3.0-or-later
*/
#ifndef __LIB_MASTERFIP_DIAG_H
......
/*
* Copyright (C) 2016-2017 CERN (www.cern.ch)
* Author: Michel Arruat <michel.arruat@cern.ch>
*
* SPDX-License-Identifier: LGPL-3.0-or-later
*/
#include <libmockturtle.h>
#include "libmasterfip-priv.h"
......@@ -35,7 +42,6 @@ void mstrfip_error_init()
int i;
int static_err_count = sizeof(mstrfip_static_errors) / sizeof(char *);
int dynamic_err_count;
if (mstrfip_error_init_flg)
return;
......@@ -43,8 +49,6 @@ void mstrfip_error_init()
for (i = 0; i < static_err_count; ++i) {
mstrfip_errors[i] = mstrfip_static_errors[i];
}
dynamic_err_count = __MSTRFIP_MAX_ERROR_CODE -
MSTRFIP_ERROR_CODE_OFFSET - static_err_count;
for (; i < __MSTRFIP_MAX_ERROR_CODE - MSTRFIP_ERROR_CODE_OFFSET; ++i) {
mstrfip_errors[i] = calloc(MSTRFIP_DYNAMIC_ERR_MSG_SZ, (size_t)1);
mstrfip_errors[i][0] = '\0'; /* useless with calloc !!! */
......
/*
* Copyright (C) 2016 CERN (www.cern.ch)
* Authors: Michel Arruat <michel.arruat@cern.ch>
* License: GPL v3
* Copyright (C) 2016-2017 CERN (www.cern.ch)
* Author: Michel Arruat <michel.arruat@cern.ch>
*
* Interface to the CERN MasterFIP
* SPDX-License-Identifier: LGPL-3.0-or-later
*/
#include <stdint.h>
......@@ -91,6 +90,24 @@ static void mstrfip_get_irq_entry(struct mstrfip_desc *mstrfip,
irq->irq_count = (*irq_entry)->irq_count;
}
static void mstrfip_purge_trtl_hmq(struct mstrfip_desc *mstrfip)
{
struct trtl_msg trtlmsg;
int i, n;
/*
* try to read a maximum of trtl messages in once: we don't know how
* many messages are accumulated in the driver, but we can't read more
* than the remaining space in the msglist
*/
for (i = 0; i < MSTRFIP_HMQ_ACQ_SLOT_COUNT; ++i) {
do {
n = trtl_hmq_receive_n(mstrfip->hmq_acq_slot[i],
&trtlmsg, 1);
} while(n > 0);
}
}
static int mstrfip_read_trtlmsg(struct mstrfip_desc *mstrfip, int mq_slot,
struct mstrfip_trtl_buf *trtl)
{
......@@ -307,7 +324,7 @@ static struct mstrfip_trtl_buf*
static void* mstrfip_irq_run(void *arg)
{
struct mstrfip_desc *mstrfip = (struct mstrfip_desc *)arg;
int nevt, evt, mq_slot, res, timeout;
int nevt, evt, mq_slot, res, timeout, start_flg;
struct pollfd p[5]; /* poll all the acq MQ slots */
struct mstrfip_irq irq = {0};
struct mstrfip_irq_entry_desc *irq_entry = NULL;
......@@ -331,6 +348,13 @@ static void* mstrfip_irq_run(void *arg)
&mstrfip->ba.mcycle->diag.trtl;
mstrfip->ba.irq_run = 1;
/*
* purge mock-turtle queue in case of remaining messages from previous
* macro-cycle. This may happen when application switch dynamically
* macro-cycle.
*/
mstrfip_purge_trtl_hmq(mstrfip);
/*
* poll timeout = 10 % more than macrocycle. Add + 1ms for very short
* macrocycle less than 10ms to be sure to geta number bigger than
......@@ -338,14 +362,24 @@ static void* mstrfip_irq_run(void *arg)
* computation)
*/
timeout = (int)(1.1 * (mstrfip->ba.mcycle->cycle_ustime / 1000)) + 1;
start_flg = 1;
while(mstrfip->ba.irq_run) {
/*
* man 7 pthreads: according to POSIX.1-2001 and/or POSIX.1-2008