Commit 85013c4f authored by Lucas Russo's avatar Lucas Russo

all: start refactor code into libs/

parent 2fefd370
......@@ -17,7 +17,7 @@
#include "dev_mngr.h"
#include "debug_print.h"
#include "hal_varg.h"
#include "varg_macros.h"
#include "hal_utils.h"
#define DFLT_BIND_FOLDER "/tmp/bpm"
......
......@@ -2,7 +2,7 @@
#define _DDR3_MAP_AFCV3_H_
#include "acq_chan_afcv3.h"
#include "hal_varg.h"
#include "varg_macros.h"
/* Does the acquisition channel gets a memory region? */
#define DDR3_MEM_BOOL(MEM_SIZE) IF(MEM_SIZE > 0)(1, 0)
......
......@@ -2,7 +2,7 @@
#define _DDR3_MAP_ML605_H_
#include "acq_chan_ml605.h"
#include "hal_varg.h"
#include "varg_macros.h"
/* Does the acquisition channel gets a memory region? */
#define DDR3_MEM_BOOL(MEM_SIZE) IF(MEM_SIZE > 0)(1, 0)
......
......@@ -9,7 +9,7 @@
#define _HAL_ASSERT_H_
#include "debug_print.h"
#include "hal_varg.h"
#include "varg_macros.h"
/* TODO: find a way avoid modifying the "global" err variable */
#define SET_ERR_VAR(err_code) WHENNOT(ISEMPTY(err_code))( \
......
......@@ -5,8 +5,8 @@
* Released according to the GNU LGPL, version 3 or any later version.
*/
#ifndef _HAL_VARG_H_
#define _HAL_VARG_H_
#ifndef _VARG_MACROS_H_
#define _VARG_MACROS_H_
/********************** Detecting NULL passed to MACRO ************************/
/* based on from "Detect empty macro arguments" from Jens Gustedt, published
......
......@@ -7,7 +7,7 @@
#include <inttypes.h>
#include <mdp.h>
#include "hal_varg.h"
#include "varg_macros.h"
#include "rw_param_codes.h"
#include "msg.h"
......
# Set your cross compile prefix with CROSS_COMPILE variable
CROSS_COMPILE ?=
CMDSEP = ;
CC = $(CROSS_COMPILE)gcc
AR = $(CROSS_COMPILE)ar
LD = $(CROSS_COMPILE)ld
OBJDUMP = $(CROSS_COMPILE)objdump
OBJCOPY = $(CROSS_COMPILE)objcopy
SIZE = $(CROSS_COMPILE)size
MAKE = make
PWD = $(shell pwd)
LIBDEBUG = libdebug
# General C flags
CFLAGS = -std=gnu99 -O2
# Debug flags -D<flasg_name>=<value>
CFLAGS_DEBUG += -g
# Specific platform Flags
CFLAGS_PLATFORM = -Wall -Wextra -Werror
LDFLAGS_PLATFORM =
# Libraries
LIBS =
# General library flags -L<libdir>
LFLAGS =
# Include directories
INCLUDE_DIRS = -I.
# Merge all flags. Optimize for size (-Os)
CFLAGS += $(CFLAGS_PLATFORM) $(CFLAGS_DEBUG)
LDFLAGS = $(LDFLAGS_PLATFORM)
# Output library names
OUT = $(LIBDEBUG)
.SECONDEXPANSION:
# Library objects
$(LIBDEBUG)_OBJS_LIB = debug_print.o debug_subsys.o local_print.o
# Objects common for this library
common_OBJS =
# Objects for each version of library
$(LIBDEBUG)_OBJS = $(common_OBJS) $($(LIBDEBUG)_OBJS_LIB)
$(LIBDEBUG)_CODE_HEADERS = debug_opts.h
$(LIBDEBUG)_HEADERS = $($(LIBDEBUG)_OBJS_LIB:.o=.h) $($(LIBDEBUG)_CODE_HEADERS)
OBJS_all = $(common_OBJS) $($(LIBDEBUG)_OBJS)
# Libraries suffixes
LIB_STATIC_SUFFIX = .a
# Generate suitable names for static libraries
TARGET_STATIC = $(addsuffix $(LIB_STATIC_SUFFIX), $(OUT))
.PHONY: all clean mrproper install uninstall
# Avoid deletion of intermediate files, such as objects
.SECONDARY: $(OBJS_all)
# Makefile rules
all: $(TARGET_STATIC)
# Compile static library
%.a: $$($$*_OBJS)
$(AR) rcs $@ $^
# Pull in dependency info for *existing* .o files and don't complain if the
# corresponding .d file is not found
-include $(OBJS_all:.o=.d)
# Compile with position-independent objects.
# Autodependencies generatation by Scott McPeak, November 2001,
# from article "Autodependencies with GNU make"
%.o: %.c
$(CC) $(CFLAGS) $(INCLUDE_DIRS) -c $*.c -o $@
# create the dependency files "target: pre-requisites"
${CC} -MM $(CFLAGS) $(INCLUDE_DIRS) $*.c > $*.d
# Workaround to make objects in different folders have
# the correct target path. e.g., "dir/bar.o: dir/bar.c dir/foo.h"
# instead of "bar.o: dir/bar.c dir/foo.h"
@mv -f $*.d $*.d.tmp
@sed -e 's|.*:|$*.o:|' < $*.d.tmp > $*.d
# All prereqs listed will also become command-less,
# prereq-less targets. In this way, the prereq file will be
# treated as changed and the target will be rebuilt
# sed: strip the target (everything before colon)
# sed: remove any continuation backslashes
# fmt -1: list words one per line
# sed: strip leading spaces
# sed: add trailing colons
@sed -e 's/.*://' -e 's/\\$$//' < $*.d.tmp | fmt -1 | \
sed -e 's/^ *//' -e 's/$$/:/' >> $*.d
@rm -f $*.d.tmp
install:
uninstall:
clean:
rm -f $(OBJS_all) $(OBJS_all:.o=.d)
mrproper: clean
rm -f *.a
/*
* Copyright (C) 2014 LNLS (www.lnls.br)
* Author: Lucas Russo <lucas.russo@lnls.br>
*
* Released according to the GNU LGPL, version 3 or any later version.
*/
#include <unistd.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include <czmq.h>
#include "convc.h"
#include "debug_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, LL_IO, "[ll_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, LL_IO, "[ll_io:utils]", \
llio_err_str(LLIO_ERR_ALLOC), \
err_goto_label, /* err_core */ __VA_ARGS__)
#ifdef CHECK_ERR
#undef CHECK_ERR
#endif
#define CHECK_ERR(err, err_type) \
CHECK_HAL_ERR(err, LL_IO, "[ll_io:utils]", \
llio_err_str (err_type))
#define CONVC_TYPE_STR_SIZE 16
/************** Utility functions ****************/
char *convc_gen_type_to_str (int type, const convc_types_t *convc_types)
{
/* Should be large enough for all possible debug levels */
size_t size = CONVC_TYPE_STR_SIZE;
char *str = zmalloc (size*sizeof (char));
ASSERT_ALLOC(str, err_alloc_str);
/* Do a simple linear search to look for matching IDs */
uint32_t i;
for (i = 0; convc_types [i].type != CONVC_TYPE_END; ++i) {
if (type == convc_types [i].type) {
const char *type_str = convc_types [i].name;
int errs = snprintf (str, size, "%s", type_str);
ASSERT_TEST (errs >= 0,
"[ll_io:utils] Could not clone string. Enconding error?\n",
err_copy_str);
/* This shouldn't happen. Only when the number of characters written is
* less than the whole buffer, it is guaranteed that the string was
* written successfully */
ASSERT_TEST ((size_t) errs < size,
"[ll_io:utils] Cloned string was truncated\n", err_trunc_str);
break;
}
}
/* No device found */
if (convc_types [i].type == CONVC_TYPE_END) {
free (str);
str = NULL;
}
return str;
/* Fail miserably for now ... */
err_trunc_str:
err_copy_str:
free (str);
str = NULL;
err_alloc_str:
return NULL;
}
int convc_str_to_gen_type (const char *type_str, const convc_types_t *convc_types)
{
assert (type_str);
int type = CONVC_TYPE_END; /* Not found */
/* Do a simple linear search to look for matching names */
uint32_t i;
for (i = 0; convc_types [i].type != CONVC_TYPE_END; ++i) {
if (streq (type_str, convc_types [i].name)) {
type = convc_types [i].type;
break;
}
}
return type;
}
/*
* Copyright (C) 2014 LNLS (www.lnls.br)
* Author: Lucas Russo <lucas.russo@lnls.br>
*
* Released according to the GNU LGPL, version 3 or any later version.
*/
#ifndef _CONVC_H_
#define _CONVC_H_
#include <inttypes.h>
#define CONVC_TYPE_END 0xFFFF
#define CONVC_TYPE_NAME_END ""
struct _convc_types_t {
int type;
char *name;
};
typedef struct _convc_types_t convc_types_t;
/************** Utility functions ****************/
/* Generic mapping functions */
/* Converts the CONVC type ID into a string */
char *convc_gen_type_to_str (int type, const convc_types_t *convc_types);
/* Converts a string to an CONVC type ID. If no match if found,
* a INVALID_DEV is returned */
int convc_str_to_gen_type (const char *type_str,
const convc_types_t *convc_types);
#endif
# Set your cross compile prefix with CROSS_COMPILE variable
CROSS_COMPILE ?=
CMDSEP = ;
CC = $(CROSS_COMPILE)gcc
AR = $(CROSS_COMPILE)ar
LD = $(CROSS_COMPILE)ld
OBJDUMP = $(CROSS_COMPILE)objdump
OBJCOPY = $(CROSS_COMPILE)objcopy
SIZE = $(CROSS_COMPILE)size
MAKE = make
PWD = $(shell pwd)
LIBDEBUG = libdebug
# General C flags
CFLAGS = -std=gnu99 -O2
# Debug flags -D<flasg_name>=<value>
CFLAGS_DEBUG += -g
# Specific platform Flags
CFLAGS_PLATFORM = -Wall -Wextra -Werror
LDFLAGS_PLATFORM =
# Libraries
LIBS =
# General library flags -L<libdir>
LFLAGS =
# Include directories
INCLUDE_DIRS = -I.
# Merge all flags. Optimize for size (-Os)
CFLAGS += $(CFLAGS_PLATFORM) $(CFLAGS_DEBUG)
LDFLAGS = $(LDFLAGS_PLATFORM)
# Output library names
OUT = $(LIBDEBUG)
.SECONDEXPANSION:
# Library objects
$(LIBDEBUG)_OBJS_LIB = debug_print.o debug_subsys.o local_print.o
# Objects common for this library
common_OBJS =
# Objects for each version of library
$(LIBDEBUG)_OBJS = $(common_OBJS) $($(LIBDEBUG)_OBJS_LIB)
$(LIBDEBUG)_CODE_HEADERS = debug_opts.h
$(LIBDEBUG)_HEADERS = $($(LIBDEBUG)_OBJS_LIB:.o=.h) $($(LIBDEBUG)_CODE_HEADERS)
OBJS_all = $(common_OBJS) $($(LIBDEBUG)_OBJS)
# Libraries suffixes
LIB_STATIC_SUFFIX = .a
# Generate suitable names for static libraries
TARGET_STATIC = $(addsuffix $(LIB_STATIC_SUFFIX), $(OUT))
.PHONY: all clean mrproper install uninstall
# Avoid deletion of intermediate files, such as objects
.SECONDARY: $(OBJS_all)
# Makefile rules
all: $(TARGET_STATIC)
# Compile static library
%.a: $$($$*_OBJS)
$(AR) rcs $@ $^
# Pull in dependency info for *existing* .o files and don't complain if the
# corresponding .d file is not found
-include $(OBJS_all:.o=.d)
# Compile with position-independent objects.
# Autodependencies generatation by Scott McPeak, November 2001,
# from article "Autodependencies with GNU make"
%.o: %.c
$(CC) $(CFLAGS) $(INCLUDE_DIRS) -c $*.c -o $@
# create the dependency files "target: pre-requisites"
${CC} -MM $(CFLAGS) $(INCLUDE_DIRS) $*.c > $*.d
# Workaround to make objects in different folders have
# the correct target path. e.g., "dir/bar.o: dir/bar.c dir/foo.h"
# instead of "bar.o: dir/bar.c dir/foo.h"
@mv -f $*.d $*.d.tmp
@sed -e 's|.*:|$*.o:|' < $*.d.tmp > $*.d
# All prereqs listed will also become command-less,
# prereq-less targets. In this way, the prereq file will be
# treated as changed and the target will be rebuilt
# sed: strip the target (everything before colon)
# sed: remove any continuation backslashes
# fmt -1: list words one per line
# sed: strip leading spaces
# sed: add trailing colons
@sed -e 's/.*://' -e 's/\\$$//' < $*.d.tmp | fmt -1 | \
sed -e 's/^ *//' -e 's/$$/:/' >> $*.d
@rm -f $*.d.tmp
install:
uninstall:
clean:
rm -f $(OBJS_all) $(OBJS_all:.o=.d)
mrproper: clean
rm -f *.a
/*
* Copyright (C) 2014 LNLS (www.lnls.br)
* Author: Lucas Russo <lucas.russo@lnls.br>
*
* Released according to the GNU LGPL, version 3 or any later version.
*/
#ifndef _DEBUG_ASSERT_H_
#define _DEBUG_ASSERT_H_
#include "debug_print.h"
#include "varg_macros.h" /* Point the -I to somewhere visible */
/* TODO: find a way avoid modifying the "global" err variable */
#define SET_ERR_VAR(err_code) WHENNOT(ISEMPTY(err_code))( \
err = err_code)
/* Generic macros for asserting in subsystems. The
* general use case for them is to wrapp these with
* meaningful strings for differentes subsystems */
#define ASSERT_DEBUG_TEST(test_boolean, debug_subsys, \
debug_name, err_str, err_goto_label, /* err_code*/ ...) \
do { \
if(!(test_boolean)) { \
DBE_DEBUG (DBG_ ##debug_subsys | DBG_LVL_FATAL, \
debug_name " %s\n", err_str); \
SET_ERR_VAR(/* err_code*/ __VA_ARGS__); \
goto err_goto_label; \
} \
} while(0)
#define ASSERT_DEBUG_ALLOC(ptr, debug_subsys, debug_name, \
err_str, err_goto_label, /* err_code*/ ...) \
ASSERT_DEBUG_TEST(ptr!=NULL, debug_subsys, debug_name, \
err_str, err_goto_label, /* err_code*/ __VA_ARGS__)
#define CHECK_DEBUG_ERR(err, debug_subsys, debug_name, \
err_str) \
do { \
if (err < 0) { \
DBE_DEBUG (DBG_ ##debug_subsys | DBG_LVL_ERR, \
debug_name " %s\n", err_str); \
return err; \
} \
} while (0)
#endif
/*
* Copyright (C) 2014 LNLS (www.lnls.br)
* Author: Lucas Russo <lucas.russo@lnls.br>
* Parts taken from lwIP debug system
*
* Released according to the GNU LGPL, version 3 or any later version.
*/
#ifndef _DEBUG_OPTS_
#define _DEBUG_OPTS_
/* Defaults to sensible values if DBG_MIN_LEVEL and DBG_SUBSYS_ON
* are not specified previously */
/*
* Define the debug level here.
* Available options are, in decreasing order of verbosity:
* DBG_LVL_TRACE = super verbose
* DBG_LVL_INFO
* DBG_LVL_WARN
* DBG_LVL_ERR
* DBG_LVL_FATAL = only the critical messages are shown
*/
#ifndef DBG_MIN_LEVEL
#define DBG_MIN_LEVEL DBG_LVL_TRACE
#endif
/* Define which subsystem will be traced. The DBG_SUBSYS_ON
* macro must be OR'ed.
* Available options are:
* DBG_DEV_MNGR
* DBG_DEV_IO
* DBG_LL_IO
* DBG_SM_IO
* DBG_MSG
* DBG_LIB_CLIENT
* DBG_SM_PR
* DBG_SM_CH
*/
#ifndef DBG_SUBSYS_ON
#define DBG_SUBSYS_ON (\
DBG_DEV_MNGR | \
DBG_DEV_IO | \
DBG_SM_IO | \
DBG_LIB_CLIENT | \
DBG_SM_PR | \
DBG_SM_CH | \
DBG_LL_IO | \
DBG_HAL_UTILS)
/* DBG_MSG | \ */
#endif
#endif
/*
* Copyright (C) 2014 LNLS (www.lnls.br)
* Author: Lucas Russo <lucas.russo@lnls.br>
*
* Released according to the GNU LGPL, version 3 or any later version.
*/
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <czmq.h>
#include "debug_print.h"
#include "local_print.h"
#define DBE_PRINT_PAD_FMT "-5"
/* Our logfile */
static FILE *_debug_logfile = NULL;
void debug_print (const char *fmt, ...)
{
va_list args;
va_start (args, fmt);
vprintf (fmt, args);
va_end (args);
}
/* Based on CZMQ s_log () function. Available in
* https://github.com/zeromq/czmq/blob/master/src/zsys.c */
static void _debug_log_write (char *dbg_lvl_str, char *msg)
{
/* Default to stdout */
if (!_debug_logfile) {
_debug_logfile = stdout;
}
time_t curtime = time (NULL);
struct tm *loctime = localtime (&curtime);
char date [20];
strftime (date, 20, "%y-%m-%d %H:%M:%S", loctime);
char log_text [1024];
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);
}
/* Based on CZMQ zsys_error () function. Available in
* https://github.com/zeromq/czmq/blob/master/src/zsys.c */
void debug_log_print (int dbg_lvl, const char *fmt, ...)
{
va_list argptr;
va_start (argptr, fmt);
char *msg = local_vprintf (fmt, argptr);
va_end (argptr);
/* Convert debug level code to string */
char *dbg_lvl_str = dbg_lvl_to_str (dbg_lvl);
_debug_log_write (dbg_lvl_str, msg);
free (msg);
free (dbg_lvl_str);
}
void debug_log_print_zmq_msg (zmsg_t *msg)
{
/* Default to stdout */
if (!_debug_logfile) {
_debug_logfile = stdout;
}
local_print_zmq_msg (msg, _debug_logfile);
}
void debug_print_vec (const char *fmt, const char *data, int len)
{
int i;
for (i = 0; i < len; ++i)
printf (fmt, data[i]);
printf ("\n");
}
static void _debug_set_log_file (FILE *log_file)
{
_debug_logfile = log_file;
}
void debug_set_log_file (FILE *log_file)
{
_debug_set_log_file (log_file);
}
int debug_set_log (const char *log_file_name, const char *mode)
{
int err = -1; /* Error */
FILE *log_file = NULL;
if (log_file_name) {
if (streq(log_file_name, "stdout")) {
log_file = stdout;
err = 1;
}
else if (streq(log_file_name, "stderr")) {
log_file = stderr;
err = 2;
}
else {
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) {
log_file = stdout;
err = 2;
}
}
}
else {
/* Default to stdout */
log_file = stdout;
}
_debug_set_log_file (log_file);
return err;
}
/*
* Copyright (C) 2014 LNLS (www.lnls.br)
* Author: Lucas Russo <lucas.russo@lnls.br>
* Parts taken from lwIP debug system
*
* Released according to the GNU LGPL, version 3 or any later version.
*/
#ifndef _DEBUG_PRINT_H_
#define _DEBUG_PRINT_H_
#include <stdarg.h>
#include <stdio.h>
#include "debug_subsys.h" /* This must come before "hal_opts.h" */
#include "debug_opts.h"
struct _zmsg_t;
/************** Debug functions declarations **************/
void debug_print (const char *fmt, ...) __attribute__((format(printf,1,2)));
void debug_print_vec (const char *fmt, const char *data, int len);
void debug_log_print (int dbg_lvl, const char *fmt, ...) __attribute__((format(printf,2,3)));
/* Set the output logfile Defaults to STDOUT */
void debug_set_log_file (FILE *log_file);
int debug_set_log (const char *log_file_name, const char *mode);
void debug_log_print_zmq_msg (struct _zmsg_t *msg);
/********************** Debug macros **********************/
#if (DBG_SUBSYS_ON & DBG_MSG)
#define LOCAL_MSG_DBG
#endif
#ifdef DBE_DBG
#define dbg_print(fmt, ...) \
debug_print(fmt, ## __VA_ARGS__)
#define dbg_print_vec(fmt, data, len) \
debug_print_vec(fmt, data, len)
#define dbg_log_print(dbg_lvl, fmt, ...) \
debug_log_print(dbg_lvl, fmt, ## __VA_ARGS__)
#else
#define dbg_print(fmt, ...)
#define dbg_print_vec(fmt, data, len)
#define dbg_log_print(dbg_lvl, fmt, ...)
#endif /* DBE_DBG */
/* dbg has the following format:
* 31 - 4 3 - 1 0-0
* DBG_SUBSYS DBG_LVL DBG_HALT
*/
#ifdef DBE_DBG
#define DBE_DEBUG(dbg, fmt, ...) \
do { \
if (((dbg) & DBG_SUBSYS_ON) && \
(((dbg) & DBG_LVL_MASK) >= \
DBG_MIN_LEVEL)) { \
dbg_log_print((dbg) & DBG_LVL_MASK, \
fmt, ## __VA_ARGS__); \
\
if ((dbg) & DBG_LVL_HALT) { \
while(1); \
} \
} \
} while(0)
#define DBE_DEBUG_ARRAY(dbg, fmt, data, len) \
do { \
if (((dbg) & DBG_SUBSYS_ON) && \
(((dbg) & DBG_LVL_MASK) >= \
DBG_MIN_LEVEL)) { \
dbg_print_vec(fmt, data, len); \
\
if ((dbg) & DBG_LVL_HALT) \
while(1); \
} \
} while(0)
#define DBE_ERR(...) \
do { \
dbg_print(fmt, ##__VA_ARGS__); \
} while(0)
#else
#define DBE_DEBUG(dbg, fmt, ...)
#define DBE_DEBUG_ARRAY(dbg, fmt, data, len)
#define DBE_ERR(...)
#endif /* DBE_DBG */
#endif
/*
* Copyright (C) 2014 LNLS (www.lnls.br)
* Author: Lucas Russo <lucas.russo@lnls.br>
*
* Released according to the GNU LGPL, version 3 or any later version.
*/
#include <czmq.h>
#include "debug_subsys.h"
const char *dbg_lvl_str [DBG_LVL_NUM] = {
[0] = DBG_LVL_TRACE_STR,
[1] = DBG_LVL_INFO_STR,
[2] = DBG_LVL_WARN_STR,
[3] = DBG_LVL_ERR_STR,
[4] = DBG_LVL_FATAL_STR
};
char *dbg_lvl_to_str (int dbg_lvl)
{
/* Should be large enough for all possible debug levels */
int size = 16;
char *str = zmalloc (size);
const char *dbg_str = dbg_lvl_str [DBG_LVL_DEGEN(dbg_lvl)-1];
memcpy (str, dbg_str, strlen (dbg_str)+1);
return str;
}
/*
* Copyright (C) 2014 LNLS (www.lnls.br)
* Author: Lucas Russo <lucas.russo@lnls.br>
*
* Released according to the GNU LGPL, version 3 or any later version.
*/
#ifndef _DEBUG_SUBSYS_H_
#define _DEBUG_SUBSYS_H_
/****************** Debug subsys macros ******************/
/*
* DBG_SUBSYS variable is one-hot encoded between
* the bits 31 and 4:
* bit 31 ... bit 4 bit 3 ... bit 0
* [1|0] [1|0] X X
*/
#define DBG_SUBSYS_SHIFT 4
/* Up to 28 debug subsystems (one-hot encoded) */
#define DBG_SUBSYS_MAX 28
#define DBG_SUBSYS_MASK_RAW ((1 << DBG_SUBSYS_MAX)-1)
#define DBG_SUBSYS_MASK (DBG_SUBSYS_MASK_RAW << DBG_SUBSYS_SHIFT)
#define DBG_SUBSYS_GEN(val) ((val & DBG_SUBSYS_MASK_RAW) << DBG_SUBSYS_SHIFT)
#define DBG_SUBSYS_DEGEN(val) ((val & DBG_SUBSYS_MASK) >> DBG_SUBSYS_SHIFT)
/* Debug subsys raw */
#define DBG_DEV_MNGR_RAW 0x1
#define DBG_DEV_IO_RAW 0x2
#define DBG_LL_IO_RAW 0x4
#define DBG_SM_IO_RAW 0x8
#define DBG_MSG_RAW 0x10
#define DBG_HAL_UTILS_RAW 0x20
#define DBG_LIB_CLIENT_RAW 0x40 /* The client library shares this macros */
#define DBG_SM_PR_RAW 0x80
#define DBG_SM_CH_RAW 0x100
#define DBG_DEV_MNGR DBG_SUBSYS_GEN(DBG_DEV_MNGR_RAW)
#define DBG_DEV_IO DBG_SUBSYS_GEN(DBG_DEV_IO_RAW)
#define DBG_LL_IO DBG_SUBSYS_GEN(DBG_LL_IO_RAW)
#define DBG_SM_IO DBG_SUBSYS_GEN(DBG_SM_IO_RAW)
#define DBG_MSG DBG_SUBSYS_GEN(DBG_MSG_RAW)
#define DBG_HAL_UTILS DBG_SUBSYS_GEN(DBG_HAL_UTILS_RAW)
/* The client library shares this macros */
#define DBG_LIB_CLIENT DBG_SUBSYS_GEN(DBG_LIB_CLIENT_RAW)
#define DBG_SM_PR DBG_SUBSYS_GEN(DBG_SM_PR_RAW)
#define DBG_SM_CH DBG_SUBSYS_GEN(DBG_SM_CH_RAW)
/****************** Debug levels macros ******************/
/*
* DBG_LVL variable is binary encoded between
* the bits 3 and 1:
* bit 31 ... bit 4 bit 3 ... bit 1 bit 0
* X X [1|0] [1|0] X
*/
#define DBG_LVL_SHIFT 1
#define DBG_LVL_MAX 3
#define DBG_LVL_MASK_RAW ((1 << DBG_LVL_MAX)-1)
#define DBG_LVL_MASK (DBG_LVL_MASK_RAW << DBG_LVL_SHIFT)
/* Up to 2^3 debug levels */
#define DBG_LVL_GEN(val) ((val & DBG_LVL_MASK_RAW) << DBG_LVL_SHIFT)
#define DBG_LVL_DEGEN(val) ((val & DBG_LVL_MASK) >> DBG_LVL_SHIFT)
#define DBG_LVL_NUM 5
/* Debug levels raw */
#define DBG_LVL_TRACE_RAW 0x1
#define DBG_LVL_INFO_RAW 0x2
#define DBG_LVL_WARN_RAW 0x3
#define DBG_LVL_ERR_RAW 0x4
#define DBG_LVL_FATAL_RAW 0x5
/* Debug levels mask'ed and shift'ed */
#define DBG_LVL_TRACE DBG_LVL_GEN(DBG_LVL_TRACE_RAW)
#define DBG_LVL_INFO DBG_LVL_GEN(DBG_LVL_INFO_RAW)
#define DBG_LVL_WARN DBG_LVL_GEN(DBG_LVL_WARN_RAW)
#define DBG_LVL_ERR DBG_LVL_GEN(DBG_LVL_ERR_RAW)
#define DBG_LVL_FATAL DBG_LVL_GEN(DBG_LVL_FATAL_RAW)
#define DBG_LVL_TRACE_STR "TRACE"
#define DBG_LVL_INFO_STR "INFO"
#define DBG_LVL_WARN_STR "WARN"
#define DBG_LVL_ERR_STR "ERR"
#define DBG_LVL_FATAL_STR "FATAL"
extern const char *dbg_lvl_str [DBG_LVL_NUM];
char *dbg_lvl_to_str (int dbg_lvl);
/****************** Debug halt macros ******************/
/*
* DBG_HALT variable is binary encoded in bit 0:
* bit 31 ... bit 4 bit 3 ... bit 1 bit 0
* X X X X [1|0]
*/
/* Debug halt */
#define DBG_HALT_SHIFT 0
#define DBG_HALT_MAX 1
#define DBG_HALT_MASK_RAW ((1 << DBG_HALT_SHIFT)-1)
#define DBG_HALT_MASK (DBG_HALT_MASK_RAW << DBG_HALT_SHIFT)
/* 1 halt signal */
#define DBG_HALT_GEN(val) ((val & DBG_HALT_MASK_RAW) << DBG_HALT_SHIFT)
#define DBG_HALT_DEGEN(val) ((val & DBG_HALT_MASK) >> DBG_HALT_SHIFT)
/* Debug halt raw */
#define DBG_LVL_HALT_RAW 0x1
/* Debug halt mask'ed and shift'ed */
#define DBG_LVL_HALT DBG_HALT_GEN(DBG_LVL_HALT_RAW)
#endif
/*
* 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 <czmq.h>
char *local_vprintf (const char *format, va_list argptr)
{
return zsys_vprintf (format, argptr);
}
void local_print_zmq_msg (zmsg_t *msg, FILE *file)
{
zmsg_fprint (msg, file);
fprintf (file, "--------------------------------------\n");
fflush (file);
}
/*
* Copyright (C) 2014 LNLS (www.lnls.br)
* Author: Lucas Russo <lucas.russo@lnls.br>
* Parts taken from lwIP debug system
*
* Released according to the GNU LGPL, version 3 or any later version.
*/
#ifndef _LOCAL_PRINT_H_
#define _LOCAL_PRINT_H_
char *local_vprintf (const char *format, va_list argptr);
void local_print_zmq_msg (zmsg_t *msg, FILE *file);
#endif
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