Commit 79fe79d8 authored by Lucas Russo's avatar Lucas Russo

all: initial commit

parents
*~
*.swp
*.orig
*.bak
*.o
*.d
dev_mngr
dev_io
valgrind_report.txt
# This file is NOT licensed under the GPLv3, which is the license for the rest
# of YouCompleteMe.
#
# Here's the license text for this file:
#
# This is free and unencumbered software released into the public domain.
#
# Anyone is free to copy, modify, publish, use, compile, sell, or
# distribute this software, either in source code form or as a compiled
# binary, for any purpose, commercial or non-commercial, and by any
# means.
#
# In jurisdictions that recognize copyright laws, the author or authors
# of this software dedicate any and all copyright interest in the
# software to the public domain. We make this dedication for the benefit
# of the public at large and to the detriment of our heirs and
# successors. We intend this dedication to be an overt act of
# relinquishment in perpetuity of all present and future rights to this
# software under copyright law.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
# IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
# OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
# ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
# OTHER DEALINGS IN THE SOFTWARE.
#
# For more information, please refer to <http://unlicense.org/>
import os
import ycm_core
# These are the compilation flags that will be used in case there's no
# compilation database set (by default, one is not set).
# CHANGE THIS LIST OF FLAGS. YES, THIS IS THE DROID YOU HAVE BEEN LOOKING FOR.
flags = [
'-Wall',
'-Wextra',
'-Werror',
'-Wno-long-long',
'-fexceptions',
# THIS IS IMPORTANT! Without a "-std=<something>" flag, clang won't know which
# language to use when compiling headers. So it will guess. Badly. So C++
# headers will be compiled as C headers. You don't want that so ALWAYS specify
# a "-std=<something>".
# For a C project, you would set this to something like 'c99' instead of
# 'c++11'.
'-std=gnuc99',
# ...and the same thing goes for the magic -x option which specifies the
# language that the files to be compiled are written in. This is mostly
# relevant for c++ headers.
# For a C project, you would set this to 'c' instead of 'c++'.
'-x',
'c',
'-isystem',
'../BoostParts',
# This path will only work on OS X, but extra paths that don't exist are not
# harmful
'-isystem',
'../llvm/include',
'-isystem',
'../llvm/tools/clang/include',
'-I',
'.',
'-I',
'./ClangCompleter',
'-isystem',
'./tests/gmock/gtest',
'-isystem',
'./tests/gmock/gtest/include',
'-isystem',
'./tests/gmock',
'-isystem',
'./tests/gmock/include',
'-isystem',
'/usr/include',
'-isystem',
'/usr/local/include',
'-I',
'hal/include',
'-I',
'hal/dev_mngr',
'-I',
'hal/dev_io',
'-I',
'hal/debug',
'-I',
'hal/hal_utils',
'-I',
'hal/ll_io',
'-I',
'hal/ll_io/ops',
'-I',
'hal/sdb',
'-I',
'hal/sm_io',
'-I',
'hal/sm_io/modules',
'-I',
'hal/sm_io/modules/fmc130m_4ch',
'-I',
'hal/msg',
'-I',
'hal/msg/smio_thsafe_ops',
'-I',
'hal/msg/exp_ops',
'-I',
'kernel/include/pcie',
'-g',
'-DDBE_DEBUG=1',
'-lzmq',
'-lczmq',
'-lmdp',
]
# Set this to the absolute path to the folder (NOT the file!) containing the
# compile_commands.json file to use that instead of 'flags'. See here for
# more details: http://clang.llvm.org/docs/JSONCompilationDatabase.html
#
# Most projects will NOT need to set this to anything; you can just change the
# 'flags' list of compilation flags. Notice that YCM itself uses that approach.
compilation_database_folder = ''
if os.path.exists( compilation_database_folder ):
database = ycm_core.CompilationDatabase( compilation_database_folder )
else:
database = None
SOURCE_EXTENSIONS = [ '.cpp', '.cxx', '.cc', '.c', '.m', '.mm' ]
def DirectoryOfThisScript():
return os.path.dirname( os.path.abspath( __file__ ) )
def MakeRelativePathsInFlagsAbsolute( flags, working_directory ):
if not working_directory:
return list( flags )
new_flags = []
make_next_absolute = False
path_flags = [ '-isystem', '-I', '-iquote', '--sysroot=' ]
for flag in flags:
new_flag = flag
if make_next_absolute:
make_next_absolute = False
if not flag.startswith( '/' ):
new_flag = os.path.join( working_directory, flag )
for path_flag in path_flags:
if flag == path_flag:
make_next_absolute = True
break
if flag.startswith( path_flag ):
path = flag[ len( path_flag ): ]
new_flag = path_flag + os.path.join( working_directory, path )
break
if new_flag:
new_flags.append( new_flag )
return new_flags
def IsHeaderFile( filename ):
extension = os.path.splitext( filename )[ 1 ]
return extension in [ '.h', '.hxx', '.hpp', '.hh' ]
def GetCompilationInfoForFile( filename ):
# The compilation_commands.json file generated by CMake does not have entries
# for header files. So we do our best by asking the db for flags for a
# corresponding source file, if any. If one exists, the flags for that file
# should be good enough.
if IsHeaderFile( filename ):
basename = os.path.splitext( filename )[ 0 ]
for extension in SOURCE_EXTENSIONS:
replacement_file = basename + extension
if os.path.exists( replacement_file ):
compilation_info = database.GetCompilationInfoForFile(
replacement_file )
if compilation_info.compiler_flags_:
return compilation_info
return None
return database.GetCompilationInfoForFile( filename )
def FlagsForFile( filename, **kwargs ):
if database:
# Bear in mind that compilation_info.compiler_flags_ does NOT return a
# python list, but a "list-like" StringVec object
compilation_info = GetCompilationInfoForFile( filename )
if not compilation_info:
return None
final_flags = MakeRelativePathsInFlagsAbsolute(
compilation_info.compiler_flags_,
compilation_info.compiler_working_dir_ )
# NOTE: This is just for YouCompleteMe; it's highly likely that your project
# does NOT need to remove the stdlib flag. DO NOT USE THIS IN YOUR
# ycm_extra_conf IF YOU'RE NOT 100% SURE YOU NEED IT.
try:
final_flags.remove( '-stdlib=libc++' )
except ValueError:
pass
else:
relative_to = DirectoryOfThisScript()
final_flags = MakeRelativePathsInFlagsAbsolute( flags, relative_to )
return {
'flags': final_flags,
'do_cache': True
}
GNU LESSER GENERAL PUBLIC LICENSE
Version 3, 29 June 2007
Copyright (C) 2007 Free Software Foundation, Inc. <http://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.
# Set your cross compile prefix with CROSS_COMPILE variable
CROSS_COMPILE ?=
CMDSEP = ;
CC = $(CROSS_COMPILE)gcc
AR = $(CROSS_COMPILE)ar
LD = $(CROSS_COMPILE)ld
OBJDUMP = $(CROSS_COMPILE)objdump
OBJCOPY = $(CROSS_COMPILE)objcopy
SIZE = $(CROSS_COMPILE)size
MAKE = make
INSTALL_DIR ?= /usr/lib
export INSTALL_DIR
# Kernel stuff (pcie driver and library) relative
# directory
KERNEL_DIR = kernel
# General C flags
CFLAGS = -std=gnu99 -O2
LOCAL_MSG_DBG ?= n
DBE_DBG ?= n
CFLAGS_DEBUG =
ifeq ($(LOCAL_MSG_DBG),y)
CFLAGS_DEBUG += -DLOCAL_MSG_DBG=1
endif
ifeq ($(DBE_DBG),y)
CFLAGS_DEBUG += -DDBE_DBG=1
endif
# Debug flags -D<flasg_name>=<value>
CFLAGS_DEBUG += -g
# Specific platform Flags
CFLAGS_PLATFORM = -Wall -Wextra -Werror
LDFLAGS_PLATFORM =
# Libraries
LIBS = -lzmq -lczmq -lmdp -lpcidriver
# General library flags -L<libdir>
LFLAGS =
# Specific platform objects
OBJS_PLATFORM =
# Include other Makefiles as needed here
#include services/services.mk
#include clients/clients.mk
include hal/hal.mk
# Include directories
INCLUDE_DIRS = $(hal_INCLUDE_DIRS) \
-I$(KERNEL_DIR)/include/pcie
# Merge all flags. Optimize for size (-Os)
CFLAGS += $(CFLAGS_PLATFORM) $(CFLAGS_DEBUG)
#-Os
LDFLAGS = $(LDFLAGS_PLATFORM)
#-ffunction-sections -fdata-sections -Wl,--gc-sections
# Output modules
OUT = $(hal_OUT)
.SECONDEXPANSION:
# Save a git repository description
#REVISION = $(shell git describe --dirty --always)
#REVISION_NAME = revision
#OBJ_REVISION = $(addsuffix .o, $(REVISION_NAME))
OBJS_all = $(hal_OBJS) $(OBJ_REVISION)
.PHONY: all kernel_check clean mrproper install uninstall tests examples
# Avoid deletion of intermediate files, such as objects
.SECONDARY: $(OBJS_all)
# Makefile rules
all: kernel_check $(OUT)
# Output Rule
$(OUT): $$($$@_OBJS)
#$(REVISION_NAME).o
$(CC) $(LFLAGS) $(CFLAGS) $(INCLUDE_DIRS) -o $@ $^ $(LDFLAGS) $(LIBS)
#$(SIZE) $@
#$(REVISION_NAME).o: $(REVISION_NAME).c
# $(CC) $(CFLAGS) $(INCLUDE_DIRS) -DGIT_REVISION=\"$(REVISION)\" -c $<
# $(SIZE) -t $@
# Pull in dependency info for *existing* .o files and don't complain if the
# corresponding .d file is not found
-include $(OBJS_all:.o=.d)
# Autodependencies generatation by Scott McPeak, November 2001,
# from article "Autodependencies with GNU make"
%.o: %.c
$(CC) $(CFLAGS) $(INCLUDE_DIRS) -c $*.c -o $@
# create the dependency files "target: pre-requisites"
${CC} -MM $(CFLAGS) $(INCLUDE_DIRS) $*.c > $*.d
# Workaround to make objects in different folders have
# the correct target path. e.g., "dir/bar.o: dir/bar.c dir/foo.h"
# instead of "bar.o: dir/bar.c dir/foo.h"
@mv -f $*.d $*.d.tmp
@sed -e 's|.*:|$*.o:|' < $*.d.tmp > $*.d
# All prereqs listed will also become command-less,
# prereq-less targets. In this way, the prereq file will be
# treated as changed and the target will be rebuilt
# sed: strip the target (everything before colon)
# sed: remove any continuation backslashes
# fmt -1: list words one per line
# sed: strip leading spaces
# sed: add trailing colons
@sed -e 's/.*://' -e 's/\\$$//' < $*.d.tmp | fmt -1 | \
sed -e 's/^ *//' -e 's/$$/:/' >> $*.d
@rm -f $*.d.tmp
kernel_check:
# Check for libraries and issue warning!!!
# $(MAKE) -C $(KERNEL_DIR) all
tests:
$(MAKE) -C $@ all
examples:
$(MAKE) -C $@ all
#install:
# @install -m 755 $(TARGET_SHARED_VER) $(INSTALL_DIR)
# $(foreach lib,$(TARGET_SHARED),ln -sf $(lib).$(LIB_VER) $(INSTALL_DIR)/$(lib) $(CMDSEP))
#
#uninstall:
# $(foreach lib,$(TARGET_SHARED),rm -f $(INSTALL_DIR)/$(lib).$(LIB_VER) $(CMDSEP))
# $(foreach lib,$(TARGET_SHARED),rm -f $(INSTALL_DIR)/$(lib) $(CMDSEP))
clean:
rm -f $(OBJS_all) $(OBJS_all:.o=.d)
$(MAKE) -C tests clean
$(MAKE) -C examples clean
$(MAKE) -C $(KERNEL_DIR) clean
mrproper: clean
rm -f $(OUT)
$(MAKE) -C examples mrproper
==============================================================================
Repository containing the Beam Position Monitor Software
==============================================================================
Prerequisites:
-> Make sure you have the following libraries installed:
* zeromq-4.0.4 (http://zeromq.org/area:download)
* czmq-2.1.0 (http://czmq.zeromq.org/page:get-the-software)
-> Cloning this repository
1 - git clone --recursive https://github.com/lerwys/bpm-software.git
==============================================================================
PCIe Installation Instructions:
1 - sudo apt-get install linux-headers-generic
-> Install the GIT package
2 - sudo apt-get install binutils gcc
-> Change folder to the pcie driver location
4 - cd kernel
-> Compile the PCIe driver and its tests
5 - make
-> Install the PCIe drivers and libraries
6 - sudo make install
-> Load the Driver module
7 - sudo insmod /lib/modules/$(uname -r)/extra/PciDriver.ko
-> After this the kernel should have found the FPGA board and
initialized it. Run the following command and check its output
8 - dmesg | tail
-> You should see something like the excerpt below:
"
[267002.495109] pciDriver - pcidriver_init :
Major 250 allocated to nodename 'fpga'
[267002.495130] pciDriver - pcidriver_probe :
Found ML605 board at 0000:01:00.0
[267002.495224] pciDriver - pcidriver_probe :
Device /dev/fpga0 added
[267002.495434] pciDriver - pcidriver_probe_irq :
Registered Interrupt Handler at pin 1, line 11, IRQ 16
[267002.495450] pciDriver - pcidriver_init :
Module loaded
"
==============================================================================
Running the PCIe self-test:
-> After the installation of the PCIe driver (see above) it is possible to run
a self test to check if everything is setup properly. For this run the following:
-> Change to the "compiled tests folder"
1 - cd tests/pcie/bin
-> Run the test entitled "testPciDriverMod"
2 - sudo ./testPciDriverMod
-> You should get an output like the following, if everythig is ok:
"
Testing OPEN DEVICE... PASSED!
Testing PCIDRIVER_IOC_MMAP_MODE... PASSED!
Testing PCIDRIVER_IOC_MMAP_AREA... PASSED!
Testing PCIDRIVER_IOC_PCI_INFO... PASSED!
Testing PCI CONFIG...
Reading PCI config area in byte mode ... PASSED!
Reading PCI config area in word mode ... PASSED!
Reading PCI config area in double-word mode ... PASSED!
Testing PCI mmap...
Reading PCI info... PASSED!
Setting mmap mode... PASSED!
Setting mmap area... PASSED!
MMAP'ing BAR0... PASSED!
Setting mmap area... PASSED!
MMAP'ing BAR2... PASSED!
Setting mmap area... PASSED!
MMAP'ing BAR4... PASSED!
Testing PCIDRIVER_IOC_KMEM_ALLOC...
alloc size 1024 : PASSED!
alloc size 2048 : PASSED!
alloc size 4096 : PASSED!
alloc size 8192 : PASSED!
alloc size 16384 : PASSED!
alloc size 32768 : PASSED!
alloc size 65536 : PASSED!
alloc size 131072 : PASSED!
alloc size 262144 : PASSED!
alloc size 524288 : PASSED!
alloc size 1048576 : PASSED!
alloc size 2097152 : PASSED!
alloc size 4194304 : PASSED!
alloc size 8388608 : FAILED (maybe size is just too big)!
Testing PCIDRIVER_IOC_KMEM_SYNC...
Setting KMEM SYNC to write mode... PASSED!
Setting KMEM SYNC to read mode... PASSED!
Setting KMEM SYNC to read/write mode... PASSED!
Testing PCIDRIVER_IOC_KMEM_FREE... PASSED!
Testing Kernel Buffer mmap...
Setting MMAP mode to KMEM... PASSED!
Allocing size 1024 : PASSED!
MMAPing size 1024 : PASSED!
Allocing size 2048 : PASSED!
MMAPing size 2048 : PASSED!
Allocing size 4096 : PASSED!
MMAPing size 4096 : PASSED!
Allocing size 8192 : PASSED!
MMAPing size 8192 : PASSED!
Allocing size 16384 : PASSED!
MMAPing size 16384 : PASSED!
Allocing size 32768 : PASSED!
MMAPing size 32768 : PASSED!
Allocing size 65536 : PASSED!
MMAPing size 65536 : PASSED!
Allocing size 131072 : PASSED!
MMAPing size 131072 : PASSED!
Allocing size 262144 : PASSED!
MMAPing size 262144 : PASSED!
Allocing size 524288 : PASSED!
MMAPing size 524288 : PASSED!
Allocing size 1048576 : PASSED!
MMAPing size 1048576 : PASSED!
Allocing size 2097152 : PASSED!
MMAPing size 2097152 : PASSED!
Allocing size 4194304 : PASSED!
MMAPing size 4194304 : PASSED!
Allocing size 8388608 : FAILED (maybe size is just too big)!
Freeing Kernel buffers...
Buffer index 0... PASSED!
Buffer index 1... PASSED!
Buffer index 2... PASSED!
Buffer index 3... PASSED!
Buffer index 4... PASSED!
Buffer index 5... PASSED!
Buffer index 6... PASSED!
Buffer index 7... PASSED!
Buffer index 8... PASSED!
Buffer index 9... PASSED!
Buffer index 10... PASSED!
Buffer index 11... PASSED!
Buffer index 12... PASSED!
Testing PCIDRIVER_IOC_UMEM_SGMAP ... PASSED!
Testing PCIDRIVER_IOC_UMEM_SGGET ... PASSED!
Testing PCIDRIVER_IOC_UMEM_SYNC ...
Setting UMEM SYNC to write mode... PASSED!
Setting UMEM SYNC to read mode... PASSED!
Setting UMEM SYNC to read/write mode... PASSED!
Testing PCIDRIVER_IOC_UMEM_SGUNMAP ... PASSED!
-------------------------------------
| All tests PASSED! |
-------------------------------------
"
-> Notice that some tests that try to evaluate the limits of a current
Linux Kernel may fail in some cases. In the example above,
two tests , due to an attempt to allocate a large buffer in kernel
space.
-> This is not actually an error or a failure, it is just trying to
allocate more memory than the kernel has available.
==============================================================================
Installation Instructions:
-> Comple everything
1 - make
-> Compile the examples
2 - make examples
-> Run the server components with a helper script
3 - ./init.sh
-> Now we should be good to start making transactions.
-> Change to the example applications folder
4 - cd examples
-> Run the Example application
5 - ./client -v
-> Leds should be blinking in the FMC ADC board
# Set your cross compile prefix with CROSS_COMPILE variable
CROSS_COMPILE ?=
CMDSEP = ;
CC = $(CROSS_COMPILE)gcc
AR = $(CROSS_COMPILE)ar
LD = $(CROSS_COMPILE)ld
OBJDUMP = $(CROSS_COMPILE)objdump
OBJCOPY = $(CROSS_COMPILE)objcopy
SIZE = $(CROSS_COMPILE)size
MAKE = make
# General C flags
CFLAGS = -std=gnu99 -O2
LOCAL_MSG_DBG ?= n
DBE_DBG ?= n
CFLAGS_DEBUG =
ifeq ($(LOCAL_MSG_DBG),y)
CFLAGS_DEBUG += -DLOCAL_MSG_DBG=1
endif
ifeq ($(DBE_DBG),y)
CFLAGS_DEBUG += -DDBE_DBG=1
endif
# Debug flags -D<flasg_name>=<value>
CFLAGS_DEBUG += -g
# Specific platform Flags
CFLAGS_PLATFORM = -Wall -Wextra -Werror
LDFLAGS_PLATFORM =
# Libraries
LIBS = -lzmq -lczmq -lmdp
# General library flags -L<libdir>
LFLAGS =
# Include directories
INCLUDE_DIRS = -I. -Iinclude
# Merge all flags. Optimize for size (-Os)
CFLAGS += $(CFLAGS_PLATFORM) $(CFLAGS_DEBUG)
#-Os
LDFLAGS = $(LDFLAGS_PLATFORM)
#-ffunction-sections -fdata-sections -Wl,--gc-sections
OUT=client
# Makefile rules
all: $(OUT)
client: client.c
$(CC) $(CFLAGS) $(INCLUDE_DIRS) $^ -o $@ $(LIBS)
#BAD
clean:
find . -iname "*.o" -exec rm '{}' \;
mrproper: clean
rm -f $(OUT)
/*
* Simple example demonstrating the communication between
* a client and the FPGA device
*/
#include <mdp.h>
#include <inttypes.h>
int main (int argc, char *argv [])
{
int verbose = (argc > 1 && streq (argv [1], "-v"));
mdp_client_t *client = mdp_client_new ("ipc:///tmp/bpm/0", verbose);
unsigned i;
for (i = 0; i < 32768; ++i) {
unsigned int j;
uint32_t operation = 0;
uint32_t leds = (1 << 1);
for (j = 0; j < 3; ++j) {
if (!zctx_interrupted) {
zmsg_t *request = zmsg_new ();
zmsg_addmem (request, &operation, sizeof (operation));
zmsg_addmem (request, &leds, sizeof (leds));
mdp_client_send (client, "BPM0:DEVIO:FMC130M_4CH", &request);
usleep (80000);
leds <<= 1;
}
}
}
mdp_client_destroy (&client);
return 0;
}
debug_DIR = hal/debug
debug_OBJS = $(debug_DIR)/debug_print.o
debug_INCLUDE_DIRS = $(debug_DIR)
/*
* Copyright (C) 2014 LNLS (www.lnls.br)
* Author: Lucas Russo <lucas.russo@lnls.br>
*
* Released according to the GNU LGPL, version 3 or any later version.
*/
#include <stdio.h>
#include "debug_print.h"
void debug_print (const char *fmt, ...)
{
va_list args;
va_start (args, fmt);
vprintf (fmt, args);
va_end (args);
}
void debug_print_vec (const char *fmt, const char *data, int len)
{
int i;
for (i = 0; i < len; ++i)
printf (fmt, data[i]);
printf ("\n");
}
/*
* Copyright (C) 2014 LNLS (www.lnls.br)
* Author: Lucas Russo <lucas.russo@lnls.br>
* Parts taken from lwIP debug system
*
* Released according to the GNU LGPL, version 3 or any later version.
*/
#ifndef _DEBUG_PRINT_H_
#define _DEBUG_PRINT_H_
#include <stdarg.h>
#include "debug_subsys.h" /* This must come before "hal_opts.h" */
#include "hal_opts.h"
/************** Debug functions declarations **************/
void debug_print (const char *fmt, ...) __attribute__((format(printf,1,2)));
void debug_print_vec (const char *fmt, const char *data, int len);
/********************** Debug macros **********************/
#if (DBG_SUBSYS_ON & DBG_MSG)
#define LOCAL_MSG_DBG
#endif
#ifdef DBE_DBG
#define dbg_print(fmt, ...) \
debug_print(fmt, ## __VA_ARGS__)
#define dbg_print_vec(fmt, data, len) \
debug_print_vec(fmt, data, len)
#else
#define dbg_print(fmt, ...)
#define dbg_print_vec(fmt, data, len)
#endif /* DBE_DBG */
/* dbg has the following format:
* 31 - 4 3 - 1 0-0
* DBG_SUBSYS DBG_LVL DBG_HALT
*/
#ifdef DBE_DBG
#define DBE_DEBUG(dbg, fmt, ...) \
do { \
if (((dbg) & DBG_SUBSYS_ON) && \
(((dbg) & DBG_LVL_MASK) >= \
DBG_MIN_LEVEL)) { \
dbg_print(fmt, ## __VA_ARGS__); \
\
if ((dbg) & DBG_LVL_HALT) { \
while(1); \
} \
} \
} while(0)
#define DBE_DEBUG_ARRAY(dbg, fmt, data, len) \
do { \
if (((dbg) & DBG_SUBSYS_ON) && \
(((dbg) & DBG_LVL_MASK) >= \
DBG_MIN_LEVEL)) { \
dbg_print_vec(fmt, data, len); \
\
if ((dbg) & DBG_LVL_HALT) \
while(1); \
} \
} while(0)
#define DBE_ERR(...) \
do { \
dbg_print(fmt, ##__VA_ARGS__); \
} while(0)
#else
#define DBE_DEBUG(dbg, fmt, ...)
#define DBE_DEBUG_ARRAY(dbg, fmt, data, len)
#define DBE_ERR(...)
#endif /* DBE_DBG */
#endif
/*
* Copyright (C) 2014 LNLS (www.lnls.br)
* Author: Lucas Russo <lucas.russo@lnls.br>
*
* Released according to the GNU LGPL, version 3 or any later version.
*/
#ifndef _DEBUG_SUBSYS_H_
#define _DEBUG_SUBSYS_H_
/****************** Debug subsys macros ******************/
/*
* DBG_SUBSYS variable is one-hot encoded between
* the bits 31 and 4:
* bit 31 ... bit 4 bit 3 ... bit 0
* [1|0] [1|0] X X
*/
#define DBG_SUBSYS_SHIFT 4
/* Up to 28 debug subsystems (one-hot encoded) */
#define DBG_SUBSYS_MAX 28
#define DBG_SUBSYS_MASK_RAW ((1 << DBG_SUBSYS_MAX)-1)
#define DBG_SUBSYS_MASK (DBG_SUBSYS_MASK_RAW << DBG_SUBSYS_SHIFT)
#define DBG_SUBSYS_GEN(val) ((val & DBG_SUBSYS_MASK_RAW) << DBG_SUBSYS_SHIFT)
/* Debug subsys raw */
#define DBG_DEV_MNGR_RAW 0x1
#define DBG_DEV_IO_RAW 0x2
#define DBG_LL_IO_RAW 0x4
#define DBG_SM_IO_RAW 0x8
#define DBG_MSG_RAW 0x10
#define DBG_HAL_UTILS_RAW 0x20
#define DBG_DEV_MNGR DBG_SUBSYS_GEN(DBG_DEV_MNGR_RAW)
#define DBG_DEV_IO DBG_SUBSYS_GEN(DBG_DEV_IO_RAW)
#define DBG_LL_IO DBG_SUBSYS_GEN(DBG_LL_IO_RAW)
#define DBG_SM_IO DBG_SUBSYS_GEN(DBG_SM_IO_RAW)
#define DBG_MSG DBG_SUBSYS_GEN(DBG_MSG_RAW)
#define DBG_HAL_UTILS DBG_SUBSYS_GEN(DBG_HAL_UTILS_RAW)
/****************** Debug levels macros ******************/
/*
* DBG_LVL variable is binary encoded between
* the bits 3 and 1:
* bit 31 ... bit 4 bit 3 ... bit 1 bit 0
* X X [1|0] [1|0] X
*/
#define DBG_LVL_SHIFT 1
#define DBG_LVL_MAX 3
#define DBG_LVL_MASK_RAW ((1 << DBG_LVL_MAX)-1)
#define DBG_LVL_MASK (DBG_LVL_MASK_RAW << DBG_LVL_SHIFT)
/* Up to 2^3 debug levels */
#define DBG_LVL_GEN(val) ((val & DBG_LVL_MASK_RAW) << DBG_LVL_SHIFT)
/* Debug levels raw */
#define DBG_LVL_TRACE_RAW 0x1
#define DBG_LVL_INFO_RAW 0x2
#define DBG_LVL_WARN_RAW 0x3
#define DBG_LVL_ERR_RAW 0x4
#define DBG_LVL_FATAL_RAW 0x5
/* Debug levels mask'ed and shift'ed */
#define DBG_LVL_TRACE DBG_LVL_GEN(DBG_LVL_TRACE_RAW)
#define DBG_LVL_INFO DBG_LVL_GEN(DBG_LVL_INFO_RAW)
#define DBG_LVL_WARN DBG_LVL_GEN(DBG_LVL_WARN_RAW)
#define DBG_LVL_ERR DBG_LVL_GEN(DBG_LVL_ERR_RAW)
#define DBG_LVL_FATAL DBG_LVL_GEN(DBG_LVL_FATAL_RAW)
/****************** Debug halt macros ******************/
/*
* DBG_HALT variable is binary encoded in bit 0:
* bit 31 ... bit 4 bit 3 ... bit 1 bit 0
* X X X X [1|0]
*/
/* Debug halt */
#define DBG_HALT_SHIFT 0
#define DBG_HALT_MAX 1
#define DBG_HALT_MASK_RAW ((1 << DBG_HALT_SHIFT)-1)
#define DBG_HALT_MASK (DBG_HALT_MASK_RAW << DBG_HALT_SHIFT)
/* 1 halt signal */
#define DBG_HALT_GEN(val) ((val & DBG_HALT_MASK_RAW) << DBG_HALT_SHIFT)
/* Debug halt raw */
#define DBG_LVL_HALT_RAW 0x1
/* Debug halt mask'ed and shift'ed */
#define DBG_LVL_HALT DBG_HALT_GEN(DBG_LVL_HALT_RAW)
#endif
#ifndef _ERROR_H_
#define _ERROR_H_
#endif
error_DIR = hal/error
#error_OBJS = $(error_DIR)/error.o
error_INCLUDE_DIRS = $(error_DIR)
# debug.mk must be declared before dev_mngr.mk, as they are variables
# exported by the former used by the latter
include hal/debug/debug.mk
include hal/hal_utils/hal_utils.mk
include hal/ll_io/ll_io.mk
include hal/sm_io/sm_io.mk
include hal/sdb/sdb.mk
include hal/dev_mngr/dev_mngr.mk
include hal/dev_io/dev_io.mk
include hal/msg/msg.mk
std_hal_INCLUDE_DIRS = hal/include
hal_OUT += $(dev_mngr_OUT) $(dev_io_OUT)
# For each target in hal_OUT we add the necessary objects
dev_mngr_OBJS = $(dev_mngr_core_OBJS) $(debug_OBJS)
dev_io_OBJS = $(dev_io_core_OBJS) $(ll_io_OBJS) $(sm_io_OBJS) \
$(msg_OBJS) $(debug_OBJS) $(hal_utils_OBJS)
# Merge all hal objects together
hal_OBJS = $(debug_OBJS) \
$(hal_utils_OBJS) \
$(ll_io_OBJS) \
$(sm_io_OBJS) \
$(msg_OBJS) \
$(dev_mngr_core_OBJS) \
$(dev_io_core_OBJS)
# Merge all include directories together
hal_all_INCLUDE_DIRS += $(std_hal_INCLUDE_DIRS) \
$(debug_INCLUDE_DIRS) \
$(hal_utils_INCLUDE_DIRS) \
$(sdb_INCLUDE_DIRS) \
$(ll_io_INCLUDE_DIRS) \
$(sm_io_INCLUDE_DIRS) \
$(msg_INCLUDE_DIRS) \
$(dev_mngr_INCLUDE_DIRS) \
$(dev_io_INCLUDE_DIRS)
# Change the include dirs into flags
hal_INCLUDE_DIRS = $(addprefix -I, $(hal_all_INCLUDE_DIRS))
/*
* Copyright (C) 2014 LNLS (www.lnls.br)
* Author: Lucas Russo <lucas.russo@lnls.br>
*
* Released according to the GNU LGPL, version 3 or any later version.
*/
#include <inttypes.h>
#include "hal_utils.h"
#include "dispatch_table.h"
#include "hal_assert.h"
/* Undef ASSERT_ALLOC to avoid conflicting with other ASSERT_ALLOC */
#ifdef ASSERT_TEST
#undef ASSERT_TEST
#endif
#define ASSERT_TEST(test_boolean, err_str, err_goto_label) \
ASSERT_HAL_TEST(test_boolean, HAL_UTILS, "[halultis:disp_table]",\
err_str, err_goto_label)
#ifdef ASSERT_ALLOC
#undef ASSERT_ALLOC
#endif
#define ASSERT_ALLOC(ptr, err_goto_label) \
ASSERT_HAL_ALLOC(ptr, HAL_UTILS, "[halutils:disp_table]",\
halutils_err_str(HALUTILS_ERR_ALLOC), \
err_goto_label)
#ifdef CHECK_ERR
#undef CHECK_ERR
#endif
#define CHECK_ERR(err, err_type) \
CHECK_HAL_ERR(err, HAL_UTILS, "[halutils:disp_table]", \
halutils_err_str (err_type))
static halutils_err_e _disp_table_insert (disp_table_t *self, const uint32_t key,
disp_table_func_fp func_fp);
static void _disp_table_free_item (void *data);
disp_table_t *disp_table_new (void)
{
disp_table_t *self = zmalloc (sizeof *self);
ASSERT_ALLOC (self, err_self_alloc);
self->table_h = zhash_new ();
ASSERT_ALLOC (self->table_h, err_table_h_alloc);
/* Only work for strings
zhash_autofree (self->table_h);*/
return self;
err_table_h_alloc:
free (self);
err_self_alloc:
return NULL;
}
halutils_err_e disp_table_destroy (disp_table_t **self_p)
{
assert (self_p);
if (*self_p) {
disp_table_t *self = *self_p;
zhash_destroy (&self->table_h);
free (self);
*self_p = NULL;
}
return HALUTILS_SUCCESS;
}
halutils_err_e disp_table_insert (disp_table_t *self, uint32_t key,
disp_table_func_fp func_fp)
{
return _disp_table_insert (self, key, func_fp);
}
halutils_err_e disp_table_remove (disp_table_t *self, uint32_t key)
{
char *key_c = halutils_stringify_key (key);
ASSERT_ALLOC (key_c, err_key_c_alloc);
DBE_DEBUG (DBG_HAL_UTILS | DBG_LVL_TRACE,
"[halutils:disp_table] Removing function (key = %u) into dispatch table\n",
key);
/* This will trigger the free fucntion previously registered */
zhash_delete (self->table_h, key_c);
free (key_c);
return HALUTILS_SUCCESS;
err_key_c_alloc:
return HALUTILS_ERR_ALLOC;
}
void *disp_table_call (disp_table_t *self, uint32_t key, void *owner, void *args)
{
char *key_c = halutils_stringify_key (key);
ASSERT_ALLOC (key_c, err_key_c_alloc);
func_fp_wrapper_t *func_fp_wrapper = zhash_lookup (self->table_h, key_c);
ASSERT_ALLOC (func_fp_wrapper, err_func_p_wrapper_null);
free (key_c);
/* DBE_DEBUG (DBG_HAL_UTILS | DBG_LVL_TRACE,
"[halutils:disp_table] Calling function (key = %u, addr = %p) from dispatch table\n",
key, func_fp_wrapper->func_fp); */
/* The function pointer is never NULL */
return func_fp_wrapper->func_fp (owner, args);
err_func_p_wrapper_null:
free (key_c);
err_key_c_alloc:
return NULL;
}
halutils_err_e disp_table_insert_all (disp_table_t *self, const disp_table_func_fp *disp_table_fp,
const uint32_t *code_table, uint32_t size)
{
assert (self);
assert (disp_table_fp);
assert (code_table);
unsigned int i;
halutils_err_e err = HALUTILS_SUCCESS;
for (i = 0; i < size; ++i) {
halutils_err_e err = _disp_table_insert (self, code_table [i],
*disp_table_fp [i]);
if (err != HALUTILS_SUCCESS) {
break;
}
}
return err;
}
halutils_err_e disp_table_remove_all (disp_table_t *self)
{
assert (self);
zlist_t *hash_keys = zhash_keys (self->table_h);
void * table_item = zlist_first (hash_keys);
for (; table_item; table_item = zlist_next (hash_keys)) {
zhash_delete (self->table_h, (char *) table_item);
}
zlist_destroy (&hash_keys);
return HALUTILS_SUCCESS;
}
/**** Local helper functions ****/
static halutils_err_e _disp_table_insert (disp_table_t *self, uint32_t key,
disp_table_func_fp func_fp)
{
if (func_fp == NULL) {
return HALUTILS_ERR_NULL_POINTER;
}
DBE_DEBUG (DBG_HAL_UTILS | DBG_LVL_TRACE,
"[halutils:disp_table] Registering function (%p) opcode (%u) into dispatch table\n",
func_fp, key);
func_fp_wrapper_t *func_fp_wrapper = zmalloc (sizeof *func_fp_wrapper);
ASSERT_ALLOC (func_fp_wrapper, err_func_wrapper_alloc);
/* Initialize func_p_wrapper struct */
func_fp_wrapper->func_fp = func_fp;
char *key_c = halutils_stringify_key (key);
ASSERT_ALLOC (key_c, err_key_c_alloc);
int zerr = zhash_insert (self->table_h, key_c, func_fp_wrapper);
ASSERT_TEST(zerr == 0, "Could not insert item into dispatch table", err_insert_hash);
/* Setup free function */
zhash_freefn (self->table_h, key_c, _disp_table_free_item);
free (key_c);
return HALUTILS_SUCCESS;
err_insert_hash:
free (key_c);
err_key_c_alloc:
free (func_fp_wrapper);
err_func_wrapper_alloc:
return HALUTILS_ERR_ALLOC;
}
static void _disp_table_free_item (void *data)
{
free ((func_fp_wrapper_t *)data);
}
/*
* Copyright (C) 2014 LNLS (www.lnls.br)
* Author: Lucas Russo <lucas.russo@lnls.br>
*
* Released according to the GNU LGPL, version 3 or any later version.
*/
#ifndef _DISPATCH_TABLE_H_
#define _DISPATCH_TABLE_H_
#include <czmq.h>
#include "hal_utils_err.h"
struct _disp_table_t {
/* Hash containg all the sm_io thsafe operations
* that we need to handle. It is composed
* of key (4-char ID) / value (pointer to funtion) */
zhash_t *table_h;
};
/* Opaque class structure */
typedef struct _disp_table_t disp_table_t;
/* Generic function pointer */
typedef void* (*disp_table_func_fp)(void *owner, void * args);
struct _func_fp_wrapper_t {
disp_table_func_fp func_fp;
};
/* Opaque class structure */
typedef struct _func_fp_wrapper_t func_fp_wrapper_t;
/***************** Our methods *****************/
disp_table_t *disp_table_new (void);
halutils_err_e disp_table_destroy (disp_table_t **self_p);
halutils_err_e disp_table_insert (disp_table_t *self, uint32_t key,
disp_table_func_fp func_fp);
halutils_err_e disp_table_insert_all (disp_table_t *self, const disp_table_func_fp *disp_table_fp,
const uint32_t *code_table, uint32_t size);
halutils_err_e disp_table_remove (disp_table_t *self, uint32_t key);
halutils_err_e disp_table_remove_all (disp_table_t *self);
void *disp_table_call (disp_table_t *self, uint32_t key, void *owner, void *args);
#endif
/*
* Copyright (C) 2014 LNLS (www.lnls.br)
* Author: Lucas Russo <lucas.russo@lnls.br>
*
* Released according to the GNU LGPL, version 3 or any later version.
*/
#include <stdio.h>
#include "hal_utils.h"
#include "hal_utils_err.h"
#include "hal_assert.h"
#include "czmq.h"
/* Undef ASSERT_ALLOC to avoid conflicting with other ASSERT_ALLOC */
#ifdef ASSERT_TEST
#undef ASSERT_TEST
#endif
#define ASSERT_TEST(test_boolean, err_str, err_goto_label) \
ASSERT_HAL_TEST(test_boolean, HAL_UTILS, "[halultis]",\
err_str, err_goto_label)
#ifdef ASSERT_ALLOC
#undef ASSERT_ALLOC
#endif
#define ASSERT_ALLOC(ptr, err_goto_label) \
ASSERT_HAL_ALLOC(ptr, HAL_UTILS, "[halutils]",\
halutils_err_str(HALUTILS_ERR_ALLOC), \
err_goto_label)
#ifdef CHECK_ERR
#undef CHECK_ERR
#endif
#define CHECK_ERR(err, err_type) \
CHECK_HAL_ERR(err, HAL_UTILS, "[halutils]", \
halutils_err_str (err_type))
uint32_t hex_to_str_len (uint32_t key)
{
uint32_t i = 0;
do {
key >>= 4;
++i;
} while (key > 0);
return i;
}
char *halutils_stringify_key (uint32_t key)
{
uint32_t key_len = hex_to_str_len (key) + 1; /* +1 for \0 */
char *key_c = zmalloc (key_len * sizeof (char));
ASSERT_ALLOC (key_c, err_key_c_alloc);
snprintf(key_c, key_len, "%x", key);
/* DBE_DEBUG (DBG_HAL_UTILS | DBG_LVL_TRACE,
"[halutils:stringify_key] key = %s, key_len = %u\n",
key_c, key_len); */
return key_c;
err_key_c_alloc:
return NULL;
}
/*
* Copyright (C) 2014 LNLS (www.lnls.br)
* Author: Lucas Russo <lucas.russo@lnls.br>
*
* Released according to the GNU LGPL, version 3 or any later version.
*/
#ifndef _HAL_UTILS_H_
#define _HAL_UTILS_H_
#include <inttypes.h>
uint32_t num_to_str_len (uint32_t key);
char *halutils_stringify_key (uint32_t key);
#endif
hal_utils_DIR = hal/hal_utils
hal_utils_OBJS = $(hal_utils_DIR)/hal_utils.o \
$(hal_utils_DIR)/hal_utils_err.o \
$(hal_utils_DIR)/dispatch_table.o \
hal_utils_INCLUDE_DIRS = $(hal_utils_DIR)
/*
* Copyright (C) 2014 LNLS (www.lnls.br)
* Author: Lucas Russo <lucas.russo@lnls.br>
*
* Released according to the GNU LGPL, version 3 or any later version.
*/
/* Error definitions and output stringification based on the work available
* at the libsllp project repository: https://github.com/brunoseivam/libsllp */
#include "hal_utils_err.h"
static const char *halutils_err [HALUTILS_ERR_END] =
{
[HALUTILS_SUCCESS] = "Success",
[HALUTILS_ERR_ALLOC] = "Could not allocate memory",
[HALUTILS_ERR_NULL_POINTER] = "Null pointer received"
};
/* Convert enumeration type to string */
const char * halutils_err_str (halutils_err_e err)
{
return halutils_err [err];
}
/*
* Copyright (C) 2014 LNLS (www.lnls.br)
* Author: Lucas Russo <lucas.russo@lnls.br>
*
* Released according to the GNU LGPL, version 3 or any later version.
*/
/* Error definitions and output stringification based on the work available
* at the libsllp project repository: https://github.com/brunoseivam/libsllp */
#ifndef _HALUTILS_ERR_H_
#define _HALUTILS_ERR_H_
enum _halutils_err_e
{
HALUTILS_SUCCESS = 0, /* No error */
HALUTILS_ERR_ALLOC, /* Could not allocate memory */
HALUTILS_ERR_NULL_POINTER, /* Null pointer received */
HALUTILS_ERR_END
};
typedef enum _halutils_err_e halutils_err_e;
/* Convert enumeration type to string */
const char * halutils_err_str (halutils_err_e err);
#endif
/*
* Copyright (C) 2014 LNLS (www.lnls.br)
* Author: Lucas Russo <lucas.russo@lnls.br>
*
* Released according to the GNU LGPL, version 3 or any later version.
*/
#ifndef _HAL_ASSERT_H_
#define _HAL_ASSERT_H_
#include "debug_print.h"
/* Generic macros for asserting in subsystems. The
* general use case for them is to wrapp these with
* meaningful strings for differentes subsystems */
#define ASSERT_HAL_TEST(test_boolean, debug_subsys, \
debug_name, err_str, err_goto_label) \
do { \
if(!(test_boolean)) { \
DBE_DEBUG (DBG_ ##debug_subsys | DBG_LVL_FATAL, \
"["debug_name"]" " %s\n", err_str); \
goto err_goto_label; \
} \
} while(0)
#define ASSERT_HAL_ALLOC(ptr, debug_subsys, debug_name, \
err_str, err_goto_label) \
ASSERT_HAL_TEST(ptr!=NULL, debug_subsys, debug_name, \
err_str, err_goto_label)
#define CHECK_HAL_ERR(err, debug_subsys, debug_name, \
err_str) \
do { \
if (err < 0) { \
DBE_DEBUG (DBG_ ##debug_subsys | DBG_LVL_ERR, \
"["debug_name"]" " %s\n", err_str); \
return err; \
} \
} while (0)
#endif
/*
* Copyright (C) 2014 LNLS (www.lnls.br)
* Author: Lucas Russo <lucas.russo@lnls.br>
* Parts taken from lwIP debug system
*
* Released according to the GNU LGPL, version 3 or any later version.
*/
#ifndef _HAL_OPTS_
#define _HAL_OPTS_
/*
* Define the debug level here.
* Available options are, in decreasing order of verbosity:
* DBG_LVL_TRACE = super verbose
* DBG_LVL_INFO
* DBG_LVL_WARN
* DBG_LVL_ERR
* DBG_LVL_FATAL = only the critical messages are shown
*/
#define DBG_MIN_LEVEL DBG_LVL_TRACE
/* Define which subsystem will be traced. The DBG_SUBSYS_ON
* macro must be OR'ed.
* Available options are:
* DBG_DEV_MNGR
* DBG_DEV_IO
* DBG_LL_IO
* DBG_SM_IO
* DBG_MSG
* DBG_HAL_UTILS
*/
#define DBG_SUBSYS_ON (\
DBG_DEV_MNGR | \
DBG_DEV_IO | \
DBG_LL_IO | \
DBG_SM_IO | \
DBG_HAL_UTILS)
/* DBG_MSG | \ */
#endif
/*
* Copyright (C) 2014 LNLS (www.lnls.br)
* Author: Lucas Russo <lucas.russo@lnls.br>
*
* Released according to the GNU LGPL, version 3 or any later version.
*/
#ifndef _PCIE_REGS_H_
#define _PCIE_REGS_H_
/* Some FPGA PCIe registers. These are inside bar0 */
#define PCIE_CFG_REG_SDRAM_PG 0x1C
#define PCIE_CFG_REG_GSR 0x20
#define PCIE_CFG_GSR_BIT_DDR_RDY (0x1 << 7)
#define PCIE_CFG_REG_WB_PG 0x24
/* Some FPGA PCIe constants */
/* SDRAM is accesses via 32-bit BAR (32-bit addressing) */
#define PCIE_SDRAM_PG_SHIFT 0 /* bits */
/* #define PCIE_SDRAM_PG_MAX 19 */ /* bits */
#define PCIE_SDRAM_PG_MAX 17 /* bits */
/* #define PCIE_SDRAM_PG_SIZE (1<<16)*/ /* in Words (32-bit) */
#define PCIE_SDRAM_PG_SIZE (1<<PCIE_SDRAM_PG_MAX) /* in Bytes (8-bit) */
#define PCIE_SDRAM_PG_MASK ((PCIE_SDRAM_PG_SIZE-1) << \
PCIE_SDRAM_PG_SHIFT)
/* One less then PCIE_SDRAM_PG_SIZE, as Wishbone is accessed via
* 64-bit BAR (64-bit addressed) */
#define PCIE_WB_PG_SHIFT 0 /* bits */
/*#define PCIE_WB_PG_MAX 17 */ /* bits */
#define PCIE_WB_PG_MAX 16 /* bits */
/* #define PCIE_WB_PG_SIZE (1<<15)*/ /* in Words (32-bit) */
#define PCIE_WB_PG_SIZE (1<<PCIE_WB_PG_MAX) /* in Bytes (8-bit) */
#define PCIE_WB_PG_MASK ((PCIE_WB_PG_SIZE-1) << \
PCIE_WB_PG_SHIFT)
/* Wishbone Word Access Shift (in legacy x86 nomenclature) */
#define WB_QWORD_ACC 3 /* 64-bit addressing */
#define WB_DWORD_ACC 2 /* 32-bit addressing */
#define WB_WORD_ACC 1 /* 16-bit addressing */
#define WB_BYTE_ACC 0 /* 8-bit addressing */
/************************************************************/
/********** PCIe Address MSB (BARs) part extractor **********/
/************************************************************/
/********** BAR numbers **********/
#define BAR0NO 0
#define BAR2NO 2
#define BAR4NO 4
/* For the PCIe device, we only have up to 28 address bits, as
* the 4 MSB are reserved for selecting the BAR to operate on */
/********** PCIe Address MSB (BARs) part extractor **********/
#define PCIE_ADDR_BAR_SHIFT 28 /* bits */
#define PCIE_ADDR_BAR_MAX 4 /* bits */
#define PCIE_ADDR_BAR_MASK (((1 << PCIE_ADDR_BAR_MAX)-1) << \
PCIE_ADDR_BAR_SHIFT)
/* PCIe LSB (generic) part extractor */
#define PCIE_ADDR_BAR(addr) ((addr & PCIE_ADDR_BAR_MASK) >> \
PCIE_ADDR_BAR_SHIFT)
/* For use by LL_IO */
/* We divide the PCIe Wishbone addresses as:
* bits 32 to 28: BAR address (0, 2 or 4)
* bits 27 to 0: Wishbone physical address (2^28-1 to 0)*/
#define BAR4_ADDR (BAR4NO << PCIE_ADDR_BAR_SHIFT)
#define BAR2_ADDR (BAR2NO << PCIE_ADDR_BAR_SHIFT)
#define BAR0_ADDR (BAR0NO << PCIE_ADDR_BAR_SHIFT)
/********** PCIe Address LSB (generic) part extractor **********/
#define PCIE_ADDR_GEN_SHIFT 0 /* bits */
#define PCIE_ADDR_GEN_MAX 28 /* bits */
#define PCIE_ADDR_GEN_MASK (((1 << PCIE_ADDR_GEN_MAX)-1) << \
PCIE_ADDR_GEN_SHIFT)
/* PCIe LSB (generic) part extractor */
#define PCIE_ADDR_GEN(addr) ((addr & PCIE_ADDR_GEN_MASK) >> \
PCIE_ADDR_GEN_SHIFT)
/* PCIe LSB (generic) part, for use by LL_IO */
#define PCIE_ADDR_WB(addr) ((addr & PCIE_ADDR_GEN_MASK) << \
PCIE_ADDR_GEN_SHIFT)
/********** PCIe SDRAM Address Page number and offset extractor **********/
#define PCIE_ADDR_SDRAM_PG_OFFS(addr) ((addr & PCIE_SDRAM_PG_MASK) >> \
PCIE_SDRAM_PG_SHIFT)
#define PCIE_ADDR_SDRAM_PG(addr) ((addr & ~PCIE_SDRAM_PG_MASK) >> \
PCIE_SDRAM_PG_MAX)
/********** PCIe WB Address Page number and offset extractor **********/
#define PCIE_ADDR_WB_PG_OFFS(addr) ((addr & PCIE_WB_PG_MASK) >> \
PCIE_WB_PG_SHIFT)
#define PCIE_ADDR_WB_PG(addr) ((addr & ~PCIE_WB_PG_MASK) >> \
PCIE_WB_PG_MAX)
/********** Read or write to BAR **********/
#define BAR32_RW(barp, addr, datap, rw) \
do { \
(rw) ? \
(*(datap) = *((barp) + (addr))) : \
(*((barp) + (addr)) = *(datap)); \
} while (0)
/* FIXME: Figure it out another convenient way of doing this without hiding code! */
/* Macros for ease the PCIe BAR pointer verbosity. */
#define BAR_ACCESS_GEN(bar_addr) (((llio_dev_pcie_t *)self->dev_handler)->bar_addr)
#define BAR0 BAR_ACCESS_GEN(bar0)
#define BAR2 BAR_ACCESS_GEN(bar2)
#define BAR4 BAR_ACCESS_GEN(bar4)
/* Setting WB and SDRAM pages */
#define SET_PG(which, num) \
do { \
BAR0[which >> WB_DWORD_ACC] = \
num; \
} while (0)
#define SET_SDRAM_PG(num) \
SET_PG(PCIE_CFG_REG_SDRAM_PG, num)
#define SET_WB_PG(num) \
SET_PG(PCIE_CFG_REG_WB_PG, num)
#endif
/*
* Copyright (C) 2014 LNLS (www.lnls.br)
* Author: Lucas Russo <lucas.russo@lnls.br>
*
* Released according to the GNU LGPL, version 3 or any later version.
*/
#include <unistd.h>
#include <string.h>
#include <stdio.h>
#include "ll_io.h"
#include "ll_io_pcie.h"
#include "ll_io_eth.h"
#include "hal_assert.h"
/* Undef ASSERT_ALLOC to avoid conflicting with other ASSERT_ALLOC */
#ifdef ASSERT_TEST
#undef ASSERT_TEST
#endif
#define ASSERT_TEST(test_boolean, err_str, err_goto_label) \
ASSERT_HAL_TEST(test_boolean, LL_IO, "[ll_io]", \
err_str, err_goto_label)
#ifdef ASSERT_ALLOC
#undef ASSERT_ALLOC
#endif
#define ASSERT_ALLOC(ptr, err_goto_label) \
ASSERT_HAL_ALLOC(ptr, LL_IO, "[ll_io]", \
llio_err_str(LLIO_ERR_ALLOC), \
err_goto_label)
#ifdef CHECK_ERR
#undef CHECK_ERR
#endif
#define CHECK_ERR(err, err_type) \
CHECK_HAL_ERR(err, LL_IO, "[ll_io]", \
llio_err_str (err_type))
/* Register Low-level operations to llio instance. Helpper function */
static llio_err_e _llio_register_ops (llio_type_e type, const llio_ops_t **llio_ops);
/* Creates a new instance of the Low-level I/O */
llio_t * llio_new (char *name, char *endpoint, llio_type_e type, int verbose)
{
assert (name);
assert (endpoint);
llio_t *self = (llio_t *) zmalloc (sizeof *self);
ASSERT_ALLOC(self, err_self_alloc);
/* Initialize Low-level IO type */
self->type = type;
self->dev_handler = NULL; /* This is set by the device functions */
self->name = strdup (name);
ASSERT_ALLOC(self->name, err_name_alloc);
self->verbose = verbose;
/* Initilialize llio_endpoint */
self->endpoint = llio_endpoint_new (endpoint);
ASSERT_ALLOC(self->endpoint, err_endpoint_alloc);
/* Initilialize llio_dev_info */
/* self->dev_info = llio_dev_info_new ();
ASSERT_ALLOC(self->dev_info, err_dev_info_alloc); Moved to dev_io */
/* Initilialize llio_ops */
/* self->ops = (llio_ops_t *) zmalloc (sizeof *self->ops); */
/* ASSERT_ALLOC(self->ops, err_ops_alloc); */
/* Nullify every ops field to indicate a non-implemented function */
/* *self->ops = (const llio_ops_t) {0}; */
/* Attach Low-level operation to instance of llio */
_llio_register_ops (type, &self->ops);
DBE_DEBUG (DBG_LL_IO | DBG_LVL_INFO, "[ll_io] Created instance of llio\n");
return self;
/*err_ops_alloc:
zlist_destroy(&self->dev_info->sdb); */
/* err_dev_info_alloc:
llio_endpoint_destroy (&self->endpoint); */
err_endpoint_alloc:
free (self->name);
err_name_alloc:
free (self);
err_self_alloc:
return NULL;
}
/* Destroy an instance of the Low-level I/O */
llio_err_e llio_destroy (llio_t **self_p)
{
assert (self_p);
if (*self_p) {
llio_t *self = *self_p;
/* Starting destructing by the last resource */
/* We must release the device structures by calling the
* registered function */
if (self->ops->release) {
/* TODO: remove self->endpoint parameter (unused!)*/
self->ops->release (self, self->endpoint);
}
/* llio_dev_info_destroy (&self->dev_info); Moved to dev_io */
llio_endpoint_destroy (&self->endpoint);
free (self->name);
free (self);
*self_p = NULL;
}
return LLIO_SUCCESS;
}
llio_err_e llio_set_endpoint (llio_t *self, const char *name)
{
return llio_endpoint_set (self->endpoint, name);
}
llio_err_e llio_get_endpoint (llio_t *self, char **name)
{
return llio_endpoint_get (self->endpoint, name);
}
/**************** Helper Functions ***************/
/* Register Low-level operations to llio instance. Helpper function */
static llio_err_e _llio_register_ops (llio_type_e type, const llio_ops_t **ops)
{
switch (type) {
case GENERIC_DEV:
*ops = NULL;
return LLIO_ERR_INV_FUNC_PARAM;
case PCIE_DEV:
*ops = &llio_ops_pcie;
break;
case ETH_DEV:
*ops = NULL;
return LLIO_ERR_INV_FUNC_PARAM;
default:
*ops = NULL;
return LLIO_ERR_INV_FUNC_PARAM;
}
DBE_DEBUG (DBG_LL_IO | DBG_LVL_INFO, "[ll_io] Ops set\n");
return LLIO_SUCCESS;
}
/********* Low-level generic methods API *********/
#define CHECK_FUNC(func_p) \
do { \
if(func_p == NULL) { \
DBE_DEBUG (DBG_LL_IO | DBG_LVL_ERR, \
"[ll_io] %s\n", \
llio_err_str (LLIO_ERR_FUNC_NOT_IMPL)); \
return -LLIO_ERR_FUNC_NOT_IMPL; \
} \
} while(0)
/* Declare wrapper for all LLIO functions API */
#define LLIO_FUNC_WRAPPER(func_name, ...) \
{ \
assert (self); \
assert (self->ops); \
CHECK_FUNC (self->ops->func_name); \
return self->ops->func_name (self, ##__VA_ARGS__); \
}
/**** Open device ****/
int llio_open (llio_t *self, llio_endpoint_t *endpoint)
LLIO_FUNC_WRAPPER (open, endpoint)
/**** Release device ****/
int llio_release (llio_t *self, llio_endpoint_t *endpoint)
LLIO_FUNC_WRAPPER (release, endpoint)
/**** Read data from device ****/
ssize_t llio_read_16 (llio_t *self, loff_t offs, uint16_t *data)
LLIO_FUNC_WRAPPER (read_16, offs, data)
ssize_t llio_read_32 (llio_t *self, loff_t offs, uint32_t *data)
LLIO_FUNC_WRAPPER (read_32, offs, data)
ssize_t llio_read_64 (llio_t *self, loff_t offs, uint64_t *data)
LLIO_FUNC_WRAPPER (read_64, offs, data)
/**** Write data to device ****/
ssize_t llio_write_16 (llio_t *self, loff_t offs, const uint16_t *data)
LLIO_FUNC_WRAPPER (write_16, offs, data)
ssize_t llio_write_32 (llio_t *self, loff_t offs, const uint32_t *data)
LLIO_FUNC_WRAPPER (write_32, offs, data)
ssize_t llio_write_64 (llio_t *self, loff_t offs, const uint64_t *data)
LLIO_FUNC_WRAPPER (write_64, offs, data)
/**** Read data block from device function pointer, size in bytes ****/
ssize_t llio_read_block (llio_t *self, loff_t offs, size_t size, uint32_t *data)
LLIO_FUNC_WRAPPER (read_block, offs, size, data)
/**** Write data block from device function pointer, size in bytes ****/
ssize_t llio_write_block (llio_t *self, loff_t offs, size_t size, const uint32_t *data)
LLIO_FUNC_WRAPPER (write_block, offs, size, data)
/**** Read data block via DMA from device, size in bytes ****/
ssize_t llio_read_dma (llio_t *self, loff_t offs, size_t size, uint32_t *data)
LLIO_FUNC_WRAPPER (read_dma, offs, size, data)
/**** Write data block via DMA from device, size in bytes ****/
ssize_t llio_write_dma (llio_t *self, loff_t offs, size_t size, const uint32_t *data)
LLIO_FUNC_WRAPPER (write_dma, offs, size, data)
/**** Read device information function pointer ****/
/* int llio_read_info (llio_t *self, llio_dev_info_t *dev_info)
LLIO_FUNC_WRAPPER (read_info, dev_info) Moved to dev_io */
/*
* Copyright (C) 2014 LNLS (www.lnls.br)
* Author: Lucas Russo <lucas.russo@lnls.br>
*
* Released according to the GNU LGPL, version 3 or any later version.
*/
#ifndef _LL_IO_H_
#define _LL_IO_H_
#include <inttypes.h>
#include <sys/types.h>
#include <stdbool.h>
#include "czmq.h"
#include "ll_io_endpoint.h"
#include "ll_io_dev_info.h"
#include "ll_io_err.h"
/* Device type */
enum _llio_type_e {
GENERIC_DEV = 0,
PCIE_DEV = 1,
ETH_DEV,
INVALID_DEV
};
struct _llio_ops_t;
/* Main class object */
struct _llio_t {
enum _llio_type_e type; /* Device type (PCIe, Ethnernet, or other) */
void *dev_handler; /* Generic pointer to a device handler. This
must be cast to a specific type by the
devices functions */
char *name; /* Identification of this llio instance */
int verbose; /* Print activity to stdout */
/* Endpoint to connect to */
struct _llio_endpoint_t *endpoint;
/* SDB device info */
/* struct _llio_dev_info_t *dev_info; Moved to dev_io */
/* Device operations */
const struct _llio_ops_t *ops;
};
/* Open device function pointer */
typedef int (*open_fp)(struct _llio_t *self, struct _llio_endpoint_t *endpoint);
/* Release device function pointer */
typedef int (*release_fp)(struct _llio_t *self, struct _llio_endpoint_t *endpoint);
/* Read data from device function pointers */
typedef ssize_t (*read_16_fp)(struct _llio_t *self, loff_t offs, uint16_t *data);
typedef ssize_t (*read_32_fp)(struct _llio_t *self, loff_t offs, uint32_t *data);
typedef ssize_t (*read_64_fp)(struct _llio_t *self, loff_t offs, uint64_t *data);
/* Write data to device function pointers */
typedef ssize_t (*write_16_fp)(struct _llio_t *self, loff_t offs, const uint16_t *data);
typedef ssize_t (*write_32_fp)(struct _llio_t *self, loff_t offs, const uint32_t *data);
typedef ssize_t (*write_64_fp)(struct _llio_t *self, loff_t offs, const uint64_t *data);
/* Read data block from device function pointer, size in bytes */
typedef ssize_t (*read_block_fp)(struct _llio_t *self, loff_t offs, size_t size, uint32_t *data);
/* Write data block from device function pointer, size in bytes */
typedef ssize_t (*write_block_fp)(struct _llio_t *self, loff_t offs, size_t size, const uint32_t *data);
/* Read data block via DMA from device function pointer, size in bytes */
typedef ssize_t (*read_dma_fp)(struct _llio_t *self, loff_t offs, size_t size, uint32_t *data);
/* Write data block via DMA from device function pointer, size in bytes */
typedef ssize_t (*write_dma_fp)(struct _llio_t *self, loff_t offs, size_t size, const uint32_t *data);
/* Read device information function pointer */
/* typedef int (*read_info_fp)(struct _llio_t *self, struct _llio_dev_info_t *dev_info); moved to dev_io */
struct _llio_ops_t {
open_fp open; /* Open device */
release_fp release; /* Release device */
read_16_fp read_16; /* Read 16-bit data */
read_32_fp read_32; /* Read 32-bit data */
read_64_fp read_64; /* Read 64-bit data */
write_16_fp write_16; /* Write 16-bit data */
write_32_fp write_32; /* Write 32-bit data */
write_64_fp write_64; /* Write 64-bit data */
read_block_fp read_block; /* Read arbitrary block size data,
parameter size in bytes */
write_block_fp write_block; /* Write arbitrary block size data,
parameter size in bytes */
read_dma_fp read_dma; /* Read arbitrary block size data via DMA,
parameter size in bytes */
write_dma_fp write_dma; /* Write arbitrary block size data via DMA,
parameter size in bytes */
/*read_info_fp read_info; Moved to dev_io */ /* Read device information data */
};
/* Opaque llio_type_e enum */
typedef enum _llio_type_e llio_type_e;
/* Opaque class structure */
typedef struct _llio_t llio_t;
/* Opaque llio_ops structure */
typedef struct _llio_ops_t llio_ops_t;
/***************** Our methods *****************/
/* Creates a new instance of the Low-level I/O */
llio_t * llio_new (char *name, char *endpoint, llio_type_e type, int verbose);
/* Destroy an instance of the Low-level I/O */
llio_err_e llio_destroy (llio_t **self_p);
/* Sets an endpoint in case it was not done in llio_new() */
llio_err_e llio_set_endpoint (llio_t *self, const char *name);
/* Gets endpoint from name from instance of llio_endpoint */
llio_err_e llio_get_endpoint (llio_t *self, char **name);
/* Register Low-level operations to llio instance. This probably is not suitable
* to be part of the API */
/* llio_err_e llio_register_ops (llio_t *self, llio_ops_t *llio_ops); */
/********* Low-level generic methods API *********/
/* Open device */
int llio_open (llio_t *self, llio_endpoint_t *endpoint);
/* Release device */
int llio_release (llio_t *self, llio_endpoint_t *endpoint);
/* Read data from device */
ssize_t llio_read_16 (llio_t *self, loff_t offs, uint16_t *data);
ssize_t llio_read_32 (llio_t *self, loff_t offs, uint32_t *data);
ssize_t llio_read_64 (llio_t *self, loff_t offs, uint64_t *data);
/* Write data to device */
ssize_t llio_write_16 (llio_t *self, loff_t offs, const uint16_t *data);
ssize_t llio_write_32 (llio_t *self, loff_t offs, const uint32_t *data);
ssize_t llio_write_64 (llio_t *self, loff_t offs, const uint64_t *data);
/* Read data block from device, size in bytes */
ssize_t llio_read_block (llio_t *self, loff_t offs, size_t size, uint32_t *data);
/* Write data block from device, size in bytes */
ssize_t llio_write_block (llio_t *self, loff_t offs, size_t size, const uint32_t *data);
/* Read data block via DMA from device, size in bytes */
ssize_t llio_read_dma (llio_t *self, loff_t offs, size_t size, uint32_t *data);
/* Write data block via DMA from device, size in bytes */
ssize_t llio_write_dma (llio_t *self, loff_t offs, size_t size, const uint32_t *data);
/* Read device information */
/* int llio_read_info (llio_t *self, llio_dev_info_t *dev_info); Moved to dev_io */
#endif
include hal/ll_io/ops/ops.mk
ll_io_DIR = hal/ll_io
# Here we call <output_name>_core_OBJS as we need to add
# more objects to this target. This is done in the hal.mk
# makefile
ll_io_OBJS = $(ll_io_DIR)/ll_io.o \
$(ll_io_DIR)/ll_io_endpoint.o \
$(ll_io_DIR)/ll_io_dev_info.o \
$(ll_io_DIR)/ll_io_err.o \
$(ll_io_ops_OBJS)
ll_io_INCLUDE_DIRS = $(ll_io_DIR) $(ll_io_ops_DIR)
/*
* Copyright (C) 2014 LNLS (www.lnls.br)
* Author: Lucas Russo <lucas.russo@lnls.br>
*
* Released according to the GNU LGPL, version 3 or any later version.
*/
#include <string.h>
#include <stdio.h>
#include "ll_io_dev_info.h"
#include "hal_assert.h"
/* Undef ASSERT_ALLOC to avoid conflicting with other ASSERT_ALLOC */
#ifdef ASSERT_TEST
#undef ASSERT_TEST
#endif
#define ASSERT_TEST(test_boolean, err_str, err_goto_label) \
ASSERT_HAL_TEST(test_boolean, LL_IO, "ll_io_dev_info", \
err_str, err_goto_label)
#ifdef ASSERT_ALLOC
#undef ASSERT_ALLOC
#endif
#define ASSERT_ALLOC(ptr, err_goto_label) \
ASSERT_HAL_ALLOC(ptr, LL_IO, "ll_io_dev_info", \
llio_err_str(LLIO_ERR_ALLOC), \
err_goto_label)
#ifdef CHECK_ERR
#undef CHECK_ERR
#endif
#define CHECK_ERR(err, err_type) \
CHECK_HAL_ERR(err, LL_IO, "ll_io_dev_info", \
llio_err_str (err_type))
/* Creates a new instance of Device Information */
llio_dev_info_t * llio_dev_info_new ()
{
llio_dev_info_t *self = (llio_dev_info_t *) zmalloc (sizeof *self);
ASSERT_ALLOC(self, err_self_alloc);
/* Initilialize llio_dev_info */
/* Put some default values as these are going to be filled
later by read_dev_info() */
self->sdb_addr = 0x0;
self->parsed = false;
self->sdb = zlist_new (); /* HASH!? */
ASSERT_ALLOC(self->sdb, err_sdb_alloc);
return self;
err_sdb_alloc:
free (self);
err_self_alloc:
return NULL;
}
/* Destroy an instance of the Device Information */
llio_err_e llio_dev_info_destroy (llio_dev_info_t **self_p)
{
assert (self_p);
if (*self_p) {
llio_dev_info_t *self = *self_p;
/* Starting destructing by the last resource */
zlist_destroy (&self->sdb);
free (self);
*self_p = NULL;
}
return LLIO_SUCCESS;
}
/*
* Copyright (C) 2014 LNLS (www.lnls.br)
* Author: Lucas Russo <lucas.russo@lnls.br>
*
* Released according to the GNU LGPL, version 3 or any later version.
*/
#ifndef _LL_IO_DEV_INFO_H_
#define _LL_IO_DEV_INFO_H_
#include <inttypes.h>
#include <sys/types.h>
#include <stdbool.h>
#include "czmq.h"
#include "ll_io_dev_info.h"
#include "ll_io_err.h"
/* This hold the SDB structures of the device */
struct _llio_dev_info_t {
loff_t sdb_addr; /* Location of the SDB structures in device */
bool parsed; /* True if device was already parsed */
zlist_t *sdb; /* List holding the SDB structures of the device */
};
/* Opaque llio_dev_info structure */
typedef struct _llio_dev_info_t llio_dev_info_t;
/***************** Our methods *****************/
/* Creates a new instance of Device Information */
llio_dev_info_t * llio_dev_info_new ();
/* Destroy an instance of the Device Information */
llio_err_e llio_dev_info_destroy (llio_dev_info_t **self_p);
#endif
/*
* Copyright (C) 2014 LNLS (www.lnls.br)
* Author: Lucas Russo <lucas.russo@lnls.br>
*
* Released according to the GNU LGPL, version 3 or any later version.
*/
#include <unistd.h>
#include <string.h>
#include <stdio.h>
#include "ll_io_endpoint.h"
#include "hal_assert.h"
/* Undef ASSERT_ALLOC to avoid conflicting with other ASSERT_ALLOC */
#ifdef ASSERT_TEST
#undef ASSERT_TEST
#endif
#define ASSERT_TEST(test_boolean, err_str, err_goto_label) \
ASSERT_HAL_TEST(test_boolean, LL_IO, "ll_io_endpoint", \
err_str, err_goto_label)
#ifdef ASSERT_ALLOC
#undef ASSERT_ALLOC
#endif
#define ASSERT_ALLOC(ptr, err_goto_label) \
ASSERT_HAL_ALLOC(ptr, LL_IO, "ll_io_endpoint", \
llio_err_str(LLIO_ERR_ALLOC), \
err_goto_label)
#ifdef CHECK_ERR
#undef CHECK_ERR
#endif
#define CHECK_ERR(err, err_type) \
CHECK_HAL_ERR(err, LL_IO, "ll_io_endpoint", \
llio_err_str (err_type))
static llio_err_e _llio_endpoint_set (llio_endpoint_t *self, const char *name);
static llio_err_e _llio_endpoint_get (llio_endpoint_t *self, char **endpoint);
/* Creates a new instance of the Endpoint*/
llio_endpoint_t * llio_endpoint_new (const char *endpoint)
{
llio_endpoint_t *self = (llio_endpoint_t *) zmalloc (sizeof *self);
ASSERT_ALLOC(self, err_self_alloc);
/* Initilialize llio_endpoint */
self->opened = false;
llio_err_e err = _llio_endpoint_set (self, endpoint);
ASSERT_TEST(err==LLIO_SUCCESS, llio_err_str(err), err_name_alloc);
return self;
err_name_alloc:
free (self);
err_self_alloc:
return NULL;
}
/* Destroy an instance of the Endpoint */
llio_err_e llio_endpoint_destroy (llio_endpoint_t **self_p)
{
assert (self_p);
if (*self_p) {
llio_endpoint_t *self = *self_p;
/* Starting destructing by the last resource */
free (self->name);
free (self);
*self_p = NULL;
}
return LLIO_SUCCESS;
}
/* Register endpoint to llio instance */
llio_err_e llio_endpoint_set (llio_endpoint_t *self, const char *name)
{
assert (self);
return _llio_endpoint_set (self, name);
}
/* Get endpoint from name from instance of llio_endpoint */
llio_err_e llio_endpoint_get (llio_endpoint_t *self, char **endpoint)
{
assert (self);
return _llio_endpoint_get (self, endpoint);
}
/**************** Helper Functions ***************/
static llio_err_e _llio_endpoint_set (llio_endpoint_t *self, const char *name)
{
if (self->opened) {
return LLIO_ERR_SET_ENDP;
}
if (name) {
if (self->name) {
free (self->name);
}
self->name = strdup (name);
ASSERT_ALLOC(self->name, err_name_alloc);
}
return LLIO_SUCCESS;
/* FIXME Remove goto label as it doesn't enhance anything,
* as we have only one pssible chance of error */
err_name_alloc:
return LLIO_ERR_ALLOC;
}
/* Get endpoint from name from instance of llio_endpoint */
static llio_err_e _llio_endpoint_get (llio_endpoint_t *self, char **endpoint)
{
*endpoint = strdup (self->name);
ASSERT_ALLOC(*endpoint, err_alloc);
return LLIO_SUCCESS;
err_alloc:
return LLIO_ERR_ALLOC;
}
/*
* Copyright (C) 2014 LNLS (www.lnls.br)
* Author: Lucas Russo <lucas.russo@lnls.br>
*
* Released according to the GNU LGPL, version 3 or any later version.
*/
#ifndef _LL_IO_ENDPOINT_H_
#define _LL_IO_ENDPOINT_H_
#include <inttypes.h>
#include <stdbool.h>
#include "czmq.h"
#include "ll_io_err.h"
/* Device endpoint */
struct _llio_endpoint_t {
bool opened; /* True if device if already opened */
char *name; /* Name of the endpoint, e.g., "/dev/fpga0"
and "tcp://192.168.0.100:5556" */
};
/* Opaque llio_endpoint structure */
typedef struct _llio_endpoint_t llio_endpoint_t;
/***************** Our methods *****************/
/* Creates a new instance of the Endpoint*/
llio_endpoint_t * llio_endpoint_new (const char *endpoint);
/* Destroy an instance of the Endpoint */
llio_err_e llio_endpoint_destroy (llio_endpoint_t **self_p);
/* Set endpoint to llio instance in case it was not done in llio_endpoint_new() */
llio_err_e llio_endpoint_set (llio_endpoint_t *self, const char *endpoint);
/* Get endpoint from name from instance of llio_endpoint */
llio_err_e llio_endpoint_get (llio_endpoint_t *self, char **endpoint);
#endif
/*
* Copyright (C) 2014 LNLS (www.lnls.br)
* Author: Lucas Russo <lucas.russo@lnls.br>
*
* Released according to the GNU LGPL, version 3 or any later version.
*/
/* Error definitions and output stringification based on the work available
* at the libsllp project repository: https://github.com/brunoseivam/libsllp */
#include "ll_io_err.h"
static const char *llio_err [LLIO_ERR_END] =
{
[LLIO_SUCCESS] = "Success",
[LLIO_ERR_ALLOC] = "Could not allocate memory",
[LLIO_ERR_FUNC_NOT_IMPL] = "Function not implemented",
[LLIO_ERR_INV_FUNC_PARAM] = "Invalid function parameter",
[LLIO_ERR_SET_ENDP] = "Could not change enpoint (device opened)",
[LLIO_ERR_DEV_CLOSE] = "Could not close device appropriately"
};
/* Convert enumeration type to string */
const char * llio_err_str (llio_err_e err)
{
return llio_err [err];
}
/*
* Copyright (C) 2014 LNLS (www.lnls.br)
* Author: Lucas Russo <lucas.russo@lnls.br>
*
* Released according to the GNU LGPL, version 3 or any later version.
*/
/* Error definitions and output stringification based on the work available
* at the libsllp project repository: https://github.com/brunoseivam/libsllp */
#ifndef _LLIO_ERR_H_
#define _LLIO_ERR_H_
enum _llio_err_e
{
LLIO_SUCCESS = 0, /* No error */
LLIO_ERR_ALLOC, /* Could not allocate memory */
LLIO_ERR_FUNC_NOT_IMPL, /* Function not implemented */
LLIO_ERR_INV_FUNC_PARAM, /* Invalid function parameter */
LLIO_ERR_SET_ENDP, /* Could not set endpoint (device already opened)*/
LLIO_ERR_DEV_CLOSE, /* Error closing a device */
LLIO_ERR_END /* End of enum marker */
};
typedef enum _llio_err_e llio_err_e;
/* Convert enumeration type to string */
const char * llio_err_str (llio_err_e err);
#endif
/*
* Copyright (C) 2014 LNLS (www.lnls.br)
* Author: Lucas Russo <lucas.russo@lnls.br>
*
* Released according to the GNU LGPL, version 3 or any later version.
*/
#include "ll_io_eth.h"
/*
* Copyright (C) 2014 LNLS (www.lnls.br)
* Author: Lucas Russo <lucas.russo@lnls.br>
*
* Released according to the GNU LGPL, version 3 or any later version.
*/
#ifndef _LL_IO_ETH_H_
#define _LL_IO_ETH_H_
#include "ll_io.h"
extern const llio_ops_t llio_ops_eth;
#endif
This diff is collapsed.
/*
* Copyright (C) 2014 LNLS (www.lnls.br)
* Author: Lucas Russo <lucas.russo@lnls.br>
*
* Released according to the GNU LGPL, version 3 or any later version.
*/
#ifndef _LL_IO_PCIE_H_
#define _LL_IO_PCIE_H_
#include "ll_io.h"
#include "hw/pcie_regs.h"
#include "lib/pciDriver.h"
/* Default value for Wishbone access granularity */
/* For our FPGA firmware, Wishbone is accesses via a 64-bit BAR */
#ifndef WB_ACC
#define WB_ACC WB_QWORD_ACC
#endif
/* For use by llio_t general structure */
extern const llio_ops_t llio_ops_pcie;
/* Device endpoint */
struct _llio_dev_pcie_t {
pd_device_t *dev; /* PCIe device handler */
uint32_t *bar0; /* PCIe BAR0 */
uint32_t *bar2; /* PCIe BAR2 */
uint64_t *bar4; /* PCIe BAR4 */
};
/* Opaque llio_dev_pcie structure */
typedef struct _llio_dev_pcie_t llio_dev_pcie_t;
/***************** Our methods *****************/
/* Creates a new instance of the Endpoint*/
llio_dev_pcie_t * llio_dev_pcie_new (char *dev_entry);
/* Destroy an instance of the Endpoint */
llio_err_e llio_dev_pcie_destroy (llio_dev_pcie_t **self_p);
#endif
ll_io_ops_DIR = hal/ll_io/ops
ll_io_ops_OBJS = $(ll_io_ops_DIR)/ll_io_pcie.o \
$(ll_io_ops_DIR)/ll_io_eth.o
ll_io_ops_INCLUDE_DIRS = $(ll_io_ops_DIR)
/*
* Copyright (C) 2014 LNLS (www.lnls.br)
* Author: Lucas Russo <lucas.russo@lnls.br>
*
* Released according to the GNU LGPL, version 3 or any later version.
*/
#include "exp_msg_zmq.h"
#include "hal_assert.h"
/* Undef ASSERT_ALLOC to avoid conflicting with other ASSERT_ALLOC */
#ifdef ASSERT_TEST
#undef ASSERT_TEST
#endif
#define ASSERT_TEST(test_boolean, err_str, err_goto_label) \
ASSERT_HAL_TEST(test_boolean, MSG, "[exp_msg:zmq]", \
err_str, err_goto_label)
#ifdef ASSERT_ALLOC
#undef ASSERT_ALLOC
#endif
#define ASSERT_ALLOC(ptr, err_goto_label) \
ASSERT_HAL_ALLOC(ptr, MSG, "[exp_msg:zmq]", \
msg_err_str(MSG_ERR_ALLOC), \
err_goto_label)
#ifdef CHECK_ERR
#undef CHECK_ERR
#endif
#define CHECK_ERR(err, err_type) \
CHECK_HAL_ERR(err, MSG, "[exp_msg:zmq]", \
msg_err_str (err_type))
/*
* Copyright (C) 2014 LNLS (www.lnls.br)
* Author: Lucas Russo <lucas.russo@lnls.br>
*
* Released according to the GNU LGPL, version 3 or any later version.
*/
#ifndef _EXP_MSG_ZMQ_H_
#define _EXP_MSG_ZMQ_H_
#include <czmq.h>
struct _exp_msg_zmq_t {
zmsg_t **msg;
zframe_t *reply_to;
};
typedef struct _exp_msg_zmq_t exp_msg_zmq_t;
#endif
/*
* Copyright (C) 2014 LNLS (www.lnls.br)
* Author: Lucas Russo <lucas.russo@lnls.br>
*
* Released according to the GNU LGPL, version 3 or any later version.
*/
#include <exp_ops_codes.h>
/*
* Copyright (C) 2014 LNLS (www.lnls.br)
* Author: Lucas Russo <lucas.russo@lnls.br>
*
* Released according to the GNU LGPL, version 3 or any later version.
*/
#ifndef _EXP_OPS_CODES_H_
#define _EXP_OPS_CODES_H_
#include <inttypes.h>
/* Messaging OPCODES */
#define EXP_OPS_OPCODE_SIZE (sizeof (uint32_t))
#define EXP_OPS_OPCODE_TYPE uint32_t
/* Messaging Reply OPCODES */
#define EXP_OPS_REPLY_SIZE (sizeof(uint32_t))
#define EXP_OPS_REPLY_TYPE uint32_t
#define EXP_OPS_REPLY_OK 0
#define EXP_OPS_REPLY_ERR 1
/* Messaging Return Codes */
#define EXP_OPS_RETURN_SIZE (sizeof(int32_t))
#define EXP_OPS_RETURN_TYPE int32_t
#endif
exp_ops_DIR = hal/msg/exp_ops
exp_ops_OBJS = $(exp_ops_DIR)/exp_msg_zmq.o
exp_ops_INCLUDE_DIRS = $(exp_ops_DIR)
include hal/msg/exp_ops/ops.mk
include hal/msg/smio_thsafe_ops/ops.mk
msg_DIR = hal/msg
msg_OBJS = $(msg_DIR)/msg_err.o \
$(exp_ops_OBJS) \
$(smio_thsafe_ops_OBJS)
msg_INCLUDE_DIRS = $(msg_DIR) \
$(exp_ops_INCLUDE_DIRS) \
$(smio_thsafe_ops_INCLUDE_DIRS)
/*
* Copyright (C) 2014 LNLS (www.lnls.br)
* Author: Lucas Russo <lucas.russo@lnls.br>
*
* Released according to the GNU LGPL, version 3 or any later version.
*/
/* Error definitions and output stringification based on the work available
* at the libsllp project repository: https://github.com/brunoseivam/libsllp */
#include "msg_err.h"
static const char *msg_err [MSG_ERR_END] =
{
[MSG_SUCCESS] = "Success",
[MSG_ERR] = "Messaging error",
[MSG_ERR_ALLOC] = "Could not allocate message",
[MSG_FUNC_NOT_IMPL] = "Function not implemented"
};
/* Convert enumeration type to string */
const char * msg_err_str (msg_err_e err)
{
return msg_err [err];
}
/*
* Copyright (C) 2014 LNLS (www.lnls.br)
* Author: Lucas Russo <lucas.russo@lnls.br>
*
* Released according to the GNU LGPL, version 3 or any later version.
*/
/* Error definitions and output stringification based on the work available
* at the libsllp project repository: https://github.com/brunoseivam/libsllp */
#ifndef _MSG_ERR_H_
#define _MSG_ERR_H_
enum _msg_err_e
{
MSG_SUCCESS = 0, /* No error */
MSG_ERR, /* Generic messaging error */
MSG_ERR_ALLOC, /* Could not allocate message */
MSG_FUNC_NOT_IMPL, /* Function not implemented */
MSG_ERR_END
};
typedef enum _msg_err_e msg_err_e;
/* Convert enumeration type to string */
const char * msg_err_str (msg_err_e err);
#endif
smio_thsafe_ops_DIR = hal/msg/smio_thsafe_ops
smio_thsafe_ops_OBJS = $(smio_thsafe_ops_DIR)/smio_thsafe_zmq_client.o \
$(smio_thsafe_ops_DIR)/smio_thsafe_zmq_server.o
smio_thsafe_ops_INCLUDE_DIRS = $(smio_thsafe_ops_DIR)
This diff is collapsed.
/*
* Copyright (C) 2014 LNLS (www.lnls.br)
* Author: Lucas Russo <lucas.russo@lnls.br>
*
* Released according to the GNU LGPL, version 3 or any later version.
*/
#ifndef _SMIO_THSAFE_ZMQ_H_
#define _SMIO_THSAFE_ZMQ_H_
#include "sm_io.h"
#include "sm_io_thsafe_codes.h"
/* For use by smio_t general structure */
extern const smio_thsafe_client_ops_t smio_thsafe_client_zmq_ops;
#endif
This diff is collapsed.
/*
* Copyright (C) 2014 LNLS (www.lnls.br)
* Author: Lucas Russo <lucas.russo@lnls.br>
*
* Released according to the GNU LGPL, version 3 or any later version.
*/
#ifndef _SMIO_THSAFE_ZMQ_H_
#define _SMIO_THSAFE_ZMQ_H_
#include "dev_io_core.h"
#include "sm_io_thsafe_codes.h"
/* For use by smio_t general structure */
extern const smio_thsafe_server_ops_t smio_thsafe_zmq_server_ops;
struct _zmq_server_args_t {
zmsg_t **msg;
void *reply_to;
};
typedef struct _zmq_server_args_t zmq_server_args_t;
#endif
/*
* Copyright (C) 2014 LNLS (www.lnls.br)
* Author: Lucas Russo <lucas.russo@lnls.br>
*
* Released according to the GNU LGPL, version 3 or any later version.
*
* This was taken from wrpc-sw reposytory at
* http://www.ohwr.org/projects/wrpc-sw/repository
*/
#ifndef _SDB_H_
#define _SDB_H_
#include <inttypes.h>
#define SDB_INTERCONNET 0x00
#define SDB_DEVICE 0x01
#define SDB_BRIDGE 0x02
#define SDB_EMPTY 0xFF
typedef struct pair64 {
uint32_t high;
uint32_t low;
} pair64_t;
struct sdb_empty {
int8_t reserved[63];
uint8_t record_type;
};
struct sdb_product {
pair64_t vendor_id;
uint32_t device_id;
uint32_t version;
uint32_t date;
int8_t name[19];
uint8_t record_type;
};
struct sdb_component {
pair64_t addr_first;
pair64_t addr_last;
struct sdb_product product;
};
struct sdb_device {
uint16_t abi_class;
uint8_t abi_ver_major;
uint8_t abi_ver_minor;
uint32_t bus_specific;
struct sdb_component sdb_component;
};
struct sdb_bridge {
pair64_t sdb_child;
struct sdb_component sdb_component;
};
struct sdb_interconnect {
uint32_t sdb_magic;
uint16_t sdb_records;
uint8_t sdb_version;
uint8_t sdb_bus_type;
struct sdb_component sdb_component;
};
typedef union sdb_record {
struct sdb_empty empty;
struct sdb_device device;
struct sdb_bridge bridge;
struct sdb_interconnect interconnect;
} sdb_record_t;
#endif
sdb_DIR = hal/sdb
# Here we call <output_name>_core_OBJS as we need to add
# more objects to this target. This is done in the hal.mk
# makefile
#sdb_core_OBJS = $(sdb_DIR)/sdb.o
sdb_INCLUDE_DIRS = $(sdb_DIR)
sdb_OUT = sdb
sm_io_fmc130m_4ch_DIR = hal/sm_io/modules/fmc130m_4ch
sm_io_fmc130m_4ch_OBJS = $(sm_io_fmc130m_4ch_DIR)/sm_io_fmc130m_4ch.o
sm_io_fmc130m_4ch_INCLUDE_DIRS = $(sm_io_fmc130m_4ch_DIR)
/*
* Copyright (C) 2014 LNLS (www.lnls.br)
* Author: Lucas Russo <lucas.russo@lnls.br>
*
* Released according to the GNU LGPL, version 3 or any later version.
*/
#include <stdlib.h>
#include "sm_io_fmc130m_4ch.h"
#include "sm_io.h"
#include "dev_io.h"
#include "hal_assert.h"
/* Undef ASSERT_ALLOC to avoid conflicting with other ASSERT_ALLOC */
#ifdef ASSERT_TEST
#undef ASSERT_TEST
#endif
#define ASSERT_TEST(test_boolean, err_str, err_goto_label) \
ASSERT_HAL_TEST(test_boolean, SM_IO, "[sm_io:fmc130m_4ch]",\
err_str, err_goto_label)
#ifdef ASSERT_ALLOC
#undef ASSERT_ALLOC
#endif
#define ASSERT_ALLOC(ptr, err_goto_label) \
ASSERT_HAL_ALLOC(ptr, SM_IO, "[sm_io:fmc130m_4ch]", \
smio_err_str(SMIO_ERR_ALLOC), \
err_goto_label)
#ifdef CHECK_ERR
#undef CHECK_ERR
#endif
#define CHECK_ERR(err, err_type) \
CHECK_HAL_ERR(err, SM_IO, "[sm_io:fmc130m_4ch]", \
smio_err_str (err_type))
/************************************************************/
/****************** Specific Operations ********************/
/************************************************************/
/* This does not belong to any public interface. It's meant to
* allow the do_ops() function to route the operations based on
* the opcode */
/* FIXME FIXME! We don't have to know our transport layer! */
#define BAR4_ADDR (4 << 28)
#define FMC1_ADDR 0x00310000
/* #define FMC2_ADDR 0x00310000 + ???? */
#define FMC_MONITOR_REG (0x010)
#define FMC1 1
#define FMC2 2
/************************************************************/
/************* Specific fmc_130m_4ch functions **************/
/************************************************************/
static void *_fmc130m_4ch_leds (void *owner, void *args)
{
assert (owner);
assert (args);
smio_t *self = (smio_t *) owner;
exp_msg_zmq_t *exp_msg = (exp_msg_zmq_t *) args;
assert (zmsg_size (*exp_msg->msg) > 0);
DBE_DEBUG (DBG_SM_IO | DBG_LVL_TRACE, "[sm_io:fmc130m_4ch] Calling _fmc130m_4ch_leds\n");
uint32_t leds = *(uint32_t *) zframe_data (zmsg_pop (*exp_msg->msg));
smio_thsafe_client_write_32 (self, BAR4_ADDR | FMC1_ADDR | FMC_MONITOR_REG,
&leds);
DBE_DEBUG (DBG_SM_IO | DBG_LVL_TRACE, "[sm_io:fmc130m_4ch_boot] Led write: 0x%08x\n",
leds);
/* Don't send any response, for now... */
return NULL;
}
/* #define EXP_FUNC_FMC130M_4CH_SIZE 1 */
#define FMC130M_4CH_OPCODE_LEDS 0
#define FMC130M_4CH_NAME_LEDS "leds"
#define FMC130M_4CH_OPCODE_END 1
const smio_exp_ops_t fmc130m_exp_ops [] = {
{.name = FMC130M_4CH_NAME_LEDS, .opcode = FMC130M_4CH_OPCODE_LEDS, .func_fp = _fmc130m_4ch_leds},
{.name = NULL, .opcode = 0, .func_fp = NULL} /* Must end with this NULL pattern */
};
/************************************************************/
/***************** Export methods functions *****************/
/************************************************************/
static smio_err_e _fmc130m_4ch_do_op (void *owner, void *msg);
/* Attach an instance of sm_io to dev_io function pointer */
smio_err_e fmc130m_4ch_attach (smio_t *self, devio_t *parent)
{
(void) self;
(void) parent;
return SMIO_ERR_FUNC_NOT_IMPL;
}
/* Deattach an instance of sm_io to dev_io function pointer */
smio_err_e fmc130m_4ch_deattach (smio_t *self)
{
(void) self;
return SMIO_ERR_FUNC_NOT_IMPL;
}
/* Export (register) sm_io to handle operations function pointer */
smio_err_e fmc130m_4ch_export_ops (smio_t *self,
const smio_exp_ops_t* smio_exp_ops)
{
(void) self;
(void) smio_exp_ops;
return SMIO_ERR_FUNC_NOT_IMPL;
}
/* Unexport (unregister) sm_io to handle operations function pointer */
smio_err_e fmc130m_4ch_unexport_ops (smio_t *self)
{
(void) self;
return SMIO_ERR_FUNC_NOT_IMPL;
}
/* Generic wrapper for receiving opcodes and arguments to specific funtions function pointer */
/* FIXME: Code repetition! _devio_do_smio_op () function does almost the same!!! */
smio_err_e _fmc130m_4ch_do_op (void *owner, void *msg)
{
(void) owner;
(void) msg;
return SMIO_ERR_FUNC_NOT_IMPL;
}
smio_err_e fmc130m_4ch_do_op (void *self, void *msg)
{
return _fmc130m_4ch_do_op (self, msg);
}
const smio_ops_t fmc130m_4ch_ops = {
.attach = fmc130m_4ch_attach, /* Attach sm_io instance to dev_io */
.deattach = fmc130m_4ch_deattach, /* Deattach sm_io instance to dev_io */
.export_ops = fmc130m_4ch_export_ops, /* Export sm_io operations to dev_io */
.unexport_ops = fmc130m_4ch_unexport_ops, /* Unexport sm_io operations to dev_io */
.do_op = fmc130m_4ch_do_op /* Generic wrapper for handling specific operations */
};
/************************************************************/
/****************** Bootstrap Operations ********************/
/************************************************************/
smio_err_e fmc130m_4ch_init (smio_t * self)
{
DBE_DEBUG (DBG_SM_IO | DBG_LVL_TRACE, "[sm_io:fmc130m_4ch] Initializing fmc130m_4ch\n");
smio_err_e err = SMIO_ERR_ALLOC;
self->id = FMC130M_4CH_SDB_DEVID;
self->name = strdup (FMC130M_4CH_SDB_NAME);
ASSERT_ALLOC(self->name, err_name_alloc);
/* Set SMIO ops pointers */
self->ops = &fmc130m_4ch_ops;
self->thsafe_client_ops = &smio_thsafe_client_zmq_ops;
self->exp_ops = fmc130m_exp_ops;
err = SMIO_SUCCESS;
err_name_alloc:
return err;
}
/* Destroy sm_io instance of fmc130m_4ch */
smio_err_e fmc130m_4ch_shutdown (smio_t *self)
{
DBE_DEBUG (DBG_SM_IO | DBG_LVL_TRACE, "[sm_io:fmc130m_4ch] Shutting down fmc130m_4ch\n");
self->exp_ops = NULL;
self->thsafe_client_ops = NULL;
self->ops = NULL;
free (self->name);
return SMIO_SUCCESS;
}
const smio_bootstrap_ops_t fmc130m_4ch_bootstrap_ops = {
.init = fmc130m_4ch_init,
.shutdown = fmc130m_4ch_shutdown
};
/*
* Copyright (C) 2014 LNLS (www.lnls.br)
* Author: Lucas Russo <lucas.russo@lnls.br>
*
* Released according to the GNU LGPL, version 3 or any later version.
*/
#ifndef _FMC130M_4CH_H_
#define _FMC130M_4CH_H_
#include "sm_io_bootstrap.h"
#include "smio_thsafe_zmq_client.h"
#include "exp_ops_codes.h"
/* Known modules IDs (from SDB records defined in FPGA) */
#define FMC130M_4CH_SDB_DEVID 0x7085ef15
#define FMC130M_4CH_SDB_NAME "FMC130M_4CH"
extern const smio_bootstrap_ops_t fmc130m_4ch_bootstrap_ops;
#endif
include hal/sm_io/modules/fmc130m_4ch/fmc130m_4ch.mk
sm_io_modules_DIR = hal/sm_io/modules
sm_io_modules_OBJS = $(sm_io_modules_DIR)/sm_io_mod_dispatch.o \
$(sm_io_fmc130m_4ch_OBJS)
sm_io_modules_INCLUDE_DIRS = $(sm_io_modules_DIR) \
$(sm_io_fmc130m_4ch_DIR)
/*
* Copyright (C) 2014 LNLS (www.lnls.br)
* Author: Lucas Russo <lucas.russo@lnls.br>
*
* Released according to the GNU LGPL, version 3 or any later version.
*/
#include "sm_io_mod_dispatch.h"
/* Include all available module we can handle */
#include "sm_io_fmc130m_4ch.h"
/* Table of all known modules we can handle */
const smio_mod_dispatch_t smio_mod_dispatch[MOD_DISPATCH_END] = {
[0] = { .id = FMC130M_4CH_SDB_DEVID,
.name = FMC130M_4CH_SDB_NAME,
.bootstrap_ops = &fmc130m_4ch_bootstrap_ops
}
};
/*
* Copyright (C) 2014 LNLS (www.lnls.br)
* Author: Lucas Russo <lucas.russo@lnls.br>
*
* Released according to the GNU LGPL, version 3 or any later version.
*/
#ifndef _MOD_DISPATCH_H_
#define _MOD_DISPATCH_H_
#include <inttypes.h>
/* #include "sm_io_bootstrap.h" */
/* Number of known specific modules that we can handle */
#define MOD_DISPATCH_END 1
struct _smio_bootstrap_ops_t;
struct _smio_mod_dispatch_t {
uint32_t id;
const char *name;
const struct _smio_bootstrap_ops_t *bootstrap_ops;
};
typedef struct _smio_mod_dispatch_t smio_mod_dispatch_t;
extern const smio_mod_dispatch_t
smio_mod_dispatch[MOD_DISPATCH_END];
#endif
/*
* Copyright (C) 2014 LNLS (www.lnls.br)
* Author: Lucas Russo <lucas.russo@lnls.br>
*
* Released according to the GNU LGPL, version 3 or any later version.
*/
#include "sm_io.h"
#include "exp_ops_codes.h"
#include "hal_assert.h"
/* Undef ASSERT_ALLOC to avoid conflicting with other ASSERT_ALLOC */
#ifdef ASSERT_TEST
#undef ASSERT_TEST
#endif
#define ASSERT_TEST(test_boolean, err_str, err_goto_label) \
ASSERT_HAL_TEST(test_boolean, SM_IO, "[sm_io]", \
err_str, err_goto_label)
#ifdef ASSERT_ALLOC
#undef ASSERT_ALLOC
#endif
#define ASSERT_ALLOC(ptr, err_goto_label) \
ASSERT_HAL_ALLOC(ptr, SM_IO, "[sm_io]", \
smio_err_str(SMIO_ERR_ALLOC), \
err_goto_label)
#ifdef CHECK_ERR
#undef CHECK_ERR
#endif
#define CHECK_ERR(err, err_type) \
CHECK_HAL_ERR(err, SM_IO, "[sm_io]", \
smio_err_str (err_type))
#define CHECK_FUNC(func_p) \
do { \
if(func_p == NULL) { \
DBE_DEBUG (DBG_SM_IO | DBG_LVL_ERR, \
"[sm_io] %s\n", \
smio_err_str (SMIO_ERR_FUNC_NOT_IMPL)); \
return -SMIO_ERR_FUNC_NOT_IMPL; \
} \
} while(0)
/* Declare wrapper for all SMIO functions API */
#define SMIO_FUNC_WRAPPER(func_name, ...) \
{ \
assert (self); \
assert (self->thsafe_client_ops); \
CHECK_FUNC (self->thsafe_client_ops->func_name); \
return self->thsafe_client_ops->func_name (self, ##__VA_ARGS__); \
}
#define SMIO_FUNC_OPS_NOFAIL_WRAPPER(err, func_name, ...) \
do { \
if (self->ops && self->ops->func_name) { \
smio_err_e local_err = self->ops->func_name (self, ##__VA_ARGS__); \
err = (local_err != SMIO_ERR_FUNC_NOT_IMPL) ? \
local_err : err; \
} \
} while (0)
/************************************************************/
/**************** SMIO Ops wrapper functions ****************/
/************************************************************/
/* Attach an instance of sm_io to dev_io function pointer */
smio_err_e smio_attach (smio_t *self, struct _devio_t *parent)
{
assert (self);
smio_err_e err = SMIO_SUCCESS;
self->parent = parent;
SMIO_FUNC_OPS_NOFAIL_WRAPPER(err, attach, parent);
return err;
}
/* Deattach an instance of sm_io to dev_io function pointer */
smio_err_e smio_deattach (smio_t *self)
{
assert (self);
smio_err_e err = SMIO_SUCCESS;
self->parent = NULL;
SMIO_FUNC_OPS_NOFAIL_WRAPPER(err, deattach);
return SMIO_SUCCESS;
}
/* Export (Register) sm_io to handle specific operations */
smio_err_e smio_export_ops (smio_t *self, const smio_exp_ops_t* smio_exp_ops)
{
assert (self);
assert (smio_exp_ops);
/* FIXME: Dispatch table disp_table_insert_all implements almost the
* same code! Try to reuse it! */
const smio_exp_ops_t* smio_exp_ops_it = smio_exp_ops;
smio_err_e err = SMIO_SUCCESS;
/* FIXME: Iterator is not very good as it has to check an specific field */
for (smio_exp_ops_it = smio_exp_ops; smio_exp_ops_it->func_fp != NULL;
smio_exp_ops_it++) {
halutils_err_e herr = disp_table_insert (self->exp_ops_dtable,
smio_exp_ops_it->opcode, smio_exp_ops_it->func_fp);
if (herr != HALUTILS_SUCCESS) {
err = SMIO_ERR_EXPORT_OP;
goto err_export_op;
}
}
SMIO_FUNC_OPS_NOFAIL_WRAPPER(err, export_ops, smio_exp_ops);
err_export_op:
return err;
}
/* Unexport (unregister) sm_io to handle specific operations */
smio_err_e smio_unexport_ops (smio_t *self)
{
assert (self);
smio_err_e err = SMIO_SUCCESS;
halutils_err_e herr = disp_table_remove_all (self->exp_ops_dtable);
if (herr != HALUTILS_SUCCESS) {
err = SMIO_ERR_EXPORT_OP;
goto err_unexport_op;
}
SMIO_FUNC_OPS_NOFAIL_WRAPPER(err, unexport_ops);
err_unexport_op:
return err;
}
smio_err_e smio_do_op (void *owner, void *msg)
{
assert (owner);
assert (msg);
smio_t *self = (smio_t *) owner;
exp_msg_zmq_t *exp_msg = (exp_msg_zmq_t *) msg;
smio_err_e err = SMIO_SUCCESS;
/* TODO: The SMIO do_op must not modify the packet! We could pass a copy of the
* message to it, but we this is in the critical path! Evaluate the imapct
* of doing this */
SMIO_FUNC_OPS_NOFAIL_WRAPPER(err, do_op, msg);
ASSERT_TEST (err==SMIO_SUCCESS, "Error executing SMIO do_op ()",
err_do_op);
/* Our simple packet is composed of:
* frame 0: operation
* frame n: arguments*/
zframe_t *opcode = zmsg_pop (*exp_msg->msg);
err = (opcode == NULL) ? SMIO_ERR_WRONG_NARGS : SMIO_SUCCESS;
ASSERT_TEST(opcode != NULL, "Could not receive opcode", err_null_opcode);
if (zframe_size (opcode) != EXP_OPS_OPCODE_SIZE) {
DBE_DEBUG (DBG_SM_IO | DBG_LVL_ERR,
"[sm_io] Invalid opcode size received\n");
err = SMIO_ERR_WRONG_NARGS;
goto err_wrong_opcode_size;
}
uint32_t opcode_data = *(uint32_t *) zframe_data (opcode);
if (opcode_data > SMIO_MAX_OPS-1) {
DBE_DEBUG (DBG_SM_IO | DBG_LVL_ERR,
"[sm_io] Invalid opcode received\n");
err = SMIO_ERR_WRONG_NARGS;
goto err_invalid_opcode;
}
/* Do the actual work... */
disp_table_call (self->exp_ops_dtable, opcode_data, self, exp_msg);
err_invalid_opcode:
err_wrong_opcode_size:
zframe_destroy (&opcode);
err_null_opcode:
err_do_op:
/* Should reply_to field be zframe_t ** type ?*/
zframe_destroy (&exp_msg->reply_to);
zmsg_destroy (exp_msg->msg);
return err;
}
/************************************************************/
/************* SMIO thsafe wrapper functions **************/
/************************************************************/
/**** Open device ****/
int smio_thsafe_client_open (smio_t *self, llio_endpoint_t *endpoint)
SMIO_FUNC_WRAPPER (thsafe_client_open, endpoint)
/**** Release device ****/
int smio_thsafe_client_release (smio_t *self, llio_endpoint_t *endpoint)
SMIO_FUNC_WRAPPER (thsafe_client_release, endpoint)
/**** Read data from device ****/
ssize_t smio_thsafe_client_read_16 (smio_t *self, loff_t offs, uint16_t *data)
SMIO_FUNC_WRAPPER (thsafe_client_read_16, offs, data)
ssize_t smio_thsafe_client_read_32 (smio_t *self, loff_t offs, uint32_t *data)
SMIO_FUNC_WRAPPER (thsafe_client_read_32, offs, data)
ssize_t smio_thsafe_client_read_64 (smio_t *self, loff_t offs, uint64_t *data)
SMIO_FUNC_WRAPPER (thsafe_client_read_64, offs, data)
/**** Write data to device ****/
ssize_t smio_thsafe_client_write_16 (smio_t *self, loff_t offs, const uint16_t *data)
SMIO_FUNC_WRAPPER (thsafe_client_write_16, offs, data)
ssize_t smio_thsafe_client_write_32 (smio_t *self, loff_t offs, const uint32_t *data)
SMIO_FUNC_WRAPPER (thsafe_client_write_32, offs, data)
ssize_t smio_thsafe_client_write_64 (smio_t *self, loff_t offs, const uint64_t *data)
SMIO_FUNC_WRAPPER (thsafe_client_write_64, offs, data)
/**** Read data block from device function pointer, size in bytes ****/
ssize_t smio_thsafe_client_read_block (smio_t *self, loff_t offs, size_t size, uint32_t *data)
SMIO_FUNC_WRAPPER (thsafe_client_read_block, offs, size, data)
/**** Write data block from device function pointer, size in bytes ****/
ssize_t smio_thsafe_client_write_block (smio_t *self, loff_t offs, size_t size, const uint32_t *data)
SMIO_FUNC_WRAPPER (thsafe_client_write_block, offs, size, data)
/**** Read data block via DMA from device, size in bytes ****/
ssize_t smio_thsafe_client_read_dma (smio_t *self, loff_t offs, size_t size, uint32_t *data)
SMIO_FUNC_WRAPPER (thsafe_client_read_dma, offs, size, data)
/**** Write data block via DMA from device, size in bytes ****/
ssize_t smio_thsafe_client_write_dma (smio_t *self, loff_t offs, size_t size, const uint32_t *data)
SMIO_FUNC_WRAPPER (thsafe_client_write_dma, offs, size, data)
/**** Read device information function pointer ****/
/* int smio_thsafe_client_read_info (smio_t *self, llio_dev_info_t *dev_info)
SMIO_FUNC_WRAPPER (thsafe_client_read_info, dev_info) Moved to dev_io */
/*
* Copyright (C) 2014 LNLS (www.lnls.br)
* Author: Lucas Russo <lucas.russo@lnls.br>
*
* Released according to the GNU LGPL, version 3 or any later version.
*/
#ifndef _SM_IO_H_
#define _SM_IO_H_
#include <inttypes.h>
#include <sys/types.h>
#include <stdbool.h>
/* #include "dev_io_core.h" */
#include "ll_io.h"
#include "sm_io_err.h"
#include "exp_msg_zmq.h"
#include "sm_io_bootstrap.h"
#include "sm_io_mod_dispatch.h"
#include "mdp.h"
#include "dispatch_table.h"
/* Arbitrary number*/
#define SMIO_MAX_OPS 200
struct _devio_t;
struct _smio_ops_t;
struct _smio_thsafe_client_ops_t;
struct _smio_exp_ops_t;
/* Main class object that every sm_io must implement */
struct _smio_t {
uint32_t id; /* Unique identifier for this sm_io type. This must be
the same from the SDB ID */
char *name; /* Identification of this sm_io instance */
/* int verbose; */ /* Print activity to stdout */
mdp_worker_t *worker; /* zeroMQ Majordomo worker */
struct _devio_t *parent; /* Pointer back to parent dev_io */
zctx_t *ctx; /* Our context */
void *pipe; /* Pipe back to parent to exchange messages */
/* Specific SMIO operations dispatch table for exported operations */
disp_table_t *exp_ops_dtable;
/* Specific SMIO instance functions. This will be exported on SMIO startup */
const struct _smio_exp_ops_t *exp_ops;
/* Minimum set of methods that every sm_io instance must implement.
* This is thought as the interface to the world */
const struct _smio_ops_t *ops;
/* These operations must be used to access LLIO methods, as they are
* thread safe. The method's signatures are almost the same as the
* ones available in llio, changing the llio_t self pointer to a void
* pointer (socket to parent thread) */
const struct _smio_thsafe_client_ops_t *thsafe_client_ops;
};
/* Attach an instance of sm_io to dev_io function pointer */
typedef enum _smio_err_e (*attach_fp)(struct _smio_t *self, struct _devio_t *parent);
/* Deattach an instance of sm_io to dev_io function pointer */
typedef enum _smio_err_e (*deattach_fp)(struct _smio_t *self);
/* Export (register) sm_io to handle operations function pointer */
typedef enum _smio_err_e (*export_ops_fp)(struct _smio_t *self,
const struct _smio_exp_ops_t* smio_exp_ops);
/* Unexport (unregister) sm_io to handle operations function pointer */
typedef enum _smio_err_e (*unexport_ops_fp)(struct _smio_t *self);
/* Generic wrapper for receiving opcodes and arguments to specific funtions function pointer */
typedef enum _smio_err_e (*do_op_fp)(void *owner, void *msg);
struct _smio_ops_t {
attach_fp attach; /* Attach sm_io instance to dev_io */
deattach_fp deattach; /* Deattach sm_io instance to dev_io */
export_ops_fp export_ops; /* Export sm_io operations to dev_io */
unexport_ops_fp unexport_ops; /* Unexport sm_io operations to dev_io */
do_op_fp do_op; /* Generic wrapper for handling specific operations */
};
/* Open device */
typedef int (*thsafe_client_open_fp) (struct _smio_t *self, llio_endpoint_t *endpoint);
/* Release device */
typedef int (*thsafe_client_release_fp) (struct _smio_t *self, llio_endpoint_t *endpoint);
/* Read data from device */
typedef ssize_t (*thsafe_client_read_16_fp) (struct _smio_t *self, loff_t offs, uint16_t *data);
typedef ssize_t (*thsafe_client_read_32_fp) (struct _smio_t *self, loff_t offs, uint32_t *data);
typedef ssize_t (*thsafe_client_read_64_fp) (struct _smio_t *self, loff_t offs, uint64_t *data);
/* Write data to device */
typedef ssize_t (*thsafe_client_write_16_fp) (struct _smio_t *self, loff_t offs, const uint16_t *data);
typedef ssize_t (*thsafe_client_write_32_fp) (struct _smio_t *self, loff_t offs, const uint32_t *data);
typedef ssize_t (*thsafe_client_write_64_fp) (struct _smio_t *self, loff_t offs, const uint64_t *data);
/* Read data block from device, size in bytes */
typedef ssize_t (*thsafe_client_read_block_fp) (struct _smio_t *self, loff_t offs, size_t size, uint32_t *data);
/* Write data block from device, size in bytes */
typedef ssize_t (*thsafe_client_write_block_fp) (struct _smio_t *self, loff_t offs, size_t size, const uint32_t *data);
/* Read data block via DMA from device, size in bytes */
typedef ssize_t (*thsafe_client_read_dma_fp) (struct _smio_t *self, loff_t offs, size_t size, uint32_t *data);
/* Write data block via DMA from device, size in bytes */
typedef ssize_t (*thsafe_client_write_dma_fp) (struct _smio_t *self, loff_t offs, size_t size, const uint32_t *data);
/* Read device information */
/* typedef int (*thsafe_client_read_info_fp) (struct _smio_t *self, llio_dev_info_t *dev_info); Moved to dev_io */
struct _smio_thsafe_client_ops_t {
thsafe_client_open_fp thsafe_client_open; /* Open device */
thsafe_client_release_fp thsafe_client_release; /* Release device */
thsafe_client_read_16_fp thsafe_client_read_16; /* Read 16-bit data */
thsafe_client_read_32_fp thsafe_client_read_32; /* Read 32-bit data */
thsafe_client_read_64_fp thsafe_client_read_64; /* Read 64-bit data */
thsafe_client_write_16_fp thsafe_client_write_16; /* Write 16-bit data */
thsafe_client_write_32_fp thsafe_client_write_32; /* Write 32-bit data */
thsafe_client_write_64_fp thsafe_client_write_64; /* Write 64-bit data */
thsafe_client_read_block_fp thsafe_client_read_block; /* Read arbitrary block size data,
parameter size in bytes */
thsafe_client_write_block_fp thsafe_client_write_block; /* Write arbitrary block size data,
parameter size in bytes */
thsafe_client_read_dma_fp thsafe_client_read_dma; /* Read arbitrary block size data via DMA,
parameter size in bytes */
thsafe_client_write_dma_fp thsafe_client_write_dma; /* Write arbitrary block size data via DMA,
parameter size in bytes */
/*thsafe_client_read_info_fp thsafe_client_read_info; Moved to dev_io */ /* Read device information data */
};
struct _smio_exp_ops_t {
const char *name;
uint32_t opcode;
disp_table_func_fp func_fp;
};
/* Opaque class structure */
typedef struct _smio_t smio_t;
/* Opaque smio_ops structure */
typedef struct _smio_ops_t smio_ops_t;
/* Opaque llio_th_safe_ops structure */
typedef struct _smio_thsafe_client_ops_t smio_thsafe_client_ops_t;
/* smio exported interface function strcuture */
typedef struct _smio_exp_ops_t smio_exp_ops_t;
/***************** Our methods *****************/
/* Creates a new instance of the Low-level I/O */
/* smio_t * smio_new (uint32_t id, char *name, devio_t *parent); */
/* Destroy an instance of the Low-level I/O */
/* smio_err_e smio_destroy (smio_t **self_p); */
/************************************************************/
/**************** Smio OPS generic methods API **************/
/************************************************************/
/* Attach an instance of sm_io to dev_io function pointer */
smio_err_e smio_attach (smio_t *self, struct _devio_t *parent);
/* Deattach an instance of sm_io to dev_io function pointer */
smio_err_e smio_deattach (smio_t *self);
/* Export (Register) sm_io to handle specific operations */
smio_err_e smio_export_ops (smio_t *self, const smio_exp_ops_t* smio_exp_ops);
/* Unexport (unregister) sm_io to handle specific operations */
smio_err_e smio_unexport_ops (smio_t *self);
/* Handle the operation */
smio_err_e smio_do_op (void *owner, void *msg);
/************************************************************/
/***************** Thsafe generic methods API ***************/
/************************************************************/
/* Open device */
int smio_thsafe_client_open (smio_t *self, llio_endpoint_t *endpoint);
/* Release device */
int smio_thsafe_client_release (smio_t *self, llio_endpoint_t *endpoint);
/* Read data from device */
ssize_t smio_thsafe_client_read_16 (smio_t *self, loff_t offs, uint16_t *data);
ssize_t smio_thsafe_client_read_32 (smio_t *self, loff_t offs, uint32_t *data);
ssize_t smio_thsafe_client_read_64 (smio_t *self, loff_t offs, uint64_t *data);
/* Write data to device */
ssize_t smio_thsafe_client_write_16 (smio_t *self, loff_t offs, const uint16_t *data);
ssize_t smio_thsafe_client_write_32 (smio_t *self, loff_t offs, const uint32_t *data);
ssize_t smio_thsafe_client_write_64 (smio_t *self, loff_t offs, const uint64_t *data);
/* Read data block from device, size in bytes */
ssize_t smio_thsafe_client_read_block (smio_t *self, loff_t offs, size_t size, uint32_t *data);
/* Write data block from device, size in bytes */
ssize_t smio_thsafe_client_write_block (smio_t *self, loff_t offs, size_t size, const uint32_t *data);
/* Read data block via DMA from device, size in bytes */
ssize_t smio_thsafe_client_read_dma (smio_t *self, loff_t offs, size_t size, uint32_t *data);
/* Write data block via DMA from device, size in bytes */
ssize_t smio_thsafe_client_write_dma (smio_t *self, loff_t offs, size_t size, const uint32_t *data);
/* Read device information */
/* int smio_thsafe_client_read_info (smio_t *self, llio_dev_info_t *dev_info) */
#endif
include hal/sm_io/modules/modules.mk
sm_io_DIR = hal/sm_io
sm_io_OBJS = $(sm_io_DIR)/sm_io.o \
$(sm_io_DIR)/sm_io_bootstrap.o \
$(sm_io_DIR)/sm_io_err.o \
$(sm_io_DIR)/sm_io_thsafe_codes.o \
$(sm_io_modules_OBJS)
sm_io_INCLUDE_DIRS = $(sm_io_DIR) \
$(sm_io_modules_INCLUDE_DIRS)
This diff is collapsed.
/*
* Copyright (C) 2014 LNLS (www.lnls.br)
* Author: Lucas Russo <lucas.russo@lnls.br>
*
* Released according to the GNU LGPL, version 3 or any later version.
*/
#ifndef _SM_IO_BOOTSTRAP_H_
#define _SM_IO_BOOTSTRAP_H_
#include <inttypes.h>
/* #include "sm_io.h" */
/* #include "dev_io.h" */
#include "sm_io_err.h"
#include "czmq.h"
/* Foward declarations. We don't need to include the associated header files.
* The following should suffice */
struct _smio_t;
struct _devio_t;
/* Create instance of sm_io function pointer. This tells how to create
* such an object */
typedef smio_err_e (*smio_init_fp)(struct _smio_t *self);
/* Destroy instance of sm)io functuion pointer. This tells how to destroy
* such an object */
typedef smio_err_e (*smio_shutdown_fp)(struct _smio_t *self);
/* Main class object that every sm_io must implement */
struct _smio_bootstrap_ops_t {
smio_init_fp init;
smio_shutdown_fp shutdown;
};
typedef struct _smio_bootstrap_ops_t smio_bootstrap_ops_t;
/* Thread boot args structure */
struct _th_boot_args_t {
struct _devio_t *parent; /* Pointer back to devo parent */
uint32_t smio_id; /* ID of the SMIO instance */
char *broker; /* Endpoint to connect to broker */
char *service; /* (part of) the service name to be exported */
int verbose; /* Print trace information to stdout*/
void *priv; /* Pointer to a private strucutre to be passed
untouched by devio to the specific smio instace*/
};
typedef struct _th_boot_args_t th_boot_args_t;
/************************************************************/
/************************ Our methods ***********************/
/************************************************************/
void smio_startup (void *args, zctx_t *ctx, void *pipe);
struct _smio_t *smio_new (struct _devio_t *parent, struct _zctx_t *ctx, void *pipe,
char *broker, char *service, int verbose);
smio_err_e smio_destroy (struct _smio_t **self_p);
smio_err_e smio_loop (struct _smio_t *self);
#endif
/*
* Copyright (C) 2014 LNLS (www.lnls.br)
* Author: Lucas Russo <lucas.russo@lnls.br>
*
* Released according to the GNU LGPL, version 3 or any later version.
*/
/* Error definitions and output stringification based on the work available
* at the libsllp project repository: https://github.com/brunoseivam/libsllp */
#include "sm_io_err.h"
static const char *smio_err [SMIO_ERR_END] =
{
[SMIO_SUCCESS] = "Success",
[SMIO_ERR_ALLOC] = "Could not allocate memory",
[SMIO_ERR_FUNC_NOT_IMPL] = "Function not implemented",
[SMIO_ERR_OPCODE_NOT_SUPP] = "Opcode not supported",
[SMIO_ERR_WRONG_NARGS] = "Wrong number of arguments",
[SMIO_ERR_WRONG_PARAM] = "Wrong parameter value",
[SMIO_ERR_LLIO] = "Low-level I/O could not complete operation",
[SMIO_ERR_EXPORT_OP] = "Could not export function"
};
/* Convert enumeration type to string */
const char * smio_err_str (smio_err_e err)
{
return smio_err [err];
}
/*
* Copyright (C) 2014 LNLS (www.lnls.br)
* Author: Lucas Russo <lucas.russo@lnls.br>
*
* Released according to the GNU LGPL, version 3 or any later version.
*/
/* Error definitions and output stringification based on the work available
* at the libsllp project repository: https://github.com/brunoseivam/libsllp */
#ifndef _SMIO_ERR_H_
#define _SMIO_ERR_H_
enum _smio_err_e
{
SMIO_SUCCESS = 0, /* No error */
SMIO_ERR_ALLOC, /* Could not allocate memory */
SMIO_ERR_FUNC_NOT_IMPL, /* Function not implemented */
SMIO_ERR_OPCODE_NOT_SUPP, /* Opcode not supported */
SMIO_ERR_WRONG_NARGS, /* Wrong number of arguments */
SMIO_ERR_WRONG_PARAM, /* Wrong parameter value */
SMIO_ERR_LLIO, /* Low-level I/O could not complete operation */
SMIO_ERR_EXPORT_OP, /* Error exporting function */
SMIO_ERR_END /* End of enum marker */
};
typedef enum _smio_err_e smio_err_e;
/* Convert enumeration type to string */
const char * smio_err_str (smio_err_e err);
#endif
/*
* Copyright (C) 2014 LNLS (www.lnls.br)
* Author: Lucas Russo <lucas.russo@lnls.br>
*
* Released according to the GNU LGPL, version 3 or any later version.
*/
#include <sm_io_thsafe_codes.h>
const uint32_t thsafe_opcodes [THSAFE_OPCODE_END] = {
[0] = THSAFE_OPEN,
[1] = THSAFE_RELEASE,
[2] = THSAFE_READ_16,
[3] = THSAFE_READ_32,
[4] = THSAFE_READ_64,
[5] = THSAFE_WRITE_16,
[6] = THSAFE_WRITE_32,
[7] = THSAFE_WRITE_64,
[8] = THSAFE_READ_BLOCK,
[9] = THSAFE_WRITE_BLOCK,
[10] = THSAFE_READ_DMA,
[11] = THSAFE_WRITE_DMA
// [12] = THSAFE_READ_INFO
};
const uint32_t thsafe_reply_opcodes [THSAFE_REPLY_END] = {
[0] = THSAFE_OK,
[1] = THSAFE_ERR
};
This diff is collapsed.
#!/bin/bash
# Broker Endpoint
EXPECTED_ARGS=1
if [ "$(id -u)" != "0" ]
then
echo "This must be run as root"
exit 1
fi
if [ $# -ne $EXPECTED_ARGS ]
then
echo "Usage: `basename $0` {broker endpoint}"
exit 1;
fi
broker_endp=$1
# Launch Device Manager
./dev_mngr "ipc://"$broker_endp &
# Signal dev_mngr of a "new" PCIe device
killall -SIGUSR1 dev_mngr
# Change IPC permissions
chmod 777 $broker_endp
This diff is collapsed.
This diff is collapsed.
# Main Makefile for the pciDriver
#helpful in case of buildroot crosscompiling
ROOTDIR :=
CURDIR := $(shell pwd)
export SRCDIR := $(CURDIR)/src
all:
$(Q)$(MAKE) -C $(SRCDIR)
install:
$(Q)$(MAKE) -C $(SRCDIR) install
@echo "INSTALL 60-udev_fpga.rules"
-$(Q)install -m 644 etc/udev/rules.d/60-udev_fpga.rules $(ROOTDIR)/etc/udev/rules.d/
uninstall:
$(Q)$(MAKE) -C $(SRCDIR) uninstall
@echo "UNINSTALL 60-udev_fpga.rules"
-$(Q)rm -f $(ROOTDIR)/etc/udev/rules.d/60-udev_fpga.rules
clean:
@echo "Cleaning..."
-$(Q)$(MAKE) -C $(SRCDIR) clean
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
long pcidriver_ioctl(struct file *filp, unsigned int cmd, unsigned long arg);
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment