open-close.c 2.45 KB
Newer Older
1
/*
2 3 4 5
 * Copyright (C) 2011 CERN (www.cern.ch)
 * Author: Aurelio Colosimo
 *
 * Released according to the GNU LGPL, version 2.1 or any later version.
6
 */
7

Alessandro Rubini's avatar
Alessandro Rubini committed
8
#include <ppsi/ppsi.h>
9 10

/*
11 12
 * This is a global structure, because commandline and other config places
 * need to change some values in there.
13
 */
14
struct pp_runtime_opts __pp_default_rt_opts = {
15
	.clock_quality = {
16
			.clockClass = PP_CLASS_DEFAULT,
17 18 19
			.clockAccuracy = PP_DEFAULT_CLOCK_ACCURACY,
			.offsetScaledLogVariance = PP_DEFAULT_CLOCK_VARIANCE,
	},
20
	.flags =		PP_DEFAULT_FLAGS,
21 22 23 24 25 26 27 28
	.ap =			PP_DEFAULT_AP,
	.ai =			PP_DEFAULT_AI,
	.s =			PP_DEFAULT_DELAY_S,
	.announce_intvl =	PP_DEFAULT_ANNOUNCE_INTERVAL,
	.sync_intvl =		PP_DEFAULT_SYNC_INTERVAL,
	.prio1 =		PP_DEFAULT_PRIORITY1,
	.prio2 =		PP_DEFAULT_PRIORITY2,
	.domain_number =	PP_DEFAULT_DOMAIN_NUMBER,
29
	.ttl =			PP_DEFAULT_TTL,
30 31
};

32 33 34 35 36 37
/*
 * This file deals with opening and closing an instance. The channel
 * must already have been created. In practice, this initializes the
 * state machine to the first state.
 */

38
int pp_init_globals(struct pp_globals *ppg, struct pp_runtime_opts *pp_rt_opts)
39
{
40 41 42 43 44 45
	/*
	 * Initialize default data set
	 */
	int i;
	struct DSDefault *def = ppg->defaultDS;
	def->twoStepFlag = TRUE;
46 47 48 49

	/* if ppg->nlinks == 0, let's assume that the 'pp_links style'
	 * configuration was not used, so we have 1 port */
	def->numberPorts = ppg->nlinks > 0 ? ppg->nlinks : 1;
50 51
	struct pp_runtime_opts *rt_opts;

52
	if (!ppg->rt_opts)
53
		ppg->rt_opts = pp_rt_opts;
54

55
	rt_opts = ppg->rt_opts;
56 57 58 59

	memcpy(&def->clockQuality, &rt_opts->clock_quality,
		   sizeof(ClockQuality));

60
	if (def->numberPorts == 1)
61
		def->slaveOnly = (INST(ppg, 0)->role == PPSI_ROLE_SLAVE);
62 63 64 65
	else
		def->slaveOnly = 1; /* the for cycle below will set it to 0 if not
							 * ports are not all slave_only */

66 67 68 69
	def->priority1 = rt_opts->prio1;
	def->priority2 = rt_opts->prio2;
	def->domainNumber = rt_opts->domain_number;

70
	for (i = 0; i < def->numberPorts; i++) {
71
		struct pp_instance *ppi = INST(ppg, i);
72

73
		if (def->slaveOnly && ppi->role != PPSI_ROLE_SLAVE)
74
			def->slaveOnly = 0;
75

76
		ppi->state = PPS_INITIALIZING;
77
		ppi->current_state_item = NULL;
78 79
		ppi->port_idx = i;
		ppi->frgn_rec_best = -1;
80 81
	}

82 83
	if (def->slaveOnly) {
		pp_printf("Slave Only, clock class set to 255\n");
84
		def->clockQuality.clockClass = PP_CLASS_SLAVE_ONLY;
85
	}
86

87
	if (pp_hooks.open)
88
		return pp_hooks.open(ppg, rt_opts);
89 90 91
	return 0;
}

92
int pp_close_globals(struct pp_globals *ppg)
93
{
94
	if (pp_hooks.close)
95
		return pp_hooks.close(ppg);
96 97
	return 0;
}