sim-conf.c 3.7 KB
Newer Older
1 2 3 4 5 6 7 8 9 10
/*
 * Copyright (C) 2013 CERN (www.cern.ch)
 * Author: Pietro Fezzardi (pietrofezzardi@gmail.com)
 *
 * Released according to GNU LGPL, version 2.1 or any later
 */

#include <ppsi/ppsi.h>
#include "ppsi-sim.h"

11
static int f_ppm_real(struct pp_argline *l, int lineno, struct pp_globals *ppg,
12 13 14 15 16 17 18
			union pp_cfg_arg *arg)
{
	struct pp_instance *ppi_slave;

	/* master clock is supposed to be perfect. parameters about ppm are
	 * modifiable only for slave ppi */
	ppi_slave = pp_sim_get_slave(ppg);
19
	SIM_PPI_ARCH(ppi_slave)->time.freq_ppb_real = arg->i * 1000;
20 21 22
	return 0;
}

23
static int f_ppm_servo(struct pp_argline *l, int lineno, struct pp_globals *ppg,
24 25 26 27 28 29 30
			union pp_cfg_arg *arg)
{
	struct pp_instance *ppi_slave;

	/* master clock is supposed to be perfect. parameters about ppm are
	 * modifiable only for slave ppi */
	ppi_slave = pp_sim_get_slave(ppg);
31
	SIM_PPI_ARCH(ppi_slave)->time.freq_ppb_servo = arg->i * 1000;
32 33 34
	return 0;
}

35
static int f_ofm(struct pp_argline *l, int lineno, struct pp_globals *ppg,
36 37 38 39 40 41 42 43 44 45 46 47
			union pp_cfg_arg *arg)
{
	struct pp_sim_time_instance *t_master, *t_slave;

	t_master = &SIM_PPI_ARCH(pp_sim_get_master(ppg))->time;
	t_slave = &SIM_PPI_ARCH(pp_sim_get_slave(ppg))->time;
	t_slave->current_ns = t_master->current_ns + arg->ts.tv_nsec +
				arg->ts.tv_sec * (long long)PP_NSEC_PER_SEC;

	return 0;
}

48
static int f_init_time(struct pp_argline *l, int lineno, struct pp_globals *ppg,
49 50 51 52 53 54 55 56 57 58 59
			union pp_cfg_arg *arg)
{
	struct pp_sim_time_instance *t_inst;

	t_inst = &SIM_PPI_ARCH(pp_sim_get_master(ppg))->time;
	t_inst->current_ns = arg->ts.tv_nsec +
				arg->ts.tv_sec * (long long)PP_NSEC_PER_SEC;

	return 0;
}

60 61
static int f_fwd_t_prop(struct pp_argline *l, int lineno,
			struct pp_globals *ppg, union pp_cfg_arg *arg)
62 63 64 65 66 67 68
{
	struct sim_ppi_arch_data *data;
	data = SIM_PPI_ARCH(pp_sim_get_master(ppg));
	data->n_delay.t_prop_ns = arg->i;
	return 0;
}

69 70
static int f_bckwd_t_prop(struct pp_argline *l, int lineno,
			  struct pp_globals *ppg, union pp_cfg_arg *arg)
71 72 73 74 75 76 77
{
	struct sim_ppi_arch_data *data;
	data = SIM_PPI_ARCH(pp_sim_get_slave(ppg));
	data->n_delay.t_prop_ns = arg->i;
	return 0;
}

78 79
static int f_t_prop(struct pp_argline *l, int lineno, struct pp_globals *ppg,
		    union pp_cfg_arg *arg)
80
{
81 82
	f_fwd_t_prop(l, lineno, ppg, arg);
	f_bckwd_t_prop(l, lineno, ppg, arg);
83 84 85
	return 0;
}

86
static int f_fwd_jit(struct pp_argline *l, int lineno, struct pp_globals *ppg,
87 88 89 90 91 92 93 94 95
			union pp_cfg_arg *arg)
{
	struct sim_ppi_arch_data *data;
	data = SIM_PPI_ARCH(pp_sim_get_master(ppg));
	data->n_delay.jit_ns = arg->i;
	return 0;
}


96
static int f_bckwd_jit(struct pp_argline *l, int lineno, struct pp_globals *ppg,
97 98 99 100 101 102 103 104
			union pp_cfg_arg *arg)
{
	struct sim_ppi_arch_data *data;
	data = SIM_PPI_ARCH(pp_sim_get_slave(ppg));
	data->n_delay.jit_ns = arg->i;
	return 0;
}

105
static int f_jit(struct pp_argline *l, int lineno, struct pp_globals *ppg,
106 107
			union pp_cfg_arg *arg)
{
108 109
	f_fwd_jit(l, lineno, ppg, arg);
	f_bckwd_jit(l, lineno, ppg, arg);
110 111 112
	return 0;
}

113
static int f_iter(struct pp_argline *l, int lineno, struct pp_globals *ppg,
114 115
			union pp_cfg_arg *arg)
{
116
	SIM_PPG_ARCH(ppg)->sim_iter_max = arg->i;
117 118 119
	return 0;
}

120
struct pp_argline pp_arch_arglines[] = {
121 122 123 124 125 126 127 128 129 130 131
	LEGACY_OPTION(f_ppm_real,	"sim_ppm_real",		ARG_INT),
	LEGACY_OPTION(f_ppm_servo,	"sim_init_ppm_servo",	ARG_INT),
	LEGACY_OPTION(f_ofm,		"sim_init_ofm",		ARG_TIME),
	LEGACY_OPTION(f_init_time,	"sim_init_master_time", ARG_TIME),
	LEGACY_OPTION(f_t_prop,		"sim_t_prop_ns",	ARG_INT),
	LEGACY_OPTION(f_fwd_t_prop,	"sim_fwd_t_prop_ns",	ARG_INT),
	LEGACY_OPTION(f_bckwd_t_prop,	"sim_bckwd_t_prop",	ARG_INT),
	LEGACY_OPTION(f_jit,		"sim_jit_ns",		ARG_INT),
	LEGACY_OPTION(f_fwd_jit,	"sim_fwd_jit_ns",	ARG_INT),
	LEGACY_OPTION(f_bckwd_jit,	"sim_bckwd_jit_ns",	ARG_INT),
	LEGACY_OPTION(f_iter,		"sim_iter_max",		ARG_TIME),
132 133 134 135
	{}
};