Maintenance scheduled 24th July -- expect downtime along that day

diag.c 1.32 KB
Newer Older
1
/*
2 3 4 5
 * Copyright (C) 2013 CERN (www.cern.ch)
 * Author: Alessandro Rubini
 *
 * Released according to the GNU LGPL, version 2.1 or any later version.
6 7 8 9
 */
#include <stdarg.h>
#include <ppsi/ppsi.h>

10 11 12 13
#ifndef ARRAY_SIZE
#define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0]))
#endif

14 15 16 17 18 19 20
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",
21
	[pp_dt_config]	= "diag-config",
22 23 24 25 26 27 28
};


void __pp_diag(struct pp_instance *ppi, enum pp_diag_things th,
		      int level, char *fmt, ...)
{
	va_list args;
29
	char *name = ppi ? ppi->port_name : "ppsi";
30 31 32 33

	if (!__PP_DIAG_ALLOW(ppi, th, level))
		return;

34
	/* Use the normal output channel for diagnostics */
35
	pp_printf("%s-%i-%s: ", thing_name[th], level, name);
36 37 38 39 40 41 42 43
	va_start(args, fmt);
	pp_vprintf(fmt, args);
	va_end(args);
}

unsigned long pp_diag_parse(char *diaglevel)
{
	unsigned long res = 0;
44
	int i = 28; /* number of bits to shift the nibble: 28..31 is first */
45
	int nthings = ARRAY_SIZE(thing_name);
46

47
	while (*diaglevel && i >= (32 - 4 * nthings)) {
48 49 50 51 52 53 54 55 56 57 58
		if (*diaglevel < '0' || *diaglevel > '3')
			break;
		res |= ((*diaglevel - '0') << i);
		i -= 4;
		diaglevel++;
	}
	if (*diaglevel)
		pp_printf("%s: error parsing \"%s\"\n", __func__, diaglevel);

	return res;
}