Commit 2856e2ea authored by Lucas Russo's avatar Lucas Russo

Merge branch 'devel'

parents 5fc880a0 8f0fd4b7
[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
[submodule "foreign/libmdp"]
path = foreign/libmdp
url = https://github.com/lerwys/majordomo.git
url = https://github.com/lnls-dig/fpga_pcie_driver.git
# Travis CI script
language: c
compiler:
- clang
- gcc
env:
- BOARD=ml605 WITH_EXAMPLES=with_examples
- BOARD=afcv3 WITH_EXAMPLES=with_examples
before_install:
- git submodule update --init --recursive
# Build-check-install all subprojects
before_script:
- sudo apt-get install uuid-dev
# libsodium
- git clone git://github.com/jedisct1/libsodium.git
- ( cd libsodium; ./autogen.sh; ./configure; make check; sudo make install; sudo ldconfig )
# libzmq
- git clone git://github.com/zeromq/libzmq.git
- ( cd libzmq; ./autogen.sh; ./configure; make check; sudo make install; sudo ldconfig )
# CZMQ
- git clone git://github.com/zeromq/czmq.git
- ( cd czmq; ./autogen.sh; ./configure; make check; sudo make install; sudo ldconfig )
# Zyre
- git clone git://github.com/zeromq/zyre.git
- ( cd zyre; ./autogen.sh; ./configure; make check; sudo make install; sudo ldconfig )
# Malamute
- git clone git://github.com/zeromq/malamute.git
- ( cd malamute; ./autogen.sh; ./configure; make check; sudo make install; sudo ldconfig )
# Build and check this project
script:
- ./ci_build.sh
This diff is collapsed.
[![Build Status](https://travis-ci.org/lnls-dig/bpm-sw.svg)](https://travis-ci.org/lnls-dig/bpm-sw)
# Beam Position Monitor Software
Software for controlling the AFC BPM boards
## Prerequisites:
Make sure you have the following libraries installed:
Make sure you have the following libraries installed, either by download
the binaries or executing the instructions below:
* zeromq-4.2.0 (http://zeromq.org/area:download)
* czmq-3.0.1 (http://czmq.zeromq.org/page:get-the-software)
* mlm-0.1.0 (https://github.com/zeromq/malamute.git)
* zeromq-4.0.4 (http://zeromq.org/area:download)
* czmq-2.2.0 (http://czmq.zeromq.org/page:get-the-software)
## Optional libraries:
Cloning this repository
* uuid (distribution available):
git clone --recursive https://github.com/lerwys/bpm-software.git
sudo apt-get install uuid
Install the Majordomo application from this repository (autotools-based)
### Prerequisites Installation Instructions
cd majordomo/libmdp
git clone git://github.com/zeromq/libzmq.git && \
git clone git://github.com/zeromq/czmq.git && \
git clone git://github.com/zeromq/malamute.git &&
for project in libsodium libzmq czmq malamute; do
cd $project
./autogen.sh
./configure && make check
sudo make install
sudo ldconfig
cd ..
done
Execute the traditional sequence of autotools commands:
## Cloning this repository
./autogen.sh && make && sudo make install
git clone --recursive https://github.com/lerwys/bpm-sw.git
## PCIe Installation Instructions
......@@ -47,28 +63,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 +101,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 +134,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 +201,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 <board type = [ml605|afcv3]>
### 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
......@@ -3,18 +3,24 @@ 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
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
CFG_DIR ?= /etc/bpm_sw
PREFIX ?= /usr/local
CFG_DIR ?= ${PREFIX}/etc/bpm_sw
# Get all .cfg files
CFG_FILES ?= $(wildcard *.cfg)
# Config file must have the following name
CFG_FILENAME = bpm_sw.cfg
# This could be set to a different config folder
CFG ?= crude_defconfig
# Get crude defconfig .cfg file
CFG_FILES = $(CFG)/$(CFG_FILENAME)
.PHONY: all clean mrproper install uninstall
......@@ -22,7 +28,7 @@ CFG_FILES ?= $(wildcard *.cfg)
all:
install:
@mkdir -p $(CFG_DIR)
@mkdir -m 755 -p $(CFG_DIR)
$(foreach cfg,$(CFG_FILES),install -m 755 $(cfg) $(CFG_DIR)/ $(CMDSEP))
uninstall:
......
......@@ -3,9 +3,9 @@
# Device manager configurations
dev_mngr
broker
bind = tcp://10.0.18.35:8888
bind = tcp://127.0.0.1:9999
log
dir = /export/remote_logs
dir = /media/remote_logs
filename = dev_mngr.log
verbose = 1 # Ask for a trace
daemonize = no # Ask for daemonize process (options are: yes or no)
......@@ -16,7 +16,7 @@ dev_io
bpm0
dbe
afe
bind = tcp://10.0.18.59:6791
bind =
bpm1
dbe
afe
......
# BPM-SW configuration file
# Device manager configurations
dev_mngr
broker
bind = tcp://127.0.0.1:9999
log
dir = /media/remote_logs
filename = dev_mngr.log
verbose = 1 # Ask for a trace
daemonize = no # Ask for daemonize process (options are: yes or no)
# Device I/O configurations
dev_io
board0
bpm0
dbe
afe
bind =
bpm1
dbe
afe
bind =
board1
bpm0
dbe
afe
bind =
bpm1
dbe
afe
bind =
board2
bpm0
dbe
afe
bind = tcp://10.2.117.210:6791
bpm1
dbe
afe
bind = tcp://10.2.117.211:6791
board3
bpm0
dbe
afe
bind = tcp://10.2.117.208:6791
bpm1
dbe
afe
bind = tcp://10.2.117.209:6791
board4
bpm0
dbe
afe
bind = tcp://10.2.117.206:6791
bpm1
dbe
afe
bind = tcp://10.2.117.207:6791
board5
bpm0
dbe
afe
bind =
bpm1
dbe
afe
bind =
board6
bpm0
dbe
afe
bind =
bpm1
dbe
afe
bind =
board7
bpm0
dbe
afe
bind = tcp://10.2.117.204:6791
bpm1
dbe
afe
bind = tcp://10.2.117.205:6791
board8
bpm0
dbe
afe
bind = tcp://10.2.117.202:6791
bpm1
dbe
afe
bind = tcp://10.2.117.203:6791
board9
bpm0
dbe
afe
bind = tcp://10.2.117.200:6791
bpm1
dbe
afe
bind = tcp://10.2.117.201:6791
board10
bpm0
dbe
afe
bind =
bpm1
dbe
afe
bind =
board11
bpm0
dbe
afe
bind =
bpm1
dbe
afe
bind =
#!/usr/bin/env bash
./compile.sh $BOARD $WITH_EXAMPLES
#!/bin/bash
#!/usr/bin/env bash
VALID_BOARDS_STR="Valid values are: \"ml605\" and \"afcv3\"."
VALID_WITH_EXAMPLES_STR="Valid values are: \"with_examples\" or \"without_examples\"."
#######################################
# All of our Makefile options
#######################################
# Select board in which we will work. Options are: ml605 or afcv3
BOARD=afcv3
BOARD=$1
if [ -z "$BOARD" ]; then
echo "\"BOARD\" variable unset. "$VALID_BOARDS_STR
exit 1
fi
if [ "$BOARD" != "afcv3" ] && [ "$BOARD" != "ml605" ]; then
echo "Unsupported board. "$VALID_BOARDS_STR
exit 1
fi
WITH_EXAMPLES=$2
if [ -n "$WITH_EXAMPLES" ] && [ "$WITH_EXAMPLES" != "with_examples" ] && [ "$WITH_EXAMPLES" != "without_examples" ]; then
echo "Wrong variable value. "$VALID_WITH_EXAMPLES_STR
exit 1
fi
# Select if we want to have the AFCv3 DDR memory shrink to 2^28 or the full size 2^32. Options are: (y)es ot (n)o.
# This is a TEMPORARY fix until the AFCv3 FPGA firmware is fixed. If unsure, select (y)es.
SHRINK_AFCV3_DDR_SIZE=y
#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:
......@@ -17,10 +47,18 @@ FMC130M_4CH_EEPROM_PROGRAM=
WITH_DEV_MNGR=y
# Selects the AFE RFFE version. Options are: 2
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=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
CFG_DIR=/etc/bpm_sw
PREFIX=/usr/local
CFG_DIR=${PREFIX}/etc/bpm_sw
# Selects which config file to install. Options are: crude_defconfig or lnls_defconfig
CFG=lnls_defconfig
export CFG
COMMAND_DEPS="\
make deps && \
......@@ -28,25 +66,39 @@ COMMAND_DEPS="\
COMMAND_HAL="\
make BOARD=${BOARD} \
SHRINK_AFCV3_DDR_SIZE=${SHRINK_AFCV3_DDR_SIZE} \
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} \
AFE_RFFE_TYPE=${AFE_RFFE_TYPE} \
WITH_DEVIO_CFG=${WITH_DEVIO_CFG} \
CFG_DIR=${CFG_DIR} && \
sudo make install"
sudo make CFG=${CFG} 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"
if [ "$WITH_EXAMPLES" = "with_examples" ]; then
COMMAND_EXAMPLES="\
make examples"
else
COMMAND_EXAMPLES=""
fi
COMMAND_ARRAY=(
"${COMMAND_DEPS}"
"${COMMAND_HAL}"
"${COMMAND_LIBCLIENT}"
"${COMMAND_LIBBPMCLIENT}"
"${COMMAND_EXAMPLES}"
)
for i in "${COMMAND_ARRAY[@]}"
......
......@@ -3,13 +3,13 @@ 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
CC ?= $(CROSS_COMPILE)gcc
AR ?= $(CROSS_COMPILE)ar
LD ?= $(CROSS_COMPILE)ld
OBJDUMP ?= $(CROSS_COMPILE)objdump
OBJCOPY ?= $(CROSS_COMPILE)objcopy
SIZE ?= $(CROSS_COMPILE)size
MAKE ?= make
# General C flags
CFLAGS = -std=gnu99 -O2
......@@ -30,11 +30,13 @@ endif
CFLAGS_DEBUG += -g
# Specific platform Flags
CFLAGS_PLATFORM = -Wall -Wextra -Werror
CFLAGS_PLATFORM = -Wall -Wextra -Werror \
-Wno-missing-field-initializers \
-Wno-missing-braces
LDFLAGS_PLATFORM =
# Libraries
LIBS = -lbpmclient -lmdp -lczmq -lzmq
LIBS = -lbpmclient -lerrhand -lhutils -lmlm -lczmq -lzmq
# General library flags -L<libdir>
LFLAGS =
......
Project Dependencies:
liberrhand
libhutils
libbpmclient
Foreign Dependencies:
libmlm
libczmq
libzmq
......@@ -3,7 +3,6 @@
* * a client and the FPGA device
* */
#include <mdp.h>
#include <czmq.h>
#include <inttypes.h>
#include <stdio.h>
......@@ -19,7 +18,6 @@
#define MAX_BPM_NUMBER 1
#define DFLT_BOARD_NUMBER 0
#define MAX_BOARD_NUMBER 5
/* Arbitrary hard limits */
#define MAX_NUM_SAMPLES (1 << 28)
......@@ -28,7 +26,7 @@
void print_data (uint32_t chan, uint32_t *data, uint32_t size)
{
/* FIXME: Make it more generic */
if (chan == 0 || chan == 9) {
if (chan == 0 || chan == 1 /* Only ADC and ADC SWAP */ ) {
int16_t *raw_data16 = (int16_t *) data;
for (uint32_t i = 0; i < (size/sizeof(uint16_t)) / 4; i++) {
if (zctx_interrupted) {
......@@ -66,6 +64,7 @@ void print_help (char *program_name)
"\t-b <broker_endpoint> Broker endpoint\n"
"\t-s <num_samples_str> Number of samples\n"
"\t-board <AMC board = [0|1|2|3|4|5]>\n"
"\t-bpm <BPM number = [0|1]>\n"
"\t-ch <chan_str> Acquisition channel\n"
, program_name);
}
......@@ -126,8 +125,6 @@ int main (int argc, char *argv [])
broker_endp = strdup ("ipc://"DFLT_BIND_FOLDER);
}
bpm_client_t *bpm_client = bpm_client_new (broker_endp, verbose, NULL);
/* Set default number samples */
uint32_t num_samples;
if (num_samples_str == NULL) {
......@@ -155,10 +152,10 @@ int main (int argc, char *argv [])
else {
chan = strtoul (chan_str, NULL, 10);
if (chan > MAX_NUM_CHANS) {
if (chan > END_CHAN_ID-1) {
fprintf (stderr, "[client:acq]: Channel number too big! Defaulting to: %u\n",
MAX_NUM_CHANS);
chan = MAX_NUM_CHANS;
chan = END_CHAN_ID-1;
}
}
//fprintf (stdout, "[client:acq]: chan = %u\n", chan);
......@@ -172,12 +169,6 @@ int main (int argc, char *argv [])
}
else {
board_number = strtoul (board_number_str, NULL, 10);
if (board_number > MAX_BOARD_NUMBER) {
fprintf (stderr, "[client:acq]: Board number too big! Defaulting to: %u\n",
MAX_BOARD_NUMBER);
board_number = MAX_BOARD_NUMBER;
}
}
/* Set default bpm number */
......@@ -198,11 +189,16 @@ int main (int argc, char *argv [])
}
char service[50];
sprintf (service, "BPM%u:DEVIO:ACQ%u", board_number, bpm_number);
snprintf (service, sizeof (service), "BPM%u:DEVIO:ACQ%u", board_number, bpm_number);
bpm_client_t *bpm_client = bpm_client_new (broker_endp, verbose, NULL);
if (bpm_client == NULL) {
fprintf (stderr, "[client:acq]: bpm_client could be created\n");
goto err_bpm_client_new;
}
uint32_t data_size = num_samples*acq_chan[chan].sample_size;
uint32_t *data = (uint32_t *) zmalloc (data_size*sizeof (uint8_t));
//bool new_acq = false;
bool new_acq = true;
acq_trans_t acq_trans = {.req = {
.num_samples = num_samples,
......@@ -224,6 +220,7 @@ int main (int argc, char *argv [])
fprintf (stdout, "clear\n");
print_data (chan, data, acq_trans.block.bytes_read);
err_bpm_client_new:
err_bpm_get_curve:
str_p = &chan_str;
free (*str_p);
......@@ -231,6 +228,9 @@ err_bpm_get_curve:
str_p = &board_number_str;
free (*str_p);
board_number_str = NULL;
str_p = &bpm_number_str;
free (*str_p);
bpm_number_str = NULL;
str_p = &num_samples_str;
free (*str_p);
num_samples_str = NULL;
......
/*
* * Simple example demonstrating the communication between
* * a client and the FPGA device
* */
* Controlling the AD9510 chip
*/
#include <mdp.h>
#include <czmq.h>
#include <inttypes.h>
#include <stdio.h>
#include <string.h>
......@@ -18,7 +15,6 @@
#define MAX_BPM_NUMBER 1
#define DFLT_BOARD_NUMBER 0
#define MAX_BOARD_NUMBER 5
#define FUNC_AD9510_A_DIV_IDX 0
#define FUNC_AD9510_B_DIV_IDX 1
......@@ -186,12 +182,6 @@ int main (int argc, char *argv [])
}
else {
board_number = strtoul (board_number_str, NULL, 10);
if (board_number > MAX_BOARD_NUMBER) {
fprintf (stderr, "[client:leds]: BOARD number too big! Defaulting to: %u\n",
MAX_BOARD_NUMBER);
board_number = MAX_BOARD_NUMBER;
}
}
/* Set default bpm number */
......@@ -212,9 +202,13 @@ int main (int argc, char *argv [])
}
char service[50];
sprintf (service, "BPM%u:DEVIO:FMC130M_4CH%u", board_number, bpm_number);
snprintf (service, sizeof (service), "BPM%u:DEVIO:FMC130M_4CH%u", board_number, bpm_number);
bpm_client_t *bpm_client = bpm_client_new (broker_endp, verbose, NULL);
if (bpm_client == NULL) {
fprintf (stderr, "[client:acq]: bpm_client could be created\n");
goto err_bpm_client_new;
}
for (i = 0; i < MAX_NUM_FUNCS; ++i) {
if (func_call [i].call == 1) {
......@@ -230,6 +224,7 @@ int main (int argc, char *argv [])
}
}
err_bpm_client_new:
bpm_client_destroy (&bpm_client);
/* ugly... */
......
/*
* Simple example demonstrating the communication between
* a client and the FPGA device
* Controlling the FMC ADC data
*/
#include <mdp.h>
#include <czmq.h>
#include <inttypes.h>
#include <bpm_client.h>
#define DFLT_BIND_FOLDER "/tmp/bpm"
#define DFLT_BPM_NUMBER 0
#define MAX_BPM_NUMBER 1
#define DFLT_BOARD_NUMBER 0
void print_help (char *program_name)
{
printf( "Usage: %s [options]\n"
"\t-h This help message\n"
"\t-v Verbose output\n"
"\t-b <broker_endpoint> Broker endpoint\n", program_name);
"\t-b <broker_endpoint> Broker endpoint\n"
"\t-board <AMC board = [0|1|2|3|4|5]>\n"
"\t-bpm <BPM number = [0|1]>\n", program_name);
}
int main (int argc, char *argv [])
{
int verbose = 0;
char *broker_endp = NULL;
char *board_number_str = NULL;
char *bpm_number_str = NULL;
char **str_p = NULL;
if (argc < 2) {
......@@ -58,11 +63,46 @@ int main (int argc, char *argv [])
broker_endp = strdup ("ipc://"DFLT_BIND_FOLDER);
}
/* Set default board number */
uint32_t board_number;
if (board_number_str == NULL) {
fprintf (stderr, "[client:acq]: Setting default value to BOARD number: %u\n",
DFLT_BOARD_NUMBER);
board_number = DFLT_BOARD_NUMBER;
}
else {
board_number = strtoul (board_number_str, NULL, 10);
}
/* Set default bpm number */
uint32_t bpm_number;
if (bpm_number_str == NULL) {
fprintf (stderr, "[client:leds]: Setting default value to BPM number: %u\n",
DFLT_BPM_NUMBER);
bpm_number = DFLT_BPM_NUMBER;
}
else {
bpm_number = strtoul (bpm_number_str, NULL, 10);
if (bpm_number > MAX_BPM_NUMBER) {
fprintf (stderr, "[client:leds]: BPM number too big! Defaulting to: %u\n",
MAX_BPM_NUMBER);
bpm_number = MAX_BPM_NUMBER;
}
}
char service [50];
snprintf (service, sizeof (service), "BPM%u:DEVIO:FMC130M_4CH%u",
board_number, bpm_number);
bpm_client_t *bpm_client = bpm_client_new (broker_endp, verbose, NULL);
if (bpm_client == NULL) {
fprintf (stderr, "[client:acq]: bpm_client could be created\n");
goto err_bpm_client_new;
}
uint32_t adc_data;
bpm_client_err_e err = bpm_get_adc_data0 (bpm_client, "BPM0:DEVIO:FMC130M_4CH0",
&adc_data);
bpm_client_err_e err = bpm_get_adc_data0 (bpm_client, service, &adc_data);
if (err != BPM_CLIENT_SUCCESS){
fprintf (stderr, "[client:acq]: bpm_get_adc_data0 failed\n");
goto err_get_adc_data;
......@@ -70,8 +110,7 @@ int main (int argc, char *argv [])
fprintf (stdout, "[client:adc_data]: data0 = %d\n", (int16_t) adc_data);
err = bpm_get_adc_data1 (bpm_client, "BPM0:DEVIO:FMC130M_4CH0",
&adc_data);
err = bpm_get_adc_data1 (bpm_client, service, &adc_data);
if (err != BPM_CLIENT_SUCCESS){
fprintf (stderr, "[client:acq]: bpm_get_adc_data1 failed\n");
goto err_get_adc_data;
......@@ -79,8 +118,7 @@ int main (int argc, char *argv [])
fprintf (stdout, "[client:adc_data]: data1 = %d\n", (int16_t) adc_data);
err = bpm_get_adc_data2 (bpm_client, "BPM0:DEVIO:FMC130M_4CH0",
&adc_data);
err = bpm_get_adc_data2 (bpm_client, service, &adc_data);
if (err != BPM_CLIENT_SUCCESS){
fprintf (stderr, "[client:acq]: bpm_get_adc_data2 failed\n");
goto err_get_adc_data;
......@@ -88,8 +126,7 @@ int main (int argc, char *argv [])
fprintf (stdout, "[client:adc_data]: data2 = %d\n", (int16_t) adc_data);
err = bpm_get_adc_data3 (bpm_client, "BPM0:DEVIO:FMC130M_4CH0",
&adc_data);
err = bpm_get_adc_data3 (bpm_client, service, &adc_data);
if (err != BPM_CLIENT_SUCCESS){
fprintf (stderr, "[client:acq]: bpm_get_adc_data3 failed\n");
goto err_get_adc_data;
......@@ -97,10 +134,17 @@ int main (int argc, char *argv [])
fprintf (stdout, "[client:adc_data]: data3 = %d\n", (int16_t) adc_data);
err_bpm_client_new:
err_get_adc_data:
bpm_client_destroy (&bpm_client);
str_p = &broker_endp;
free (*str_p);
broker_endp = NULL;
str_p = &board_number_str;
free (*str_p);
board_number_str = NULL;
str_p = &bpm_number_str;
free (*str_p);
bpm_number_str = NULL;
return 0;
}
/*
* * Simple example demonstrating the communication between
* * a client and the FPGA device
* */
* Controlling the ADC delays
*/
#include <mdp.h>
#include <czmq.h>
#include <inttypes.h>
#include <stdio.h>
#include <string.h>
......@@ -18,7 +15,6 @@
#define MAX_BPM_NUMBER 1
#define DFLT_BOARD_NUMBER 0
#define MAX_BOARD_NUMBER 5
#define DFLT_ADC_DLY_VALUE 10
#define MAX_ADC_DLY_VALUE 31
......@@ -113,12 +109,6 @@ int main (int argc, char *argv [])
}
else {
board_number = strtoul (board_number_str, NULL, 10);
if (board_number > MAX_BOARD_NUMBER) {
fprintf (stderr, "[client:leds]: BOARD number too big! Defaulting to: %u\n",
MAX_BOARD_NUMBER);
board_number = MAX_BOARD_NUMBER;
}
}
/* Set default bpm number */
......@@ -193,9 +183,13 @@ int main (int argc, char *argv [])
fprintf (stdout, "[client:adc_dly]: ADC delay value = %u\n", dly_val);
char service[50];
sprintf (service, "BPM%u:DEVIO:FMC130M_4CH%u", board_number, bpm_number);
snprintf (service, sizeof (service), "BPM%u:DEVIO:FMC130M_4CH%u", board_number, bpm_number);
bpm_client_t *bpm_client = bpm_client_new (broker_endp, verbose, NULL);
if (bpm_client == NULL) {
fprintf (stderr, "[client:acq]: bpm_client could be created\n");
goto err_bpm_client_new;
}
/* Call the appropriate delay function. FIXME: the case construct is
* not generic nor expansible */
......@@ -217,6 +211,7 @@ int main (int argc, char *argv [])
break;
}
err_bpm_client_new:
bpm_client_destroy (&bpm_client);
str_p = &board_number_str;
......
This diff is collapsed.
/*
* Controlling the FMC 130 MSPS board
*/
#include <inttypes.h>
#include <stdio.h>
#include <string.h>
#include <bpm_client.h>
#define DFLT_BIND_FOLDER "/tmp/bpm"
#define DFLT_BPM_NUMBER 0
#define MAX_BPM_NUMBER 1
#define DFLT_BOARD_NUMBER 0
void print_help (char *program_name)
{
printf( "Usage: %s [options]\n"
"\t-h This help message\n"
"\t-v Verbose output\n"
"\t-board <AMC board = [0|1|2|3|4|5]>\n"
"\t-bpm <BPM number = [0|1]>\n"
"\t-b <broker_endpoint> Broker endpoint\n"
"\t-pll_status PLL Lock status\n"
"\t-trig_dir <dir> Trigger direction\n"
"\t-trig_term <term> Trigger termination\n"
"\t-adc_rand <Rand enable = [0|1]> Enable ADC Rand\n"
"\t-adc_dith <Dith enable = [0|1]> Enable ADC Dith\n"
"\t-adc_shdn <SHDN enable = [0|1]> Enable ADC SHDN\n"
"\t-adc_rand <PGA enable = [0|1]> Enable ADC PGA\n"
, program_name);
}
int main (int argc, char *argv [])
{
int verbose = 0;
char *broker_endp = NULL;
char *board_number_str = NULL;
char *bpm_number_str = NULL;
char *trig_dir_str = NULL;
char *trig_term_str = NULL;
char *adc_rand_str = NULL;
char *adc_dith_str = NULL;
char *adc_shdn_str = NULL;
char *adc_pga_str = NULL;
uint32_t get_pll_status = 0;
char **str_p = NULL;
if (argc < 3) {
print_help (argv[0]);
exit (1);
}
/* FIXME: This is rather buggy! */
/* Simple handling of command-line options. This should be done
* * with getopt, for instance*/
int i;
for (i = 1; i < argc; i++)
{
if (streq(argv[i], "-v")) {
verbose = 1;
}
else if (streq(argv[i], "-h"))
{
print_help (argv [0]);
exit (1);
}
else if (streq(argv[i], "-board"))
{
str_p = &board_number_str;
}
else if (streq(argv[i], "-bpm"))
{
str_p = &bpm_number_str;
}
else if (streq (argv[i], "-b")) {
str_p = &broker_endp;
}
else if (streq(argv[i], "-pll_status"))
{
get_pll_status = 1;
}
else if (streq (argv[i], "-trig_dir")) {
str_p = &trig_dir_str;
}
else if (streq (argv[i], "-trig_term")) {
str_p = &trig_term_str;
}
else if (streq (argv[i], "-adc_rand")) {
str_p = &adc_rand_str;
}
else if (streq (argv[i], "-adc_dith")) {
str_p = &adc_dith_str;
}
else if (streq (argv[i], "-adc_shdn")) {
str_p = &adc_shdn_str;
}
else if (streq (argv[i], "-adc_pga")) {
str_p = &adc_pga_str;
}
/* Fallout for options with parameters */
else {
*str_p = strdup (argv[i]);
}
}
/* Set default broker address */
if (broker_endp == NULL) {
broker_endp = strdup ("ipc://"DFLT_BIND_FOLDER);
}
/* Set default board number */
uint32_t board_number;
if (board_number_str == NULL) {
fprintf (stderr, "[client:fmc130m_4ch]: Setting default value to BOARD number: %u\n",
DFLT_BOARD_NUMBER);
board_number = DFLT_BOARD_NUMBER;
}
else {
board_number = strtoul (board_number_str, NULL, 10);
}
/* Set default bpm number */
uint32_t bpm_number;
if (bpm_number_str == NULL) {
fprintf (stderr, "[client:fmc130m_4ch]: Setting default value to BPM number: %u\n",
DFLT_BPM_NUMBER);
bpm_number = DFLT_BPM_NUMBER;
}
else {
bpm_number = strtoul (bpm_number_str, NULL, 10);
if (bpm_number > MAX_BPM_NUMBER) {
fprintf (stderr, "[client:fmc130m_4ch]: BPM number too big! Defaulting to: %u\n",
MAX_BPM_NUMBER);
bpm_number = MAX_BPM_NUMBER;
}
}
/* Generate the service names for each SMIO */
char service[50];
snprintf (service, sizeof (service), "BPM%u:DEVIO:FMC130M_4CH%u", board_number, bpm_number);
bpm_client_t *bpm_client = bpm_client_new (broker_endp, verbose, NULL);
bpm_client_err_e err = BPM_CLIENT_SUCCESS;
uint32_t trig_dir = 0;
if (trig_dir_str != NULL) {
trig_dir = strtoul (trig_dir_str, NULL, 10);
fprintf (stdout, "[client:fmc130m_4ch]: trig_dir = %u\n", trig_dir);
err = bpm_set_trig_dir (bpm_client, service, trig_dir);
if (err != BPM_CLIENT_SUCCESS){
fprintf (stderr, "[client:fmc130m_4ch]: bpm_set_trig_dir failed\n");
goto err_bpm_exit;
}
fprintf (stdout, "[client:fmc130m_4ch]: bpm_set_trig_dir was successfully executed\n");
}
uint32_t trig_term = 0;
if (trig_term_str != NULL) {
trig_term = strtoul (trig_term_str, NULL, 10);
fprintf (stdout, "[client:fmc130m_4ch]: trig_term = %u\n", trig_term);
err = bpm_set_trig_term (bpm_client, service, trig_term);
if (err != BPM_CLIENT_SUCCESS){
fprintf (stderr, "[client:fmc130m_4ch]: bpm_set_trig_term failed\n");
goto err_bpm_exit;
}
fprintf (stdout, "[client:fmc130m_4ch]: bpm_set_trig_term was successfully executed\n");
}
uint32_t adc_rand = 0;
if (adc_rand_str != NULL) {
adc_rand = strtoul (adc_rand_str, NULL, 10);
fprintf (stdout, "[client:fmc130m_4ch]: adc_rand = %u\n", adc_rand);
err = bpm_set_adc_rand (bpm_client, service, adc_rand);
if (err != BPM_CLIENT_SUCCESS){
fprintf (stderr, "[client:fmc130m_4ch]: bpm_set_adc_rand failed\n");
goto err_bpm_exit;
}
fprintf (stdout, "[client:fmc130m_4ch]: bpm_set_adc_rand was successfully executed\n");
}
uint32_t adc_dith = 0;
if (adc_dith_str != NULL) {
adc_dith = strtoul (adc_dith_str, NULL, 10);
fprintf (stdout, "[client:fmc130m_4ch]: adc_dith = %u\n", adc_dith);
err = bpm_set_adc_dith (bpm_client, service, adc_dith);
if (err != BPM_CLIENT_SUCCESS){
fprintf (stderr, "[client:fmc130m_4ch]: bpm_set_adc_dith failed\n");
goto err_bpm_exit;
}
fprintf (stdout, "[client:fmc130m_4ch]: bpm_set_adc_dith was successfully executed\n");
}
uint32_t adc_shdn = 0;
if (adc_shdn_str != NULL) {
adc_shdn = strtoul (adc_shdn_str, NULL, 10);
fprintf (stdout, "[client:fmc130m_4ch]: adc_shdn = %u\n", adc_shdn);
err = bpm_set_adc_shdn (bpm_client, service, adc_shdn);
if (err != BPM_CLIENT_SUCCESS){
fprintf (stderr, "[client:fmc130m_4ch]: bpm_set_adc_shdn failed\n");
goto err_bpm_exit;
}
fprintf (stdout, "[client:fmc130m_4ch]: bpm_set_adc_shdn was successfully executed\n");
}
uint32_t adc_pga = 0;
if (adc_pga_str != NULL) {
adc_pga = strtoul (adc_pga_str, NULL, 10);
fprintf (stdout, "[client:fmc130m_4ch]: adc_pga = %u\n", adc_pga);
err = bpm_set_adc_pga (bpm_client, service, adc_pga);
if (err != BPM_CLIENT_SUCCESS){
fprintf (stderr, "[client:fmc130m_4ch]: bpm_set_adc_pga failed\n");
goto err_bpm_exit;
}
fprintf (stdout, "[client:fmc130m_4ch]: bpm_set_adc_pga was successfully executed\n");
}
if (get_pll_status) {
uint32_t pll_status = 0;
bpm_client_err_e err = bpm_get_fmc_pll_status (bpm_client, service, &pll_status);
if (err != BPM_CLIENT_SUCCESS){
fprintf (stderr, "[client:fmc130m_4ch]: bpm_get_fmc_pll_status failed\n");
goto err_bpm_exit;
}
fprintf (stdout, "[client:fmc130m_4ch]: bpm_get_fmc_pll_status: 0x%08X\n",
pll_status);
}
err_bpm_exit:
bpm_client_destroy (&bpm_client);
str_p = &adc_rand_str;
free (*str_p);
adc_rand_str = NULL;
str_p = &adc_dith_str;
free (*str_p);
adc_dith_str = NULL;
str_p = &adc_shdn_str;
free (*str_p);
adc_shdn_str = NULL;
str_p = &adc_pga_str;
free (*str_p);
adc_pga_str = NULL;
str_p = &trig_term_str;
free (*str_p);
trig_term_str = NULL;
str_p = &trig_dir_str;
free (*str_p);
trig_dir_str = NULL;
str_p = &broker_endp;
free (*str_p);
broker_endp = NULL;
str_p = &board_number_str;
free (*str_p);
board_number_str = NULL;
str_p = &bpm_number_str;
free (*str_p);
bpm_number_str = NULL;
return 0;
}
/*
* * Simple example demonstrating the communication between
* * a client and the FPGA device
* */
#include <czmq.h>
#include <inttypes.h>
#include <stdio.h>
#include <string.h>
#include <bpm_client.h>
#define DFLT_BIND_FOLDER "/tmp/bpm"
#define DFLT_BPM_NUMBER 0
#define MAX_BPM_NUMBER 1
#define DFLT_BOARD_NUMBER 0
void print_help (char *program_name)
{
printf( "Usage: %s [options]\n"
"\t-h This help message\n"
"\t-v Verbose output\n"
"\t-board <AMC board = [0|1|2|3|4|5]>\n"
"\t-bpm <BPM number = [0|1]>\n"
"\t-b <broker_endpoint> Broker endpoint\n"
, program_name);
}
int main (int argc, char *argv [])
{
int verbose = 0;
char *broker_endp = NULL;
char *board_number_str = NULL;
char *bpm_number_str = NULL;
char **str_p = NULL;
if (argc < 3) {
print_help (argv[0]);
exit (1);
}
/* FIXME: This is rather buggy! */
/* Simple handling of command-line options. This should be done
* * with getopt, for instance*/
int i;
for (i = 1; i < argc; i++)
{
if (streq(argv[i], "-v")) {
verbose = 1;
}
else if (streq(argv[i], "-h"))
{
print_help (argv [0]);
exit (1);
}
else if (streq(argv[i], "-board"))
{
str_p = &board_number_str;
}
else if (streq(argv[i], "-bpm"))
{
str_p = &bpm_number_str;
}
else if (streq (argv[i], "-b")) {
str_p = &broker_endp;
}
/* Fallout for options with parameters */
else {
*str_p = strdup (argv[i]);
}
}
/* Set default broker address */
if (broker_endp == NULL) {
broker_endp = strdup ("ipc://"DFLT_BIND_FOLDER);
}
/* Set default board number */
uint32_t board_number;
if (board_number_str == NULL) {
fprintf (stderr, "[client:afc_diag]: Setting default value to BOARD number: %u\n",
DFLT_BOARD_NUMBER);
board_number = DFLT_BOARD_NUMBER;
}
else {
board_number = strtoul (board_number_str, NULL, 10);
}
/* Set default bpm number */
uint32_t bpm_number;
if (bpm_number_str == NULL) {
fprintf (stderr, "[client:afc_diag]: Setting default value to BPM number: %u\n",
DFLT_BPM_NUMBER);
bpm_number = DFLT_BPM_NUMBER;
}
else {
bpm_number = strtoul (bpm_number_str, NULL, 10);
if (bpm_number > MAX_BPM_NUMBER) {
fprintf (stderr, "[client:afc_diag]: BPM number too big! Defaulting to: %u\n",
MAX_BPM_NUMBER);
bpm_number = MAX_BPM_NUMBER;
}
}
/* Generate the service names for each SMIO */
char service_afc_diag[50];
snprintf (service_afc_diag, sizeof (service_afc_diag), "BPM%u:DEVIO:AFC_DIAG0",
board_number);
bpm_client_t *bpm_client = bpm_client_new (broker_endp, verbose, NULL);
if (bpm_client == NULL) {
fprintf (stderr, "[client:acq]: bpm_client could be created\n");
goto err_bpm_client_new;
}
uint32_t data;
bpm_client_err_e err = bpm_get_afc_diag_card_slot (bpm_client, service_afc_diag, &data);
if (err != BPM_CLIENT_SUCCESS){
fprintf (stderr, "[client:afc_diag]: bpm_get_afc_diag_card_slot failed\n");
goto err_bpm_get;
}
fprintf (stdout, "[client:afc_diag]: Card slot: 0x%08X\n", data);
err = bpm_get_afc_diag_ipmi_addr (bpm_client, service_afc_diag, &data);
if (err != BPM_CLIENT_SUCCESS){
fprintf (stderr, "[client:afc_diag]: bpm_get_afc_diag_ipmi_addr failed\n");
goto err_bpm_get;
}
fprintf (stdout, "[client:afc_diag]: IPMI addr: 0x%08X\n", data);
smio_afc_diag_revision_data_t rev_data;
err = bpm_get_afc_diag_build_date (bpm_client, service_afc_diag, &rev_data);
if (err != BPM_CLIENT_SUCCESS){
fprintf (stderr, "[client:afc_diag]: bpm_get_afc_diag_build_user_date failed\n");
goto err_bpm_get;
}
fprintf (stdout, "[client:afc_diag]: Build date: %s\n", (char *) rev_data.data);
err = bpm_get_afc_diag_build_user_name (bpm_client, service_afc_diag, &rev_data);
if (err != BPM_CLIENT_SUCCESS){
fprintf (stderr, "[client:afc_diag]: bpm_get_afc_diag_build_user_name failed\n");
goto err_bpm_get;
}
fprintf (stdout, "[client:afc_diag]: Build user name: %s\n", (char *) rev_data.data);
err = bpm_get_afc_diag_build_user_email (bpm_client, service_afc_diag, &rev_data);
if (err != BPM_CLIENT_SUCCESS){
fprintf (stderr, "[client:afc_diag]: bpm_get_afc_diag_build_user_email failed\n");
goto err_bpm_get;
}
fprintf (stdout, "[client:afc_diag]: Build user email: %s\n", (char *) rev_data.data);
err_bpm_client_new:
err_bpm_get:
bpm_client_destroy (&bpm_client);
str_p = &broker_endp;
free (*str_p);
broker_endp = NULL;
str_p = &board_number_str;
free (*str_p);
board_number_str = NULL;
str_p = &bpm_number_str;
free (*str_p);
bpm_number_str = NULL;
return 0;
}
/*
* Simple example demonstrating the communication between
* a client and the FPGA device
* Controlling the FMC 130 MSPS leds
*/
#include <mdp.h>
#include <czmq.h>
#include <inttypes.h>
#include <bpm_client.h>
#define DFLT_BIND_FOLDER "/tmp/bpm"
......@@ -15,7 +11,6 @@
#define MAX_BPM_NUMBER 1
#define DFLT_BOARD_NUMBER 0
#define MAX_BOARD_NUMBER 5
void print_help (char *program_name)
{
......@@ -85,12 +80,6 @@ int main (int argc, char *argv [])
}
else {
board_number = strtoul (board_number_str, NULL, 10);
if (board_number > MAX_BOARD_NUMBER) {
fprintf (stderr, "[client:leds]: BOARD number too big! Defaulting to: %u\n",
MAX_BOARD_NUMBER);
board_number = MAX_BOARD_NUMBER;
}
}
/* Set default bpm number */
......@@ -111,9 +100,13 @@ int main (int argc, char *argv [])
}
char service[50];
sprintf (service, "BPM%u:DEVIO:FMC130M_4CH%u", board_number, bpm_number);
snprintf (service, sizeof (service), "BPM%u:DEVIO:FMC130M_4CH%u", board_number, bpm_number);
bpm_client_t *bpm_client = bpm_client_new (broker_endp, verbose, NULL);
if (bpm_client == NULL) {
fprintf (stderr, "[client:acq]: bpm_client could be created\n");
goto err_bpm_client_new;
}
for (i = 0; i < 32768; ++i) {
uint32_t leds = (1 << 1);
......@@ -129,6 +122,7 @@ int main (int argc, char *argv [])
}
}
err_bpm_client_new:
bpm_client_destroy (&bpm_client);
str_p = &broker_endp;
......
/*
* Simple example demonstrating the communication between
* a client and the FPGA device
* Controlling the Monitoring data
*/
#include <mdp.h>
#include <czmq.h>
#include <inttypes.h>
#include <bpm_client.h>
#define DFLT_BIND_FOLDER "/tmp/bpm"
#define DFLT_BPM_NUMBER 0
#define MAX_BPM_NUMBER 1
#define DFLT_BOARD_NUMBER 0
void print_help (char *program_name)
{
printf( "Usage: %s [options]\n"
"\t-h This help message\n"
"\t-v Verbose output\n"
"\t-b <broker_endpoint> Broker endpoint\n", program_name);
"\t-b <broker_endpoint> Broker endpoint\n"
"\t-board <AMC board = [0|1|2|3|4|5]>\n"
"\t-bpm <BPM number = [0|1]>\n"
, program_name);
}
int main (int argc, char *argv [])
{
int verbose = 0;
char *broker_endp = NULL;
char *board_number_str = NULL;
char *bpm_number_str = NULL;
char **str_p = NULL;
if (argc < 2) {
......@@ -47,6 +53,13 @@ int main (int argc, char *argv [])
else if (streq (argv[i], "-b")) {
str_p = &broker_endp;
}
else if (streq (argv[i], "-board")) { /* board_number: board number */
str_p = &board_number_str;
}
else if (streq(argv[i], "-bpm"))
{
str_p = &bpm_number_str;
}
/* Fallout for options with parameters */
else {
*str_p = strdup (argv[i]);
......@@ -58,10 +71,45 @@ int main (int argc, char *argv [])
broker_endp = strdup ("ipc://"DFLT_BIND_FOLDER);
}
/* Set default board number */
uint32_t board_number;
if (board_number_str == NULL) {
fprintf (stderr, "[client:acq]: Setting default value to BOARD number: %u\n",
DFLT_BOARD_NUMBER);
board_number = DFLT_BOARD_NUMBER;
}
else {
board_number = strtoul (board_number_str, NULL, 10);
}
/* Set default bpm number */
uint32_t bpm_number;
if (bpm_number_str == NULL) {
fprintf (stderr, "[client:leds]: Setting default value to BPM number: %u\n",
DFLT_BPM_NUMBER);
bpm_number = DFLT_BPM_NUMBER;
}
else {
bpm_number = strtoul (bpm_number_str, NULL, 10);
if (bpm_number > MAX_BPM_NUMBER) {
fprintf (stderr, "[client:leds]: BPM number too big! Defaulting to: %u\n",
MAX_BPM_NUMBER);
bpm_number = MAX_BPM_NUMBER;
}
}
char service[50];
snprintf (service, sizeof (service), "BPM%u:DEVIO:DSP%u", board_number, bpm_number);
bpm_client_t *bpm_client = bpm_client_new (broker_endp, verbose, NULL);
if (bpm_client == NULL) {
fprintf (stderr, "[client:acq]: bpm_client could be created\n");
goto err_bpm_client_new;
}
uint32_t monit_amp;
bpm_client_err_e err = bpm_get_monit_amp_ch0 (bpm_client, "BPM0:DEVIO:DSP0",
bpm_client_err_e err = bpm_get_monit_amp_ch0 (bpm_client, service,
&monit_amp);
if (err != BPM_CLIENT_SUCCESS){
fprintf (stderr, "[client:acq]: bpm_get_monit_amp_ch0 failed\n");
......@@ -70,8 +118,7 @@ int main (int argc, char *argv [])
fprintf (stdout, "[client:monit_amp]: monitoring amplitude ch0 = %u\n", monit_amp);
err = bpm_get_monit_amp_ch1 (bpm_client, "BPM0:DEVIO:DSP0",
&monit_amp);
err = bpm_get_monit_amp_ch1 (bpm_client, service, &monit_amp);
if (err != BPM_CLIENT_SUCCESS){
fprintf (stderr, "[client:acq]: bpm_get_monit_amp_ch1 failed\n");
goto err_get_monit_amp;
......@@ -79,8 +126,7 @@ int main (int argc, char *argv [])
fprintf (stdout, "[client:monit_amp]: monitoring amplitude ch1 = %u\n", monit_amp);
err = bpm_get_monit_amp_ch2 (bpm_client, "BPM0:DEVIO:DSP0",
&monit_amp);
err = bpm_get_monit_amp_ch2 (bpm_client, service, &monit_amp);
if (err != BPM_CLIENT_SUCCESS){
fprintf (stderr, "[client:acq]: bpm_get_monit_amp_ch2 failed\n");
goto err_get_monit_amp;
......@@ -88,8 +134,7 @@ int main (int argc, char *argv [])
fprintf (stdout, "[client:monit_amp]: monitoring amplitude ch2 = %u\n", monit_amp);
err = bpm_get_monit_amp_ch3 (bpm_client, "BPM0:DEVIO:DSP0",
&monit_amp);
err = bpm_get_monit_amp_ch3 (bpm_client, service, &monit_amp);
if (err != BPM_CLIENT_SUCCESS){
fprintf (stderr, "[client:acq]: bpm_get_monit_amp_ch3 failed\n");
goto err_get_monit_amp;
......@@ -97,8 +142,15 @@ int main (int argc, char *argv [])
fprintf (stdout, "[client:monit_amp]: monitoring amplitude ch3 = %u\n", monit_amp);
err_bpm_client_new:
err_get_monit_amp:
bpm_client_destroy (&bpm_client);
str_p = &board_number_str;
free (*str_p);
board_number_str = NULL;
str_p = &bpm_number_str;
free (*str_p);
bpm_number_str = NULL;
str_p = &broker_endp;
free (*str_p);
broker_endp = NULL;
......
/*
* Simple example demonstrating the communication between
* a client and the FPGA device
* Controlling the Monitoring Position
*/
#include <mdp.h>
#include <czmq.h>
#include <inttypes.h>
#include <bpm_client.h>
#define DFLT_BIND_FOLDER "/tmp/bpm"
#define DFLT_BPM_NUMBER 0
#define MAX_BPM_NUMBER 1
#define DFLT_BOARD_NUMBER 0
void print_help (char *program_name)
{
printf( "Usage: %s [options]\n"
"\t-h This help message\n"
"\t-v Verbose output\n"
"\t-b <broker_endpoint> Broker endpoint\n", program_name);
"\t-b <broker_endpoint> Broker endpoint\n"
"\t-board <AMC board = [0|1|2|3|4|5]>\n"
"\t-bpm <BPM number = [0|1]>\n"
, program_name);
}
int main (int argc, char *argv [])
{
int verbose = 0;
char *broker_endp = NULL;
char *board_number_str = NULL;
char *bpm_number_str = NULL;
char **str_p = NULL;
if (argc < 2) {
......@@ -47,6 +53,13 @@ int main (int argc, char *argv [])
else if (streq (argv[i], "-b")) {
str_p = &broker_endp;
}
else if (streq (argv[i], "-board")) { /* board_number: board number */
str_p = &board_number_str;
}
else if (streq(argv[i], "-bpm"))
{
str_p = &bpm_number_str;
}
/* Fallout for options with parameters */
else {
*str_p = strdup (argv[i]);
......@@ -58,10 +71,45 @@ int main (int argc, char *argv [])
broker_endp = strdup ("ipc://"DFLT_BIND_FOLDER);
}
/* Set default board number */
uint32_t board_number;
if (board_number_str == NULL) {
fprintf (stderr, "[client:acq]: Setting default value to BOARD number: %u\n",
DFLT_BOARD_NUMBER);
board_number = DFLT_BOARD_NUMBER;
}
else {
board_number = strtoul (board_number_str, NULL, 10);
}
/* Set default bpm number */
uint32_t bpm_number;
if (bpm_number_str == NULL) {
fprintf (stderr, "[client:leds]: Setting default value to BPM number: %u\n",
DFLT_BPM_NUMBER);
bpm_number = DFLT_BPM_NUMBER;
}
else {
bpm_number = strtoul (bpm_number_str, NULL, 10);
if (bpm_number > MAX_BPM_NUMBER) {
fprintf (stderr, "[client:leds]: BPM number too big! Defaulting to: %u\n",
MAX_BPM_NUMBER);
bpm_number = MAX_BPM_NUMBER;
}
}
char service[50];
snprintf (service, sizeof (service), "BPM%u:DEVIO:DSP%u", board_number, bpm_number);
bpm_client_t *bpm_client = bpm_client_new (broker_endp, verbose, NULL);
if (bpm_client == NULL) {
fprintf (stderr, "[client:acq]: bpm_client could be created\n");
goto err_bpm_client_new;
}
uint32_t monit_pos;
bpm_client_err_e err = bpm_get_monit_pos_x (bpm_client, "BPM0:DEVIO:DSP0",
bpm_client_err_e err = bpm_get_monit_pos_x (bpm_client, service,
&monit_pos);
if (err != BPM_CLIENT_SUCCESS){
fprintf (stderr, "[client:acq]: bpm_get_monit_pos_x failed\n");
......@@ -70,8 +118,7 @@ int main (int argc, char *argv [])
fprintf (stdout, "[client:monit_pos]: monitoring pos x = %d\n", (int32_t) monit_pos);
err = bpm_get_monit_pos_y (bpm_client, "BPM0:DEVIO:DSP0",
&monit_pos);
err = bpm_get_monit_pos_y (bpm_client, service, &monit_pos);
if (err != BPM_CLIENT_SUCCESS){
fprintf (stderr, "[client:acq]: bpm_get_monit_pos_y failed\n");
goto err_get_monit_pos;
......@@ -79,8 +126,7 @@ int main (int argc, char *argv [])
fprintf (stdout, "[client:monit_pos]: monitoring pos y = %d\n", (int32_t) monit_pos);
err = bpm_get_monit_pos_q (bpm_client, "BPM0:DEVIO:DSP0",
&monit_pos);
err = bpm_get_monit_pos_q (bpm_client, service, &monit_pos);
if (err != BPM_CLIENT_SUCCESS){
fprintf (stderr, "[client:acq]: bpm_get_monit_pos_q failed\n");
goto err_get_monit_pos;
......@@ -88,8 +134,7 @@ int main (int argc, char *argv [])
fprintf (stdout, "[client:monit_pos]: monitoring pos q = %d\n", (int32_t) monit_pos);
err = bpm_get_monit_pos_sum (bpm_client, "BPM0:DEVIO:DSP0",
&monit_pos);
err = bpm_get_monit_pos_sum (bpm_client, service, &monit_pos);
if (err != BPM_CLIENT_SUCCESS){
fprintf (stderr, "[client:acq]: bpm_get_monit_pos_sum failed\n");
goto err_get_monit_pos;
......@@ -97,8 +142,15 @@ int main (int argc, char *argv [])
fprintf (stdout, "[client:monit_pos]: monitoring pos sum = %d\n", (int32_t) monit_pos);
err_bpm_client_new:
err_get_monit_pos:
bpm_client_destroy (&bpm_client);
str_p = &board_number_str;
free (*str_p);
board_number_str = NULL;
str_p = &bpm_number_str;
free (*str_p);
bpm_number_str = NULL;
str_p = &broker_endp;
free (*str_p);
broker_endp = NULL;
......
/*
* * Simple example demonstrating the communication between
* * a client and the FPGA device
* */
* Controlling the RFFE board
*/
#include <mdp.h>
#include <czmq.h>
#include <inttypes.h>
#include <stdio.h>
#include <string.h>
......@@ -18,7 +15,6 @@
#define MAX_BPM_NUMBER 1
#define DFLT_BOARD_NUMBER 0
#define MAX_BOARD_NUMBER 5
#define FUNC_RFFE_SW_IDX 0
#define FUNC_RFFE_ATT1_IDX 1
......@@ -198,12 +194,6 @@ int main (int argc, char *argv [])
}
else {
board_number = strtoul (board_number_str, NULL, 10);
if (board_number > MAX_BOARD_NUMBER) {
fprintf (stderr, "[client:rffe]: BOARD number too big! Defaulting to: %u\n",
MAX_BOARD_NUMBER);
board_number = MAX_BOARD_NUMBER;
}
}
/* Set default bpm number */
......@@ -224,9 +214,13 @@ int main (int argc, char *argv [])
}
char service[50];
sprintf (service, "BPM%u:DEVIO:RFFE%u", board_number, bpm_number);
snprintf (service, sizeof (service), "BPM%u:DEVIO:RFFE%u", board_number, bpm_number);
bpm_client_t *bpm_client = bpm_client_new (broker_endp, verbose, NULL);
if (bpm_client == NULL) {
fprintf (stderr, "[client:acq]: bpm_client could be created\n");
goto err_bpm_client_new;
}
for (i = 0; i < MAX_NUM_FUNCS; ++i) {
if (func_call [i].call == 1) {
......@@ -242,6 +236,7 @@ int main (int argc, char *argv [])
}
}
err_bpm_client_new:
bpm_client_destroy (&bpm_client);
/* ugly... */
......
/*
* Simple example demonstrating the communication between
* a client and the FPGA device
* Controlling the Si571 in FMC 130 MSPS chip
*/
#include <mdp.h>
#include <czmq.h>
#include <inttypes.h>
#include <bpm_client.h>
#define DFLT_BIND_FOLDER "/tmp/bpm"
......@@ -138,9 +134,13 @@ int main (int argc, char *argv [])
}
char service[50];
sprintf (service, "BPM%u:DEVIO:FMC130M_4CH%u", board_number, bpm_number);
snprintf (service, sizeof (service), "BPM%u:DEVIO:FMC130M_4CH%u", board_number, bpm_number);
bpm_client_t *bpm_client = bpm_client_new (broker_endp, verbose, NULL);
if (bpm_client == NULL) {
fprintf (stderr, "[client:acq]: bpm_client could be created\n");
goto err_bpm_client_new;
}
bpm_client_err_e err = bpm_set_si571_set_freq (bpm_client, service, si571_freq);
if (err != BPM_CLIENT_SUCCESS){
......@@ -148,6 +148,7 @@ int main (int argc, char *argv [])
goto err_bpm_set_freq;
}
err_bpm_client_new:
err_bpm_set_freq:
bpm_client_destroy (&bpm_client);
......
/*
* Simple example demonstrating the communication between
* a client and the FPGA device
* Controlling the FMC 130 MSPS test functions
*/
#include <mdp.h>
#include <czmq.h>
#include <inttypes.h>
#include <bpm_client.h>
#define DFLT_BIND_FOLDER "/tmp/bpm"
......@@ -18,7 +14,6 @@
#define MAX_BPM_NUMBER 1
#define DFLT_BOARD_NUMBER 0
#define MAX_BOARD_NUMBER 5
void print_help (char *program_name)
{
......@@ -93,12 +88,6 @@ int main (int argc, char *argv [])
}
else {
board_number = strtoul (board_number_str, NULL, 10);
if (board_number > MAX_BOARD_NUMBER) {
fprintf (stderr, "[client:leds]: BOARD number too big! Defaulting to: %u\n",
MAX_BOARD_NUMBER);
board_number = MAX_BOARD_NUMBER;
}
}
/* Set default bpm number */
......@@ -136,14 +125,19 @@ int main (int argc, char *argv [])
fprintf (stdout, "[client:test_data_en]: test_data_en = %u\n", test_data_en);
char service[50];
sprintf (service, "BPM%u:DEVIO:FMC130M_4CH%u", board_number, bpm_number);
snprintf (service, sizeof (service), "BPM%u:DEVIO:FMC130M_4CH%u", board_number, bpm_number);
bpm_client_t *bpm_client = bpm_client_new (broker_endp, verbose, NULL);
if (bpm_client == NULL) {
fprintf (stderr, "[client:acq]: bpm_client could be created\n");
goto err_bpm_client_new;
}
/* Test data enable */
bpm_set_adc_test_data_en (bpm_client, service, test_data_en);
/* Cleanup */
err_bpm_client_new:
bpm_client_destroy (&bpm_client);
str_p = &board_number_str;
......
Subproject commit 16a0b9a4cf387148b77d874938b9dfec09f4eaa5
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__ */
Subproject commit 041e31e89785f01e71d4c06a191bbe035de4a478
Subproject commit 1168603b61ab36fe788a8290ae1f98762718d536
boards_DIR = hal/boards
boards_INCLUDE_DIRS = $(boards_DIR)/$(BOARD)
debug_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 = 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)
/*
* Copyright (C) 2014 LNLS (www.lnls.br)
* Author: Lucas Russo <lucas.russo@lnls.br>
*
* Released according to the GNU LGPL, version 3 or any later version.
*/
#include <string.h>
#include "dev_mngr_dev_info.h"
#include "hal_assert.h"
#include "debug_print.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, DEV_MNGR, "dev_mngr_dev_info",\
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, DEV_MNGR, "dev_mngr_dev_info", \
dmngr_err_str(DMNGR_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, DEV_MNGR, "dev_mngr_dev_info", \
dmngr_err_str (err_type))
/* Creates a new instance of the Device Manager */
devio_info_t * devio_info_new (char *dev_pathname, uint32_t id, llio_type_e type,
devio_type_e devio_type, uint32_t smio_inst_id, devio_state_e state)
{
assert (dev_pathname);
devio_info_t *self = zmalloc (sizeof *self);
ASSERT_ALLOC (self, err_devio_info_alloc);
self->dev_pathname = strdup (dev_pathname);
ASSERT_ALLOC (self->dev_pathname, err_pathname_alloc);
self->id = id;
self->type = type;
self->devio_type = devio_type;
self->smio_inst_id = smio_inst_id;
self->state = state;
return self;
err_pathname_alloc:
free (self);
err_devio_info_alloc:
return NULL;
}
/* Destroy an instance of the Device Manager */
dmngr_err_e devio_info_destroy (devio_info_t **self_p)
{
assert (self_p);
if (*self_p) {
devio_info_t *self = *self_p;
free (self->dev_pathname);
free (self);
*self_p = NULL;
}
return DMNGR_SUCCESS;
}
# debug.mk must be declared before dev_mngr.mk, as they are variables
# exported by the former used by the latter
include hal/debug/debug.mk
include hal/ll_io/ll_io.mk
include hal/sm_io/sm_io.mk
include hal/sdb/sdb.mk
include hal/dev_mngr/dev_mngr.mk
include hal/dev_io/dev_io.mk
include hal/msg/msg.mk
include hal/hal_utils/hal_utils.mk
include hal/boards/boards.mk
std_hal_INCLUDE_DIRS = hal/include \
hal/include/hw \
hal/include/protocols \
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_mngr_LIBS =
dev_mngr_STATIC_LIBS =
dev_io_LIBS = -lbsmp
dev_io_STATIC_LIBS = $(LIBCLIENT_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))
/*
* Copyright (C) 2014 LNLS (www.lnls.br)
* Author: Lucas Russo <lucas.russo@lnls.br>
*
* Released according to the GNU LGPL, version 3 or any later version.
*/
#include <stdio.h>
#include "hal_utils.h"
#include "hal_utils_err.h"
#include "hal_assert.h"
#include "czmq.h"
/* Undef ASSERT_ALLOC to avoid conflicting with other ASSERT_ALLOC */
#ifdef ASSERT_TEST
#undef ASSERT_TEST
#endif
#define ASSERT_TEST(test_boolean, err_str, err_goto_label, /* err_core */ ...) \
ASSERT_HAL_TEST(test_boolean, HAL_UTILS, "[halultis]",\
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, HAL_UTILS, "[halutils]",\
halutils_err_str(HALUTILS_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, HAL_UTILS, "[halutils]", \
halutils_err_str (err_type))
static char *_halutils_concat_strings_raw (const char *str1, const char* str2,
const char *str3, char sep);
uint32_t num_to_str_len (uint32_t key, uint32_t base)
{
uint32_t i = 0;
uint32_t rem = key;
do {
rem /= base;
++i;
} while (rem > 0);
return i;
}
uint32_t hex_to_str_len (uint32_t key)
{
return num_to_str_len (key, 16);
}
uint32_t dec_to_str_len (uint32_t key)
{
return num_to_str_len (key, 10);
}
char *halutils_stringify_key (uint32_t key, uint32_t base)
{
uint32_t key_len = num_to_str_len (key, base) + 1; /* +1 for \0 */
char *key_c = zmalloc (key_len * sizeof (char));
ASSERT_ALLOC (key_c, err_key_c_alloc);
snprintf(key_c, key_len, "%x", key);
/* DBE_DEBUG (DBG_HAL_UTILS | DBG_LVL_TRACE,
"[halutils:stringify_key] key = %s, key_len = %u\n",
key_c, key_len); */
return key_c;
err_key_c_alloc:
return NULL;
}
char *halutils_stringify_dec_key (uint32_t key)
{
return halutils_stringify_key (key, 10);
}
char *halutils_stringify_hex_key (uint32_t key)
{
return halutils_stringify_key (key, 16);
}
#define SEPARATOR_BYTES 1
/* FIXME: poorly written */
static char *_halutils_concat_strings_raw (const char *str1, const char* str2,
const char *str3, char sep)
{
assert (str1);
assert (str2);
char *str = NULL;
if (str3 != NULL) {
str = zmalloc (strlen (str1) + strlen (str2) + strlen (str3) +
SEPARATOR_BYTES /* separator length */+ 1 /* \0 */);
ASSERT_ALLOC(str, err_str3_alloc);
sprintf (str, "%s%c%s%s", str1, sep, str2, str3);
}
else {
str = zmalloc (strlen(str1) + strlen(str2) +
SEPARATOR_BYTES /* separator length */+ 1 /* \0 */);
ASSERT_ALLOC(str, err_str2_alloc);
sprintf (str, "%s%c%s", str1, sep, str2);
}
return str;
err_str3_alloc:
err_str2_alloc:
return NULL;
}
char *halutils_concat_strings (const char *str1, const char* str2, char sep)
{
return _halutils_concat_strings_raw (str1, str2, NULL, sep);
}
char *halutils_concat_strings3 (const char *str1, const char* str2,
const char* str3, char sep)
{
return _halutils_concat_strings_raw (str1, str2, str3, sep);
}
/*
* Copyright (C) 2014 LNLS (www.lnls.br)
* Author: Lucas Russo <lucas.russo@lnls.br>
*
* Released according to the GNU LGPL, version 3 or any later version.
*/
#ifndef _HAL_UTILS_H_
#define _HAL_UTILS_H_
#include <inttypes.h>
/* Returns the necessary string length including the termianting null character
* for a number in a arbitrary base */
uint32_t num_to_str_len (uint32_t key, uint32_t base);
/* Returns the necessary string length including the termianting null character
* for a hexadecimal number */
uint32_t hex_to_str_len (uint32_t key);
/* Returns the necessary string length including the termianting null character
* for a decimal number */
uint32_t dec_to_str_len (uint32_t key);
/* Allocates a string with the necessary size to fit a number in an arbitrary base */
char *halutils_stringify_key (uint32_t key, uint32_t base);
/* Allocates a string with the necessary size to fit a decimal key */
char *halutils_stringify_dec_key (uint32_t key);
/* Allocates a string with the necessary size to fit an hexadecimal key */
char *halutils_stringify_hex_key (uint32_t key);
/* Concatenates 2 strings togheter with a separator. returns the string if
* OK, NULL in case of error */
char *halutils_concat_strings (const char *str1, const char* str2, char sep);
/* Concatenates 3 strings togheter with a separator between the first and second
* strings. returns the string if OK, NULL in case of error */
char *halutils_concat_strings3 (const char *str1, const char* str2,
const char* str3, char sep);
#endif
hal_utils_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.
*/
#ifndef _LL_IO_ETH_H_
#define _LL_IO_ETH_H_
#include "ll_io.h"
#define LLIO_ETH_HANDLER(self) ((llio_dev_eth_t *) self->dev_handler)
enum _llio_eth_type_e {
TCP_ETH_SOCK = 0,
UDP_ETH_SOCK = 1,
INVALID_ETH_SOCK
};
#define TCP_ETH_SOCK_STR "tcp"
#define UDP_ETH_SOCK_STR "udp"
#define INVALID_ETH_SOCK_STR "invalid"
typedef enum _llio_eth_type_e llio_eth_type_e;
/* For use by llio_t general structure */
extern const llio_ops_t llio_ops_eth;
/* Device endpoint */
struct _llio_dev_eth_t {
llio_eth_type_e type;
int fd;
char *hostname;
char *port;
};
/* Opaque llio_dev_eth structure */
typedef struct _llio_dev_eth_t llio_dev_eth_t;
/***************** Our methods *****************/
/* Creates a new instance of the Ethernet endpoint*/
llio_dev_eth_t * llio_dev_eth_new (const char *sock_type, const char *hostname,
const char *port);
/* Destroy an instance of the Ethernet Endpoint */
llio_err_e llio_dev_eth_destroy (llio_dev_eth_t **self_p);
#endif
include hal/msg/exp_ops/ops.mk
include hal/msg/smio_thsafe_ops/ops.mk
msg_DIR = hal/msg
msg_OBJS = $(msg_DIR)/msg.o \
$(msg_DIR)/msg_err.o \
$(exp_ops_OBJS) \
$(smio_thsafe_ops_OBJS)
msg_INCLUDE_DIRS = $(msg_DIR) \
$(exp_ops_INCLUDE_DIRS) \
$(smio_thsafe_ops_INCLUDE_DIRS)
# FIXME: For use in hal.mk with dev_mngr_OBJS
thsafe_msg_zmq_OBJS = $(smio_thsafe_ops_DIR)/thsafe_msg_zmq.o \
$(msg_DIR)/msg_err.o
/*
* Copyright (C) 2014 LNLS (www.lnls.br)
* Author: Lucas Russo <lucas.russo@lnls.br>
*
* Released according to the GNU LGPL, version 3 or any later version.
*
* This was taken from wrpc-sw reposytory at
* http://www.ohwr.org/projects/wrpc-sw/repository
*/
#ifndef _SDB_H_
#define _SDB_H_
#include <inttypes.h>
#define SDB_INTERCONNET 0x00
#define SDB_DEVICE 0x01
#define SDB_BRIDGE 0x02
#define SDB_EMPTY 0xFF
typedef struct pair64 {
uint32_t high;
uint32_t low;
} pair64_t;
struct sdb_empty {
int8_t reserved[63];
uint8_t record_type;
};
struct sdb_product {
pair64_t vendor_id;
uint32_t device_id;
uint32_t version;
uint32_t date;
int8_t name[19];
uint8_t record_type;
};
struct sdb_component {
pair64_t addr_first;
pair64_t addr_last;
struct sdb_product product;
};
struct sdb_device {
uint16_t abi_class;
uint8_t abi_ver_major;
uint8_t abi_ver_minor;
uint32_t bus_specific;
struct sdb_component sdb_component;
};
struct sdb_bridge {
pair64_t sdb_child;
struct sdb_component sdb_component;
};
struct sdb_interconnect {
uint32_t sdb_magic;
uint16_t sdb_records;
uint8_t sdb_version;
uint8_t sdb_bus_type;
struct sdb_component sdb_component;
};
typedef union sdb_record {
struct sdb_empty empty;
struct sdb_device device;
struct sdb_bridge bridge;
struct sdb_interconnect interconnect;
} sdb_record_t;
#endif
sdb_DIR = hal/sdb
# Here we call <output_name>_core_OBJS as we need to add
# more objects to this target. This is done in the hal.mk
# makefile
#sdb_core_OBJS = $(sdb_DIR)/sdb.o
sdb_INCLUDE_DIRS = $(sdb_DIR)
sdb_OUT = sdb
/*
* Copyright (C) 2014 LNLS (www.lnls.br)
* Author: Lucas Russo <lucas.russo@lnls.br>
*
* Released according to the GNU LGPL, version 3 or any later version.
*/
#include "sm_io_mod_dispatch.h"
/* Include all available module we can handle */
#include "sm_io_fmc130m_4ch_exp.h"
#include "sm_io_acq_exp.h"
#include "sm_io_dsp_exp.h"
#include "sm_io_swap_exp.h"
#include "sm_io_rffe_exp.h"
/* Table of all known modules we can handle */
const smio_mod_dispatch_t smio_mod_dispatch[MOD_DISPATCH_END] = {
[0] = { .id = FMC130M_4CH_SDB_DEVID,
.name = FMC130M_4CH_SDB_NAME,
.bootstrap_ops = &fmc130m_4ch_bootstrap_ops
},
[1] = { .id = ACQ_SDB_DEVID,
.name = ACQ_SDB_NAME,
.bootstrap_ops = &acq_bootstrap_ops
},
[2] = { .id = DSP_SDB_DEVID,
.name = DSP_SDB_NAME,
.bootstrap_ops = &dsp_bootstrap_ops
},
[3] = { .id = SWAP_SDB_DEVID,
.name = SWAP_SDB_NAME,
.bootstrap_ops = &swap_bootstrap_ops
},
[4] = { .id = RFFE_DEVID, /* No SDB as this is not an FPGA module */
.name = RFFE_NAME,
.bootstrap_ops = &rffe_bootstrap_ops
}
};
/*
* Copyright (C) 2014 LNLS (www.lnls.br)
* Author: Lucas Russo <lucas.russo@lnls.br>
*
* Released according to the GNU LGPL, version 3 or any later version.
*/
#ifndef _SM_PR_I2C_DEFAULTS_H_
#define _SM_PR_I2C_DEFAULTS_H_
#define SM_PR_I2C_DFLT_SYS_FREQ 100000000 /* 100 MHz */
#define SM_PR_I2C_DFLT_I2C_FREQ 100000 /* 100 KHz */
#define SM_PR_I2C_DFLT_I2C_CONFIG 0x0 /* Nothing for now */
#define SM_PR_I2C_DFLT_I2C_SLEEP_USECS 10000 /* 10 ms sleep between read/writes */
#endif
# include hal/sm_io/rw_param/otherDIR...
sm_io_rw_param_DIR = hal/sm_io/rw_param
sm_io_rw_param_OBJS = $(sm_io_rw_param_DIR)/rw_param.o
sm_io_rw_param_INCLUDE_DIRS = $(sm_io_rw_param_DIR)
......@@ -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 */
......
......@@ -11,24 +11,56 @@
#define ADC0_CHAN_ID 0
#define ADC0_SAMPLE_SIZE 8 /* 8 Bytes -> ADC0 = 16-bit / ADC1 = 16-bit ... */
/* MIXER I */
#define MIX0_CHAN_ID (ADC0_CHAN_ID + 1)
#define MIX0_SAMPLE_SIZE 16 /* 16 Bytes -> MIX0 = 32-bit / MIX1 = 32-bit ... */
/* ADC SWAPPED (after the switching module) */
#define ADCSWAP0_CHAN_ID (ADC0_CHAN_ID + 1)
#define ADCSWAP0_SAMPLE_SIZE 8 /* 8 Bytes -> ADCSWAP0 = 16-bit / ADCSWAP1 = 16-bit ... */
/* MIXER I/Q 1/2 */
#define MIXIQ120_CHAN_ID (ADCSWAP0_CHAN_ID + 1)
#define MIXIQ120_SAMPLE_SIZE 16 /* 16 Bytes -> MIXI0 = 32-bit / MIXQ0 = 32-bit ... */
/* MIXER I/Q 3/4 */
#define MIXIQ340_CHAN_ID (MIXIQ120_CHAN_ID + 1)
#define MIXIQ340_SAMPLE_SIZE 16 /* 16 Bytes -> MIXI2 = 32-bit / MIXQ2 = 32-bit ... */
/* TBTDECIM I/Q 1/2 */
#define TBTDECIMIQ120_CHAN_ID (MIXIQ340_CHAN_ID + 1)
#define TBTDECIMIQ120_SAMPLE_SIZE 16 /* 16 Bytes -> TBTDECIM0 = 32-bit / TBTDECIM1 = 32-bit ... */
/* TBTDECIM I/Q 3/4 */
#define TBTDECIMIQ340_CHAN_ID (TBTDECIMIQ120_CHAN_ID + 1)
#define TBTDECIMIQ340_SAMPLE_SIZE 16 /* 16 Bytes -> TBTDECIM0 = 32-bit / TBTDECIM1 = 32-bit ... */
/* TBT AMP */
#define TBTAMP0_CHAN_ID (MIX0_CHAN_ID + 1)
#define TBTAMP0_CHAN_ID (TBTDECIMIQ340_CHAN_ID + 1)
#define TBTAMP0_SAMPLE_SIZE 16 /* 16 Bytes -> TBTAMP0 = 32-bit / TBTAMP1 = 32-bit ... */
/* TBT PHASE */
#define TBTPHA0_CHAN_ID (TBTAMP0_CHAN_ID + 1)
#define TBTPHA0_SAMPLE_SIZE 16 /* 16 Bytes -> TBTPHA0 = 32-bit / TBTPHA1 = 32-bit ... */
/* TBT POS */
#define TBTPOS0_CHAN_ID (TBTAMP0_CHAN_ID + 1)
#define TBTPOS0_CHAN_ID (TBTPHA0_CHAN_ID + 1)
#define TBTPOS0_SAMPLE_SIZE 16 /* 16 Bytes -> X = 32-bit / Y = 32-bit ... */
/* FOFBDECIM I/Q 1/2 */
#define FOFBDECIMIQ120_CHAN_ID (TBTPOS0_CHAN_ID + 1)
#define FOFBDECIMIQ120_SAMPLE_SIZE 16 /* 16 Bytes -> FOFBDECIM0 = 32-bit / FOFBDECIM1 = 32-bit ... */
/* FOFBDECIM I/Q 3/4 */
#define FOFBDECIMIQ340_CHAN_ID (FOFBDECIMIQ120_CHAN_ID + 1)
#define FOFBDECIMIQ340_SAMPLE_SIZE 16 /* 16 Bytes -> FOFBDECIM0 = 32-bit / FOFBDECIM1 = 32-bit ... */
/* FOFB AMP */
#define FOFBAMP0_CHAN_ID (TBTPOS0_CHAN_ID + 1)
#define FOFBAMP0_CHAN_ID (FOFBDECIMIQ340_CHAN_ID + 1)
#define FOFBAMP0_SAMPLE_SIZE 16 /* 16 Bytes -> FOFBAMP0 = 32-bit / FOFBAMP1 = 32-bit ... */
/* FOFB PHA */
#define FOFBPHA0_CHAN_ID (FOFBAMP0_CHAN_ID + 1)
#define FOFBPHA0_SAMPLE_SIZE 16 /* 16 Bytes -> FOFBPHA0 = 32-bit / FOFBPHA1 = 32-bit ... */
/* FOFB POS */
#define FOFBPOS0_CHAN_ID (FOFBAMP0_CHAN_ID + 1)
#define FOFBPOS0_CHAN_ID (FOFBPHA0_CHAN_ID + 1)
#define FOFBPOS0_SAMPLE_SIZE 16 /* 16 Bytes -> X = 32-bit / Y = 32-bit ... */
/* MONIT AMP */
......
#ifndef _DDR3_DEFS_H_
#define _DDR3_DEFS_H_
#define MEM_TOTAL_SIZE (1UL << 31) /* 2 GB reserved for position storage */
#ifdef __SHRINK_AFCV3_DDR_SIZE__
#define MEM_TOTAL_SIZE (1ULL << 28) /* 256 MB reserved for position storage */
#else
#define MEM_TOTAL_SIZE (1ULL << 31) /* 2 GB reserved for position storage */
#endif
#define MEM_REGION_SIZE (MEM_TOTAL_SIZE / 16)
/* FPGA Specific */
......
#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
......@@ -18,6 +18,9 @@
#define DSP_CTRL_RAW_REGS_OFFS 0x0000
#define DSP_BPM_RAW_SWAP_OFFS 0x0100
/* AFC DIAG Components */
#define WB_AFC_DIAG_CTRL_RAW_REGS_OFFS 0x0000
/* Should be autodiscovered by SDB */
/* Wishbone RAW Addresses */
......@@ -67,6 +70,11 @@
#define WB_PERIPH_RAW_ADDR 0x00370000
#define WB_AFC_DIAG_RAW_ADDR 0x00380000
#define WB_AFC_DIAG_CTRL_RAW_REGS (WB_AFC_DIAG_RAW_ADDR + \
WB_AFC_DIAG_CTRL_RAW_REGS_OFFS)
/* Large Memory RAW Addresses. It lives at address 0 */
#define LARGE_MEM_RAW_ADDR 0x00000000
......@@ -135,6 +143,10 @@
#define WB_PERIPH_BASE_ADDR (BAR4_ADDR | WB_PERIPH_RAW_ADDR)
#define WB_AFC_DIAG_BASE_ADDR (BAR4_ADDR | WB_AFC_DIAG_RAW_ADDR)
#define WB_AFC_DIAG_CTRL_REGS (BAR4_ADDR | WB_AFC_DIAG_CTRL_RAW_REGS)
/* Large Memory Addresses */
#define LARGE_MEM_ADDR (BAR2_ADDR | LARGE_MEM_RAW_ADDR)
......
#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)
......@@ -28,7 +28,7 @@
#define DDR3_ADC0_MEM_SIZE 2
#define DDR3_ADC0_MEM_BOOL DDR3_MEM_BOOL(DDR3_ADC0_MEM_SIZE)
#define DDR3_ADC0_START_ADDR (DDR3_DUMMY_INIT0_START_ADDR + DDR3_ADC0_MEM_BOOL*DDR3_DUMMY_INIT0_SAMPLE_SIZE)
#define DDR3_ADC0_START_ADDR (DDR3_DUMMY_INIT0_START_ADDR + DDR3_DUMMY_INIT0_MEM_BOOL*DDR3_DUMMY_INIT0_SAMPLE_SIZE)
#define DDR3_ADC0_END_ADDR (DDR3_ADC0_START_ADDR + DDR3_ADC0_MEM_SIZE*MEM_REGION_SIZE - DDR3_ADC0_MEM_BOOL*DDR3_ADC0_SAMPLE_SIZE)
#define DDR3_ADC0_MAX_SAMPLES ((DDR3_ADC0_END_ADDR-DDR3_ADC0_START_ADDR) / DDR3_ADC0_SAMPLE_SIZE)
......@@ -38,7 +38,7 @@
#define DDR3_TBTAMP0_MEM_SIZE 2
#define DDR3_TBTAMP0_MEM_BOOL DDR3_MEM_BOOL(DDR3_TBTAMP0_MEM_SIZE)
#define DDR3_TBTAMP0_START_ADDR (DDR3_ADC0_END_ADDR + DDR3_TBTAMP0_MEM_BOOL*DDR3_ADC0_SAMPLE_SIZE)
#define DDR3_TBTAMP0_START_ADDR (DDR3_ADC0_END_ADDR + DDR3_ADC0_MEM_BOOL*DDR3_ADC0_SAMPLE_SIZE)
#define DDR3_TBTAMP0_END_ADDR (DDR3_TBTAMP0_START_ADDR + DDR3_TBTAMP0_MEM_SIZE*MEM_REGION_SIZE - DDR3_TBTAMP0_MEM_BOOL*DDR3_TBTAMP0_SAMPLE_SIZE)
#define DDR3_TBTAMP0_MAX_SAMPLES ((DDR3_TBTAMP0_END_ADDR-DDR3_TBTAMP0_START_ADDR) / DDR3_TBTAMP0_SAMPLE_SIZE)
......@@ -48,7 +48,7 @@
#define DDR3_TBTPOS0_MEM_SIZE 0
#define DDR3_TBTPOS0_MEM_BOOL DDR3_MEM_BOOL(DDR3_TBTPOS0_MEM_SIZE)
#define DDR3_TBTPOS0_START_ADDR (DDR3_TBTAMP0_END_ADDR + DDR3_TBTPOS0_MEM_BOOL*DDR3_TBTAMP0_SAMPLE_SIZE)
#define DDR3_TBTPOS0_START_ADDR (DDR3_TBTAMP0_END_ADDR + DDR3_TBTAMP0_MEM_BOOL*DDR3_TBTAMP0_SAMPLE_SIZE)
#define DDR3_TBTPOS0_END_ADDR (DDR3_TBTPOS0_START_ADDR + DDR3_TBTPOS0_MEM_SIZE*MEM_REGION_SIZE - DDR3_TBTPOS0_MEM_BOOL*DDR3_TBTPOS0_SAMPLE_SIZE)
#define DDR3_TBTPOS0_MAX_SAMPLES ((DDR3_TBTPOS0_END_ADDR-DDR3_TBTPOS0_START_ADDR) / DDR3_TBTPOS0_SAMPLE_SIZE)
......@@ -58,7 +58,7 @@
#define DDR3_FOFBAMP0_MEM_SIZE 2
#define DDR3_FOFBAMP0_MEM_BOOL DDR3_MEM_BOOL(DDR3_FOFBAMP0_MEM_SIZE)
#define DDR3_FOFBAMP0_START_ADDR (DDR3_TBTPOS0_END_ADDR + DDR3_FOFBAMP0_MEM_BOOL*DDR3_TBTPOS0_SAMPLE_SIZE)
#define DDR3_FOFBAMP0_START_ADDR (DDR3_TBTPOS0_END_ADDR + DDR3_TBTPOS0_MEM_BOOL*DDR3_TBTPOS0_SAMPLE_SIZE)
#define DDR3_FOFBAMP0_END_ADDR (DDR3_FOFBAMP0_START_ADDR + DDR3_FOFBAMP0_MEM_SIZE*MEM_REGION_SIZE - DDR3_FOFBAMP0_MEM_BOOL*DDR3_FOFBAMP0_SAMPLE_SIZE)
#define DDR3_FOFBAMP0_MAX_SAMPLES ((DDR3_FOFBAMP0_END_ADDR-DDR3_FOFBAMP0_START_ADDR) / DDR3_FOFBAMP0_SAMPLE_SIZE)
......@@ -68,7 +68,7 @@
#define DDR3_FOFBPOS0_MEM_SIZE 0
#define DDR3_FOFBPOS0_MEM_BOOL DDR3_MEM_BOOL(DDR3_FOFBPOS0_MEM_SIZE)
#define DDR3_FOFBPOS0_START_ADDR (DDR3_FOFBAMP0_END_ADDR + DDR3_FOFBPOS0_MEM_BOOL*DDR3_FOFBAMP0_SAMPLE_SIZE)
#define DDR3_FOFBPOS0_START_ADDR (DDR3_FOFBAMP0_END_ADDR + DDR3_FOFBAMP0_MEM_BOOL*DDR3_FOFBAMP0_SAMPLE_SIZE)
#define DDR3_FOFBPOS0_END_ADDR (DDR3_FOFBPOS0_START_ADDR + DDR3_FOFBPOS0_MEM_SIZE*MEM_REGION_SIZE - DDR3_FOFBPOS0_MEM_BOOL*DDR3_FOFBPOS0_SAMPLE_SIZE)
#define DDR3_FOFBPOS0_MAX_SAMPLES ((DDR3_FOFBPOS0_END_ADDR-DDR3_FOFBPOS0_START_ADDR) / DDR3_FOFBPOS0_SAMPLE_SIZE)
......@@ -78,7 +78,7 @@
#define DDR3_MONITAMP0_MEM_SIZE 0
#define DDR3_MONITAMP0_MEM_BOOL DDR3_MEM_BOOL(DDR3_MONITAMP0_MEM_SIZE)
#define DDR3_MONITAMP0_START_ADDR (DDR3_FOFBPOS0_END_ADDR + DDR3_MONITAMP0_MEM_BOOL*DDR3_FOFBPOS0_SAMPLE_SIZE)
#define DDR3_MONITAMP0_START_ADDR (DDR3_FOFBPOS0_END_ADDR + DDR3_FOFBPOS0_MEM_BOOL*DDR3_FOFBPOS0_SAMPLE_SIZE)
#define DDR3_MONITAMP0_END_ADDR (DDR3_MONITAMP0_START_ADDR + DDR3_MONITAMP0_MEM_SIZE*MEM_REGION_SIZE - DDR3_MONITAMP0_MEM_BOOL*DDR3_MONITAMP0_SAMPLE_SIZE)
#define DDR3_MONITAMP0_MAX_SAMPLES ((DDR3_MONITAMP0_END_ADDR-DDR3_MONITAMP0_START_ADDR) / DDR3_MONITAMP0_SAMPLE_SIZE)
......@@ -88,7 +88,7 @@
#define DDR3_MONITPOS0_MEM_SIZE 0
#define DDR3_MONITPOS0_MEM_BOOL DDR3_MEM_BOOL(DDR3_MONITPOS0_MEM_SIZE)
#define DDR3_MONITPOS0_START_ADDR (DDR3_MONITAMP0_END_ADDR + DDR3_MONITPOS0_MEM_BOOL*DDR3_MONITAMP0_SAMPLE_SIZE)
#define DDR3_MONITPOS0_START_ADDR (DDR3_MONITAMP0_END_ADDR + DDR3_MONITAMP0_MEM_BOOL*DDR3_MONITAMP0_SAMPLE_SIZE)
#define DDR3_MONITPOS0_END_ADDR (DDR3_MONITPOS0_START_ADDR + DDR3_MONITPOS0_MEM_SIZE*MEM_REGION_SIZE - DDR3_MONITPOS0_MEM_BOOL*DDR3_MONITPOS0_SAMPLE_SIZE)
#define DDR3_MONITPOS0_MAX_SAMPLES ((DDR3_MONITPOS0_END_ADDR-DDR3_MONITPOS0_START_ADDR) / DDR3_MONITPOS0_SAMPLE_SIZE)
......@@ -98,7 +98,7 @@
#define DDR3_MONIT1POS0_MEM_SIZE 0
#define DDR3_MONIT1POS0_MEM_BOOL DDR3_MEM_BOOL(DDR3_MONIT1POS0_MEM_SIZE)
#define DDR3_MONIT1POS0_START_ADDR (DDR3_MONITPOS0_END_ADDR + DDR3_MONIT1POS0_MEM_BOOL*DDR3_MONITPOS0_SAMPLE_SIZE)
#define DDR3_MONIT1POS0_START_ADDR (DDR3_MONITPOS0_END_ADDR + DDR3_MONITPOS0_MEM_BOOL*DDR3_MONITPOS0_SAMPLE_SIZE)
#define DDR3_MONIT1POS0_END_ADDR (DDR3_MONIT1POS0_START_ADDR + DDR3_MONIT1POS0_MEM_SIZE*MEM_REGION_SIZE - DDR3_MONIT1POS0_MEM_BOOL*DDR3_MONIT1POS0_SAMPLE_SIZE)
#define DDR3_MONIT1POS0_MAX_SAMPLES ((DDR3_MONIT1POS0_END_ADDR-DDR3_MONIT1POS0_START_ADDR) / DDR3_MONIT1POS0_SAMPLE_SIZE)
......
#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
......
/*
* 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.
*/
#ifndef _BPM_SERVER_H_
#define _BPM_SERVER_H_
#include "bpm_server_classes.h"
#endif
/*
* 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.
*/
#ifndef _BPM_SERVER_CLASSES_H_
#define _BPM_SERVER_CLASSES_H_
/* Set up environment for the application */
#include "bpm_server_prelude.h"
/* External dependencies */
#include <czmq.h>
#include <malamute.h>
#include <bsmp/client.h>
/* Internal libraries dependencies */
#include "libsdbfs.h"
#include "convc.h"
#include "disp_table.h"
#include "errhand.h"
#include "hutils.h"
#include "hal_stddef.h"
#include "hutils_math.h"
/* General dependencies */
#include "board.h"
#include "revision.h"
#include "acq_chan_gen_defs.h"
/* BPM version macros for compile-time API detection */
#define BPM_VERSION_MAJOR 0
#define BPM_VERSION_MINOR 1
#define BPM_VERSION_PATCH 0
#define BPM_MAKE_VERSION(major, minor, patch) \
((major) * 10000 + (minor) * 100 + (patch))
#define BPM_VERSION \
BPM_MAKE_VERSION(BPM_VERSION_MAJOR, BPM_VERSION_MINOR, BPM_VERSION_PATCH)
#if defined (__WINDOWS__)
# if defined LIBBPM_STATIC
# define BPM_EXPORT
# elif defined LIBBPM_EXPORTS
# define BPM_EXPORT __declspec(dllexport)
# else
# define BPM_EXPORT __declspec(dllimport)
# endif
#else
# define BPM_EXPORT
#endif
/* Opaque class structures to allow forward references */
/* Forward dmngr_err_e declaration enumeration */
typedef enum _dmngr_err_e dmngr_err_e;
/* Opaque devio_info_t structure */
typedef struct _devio_info_t devio_info_t;
/* Opaque dmngr_t class structure */
typedef struct _dmngr_t dmngr_t;
/* Forward llio_err_e declaration enumeration */
typedef enum _llio_err_e llio_err_e;
/* Forward llio_type_e declaration enumeration */
typedef enum _llio_type_e llio_type_e;
/* Forward llio_eth_type_e declaration enumeration */
typedef enum _llio_eth_type_e llio_eth_type_e;
/* Opaque llio_dev_info_t structure */
typedef struct _llio_dev_info_t llio_dev_info_t;
/* Opaque llio_endpoint_t structure */
typedef struct _llio_endpoint_t llio_endpoint_t;
/* Opaque llio_t structure */
typedef struct _llio_t llio_t;
/* Forward devio_err_e declaration enumeration */
typedef enum _devio_err_e devio_err_e;
/* Forward devio_type_e declaration enumeration */
typedef enum _devio_type_e devio_type_e;
/* Opaque devio_t structure */
typedef struct _devio_t devio_t;
/* Forward smpr_err_e declaration enumeration */
typedef enum _smpr_err_e smpr_err_e;
/* Opaque sm_pr_t structure */
typedef struct _smpr_t smpr_t;
/* Forward smch_err_e declaration enumeration */
typedef enum _smch_err_e smch_err_e;
/* Opaque sm_ch_24aa64_t structure */
typedef struct _smch_24aa64_t smch_24aa64_t;
/* Opaque sm_ch_ad9510_t structure */
typedef struct _smch_ad9510_t smch_ad9510_t;
/* Opaque sm_ch_pca9547_t structure */
typedef struct _smch_pca9547_t smch_pca9547_t;
/* Opaque sm_ch_si57x_t structure */
typedef struct _smch_si57x_t smch_si57x_t;
/* Opaque sm_ch_rffe_t structure */
typedef struct _smch_rffe_t smch_rffe_t;
/* Forward smio_err_e declaration enumeration */
typedef enum _smio_err_e smio_err_e;
/* Opaque smio_t structure */
typedef struct _smio_t smio_t;
/* Forward msg_err_e declaration enumeration */
typedef enum _msg_err_e msg_err_e;
/* Forward exp_msg_t declaration structure */
typedef struct _exp_msg_zmq_t exp_msg_zmq_t;
/* Forward zmq_server_args_t declaration structure */
typedef struct _zmq_server_args_t zmq_server_args_t;
/* Public API classes */
/* DEV MNGR */
#include "dev_mngr_err.h"
#include "dev_mngr_dev_info.h"
#include "dev_mngr_core.h"
/* LL_IO */
#include "ll_io_err.h"
#include "ll_io_utils.h"
#include "ll_io_dev_info.h"
#include "ll_io_endpoint.h"
#include "ll_io.h"
#include "ll_io_pcie.h"
#include "ll_io_eth_utils.h"
#include "ll_io_eth.h"
/* DEV_IO */
#include "dev_io_err.h"
#include "dev_io_utils.h"
#include "dev_io_exports.h"
#include "dev_io_core.h"
#include "dev_io.h"
/* SM_PR */
#include "sm_pr_err.h"
#include "sm_pr.h"
#include "sm_pr_spi.h"
#include "hw/wb_spi_regs.h"
#include "protocols/smpr_spi_regs.h"
#include "sm_pr_i2c.h"
#include "hw/wb_i2c_regs.h"
#include "protocols/smpr_i2c_regs.h"
#include "sm_pr_bsmp.h"
/* SM_CH */
#include "sm_ch_err.h"
#include "sm_ch_24aa64.h"
#include "chips/e24aa64_regs.h"
#include "sm_ch_ad9510.h"
#include "chips/ad9510_regs.h"
#include "sm_ch_pca9547.h"
#include "chips/pca9547_regs.h"
#include "sm_ch_si57x.h"
#include "chips/si57x_regs.h"
#include "sm_ch_rffe.h"
/* SM_IO */
#include "sm_io_err.h"
#include "sm_io_exports.h"
#include "sm_io_thsafe_codes.h"
#include "sm_io_bootstrap.h"
#include "sm_io_mod_dispatch.h"
#include "sm_io.h"
/* MSG */
#include "msg_macros.h"
#include "msg_err.h"
/* MSG EXP ops */
#include "exp_ops_codes.h"
#include "exp_msg_zmq.h"
/* MSG SMIO THSAFE ops */
#include "smio_thsafe_zmq_server.h"
#include "smio_thsafe_zmq_client.h"
/* General MSG */
#include "thsafe_msg_zmq.h"
#include "msg.h"
/* Other headers */
#include "bpm_client.h"
#include "rw_param.h"
#include "rw_param_codes.h"
#endif
/*
* 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.
*/
/* Copied from CZMQ repository, available at
* https://github.com/zeromq/czmq/blob/master/include/czmq_prelude.h */
#ifndef _BPM_SERVER_PRELUDE_H_
#define _BPM_SERVER_PRELUDE_H_
/* External dependencies */
#include <inttypes.h>
#include <sys/types.h>
#include <stdbool.h>
#endif
#ifndef _DEV_BE_IO_
#define _DEV_BE_IO_
#ifndef _DEV_IO_
#define _DEV_IO_
#include "dev_io_core.h"
#include "dev_io_utils.h"
#endif
......@@ -11,25 +11,35 @@
#ifndef _DEVIO_ERR_H_
#define _DEVIO_ERR_H_
enum _devio_err_e
{
#ifdef __cplusplus
extern "C" {
#endif
enum _devio_err_e {
DEVIO_SUCCESS = 0, /* No error */
DEVIO_ERR_ALLOC, /* Could not allocate memory */
DEVIO_ERR_FUNC_NOT_IMPL, /* Function not implemented */
DEVIO_ERR_SMIO_DO_OP, /* Error calling sm_io specific function */
DEVIO_ERR_NO_SMIO_OP, /* No sm_io registered for the opcode argument */
DEVIO_ERR_NO_SMIO_ID, /* No sm_io registered with the id argument */
DEVIO_ERR_MAX_SMIOS, /* Maximum number os SMIOs reached */
DEVIO_ERR_NO_NODES, /* No thread nodes available */
DEVIO_ERR_UNINIT_POLLER, /* Uninitliazed poller */
DEVIO_ERR_INTERRUPTED_POLLER, /* Poller interrupted. zeroMQ context was terminated or received interrupt signal */
DEVIO_ERR_BAD_MSG, /* Malformed message received */
DEVIO_ERR_TERMINATED, /* Terminated devio instance */
DEVIO_ERR_SMIO_DESTROY, /* Could not destroy sm_io instance */
DEVIO_ERR_INV_SOCKET, /* Invalid socket reference */
DEVIO_ERR_MOD_LLIO, /* Error modifying LLIO instance */
DEVIO_ERR_CFG, /* Could not get property from config file */
DEVIO_ERR_END /* End of enum marker */
};
typedef enum _devio_err_e devio_err_e;
/* Convert enumeration type to string */
const char * devio_err_str (devio_err_e err);
#ifdef __cplusplus
}
#endif
#endif
......@@ -8,9 +8,15 @@
#ifndef _DEV_IO_EXPORTS_H_
#define _DEV_IO_EXPORTS_H_
#include "smio_thsafe_zmq_server.h"
#ifdef __cplusplus
extern "C" {
#endif
#define DEVIO_OWNER_TYPE devio_t
#define DEVIO_EXP_OWNER(owner) ((devio_t *) owner)
#ifdef __cplusplus
}
#endif
#endif
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
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