Commit 222d30ef authored by Alessandro Rubini's avatar Alessandro Rubini

diag.c: the functions used by diag-macros.h

Signed-off-by: Alessandro Rubini's avatarAlessandro Rubini <rubini@gnudd.com>
parent bdf18817
......@@ -35,7 +35,7 @@ CFLAGS = $(USER_CFLAGS)
CFLAGS += -Wall -O2 -ggdb -Iinclude
# to avoid ifdef as much as possible, I use the kernel trick for OBJ variables
OBJ-y := fsm.o
OBJ-y := fsm.o diag.o
# include pp_printf code, by default the "full" version. Please
# set CONFIG_PRINTF_NONE or CONFIG_PRINTF_XINT if needed.
......
/*
* Alessandro Rubini for CERN, 2013 -- GNU LGPL v2.1 or later
*/
#include <stdarg.h>
#include <ppsi/ppsi.h>
static char *thing_name[] = {
[pp_dt_fsm] = "diag-fsm",
[pp_dt_time] = "diag-time",
[pp_dt_frames] = "diag-frames",
[pp_dt_servo] = "diag-servo",
[pp_dt_bmc] = "diag-bmc",
[pp_dt_ext] = "diag-extension",
};
void __pp_diag(struct pp_instance *ppi, enum pp_diag_things th,
int level, char *fmt, ...)
{
va_list args;
if (!__PP_DIAG_ALLOW(ppi, th, level))
return;
pp_printf("%s-%i-%s: ", thing_name[th], level, OPTS(ppi)->iface_name);
va_start(args, fmt);
pp_vprintf(fmt, args);
va_end(args);
}
unsigned long pp_diag_parse(char *diaglevel)
{
unsigned long res = 0;
int i = 28;
#ifdef VERB_LOG_MSGS /* compatible with older way: this enables all */
return ~0xf;
#endif
while (*diaglevel && i >= 4) {
if (*diaglevel < '0' || *diaglevel > '3')
break;
res |= ((*diaglevel - '0') << i);
i -= 4;
diaglevel++;
}
if (*diaglevel)
pp_printf("%s: error parsing \"%s\"\n", __func__, diaglevel);
pp_printf("diag level: %08lx\n", res);
return res;
}
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