Commit 5fc880a0 authored by Lucas Russo's avatar Lucas Russo

Merge branch 'proposed-master'

Conflicts:
	foreign/libmdp
parents 9f616b89 c3d15068
[submodule "majordomo"]
path = majordomo
[submodule "foreign/libbsmp"]
path = foreign/libbsmp
url = https://github.com/lerwys/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
......@@ -98,12 +98,26 @@ flags = [
'-I',
'hal/sm_io',
'-I',
'hal/sm_io/exports',
'-I',
'hal/sm_io/modules',
'-I',
'hal/sm_io/rw_param',
'-I',
'hal/sm_io/modules/fmc130m_4ch',
'-I',
'hal/sm_io/modules/acq',
'-I',
'hal/sm_io/modules/dsp',
'-I',
'hal/sm_io/modules/swap',
'-I',
'hal/sm_io/protocols',
'-I',
'hal/sm_io/protocols/ops',
'-I',
'hal/sm_io/chips',
'-I',
'hal/msg',
'-I',
'hal/msg/smio_thsafe_ops',
......
......@@ -11,28 +11,92 @@ OBJCOPY = $(CROSS_COMPILE)objcopy
SIZE = $(CROSS_COMPILE)size
MAKE = make
# Select board in which we will work. Options are: ml605, afc
BOARD = ml605
# Select board in which we will work. Options are: ml605 or afcv3
BOARD ?= ml605
#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
# 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:
# active, passive or nothing (dont' program EEPROM)
FMC130M_4CH_EEPROM_PROGRAM ?=
# Selects if we want to compile DEV_MNGR. Options are: y(es) or n(o)
WITH_DEV_MNGR ?= y
# Selects the AFE RFFE version. Options are: 2
AFE_RFFE_TYPE ?= 2
# Selects the install location of the config file
CFG_DIR ?= /etc/bpm_sw
export CFG_DIR
INSTALL_DIR ?= /usr/local
export INSTALL_DIR
# Config filename
CFG_FILENAME = bpm_sw.cfg
INIT_SCRIPTS = init.sh shutdown.sh
# Kernel stuff (pcie driver and library) relative
# Subdmoules and third-party codes
FOREIGN_DIR = foreign
# Our submodules and third-party codes
LIBMDP_DIR = $(FOREIGN_DIR)/libmdp/libmdp
LIBBSMP_DIR = $(FOREIGN_DIR)/libbsmp
PCIE_DRIVER_DIR = $(FOREIGN_DIR)/pcie-driver
# PCIe driver stuff (pcie driver and library) relative
# directory
KERNEL_DIR = kernel
KERNEL_VER = $(shell uname -r)
DRIVER_OBJ = /lib/modules/$(KERNEL_VER)/extra/pciDriver.ko
PCIE_DRIVER_VER = $(shell uname -r)
DRIVER_OBJ = /lib/modules/$(PCIE_DRIVER_VER)/extra/pciDriver.ko
# Client library
LIBCLIENT_DIR=libclient
# General C flags
CFLAGS = -std=gnu99 -O2 -DWR_SHIFT=2
CFLAGS = -std=gnu99 -O2
LOCAL_MSG_DBG ?= n
DBE_DBG ?= n
# Board selection
ifeq ($(BOARD),ml605)
CFLAGS += -D__BOARD_ML605__ -D__WR_SHIFT_FIX__=2
endif
ifeq ($(BOARD),afcv3)
CFLAGS += -D__BOARD_AFCV3__ -D__WR_SHIFT_FIX__=0
endif
# Program FMC130M_4CH EEPROM
ifeq ($(FMC130M_4CH_EEPROM_PROGRAM),active)
CFLAGS += -D__FMC130M_4CH_EEPROM_PROGRAM__=1
endif
ifeq ($(FMC130M_4CH_EEPROM_PROGRAM),passive)
CFLAGS += -D__FMC130M_4CH_EEPROM_PROGRAM__=2
endif
# Compile DEV MNGR or not
ifeq ($(WITH_DEV_MNGR),y)
CFLAGS += -D__WITH_DEV_MNGR__
endif
ifeq ($(AFE_RFFE_TYPE),1)
CFLAGS += -D__AFE_RFFE_V1__
endif
ifeq ($(AFE_RFFE_TYPE),2)
CFLAGS += -D__AFE_RFFE_V2__
endif
ifneq ($(CFG_DIR),)
CFLAGS += -D__CFG_DIR__=$(CFG_DIR)
endif
ifneq ($(CFG_FILENAME),)
CFLAGS += -D__CFG_FILENAME__=$(CFG_FILENAME)
endif
# Debug conditional flags
CFLAGS_DEBUG =
ifeq ($(LOCAL_MSG_DBG),y)
......@@ -51,7 +115,7 @@ CFLAGS_PLATFORM = -Wall -Wextra -Werror
LDFLAGS_PLATFORM =
# Libraries
LIBS = -lzmq -lczmq -lmdp -lpcidriver
LIBS = -lm -lzmq -lczmq -lmdp -lpcidriver
# General library flags -L<libdir>
LFLAGS =
......@@ -65,7 +129,7 @@ include hal/hal.mk
# Include directories
INCLUDE_DIRS = $(hal_INCLUDE_DIRS) \
-I$(KERNEL_DIR)/include/pcie \
-I$(PCIE_DRIVER_DIR)/include/pcie \
-I/usr/local/include
# Merge all flags.
......@@ -76,6 +140,9 @@ LDFLAGS = $(LDFLAGS_PLATFORM)
# Output modules
OUT = $(hal_OUT)
# All possible output modules
ALL_OUT = $(hal_all_OUT)
.SECONDEXPANSION:
# Save a git repository description
......@@ -85,18 +152,21 @@ OBJ_REVISION = $(addsuffix .o, $(REVISION_NAME))
OBJS_all = $(hal_OBJS) $(OBJ_REVISION)
.PHONY: all kernel clean mrproper install uninstall tests examples \
kernel_install kernel_uninstall kernel_check \
libclient libclient_install libclient_uninstall libclient_mrproper \
.PHONY: all install uninstall clean mrproper \
pcie_driver pcie_driver_install pcie_driver_uninstall pcie_driver_clean pcie_driver_check \
libclient libclient_install libclient_uninstall libclient_clean libclient_mrproper \
libmdp libmdp_install libmdp_uninstall libmdp_clean libmdp_mrproper \
libbsmp libbsmp_install libbsmp_uninstall libbsmp_clean libbsmp_mrproper \
hal_install hal_uninstall hal_clean hal_mrproper \
tests tests_clean tests_mrproper \
examples_clean examples_mrproper
examples examples_clean examples_mrproper \
cfg cfg_install cfg_uninstall cfg_clean cfg_mrproper
# Avoid deletion of intermediate files, such as objects
.SECONDARY: $(OBJS_all)
# Makefile rules
all: kernel libclient $(OUT)
all: libclient cfg $(OUT)
# Output Rule
$(OUT): $$($$@_OBJS) $(REVISION_NAME).o
......@@ -135,26 +205,62 @@ $(REVISION_NAME).o: $(REVISION_NAME).c
sed -e 's/^ *//' -e 's/$$/:/' >> $*.d
@rm -f $*.d.tmp
kernel: kernel_check
$(MAKE) -C $(KERNEL_DIR) all
pcie_driver:
$(MAKE) -C $(PCIE_DRIVER_DIR) all
#Verify if the driver is in place
kernel_check:
pcie_driver_check:
ifeq ($(wildcard $(DRIVER_OBJ)),)
@echo "PCI driver not found!";
@echo "Compilation will continue, but you must install";
@echo "and load the driver prior to initializing the software";
@sleep 2;
endif
kernel_install:
$(MAKE) -C $(KERNEL_DIR) install
pcie_driver_install:
$(MAKE) -C $(PCIE_DRIVER_DIR) install
pcie_driver_uninstall:
$(MAKE) -C $(PCIE_DRIVER_DIR) uninstall
pcie_driver_clean:
$(MAKE) -C $(PCIE_DRIVER_DIR) clean
libmdp_pre:
ifeq ($(wildcard $(LIBMDP_DIR)/Makefile),)
@echo "LIBMDP is not configured. Configuring ..."
@cd $(LIBMDP_DIR) && \
./autogen.sh && \
./configure
endif
libmdp: libmdp_pre
$(MAKE) -C $(LIBMDP_DIR)
libmdp_install: libmdp_pre
$(MAKE) -C $(LIBMDP_DIR) install
ldconfig
libmdp_uninstall: libmdp_pre
$(MAKE) -C $(LIBMDP_DIR) install
libmdp_clean: libmdp_pre
$(MAKE) -C $(LIBMDP_DIR) clean
libmdp_mrproper: libmdp_pre
$(MAKE) -C $(LIBMDP_DIR) distclean
libbsmp:
$(MAKE) -C $(LIBBSMP_DIR) all
libbsmp_install:
$(MAKE) -C $(LIBBSMP_DIR) PREFIX=$(INSTALL_DIR) install
kernel_uninstall:
$(MAKE) -C $(KERNEL_DIR) uninstall
libbsmp_uninstall:
$(MAKE) -C $(LIBBSMP_DIR) PREFIX=$(INSTALL_DIR) uninstall
kernel_clean:
$(MAKE) -C $(KERNEL_DIR) clean
libbsmp_clean:
$(MAKE) -C $(LIBBSMP_DIR) clean
libbsmp_mrproper:
$(MAKE) -C $(LIBBSMP_DIR) distclean
libclient:
$(MAKE) -C $(LIBCLIENT_DIR) all
......@@ -171,19 +277,29 @@ libclient_clean:
libclient_mrproper:
$(MAKE) -C $(LIBCLIENT_DIR) mrproper
deps: pcie_driver libmdp libbsmp
deps_install: pcie_driver_install libmdp_install libbsmp_install
deps_uninstall: pcie_driver_uninstall libmdp_uninstall libbsmp_uninstall
deps_clean: pcie_driver_clean libmdp_clean libbsmp_clean
deps_mrproper: libmdp_mrproper libbsmp_mrproper
hal_install:
$(foreach hal_bin,$(OUT),install -m 755 $(hal_bin) $(INSTALL_DIR)/bin $(CMDSEP))
$(foreach hal_bin,$(ALL_OUT),install -m 755 $(hal_bin) $(INSTALL_DIR)/bin $(CMDSEP))
$(foreach hal_script,$(INIT_SCRIPTS),install -m 755 $(hal_script) $(INSTALL_DIR)/etc $(CMDSEP))
hal_uninstall:
$(foreach hal_bin,$(OUT),rm -f $(INSTALL_DIR)/bin/$(hal_bin) $(CMDSEP))
$(foreach hal_bin,$(ALL_OUT),rm -f $(INSTALL_DIR)/bin/$(hal_bin) $(CMDSEP))
$(foreach hal_script,$(INIT_SCRIPTS),rm -f $(INSTALL_DIR)/etc/$(hal_script) $(CMDSEP))
hal_clean:
rm -f $(OBJS_all) $(OBJS_all:.o=.d)
hal_mrproper:
rm -f $(OUT)
rm -f $(ALL_OUT)
tests:
$(MAKE) -C tests all
......@@ -203,11 +319,26 @@ examples_clean:
examples_mrproper:
$(MAKE) -C examples mrproper
install: hal_install kernel_install libclient_install
cfg:
$(MAKE) -C cfg all
cfg_install:
$(MAKE) -C cfg install
cfg_uninstall:
$(MAKE) -C cfg uninstall
cfg_clean:
$(MAKE) -C cfg clean
cfg_mrproper:
$(MAKE) -C cfg mrproper
install: hal_install deps_install libclient_install cfg_install
uninstall: hal_uninstall kernel_uninstall libclient_uninstall
uninstall: hal_uninstall deps_uninstall libclient_uninstall cfg_uninstall
clean: hal_clean kernel_clean libclient_clean examples_clean tests_clean
clean: hal_clean deps_clean libclient_clean examples_clean tests_clean cfg_clean
mrproper: clean hal_mrproper libclient_mrproper examples_mrproper libclient_mrproper
mrproper: clean hal_mrproper deps_mrproper libclient_mrproper examples_mrproper tests_mrproper cfg_mrproper
# Set your cross compile prefix with CROSS_COMPILE variable
CROSS_COMPILE ?=
CMDSEP = ;
CC = $(CROSS_COMPILE)gcc
AR = $(CROSS_COMPILE)ar
LD = $(CROSS_COMPILE)ld
OBJDUMP = $(CROSS_COMPILE)objdump
OBJCOPY = $(CROSS_COMPILE)objcopy
SIZE = $(CROSS_COMPILE)size
MAKE = make
CFG_DIR ?= /etc/bpm_sw
# Get all .cfg files
CFG_FILES ?= $(wildcard *.cfg)
.PHONY: all clean mrproper install uninstall
# Makefile rules
all:
install:
@mkdir -p $(CFG_DIR)
$(foreach cfg,$(CFG_FILES),install -m 755 $(cfg) $(CFG_DIR)/ $(CMDSEP))
uninstall:
$(foreach cfg,$(CFG_FILES),rm -f $(CFG_DIR)/$(cfg) $(CMDSEP))
@rm -rf $(CFG_DIR)
clean:
mrproper: clean
# BPM-SW configuration file
# Device manager configurations
dev_mngr
broker
bind = tcp://10.0.18.35:8888
log
dir = /export/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 = tcp://10.0.18.59:6791
bpm1
dbe
afe
bind =
board1
bpm0
dbe
afe
bind =
bpm1
dbe
afe
bind =
board2
bpm0
dbe
afe
bind =
bpm1
dbe
afe
bind =
board3
bpm0
dbe
afe
bind =
bpm1
dbe
afe
bind =
board4
bpm0
dbe
afe
bind =
bpm1
dbe
afe
bind =
board5
bpm0
dbe
afe
bind =
bpm1
dbe
afe
bind =
#!/bin/bash
# All of our Makefile options
# Select board in which we will work. Options are: ml605 or afcv3
BOARD=afcv3
#Select if we want to compile code with all messages outputs. Options are: y(es) or n(o)
LOCAL_MSG_DBG=n
#Select if we want to compile with debug mode on. Options are: y(es) or n(o)
DBE_DBG=y
# 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:
# active, passive or nothing (dont' program EEPROM)
FMC130M_4CH_EEPROM_PROGRAM=
# Selects if we want to compile DEV_MNGR. Options are: y(es) or n(o)
WITH_DEV_MNGR=y
# Selects the AFE RFFE version. Options are: 2
AFE_RFFE_TYPE=2
# 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
COMMAND_DEPS="\
make deps && \
sudo make deps_install"
COMMAND_HAL="\
make BOARD=${BOARD} \
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} \
CFG_DIR=${CFG_DIR} && \
sudo make install"
COMMAND_LIBCLIENT="\
make BOARD=${BOARD} \
LOCAL_MSG_DBG=${LOCAL_MSG_DBG} \
DBE_DBG=${DBE_DBG} libclient && \
sudo make libclient_install"
COMMAND_ARRAY=(
"${COMMAND_DEPS}"
"${COMMAND_HAL}"
"${COMMAND_LIBCLIENT}"
)
for i in "${COMMAND_ARRAY[@]}"
do
echo "Executing: " $i
eval $i
# Check return value
rc=$?
if [[ $rc != 0 ]]; then
exit $rc
fi
done
......@@ -12,28 +12,23 @@
#define DFLT_BIND_FOLDER "/tmp/bpm"
#define DEFAULT_NUM_SAMPLES 4096
#define DEFAULT_CHAN_NUM 0
#define DFLT_NUM_SAMPLES 4096
#define DFLT_CHAN_NUM 0
#define DFLT_BPM_NUMBER 0
#define MAX_BPM_NUMBER 1
#define DFLT_BOARD_NUMBER 0
#define MAX_BOARD_NUMBER 5
/* Arbitrary hard limits */
#define MAX_NUM_SAMPLES (1 << 28)
#define MAX_NUM_CHANS (1 << 8)
typedef struct _acq_chan_t {
uint32_t chan;
uint32_t sample_size;
} acq_chan_t;
/* Global structure merging all of the channel's sample sizes */
acq_chan_t __acq_chan[END_CHAN_ID] = { [0] = {.chan = ADC_CHAN_ID, .sample_size = ADC_SAMPLE_SIZE},
[1] = {.chan = TBTAMP_CHAN_ID, .sample_size = TBTAMP_SAMPLE_SIZE},
[2] = {.chan = TBTPOS_CHAN_ID, .sample_size = TBTPOS_SAMPLE_SIZE},
[3] = {.chan = FOFBAMP_CHAN_ID, .sample_size = FOFBAMP_SAMPLE_SIZE},
[4] = {.chan = FOFBPOS_CHAN_ID, .sample_size = FOFBPOS_SAMPLE_SIZE} };
void print_data (uint32_t chan, uint32_t *data, uint32_t size)
{
/* FIXME: Make it more generic */
if (chan == 0) {
if (chan == 0 || chan == 9) {
int16_t *raw_data16 = (int16_t *) data;
for (uint32_t i = 0; i < (size/sizeof(uint16_t)) / 4; i++) {
if (zctx_interrupted) {
......@@ -70,6 +65,7 @@ void print_help (char *program_name)
"\t-v Verbose output\n"
"\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-ch <chan_str> Acquisition channel\n"
, program_name);
}
......@@ -79,6 +75,8 @@ int main (int argc, char *argv [])
int verbose = 0;
char *broker_endp = NULL;
char *num_samples_str = NULL;
char *board_number_str = NULL;
char *bpm_number_str = NULL;
char *chan_str = NULL;
char **str_p = NULL;
......@@ -110,6 +108,13 @@ int main (int argc, char *argv [])
else if (streq (argv[i], "-ch")) { /* ch: channel */
str_p = &chan_str;
}
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]);
......@@ -127,8 +132,8 @@ int main (int argc, char *argv [])
uint32_t num_samples;
if (num_samples_str == NULL) {
fprintf (stderr, "[client:acq]: Setting default value to number of samples: %u\n",
DEFAULT_NUM_SAMPLES);
num_samples = DEFAULT_NUM_SAMPLES;
DFLT_NUM_SAMPLES);
num_samples = DFLT_NUM_SAMPLES;
}
else {
num_samples = strtoul (num_samples_str, NULL, 10);
......@@ -139,13 +144,13 @@ int main (int argc, char *argv [])
num_samples = MAX_NUM_SAMPLES;
}
}
fprintf (stdout, "[client:acq]: num_samples = %u\n", num_samples);
//fprintf (stdout, "[client:acq]: num_samples = %u\n", num_samples);
/* Set default channel */
uint32_t chan;
if (chan_str == NULL) {
fprintf (stderr, "[client:acq]: Setting default value to 'chan'\n");
chan = DEFAULT_CHAN_NUM;
chan = DFLT_CHAN_NUM;
}
else {
chan = strtoul (chan_str, NULL, 10);
......@@ -156,10 +161,49 @@ int main (int argc, char *argv [])
chan = MAX_NUM_CHANS;
}
}
fprintf (stdout, "[client:acq]: chan = %u\n", chan);
//fprintf (stdout, "[client:acq]: chan = %u\n", chan);
/* 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);
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 */
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);
uint32_t data_size = num_samples*__acq_chan[chan].sample_size;
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];
sprintf (service, "BPM%u:DEVIO:ACQ%u", board_number, bpm_number);
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,
.chan = chan,
......@@ -169,19 +213,24 @@ int main (int argc, char *argv [])
.data_size = data_size,
}
};
bpm_client_err_e err = bpm_get_curve (bpm_client, "BPM0:DEVIO:ACQ", &acq_trans);
bpm_client_err_e err = bpm_get_curve (bpm_client, service, &acq_trans,
50000, new_acq);
if (err != BPM_CLIENT_SUCCESS){
fprintf (stderr, "[client:acq]: bpm_get_curve failed\n");
goto err_bpm_get_curve;
}
fprintf (stdout, "[client:acq]: bpm_get_curve was successfully executed\n");
//fprintf (stdout, "[client:acq]: bpm_get_curve was successfully executed\n");
fprintf (stdout, "clear\n");
print_data (chan, data, acq_trans.block.bytes_read);
err_bpm_get_curve:
str_p = &chan_str;
free (*str_p);
chan_str = NULL;
str_p = &board_number_str;
free (*str_p);
board_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
* */
#include <mdp.h>
#include <czmq.h>
#include <inttypes.h>
#include <stdio.h>
#include <string.h>
#include <bpm_client.h>
#define DFLT_BIND_FOLDER "/tmp/bpm"
/* Default value definitions */
#define DFLT_BPM_NUMBER 0
#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
#define FUNC_AD9510_PRESCALER_IDX 2
#define FUNC_AD9510_R_DIV_IDX 3
#define FUNC_AD9510_PLL_PDOWN_IDX 4
#define FUNC_AD9510_MUX_STATUS_IDX 5
#define FUNC_AD9510_CP_CURRENT_IDX 6
#define FUNC_AD9510_OUTPUTS_IDX 7
#define FUNC_AD9510_PLL_CLK_SEL_IDX 8
#define FUNC_AD9510_END 9
#define MAX_NUM_FUNCS FUNC_AD9510_END
typedef bpm_client_err_e (*bpm_func_fp) (bpm_client_t *self, char *service,
uint32_t value);
static const bpm_func_fp bpm_ad9510_funcs [MAX_NUM_FUNCS] = {
&bpm_set_ad9510_pll_a_div,
&bpm_set_ad9510_pll_b_div,
&bpm_set_ad9510_pll_prescaler,
&bpm_set_ad9510_r_div,
&bpm_set_ad9510_pll_pdown,
&bpm_set_ad9510_mux_status,
&bpm_set_ad9510_cp_current,
&bpm_set_ad9510_outputs,
&bpm_set_ad9510_pll_clk_sel,
};
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"
"\t-board <AMC board = [0|1|2|3|4|5]>\n"
"\t-bpm <BPM number = [0|1]>\n"
"\t-a_div <divider> PLL A Divider\n"
"\t-b_div <divider> PLL B Divider\n"
"\t-prescaler <value> PLL Prescaler value\n"
"\t-r_div <value> PLL Prescaler value\n"
"\t-pll_pdown <value> PLL Power down\n"
"\t-mux_status <value> PLL Mux status\n"
"\t-cp_current <value> PLL Charge Pump current [600|1200|...|4800]i uA\n"
"\t-outputs <value> Clock outputs control = [8-bit bitmask]\n"
"\t-pll_clk_sel <value> PLL Clock selection = [1|2]\n"
, program_name);
}
typedef struct _func_call_t {
int call;
char **arg;
} func_call_t;
int main (int argc, char *argv [])
{
int verbose = 0;
char *broker_endp = NULL;
char *board_number_str = NULL;
char *bpm_number_str = NULL;
char *a_div_str = NULL;
char *b_div_str = NULL;
char *prescaler_div_str = NULL;
char *r_div_str = NULL;
char *pll_pdown_str = NULL;
char *mux_status_str = NULL;
char *cp_current_str = NULL;
char *outputs_str = NULL;
char *pll_clk_sel_str = NULL;
func_call_t func_call [MAX_NUM_FUNCS] = {{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], "-b")) {
str_p = &broker_endp;
}
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], "-a_div")) { /* a_div: divider value */
func_call [FUNC_AD9510_A_DIV_IDX].call = 1;
func_call [FUNC_AD9510_A_DIV_IDX].arg = &a_div_str;
str_p = &a_div_str;
}
else if (streq (argv[i], "-b_div")) { /* b_div: divider value */
func_call [FUNC_AD9510_B_DIV_IDX].call = 1;
func_call [FUNC_AD9510_B_DIV_IDX].arg = &b_div_str;
str_p = &b_div_str;
}
else if (streq (argv[i], "-prescaler_div")) { /* prescaler_div: divider value */
func_call [FUNC_AD9510_PRESCALER_IDX].call = 1;
func_call [FUNC_AD9510_PRESCALER_IDX].arg = &prescaler_div_str;
str_p = &prescaler_div_str;
}
else if (streq (argv[i], "-r_div")) { /* r_div: divider value */
func_call [FUNC_AD9510_R_DIV_IDX].call = 1;
func_call [FUNC_AD9510_R_DIV_IDX].arg = &r_div_str;
str_p = &r_div_str;
}
else if (streq (argv[i], "-pll_pdown")) { /* pll_pdown: divider value */
func_call [FUNC_AD9510_PLL_PDOWN_IDX].call = 1;
func_call [FUNC_AD9510_PLL_PDOWN_IDX].arg = &pll_pdown_str;
str_p = &pll_pdown_str;
}
else if (streq (argv[i], "-mux_status")) { /* mux_status: divider value */
func_call [FUNC_AD9510_MUX_STATUS_IDX].call = 1;
func_call [FUNC_AD9510_MUX_STATUS_IDX].arg = &mux_status_str;
str_p = &mux_status_str;
}
else if (streq (argv[i], "-cp_current")) { /* cp_current: divider value */
func_call [FUNC_AD9510_CP_CURRENT_IDX].call = 1;
func_call [FUNC_AD9510_CP_CURRENT_IDX].arg = &cp_current_str;
str_p = &cp_current_str;
}
else if (streq (argv[i], "-outputs")) { /* outputs: divider value */
func_call [FUNC_AD9510_OUTPUTS_IDX].call = 1;
func_call [FUNC_AD9510_OUTPUTS_IDX].arg = &outputs_str;
str_p = &outputs_str;
}
else if (streq (argv[i], "-pll_clk_sel")) { /* pll_clk_sel: divider value */
func_call [FUNC_AD9510_PLL_CLK_SEL_IDX].call = 1;
func_call [FUNC_AD9510_PLL_CLK_SEL_IDX].arg = &pll_clk_sel_str;
str_p = &pll_clk_sel_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:leds]: 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);
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 */
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];
sprintf (service, "BPM%u:DEVIO:FMC130M_4CH%u", board_number, bpm_number);
bpm_client_t *bpm_client = bpm_client_new (broker_endp, verbose, NULL);
for (i = 0; i < MAX_NUM_FUNCS; ++i) {
if (func_call [i].call == 1) {
fprintf (stdout, "[client:ad9510_ctl]: Calling function #%d\n", i);
fprintf (stdout, "[client:ad9510_ctl]: Argument: %lu\n", strtoul (*func_call [i].arg, NULL, 10));
bpm_client_err_e err = bpm_ad9510_funcs [i]
(bpm_client, service, strtoul (*func_call [i].arg, NULL, 10));
if (err != BPM_CLIENT_SUCCESS) {
fprintf (stderr, "[client:ad9510_ctl]: Error executing remote "
"function: %s\n", bpm_client_err_str (err));
}
}
}
bpm_client_destroy (&bpm_client);
/* ugly... */
free (a_div_str);
free (b_div_str);
free (prescaler_div_str);
free (r_div_str);
free (pll_pdown_str);
free (mux_status_str);
free (cp_current_str);
free (outputs_str);
free (pll_clk_sel_str);
free (board_number_str);
free (bpm_number_str);
free (broker_endp);
return 0;
}
/*
* Simple example demonstrating the communication between
* a client and the FPGA device
*/
#include <mdp.h>
#include <czmq.h>
#include <inttypes.h>
#include <bpm_client.h>
#define DFLT_BIND_FOLDER "/tmp/bpm"
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);
}
int main (int argc, char *argv [])
{
int verbose = 0;
char *broker_endp = NULL;
char **str_p = NULL;
if (argc < 2) {
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], "-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);
}
bpm_client_t *bpm_client = bpm_client_new (broker_endp, verbose, NULL);
uint32_t adc_data;
bpm_client_err_e err = bpm_get_adc_data0 (bpm_client, "BPM0:DEVIO:FMC130M_4CH0",
&adc_data);
if (err != BPM_CLIENT_SUCCESS){
fprintf (stderr, "[client:acq]: bpm_get_adc_data0 failed\n");
goto err_get_adc_data;
}
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);
if (err != BPM_CLIENT_SUCCESS){
fprintf (stderr, "[client:acq]: bpm_get_adc_data1 failed\n");
goto err_get_adc_data;
}
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);
if (err != BPM_CLIENT_SUCCESS){
fprintf (stderr, "[client:acq]: bpm_get_adc_data2 failed\n");
goto err_get_adc_data;
}
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);
if (err != BPM_CLIENT_SUCCESS){
fprintf (stderr, "[client:acq]: bpm_get_adc_data3 failed\n");
goto err_get_adc_data;
}
fprintf (stdout, "[client:adc_data]: data3 = %d\n", (int16_t) adc_data);
err_get_adc_data:
bpm_client_destroy (&bpm_client);
str_p = &broker_endp;
free (*str_p);
broker_endp = NULL;
return 0;
}
/*
* * Simple example demonstrating the communication between
* * a client and the FPGA device
* */
#include <mdp.h>
#include <czmq.h>
#include <inttypes.h>
#include <stdio.h>
#include <string.h>
#include <bpm_client.h>
#define DFLT_BIND_FOLDER "/tmp/bpm"
/* Default value definitions */
#define DFLT_BPM_NUMBER 0
#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
#define DFLT_CHAN_NUM 0
#define MAX_CHAN_NUM 3 /* 0-3 */
#define DFLT_LINES_NUM 1 /* DATA */
#define MAX_LINES_NUM 3 /* DATA + CLOCK */
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"
"\t-board <AMC board = [0|1|2|3|4|5]>\n"
"\t-bpm <BPM number = [0|1]>\n"
"\t-ch <channel> ADC channel\n"
"\t-lines <delay_lines> ADC delay lines (1 = data, 2 = clock, 3 = both)\n"
"\t-val <delay_value> ADC delay value (0-31)\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 *chan_str = NULL;
char *lines_str = NULL;
char *dly_val_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], "-b")) {
str_p = &broker_endp;
}
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], "-ch")) { /* ch: channel */
str_p = &chan_str;
}
else if (streq (argv[i], "-lines")) { /* lines: delay lines */
str_p = &lines_str;
}
else if (streq (argv[i], "-val")) { /* val: delay value */
str_p = &dly_val_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:leds]: 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);
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 */
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;
}
}
/* Set default channel */
uint32_t chan;
if (chan_str == NULL) {
fprintf (stderr, "[client:adc_dly]: Setting default value to: %u\n",
DFLT_CHAN_NUM);
chan = DFLT_CHAN_NUM;
}
else {
chan = strtoul (chan_str, NULL, 10);
if (chan > MAX_CHAN_NUM) {
fprintf (stderr, "[client:adc_dly]: Channel number too big! Defaulting to: %u\n",
MAX_CHAN_NUM);
chan = MAX_CHAN_NUM;
}
}
fprintf (stdout, "[client:adc_dly]: chan = %u\n", chan);
/* Set ADC default line values */
uint32_t lines = 0;
if (lines_str == NULL) {
fprintf (stderr, "[client:adc_dly]: Setting default ADC lines to: %u\n",
DFLT_LINES_NUM);
lines = DFLT_LINES_NUM;
}
else {
lines = strtoul (lines_str, NULL, 10);
if (lines > MAX_LINES_NUM) {
fprintf (stderr, "[client:adc_dly]: ADC delay value too big! Defaulting to: %u\n",
MAX_LINES_NUM);
lines = MAX_LINES_NUM;
}
}
fprintf (stdout, "[client:adc_dly]: ADC lines value = %u\n", lines);
/* Set default ADC Delay values */
uint32_t dly_val = 0;
if (dly_val_str == NULL) {
fprintf (stderr, "[client:adc_dly]: Setting default ADC delay value to: %u\n",
DFLT_ADC_DLY_VALUE);
dly_val = DFLT_ADC_DLY_VALUE;
}
else {
dly_val = strtoul (dly_val_str, NULL, 10);
if (dly_val > MAX_ADC_DLY_VALUE) {
fprintf (stderr, "[client:adc_dly]: ADC delay value too big! Defaulting to: %u\n",
MAX_ADC_DLY_VALUE);
dly_val = MAX_ADC_DLY_VALUE;
}
}
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);
bpm_client_t *bpm_client = bpm_client_new (broker_endp, verbose, NULL);
/* Call the appropriate delay function. FIXME: the case construct is
* not generic nor expansible */
switch(chan) {
case 0:
bpm_set_adc_dly0 (bpm_client, service, lines, dly_val);
break;
case 1:
bpm_set_adc_dly1 (bpm_client, service, lines, dly_val);
break;
case 2:
bpm_set_adc_dly2 (bpm_client, service, lines, dly_val);
break;
case 3:
bpm_set_adc_dly3 (bpm_client, service, lines, dly_val);
break;
default:
bpm_set_adc_dly0 (bpm_client, service, lines, dly_val);
break;
}
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 = &chan_str;
free (*str_p);
chan_str = NULL;
str_p = &dly_val_str;
free (*str_p);
dly_val_str = NULL;
str_p = &broker_endp;
free (*str_p);
broker_endp = NULL;
return 0;
}
......@@ -62,9 +62,18 @@ int main (int argc, char *argv [])
bpm_client_t *bpm_client = bpm_client_new (broker_endp, verbose, NULL);
uint32_t trig_dir = 0;
fprintf (stdout, "[client:dsp]: trig_dir = %u\n", trig_dir);
bpm_client_err_e err = bpm_set_trig_dir (bpm_client, "BPM0:DEVIO:FMC130M_4CH0", trig_dir);
if (err != BPM_CLIENT_SUCCESS){
fprintf (stderr, "[client:dsp]: bpm_set_trig_dir failed\n");
goto err_bpm_set;
}
fprintf (stdout, "[client:dsp]: bpm_set_trig_dir was successfully executed\n");
uint32_t kx_set = 10000000;
fprintf (stdout, "[client:dsp]: kx = %u\n", kx_set);
bpm_client_err_e err = bpm_set_kx (bpm_client, "BPM0:DEVIO:DSP", kx_set);
err = bpm_set_kx (bpm_client, "BPM0:DEVIO:DSP0", kx_set);
if (err != BPM_CLIENT_SUCCESS){
fprintf (stderr, "[client:dsp]: bpm_set_kx failed\n");
goto err_bpm_set;
......@@ -73,7 +82,7 @@ int main (int argc, char *argv [])
uint32_t ds_tbt_thres = 200000;
fprintf (stdout, "[client:dsp]: ds_tbt_thres = %u\n", ds_tbt_thres);
err = bpm_set_ds_tbt_thres (bpm_client, "BPM0:DEVIO:DSP", ds_tbt_thres);
err = bpm_set_ds_tbt_thres (bpm_client, "BPM0:DEVIO:DSP0", ds_tbt_thres);
if (err != BPM_CLIENT_SUCCESS){
fprintf (stderr, "[client:dsp]: bpm_set_tbt_ds_thres failed\n");
goto err_bpm_set;
......@@ -81,17 +90,17 @@ int main (int argc, char *argv [])
fprintf (stdout, "[client:dsp]: bpm_set_ds_tbt_thres was successfully executed\n");
uint32_t kx_get;
err = bpm_get_kx (bpm_client, "BPM0:DEVIO:DSP", &kx_get);
err = bpm_get_kx (bpm_client, "BPM0:DEVIO:DSP0", &kx_get);
if (err != BPM_CLIENT_SUCCESS){
fprintf (stderr, "[client:dsp]: bpm_get_kx failed\n");
goto err_bpm_get;
}
fprintf (stdout, "[client:dsp]: bpm_get_kx = %u was successfully executed\n",
kx_get);
kx_get);
uint32_t ky_set = 10000000;
fprintf (stdout, "[client:dsp]: ky = %u\n", ky_set);
err = bpm_set_ky (bpm_client, "BPM0:DEVIO:DSP", ky_set);
err = bpm_set_ky (bpm_client, "BPM0:DEVIO:DSP0", ky_set);
if (err != BPM_CLIENT_SUCCESS){
fprintf (stderr, "[client:dsp]: bpm_set_ky failed\n");
goto err_bpm_set;
......@@ -99,17 +108,17 @@ int main (int argc, char *argv [])
fprintf (stdout, "[client:dsp]: bpm_set_ky was successfully executed\n");
uint32_t ky_get;
err = bpm_get_ky (bpm_client, "BPM0:DEVIO:DSP", &ky_get);
err = bpm_get_ky (bpm_client, "BPM0:DEVIO:DSP0", &ky_get);
if (err != BPM_CLIENT_SUCCESS){
fprintf (stderr, "[client:dsp]: bpm_get_ky failed\n");
goto err_bpm_get;
}
fprintf (stdout, "[client:dsp]: bpm_get_ky = %u was successfully executed\n",
ky_get);
ky_get);
uint32_t ksum_set = 0x0FFFFFF; // 1.0 FIX25_24;
uint32_t ksum_set = 0x7FFFFF; // 1.0 FIX25_24;
fprintf (stdout, "[client:dsp]: ksum = %u\n", ksum_set);
err = bpm_set_ksum (bpm_client, "BPM0:DEVIO:DSP", ksum_set);
err = bpm_set_ksum (bpm_client, "BPM0:DEVIO:DSP0", ksum_set);
if (err != BPM_CLIENT_SUCCESS){
fprintf (stderr, "[client:dsp]: bpm_set_ksum failed\n");
goto err_bpm_set;
......@@ -117,44 +126,44 @@ int main (int argc, char *argv [])
fprintf (stdout, "[client:dsp]: bpm_set_ksum was successfully executed\n");
uint32_t ksum_get;
err = bpm_get_ksum (bpm_client, "BPM0:DEVIO:DSP", &ksum_get);
err = bpm_get_ksum (bpm_client, "BPM0:DEVIO:DSP0", &ksum_get);
if (err != BPM_CLIENT_SUCCESS){
fprintf (stderr, "[client:dsp]: bpm_get_ksum failed\n");
goto err_bpm_get;
}
fprintf (stdout, "[client:dsp]: bpm_get_ksum = %u was successfully executed\n",
ksum_get);
ksum_get);
uint32_t sw = 1;
err = bpm_set_sw (bpm_client, "BPM0:DEVIO:SWAP", sw);
err = bpm_set_sw (bpm_client, "BPM0:DEVIO:SWAP0", sw);
if (err != BPM_CLIENT_SUCCESS){
fprintf (stderr, "[client:swap]: bpm_set_sw failed\n");
goto err_bpm_set;
}
fprintf (stdout, "[client:swap]: bpm_set_sw = %u was successfully executed\n",
sw);
sw);
uint32_t sw_en = 0;
err = bpm_set_sw_en (bpm_client, "BPM0:DEVIO:SWAP", sw_en);
uint32_t sw_en = 1;
err = bpm_set_sw_en (bpm_client, "BPM0:DEVIO:SWAP0", sw_en);
if (err != BPM_CLIENT_SUCCESS){
fprintf (stderr, "[client:swap]: bpm_set_sw_en failed\n");
goto err_bpm_set;
}
fprintf (stdout, "[client:swap]: bpm_set_sw_en = %u was successfully executed\n",
sw_en);
sw_en);
uint32_t div_clk = 250;
err = bpm_set_div_clk (bpm_client, "BPM0:DEVIO:SWAP", div_clk);
err = bpm_set_div_clk (bpm_client, "BPM0:DEVIO:SWAP0", div_clk);
if (err != BPM_CLIENT_SUCCESS){
fprintf (stderr, "[client:swap]: bpm_set_div_clk failed\n");
goto err_bpm_set;
}
fprintf (stdout, "[client:swap]: bpm_set_div_clk = %u was successfully executed\n",
div_clk);
div_clk);
uint32_t gain_aa = 32768;
uint32_t gain_ac = 32768;
err = bpm_set_gain_a (bpm_client, "BPM0:DEVIO:SWAP", gain_aa, gain_ac);
err = bpm_set_gain_a (bpm_client, "BPM0:DEVIO:SWAP0", gain_aa, gain_ac);
if (err != BPM_CLIENT_SUCCESS){
fprintf (stderr, "[client:swap]: bpm_set_gain_a failed\n");
goto err_bpm_set;
......@@ -162,7 +171,7 @@ int main (int argc, char *argv [])
fprintf (stdout, "[client:swap]: bpm_set_gain_a = direct %u, inverted %u was successfully executed\n",
gain_aa, gain_ac);
err = bpm_set_gain_b (bpm_client, "BPM0:DEVIO:SWAP", gain_aa, gain_ac);
err = bpm_set_gain_b (bpm_client, "BPM0:DEVIO:SWAP0", gain_aa, gain_ac);
if (err != BPM_CLIENT_SUCCESS){
fprintf (stderr, "[client:swap]: bpm_set_gain_b failed\n");
goto err_bpm_set;
......@@ -170,7 +179,7 @@ int main (int argc, char *argv [])
fprintf (stdout, "[client:swap]: bpm_set_gain_b = direct %u, inverted %u was successfully executed\n",
gain_aa, gain_ac);
err = bpm_set_gain_c (bpm_client, "BPM0:DEVIO:SWAP", gain_aa, gain_ac);
err = bpm_set_gain_c (bpm_client, "BPM0:DEVIO:SWAP0", gain_aa, gain_ac);
if (err != BPM_CLIENT_SUCCESS){
fprintf (stderr, "[client:swap]: bpm_set_gain_c failed\n");
goto err_bpm_set;
......@@ -178,7 +187,7 @@ int main (int argc, char *argv [])
fprintf (stdout, "[client:swap]: bpm_set_gain_c = direct %u, inverted %u was successfully executed\n",
gain_aa, gain_ac);
err = bpm_set_gain_d (bpm_client, "BPM0:DEVIO:SWAP", gain_aa, gain_ac);
err = bpm_set_gain_d (bpm_client, "BPM0:DEVIO:SWAP0", gain_aa, gain_ac);
if (err != BPM_CLIENT_SUCCESS){
fprintf (stderr, "[client:swap]: bpm_set_gain_d failed\n");
goto err_bpm_set;
......
......@@ -11,11 +11,19 @@
#define DFLT_BIND_FOLDER "/tmp/bpm"
#define DFLT_BPM_NUMBER 0
#define MAX_BPM_NUMBER 1
#define DFLT_BOARD_NUMBER 0
#define MAX_BOARD_NUMBER 5
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);
}
......@@ -23,7 +31,9 @@ int main (int argc, char *argv [])
{
int verbose = 0;
char *broker_endp = NULL;
char **str_p;
char *board_number_str = NULL;
char *bpm_number_str = NULL;
char **str_p = NULL;
if (argc < 2) {
print_help (argv[0]);
......@@ -44,6 +54,14 @@ int main (int argc, char *argv [])
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;
}
......@@ -58,6 +76,43 @@ 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:leds]: 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);
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 */
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];
sprintf (service, "BPM%u:DEVIO:FMC130M_4CH%u", board_number, bpm_number);
bpm_client_t *bpm_client = bpm_client_new (broker_endp, verbose, NULL);
for (i = 0; i < 32768; ++i) {
......@@ -68,15 +123,22 @@ int main (int argc, char *argv [])
break;
}
bpm_blink_leds (bpm_client, "BPM0:DEVIO:FMC130M_4CH", leds);
usleep (80000);
bpm_blink_leds (bpm_client, service, leds);
usleep (400000);
leds <<= 1;
}
}
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
*/
#include <mdp.h>
#include <czmq.h>
#include <inttypes.h>
#include <bpm_client.h>
#define DFLT_BIND_FOLDER "/tmp/bpm"
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);
}
int main (int argc, char *argv [])
{
int verbose = 0;
char *broker_endp = NULL;
char **str_p = NULL;
if (argc < 2) {
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], "-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);
}
bpm_client_t *bpm_client = bpm_client_new (broker_endp, verbose, NULL);
uint32_t monit_amp;
bpm_client_err_e err = bpm_get_monit_amp_ch0 (bpm_client, "BPM0:DEVIO:DSP0",
&monit_amp);
if (err != BPM_CLIENT_SUCCESS){
fprintf (stderr, "[client:acq]: bpm_get_monit_amp_ch0 failed\n");
goto err_get_monit_amp;
}
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);
if (err != BPM_CLIENT_SUCCESS){
fprintf (stderr, "[client:acq]: bpm_get_monit_amp_ch1 failed\n");
goto err_get_monit_amp;
}
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);
if (err != BPM_CLIENT_SUCCESS){
fprintf (stderr, "[client:acq]: bpm_get_monit_amp_ch2 failed\n");
goto err_get_monit_amp;
}
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);
if (err != BPM_CLIENT_SUCCESS){
fprintf (stderr, "[client:acq]: bpm_get_monit_amp_ch3 failed\n");
goto err_get_monit_amp;
}
fprintf (stdout, "[client:monit_amp]: monitoring amplitude ch3 = %u\n", monit_amp);
err_get_monit_amp:
bpm_client_destroy (&bpm_client);
str_p = &broker_endp;
free (*str_p);
broker_endp = NULL;
return 0;
}
/*
* Simple example demonstrating the communication between
* a client and the FPGA device
*/
#include <mdp.h>
#include <czmq.h>
#include <inttypes.h>
#include <bpm_client.h>
#define DFLT_BIND_FOLDER "/tmp/bpm"
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);
}
int main (int argc, char *argv [])
{
int verbose = 0;
char *broker_endp = NULL;
char **str_p = NULL;
if (argc < 2) {
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], "-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);
}
bpm_client_t *bpm_client = bpm_client_new (broker_endp, verbose, NULL);
uint32_t monit_pos;
bpm_client_err_e err = bpm_get_monit_pos_x (bpm_client, "BPM0:DEVIO:DSP0",
&monit_pos);
if (err != BPM_CLIENT_SUCCESS){
fprintf (stderr, "[client:acq]: bpm_get_monit_pos_x failed\n");
goto err_get_monit_pos;
}
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);
if (err != BPM_CLIENT_SUCCESS){
fprintf (stderr, "[client:acq]: bpm_get_monit_pos_y failed\n");
goto err_get_monit_pos;
}
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);
if (err != BPM_CLIENT_SUCCESS){
fprintf (stderr, "[client:acq]: bpm_get_monit_pos_q failed\n");
goto err_get_monit_pos;
}
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);
if (err != BPM_CLIENT_SUCCESS){
fprintf (stderr, "[client:acq]: bpm_get_monit_pos_sum failed\n");
goto err_get_monit_pos;
}
fprintf (stdout, "[client:monit_pos]: monitoring pos sum = %d\n", (int32_t) monit_pos);
err_get_monit_pos:
bpm_client_destroy (&bpm_client);
str_p = &broker_endp;
free (*str_p);
broker_endp = NULL;
return 0;
}
#!/bin/bash
EXPECTED_ARGS=5
DATAPLOT_FILE=".feedgnuplot_data"
DFLT_SLEEP_INTERV=2 # in seconds
if [ $# -lt $EXPECTED_ARGS ]
then
echo "Usage: `basename $0` {broker endpoint} {number of samples} {channel number} {board number} {bpm number} [sleep interval]"
exit 1;
fi
broker_endp=$1
nsamples=$2
ch_number=$3
board_number=$4
bpm_number=$5
if [ -z "$6" ]
then
sleep_interval=$DFLT_SLEEP_INTERV
else
sleep_interval=$6
fi
acquire_samples () {
if [ $# -lt 5 ]
then
echo "acquire_samples usage: {broker endpoint} {number of samples} {channel number} {board number} {bpm number} [sleep_interval]"
exit 1;
fi
while :
do
./acq -b $1 -s $2 -ch $3 -board $4 -bpm $5 > ${DATAPLOT_FILE}.$4.$5
sleep $6
done
}
plot_data () {
tail -n $1 -f ${DATAPLOT_FILE}.$2.$3 2> /dev/null |
feedgnuplot --lines \
--stream $4 \
--domain \
--title 'Data' \
--ylabel 'Counts [arb. units]' \
--xlabel 'Samples' \
--legend 0 'A' \
--legend 1 'B' \
--legend 2 'C' \
--legend 3 'D'
}
acquire_samples $broker_endp $nsamples $ch_number $board_number $bpm_number $sleep_interval &
sleep 2
plot_data $nsamples $board_number $bpm_number $sleep_interval
/*
* * Simple example demonstrating the communication between
* * a client and the FPGA device
* */
#include <mdp.h>
#include <czmq.h>
#include <inttypes.h>
#include <stdio.h>
#include <string.h>
#include <bpm_client.h>
#define DFLT_BIND_FOLDER "/tmp/bpm"
/* Default value definitions */
#define DFLT_BPM_NUMBER 0
#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
#define FUNC_RFFE_ATT2_IDX 2
#define FUNC_RFFE_SET_POINT1_IDX 3
#define FUNC_RFFE_SET_POINT2_IDX 4
#define FUNC_RFFE_TEMP_CONTROL_IDX 5
#define FUNC_RFFE_RESET_IDX 6
#define FUNC_RFFE_END 7
#define MAX_NUM_FUNCS FUNC_RFFE_END
/* Functions redeclaration for compatibility with double arguments */
bpm_client_err_e bpm_set_rffe_sw_double (bpm_client_t *self, char *service,
double rffe_sw)
{
return bpm_set_rffe_sw (self, service, (rffe_sw == 0.0) ? 0 : 1);
}
bpm_client_err_e bpm_set_rffe_temp_control_double (bpm_client_t *self, char *service,
double rffe_temp_control)
{
return bpm_set_rffe_temp_control (self, service,
(rffe_temp_control == 0.0) ? 0 : 1);
}
bpm_client_err_e bpm_set_rffe_reset_double (bpm_client_t *self, char *service,
double rffe_reset)
{
return bpm_set_rffe_reset (self, service, (rffe_reset == 0.0) ? 0 : 1);
}
/* Our dispatch table */
typedef bpm_client_err_e (*bpm_func_fp) (bpm_client_t *self, char *service,
double value);
static const bpm_func_fp bpm_rffe_funcs [MAX_NUM_FUNCS] = {
&bpm_set_rffe_sw_double, /* function "double" argument version */
&bpm_set_rffe_att1,
&bpm_set_rffe_att2,
&bpm_set_rffe_set_point1,
&bpm_set_rffe_set_point2,
&bpm_set_rffe_temp_control_double, /* function "double" argument version */
&bpm_set_rffe_reset_double, /* function "double" argument version */
};
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"
"\t-board <AMC board = [0|1|2|3|4|5]>\n"
"\t-bpm <BPM number = [0|1]>\n"
"\t-sw <on/off = [0|1]> Output switching\n"
"\t-att1 <on/off = [0 - 31.5 dB / 0.5 dB step]> Attenuator #1 value\n"
"\t-att2 <on/off = [0 - 31.5 dB / 0.5 dB step]> Attenuator #2 value\n"
#if 0
"\t-temp1 <Temperature sensor #1 value>\n"
"\t-temp2 <Temperature sensor #2 value>\n"
"\t-temp3 <Temperature sensor #3 value>\n"
"\t-temp4 <Temperature sensor #4 value>\n"
#endif
"\t-set_point1 <set point = [ambient temp. - 60.0 oC]> Set point #1\n"
"\t-set_point2 <set point = [ambient temp. - 60.0 oC]> Set point #2\n"
"\t-temp_control <on/off = [0|1]> Temperature control\n"
"\t-reset <on/off = [0|1]> Reset\n"
#if 0
"\t-version <RFFE software version>\n"
#endif
, program_name);
}
typedef struct _func_call_t {
int call;
char **arg;
} func_call_t;
int main (int argc, char *argv [])
{
int verbose = 0;
char *broker_endp = NULL;
char *board_number_str = NULL;
char *bpm_number_str = NULL;
char *sw_str = NULL;
char *att1_str = NULL;
char *att2_str = NULL;
char *set_point1_str = NULL;
char *set_point2_str = NULL;
char *temp_control_str = NULL;
char *reset_str = NULL;
func_call_t func_call [MAX_NUM_FUNCS] = {{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], "-b")) {
str_p = &broker_endp;
}
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], "-sw")) { /* sw: switching value */
func_call [FUNC_RFFE_SW_IDX].call = 1;
func_call [FUNC_RFFE_SW_IDX].arg = &sw_str;
str_p = &sw_str;
}
else if (streq (argv[i], "-att1")) { /* att1: attenuator value */
func_call [FUNC_RFFE_ATT1_IDX].call = 1;
func_call [FUNC_RFFE_ATT1_IDX].arg = &att1_str;
str_p = &att1_str;
}
else if (streq (argv[i], "-att2")) { /* att2: attenuator value */
func_call [FUNC_RFFE_ATT2_IDX].call = 1;
func_call [FUNC_RFFE_ATT2_IDX].arg = &att2_str;
str_p = &att2_str;
}
else if (streq (argv[i], "-set_point1")) { /* set_point1: temperature set point value */
func_call [FUNC_RFFE_SET_POINT1_IDX].call = 1;
func_call [FUNC_RFFE_SET_POINT1_IDX].arg = &set_point1_str;
str_p = &set_point1_str;
}
else if (streq (argv[i], "-set_point2")) { /* set_point2: Temperature set value */
func_call [FUNC_RFFE_SET_POINT2_IDX].call = 1;
func_call [FUNC_RFFE_SET_POINT2_IDX].arg = &set_point2_str;
str_p = &set_point2_str;
}
else if (streq (argv[i], "-temp_control")) { /* temp_control: on/off */
func_call [FUNC_RFFE_TEMP_CONTROL_IDX].call = 1;
func_call [FUNC_RFFE_TEMP_CONTROL_IDX].arg = &temp_control_str;
str_p = &temp_control_str;
}
else if (streq (argv[i], "-reset")) { /* reset: on/off */
func_call [FUNC_RFFE_RESET_IDX].call = 1;
func_call [FUNC_RFFE_RESET_IDX].arg = &reset_str;
str_p = &reset_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:rffe]: 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);
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 */
uint32_t bpm_number;
if (bpm_number_str == NULL) {
fprintf (stderr, "[client:rffe]: 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:rffe]: BPM number too big! Defaulting to: %u\n",
MAX_BPM_NUMBER);
bpm_number = MAX_BPM_NUMBER;
}
}
char service[50];
sprintf (service, "BPM%u:DEVIO:RFFE%u", board_number, bpm_number);
bpm_client_t *bpm_client = bpm_client_new (broker_endp, verbose, NULL);
for (i = 0; i < MAX_NUM_FUNCS; ++i) {
if (func_call [i].call == 1) {
fprintf (stdout, "[client:rffe_ctl]: Calling function #%d\n", i);
fprintf (stdout, "[client:rffe_ctl]: Argument: %f\n", strtod (*func_call [i].arg, NULL));
bpm_client_err_e err = bpm_rffe_funcs [i]
(bpm_client, service, strtod (*func_call [i].arg, NULL));
if (err != BPM_CLIENT_SUCCESS) {
fprintf (stderr, "[client:rffe_ctl]: Error executing remote "
"function: %s\n", bpm_client_err_str (err));
}
}
}
bpm_client_destroy (&bpm_client);
/* ugly... */
free (sw_str);
free (att1_str);
free (att2_str);
free (set_point1_str);
free (set_point2_str);
free (temp_control_str);
free (reset_str);
free (bpm_number_str);
free (broker_endp);
return 0;
}
/*
* Simple example demonstrating the communication between
* a client and the FPGA device
*/
#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
#define MAX_BOARD_NUMBER 5
#define DFLT_SI571_FREQ 100000000.000 /* 100 MHz */
#define MAX_SI571_FREQ 1000000000.000 /* 1GHz */
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-freq <frequency> Si571 frequency\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 *si571_freq_str = NULL;
char **str_p = NULL;
if (argc < 2) {
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], "-freq"))
{
str_p = &si571_freq_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:si571_ctl]: 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);
if (board_number > MAX_BOARD_NUMBER) {
fprintf (stderr, "[client:si571_ctl]: BOARD number too big! Defaulting to: %u\n",
MAX_BOARD_NUMBER);
board_number = MAX_BOARD_NUMBER;
}
}
/* Set default bpm number */
uint32_t bpm_number;
if (bpm_number_str == NULL) {
fprintf (stderr, "[client:si571_ctl]: 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:si571_ctl]: BPM number too big! Defaulting to: %u\n",
MAX_BPM_NUMBER);
bpm_number = MAX_BPM_NUMBER;
}
}
/* Set default frequency */
double si571_freq;
if (si571_freq_str == NULL) {
fprintf (stderr, "[client:si571_ctl]: Setting default value to BPM number: %f\n",
DFLT_SI571_FREQ);
si571_freq = DFLT_SI571_FREQ;
}
else {
si571_freq = strtod (si571_freq_str, NULL);
if (si571_freq > MAX_SI571_FREQ) {
fprintf (stderr, "[client:si571_ctl]: BPM number too big! Defaulting to: %f\n",
MAX_SI571_FREQ);
si571_freq = MAX_SI571_FREQ;
}
}
char service[50];
sprintf (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_set_si571_set_freq (bpm_client, service, si571_freq);
if (err != BPM_CLIENT_SUCCESS){
fprintf (stderr, "[client:si571_ctl]: Si571 Set frequency failed\n");
goto err_bpm_set_freq;
}
err_bpm_set_freq:
bpm_client_destroy (&bpm_client);
str_p = &si571_freq_str;
free (*str_p);
si571_freq_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 <mdp.h>
#include <czmq.h>
#include <inttypes.h>
#include <bpm_client.h>
#define DFLT_BIND_FOLDER "/tmp/bpm"
#define DFLT_TEST_DATA_EN 0
#define MAX_TEST_DATA_EN 1
#define DFLT_BPM_NUMBER 0
#define MAX_BPM_NUMBER 1
#define DFLT_BOARD_NUMBER 0
#define MAX_BOARD_NUMBER 5
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-e <[0|1]> Enable or disable TEST data\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 *test_data_en_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], "-e")) {
str_p = &test_data_en_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:leds]: 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);
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 */
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;
}
}
/* Set test data enable default */
uint32_t test_data_en;
if (test_data_en_str == NULL) {
fprintf (stderr, "[client:test_data_en]: Setting test DATA enable to 0\n");
test_data_en = DFLT_TEST_DATA_EN;
}
else {
test_data_en = strtoul (test_data_en_str, NULL, 10);
if (test_data_en > MAX_TEST_DATA_EN) {
fprintf (stderr, "[client:test_data_en]: Test data enable value too big! Defaulting to: %u\n",
MAX_TEST_DATA_EN);
test_data_en = MAX_TEST_DATA_EN;
}
}
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);
bpm_client_t *bpm_client = bpm_client_new (broker_endp, verbose, NULL);
/* Test data enable */
bpm_set_adc_test_data_en (bpm_client, service, test_data_en);
/* Cleanup */
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 = &test_data_en_str;
free (*str_p);
test_data_en_str = NULL;
str_p = &broker_endp;
free (*str_p);
broker_endp = NULL;
return 0;
}
Subproject commit bd1eb1ec1104f4b4cbe796ce07a003440105b265
File moved
Subproject commit 041e31e89785f01e71d4c06a191bbe035de4a478
#ifndef _BOARD_H_
#define _BOARD_H_
#include "board/afcv3/defs.h"
/****************************/
/* General Definitions */
/****************************/
/* CPU Clock frequency in hertz */
#define SYS_CLOCK 100000000ULL
/* Baud rate of the builtin UART (does not apply to the VUART) */
#define UART_BAUDRATE 115200ULL
int board_init();
int board_update();
#endif
#ifndef _BOARD_H_
#define _BOARD_H_
#include <mem_layout/ml605/mem_layout.h>
#include <board/ml605/defs.h>
/****************************/
/* General Definitions */
/* General Definitions */
/****************************/
/* CPU Clock frequency in hertz */
#define CPU_CLOCK 100000000ULL
#define SYS_CLOCK 100000000ULL
/* Baud rate of the builtin UART (does not apply to the VUART) */
#define UART_BAUDRATE 115200ULL
......
......@@ -12,6 +12,8 @@
#include "debug_print.h"
#include "local_print.h"
#define DBE_PRINT_PAD_FMT "-5"
/* Our logfile */
static FILE *_debug_logfile = NULL;
......@@ -40,7 +42,8 @@ static void _debug_log_write (char *dbg_lvl_str, char *msg)
strftime (date, 20, "%y-%m-%d %H:%M:%S", loctime);
char log_text [1024];
snprintf (log_text, 1024, "%s: [%s] %s", dbg_lvl_str, date, msg);
snprintf (log_text, 1024, "%" DBE_PRINT_PAD_FMT "s: [%s] %s",
dbg_lvl_str, date, msg);
fprintf (_debug_logfile, "%s", log_text);
fflush (_debug_logfile);
}
......@@ -90,7 +93,7 @@ void debug_set_log_file (FILE *log_file)
_debug_set_log_file (log_file);
}
int debug_set_log (const char *log_file_name)
int debug_set_log (const char *log_file_name, const char *mode)
{
int err = -1; /* Error */
FILE *log_file = NULL;
......@@ -105,7 +108,14 @@ int debug_set_log (const char *log_file_name)
err = 2;
}
else {
log_file = fopen (log_file_name, "w");
if (mode == NULL) {
/* Be conservative if no mode is specified */
log_file = fopen (log_file_name, "a");
}
else {
log_file = fopen (log_file_name, mode);
}
err = 0;
if (log_file == NULL) {
......
......@@ -22,7 +22,7 @@ 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);
int debug_set_log (const char *log_file_name, const char *mode);
void debug_log_print_zmq_msg (struct _zmsg_t *msg);
/********************** Debug macros **********************/
......
......@@ -34,6 +34,8 @@
#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)
......@@ -43,6 +45,8 @@
#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 ******************/
/*
......
This diff is collapsed.
#ifndef _DEV_IO_
#define _DEV_IO_
#ifndef _DEV_BE_IO_
#define _DEV_BE_IO_
#include "dev_io_core.h"
#include "dev_io_utils.h"
#endif
include hal/dev_io/utils/utils.mk
dev_io_DIR = hal/dev_io
# Here we call <output_name>_core_OBJS as we need to add
# more objects to this target. This is done in the hal.mk
# makefile
dev_io_core_OBJS = $(dev_io_DIR)/dev_io.o \
$(dev_io_DIR)/dev_io_core.o \
$(dev_io_DIR)/dev_io_err.o
dev_io_INCLUDE_DIRS = $(dev_io_DIR) $(LIBCLIENT_DIR)
dev_io_core_OBJS = $(dev_io_DIR)/dev_io_core.o \
$(dev_io_DIR)/dev_io_err.o \
$(dev_io_utils_OBJS)
dev_io_OBJS = $(dev_io_DIR)/dev_io.o
dev_io_INCLUDE_DIRS = $(dev_io_DIR) \
$(dev_io_utils_INCLUDE_DIRS) \
$(LIBCLIENT_DIR)
dev_io_OUT = dev_io
dev_io_all_OUT = $(dev_io_OUT)
This diff is collapsed.
......@@ -24,8 +24,6 @@
#define SMIO_HKEY_LEN 8
#define NODES_MAX_LEN 20
struct _smio_thsafe_server_ops_t;
struct _devio_t {
/* General information */
/*mdp_worker_t *worker;*/ /* zeroMQ Majordomo Worker */
......@@ -44,7 +42,7 @@ struct _devio_t {
/* Server part of the llio operations. This is the bridge between the
* smio client part of the llio operations and the de-facto
* llio operations */
const struct _smio_thsafe_server_ops_t *thsafe_server_ops;
const disp_op_t **thsafe_server_ops;
/* Hash containg all the sm_io objects that
* this dev_io can handle. It is composed
* of key (10-char ID) / value (sm_io instance) */
......@@ -94,11 +92,12 @@ devio_err_e devio_destroy (devio_t **self_p);
* this is stored in the SDB structure inside the device */
devio_err_e devio_print_info (devio_t *self);
/* Register an specific sm_io module to this device */
devio_err_e devio_register_sm (devio_t *self, uint32_t smio_id, void *priv);
devio_err_e devio_register_sm (devio_t *self, uint32_t smio_id, uint32_t base,
uint32_t inst_id);
/* Register all sm_io module that this device can handle,
* according to the device information stored in the SDB */
devio_err_e devio_register_all_sm (devio_t *self);
devio_err_e devio_unregister_sm (devio_t *self, uint32_t smio_id);
devio_err_e devio_unregister_sm (devio_t *self, uint32_t smio_id, uint32_t inst_id);
devio_err_e devio_unregister_all_sm (devio_t *self);
/* Initilize poller with all of the initialized PIPE sockets */
devio_err_e devio_init_poller_sm (devio_t *self);
......@@ -114,26 +113,26 @@ devio_err_e devio_do_smio_op (devio_t *self, void *msg);
/********* Low-level generic methods API *********/
/* Open device */
void *smio_thsafe_server_open (void *owner, void *args);
int smio_thsafe_server_open (void *owner, void *args, void *ret);
/* Release device */
void *smio_thsafe_server_release (void *owner, void *args);
int smio_thsafe_server_release (void *owner, void *args, void *ret);
/* Read data from device */
void *smio_thsafe_server_read_16 (void *owner, void *args);
void *smio_thsafe_server_read_32 (void *owner, void *args);
void *smio_thsafe_server_read_64 (void *owner, void *args);
int smio_thsafe_server_read_16 (void *owner, void *args, void *ret);
int smio_thsafe_server_read_32 (void *owner, void *args, void *ret);
int smio_thsafe_server_read_64 (void *owner, void *args, void *ret);
/* Write data to device */
void *smio_thsafe_server_write_16 (void *owner, void *args);
void *smio_thsafe_server_write_32 (void *owner, void *args);
void *smio_thsafe_server_write_64 (void *owner, void *args);
int smio_thsafe_server_write_16 (void *owner, void *args, void *ret);
int smio_thsafe_server_write_32 (void *owner, void *args, void *ret);
int smio_thsafe_server_write_64 (void *owner, void *args, void *ret);
/* Read data block from device, size in bytes */
void *smio_thsafe_server_read_block (void *owner, void *args);
int smio_thsafe_server_read_block (void *owner, void *args, void *ret);
/* Write data block from device, size in bytes */
void *smio_thsafe_server_write_block (void *owner, void *args);
int smio_thsafe_server_write_block (void *owner, void *args, void *ret);
/* Read data block via DMA from device, size in bytes */
void *smio_thsafe_server_read_dma (void *owner, void *args);
int smio_thsafe_server_read_dma (void *owner, void *args, void *ret);
/* Write data block via DMA from device, size in bytes */
void *smio_thsafe_server_write_dma (void *owner, void *args);
int smio_thsafe_server_write_dma (void *owner, void *args, void *ret);
/* Read device information */
/* void *smio_thsafe_server_read_info (void *owner, void *args); */
/* int smio_thsafe_server_read_info (void *owner, void *args, void *ret); */
#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 _DEV_IO_EXPORTS_H_
#define _DEV_IO_EXPORTS_H_
#include "smio_thsafe_zmq_server.h"
#define DEVIO_OWNER_TYPE devio_t
#define DEVIO_EXP_OWNER(owner) ((devio_t *) owner)
#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.
*/
#include "dev_io_utils.h"
#include "ll_io_utils.h"
#include "hal_assert.h"
/* Undef ASSERT_ALLOC to avoid conflicting with other ASSERT_ALLOC */
#ifdef ASSERT_TEST
#undef ASSERT_TEST
#endif
#define ASSERT_TEST(test_boolean, err_str, err_goto_label, /* err_core */ ...) \
ASSERT_HAL_TEST(test_boolean, DEV_IO, "[dev_io:utils]", \
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_IO, "[dev_io:utils]", \
devio_err_str(DEVIO_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_IO, "[dev_io:utils]", \
devio_err_str (err_type))
/************** Utility functions ****************/
static const llio_types_t devio_types_map [] = {
{.name = BE_DEVIO_STR, .type = BE_DEVIO},
{.name = FE_DEVIO_STR, .type = FE_DEVIO},
{.name = INVALID_DEVIO_STR, .type = INVALID_DEVIO},
{.name = LLIO_TYPE_NAME_END, .type = LLIO_TYPE_END} /* End marker */
};
devio_type_e devio_str_to_type (const char *type_str)
{
devio_type_e ret = llio_str_to_gen_type (type_str, devio_types_map);
return (ret == LLIO_TYPE_END)? INVALID_DEVIO: ret;
}
char *devio_type_to_str (devio_type_e type)
{
return llio_gen_type_to_str (type, devio_types_map);
}
/*
* 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 _DEV_IO_UTILS_H_
#define _DEV_IO_UTILS_H_
#include <inttypes.h>
/* Device type */
enum _devio_type_e {
BE_DEVIO = 0, /* Back-End DEVIO */
FE_DEVIO, /* Front-End DEVIO */
INVALID_DEVIO
};
typedef enum _devio_type_e devio_type_e;
#define BE_DEVIO_STR "be"
#define FE_DEVIO_STR "fe"
#define INVALID_DEVIO_STR "invalid"
devio_type_e devio_str_to_type (const char *type_str);
char *devio_type_to_str (devio_type_e type);
#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)
This diff is collapsed.
......@@ -3,10 +3,20 @@ dev_mngr_DIR = hal/dev_mngr
# Here we call <output_name>_core_OBJS as we need to add
# more objects to this target. This is done in the hal.mk
# makefile
dev_mngr_core_OBJS = $(dev_mngr_DIR)/dev_mngr.o \
$(dev_mngr_DIR)/dev_mngr_core.o \
dev_mngr_core_OBJS = $(dev_mngr_DIR)/dev_mngr_core.o \
$(dev_mngr_DIR)/dev_mngr_err.o \
$(dev_mngr_DIR)/dev_mngr_dev_info.o
dev_mngr_INCLUDE_DIRS = $(dev_mngr_DIR)
# Compile Digital Back-End DEVIO
ifeq ($(WITH_DEV_MNGR),y)
dev_mngr_OBJS = $(dev_mngr_DIR)/dev_mngr.o
dev_mngr_OUT = dev_mngr
else
dev_mngr_OBJS =
dev_mngr_OUT =
endif
dev_mngr_INCLUDE_DIRS = $(dev_mngr_DIR)
dev_mngr_all_OUT = dev_mngr
This diff is collapsed.
......@@ -12,6 +12,15 @@
#include "dev_mngr_err.h"
#include "dev_mngr_dev_info.h"
/* Configuration variables. To be filled by dev_mngr */
extern const char *dmngr_log_filename;
extern char *dmngr_log_dir;
extern char *dmngr_broker_endp;
extern char *dmngr_verbose_str;
extern int dmngr_verbose;
extern char *dmngr_daemonize_str;
extern int dmngr_daemonize;
/* Signal handler function pointer */
typedef void (*sig_handler_fp)(int sig, siginfo_t *siginfo, void *context);
/* Wait child handler function pointer */
......@@ -48,10 +57,11 @@ struct _dmngr_t {
struct _dmngr_ops_t *ops;
/* zeroMQ broker management */
bool broker_running; /* true if broker is already running */
bool broker_running; /* true if broker is already running */
/* Device managment */
zhash_t *devio_info_h;
zhash_t *hints_h; /* Config hints from configuration file */
};
/* Opaque class signal handler structure */
......@@ -65,7 +75,7 @@ typedef struct _dmngr_t dmngr_t;
/* Creates a new instance of the Device Manager */
dmngr_t * dmngr_new (char *name, char *endpoint, int verbose,
const char *log_prefix);
const char *log_prefix, zhash_t *hints_h);
/* Destroy an instance of the Device Manager */
dmngr_err_e dmngr_destroy (dmngr_t **self_p);
......@@ -89,9 +99,12 @@ bool dmngr_is_broker_running (dmngr_t *self);
/* Spawn broker if not running */
dmngr_err_e dmngr_spawn_broker (dmngr_t *self, char *broker_endp);
/* Scan for Devices to control */
uint32_t dmngr_scan_devs (dmngr_t *self);
dmngr_err_e dmngr_scan_devs (dmngr_t *self, uint32_t *num_devs_found);
/* Spwan all devices previously found by dmngr_scan_devs () */
dmngr_err_e dmngr_spawn_all_devios (dmngr_t *self, char *broker_endp,
char *devio_log_filename, bool respawn_killed_devio);
/* Utility functions */
dmngr_err_e dmngr_get_hints (zconfig_t *root_cfg, zhash_t *hints_h);
#endif
......@@ -36,7 +36,7 @@
/* 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_state_e state)
devio_type_e devio_type, uint32_t smio_inst_id, devio_state_e state)
{
assert (dev_pathname);
......@@ -47,6 +47,8 @@ devio_info_t * devio_info_new (char *dev_pathname, uint32_t id, llio_type_e type
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;
......
......@@ -10,7 +10,8 @@
#include "czmq.h"
#include "dev_mngr_err.h"
#include "ll_io_utils.h" /* LLIO types */
#include "ll_io_utils.h" /* LLIO types */
#include "dev_io_utils.h" /* DEVIO types */
enum _devio_state_e {
INACTIVE = 0, /* Nothing found yet */
......@@ -23,6 +24,9 @@ enum _devio_state_e {
struct _devio_info_t {
uint32_t id; /* Device IO ID */
llio_type_e type; /* Device type */
devio_type_e devio_type; /* DEVIO type */
uint32_t smio_inst_id; /* Optional SMIO instance ID for DEVIOs
with a single SMIO */
char *dev_pathname; /* /dev pathname */
enum _devio_state_e state; /* Device IO state */
};
......@@ -31,7 +35,7 @@ typedef struct _devio_info_t devio_info_t;
typedef enum _devio_state_e devio_state_e;
devio_info_t * devio_info_new (char *dev_pathname, uint32_t id, llio_type_e type,
devio_state_e state);
devio_type_e devio_type, uint32_t smio_inst_id, devio_state_e state);
dmngr_err_e devio_info_destroy (devio_info_t **self_p);
#endif
......@@ -18,7 +18,8 @@ static const char *dmngr_err [DMNGR_ERR_END] =
[DMNGR_ERR_SIGACTION] = "Signal registration error",
[DMNGR_ERR_WAITCHLD] = "Could not complete wait child routine",
[DMNGR_ERR_SPAWNCHLD] = "Could not complete spawn child routine",
[DMNGR_ERR_BROK_RUNN] = "Broker already running"
[DMNGR_ERR_BROK_RUNN] = "Broker already running",
[DMNGR_ERR_CFG] = "Could not get property from config file"
};
/* Convert enumeration type to string */
......
......@@ -20,6 +20,7 @@ enum _dmngr_err_e
DMNGR_ERR_WAITCHLD, /* Wait child routine error */
DMNGR_ERR_SPAWNCHLD, /* Spawn child routine error */
DMNGR_ERR_BROK_RUNN, /* Broker already running error */
DMNGR_ERR_CFG, /* Could not get property from config file */
DMNGR_ERR_END /* End of enum marker */
};
......
# debug.mk must be declared before dev_mngr.mk, as they are variables
# exported by the former used by the latter
include hal/debug/debug.mk
include hal/hal_utils/hal_utils.mk
include hal/ll_io/ll_io.mk
include hal/sm_io/sm_io.mk
include hal/sdb/sdb.mk
include hal/dev_mngr/dev_mngr.mk
include hal/dev_io/dev_io.mk
include hal/msg/msg.mk
include hal/hal_utils/hal_utils.mk
include hal/boards/boards.mk
std_hal_INCLUDE_DIRS = hal/include \
hal/include/hw
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
dev_mngr_OBJS = $(dev_mngr_core_OBJS) $(debug_OBJS) \
$(hal_utils_OBJS) $(ll_io_utils_OBJS)
dev_io_OBJS = $(dev_io_core_OBJS) $(ll_io_OBJS) $(sm_io_OBJS) \
$(msg_OBJS) $(debug_OBJS) $(hal_utils_OBJS)
# 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_io_LIBS =
dev_mngr_STATIC_LIBS =
dev_io_LIBS = -lbsmp
dev_io_STATIC_LIBS = $(LIBCLIENT_DIR)/libbpmclient.a
# Merge all hal objects together
......
This diff is collapsed.
......@@ -5,6 +5,12 @@
* Released according to the GNU LGPL, version 3 or any later version.
*/
/* This is roughly based on the work of Alessandro Rubini and others
* "mini-rpc", located on "https://github.com/a-rubini/mini-rpc"
*
* In the end, I changed much of the original code and only the main
* idea with a couple of the original structures remain */
#ifndef _DISPATCH_TABLE_H_
#define _DISPATCH_TABLE_H_
......@@ -22,26 +28,81 @@ struct _disp_table_t {
typedef struct _disp_table_t disp_table_t;
/* Generic function pointer */
typedef void* (*disp_table_func_fp)(void *owner, void * args);
typedef int (*disp_table_func_fp)(void *owner, void * args, void *ret);
struct _func_fp_wrapper_t {
disp_table_func_fp func_fp;
/* Argument type (and retval type). The size is encoded in the same word */
enum _disp_at_e {
DISP_ATYPE_ERROR = 0xFF,
DISP_ATYPE_NONE = 0, /* used as terminator */
DISP_ATYPE_INT16 = 1,
DISP_ATYPE_UINT16,
DISP_ATYPE_INT32,
DISP_ATYPE_UINT32,
DISP_ATYPE_INT64,
DISP_ATYPE_UINT64,
DISP_ATYPE_DOUBLE, /* float is promoted to double */
DISP_ATYPE_STRING, /* size of strings is strlen() each time */
DISP_ATYPE_STRUCT,
DISP_ATYPE_VAR /* variable argument size. Allowed to be
up to the size of the encoded argument.
Typically a structure */
};
/* Opaque class structure */
typedef struct _func_fp_wrapper_t func_fp_wrapper_t;
typedef enum _disp_at_e disp_at_e;
/* FIXME: large arguments can overflow the macro!
* Encoding of argument type and size in one word */
#define __DISP_ARG_ENCODE(atype, asize) (((atype) << 24) | (asize))
#define DISP_ARG_ENCODE(atype, type) __DISP_ARG_ENCODE(atype, sizeof(type))
#define DISP_GET_ATYPE(word) ((word) >> 24)
#define DISP_GET_ASIZE(word) ((word) & 0xFFFFFF)
#define DISP_ARG_END __DISP_ARG_ENCODE(DISP_ATYPE_NONE, 0) /* zero */
enum _disp_val_owner_e {
DISP_OWNER_FUNC = 0, /* Value is owned by the function itself*/
DISP_OWNER_OTHER /* Value is owned by someone else and
must take care of allocations, if
necessary */
};
typedef enum _disp_val_owner_e disp_val_owner_e;
struct _disp_op_t {
const char *name; /* Function name */
uint32_t opcode; /* Operation code */
disp_table_func_fp func_fp; /* Pointer to exported function */
uint32_t retval; /* Type of return value */
disp_val_owner_e retval_owner; /* Who owns the return value */
void *ret; /* Buffer for function return value */
uint32_t args []; /* Zero-terminated */
};
/* Dispatch exported interface function structure */
typedef struct _disp_op_t disp_op_t;
/***************** Our methods *****************/
disp_table_t *disp_table_new (void);
halutils_err_e disp_table_destroy (disp_table_t **self_p);
halutils_err_e disp_table_insert (disp_table_t *self, uint32_t key,
disp_table_func_fp func_fp);
halutils_err_e disp_table_insert_all (disp_table_t *self, const disp_table_func_fp *disp_table_fp,
const uint32_t *code_table, uint32_t size);
halutils_err_e disp_table_insert (disp_table_t *self, const disp_op_t *disp_op);
halutils_err_e disp_table_insert_all (disp_table_t *self,
const disp_op_t **disp_ops);
halutils_err_e disp_table_remove (disp_table_t *self, uint32_t key);
halutils_err_e disp_table_remove_all (disp_table_t *self);
void *disp_table_call (disp_table_t *self, uint32_t key, void *owner, void *args);
halutils_err_e disp_table_fill_desc (disp_table_t *self, disp_op_t **disp_ops,
const disp_table_func_fp *func_fps);
halutils_err_e disp_table_check_args (disp_table_t *self, uint32_t key,
void *args, void **ret);
halutils_err_e disp_table_cleanup_args (disp_table_t *self, uint32_t key);
disp_op_t *disp_table_lookup (disp_table_t *self, uint32_t key);
int disp_table_call (disp_table_t *self, uint32_t key, void *owner, void *args,
void *ret);
int disp_table_check_call (disp_table_t *self, uint32_t key, void *owner,
void *args, void **ret);
halutils_err_e disp_table_set_ret (disp_table_t *self, uint32_t key, void **ret);
#endif
/*
* Copyright (C) 2014 LNLS (www.lnls.br)
* Author: Lucas Russo <lucas.russo@lnls.br>
*
* Released according to the GNU LGPL, version 3 or any later version.
*/
#include "hal_math.h"
#include <inttypes.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:math]", \
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:math]", \
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:math]", \
halutils_err_str (err_type))
static uint64_t _div_u64_rem (uint64_t dividend, uint32_t divisor,
uint32_t *remainder);
/* Cuts from Linux kernel */
uint64_t div_u64_rem (uint64_t dividend, uint32_t divisor,
uint32_t *remainder)
{
return _div_u64_rem (dividend, divisor, remainder);
}
uint64_t div_u64 (uint64_t dividend, uint32_t divisor)
{
uint32_t remainder;
return div_u64_rem (dividend, divisor, &remainder);
}
uint64_t div64_u64 (uint64_t dividend, uint64_t divisor)
{
return dividend / divisor;
}
int64_t div64_s64 (int64_t dividend, int64_t divisor)
{
return dividend / divisor;
}
/***************************** Static Functions ******************************/
static uint64_t _div_u64_rem (uint64_t dividend, uint32_t divisor,
uint32_t *remainder)
{
*remainder = dividend % divisor;
return dividend / divisor;
}
/*
* 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_MATH_H_
#define _HAL_MATH_H_
#include <math.h>
#include <inttypes.h>
#define POW_2_28 268435456.0
#define FLOORF(value) floorf (value)
#define CEILF(value) ceilf (value)
#define FLOOR(value) floor (value)
#define CEIL(value) ceil (value)
uint64_t div_u64_rem (uint64_t dividend, uint32_t divisor,
uint32_t *remainder);
uint64_t div_u64 (uint64_t dividend, uint32_t divisor);
uint64_t div64_u64 (uint64_t dividend, uint64_t divisor);
int64_t div64_s64 (int64_t dividend, int64_t divisor);
#endif
......@@ -35,6 +35,9 @@
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;
......@@ -86,15 +89,41 @@ char *halutils_stringify_hex_key (uint32_t key)
}
#define SEPARATOR_BYTES 1
char *halutils_concat_strings (const char *str1, const char* str2, char sep)
/* FIXME: poorly written */
static char *_halutils_concat_strings_raw (const char *str1, const char* str2,
const char *str3, char sep)
{
char *str = zmalloc (strlen(str1) + strlen(str2) +
SEPARATOR_BYTES /* separator length */+ 1 /* \0 */);
ASSERT_ALLOC(str, err_str_alloc);
sprintf (str, "%s%c%s", str1, sep, str2);
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_str_alloc:
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);
}
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.
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.
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