Commit ea4e3500 authored by Lucas Russo's avatar Lucas Russo

Merge branch 'refactor-2015-04-15' into devel

parents 2fefd370 4c510ada
[submodule "foreign/libbsmp"]
path = foreign/libbsmp
url = https://github.com/lerwys/libbsmp.git
url = https://github.com/lnls-dig/libbsmp.git
[submodule "foreign/pcie-driver"]
path = foreign/pcie-driver
url = https://github.com/lerwys/fpga_pcie_driver.git
url = https://github.com/lnls-dig/fpga_pcie_driver.git
[submodule "foreign/libmdp"]
path = foreign/libmdp
url = https://github.com/lerwys/majordomo.git
url = https://github.com/lnls-dig/majordomo.git
......@@ -55,8 +55,13 @@ PCIE_DRIVER_DIR = $(FOREIGN_DIR)/pcie-driver
PCIE_DRIVER_VER = $(shell uname -r)
DRIVER_OBJ = /lib/modules/$(PCIE_DRIVER_VER)/extra/pciDriver.ko
# Client library
LIBBPMCLIENT_DIR=src/libs/libbpmclient
# Project libraries
LIBERRHAND_DIR = src/libs/liberrhand
LIBCONVC_DIR = src/libs/libconvc
LIBHUTILS_DIR = src/libs/libhutils
LIBDISPTABLE_DIR = src/libs/libdisptable
LIBBPMCLIENT_DIR = src/libs/libbpmclient
LIBSDBFS_DIR = foreign/libsdbfs
# General C flags
CFLAGS = -std=gnu99 -O2
......@@ -112,8 +117,23 @@ ifeq ($(LOCAL_MSG_DBG),y)
CFLAGS_DEBUG += -DLOCAL_MSG_DBG=1
endif
ifeq ($(DBE_DBG),y)
CFLAGS_DEBUG += -DDBE_DBG=1
# To enable this option, use: make ERRHAND_DBG=y
ifneq ($(ERRHAND_DBG),)
CFLAGS_DEBUG += -DERRHAND_DBG=$(ERRHAND_DBG)
endif
# To enable this option use: make ERRHAND_MIN_LEVEL=DBG_MIN_TRACE
ifneq ($(ERRHAND_MIN_LEVEL),)
CFLAGS_DEBUG += -DERRHAND_MIN_LEVEL=$(ERRHAND_MIN_LEVEL)
endif
# To enable this option use: make ERRHAND_SUBSYS_ON='"(DBG_DEV_MNGR | \
# DBG_DEV_IO | DBG_SM_IO | DBG_LIB_CLIENT | DBG_SM_PR | DBG_SM_CH | DBG_LL_IO | DBG_HAL_UTILS)"'
#
# You can also OR the available subsytems to enable debug messages in just the
# those subsytems. See file errhand_opts.h for more information
ifneq ($(ERRHAND_SUBSYS_ON),)
CFLAGS_DEBUG += -DERRHAND_SUBSYS_ON=$(ERRHAND_SUBSYS_ON)
endif
# Debug flags -D<flasg_name>=<value>
......@@ -125,8 +145,15 @@ LDFLAGS_PLATFORM =
# Libraries
LIBS = -lm -lzmq -lczmq -lmdp -lpcidriver
# FIXME: make the project libraries easily interchangeable, specifying
# the lib only a single time
PROJECT_LIBS_NAME = liberrhand libconvc libhutils libdisptable libbpmclient libsdbfs
PROJECT_LIBS = -lerrhand -lconvc -lhutils -ldisptable -lbpmclient -lsdbfs
# General library flags -L<libdir>
LFLAGS =
LFLAGS = -Lsrc/libs/liberrhand -Lsrc/libs/libconvc -Lsrc/libs/libhutils \
-Lsrc/libs/libdisptable -Lsrc/libs/libbpmclient -Lforeign/libsdbfs
# Specific platform objects
OBJS_PLATFORM =
......@@ -135,13 +162,33 @@ OBJS_PLATFORM =
SRC_DIR = src
# Include other Makefiles as needed here
include $(SRC_DIR)/hal/hal.mk
include $(SRC_DIR)/ll_io/ll_io.mk
include $(SRC_DIR)/sm_io/sm_io.mk
include $(SRC_DIR)/dev_mngr/dev_mngr.mk
include $(SRC_DIR)/dev_io/dev_io.mk
include $(SRC_DIR)/msg/msg.mk
include $(SRC_DIR)/revision/revision.mk
# Project boards
boards_INCLUDE_DIRS = -Iinclude/boards/$(BOARD)
# Include directories
INCLUDE_DIRS = $(hal_INCLUDE_DIRS) \
$(revision_INCLUDE_DIRS) \
INCLUDE_DIRS = \
$(ll_io_INCLUDE_DIRS) \
$(sm_io_INCLUDE_DIRS) \
$(msg_INCLUDE_DIRS) \
$(dev_mngr_INCLUDE_DIRS) \
$(dev_io_INCLUDE_DIRS) \
$(revision_INCLUDE_DIRS) \
$(boards_INCLUDE_DIRS) \
-I$(PCIE_DRIVER_DIR)/include/pcie \
-Iinclude \
-Isrc/libs/liberrhand \
-Isrc/libs/libconvc \
-Isrc/libs/libhutils \
-Isrc/libs/libdisptable \
-Isrc/libs/libbpmclient \
-Iforeign/libsdbfs \
-I/usr/local/include
# Merge all flags.
......@@ -150,10 +197,31 @@ CFLAGS += $(CFLAGS_PLATFORM) $(CFLAGS_DEBUG)
LDFLAGS = $(LDFLAGS_PLATFORM)
# Output modules
OUT = $(hal_OUT)
OUT = $(dev_mngr_OUT) $(dev_io_OUT)
# All possible output modules
ALL_OUT = $(hal_all_OUT)
ALL_OUT = $(dev_mngr_all_OUT) $(dev_io_all_OUT)
# Out objects
dev_mngr_OBJS += $(dev_mngr_core_OBJS) $(debug_OBJS) \
$(exp_ops_OBJS) $(thsafe_msg_zmq_OBJS) \
$(ll_io_utils_OBJS) $(dev_io_core_utils_OBJS)
dev_io_OBJS += $(dev_io_core_OBJS) $(ll_io_OBJS) \
$(sm_io_OBJS) $(msg_OBJS)
dev_io_cfg_OBJS += $(dev_io_core_OBJS) $(ll_io_OBJS) \
$(sm_io_OBJS) $(msg_OBJS)
# Specific libraries for OUT targets
dev_mngr_LIBS =
dev_mngr_STATIC_LIBS =
dev_io_LIBS = -lbsmp
dev_io_STATIC_LIBS =
dev_io_cfg_LIBS = -lbsmp
dev_io_cfg_STATIC_LIBS =
.SECONDEXPANSION:
......@@ -162,7 +230,13 @@ GIT_REVISION = $(shell git describe --dirty --always)
GIT_USER_NAME = $(shell git config --get user.name)
GIT_USER_EMAIL = $(shell git config --get user.email)
OBJS_all = $(hal_OBJS) $(revision_OBJS)
OBJS_all = $(ll_io_OBJS) \
$(sm_io_OBJS) \
$(msg_OBJS) \
$(dev_mngr_OBJS) \
$(dev_io_OBJS) \
$(dev_io_cfg_OBJS) \
$(revision_OBJS)
# Sources
all_SRCS = $(patsubst %.o,%.c,$(OBJS_all))
......@@ -170,7 +244,12 @@ revision_SRCS = $(patsubst %.o,%.c,$(revision_OBJS))
.PHONY: all install uninstall clean mrproper \
pcie_driver pcie_driver_install pcie_driver_uninstall pcie_driver_clean pcie_driver_check \
liberrhand liberrhand_install liberrhand_uninstall liberrhand_clean liberrhand_mrproper \
libconvc libconvc_install libconvc_uninstall libconvc_clean libconvc_mrproper \
libhutils libhutils_install libhutils_uninstall libhutils_clean libhutils_mrproper \
libdisptable libdisptable_install libdisptable_uninstall libdisptable_clean libdisptable_mrproper \
libbpmclient libbpmclient_install libbpmclient_uninstall libbpmclient_clean libbpmclient_mrproper \
libsdbfs libsdbfs_install libsdbfs_uninstall libsdbfs_clean libsdbfs_mrproper \
libmdp libmdp_install libmdp_uninstall libmdp_clean libmdp_mrproper \
libbsmp libbsmp_install libbsmp_uninstall libbsmp_clean libbsmp_mrproper \
hal_install hal_uninstall hal_clean hal_mrproper \
......@@ -182,11 +261,11 @@ revision_SRCS = $(patsubst %.o,%.c,$(revision_OBJS))
.SECONDARY: $(OBJS_all)
# Makefile rules
all: libbpmclient cfg $(OUT)
all: $(PROJECT_LIBS_NAME) cfg $(OUT)
# Output Rule
$(OUT): $$($$@_OBJS) $(revision_OBJS)
$(CC) $(LFLAGS) $(CFLAGS) $(INCLUDE_DIRS) -o $@ $^ $($@_STATIC_LIBS) $(LDFLAGS) $(LIBS) $($@_LIBS)
$(CC) $(LFLAGS) $(CFLAGS) $(INCLUDE_DIRS) -o $@ $^ $($@_STATIC_LIBS) $(LDFLAGS) $(LIBS) $($@_LIBS) $(PROJECT_LIBS)
# Special rule for the revision object
$(revision_OBJS): $(revision_SRCS)
......@@ -286,6 +365,68 @@ libbsmp_clean:
libbsmp_mrproper:
$(MAKE) -C $(LIBBSMP_DIR) distclean
# Project Libraries
liberrhand:
$(MAKE) -C $(LIBERRHAND_DIR) all
liberrhand_install:
$(MAKE) -C $(LIBERRHAND_DIR) install
liberrhand_uninstall:
$(MAKE) -C $(LIBERRHAND_DIR) uninstall
liberrhand_clean:
$(MAKE) -C $(LIBERRHAND_DIR) clean
liberrhand_mrproper:
$(MAKE) -C $(LIBERRHAND_DIR) mrproper
libconvc:
$(MAKE) -C $(LIBCONVC_DIR) all
libconvc_install:
$(MAKE) -C $(LIBCONVC_DIR) install
libconvc_uninstall:
$(MAKE) -C $(LIBCONVC_DIR) uninstall
libconvc_clean:
$(MAKE) -C $(LIBCONVC_DIR) clean
libconvc_mrproper:
$(MAKE) -C $(LIBCONVC_DIR) mrproper
libhutils:
$(MAKE) -C $(LIBHUTILS_DIR) all
libhutils_install:
$(MAKE) -C $(LIBHUTILS_DIR) install
libhutils_uninstall:
$(MAKE) -C $(LIBHUTILS_DIR) uninstall
libhutils_clean:
$(MAKE) -C $(LIBHUTILS_DIR) clean
libhutils_mrproper:
$(MAKE) -C $(LIBHUTILS_DIR) mrproper
libdisptable:
$(MAKE) -C $(LIBDISPTABLE_DIR) all
libdisptable_install:
$(MAKE) -C $(LIBDISPTABLE_DIR) install
libdisptable_uninstall:
$(MAKE) -C $(LIBDISPTABLE_DIR) uninstall
libdisptable_clean:
$(MAKE) -C $(LIBDISPTABLE_DIR) clean
libdisptable_mrproper:
$(MAKE) -C $(LIBDISPTABLE_DIR) mrproper
libbpmclient:
$(MAKE) -C $(LIBBPMCLIENT_DIR) all
......@@ -301,6 +442,23 @@ libbpmclient_clean:
libbpmclient_mrproper:
$(MAKE) -C $(LIBBPMCLIENT_DIR) mrproper
libsdbfs:
$(MAKE) -C $(LIBSDBFS_DIR) all
libsdbfs_install:
$(MAKE) -C $(LIBSDBFS_DIR) install
libsdbfs_uninstall:
$(MAKE) -C $(LIBSDBFS_DIR) uninstall
libsdbfs_clean:
$(MAKE) -C $(LIBSDBFS_DIR) clean
libsdbfs_mrproper:
$(MAKE) -C $(LIBSDBFS_DIR) mrproper
# External project dependencies
deps: libmdp libbsmp
deps_install: libmdp_install libbsmp_install
......@@ -358,11 +516,11 @@ cfg_clean:
cfg_mrproper:
$(MAKE) -C cfg mrproper
install: hal_install deps_install libbpmclient_install cfg_install
install: hal_install deps_install liberrhand_install libconvc_install libhutils_install libbpmclient_install cfg_install
uninstall: hal_uninstall deps_uninstall libbpmclient_uninstall cfg_uninstall
uninstall: hal_uninstall deps_uninstall liberrhand_uninstall libconvc_uninstall libhutils_uninstall libbpmclient_uninstall cfg_uninstall
clean: hal_clean deps_clean libbpmclient_clean examples_clean tests_clean cfg_clean
clean: hal_clean deps_clean liberrhand_clean libconvc_clean libhutils_clean libbpmclient_clean examples_clean tests_clean cfg_clean
mrproper: clean hal_mrproper deps_mrproper libbpmclient_mrproper examples_mrproper tests_mrproper cfg_mrproper
mrproper: clean hal_mrproper deps_mrproper liberrhand_mrproper libconvc_mrproper libhutils_mrproper libbpmclient_mrproper examples_mrproper tests_mrproper cfg_mrproper
......@@ -4,14 +4,14 @@ Software for controlling the AFC BPM boards
## Prerequisites:
Make sure you have the following libraries installed:
Make sure you have the following libraries installed:
* zeromq-4.0.4 (http://zeromq.org/area:download)
* czmq-2.2.0 (http://czmq.zeromq.org/page:get-the-software)
Cloning this repository
git clone --recursive https://github.com/lerwys/bpm-software.git
git clone --recursive https://github.com/lerwys/bpm-sw.git
Install the Majordomo application from this repository (autotools-based)
......@@ -47,28 +47,28 @@ Load the Driver module
sudo insmod /lib/modules/$(uname -r)/extra/PciDriver.ko
After this the kernel should have found the FPGA board
After this the kernel should have found the FPGA board
and initialized it. Run the following command and check its output
dmesg | tail
You should see something like the excerpt below:
[267002.495109] pciDriver - pcidriver_init :
[267002.495109] pciDriver - pcidriver_init :
Major 250 allocated to nodename 'fpga'
[267002.495130] pciDriver - pcidriver_probe :
[267002.495130] pciDriver - pcidriver_probe :
Found ML605 board at 0000:01:00.0
[267002.495224] pciDriver - pcidriver_probe :
[267002.495224] pciDriver - pcidriver_probe :
Device /dev/fpga0 added
[267002.495434] pciDriver - pcidriver_probe_irq :
[267002.495434] pciDriver - pcidriver_probe_irq :
Registered Interrupt Handler at pin 1, line 11, IRQ 16
[267002.495450] pciDriver - pcidriver_init :
[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
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"
......@@ -85,11 +85,11 @@ You should get an output like the following, if everythig is ok:
Testing PCIDRIVER_IOC_MMAP_MODE... PASSED!
Testing PCIDRIVER_IOC_MMAP_AREA... PASSED!
Testing PCIDRIVER_IOC_PCI_INFO... PASSED!
Testing PCI CONFIG...
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...
Testing PCI mmap...
Reading PCI info... PASSED!
Setting mmap mode... PASSED!
Setting mmap area... PASSED!
......@@ -118,7 +118,7 @@ You should get an output like the following, if everythig is ok:
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...
Testing Kernel Buffer mmap...
Setting MMAP mode to KMEM... PASSED!
Allocing size 1024 : PASSED!
MMAPing size 1024 : PASSED!
......@@ -185,66 +185,52 @@ allocate more memory than the kernel has available.
### Server
Compile everything with debug info. The superuser access
is necessary because it checks (and installs if needed)
the PCIe kernel driver.
Compile everything with debug info. The superuser access
is necessary because it checks (and installs if needed)
the PCIe kernel driver.
If the PCIe driver is already installed, you could
run it without superuser.
make DBE_DBG=y
./compile.sh
### Client
Change to the Client API folder
cd libclient
cd src/libs/libbpmclient
Compile the library
Compile the library, with debug info
make
make ERRHAND_DBG=y ERRHAND_MIN_LEVEL=DBG_MIN_TRACE \
ERRHAND_SUBSYS_ON=’”(DBG_DEV_MNGR | DBG_DEV_IO | DBG_SM_IO | \
DBG_LIB_CLIENT | DBG_SM_PR | DBG_SM_CH | DBG_LL_IO | DBG_HAL_UTILS)”’
Install the library
sudo make install
## Running the example
## Running the examples
Change to the examples folder
cd examples
Compile the examples
make examples
make
Run the server components with the helper script, like shown below:
Run an example application, for instance, the leds example
./init.sh <tranport type = [ipc|tcp]> <broker_endpoint>
./leds -v -b <broker_endpoint> -board <board_number> -bpm <bpm_number>
Typically, one should choose the IPC transport method
for its faster than TCP. For instance:
./init.sh ipc /tmp/bpm
If one would like to use TCP, it should call, for instance:
./init.sh tcp 127.0.0.1:8888
Now we should be good to start making transactions.
Change to the example applications folder
cd examples
Run the Example application with verbose flag (-v)
and specifying a broker endpoint (-b)
./client -v -b <broker_endpoint>
Typically, one should choose the the IPC transport method
for its faster than TCP. For instance:
./client -v -b ipc:///tmp/bpm
./leds -v -b ipc:///tmp/bpm -board <board_number> -bpm <bpm_number>
If one would like to use TCP, it should call, for instance:
./client -v -b tcp://127.0.0.1:8888
./leds -v -b tcp://127.0.0.1:8888 -board <board_number> -bpm <bpm_number>
Leds should be blinking in the FMC ADC board
......@@ -7,7 +7,11 @@ BOARD=afcv3
#Select if we want to compile code with all messages outputs. Options are: y(es) or n(o)
LOCAL_MSG_DBG=n
#Select if we want to compile with debug mode on. Options are: y(es) or n(o)
DBE_DBG=y
ERRHAND_DBG=y
# Select the minimum debug verbosity. See liberrhand file errhand_opts.h for more info.
ERRHAND_MIN_LEVEL=DBG_LVL_TRACE
# Select the subsytems which will have the debug on. See liberrhand file errhand_opts.h for more info.
ERRHAND_SUBSYS_ON='"(DBG_DEV_MNGR | DBG_DEV_IO | DBG_SM_IO | DBG_LIB_CLIENT | DBG_SM_PR | DBG_SM_CH | DBG_LL_IO | DBG_HAL_UTILS)"'
# Select the FMC ADC board type. Options are: passive or active
FMC130M_4CH_TYPE=passive
# Select if we should program FMC EEPROM with some code or not. Option are:
......@@ -20,7 +24,7 @@ AFE_RFFE_TYPE=2
# Selects if we want to compile DEVIO Config. Options are: y(es) or n(o).
# If selected, the FPGA firmware must have the AFC diagnostics module
# synthesized.
WITH_DEVIO_CFG=n
WITH_DEVIO_CFG=y
# Selects the install location of the config file
CFG_FILENAME=/etc/bpm_sw/bpm_sw.cfg
# Selects the install location of the config file
......@@ -32,8 +36,10 @@ COMMAND_DEPS="\
COMMAND_HAL="\
make BOARD=${BOARD} \
ERRHAND_DBG=${ERRHAND_DBG} \
ERRHAND_MIN_LEVEL=${ERRHAND_MIN_LEVEL} \
ERRHAND_SUBSYS_ON='"${ERRHAND_SUBSYS_ON}"' \
LOCAL_MSG_DBG=${LOCAL_MSG_DBG} \
DBE_DBG=${DBE_DBG} \
FMC130M_4CH_TYPE=${FMC130M_4CH_TYPE} \
FMC130M_4CH_EEPROM_PROGRAM=${FMC130M_4CH_EEPROM_PROGRAM} \
WITH_DEV_MNGR=${WITH_DEV_MNGR} \
......@@ -42,16 +48,18 @@ COMMAND_HAL="\
CFG_DIR=${CFG_DIR} && \
sudo make install"
COMMAND_LIBCLIENT="\
COMMAND_LIBBPMCLIENT="\
make BOARD=${BOARD} \
LOCAL_MSG_DBG=${LOCAL_MSG_DBG} \
DBE_DBG=${DBE_DBG} libclient && \
sudo make libclient_install"
ERRHAND_DBG=${ERRHAND_DBG} \
ERRHAND_MIN_LEVEL=${ERRHAND_MIN_LEVEL} \
ERRHAND_SUBSYS_ON='"${ERRHAND_SUBSYS_ON}"' \
LOCAL_MSG_DBG=${LOCAL_MSG_DBG} && \
sudo make libbpmclient_install"
COMMAND_ARRAY=(
"${COMMAND_DEPS}"
"${COMMAND_HAL}"
"${COMMAND_LIBCLIENT}"
"${COMMAND_LIBBPMCLIENT}"
)
for i in "${COMMAND_ARRAY[@]}"
......
......@@ -34,7 +34,7 @@ CFLAGS_PLATFORM = -Wall -Wextra -Werror
LDFLAGS_PLATFORM =
# Libraries
LIBS = -lbpmclient -lmdp -lczmq -lzmq
LIBS = -lbpmclient -lerrhand -lmdp -lczmq -lzmq
# General library flags -L<libdir>
LFLAGS =
......
Project Dependencies:
liberrhand
libbpmclient
Foreign Dependencies:
libmdp
libczmq
libzmq
LINUX ?= /lib/modules/$(shell uname -r)/build
# If we compile for the kernel, we need to include real kernel headers.
# The thing is enough a mess that I moved it to a different file
include Makefile.arch
AS = $(CROSS_COMPILE)as
LD = $(CROSS_COMPILE)ld
CC = $(CROSS_COMPILE)gcc
CPP = $(CC) -E
AR = $(CROSS_COMPILE)ar
NM = $(CROSS_COMPILE)nm
STRIP = $(CROSS_COMPILE)strip
OBJCOPY = $(CROSS_COMPILE)objcopy
OBJDUMP = $(CROSS_COMPILE)objdump
# calculate endianness at compile time
ENDIAN := $(shell ./check-endian $(CC))
CFLAGS = -Wall -ggdb -O2
CFLAGS += -I../../include # for <sdb.h>
CFLAGS += -ffunction-sections -fdata-sections
CFLAGS += -Wno-pointer-sign
CFLAGS += $(ENDIAN) $(LINUXINCLUDE)
LIB = libsdbfs.a
OBJS = glue.o access.o
all: $(LIB)
$(OBJS): $(wildcard *.h)
$(LIB): $(OBJS)
$(AR) r $@ $(OBJS)
clean:
rm -f $(OBJS) $(LIB) *~ core
mrproper: clean
# add the other unused targets, so the rule in ../Makefile works
modules install uninstall modules_install:
srctree = $(LINUX)
#
# This set of contortions comes from the kernel Makefile. We need this
# in order to properly compile libsdbfs for the kernel without being
# in a kernel build environment (for example, to check for compile errors).
#
ARCH := $(shell uname -m | sed -e s/i.86/i386/ -e s/sun4u/sparc64/ \
-e s/arm.*/arm/ -e s/sa110/arm/ \
-e s/s390x/s390/ -e s/parisc64/parisc/ \
-e s/ppc.*/powerpc/ -e s/mips.*/mips/ \
-e s/sh[234].*/sh/ )
SRCARCH := $(ARCH)
# Additional ARCH settings for x86
ifeq ($(ARCH),i386)
SRCARCH := x86
endif
ifeq ($(ARCH),x86_64)
SRCARCH := x86
endif
# Additional ARCH settings for sparc
ifeq ($(ARCH),sparc32)
SRCARCH := sparc
endif
ifeq ($(ARCH),sparc64)
SRCARCH := sparc
endif
# Additional ARCH settings for sh
ifeq ($(ARCH),sh64)
SRCARCH := sh
endif
# Additional ARCH settings for tile
ifeq ($(ARCH),tilepro)
SRCARCH := tile
endif
ifeq ($(ARCH),tilegx)
SRCARCH := tile
endif
# Where to locate arch specific headers
hdr-arch := $(SRCARCH)
ifeq ($(ARCH),m68knommu)
hdr-arch := m68k
endif
# Use LINUXINCLUDE when you must reference the include/ directory.
# Needed to be compatible with the O= option
LINUXINCLUDE := -I$(srctree)/arch/$(hdr-arch)/include \
-Iarch/$(hdr-arch)/include/generated \
-I$(srctree)/include
/*
* Copyright (C) 2012,2013 CERN (www.cern.ch)
* Author: Alessandro Rubini <rubini@gnudd.com>
*
* Released according to the GNU GPL, version 2 or any later version.
*
* This work is part of the White Rabbit project, a research effort led
* by CERN, the European Institute for Nuclear Research.
*/
/* To avoid many #ifdef and associated mess, all headers are included there */
#include "libsdbfs.h"
int sdbfs_fstat(struct sdbfs *fs, struct sdb_device *record_return)
{
if (!fs->currentp)
return -ENOENT;
memcpy(record_return, fs->currentp, sizeof(*record_return));
return 0;
}
int sdbfs_fread(struct sdbfs *fs, int offset, void *buf, int count)
{
int ret;
if (!fs->currentp)
return -ENOENT;
if (offset < 0)
offset = fs->read_offset;
if (offset + count > fs->f_len)
count = fs->f_len - offset;
ret = count;
if (fs->data)
memcpy(buf, fs->data + fs->f_offset + offset, count);
else
ret = fs->read(fs, fs->f_offset + offset, buf, count);
if (ret > 0)
fs->read_offset = offset + ret;
return ret;
}
int sdbfs_fwrite(struct sdbfs *fs, int offset, void *buf, int count)
{
int ret;
if (!fs->currentp)
return -ENOENT;
if (offset < 0)
offset = fs->read_offset;
if (offset + count > fs->f_len)
count = fs->f_len - offset;
ret = count;
if (fs->data)
memcpy(fs->data + fs->f_offset + offset, buf, count);
else
ret = fs->write(fs, fs->f_offset + offset, buf, count);
if (ret > 0)
fs->read_offset = offset + ret;
return ret;
}
int sdbfs_ferase(struct sdbfs *fs, int offset, int count)
{
int ret;
if (!fs->currentp)
return -ENOENT;
if (offset < 0)
offset = fs->read_offset;
if (offset + count > fs->f_len)
count = fs->f_len - offset;
ret = count;
if (fs->data)
memset(fs->data + fs->f_offset + offset, 0xFF, count);
else
ret = fs->erase(fs, fs->f_offset + offset, count);
if (ret > 0)
fs->read_offset = offset + ret;
return ret;
}
#!/bin/bash
# Check endianness at compile time, so we can pass the -D to CFLAGS
CC=$1
if [ "x$CC" == "x" ]; then
echo "$0: pass the compiler path (\$CC) as argument" >& 2
exit 1
fi
# Check endianness, by making an object file
TMPC=$(mktemp /tmp/endian-c-XXXXXX)
TMPO=$(mktemp /tmp/endian-o-XXXXXX)
echo "int i = 0xbbee;" > $TMPC
$CC -x c -c $TMPC -o $TMPO
OBJCOPY=$(echo $CC | sed 's/gcc$/objcopy/')
if $OBJCOPY -O binary $TMPO /dev/stdout | od -t x1 -An | \
grep -q 'bb ee'; then
echo " -DSDBFS_BIG_ENDIAN"
else
echo " -DSDBFS_LITTLE_ENDIAN"
fi
rm -f $TMPC $TMPO
/*
* Copyright (C) 2012,2014 CERN (www.cern.ch)
* Author: Alessandro Rubini <rubini@gnudd.com>
*
* Released according to the GNU GPL, version 2 or any later version.
*
* This work is part of the White Rabbit project, a research effort led
* by CERN, the European Institute for Nuclear Research.
*/
/* To avoid many #ifdef and associated mess, all headers are included there */
#include "libsdbfs.h"
static struct sdbfs *sdbfs_list;
/* All fields unused by the caller are expected to be zeroed */
int sdbfs_dev_create(struct sdbfs *fs)
{
unsigned int magic;
/* First, check we have the magic */
if (fs->data || (fs->flags & SDBFS_F_ZEROBASED))
magic = *(unsigned int *)(fs->data + fs->entrypoint);
else
fs->read(fs, fs->entrypoint, &magic, sizeof(magic));
if (magic == SDB_MAGIC) {
/* Uh! If we are little-endian, we must convert */
if (ntohl(1) != 1)
fs->flags |= SDBFS_F_CONVERT32;
} else if (htonl(magic) == SDB_MAGIC) {
/* ok, don't convert */
} else {
return -ENOTDIR;
}
fs->next = sdbfs_list;
sdbfs_list = fs;
return 0;
}
int sdbfs_dev_destroy(struct sdbfs *fs)
{
struct sdbfs **p;
for (p = &sdbfs_list; *p && *p != fs; p = &(*p)->next)
;
if (!*p)
return -ENOENT;
*p = fs->next;
return 0;
}
struct sdbfs *sdbfs_dev_find(const char *name)
{
struct sdbfs *l;
for (l = sdbfs_list; l && strcmp(l->name, name); l = l->next)
;
if (!l)
return NULL;
return l;
}
/*
* To open by name or by ID we need to scan the tree. The scan
* function is also exported in order for "sdb-ls" to use it
*/
static struct sdb_device *sdbfs_readentry(struct sdbfs *fs,
unsigned long offset)
{
/*
* This function reads an entry from a known good offset. It
* returns the pointer to the entry, which may be stored in
* the fs structure itself. Only touches fs->current_record.
*/
if (fs->data || (fs->flags & SDBFS_F_ZEROBASED)) {
if (!(fs->flags & SDBFS_F_CONVERT32))
return (struct sdb_device *)(fs->data + offset);
/* copy to local storage for conversion */
memcpy(&fs->current_record, fs->data + offset,
sizeof(fs->current_record));
} else {
if (!fs->read)
return NULL;
fs->read(fs, offset, &fs->current_record,
sizeof(fs->current_record));
}
if (fs->flags & SDBFS_F_CONVERT32) {
uint32_t *p = (void *)&fs->current_record;
int i;
for (i = 0; i < sizeof(fs->current_record) / sizeof(*p); i++)
p[i] = ntohl(p[i]);
}
return &fs->current_record;
}
/* Helper for scanning: we enter a new directory, and we must validate */
static struct sdb_device *scan_newdir(struct sdbfs *fs, int depth)
{
struct sdb_device *dev;
struct sdb_interconnect *intercon;
dev = fs->currentp = sdbfs_readentry(fs, fs->this[depth]);
if (dev->sdb_component.product.record_type != sdb_type_interconnect)
return NULL;
intercon = (typeof(intercon))dev;
if (ntohl(intercon->sdb_magic) != SDB_MAGIC)
return NULL;
fs->nleft[depth] = ntohs(intercon->sdb_records) - 1;
fs->this[depth] += sizeof(*intercon);
fs->depth = depth;
return dev;
}
struct sdb_device *sdbfs_scan(struct sdbfs *fs, int newscan)
{
/*
* This returns a pointer to the next sdb record, or the first one.
* Subdirectories (bridges) are returned before their contents.
* It only uses internal fields.
*/
struct sdb_device *dev;
struct sdb_bridge *bridge;
int depth, type, newdir = 0; /* check there's the magic */
if (newscan) {
fs->base[0] = 0;
fs->this[0] = fs->entrypoint;
depth = fs->depth = 0;
newdir = 1;
goto scan;
}
/* If we already returned a bridge, go inside it (check type) */
depth = fs->depth;
type = fs->currentp->sdb_component.product.record_type;
if (type == sdb_type_bridge && depth + 1 < SDBFS_DEPTH) {
bridge = (typeof(bridge))fs->currentp;
fs->this[depth + 1] = fs->base[depth]
+ ntohll(bridge->sdb_child);
fs->base[depth + 1] = fs->base[depth]
+ ntohll(bridge->sdb_component.addr_first);
depth++;
newdir++;
}
scan:
/* If entering a new directory, verify magic and set nleft */
if (newdir) {
dev = scan_newdir(fs, depth);
if (dev)
goto out;
/* Otherwise the directory is not there: no intercon */
if (!depth)
return NULL; /* no entries at all */
depth--;
}
while (fs->nleft[depth] == 0) {
/* No more at this level, "cd .." if possible */
if (!depth)
return NULL;
fs->depth = --depth;
}
/* so, read the next entry */
dev = fs->currentp = sdbfs_readentry(fs, fs->this[depth]);
fs->this[depth] += sizeof(*dev);
fs->nleft[depth]--;
out:
fs->f_offset = fs->base[fs->depth]
+ htonll(fs->currentp->sdb_component.addr_first);
return dev;
}
static void __open(struct sdbfs *fs)
{
fs->f_offset = fs->base[fs->depth]
+ htonll(fs->currentp->sdb_component.addr_first);
fs->f_len = htonll(fs->currentp->sdb_component.addr_last)
+ 1 - htonll(fs->currentp->sdb_component.addr_first);
fs->read_offset = 0;
}
int sdbfs_open_name(struct sdbfs *fs, const char *name)
{
struct sdb_device *d;
int len = strlen(name);
if (len > 19)
return -ENOENT;
sdbfs_scan(fs, 1); /* new scan: get the interconnect and igore it */
while ( (d = sdbfs_scan(fs, 0)) != NULL) {
if (strncmp(name, d->sdb_component.product.name, len))
continue;
if (len < 19 && d->sdb_component.product.name[len] != ' ')
continue;
fs->currentp = d;
__open(fs);
return 0;
}
return -ENOENT;
}
int sdbfs_open_id(struct sdbfs *fs, uint64_t vid, uint32_t did)
{
struct sdb_device *d;
sdbfs_scan(fs, 1); /* new scan: get the interconnect and igore it */
while ( (d = sdbfs_scan(fs, 0)) != NULL) {
if (vid != d->sdb_component.product.vendor_id)
continue;
if (did != d->sdb_component.product.device_id)
continue;
fs->currentp = d;
__open(fs);
return 0;
}
return -ENOENT;
}
int sdbfs_close(struct sdbfs *fs)
{
fs->currentp = NULL;
return 0;
}
/* to "find" a device, open it, get the current offset, then close */
unsigned long sdbfs_find_name(struct sdbfs *fs, const char *name)
{
unsigned long offset;
int ret;
ret = sdbfs_open_name(fs, name);
if (ret < 0)
return (unsigned long)ret;
offset = fs->f_offset;
sdbfs_close(fs);
return offset;
}
unsigned long sdbfs_find_id(struct sdbfs *fs, uint64_t vid, uint32_t did)
{
unsigned long offset;
int ret;
ret = sdbfs_open_id(fs, vid, did);
if (ret < 0)
return (unsigned long)ret;
offset = fs->f_offset;
sdbfs_close(fs);
return offset;
}
/* Though freestanding, some minimal headers are expected to exist */
#include <stdlib.h>
#include <stdint.h>
#include <string.h>
#include <errno.h>
#define SDB_KERNEL 0
#define SDB_USER 0
#define SDB_FREESTAND 1
#ifdef SDBFS_BIG_ENDIAN
# define ntohs(x) (x)
# define htons(x) (x)
# define ntohl(x) (x)
# define htonl(x) (x)
#else
# error "No support, yet, for little-endian freestanding library"
#endif
/*
* This supports both the Linux kernel and barebox, that is similar
* by design, and defines __KERNEL__ too.
*/
#ifdef __BAREBOX__
# include <errno.h>
#else /* really linux */
# include <linux/errno.h>
#endif
#include <linux/types.h>
#include <linux/string.h>
#include <asm/byteorder.h>
/*
* The default installed /usr/include/linux stuff misses the __KERNEL__ parts.
* For libsdbfs it means we won't get uint32_t and similar types.
*
* So, check if we got the information we need before strange errors happen.
* The DECLARE_BITMAP macro is in <linux/types.h> since the epoch, but it
* is not installed in /usr/include/linux/types.h, so use it to check.
*
* If building for barebox, we miss the macro, but we are sure that
* we are picking the correct header, because the library is only built
* within the barebox source tree.
*/
#if !defined(DECLARE_BITMAP) && !defined(__BAREBOX__)
# error "Please point LINUX to a source tree if you define __KERNEL__"
#endif
#define SDB_KERNEL 1
#define SDB_USER 0
#define SDB_FREESTAND 0
#define sdb_print(format, ...) printk(format, __VA_ARGS__)
#ifndef __LIBSDBFS_USER_H__
#define __LIBSDBFS_USER_H__
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <arpa/inet.h> /* htonl */
#define SDB_KERNEL 0
#define SDB_USER 1
#define SDB_FREESTAND 0
#define sdb_print(format, ...) fprintf(stderr, format, __VA_ARGS__)
#endif /* __LIBSDBFS_USER_H__ */
#ifndef __LIBSDBFS_H__
#define __LIBSDBFS_H__
/* The library can work in different environments, take care of them */
#ifdef __KERNEL__
# include "libsdbfs-kernel.h"
#elif defined(__unix__)
# include "libsdbfs-user.h"
#else
# include "libsdbfs-freestanding.h"
#endif
#include <sdb.h> /* Please point your "-I" to some sensible place */
#define SDBFS_DEPTH 4 /* Max number of subdirectory depth */
/*
* Data structures: please not that the library intself doesn't use
* malloc, so it's the caller who must deal withallocation/removal.
* For this reason we can have no opaque structures, but some fields
* are private
*/
struct sdbfs {
/* Some fields are informative */
char *name; /* may be null */
void *drvdata; /* driver may need some detail.. */
unsigned long blocksize;
unsigned long entrypoint;
unsigned long flags;
/* The "driver" must offer some methods */
void *data; /* Use this if directly mapped */
unsigned long datalen; /* Length of the above array */
int (*read)(struct sdbfs *fs, int offset, void *buf, int count);
int (*write)(struct sdbfs *fs, int offset, void *buf, int count);
int (*erase)(struct sdbfs *fs, int offset, int count);
/* The following fields are library-private */
struct sdb_device *currentp;
struct sdb_device current_record;
unsigned long f_len;
unsigned long f_offset; /* start of file */
unsigned long read_offset; /* current location */
struct sdbfs *next;
/* The following ones are directory-aware */
unsigned long base[SDBFS_DEPTH]; /* for relative addresses */
unsigned long this[SDBFS_DEPTH]; /* current sdb record */
int nleft[SDBFS_DEPTH];
int depth;
};
/* Some flags are set by the user, some (convert32) by the library */
#define SDBFS_F_VERBOSE 0x0001 /* not really used yet */
#define SDBFS_F_CONVERT32 0x0002 /* swap SDB words as they are read */
#define SDBFS_F_ZEROBASED 0x0004 /* zero is a valid data pointer */
/* Defined in glue.c */
int sdbfs_dev_create(struct sdbfs *fs);
int sdbfs_dev_destroy(struct sdbfs *fs);
struct sdbfs *sdbfs_dev_find(const char *name);
unsigned long sdbfs_find_name(struct sdbfs *fs, const char *name);
unsigned long sdbfs_find_id(struct sdbfs *fs, uint64_t vid, uint32_t did);
int sdbfs_open_name(struct sdbfs *fs, const char *name);
int sdbfs_open_id(struct sdbfs *fs, uint64_t vid, uint32_t did);
int sdbfs_close(struct sdbfs *fs);
struct sdb_device *sdbfs_scan(struct sdbfs *fs, int newscan);
/* Defined in access.c */
int sdbfs_fstat(struct sdbfs *fs, struct sdb_device *record_return);
int sdbfs_fread(struct sdbfs *fs, int offset, void *buf, int count);
int sdbfs_fwrite(struct sdbfs *fs, int offset, void *buf, int count);
int sdbfs_ferase(struct sdbfs *fs, int offset, int count);
/* This is needed to convert endianness. Hoping it is not defined elsewhere */
static inline uint64_t htonll(uint64_t ll)
{
uint64_t res;
if (htonl(1) == 1)
return ll;
res = htonl(ll >> 32);
res |= (uint64_t)(htonl((uint32_t)ll)) << 32;
return res;
}
static inline uint64_t ntohll(uint64_t ll)
{
return htonll(ll);
}
#endif /* __LIBSDBFS_H__ */
......@@ -2,9 +2,9 @@
#define _ACQ_CHAN_H_
#if defined(__BOARD_ML605__)
#include "board/ml605/acq_chan_ml605.h"
#include "boards/ml605/priv_defs/acq_chan_ml605.h"
#elif defined(__BOARD_AFCV3__)
#include "board/afcv3/acq_chan_afcv3.h"
#include "boards/afcv3/priv_defs/acq_chan_afcv3.h"
#else
#error "Could not include acquisition channel definitions. Unsupported board!"
#endif
......
#ifndef _BOARD_H_
#define _BOARD_H_
#include "board/afcv3/defs.h"
#include "priv_defs/defs.h"
/****************************/
/* General Definitions */
......
......@@ -2,7 +2,7 @@
#define _DDR3_MAP_AFCV3_H_
#include "acq_chan_afcv3.h"
#include "hal_varg.h"
#include "varg_macros.h"
/* Does the acquisition channel gets a memory region? */
#define DDR3_MEM_BOOL(MEM_SIZE) IF(MEM_SIZE > 0)(1, 0)
......
#ifndef _MEM_LAYOUT_H_
#define _MEM_LAYOUT_H_
#include "pcie_regs.h"
#include "hw/pcie_regs.h"
#include "acq_chan_afcv3.h"
#define NUM_FMC130M_4CH_SMIOS 2
......
#ifndef _BOARD_H_
#define _BOARD_H_
#include <board/ml605/defs.h>
#include "priv_defs/defs.h"
/****************************/
/* General Definitions */
......
......@@ -2,7 +2,7 @@
#define _DDR3_MAP_ML605_H_
#include "acq_chan_ml605.h"
#include "hal_varg.h"
#include "varg_macros.h"
/* Does the acquisition channel gets a memory region? */
#define DDR3_MEM_BOOL(MEM_SIZE) IF(MEM_SIZE > 0)(1, 0)
......
#ifndef _MEM_LAYOUT_H_
#define _MEM_LAYOUT_H_
#include "pcie_regs.h"
#include "hw/pcie_regs.h"
#include "acq_chan_ml605.h"
#define NUM_FMC130M_4CH_SMIOS 1
......
......@@ -8,7 +8,7 @@
#ifndef _SMPR_I2C_REGS_H_
#define _SMPR_I2C_REGS_H_
#include "wb_i2c_regs.h"
#include "hw/wb_i2c_regs.h"
/* Copied from wb_acq_core_regs.h */
#if defined( __GNUC__)
......
......@@ -8,7 +8,7 @@
#ifndef _SMPR_SPI_REGS_H_
#define _SMPR_SPI_REGS_H_
#include "wb_spi_regs.h"
#include "hw/wb_spi_regs.h"
/* Copied from wb_acq_core_regs.h */
#if defined( __GNUC__)
......
/*
* This is the official version 1.1 of sdb.h
*/
#ifndef __SDB_H__
#define __SDB_H__
#ifdef __KERNEL__
#include <linux/types.h>
#else
#include <stdint.h>
#endif
/*
* All structures are 64 bytes long and are expected
* to live in an array, one for each interconnect.
* Most fields of the structures are shared among the
* various types, and most-specific fields are at the
* beginning (for alignment reasons, and to keep the
* magic number at the head of the interconnect record
*/
/* Product, 40 bytes at offset 24, 8-byte aligned
*
* device_id is vendor-assigned; version is device-specific,
* date is hex (e.g 0x20120501), name is UTF-8, blank-filled
* and not terminated with a 0 byte.
*/
struct sdb_product {
uint64_t vendor_id; /* 0x18..0x1f */
uint32_t device_id; /* 0x20..0x23 */
uint32_t version; /* 0x24..0x27 */
uint32_t date; /* 0x28..0x2b */
uint8_t name[19]; /* 0x2c..0x3e */
uint8_t record_type; /* 0x3f */
};
/*
* Component, 56 bytes at offset 8, 8-byte aligned
*
* The address range is first to last, inclusive
* (for example 0x100000 - 0x10ffff)
*/
struct sdb_component {
uint64_t addr_first; /* 0x08..0x0f */
uint64_t addr_last; /* 0x10..0x17 */
struct sdb_product product; /* 0x18..0x3f */
};
/* Type of the SDB record */
enum sdb_record_type {
sdb_type_interconnect = 0x00,
sdb_type_device = 0x01,
sdb_type_bridge = 0x02,
sdb_type_integration = 0x80,
sdb_type_repo_url = 0x81,
sdb_type_synthesis = 0x82,
sdb_type_empty = 0xFF,
};
/* Type 0: interconnect (first of the array)
*
* sdb_records is the length of the table including this first
* record, version is 1. The bus type is enumerated later.
*/
#define SDB_MAGIC 0x5344422d /* "SDB-" */
struct sdb_interconnect {
uint32_t sdb_magic; /* 0x00-0x03 */
uint16_t sdb_records; /* 0x04-0x05 */
uint8_t sdb_version; /* 0x06 */
uint8_t sdb_bus_type; /* 0x07 */
struct sdb_component sdb_component; /* 0x08-0x3f */
};
/* Type 1: device
*
* class is 0 for "custom device", other values are
* to be standardized; ABI version is for the driver,
* bus-specific bits are defined by each bus (see below)
*/
struct sdb_device {
uint16_t abi_class; /* 0x00-0x01 */
uint8_t abi_ver_major; /* 0x02 */
uint8_t abi_ver_minor; /* 0x03 */
uint32_t bus_specific; /* 0x04-0x07 */
struct sdb_component sdb_component; /* 0x08-0x3f */
};
/* Type 2: bridge
*
* child is the address of the nested SDB table
*/
struct sdb_bridge {
uint64_t sdb_child; /* 0x00-0x07 */
struct sdb_component sdb_component; /* 0x08-0x3f */
};
/* Type 0x80: integration
*
* all types with bit 7 set are meta-information, so
* software can ignore the types it doesn't know. Here we
* just provide product information for an aggregate device
*/
struct sdb_integration {
uint8_t reserved[24]; /* 0x00-0x17 */
struct sdb_product product; /* 0x08-0x3f */
};
/* Type 0x81: Top module repository url
*
* again, an informative field that software can ignore
*/
struct sdb_repo_url {
uint8_t repo_url[63]; /* 0x00-0x3e */
uint8_t record_type; /* 0x3f */
};
/* Type 0x82: Synthesis tool information
*
* this informative record
*/
struct sdb_synthesis {
uint8_t syn_name[16]; /* 0x00-0x0f */
uint8_t commit_id[16]; /* 0x10-0x1f */
uint8_t tool_name[8]; /* 0x20-0x27 */
uint32_t tool_version; /* 0x28-0x2b */
uint32_t date; /* 0x2c-0x2f */
uint8_t user_name[15]; /* 0x30-0x3e */
uint8_t record_type; /* 0x3f */
};
/* Type 0xff: empty
*
* this allows keeping empty slots during development,
* so they can be filled later with minimal efforts and
* no misleading description is ever shipped -- hopefully.
* It can also be used to pad a table to a desired length.
*/
struct sdb_empty {
uint8_t reserved[63]; /* 0x00-0x3e */
uint8_t record_type; /* 0x3f */
};
/* The type of bus, for bus-specific flags */
enum sdb_bus_type {
sdb_wishbone = 0x00,
sdb_data = 0x01,
};
#define SDB_WB_WIDTH_MASK 0x0f
#define SDB_WB_ACCESS8 0x01
#define SDB_WB_ACCESS16 0x02
#define SDB_WB_ACCESS32 0x04
#define SDB_WB_ACCESS64 0x08
#define SDB_WB_LITTLE_ENDIAN 0x80
#define SDB_DATA_READ 0x04
#define SDB_DATA_WRITE 0x02
#define SDB_DATA_EXEC 0x01
#endif /* __SDB_H__ */
......@@ -5,8 +5,8 @@
* Released according to the GNU LGPL, version 3 or any later version.
*/
#ifndef _HAL_VARG_H_
#define _HAL_VARG_H_
#ifndef _VARG_MACROS_H_
#define _VARG_MACROS_H_
/********************** Detecting NULL passed to MACRO ************************/
/* based on from "Detect empty macro arguments" from Jens Gustedt, published
......
......@@ -3,7 +3,7 @@
TOP_DIR=..
REMOTE_HOME="/home"
REMOTE_USERNAME="lnls-bpm"
REMOTE_IP=10.0.18.39
REMOTE_IP=10.0.18.52
LOCAL_IP=10.0.18.35
REMOTE_DIR="bpm-sw-deploy"
BOARD_TYPE="afcv3"
......@@ -37,5 +37,10 @@ SYM_FILES=$(find . -type l ! -iname "*.[o|a]" ! -iname "*orig" \
! -path "./majordomo*" ! -path "./.git*")
echo "Copying files to ${REMOTE_USERNAME}@${REMOTE_IP}:${REMOTE_DEPLOY_DIR}"
rsync -Rpr ${SRC_FILES} ${SYM_FILES} ${REMOTE_USERNAME}@${REMOTE_IP}:${REMOTE_DEPLOY_DIR}
rsync -Rpr ${SRC_FILES} ${REMOTE_USERNAME}@${REMOTE_IP}:${REMOTE_DEPLOY_DIR}
rsync -Rpr ${SYM_FILES} ${REMOTE_USERNAME}@${REMOTE_IP}:${REMOTE_DEPLOY_DIR}
echo "Compiling source files with \"${COMPILE_CMD}\""
ssh -l ${REMOTE_USERNAME} ${REMOTE_IP} "cd ${REMOTE_DEPLOY_DIR} && \
${COMPILE_CMD}"
......@@ -5,8 +5,8 @@
#include "czmq.h"
#include "dev_io.h"
#include "debug_print.h"
#include "board.h"
#include "errhand.h"
#include "bpm_client.h"
#define DEVIO_SERVICE_LEN 50
......@@ -194,7 +194,7 @@ int main (int argc, char *argv[])
char *argv_exec [] = {DEVIO_CFG_NAME, "-n", devio_type_str,"-t", dev_type,
"-i", dev_id_str, "-e", dev_entry, "-b", broker_endp, NULL};
/* Spawn Config DEVIO */
child_devio_cfg_pid = halutils_spawn_chld (DEVIO_CFG_NAME, argv_exec);
child_devio_cfg_pid = hutils_spawn_chld (DEVIO_CFG_NAME, argv_exec);
if (child_devio_cfg_pid < 0) {
DBE_DEBUG (DBG_DEV_IO | DBG_LVL_FATAL, "[dev_io] Could not create "
......@@ -236,7 +236,7 @@ int main (int argc, char *argv[])
/* Kill DEVIO cfg as we've already got our slot number */
kill (child_devio_cfg_pid, DEVIO_KILL_CFG_SIGNAL);
/* Wait child */
halutils_wait_chld ();
hutils_wait_chld ();
#endif
/* We don't need it anymore */
......@@ -305,7 +305,7 @@ int main (int argc, char *argv[])
}
/* wait child */
halutils_wait_chld ();
hutils_wait_chld ();
}
err_devio:
......
include $(SRC_DIR)/hal/dev_io/utils/utils.mk
dev_io_DIR = $(SRC_DIR)/dev_io
dev_io_DIR = $(SRC_DIR)/hal/dev_io
dev_io_core_utils_OBJS = $(dev_io_DIR)/dev_io_utils.o
# 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
dev_io_core_OBJS = $(dev_io_DIR)/dev_io_core.o \
$(dev_io_DIR)/dev_io_err.o \
$(dev_io_utils_OBJS)
$(dev_io_core_utils_OBJS)
dev_io_OBJS = $(dev_io_DIR)/dev_io.o
dev_io_INCLUDE_DIRS = $(dev_io_DIR) \
$(dev_io_utils_INCLUDE_DIRS) \
dev_io_ALL_DIRS = $(dev_io_DIR) \
$(LIBBPMCLIENT_DIR)
dev_io_OUT = dev_io
ifeq ($(WITH_DEVIO_CFG),y)
dev_io_cfg_OBJS = $(dev_io_DIR)/dev_io_cfg.o
dev_io_cfg_INCLUDE_DIRS = $(dev_io_DIR) \
$(dev_io_utils_INCLUDE_DIRS) \
$(LIBBPMCLIENT_DIR)
dev_io_cfg_OUT = dev_io_cfg
else
dev_io_cfg_OBJS =
dev_io_cfg_INCLUDE_DIRS =
dev_io_cfg_OUT =
endif
# Add -I prefix to all include directories
dev_io_INCLUDE_DIRS = $(addprefix -I, $(dev_io_ALL_DIRS))
dev_io_OUT += $(dev_io_cfg_OUT)
dev_io_all_OUT = dev_io dev_io_cfg
......@@ -5,7 +5,7 @@
#include "czmq.h"
#include "dev_io.h"
#include "debug_print.h"
#include "errhand.h"
#include "board.h"
#define DEVIO_SERVICE_LEN 50
......
......@@ -10,14 +10,15 @@
#include "dev_io_core.h"
#include "dev_io_err.h"
#include "hal_assert.h"
#include "errhand.h"
#include "sm_io_mod_dispatch.h"
#include "msg.h"
#include "rw_param.h"
#include "sm_io_thsafe_codes.h"
#include "sm_io_bootstrap.h"
#include "ll_io_utils.h"
#include "hal_utils.h"
#include "hutils.h"
#include "disp_table.h"
/* Undef ASSERT_ALLOC to avoid conflicting with other ASSERT_ALLOC */
#ifdef ASSERT_TEST
......@@ -50,6 +51,13 @@
#define DEVIO_MAX_DESTRUCT_MSG_TRIES 10
/* DEVIO dispatch table operations */
const disp_table_ops_t devio_disp_table_ops;
/* Dispatch table message check handler */
static disp_table_err_e _devio_check_msg_args (disp_table_t *disp_table,
const disp_op_t *disp_op, void *args);
/* Do the SMIO operation */
static devio_err_e _devio_do_smio_op (devio_t *self, void *msg);
static devio_err_e _devio_send_destruct_msg (devio_t *self, void *pipe);
......@@ -66,7 +74,7 @@ devio_t * devio_new (char *name, char *endpoint_dev, llio_type_e type,
/* Set logfile available for all dev_mngr and dev_io instances.
* We accept NULL as a parameter, meaning to suppress all messages */
debug_set_log (log_file_name, DEVIO_DFLT_LOG_MODE);
errhand_set_log (log_file_name, DEVIO_DFLT_LOG_MODE);
char *dev_type_c = llio_type_to_str (type);
DBE_DEBUG (DBG_DEV_IO | DBG_LVL_INFO, "[dev_io_core] Spawing DEVIO worker"
......@@ -136,12 +144,12 @@ devio_t * devio_new (char *name, char *endpoint_dev, llio_type_e type,
ASSERT_ALLOC(self->sm_io_h, err_sm_io_h_alloc);
/* Init sm_io_thsafe_ops_h dispatch table */
self->disp_table_thsafe_ops = disp_table_new ();
self->disp_table_thsafe_ops = disp_table_new (&devio_disp_table_ops);
ASSERT_ALLOC(self->disp_table_thsafe_ops, err_disp_table_thsafe_ops_alloc);
halutils_err_e halutils_err = disp_table_insert_all (self->disp_table_thsafe_ops,
hutils_err_e hutils_err = disp_table_insert_all (self->disp_table_thsafe_ops,
self->thsafe_server_ops);
ASSERT_TEST(halutils_err==HALUTILS_SUCCESS, "Could not initialize dispatch table",
ASSERT_TEST(hutils_err==HUTILS_SUCCESS, "Could not initialize dispatch table",
err_disp_table_init);
/* Finally, initialize mdp_worker with service being the BPM<board_number> */
......@@ -261,9 +269,9 @@ devio_err_e devio_register_sm (devio_t *self, uint32_t smio_id, uint64_t base,
* alloc can fail */
DBE_DEBUG (DBG_DEV_IO | DBG_LVL_TRACE,
"[dev_io_core:register_sm] Stringify hash ID\n");
char *inst_id_str = halutils_stringify_dec_key (inst_id);
char *inst_id_str = hutils_stringify_dec_key (inst_id);
ASSERT_ALLOC(inst_id_str, err_inst_id_str_alloc);
char *key = halutils_concat_strings_no_sep (smio_mod_dispatch[i].name,
char *key = hutils_concat_strings_no_sep (smio_mod_dispatch[i].name,
inst_id_str);
/* We don't need this anymore */
free (inst_id_str);
......@@ -506,7 +514,39 @@ devio_err_e devio_do_smio_op (devio_t *self, void *msg)
return _devio_do_smio_op (self, msg);
}
/**************** Helper Functions ***************/
/************************************************************/
/***************** Dispatch table callbacks *****************/
/************************************************************/
static disp_table_err_e _devio_check_msg_args (disp_table_t *disp_table,
const disp_op_t *disp_op, void *args)
{
assert (disp_table);
assert (disp_op);
assert (args);
devio_err_e err = DEVIO_SUCCESS;
/* Check if the message tis the correct one */
ASSERT_TEST (msg_guess_type (args) == MSG_THSAFE_ZMQ, "Invalid message tag",
err_inv_msg, DEVIO_ERR_BAD_MSG);
msg_err_e merr = msg_check_gen_zmq_args (disp_op, THSAFE_MSG_ZMQ(args));
ASSERT_TEST (merr == MSG_SUCCESS, "Unrecognized message. Message arguments "
"checking failed", err_msg_args_check, DEVIO_ERR_BAD_MSG);
err_msg_args_check:
err_inv_msg:
return err;
}
const disp_table_ops_t devio_disp_table_ops = {
.check_msg_args = _devio_check_msg_args
};
/************************************************************/
/********************* Helper Functions *********************/
/************************************************************/
static devio_err_e _devio_do_smio_op (devio_t *self, void *msg)
{
assert (self);
......
......@@ -11,8 +11,8 @@
#include "czmq.h"
#include "mdp.h"
#include "hal_utils.h"
#include "dispatch_table.h"
#include "hutils.h"
#include "disp_table.h"
#include "dev_io_err.h"
#include "ll_io.h"
/* #include "sm_io.h" */
......
......@@ -6,8 +6,8 @@
*/
#include "dev_io_utils.h"
#include "ll_io_utils.h"
#include "hal_assert.h"
#include "convc.h"
#include "errhand.h"
/* Undef ASSERT_ALLOC to avoid conflicting with other ASSERT_ALLOC */
#ifdef ASSERT_TEST
......@@ -34,21 +34,21 @@
/************** Utility functions ****************/
static const llio_types_t devio_types_map [] = {
static const convc_types_t devio_types_map [] = {
{.name = BE_DEVIO_STR, .type = BE_DEVIO},
{.name = FE_DEVIO_STR, .type = FE_DEVIO},
{.name = INVALID_DEVIO_STR, .type = INVALID_DEVIO},
{.name = LLIO_TYPE_NAME_END, .type = LLIO_TYPE_END} /* End marker */
{.name = CONVC_TYPE_NAME_END, .type = CONVC_TYPE_END} /* End marker */
};
devio_type_e devio_str_to_type (const char *type_str)
{
devio_type_e ret = llio_str_to_gen_type (type_str, devio_types_map);
devio_type_e ret = convc_str_to_gen_type (type_str, devio_types_map);
return (ret == LLIO_TYPE_END)? INVALID_DEVIO: ret;
return (ret == CONVC_TYPE_END)? INVALID_DEVIO: ret;
}
char *devio_type_to_str (devio_type_e type)
{
return llio_gen_type_to_str (type, devio_types_map);
return convc_gen_type_to_str (type, devio_types_map);
}
......@@ -16,9 +16,9 @@
#include <sys/stat.h> /* chmod */
#include "dev_mngr.h"
#include "debug_print.h"
#include "hal_varg.h"
#include "hal_utils.h"
#include "varg_macros.h"
#include "errhand.h"
#include "hutils.h"
#define DFLT_BIND_FOLDER "/tmp/bpm"
#define DFLT_BIND_ADDR "0"
......@@ -237,8 +237,8 @@ int main (int argc, char *argv[])
}
#endif
dmngr_set_wait_clhd_handler (dmngr, &halutils_wait_chld);
dmngr_set_spawn_clhd_handler (dmngr, &halutils_spawn_chld);
dmngr_set_wait_clhd_handler (dmngr, &hutils_wait_chld);
dmngr_set_spawn_clhd_handler (dmngr, &hutils_spawn_chld);
err = dmngr_register_sig_handlers (dmngr);
if (err != DMNGR_SUCCESS) {
......
dev_mngr_DIR = $(SRC_DIR)/hal/dev_mngr
dev_mngr_DIR = $(SRC_DIR)/dev_mngr
# Here we call <output_name>_core_OBJS as we need to add
# more objects to this target. This is done in the hal.mk
......@@ -16,7 +16,9 @@ dev_mngr_OBJS =
dev_mngr_OUT =
endif
dev_mngr_INCLUDE_DIRS = $(dev_mngr_DIR)
dev_mngr_ALL_DIRS = $(dev_mngr_DIR)
dev_mngr_all_OUT = dev_mngr
# Add -I prefix to all include directories
dev_mngr_INCLUDE_DIRS = $(addprefix -I, $(dev_mngr_ALL_DIRS))
dev_mngr_all_OUT = dev_mngr
......@@ -9,9 +9,8 @@
#include <glob.h>
#include "dev_mngr_core.h"
#include "hal_assert.h"
#include "debug_print.h"
#include "hal_utils.h"
#include "errhand.h"
#include "hutils.h"
/* Undef ASSERT_ALLOC to avoid conflicting with other ASSERT_ALLOC */
#ifdef ASSERT_TEST
......@@ -131,7 +130,7 @@ dmngr_t * dmngr_new (char *name, char *endpoint, int verbose,
/* Set logfile available for all dev_mngr and dev_io instances.
* We accept NULL as a parameter, meaning to suppress all messages */
debug_set_log (log_filename, DEVMNGR_DFLT_LOG_MODE);
errhand_set_log (log_filename, DEVMNGR_DFLT_LOG_MODE);
DBE_DEBUG (DBG_DEV_MNGR | DBG_LVL_INFO, "[dev_mngr_core] Spawing DEV_MNGR worker"
" with \n\tdiscovery endpoint (ignored for now) %s, with logfile %s"
......@@ -426,9 +425,9 @@ dmngr_err_e dmngr_spawn_all_devios (dmngr_t *self, char *broker_endp,
/* Alloc and convert types */
dev_type_c = llio_type_to_str (devio_info->type);
ASSERT_ALLOC (dev_type_c, err_dev_type_c_alloc, DMNGR_ERR_ALLOC);
dev_id_c = halutils_stringify_dec_key (devio_info->id);
dev_id_c = hutils_stringify_dec_key (devio_info->id);
ASSERT_ALLOC (dev_id_c, err_dev_id_c_alloc, DMNGR_ERR_ALLOC);
smio_inst_id_c = halutils_stringify_dec_key (devio_info->smio_inst_id);
smio_inst_id_c = hutils_stringify_dec_key (devio_info->smio_inst_id);
ASSERT_ALLOC (smio_inst_id_c, err_smio_inst_id_c_alloc, DMNGR_ERR_ALLOC);
/* Argument options are "process name", "device type" and
......
......@@ -8,8 +8,7 @@
#include <string.h>
#include "dev_mngr_dev_info.h"
#include "hal_assert.h"
#include "debug_print.h"
#include "errhand.h"
/* Undef ASSERT_ALLOC to avoid conflicting with other ASSERT_ALLOC */
#ifdef ASSERT_TEST
......
boards_DIR = $(SRC_DIR)/hal/boards
boards_INCLUDE_DIRS = $(boards_DIR)/$(BOARD)
debug_DIR = $(SRC_DIR)/hal/debug
debug_OBJS = $(debug_DIR)/debug_print.o \
$(debug_DIR)/local_print.o \
$(debug_DIR)/debug_subsys.o
debug_INCLUDE_DIRS = $(debug_DIR)
/*
* 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 <stdio.h>
#include "debug_subsys.h" /* This must come before "hal_opts.h" */
#include "hal_opts.h"
struct _zmsg_t;
/************** 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);
void debug_log_print (int dbg_lvl, const char *fmt, ...) __attribute__((format(printf,2,3)));
/* Set the output logfile Defaults to STDOUT */
void debug_set_log_file (FILE *log_file);
int debug_set_log (const char *log_file_name, const char *mode);
void debug_log_print_zmq_msg (struct _zmsg_t *msg);
/********************** 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)
#define dbg_log_print(dbg_lvl, fmt, ...) \
debug_log_print(dbg_lvl, fmt, ## __VA_ARGS__)
#else
#define dbg_print(fmt, ...)
#define dbg_print_vec(fmt, data, len)
#define dbg_log_print(dbg_lvl, fmt, ...)
#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_log_print((dbg) & DBG_LVL_MASK, \
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)
#define DBG_SUBSYS_DEGEN(val) ((val & DBG_SUBSYS_MASK) >> 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_LIB_CLIENT_RAW 0x40 /* The client library shares this macros */
#define DBG_SM_PR_RAW 0x80
#define DBG_SM_CH_RAW 0x100
#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)
/* The client library shares this macros */
#define DBG_LIB_CLIENT DBG_SUBSYS_GEN(DBG_LIB_CLIENT_RAW)
#define DBG_SM_PR DBG_SUBSYS_GEN(DBG_SM_PR_RAW)
#define DBG_SM_CH DBG_SUBSYS_GEN(DBG_SM_CH_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)
#define DBG_LVL_DEGEN(val) ((val & DBG_LVL_MASK) >> DBG_LVL_SHIFT)
#define DBG_LVL_NUM 5
/* 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)
#define DBG_LVL_TRACE_STR "TRACE"
#define DBG_LVL_INFO_STR "INFO"
#define DBG_LVL_WARN_STR "WARN"
#define DBG_LVL_ERR_STR "ERR"
#define DBG_LVL_FATAL_STR "FATAL"
extern const char *dbg_lvl_str [DBG_LVL_NUM];
char *dbg_lvl_to_str (int dbg_lvl);
/****************** 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)
#define DBG_HALT_DEGEN(val) ((val & DBG_HALT_MASK) >> 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
dev_io_utils_DIR = $(SRC_DIR)/hal/dev_io/utils
dev_io_utils_OBJS = $(dev_io_utils_DIR)/dev_io_utils.o
dev_io_utils_INCLUDE_DIRS = $(dev_io_utils_DIR)
# debug.mk must be declared before dev_mngr.mk, as they are variables
# exported by the former used by the latter
include $(SRC_DIR)/hal/debug/debug.mk
include $(SRC_DIR)/hal/ll_io/ll_io.mk
include $(SRC_DIR)/hal/sm_io/sm_io.mk
include $(SRC_DIR)/hal/sdb/sdb.mk
include $(SRC_DIR)/hal/dev_mngr/dev_mngr.mk
include $(SRC_DIR)/hal/dev_io/dev_io.mk
include $(SRC_DIR)/hal/msg/msg.mk
include $(SRC_DIR)/hal/hal_utils/hal_utils.mk
include $(SRC_DIR)/hal/boards/boards.mk
std_hal_INCLUDE_DIRS = $(SRC_DIR)/hal/include \
$(SRC_DIR)/hal/include/hw \
$(SRC_DIR)/hal/include/protocols \
$(SRC_DIR)/hal/include/chips
hal_OUT += $(dev_mngr_OUT) $(dev_io_OUT)
# All possible objects. Used for cleaning
hal_all_OUT += $(dev_mngr_all_OUT) $(dev_io_all_OUT)
# For each target in hal_OUT we add the necessary objects
# We need exp_ops_OBJS for hal_utils_OBJS, so we include it here.
dev_mngr_OBJS += $(dev_mngr_core_OBJS) $(debug_OBJS) \
$(hal_utils_OBJS) $(exp_ops_OBJS) \
$(thsafe_msg_zmq_OBJS) $(ll_io_utils_OBJS) \
$(dev_io_utils_OBJS)
# msg_OBJS already contains exp_ops_OBJS. So, there is no need to include
# it here twice
dev_io_OBJS += $(dev_io_core_OBJS) $(ll_io_OBJS) $(sm_io_OBJS) \
$(msg_OBJS) $(debug_OBJS) $(hal_utils_OBJS)
dev_io_cfg_OBJS += $(dev_io_core_OBJS) $(ll_io_OBJS) $(sm_io_OBJS) \
$(msg_OBJS) $(debug_OBJS) $(hal_utils_OBJS)
dev_mngr_LIBS =
dev_mngr_STATIC_LIBS =
dev_io_LIBS = -lbsmp
dev_io_STATIC_LIBS = $(LIBBPMCLIENT_DIR)/libbpmclient.a
dev_io_cfg_LIBS = -lbsmp
dev_io_cfg_STATIC_LIBS = $(LIBBPMCLIENT_DIR)/libbpmclient.a
# 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) \
$(boards_INCLUDE_DIRS)
# Change the include dirs into flags
hal_INCLUDE_DIRS = $(addprefix -I, $(hal_all_INCLUDE_DIRS))
hal_utils_DIR = $(SRC_DIR)/hal/hal_utils
# We depend on "msg.c" fucntions to determine which message
# we are dealing with
hal_utils_OBJS = $(hal_utils_DIR)/hal_utils.o \
$(hal_utils_DIR)/hal_math.o \
$(hal_utils_DIR)/hal_utils_err.o \
$(hal_utils_DIR)/dispatch_table.o \
$(msg_DIR)/msg.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",
[HALUTILS_ERR_NO_FUNC_REG] = "No function registered",
[HALUTILS_ERR_INV_LESS_ARGS] = "Less arguments than specified passed",
[HALUTILS_ERR_INV_MORE_ARGS] = "More arguments than specified passed",
[HALUTILS_ERR_INV_SIZE_ARG] = "Invalid size of argument size"
};
/* 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_NO_FUNC_REG, /* No function registered */
HALUTILS_ERR_INV_LESS_ARGS, /* Less arguments than specified passed */
HALUTILS_ERR_INV_MORE_ARGS, /* More arguments than specified passed */
HALUTILS_ERR_INV_SIZE_ARG, /* Invalid size of argument size */
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"
#include "hal_varg.h"
/* TODO: find a way avoid modifying the "global" err variable */
#define SET_ERR_VAR(err_code) WHENNOT(ISEMPTY(err_code))( \
err = err_code)
/* 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, /* err_code*/ ...) \
do { \
if(!(test_boolean)) { \
DBE_DEBUG (DBG_ ##debug_subsys | DBG_LVL_FATAL, \
debug_name " %s\n", err_str); \
SET_ERR_VAR(/* err_code*/ __VA_ARGS__); \
goto err_goto_label; \
} \
} while(0)
#define ASSERT_HAL_ALLOC(ptr, debug_subsys, debug_name, \
err_str, err_goto_label, /* err_code*/ ...) \
ASSERT_HAL_TEST(ptr!=NULL, debug_subsys, debug_name, \
err_str, err_goto_label, /* err_code*/ __VA_ARGS__)
#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>
*
* 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 = $(SRC_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
......@@ -38,16 +38,25 @@ ifeq ($(BOARD),afcv3)
CFLAGS += -D__BOARD_AFCV3__
endif
LOCAL_MSG_DBG ?= n
DBE_DBG ?= n
CFLAGS_DEBUG =
ifeq ($(LOCAL_MSG_DBG),y)
CFLAGS_DEBUG += -DLOCAL_MSG_DBG=1
# To enable this option, use: make ERRHAND_DBG=y
ifneq ($(ERRHAND_DBG),)
CFLAGS_DEBUG += -DERRHAND_DBG=$(ERRHAND_DBG)
endif
ifeq ($(DBE_DBG),y)
CFLAGS_DEBUG += -DDBE_DBG=1
# To enable this option use: make ERRHAND_MIN_LEVEL=DBG_MIN_TRACE
ifneq ($(ERRHAND_MIN_LEVEL),)
CFLAGS_DEBUG += -DERRHAND_MIN_LEVEL=$(ERRHAND_MIN_LEVEL)
endif
# To enable this option use: make ERRHAND_SUBSYS_ON='"(DBG_DEV_MNGR | \
# DBG_DEV_IO | DBG_SM_IO | DBG_LIB_CLIENT | DBG_SM_PR | DBG_SM_CH | DBG_LL_IO | DBG_HAL_UTILS)"'
#
# You can also OR the available subsytems to enable debug messages in just the
# those subsytems. See file errhand_opts.h for more information
ifneq ($(ERRHAND_SUBSYS_ON),)
CFLAGS_DEBUG += -DERRHAND_SUBSYS_ON=$(ERRHAND_SUBSYS_ON)
endif
# Debug flags -D<flasg_name>=<value>
......@@ -64,33 +73,32 @@ LIBS = -lzmq -lczmq -lmdp
LFLAGS =
# Specific board objects
OBJS_BOARD = ../../hal/sm_io/modules/acq/ddr3_map.o
OBJS_BOARD = ../../sm_io/modules/acq/ddr3_map.o
# Specific platform objects
OBJS_PLATFORM = ../../hal/debug/debug_print.o ../../hal/debug/local_print.o \
../../hal/debug/debug_subsys.o
OBJS_PLATFORM =
# Objects that are not specificaly related to the bpm_client, but composes
# our library, as it eases some tasks for us
OBJS_EXTERNAL = ../../hal/sm_io/modules/sm_io_codes.o \
../../hal/sm_io/modules/acq/sm_io_acq_exports.o \
../../hal/sm_io/modules/dsp/sm_io_dsp_exports.o \
../../hal/sm_io/modules/fmc130m_4ch/sm_io_fmc130m_4ch_exports.o \
../../hal/sm_io/modules/swap/sm_io_swap_exports.o \
../../hal/sm_io/modules/rffe/sm_io_rffe_exports.o \
../../hal/sm_io/modules/afc_diag/sm_io_afc_diag_exports.o
OBJS_EXTERNAL = ../../sm_io/modules/sm_io_codes.o \
../../sm_io/modules/acq/sm_io_acq_exports.o \
../../sm_io/modules/dsp/sm_io_dsp_exports.o \
../../sm_io/modules/fmc130m_4ch/sm_io_fmc130m_4ch_exports.o \
../../sm_io/modules/swap/sm_io_swap_exports.o \
../../sm_io/modules/rffe/sm_io_rffe_exports.o \
../../sm_io/modules/afc_diag/sm_io_afc_diag_exports.o
# Project boards
boards_INCLUDE_DIRS = -I../../../include/boards/$(BOARD)
# Include directories
INCLUDE_DIRS = -I. -I../../hal/include -I../../hal/debug \
-I../../hal/sm_io/modules \
-I../../hal/sm_io/modules/fmc130m_4ch \
-I../../hal/sm_io/modules/acq \
-I../../hal/sm_io/modules/swap \
-I../../hal/sm_io/modules/dsp \
-I../../hal/sm_io/modules/rffe \
-I../../hal/sm_io/modules/afc_diag \
-I../../hal/sm_io/rw_param \
-I../../hal/hal_utils \
-I../../hal/include/hw \
-I../../hal/boards/$(BOARD) \
INCLUDE_DIRS = -I. -I../../../include -I../liberrhand -I../libhutils -I../libdisptable \
$(boards_INCLUDE_DIRS) \
-I../../sm_io/modules \
-I../../sm_io/modules/fmc130m_4ch \
-I../../sm_io/modules/acq \
-I../../sm_io/modules/swap \
-I../../sm_io/modules/dsp \
-I../../sm_io/modules/rffe \
-I../../sm_io/modules/afc_diag \
-I/usr/local/include
# Merge all flags. Optimize for size (-Os)
......@@ -104,52 +112,50 @@ OUT = $(LIBBPMCLIENT)
.SECONDEXPANSION:
# Library objects
$(LIBBPMCLIENT)_OBJS_LIB = bpm_client.o bpm_client_err.o rw_param_client.o
$(LIBBPMCLIENT)_OBJS_LIB = bpm_client.o bpm_client_err.o bpm_client_rw_param.o
# Objects common for both server and client libraries.
common_OBJS = $(OBJS_BOARD) $(OBJS_PLATFORM) $(OBJS_EXTERNAL)
# Objects for each version of library
$(LIBBPMCLIENT)_OBJS = $(common_OBJS) $($(LIBBPMCLIENT)_OBJS_LIB)
$(LIBBPMCLIENT)_CODE_HEADERS = ../../hal/sm_io/modules/fmc130m_4ch/sm_io_fmc130m_4ch_codes.h \
../../hal/sm_io/modules/acq/sm_io_acq_codes.h \
../../hal/sm_io/modules/dsp/sm_io_dsp_codes.h \
../../hal/sm_io/modules/swap/sm_io_swap_codes.h \
../../hal/sm_io/modules/rffe/sm_io_rffe_codes.h \
../../hal/sm_io/modules/afc_diag/sm_io_afc_diag_codes.h \
../../hal/sm_io/modules/sm_io_codes.h \
../../hal/include/acq_chan_gen_defs.h \
../../hal/hal_utils/dispatch_table.h \
../../hal/hal_utils/hal_utils_err.h \
$(LIBBPMCLIENT)_CODE_HEADERS = ../../sm_io/modules/fmc130m_4ch/sm_io_fmc130m_4ch_codes.h \
../../sm_io/modules/acq/sm_io_acq_codes.h \
../../sm_io/modules/dsp/sm_io_dsp_codes.h \
../../sm_io/modules/swap/sm_io_swap_codes.h \
../../sm_io/modules/rffe/sm_io_rffe_codes.h \
../../sm_io/modules/afc_diag/sm_io_afc_diag_codes.h \
../../sm_io/modules/sm_io_codes.h \
../../../include/acq_chan_gen_defs.h \
../libdisptable/disp_table.h \
../libdisptable/disp_table_err.h \
../libhutils/hutils.h \
../libhutils/hutils_err.h \
../libhutils/hutils_math.h \
../libhutils/hutils_utils.h \
bpm_client_codes.h
$(LIBBPMCLIENT)_FUNC_EXPORTS = ../../hal/sm_io/modules/fmc130m_4ch/sm_io_fmc130m_4ch_exports.h \
../../hal/sm_io/modules/acq/sm_io_acq_exports.h \
../../hal/sm_io/modules/dsp/sm_io_dsp_exports.h \
../../hal/sm_io/modules/swap/sm_io_swap_exports.h \
../../hal/sm_io/modules/rffe/sm_io_rffe_exports.h \
../../hal/sm_io/modules/afc_diag/sm_io_afc_diag_exports.h
$(LIBBPMCLIENT)_FUNC_EXPORTS = ../../sm_io/modules/fmc130m_4ch/sm_io_fmc130m_4ch_exports.h \
../../sm_io/modules/acq/sm_io_acq_exports.h \
../../sm_io/modules/dsp/sm_io_dsp_exports.h \
../../sm_io/modules/swap/sm_io_swap_exports.h \
../../sm_io/modules/rffe/sm_io_rffe_exports.h \
../../sm_io/modules/afc_diag/sm_io_afc_diag_exports.h
# Install only specific acq_chan.h defintions according to the BOARD MACRO
# ../../hal/include/mem_layout/ml605/acq_chan_ml605.h \
# ../../hal/include/mem_layout/afcv3/acq_chan_afcv3.h
$(LIBBPMCLIENT)_ACQ_HEADER_BASENAME = acq_chan
$(LIBBPMCLIENT)_ACQ_HEADERS += \
../../hal/include/board/$(BOARD)/$($(LIBBPMCLIENT)_ACQ_HEADER_BASENAME)_$(BOARD).h
$(LIBBPMCLIENT)_ACQ_HEADERS += ../../../include/acq_chan.h
$(LIBBPMCLIENT)_HEADERS = $($(LIBBPMCLIENT)_OBJS_LIB:.o=.h) $($(LIBBPMCLIENT)_CODE_HEADERS) \
$($(LIBBPMCLIENT)_FUNC_EXPORTS)
# Installation headers
$(LIBBPMCLIENT)_INST_HEADERS = $($(LIBBPMCLIENT)_HEADERS) $($(LIBBPMCLIENT)_ACQ_HEADER_BASENAME).h
$(LIBBPMCLIENT)_INST_HEADERS = $($(LIBBPMCLIENT)_HEADERS)
# Save a git repository description
GIT_REVISION = $(shell git describe --dirty --always)
GIT_USER_NAME = $(shell git config --get user.name)
GIT_USER_EMAIL = $(shell git config --get user.email)
REVISION_NAME = revision
REVISION_NAME = bpm_client_revision
OBJ_REVISION = $(addsuffix .o, $(REVISION_NAME))
OBJS_all = $(common_OBJS) $($(LIBBPMCLIENT)_OBJS) \
......@@ -170,7 +176,7 @@ TARGET_SHARED_VER = $(addsuffix $(LIB_SHARED_SUFFIX).$(LIB_VER), $(OUT))
.SECONDARY: $(OBJS_all)
# Makefile rules
all: $(TARGET_STATIC) $(TARGET_SHARED_VER) pre_inst
all: $(TARGET_STATIC) $(TARGET_SHARED_VER)
# Compile static library
%.a: $$($$*_OBJS) $(OBJ_REVISION)
......@@ -221,15 +227,6 @@ $(REVISION_NAME).o: $(REVISION_NAME).c
# $(MAKE) -C $@ all
#
# Prepare the environment for install rule
pre_inst:
$(foreach header,$($(LIBBPMCLIENT)_ACQ_HEADERS),cp -p $(header) \
$(PWD)/$($(LIBBPMCLIENT)_ACQ_HEADER_BASENAME).h $(CMDSEP))
pre_clean:
$(foreach header,$(PWD)/$($(LIBBPMCLIENT)_ACQ_HEADER_BASENAME).h, \
rm -f $(header) $(CMDSEP))
install:
$(foreach lib,$(TARGET_SHARED_VER),install -m 755 $(lib) $(INSTALL_DIR)/lib $(CMDSEP))
$(foreach lib,$(TARGET_SHARED),ln -sf $(lib).$(LIB_VER) $(INSTALL_DIR)/lib/$(lib) $(CMDSEP))
......@@ -245,7 +242,7 @@ uninstall:
$(foreach header,$(notdir $($(LIBBPMCLIENT)_INST_HEADERS)),rm -f \
$(INSTALL_DIR)/include/$(header) $(CMDSEP))
clean: pre_clean
clean:
rm -f $(OBJS_all) $(OBJS_all:.o=.d) $(REVISION_NAME).o
mrproper: clean
......
Project Dependencies:
liberrhand
libhutils
libdisptable
Foreign Dependencies:
libmdp
libczmq
libzmq
......@@ -6,14 +6,14 @@
*/
#include "bpm_client.h"
#include "hal_assert.h"
#include "errhand.h"
#include "sm_io_acq_codes.h"
#include "sm_io_dsp_codes.h"
#include "sm_io_swap_codes.h"
#include "sm_io_swap_useful_macros.h"
#include "rw_param_codes.h"
#include "rw_param_client.h"
#include "bpm_client_rw_param_codes.h"
#include "bpm_client_rw_param.h"
/* Undef ASSERT_ALLOC to avoid conflicting with other ASSERT_ALLOC */
#ifdef ASSERT_TEST
......@@ -118,7 +118,7 @@ static bpm_client_t *_bpm_client_new (char *broker_endp, int verbose,
/* Set logfile available for all dev_mngr and dev_io instances.
* We accept NULL as a parameter, meaning to suppress all messages */
debug_set_log (log_file_name, log_mode);
errhand_set_log (log_file_name, log_mode);
DBE_DEBUG (DBG_LIB_CLIENT | DBG_LVL_INFO, "[libclient] Spawing LIBBPMCLIENT"
" with broker address %s, with logfile on %s ...\n", broker_endp,
......
......@@ -5,11 +5,11 @@
* Released according to the GNU LGPL, version 3 or any later version.
*/
#include "hal_assert.h"
#include "errhand.h"
#include "bpm_client.h"
#include "rw_param_client.h"
#include "rw_param_codes.h"
#include "bpm_client_rw_param.h"
#include "bpm_client_rw_param_codes.h"
/* Undef ASSERT_ALLOC to avoid conflicting with other ASSERT_ALLOC */
#ifdef ASSERT_TEST
......
......@@ -5,14 +5,14 @@
* Released according to the GNU LGPL, version 3 or any later version.
*/
#ifndef _RW_PARAM_CLIENT_H_
#define _RW_PARAM_CLIENT_H_
#ifndef _BPM_CLIENT_RW_PARAM_H_
#define _BPM_CLIENT_RW_PARAM_H_
#include <inttypes.h>
#include <mdp.h>
#include "bpm_client_codes.h"
#include "rw_param_codes.h"
#include "bpm_client_rw_param_codes.h"
#include "bpm_client_err.h"
#define READ_MODE 1
......
/*
* 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 _BPM_CLIENT_RW_PARAM_CODES_
#define _BPM_CLIENT_RW_PARAM_CODES_
/* Messaging Reply OPCODES */
#define RW_REPLY_SIZE (sizeof(uint32_t))
#define RW_REPLY_TYPE uint32_t
#define RW_OK 0 /* Read operation was successful */
#define RW_OOR 1 /* Parameter is out of range */
#define RW_USR_ERR 2 /* Parameter unmet user conditions */
#define RW_INV 3 /* Parameter is invalid */
#define RW_READ_EAGAIN 4 /* Read operation was incomplete */
#define RW_WRITE_EAGAIN 5 /* Write operation was incomplete */
#define RW_REPLY_END 6 /* End marker */
#define PARAM_OK 0
#define PARAM_ERR 1
#endif
# 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
PWD = $(shell pwd)
LIBCONVC = libconvc
# General C flags
CFLAGS = -std=gnu99 -O2
# To enable this option, use: make ERRHAND_DBG=y
ifneq ($(ERRHAND_DBG),)
CFLAGS_DEBUG += -DERRHAND_DBG=$(ERRHAND_DBG)
endif
# To enable this option use: make ERRHAND_MIN_LEVEL=DBG_MIN_TRACE
ifneq ($(ERRHAND_MIN_LEVEL),)
CFLAGS_DEBUG += -DERRHAND_MIN_LEVEL=$(ERRHAND_MIN_LEVEL)
endif
# To enable this option use: make ERRHAND_SUBSYS_ON='"(DBG_DEV_MNGR | \
# DBG_DEV_IO | DBG_SM_IO | DBG_LIB_CLIENT | DBG_SM_PR | DBG_SM_CH | DBG_LL_IO | DBG_HAL_UTILS)"'
#
# You can also OR the available subsytems to enable debug messages in just the
# those subsytems. See file errhand_opts.h for more information
ifneq ($(ERRHAND_SUBSYS_ON),)
CFLAGS_DEBUG += -DERRHAND_SUBSYS_ON=$(ERRHAND_SUBSYS_ON)
endif
# Debug flags -D<flasg_name>=<value>
CFLAGS_DEBUG += -g
# Specific platform Flags
CFLAGS_PLATFORM = -Wall -Wextra -Werror
LDFLAGS_PLATFORM =
# Libraries
LIBS =
# General library flags -L<libdir>
LFLAGS =
# Include directories
INCLUDE_DIRS = -I. -I../liberrhand
# Merge all flags. Optimize for size (-Os)
CFLAGS += $(CFLAGS_PLATFORM) $(CFLAGS_DEBUG)
LDFLAGS = $(LDFLAGS_PLATFORM)
# Output library names
OUT = $(LIBCONVC)
.SECONDEXPANSION:
# Library objects
$(LIBCONVC)_OBJS_LIB = convc.o convc_err.o
# Objects common for this library
common_OBJS =
# Objects for each version of library
$(LIBCONVC)_OBJS = $(common_OBJS) $($(LIBCONVC)_OBJS_LIB)
$(LIBCONVC)_CODE_HEADERS =
$(LIBCONVC)_HEADERS = $($(LIBCONVC)_OBJS_LIB:.o=.h) $($(LIBCONVC)_CODE_HEADERS)
OBJS_all = $(common_OBJS) $($(LIBCONVC)_OBJS)
# Libraries suffixes
LIB_STATIC_SUFFIX = .a
# Generate suitable names for static libraries
TARGET_STATIC = $(addsuffix $(LIB_STATIC_SUFFIX), $(OUT))
.PHONY: all clean mrproper install uninstall
# Avoid deletion of intermediate files, such as objects
.SECONDARY: $(OBJS_all)
# Makefile rules
all: $(TARGET_STATIC)
# Compile static library
%.a: $$($$*_OBJS)
$(AR) rcs $@ $^
# 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)
# Compile with position-independent objects.
# 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
install:
uninstall:
clean:
rm -f $(OBJS_all) $(OBJS_all:.o=.d)
mrproper: clean
rm -f *.a
Project Dependencies:
liberrhand
Foreign Dependencies:
......@@ -8,74 +8,69 @@
#include <unistd.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include <czmq.h>
#include "ll_io.h"
#include "hal_assert.h"
#include "errhand.h"
#include "convc.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, /* err_core */ ...) \
ASSERT_HAL_TEST(test_boolean, LL_IO, "[ll_io:utils]", \
ASSERT_HAL_TEST(test_boolean, HAL_UTILS, "[convc]", \
err_str, err_goto_label, /* err_core */ __VA_ARGS__)
#ifdef ASSERT_ALLOC
#undef ASSERT_ALLOC
#endif
#define ASSERT_ALLOC(ptr, err_goto_label, /* err_core */ ...) \
ASSERT_HAL_ALLOC(ptr, LL_IO, "[ll_io:utils]", \
llio_err_str(LLIO_ERR_ALLOC), \
#define ASSERT_ALLOC(ptr, err_goto_label, /* err_core */ ...) \
ASSERT_HAL_ALLOC(ptr, HAL_UTILS, "[convc]", \
convc_err_str(CONVC_ERR_ALLOC), \
err_goto_label, /* err_core */ __VA_ARGS__)
#ifdef CHECK_ERR
#undef CHECK_ERR
#endif
#define CHECK_ERR(err, err_type) \
CHECK_HAL_ERR(err, LL_IO, "[ll_io:utils]", \
llio_err_str (err_type))
#define CHECK_ERR(err, err_type) \
CHECK_HAL_ERR(err, HAL_UTILS, "[convc]", \
convc_err_str (err_type))
#define LLIO_TYPE_STR_SIZE 16
#define CONVC_TYPE_STR_SIZE 16
/************** Utility functions ****************/
static const llio_types_t llio_dev_types_map [] ={
{.name = GENERIC_DEV_STR, .type = GENERIC_DEV},
{.name = PCIE_DEV_STR, .type = PCIE_DEV},
{.name = ETH_DEV_STR, .type = ETH_DEV},
{.name = INVALID_DEV_STR, .type = INVALID_DEV},
{.name = LLIO_TYPE_NAME_END, .type = LLIO_TYPE_END} /* End marker */
};
char *llio_gen_type_to_str (int type, const llio_types_t *llio_types)
char *convc_gen_type_to_str (int type, const convc_types_t *convc_types)
{
/* Should be large enough for all possible debug levels */
size_t size = LLIO_TYPE_STR_SIZE;
size_t size = CONVC_TYPE_STR_SIZE;
char *str = zmalloc (size*sizeof (char));
ASSERT_ALLOC(str, err_alloc_str);
/* Do a simple linear search to look for matching IDs */
uint32_t i;
for (i = 0; llio_types [i].type != LLIO_TYPE_END; ++i) {
if (type == llio_types [i].type) {
const char *type_str = llio_types [i].name;
for (i = 0; convc_types [i].type != CONVC_TYPE_END; ++i) {
if (type == convc_types [i].type) {
const char *type_str = convc_types [i].name;
int errs = snprintf (str, size, "%s", type_str);
ASSERT_TEST (errs >= 0,
"[ll_io:utils] Could not clone string. Enconding error?\n",
"[convc] Could not clone string. Enconding error?\n",
err_copy_str);
/* This shouldn't happen. Only when the number of characters written is
* less than the whole buffer, it is guaranteed that the string was
* written successfully */
ASSERT_TEST ((size_t) errs < size,
"[ll_io:utils] Cloned string was truncated\n", err_trunc_str);
"[convc] Cloned string was truncated\n", err_trunc_str);
break;
}
}
/* No device found */
if (llio_types [i].type == LLIO_TYPE_END) {
if (convc_types [i].type == CONVC_TYPE_END) {
free (str);
str = NULL;
}
......@@ -91,21 +86,16 @@ err_alloc_str:
return NULL;
}
char *llio_type_to_str (llio_type_e type)
{
return llio_gen_type_to_str (type, llio_dev_types_map);
}
int llio_str_to_gen_type (const char *type_str, const llio_types_t *llio_types)
int convc_str_to_gen_type (const char *type_str, const convc_types_t *convc_types)
{
assert (type_str);
int type = LLIO_TYPE_END; /* Not found */
int type = CONVC_TYPE_END; /* Not found */
/* Do a simple linear search to look for matching names */
uint32_t i;
for (i = 0; llio_types [i].type != LLIO_TYPE_END; ++i) {
if (streq (type_str, llio_types [i].name)) {
type = llio_types [i].type;
for (i = 0; convc_types [i].type != CONVC_TYPE_END; ++i) {
if (streq (type_str, convc_types [i].name)) {
type = convc_types [i].type;
break;
}
}
......@@ -113,10 +103,3 @@ int llio_str_to_gen_type (const char *type_str, const llio_types_t *llio_types)
return type;
}
llio_type_e llio_str_to_type (const char *type_str)
{
llio_type_e ret = llio_str_to_gen_type (type_str, llio_dev_types_map);
return (ret == LLIO_TYPE_END)? INVALID_DEV : ret;
}
/*
* 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 _CONVC_H_
#define _CONVC_H_
#include <inttypes.h>
#include "convc_err.h"
#define CONVC_TYPE_END 0xFFFF
#define CONVC_TYPE_NAME_END ""
struct _convc_types_t {
int type;
char *name;
};
typedef struct _convc_types_t convc_types_t;
/************** Utility functions ****************/
/* Generic mapping functions */
/* Converts the CONVC type ID into a string */
char *convc_gen_type_to_str (int type, const convc_types_t *convc_types);
/* Converts a string to an CONVC type ID. If no match if found,
* a INVALID_DEV is returned */
int convc_str_to_gen_type (const char *type_str,
const convc_types_t *convc_types);
#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 "convc_err.h"
static const char *convc_err [CONVC_ERR_END] =
{
[CONVC_SUCCESS] = "Success",
[CONVC_ERR_ALLOC] = "Could not allocate memory"
};
/* Convert enumeration type to string */
const char * convc_err_str (convc_err_e err)
{
return convc_err [err];
}
/*
* Copyright (C) 2015 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 _CONVC_ERR_H_
#define _CONVC_ERR_H_
enum _convc_err_e
{
CONVC_SUCCESS = 0, /* No error */
CONVC_ERR_ALLOC, /* Could not allocate memory */
CONVC_ERR_END /* End of enum marker */
};
typedef enum _convc_err_e convc_err_e;
/* Convert enumeration type to string */
const char * convc_err_str (convc_err_e err);
#endif
# 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
PWD = $(shell pwd)
LIBDISPTABLE = libdisptable
# General C flags
CFLAGS = -std=gnu99 -O2
# To enable this option, use: make ERRHAND_DBG=y
ifneq ($(ERRHAND_DBG),)
CFLAGS_DEBUG += -DERRHAND_DBG=$(ERRHAND_DBG)
endif
# To enable this option use: make ERRHAND_MIN_LEVEL=DBG_MIN_TRACE
ifneq ($(ERRHAND_MIN_LEVEL),)
CFLAGS_DEBUG += -DERRHAND_MIN_LEVEL=$(ERRHAND_MIN_LEVEL)
endif
# To enable this option use: make ERRHAND_SUBSYS_ON='"(DBG_DEV_MNGR | \
# DBG_DEV_IO | DBG_SM_IO | DBG_LIB_CLIENT | DBG_SM_PR | DBG_SM_CH | DBG_LL_IO | DBG_HAL_UTILS)"'
#
# You can also OR the available subsytems to enable debug messages in just the
# those subsytems. See file errhand_opts.h for more information
ifneq ($(ERRHAND_SUBSYS_ON),)
CFLAGS_DEBUG += -DERRHAND_SUBSYS_ON=$(ERRHAND_SUBSYS_ON)
endif
# Debug flags -D<flasg_name>=<value>
CFLAGS_DEBUG += -g
# Specific platform Flags
CFLAGS_PLATFORM = -Wall -Wextra -Werror
LDFLAGS_PLATFORM =
# Libraries
LIBS =
# General library flags -L<libdir>
LFLAGS =
# Include directories
INCLUDE_DIRS = -I. -I../liberrhand -I../libhutils
# Merge all flags. Optimize for size (-Os)
CFLAGS += $(CFLAGS_PLATFORM) $(CFLAGS_DEBUG)
LDFLAGS = $(LDFLAGS_PLATFORM)
# Output library names
OUT = $(LIBDISPTABLE)
.SECONDEXPANSION:
# Library objects
$(LIBDISPTABLE)_OBJS_LIB = disp_table.o disp_table_err.o
# Objects common for this library
common_OBJS =
# Objects for each version of library
$(LIBDISPTABLE)_OBJS = $(common_OBJS) $($(LIBDISPTABLE)_OBJS_LIB)
$(LIBDISPTABLE)_CODE_HEADERS =
$(LIBDISPTABLE)_HEADERS = $($(LIBDISPTABLE)_OBJS_LIB:.o=.h) $($(LIBDISPTABLE)_CODE_HEADERS)
OBJS_all = $(common_OBJS) $($(LIBDISPTABLE)_OBJS)
# Libraries suffixes
LIB_STATIC_SUFFIX = .a
# Generate suitable names for static libraries
TARGET_STATIC = $(addsuffix $(LIB_STATIC_SUFFIX), $(OUT))
.PHONY: all clean mrproper install uninstall
# Avoid deletion of intermediate files, such as objects
.SECONDARY: $(OBJS_all)
# Makefile rules
all: $(TARGET_STATIC)
# Compile static library
%.a: $$($$*_OBJS)
$(AR) rcs $@ $^
# 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)
# Compile with position-independent objects.
# 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
install:
uninstall:
clean:
rm -f $(OBJS_all) $(OBJS_all:.o=.d)
mrproper: clean
rm -f *.a
Project Dependencies:
liberrhand
libhutils
Foreign Dependencies:
......@@ -15,17 +15,27 @@
#define _DISPATCH_TABLE_H_
#include <czmq.h>
#include "hal_utils_err.h"
#include "disp_table_err.h"
struct _disp_table_ops_t;
struct _disp_op_t;
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;
/* Dispatch table operations */
const struct _disp_table_ops_t *ops;
};
/* Opaque class structure */
typedef struct _disp_table_t disp_table_t;
/* Check message arguments function pointer */
typedef disp_table_err_e (*check_msg_args_fp)(struct _disp_table_t *self,
const struct _disp_op_t *disp_op, void *args);
struct _disp_table_ops_t {
check_msg_args_fp check_msg_args; /* Check message arguments */
};
/* Generic function pointer */
typedef int (*disp_table_func_fp)(void *owner, void * args, void *ret);
......@@ -48,6 +58,11 @@ enum _disp_at_e {
Typically a structure */
};
/* Opaque class structure */
typedef struct _disp_table_t disp_table_t;
/* Dispatch table operations */
typedef struct _disp_table_ops_t disp_table_ops_t;
/* Argument type */
typedef enum _disp_at_e disp_at_e;
/* FIXME: large arguments can overflow the macro!
......@@ -86,34 +101,46 @@ typedef struct _disp_op_t disp_op_t;
/* Handler for the Dispatch exported function */
typedef struct _disp_op_handler_t disp_op_handler_t;
/***************** Our methods *****************/
/************************************************************/
/********************* Generic methods API ******************/
/************************************************************/
/* Check message arguments */
disp_table_err_e disp_table_ops_check_msg (disp_table_t *self, const disp_op_t *disp_op,
void *args);
/************************************************************/
/************************* Our methods **********************/
/************************************************************/
disp_table_t *disp_table_new (void);
halutils_err_e disp_table_destroy (disp_table_t **self_p);
disp_table_t *disp_table_new (const disp_table_ops_t *ops);
disp_table_err_e disp_table_destroy (disp_table_t **self_p);
halutils_err_e disp_table_insert (disp_table_t *self, const disp_op_t *disp_op);
halutils_err_e disp_table_insert_all (disp_table_t *self,
disp_table_err_e disp_table_insert (disp_table_t *self, const disp_op_t *disp_op);
disp_table_err_e disp_table_insert_all (disp_table_t *self,
const disp_op_t **disp_ops);
halutils_err_e disp_table_remove (disp_table_t *self, uint32_t key);
halutils_err_e disp_table_remove_all (disp_table_t *self);
disp_table_err_e disp_table_remove (disp_table_t *self, uint32_t key);
disp_table_err_e disp_table_remove_all (disp_table_t *self);
halutils_err_e disp_table_fill_desc (disp_table_t *self, disp_op_t **disp_ops,
disp_table_err_e disp_table_fill_desc (disp_table_t *self, disp_op_t **disp_ops,
const disp_table_func_fp *func_fps);
halutils_err_e disp_table_check_args (disp_table_t *self, uint32_t key,
disp_table_err_e disp_table_check_args (disp_table_t *self, uint32_t key,
void *args, void **ret);
halutils_err_e disp_table_cleanup_args (disp_table_t *self, uint32_t key);
disp_table_err_e disp_table_cleanup_args (disp_table_t *self, uint32_t key);
const disp_op_t *disp_table_lookup (disp_table_t *self, uint32_t key);
int disp_table_call (disp_table_t *self, uint32_t key, void *owner, void *args,
void *ret);
int disp_table_check_call (disp_table_t *self, uint32_t key, void *owner,
void *args, void **ret);
halutils_err_e disp_table_set_ret (disp_table_t *self, uint32_t key, void **ret);
disp_table_err_e disp_table_set_ret (disp_table_t *self, uint32_t key, void **ret);
/*********************** Disp Op Handler functions ****************************/
/************************************************************/
/**************** Disp Op Handler functions *****************/
/************************************************************/
disp_op_handler_t *disp_op_handler_new (void);
halutils_err_e disp_op_handler_destroy (disp_op_handler_t **self_p);
disp_table_err_e disp_op_handler_destroy (disp_op_handler_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.
*/
/* Error definitions and output stringification based on the work available
* at the libsllp project repository: https://github.com/brunoseivam/libsllp */
#include "disp_table_err.h"
static const char *disp_table_err [DISP_TABLE_ERR_END] =
{
[DISP_TABLE_SUCCESS] = "Success",
[DISP_TABLE_ERR_ALLOC] = "Could not allocate memory",
[DISP_TABLE_ERR_NULL_POINTER] = "Null pointer received",
[DISP_TABLE_ERR_NO_FUNC_REG] = "No function registered"
};
/* Convert enumeration type to string */
const char * disp_table_err_str (disp_table_err_e err)
{
return disp_table_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 _DISP_TABLE_ERR_H_
#define _DISP_TABLE_ERR_H_
enum _disp_table_err_e
{
DISP_TABLE_SUCCESS = 0, /* No error */
DISP_TABLE_ERR_ALLOC, /* Could not allocate memory */
DISP_TABLE_ERR_NULL_POINTER, /* Null pointer received */
DISP_TABLE_ERR_NO_FUNC_REG, /* No function registered */
DISP_TABLE_ERR_END
};
typedef enum _disp_table_err_e disp_table_err_e;
/* Convert enumeration type to string */
const char * disp_table_err_str (disp_table_err_e err);
#endif
# 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
PWD = $(shell pwd)
LIBERRHAND = liberrhand
# Config variables suitable for creating shared libraries
LIB_VER_MAJOR = 1
LIB_VER_MINOR = 0
LIB_VER_REVISION = 0
LIB_VER = $(LIB_VER_MAJOR).$(LIB_VER_MINOR).$(LIB_VER_REVISION)
INSTALL_DIR ?= /usr/local
export INSTALL_DIR
# General C flags
CFLAGS = -std=gnu99 -O2 -fPIC
# To enable this option, use: make ERRHAND_DBG=y
ifneq ($(ERRHAND_DBG),)
CFLAGS_DEBUG += -DERRHAND_DBG=$(ERRHAND_DBG)
endif
# To enable this option use: make ERRHAND_MIN_LEVEL=DBG_MIN_TRACE
ifneq ($(ERRHAND_MIN_LEVEL),)
CFLAGS_DEBUG += -DERRHAND_MIN_LEVEL=$(ERRHAND_MIN_LEVEL)
endif
# To enable this option use: make ERRHAND_SUBSYS_ON='"(DBG_DEV_MNGR | \
# DBG_DEV_IO | DBG_SM_IO | DBG_LIB_CLIENT | DBG_SM_PR | DBG_SM_CH | DBG_LL_IO | DBG_HAL_UTILS)"'
#
# You can also OR the available subsytems to enable debug messages in just the
# those subsytems. See file errhand_opts.h for more information
ifneq ($(ERRHAND_SUBSYS_ON),)
CFLAGS_DEBUG += -DERRHAND_SUBSYS_ON=$(ERRHAND_SUBSYS_ON)
endif
# The following options are just for compatibility. Prefer the above ones!
ifneq ($(DBE_DBG),)
CFLAGS_DEBUG += -DDBE_DBG=$(DBE_DBG)
endif
ifneq ($(DBG_MIN_LEVEL),)
CFLAGS_DEBUG += -DDBG_MIN_LEVEL=$(DBG_MIN_LEVEL)
endif
ifneq ($(DBG_SUBSYS_ON),)
CFLAGS_DEBUG += -DDBG_SUBSYS_ON=$(DBG_SUBSYS_ON)
endif
# Debug flags -D<flasg_name>=<value>
CFLAGS_DEBUG += -g
# Specific platform Flags
CFLAGS_PLATFORM = -Wall -Wextra -Werror
LDFLAGS_PLATFORM =
# Libraries
LIBS =
# General library flags -L<libdir>
LFLAGS =
# Include directories
INCLUDE_DIRS = -I.
# Merge all flags. Optimize for size (-Os)
CFLAGS += $(CFLAGS_PLATFORM) $(CFLAGS_DEBUG)
LDFLAGS = $(LDFLAGS_PLATFORM)
# Output library names
OUT = $(LIBERRHAND)
.SECONDEXPANSION:
# Library objects
$(LIBERRHAND)_OBJS_LIB = errhand_print.o errhand_subsys.o errhand_local_print.o
# Objects common for this library
common_OBJS =
# Objects for each version of library
$(LIBERRHAND)_OBJS = $(common_OBJS) $($(LIBERRHAND)_OBJS_LIB)
$(LIBERRHAND)_CODE_HEADERS = errhand_opts.h errhand.h varg_macros.h
$(LIBERRHAND)_HEADERS = $($(LIBERRHAND)_OBJS_LIB:.o=.h) $($(LIBERRHAND)_CODE_HEADERS)
OBJS_all = $(common_OBJS) $($(LIBERRHAND)_OBJS)
# Libraries suffixes
LIB_STATIC_SUFFIX = .a
LIB_SHARED_SUFFIX = .so
# Generate suitable names for static libraries
TARGET_STATIC = $(addsuffix $(LIB_STATIC_SUFFIX), $(OUT))
TARGET_SHARED = $(addsuffix $(LIB_SHARED_SUFFIX), $(OUT))
TARGET_SHARED_VER = $(addsuffix $(LIB_SHARED_SUFFIX).$(LIB_VER), $(OUT))
.PHONY: all clean mrproper install uninstall
# Avoid deletion of intermediate files, such as objects
.SECONDARY: $(OBJS_all)
# Makefile rules
all: $(TARGET_STATIC) $(TARGET_SHARED_VER)
# Compile static library
%.a: $$($$*_OBJS)
$(AR) rcs $@ $^
# Compile dynamic library
%.so.$(LIB_VER): $$($$*_OBJS) $(OBJ_REVISION)
$(CC) -shared -fPIC -Wl,-soname,$@ -o $@ $^ $(LDFLAGS)
# 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)
# Compile with position-independent objects.
# 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
install:
$(foreach lib,$(TARGET_SHARED_VER),install -m 755 $(lib) $(INSTALL_DIR)/lib $(CMDSEP))
$(foreach lib,$(TARGET_SHARED),ln -sf $(lib).$(LIB_VER) $(INSTALL_DIR)/lib/$(lib) $(CMDSEP))
$(foreach lib,$(TARGET_SHARED),ln -sf $(lib).$(LIB_VER) $(INSTALL_DIR)/lib/$(lib).$(LIB_VER_MAJOR) $(CMDSEP))
$(foreach lib,$(TARGET_STATIC),install -m 755 $(lib) $(INSTALL_DIR)/lib $(CMDSEP))
$(foreach header,$($(LIBBPMCLIENT)_INST_HEADERS),install -m 755 $(header) $(INSTALL_DIR)/include $(CMDSEP))
uninstall:
$(foreach lib,$(TARGET_SHARED),rm -f $(INSTALL_DIR)/lib/$(lib).$(LIB_VER) $(CMDSEP))
$(foreach lib,$(TARGET_SHARED),rm -f $(INSTALL_DIR)/lib/$(lib) $(CMDSEP))
$(foreach lib,$(TARGET_SHARED),rm -f $(INSTALL_DIR)/lib/$(lib).$(LIB_VER_MAJOR) $(CMDSEP))
$(foreach lib,$(TARGET_STATIC),rm -f $(INSTALL_DIR)/lib/$(lib) $(CMDSEP))
$(foreach header,$(notdir $($(LIBBPMCLIENT)_INST_HEADERS)),rm -f \
$(INSTALL_DIR)/include/$(header) $(CMDSEP))
clean:
rm -f $(OBJS_all) $(OBJS_all:.o=.d)
mrproper: clean
rm -f *.a *.so.$(LIB_VER)
Project Dependencies:
Foreign Dependencies:
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