sim-conf.c 3.37 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
/*
 * 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"

static int f_ppm_real(int lineno, struct pp_globals *ppg,
			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);
	SIM_PPI_ARCH(ppi_slave)->time.freq_ppm_real = arg->i * 1000;
	return 0;
}

static int f_ppm_servo(int lineno, struct pp_globals *ppg,
			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);
	SIM_PPI_ARCH(ppi_slave)->time.freq_ppm_servo = arg->i * 1000;
	return 0;
}

static int f_ofm(int lineno, struct pp_globals *ppg,
			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;
}

static int f_init_time(int lineno, struct pp_globals *ppg,
			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 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112
static int f_fwd_t_prop(int lineno, struct pp_globals *ppg,
			union pp_cfg_arg *arg)
{
	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;
}

static int f_bckwd_t_prop(int lineno, struct pp_globals *ppg,
			union pp_cfg_arg *arg)
{
	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;
}

static int f_t_prop(int lineno, struct pp_globals *ppg,
			union pp_cfg_arg *arg)
{
	f_fwd_t_prop(lineno, ppg, arg);
	f_bckwd_t_prop(lineno, ppg, arg);
	return 0;
}

static int f_fwd_jit(int lineno, struct pp_globals *ppg,
			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;
}


static int f_bckwd_jit(int lineno, struct pp_globals *ppg,
			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;
}

static int f_jit(int lineno, struct pp_globals *ppg,
			union pp_cfg_arg *arg)
{
	f_fwd_jit(lineno, ppg, arg);
	f_bckwd_jit(lineno, ppg, arg);
	return 0;
}

113 114 115 116 117 118 119 120
static int f_duration(int lineno, struct pp_globals *ppg,
			union pp_cfg_arg *arg)
{
	SIM_PPG_ARCH(ppg)->duration_ns = arg->ts.tv_nsec +
				arg->ts.tv_sec * (long long)PP_NSEC_PER_SEC;
	return 0;
}

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