Commit aaa0dd79 authored by Lucas Russo's avatar Lucas Russo

hal/dev_io/*: merge dev_io_be and dev_io_fe back a single one

This makes it easier to maintain, reduces the amount of
code duplication and allow to make more generic code to
instantiate different types of DEVIOs
parent b877a247
......@@ -4,25 +4,29 @@
#include <unistd.h>
#include "czmq.h"
#include "dev_io_be.h"
#include "dev_io.h"
#include "debug_print.h"
#include "ll_io_utils.h"
#include "board.h"
#define DEVIO_SERVICE_LEN 50
static devio_err_e spwan_platform_smios (devio_t *devio);
static devio_err_e _spawn_platform_smios (devio_t *devio, devio_type_e devio_type,
uint32_t smio_inst_id);
static devio_err_e _spawn_be_platform_smios (devio_t *devio);
static devio_err_e _spawn_fe_platform_smios (devio_t *devio, uint32_t smio_inst_id);
void print_help (char *program_name)
{
printf( "DBE BPM Device I/O\n"
printf( "BPM Device I/O\n"
"Usage: %s [options]\n"
"\t-h This help message\n"
"\t-d Daemon mode.\n"
"\t-v Verbose output\n"
"\t-t <device_type> Device type\n"
"\t-e <dev_entry> Device /dev entry\n"
"\t-n <devio_type = [be|fe]> Devio type\n"
"\t-t <device_type = [eth|pcie]> Device type\n"
"\t-e <dev_entry = [ip_addr|/dev entry]> Device entry\n"
"\t-i <dev_id> Device ID\n"
"\t-s <fe_smio_id> FE SMIO ID (only valid for devio_type = fe)\n"
"\t-l <log_filename> Log filename\n"
"\t-b <broker_endpoint> Broker endpoint\n", program_name);
}
......@@ -31,10 +35,11 @@ int main (int argc, char *argv[])
{
int verbose = 0;
int daemonize = 0;
char *devio_type_str = NULL;
char *dev_type = NULL;
char *dev_entry = NULL;
char *dev_id_str = NULL;
uint32_t dev_id = 0;
char *fe_smio_id_str = NULL;
char *broker_endp = NULL;
char *log_file_name = NULL;
char **str_p = NULL;
......@@ -58,6 +63,10 @@ int main (int argc, char *argv[])
daemonize = 1;
DBE_DEBUG (DBG_DEV_IO | DBG_LVL_TRACE, "[dev_io] Demonize mode set\n");
}
else if (streq (argv[i], "-n")) {
str_p = &devio_type_str;
DBE_DEBUG (DBG_DEV_IO | DBG_LVL_TRACE, "[dev_io] Will set devio_type parameter\n");
}
else if (streq (argv[i], "-t")) {
str_p = &dev_type;
DBE_DEBUG (DBG_DEV_IO | DBG_LVL_TRACE, "[dev_io] Will set dev_type parameter\n");
......@@ -70,6 +79,10 @@ int main (int argc, char *argv[])
str_p = &dev_id_str;
DBE_DEBUG (DBG_DEV_IO | DBG_LVL_TRACE, "[dev_io] Will set dev_id_str parameter\n");
}
else if (streq (argv[i], "-s")) {
str_p = &fe_smio_id_str;
DBE_DEBUG (DBG_DEV_IO | DBG_LVL_TRACE, "[dev_io] Will set fe_smio_id_str parameter\n");
}
else if (streq (argv[i], "-b")) {
str_p = &broker_endp;
DBE_DEBUG (DBG_DEV_IO | DBG_LVL_TRACE, "[dev_io] Will set broker_endp parameter\n");
......@@ -108,22 +121,42 @@ int main (int argc, char *argv[])
goto err_exit;
}
devio_type_e devio_type = devio_str_to_type (devio_type_str);
/* Parse command-line options */
if (devio_type == INVALID_DEVIO) {
DBE_DEBUG (DBG_DEV_IO | DBG_LVL_FATAL, "[dev_io] Devio_type parameter is invalid\n");
goto err_exit;
}
/* Check for device entry */
if (dev_entry == NULL) {
DBE_DEBUG (DBG_DEV_IO | DBG_LVL_INFO, "[dev_io] Dev_entry parameter was not set. Exiting ...\n");
goto err_exit;
}
uint32_t dev_id = 0;
/* Check for device ID */
if (dev_id_str == NULL) {
DBE_DEBUG (DBG_DEV_IO | DBG_LVL_INFO, "[dev_io] Dev_id parameter was not set.\n"
"\tDefaulting it to the /dev file number ...\n");
int matches = sscanf (dev_entry, "/dev/fpga%u", &dev_id);
if (matches == 0) {
DBE_DEBUG (DBG_DEV_IO | DBG_LVL_FATAL, "[dev_io] Dev_entry parameter is invalid.\n"
"\tIt must be in the format \"/dev/fpga<device_number>\". Exiting ...\n");
goto err_exit;
switch (llio_type) {
case ETH_DEV:
DBE_DEBUG (DBG_DEV_IO | DBG_LVL_INFO, "[dev_io] Dev_id parameter was not set. Exiting ...\n");
goto err_exit;
break;
case PCIE_DEV:
DBE_DEBUG (DBG_DEV_IO | DBG_LVL_INFO, "[dev_io] Dev_id parameter was not set.\n"
"\tDefaulting it to the /dev file number ...\n");
int matches = sscanf (dev_entry, "/dev/fpga%u", &dev_id);
if (matches == 0) {
DBE_DEBUG (DBG_DEV_IO | DBG_LVL_FATAL, "[dev_io] Dev_entry parameter is invalid.\n"
"\tIt must be in the format \"/dev/fpga<device_number>\". Exiting ...\n");
goto err_exit;
}
default:
DBE_DEBUG (DBG_DEV_IO | DBG_LVL_INFO, "[dev_io] Dev_id parameter was not set. Exiting ...\n");
goto err_exit;
}
}
/* Use the passed ID */
......@@ -131,6 +164,16 @@ int main (int argc, char *argv[])
dev_id = strtoul (dev_id_str, NULL, 10);
}
uint32_t fe_smio_id = 0;
/* Check for FE SMIO ID */
if (devio_type == FE_DEVIO && fe_smio_id_str == NULL) {
DBE_DEBUG (DBG_DEV_IO | DBG_LVL_INFO, "[dev_io] Fe_smio_id parameter was not set. Exiting ...\n");
goto err_exit;
}
else {
fe_smio_id = strtoul (fe_smio_id_str, NULL, 10);
}
DBE_DEBUG (DBG_DEV_IO | DBG_LVL_INFO, "[dev_io] Dev_id parameter was set to %u.\n",
dev_id);
......@@ -166,9 +209,9 @@ int main (int argc, char *argv[])
free (*str_p);
broker_endp = NULL;
devio_err_e err = spwan_platform_smios (devio);
devio_err_e err = _spawn_platform_smios (devio, devio_type, fe_smio_id);
if (err != DEVIO_SUCCESS) {
DBE_DEBUG (DBG_DEV_IO | DBG_LVL_FATAL, "[dev_io] spwan_platform_smios error!\n");
DBE_DEBUG (DBG_DEV_IO | DBG_LVL_FATAL, "[dev_io] _spawn_platform_smios error!\n");
goto err_devio;
}
......@@ -206,20 +249,50 @@ err_exit:
free (*str_p);
str_p = &dev_type;
free (*str_p);
str_p = &devio_type_str;
free (*str_p);
return 0;
}
static devio_err_e spwan_platform_smios (devio_t *devio)
static devio_err_e _spawn_platform_smios (devio_t *devio, devio_type_e devio_type,
uint32_t smio_inst_id)
{
assert (devio);
devio_err_e err = DEVIO_SUCCESS;
switch (devio_type) {
case BE_DEVIO:
err = _spawn_be_platform_smios (devio);
break;
case FE_DEVIO:
err = _spawn_fe_platform_smios (devio, smio_inst_id);
break;
default:
/* FIXME: increase the error clarity? */
err = DEVIO_ERR_NO_SMIO_ID;
}
if (err != DEVIO_SUCCESS) {
DBE_DEBUG (DBG_DEV_IO | DBG_LVL_FATAL, "[dev_io] devio_register_sm error!\n");
goto err_register_sm;
}
err_register_sm:
return err;
}
static devio_err_e _spawn_be_platform_smios (devio_t *devio)
{
uint32_t fmc130m_4ch_id = 0x7085ef15;
uint32_t acq_id = 0x4519a0ad;
uint32_t dsp_id = 0x1bafbf1e;
uint32_t swap_id = 0x12897592;
devio_err_e err;
devio_err_e err = DEVIO_SUCCESS;
/* ML605 or AFCv3 */
/* ML605 or AFCv3 */
#if defined (__BOARD_ML605__) || defined (__BOARD_AFCV3__)
DBE_DEBUG (DBG_DEV_IO | DBG_LVL_INFO, "[dev_io] Spawning default SMIOs ...\n");
err = devio_register_sm (devio, fmc130m_4ch_id, FMC1_130M_BASE_ADDR, 0);
......@@ -274,10 +347,31 @@ static devio_err_e spwan_platform_smios (devio_t *devio)
}
#endif
#else
#error "Board not supported!"
#error "BE FPGA Board not supported!"
#endif
err_register_sm:
return err;
}
static devio_err_e _spawn_fe_platform_smios (devio_t *devio, uint32_t smio_inst_id)
{
uint32_t rffe_id = 0x7af21909;
devio_err_e err = DEVIO_SUCCESS;
/* RFFE V2 only */
/* #if defined (__AFE_RFFE_V1__) */
#if defined (__AFE_RFFE_V2__)
DBE_DEBUG (DBG_DEV_IO | DBG_LVL_INFO, "[dev_io_fe] Spawning default SMIOs ...\n");
err = devio_register_sm (devio, rffe_id, 0, smio_inst_id);
if (err != DEVIO_SUCCESS) {
DBE_DEBUG (DBG_DEV_IO | DBG_LVL_FATAL, "[dev_io_fe] devio_register_sm error!\n");
goto err_register_sm;
}
#else
#error "FE RFFE Board not supported!"
#endif
err_register_sm:
return err;
}
......@@ -2,5 +2,6 @@
#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_core.o \
$(dev_io_DIR)/dev_io_err.o
$(dev_io_DIR)/dev_io_err.o \
$(dev_io_utils_OBJS)
# Compile Digital Back-End DEVIO
ifeq ($(WITH_DBE_DEVIO),y)
dev_io_be_OBJS = $(dev_io_DIR)/dev_io_be.o
dev_io_be_OUT = dev_io_be
else
dev_io_be_OBJS =
dev_io_be_OUT =
endif
dev_io_OBJS = $(dev_io_DIR)/dev_io.o
# Compile Analog Front-End DEVIO
ifeq ($(WITH_AFE_DEVIO),y)
dev_io_fe_OBJS = $(dev_io_DIR)/dev_io_fe.o
dev_io_fe_OUT = dev_io_fe
else
dev_io_fe_OBJS =
dev_io_fe_OUT =
endif
dev_io_INCLUDE_DIRS = $(dev_io_DIR) \
$(dev_io_utils_INCLUDE_DIRS) \
$(LIBCLIENT_DIR)
dev_io_OBJS = $(dev_io_be_OBJS) $(dev_io_fe_OBJS)
dev_io_INCLUDE_DIRS = $(dev_io_DIR) $(LIBCLIENT_DIR)
dev_io_OUT = dev_io
# All possible DEVIO objects. Used for cleaning
dev_io_all_OUT = dev_io_be dev_io_fe
dev_io_all_OUT = $(dev_io_OUT)
# Specified target DEVIOs
dev_io_OUT = $(dev_io_be_OUT) $(dev_io_fe_OUT)
#include <unistd.h>
#include <stdio.h>
#include <sys/types.h> /* getpid, getppid */
#include <unistd.h>
#include "czmq.h"
#include "dev_io_fe.h"
#include "debug_print.h"
#include "ll_io_utils.h"
#include "board.h"
#define DEVIO_SERVICE_LEN 50
static devio_err_e spwan_platform_smios (devio_t *devio);
void print_help (char *program_name)
{
printf( "RFFE BPM Device I/O\n"
"Usage: %s [options]\n"
"\t-h This help message\n"
"\t-d Daemon mode.\n"
"\t-v Verbose output\n"
"\t-t <device_type> Device type\n"
"\t-e <dev_entry> Device /dev entry\n"
"\t-i <dev_id> Device ID\n"
"\t-l <log_filename> Log filename\n"
"\t-b <broker_endpoint> Broker endpoint\n", program_name);
}
int main (int argc, char *argv[])
{
int verbose = 0;
int daemonize = 0;
char *dev_type = NULL;
char *dev_entry = NULL;
char *dev_id_str = NULL;
uint32_t dev_id = 0;
char *broker_endp = NULL;
char *log_file_name = NULL;
char **str_p = NULL;
int i;
if (argc < 5) {
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*/
for (i = 1; i < argc; i++)
{
if (streq (argv[i], "-v")) {
verbose = 1;
DBE_DEBUG (DBG_DEV_IO | DBG_LVL_TRACE, "[dev_io_fe] Verbose mode set\n");
}
else if (streq (argv[i], "-d")) {
daemonize = 1;
DBE_DEBUG (DBG_DEV_IO | DBG_LVL_TRACE, "[dev_io_fe] Demonize mode set\n");
}
else if (streq (argv[i], "-t")) {
str_p = &dev_type;
DBE_DEBUG (DBG_DEV_IO | DBG_LVL_TRACE, "[dev_io_fe] Will set dev_type parameter\n");
}
else if (streq (argv[i], "-e")) {
str_p = &dev_entry;
DBE_DEBUG (DBG_DEV_IO | DBG_LVL_TRACE, "[dev_io_fe] Will set dev_entry parameter\n");
}
else if (streq (argv[i], "-i")) {
str_p = &dev_id_str;
DBE_DEBUG (DBG_DEV_IO | DBG_LVL_TRACE, "[dev_io_fe] Will set dev_id_str parameter\n");
}
else if (streq (argv[i], "-b")) {
str_p = &broker_endp;
DBE_DEBUG (DBG_DEV_IO | DBG_LVL_TRACE, "[dev_io_fe] Will set broker_endp parameter\n");
}
else if (streq (argv[i], "-l")) {
str_p = &log_file_name;
DBE_DEBUG (DBG_DEV_IO | DBG_LVL_TRACE, "[dev_io_fe] Will set log filename\n");
}
else if (streq (argv[i], "-h")) {
print_help (argv[0]);
exit (1);
}
/* Fallout for options with parameters */
else {
if (str_p) {
*str_p = strdup (argv[i]);
DBE_DEBUG (DBG_DEV_IO | DBG_LVL_TRACE, "[dev_io_fe] Parameter set to \"%s\"\n", *str_p);
}
}
}
/* Daemonize dev_io */
if (daemonize != 0) {
int rc = daemon(0, 0);
if (rc != 0) {
perror ("[dev_io_fe] daemon");
goto err_exit;
}
}
llio_type_e llio_type = llio_str_to_type (dev_type);
/* Parse command-line options */
if (llio_type == INVALID_DEV) {
DBE_DEBUG (DBG_DEV_IO | DBG_LVL_FATAL, "[dev_io_fe] Dev_type parameter is invalid\n");
goto err_exit;
}
/* Check for device entry */
if (dev_entry == NULL) {
DBE_DEBUG (DBG_DEV_IO | DBG_LVL_INFO, "[dev_io_fe] Dev_entry parameter was not set. Exiting ...\n");
goto err_exit;
}
/* Check for device ID */
if (dev_id_str == NULL) {
DBE_DEBUG (DBG_DEV_IO | DBG_LVL_INFO, "[dev_io_fe] Dev_id parameter was not set.\n"
"\tDefaulting it to the /dev file number ...\n");
int matches = sscanf (dev_entry, "/dev/fpga%u", &dev_id);
if (matches == 0) {
DBE_DEBUG (DBG_DEV_IO | DBG_LVL_FATAL, "[dev_io_fe] Dev_entry parameter is invalid.\n"
"\tIt must be in the format \"/dev/fpga<device_number>\". Exiting ...\n");
goto err_exit;
}
}
/* Use the passed ID */
else {
dev_id = strtoul (dev_id_str, NULL, 10);
}
DBE_DEBUG (DBG_DEV_IO | DBG_LVL_INFO, "[dev_io_fe] Dev_id parameter was set to %u.\n",
dev_id);
/* We don't need it anymore */
str_p = &dev_type;
free (*str_p);
dev_type = NULL;
str_p = &dev_id_str;
free (*str_p);
dev_id_str = NULL;
/* Initilialize dev_io */
DBE_DEBUG (DBG_DEV_IO | DBG_LVL_TRACE, "[dev_io_fe] Creating DEVIO instance ...\n");
char devio_service_str [DEVIO_SERVICE_LEN];
snprintf (devio_service_str, DEVIO_SERVICE_LEN-1, "BPM%u:DEVIO", dev_id);
devio_service_str [DEVIO_SERVICE_LEN-1] = '\0'; /* Just in case ... */
devio_t *devio = devio_new (devio_service_str, dev_entry, llio_type,
broker_endp, verbose, log_file_name);
/* devio_t *devio = devio_new ("BPM0:DEVIO", *str_p, llio_type,
"tcp://localhost:5555", verbose); */
if (devio == NULL) {
DBE_DEBUG (DBG_DEV_IO | DBG_LVL_FATAL, "[dev_io_fe] devio_new error!\n");
goto err_exit;
}
/* We don't need it anymore */
str_p = &dev_entry;
free (*str_p);
dev_entry = NULL;
str_p = &broker_endp;
free (*str_p);
broker_endp = NULL;
devio_err_e err = spwan_platform_smios (devio);
if (err != DEVIO_SUCCESS) {
DBE_DEBUG (DBG_DEV_IO | DBG_LVL_FATAL, "[dev_io_fe] spwan_platform_smios error!\n");
goto err_devio;
}
/* err = devio_init_poller_sm (devio); */
err = devio_init_poller2_sm (devio);
if (err != DEVIO_SUCCESS) {
DBE_DEBUG (DBG_DEV_IO | DBG_LVL_FATAL, "[dev_io_fe] devio_init_poller_sm error!\n");
goto err_devio;
}
while (!zctx_interrupted) {
/* Step 1: Loop though all the SDB records and intialize (boot) the
* smio modules*/
/* Step 2: Optionally, register the necessary smio modules specifying
* its ID and calling devio_register_sm */
/* Step 3: Poll all PIPE's sockets to determine if we have something to
* handle, like messages from smios */
/* Step 3.5: If we do, call devio_handle_smio () and treat its
* request as appropriate */
/* devio_poll_all_sm (devio); */
devio_poll2_all_sm (devio);
}
err_devio:
devio_destroy (&devio);
err_exit:
str_p = &log_file_name;
free (*str_p);
str_p = &broker_endp;
free (*str_p);
str_p = &dev_id_str;
free (*str_p);
str_p = &dev_entry;
free (*str_p);
str_p = &dev_type;
free (*str_p);
return 0;
}
static devio_err_e spwan_platform_smios (devio_t *devio)
{
assert (devio);
uint32_t rffe_v2_id = 0x7af21909;
devio_err_e err = DEVIO_SUCCESS;
/* RFFE V2 only */
/* #if defined (__AFE_RFFE_V1__) */
#if defined (__AFE_RFFE_V2__)
DBE_DEBUG (DBG_DEV_IO | DBG_LVL_INFO, "[dev_io_fe] Spawning default SMIOs ...\n");
err = devio_register_sm (devio, rffe_v2_id, 0, 0);
if (err != DEVIO_SUCCESS) {
DBE_DEBUG (DBG_DEV_IO | DBG_LVL_FATAL, "[dev_io_fe] devio_register_sm error!\n");
goto err_register_sm;
}
#else
#error "AFE RFFE Board not supported!"
#endif
err_register_sm:
return err;
}
#ifndef _DEV_BE_IO_
#define _DEV_BE_IO_
#include "dev_io_core.h"
#endif
......@@ -24,22 +24,18 @@ hal_all_OUT += $(dev_mngr_all_OUT) $(dev_io_all_OUT)
# 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)
$(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_be_OBJS += $(dev_io_core_OBJS) $(ll_io_OBJS) $(sm_io_OBJS) \
$(msg_OBJS) $(debug_OBJS) $(hal_utils_OBJS)
dev_io_fe_OBJS += $(dev_io_core_OBJS) $(ll_io_OBJS) $(sm_io_OBJS) \
$(msg_OBJS) $(debug_OBJS) $(hal_utils_OBJS)
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_be_LIBS =
dev_io_be_STATIC_LIBS = $(LIBCLIENT_DIR)/libbpmclient.a
dev_io_fe_LIBS =
dev_io_fe_STATIC_LIBS = $(LIBCLIENT_DIR)/libbpmclient.a
dev_io_LIBS =
dev_io_STATIC_LIBS = $(LIBCLIENT_DIR)/libbpmclient.a $(LIBBSMP_DIR)/libbsmp.a
# Merge all hal objects together
hal_OBJS = $(debug_OBJS) \
......
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