Commit c70c124a authored by Pietro Fezzardi's avatar Pietro Fezzardi Committed by Alessandro Rubini

arch-sim: added config option "sim_duration_sec"

It sets how much time the simulator should simulate. The default value
is set to 3600 so that running the simulator without specifying the
sim_duration_sec option will result in a simulation representing an hour
of real time
parent 3d49a8c9
......@@ -54,7 +54,7 @@ void sim_main_loop(struct pp_globals *ppg)
delay_ns = run_all_state_machines(ppg) * 1000LL * 1000LL;
while (1) {
while (data->duration_ns >= 0) {
/*
* If Ebest was changed in previous loop, run best
* master clock before checking for new packets, which
......@@ -103,4 +103,5 @@ void sim_main_loop(struct pp_globals *ppg)
sim_fast_forward_ns(ppg, delay_ns);
delay_ns = run_all_state_machines(ppg) * 1000LL * 1000LL;
}
return;
}
......@@ -57,6 +57,7 @@ struct sim_pending_pkt {
struct sim_ppg_arch_data {
int n_pending;
struct sim_pending_pkt pending[64];
int64_t duration_ns;
};
static inline struct sim_ppg_arch_data *SIM_PPG_ARCH(struct pp_globals *ppg)
......
......@@ -110,6 +110,14 @@ static int f_jit(int lineno, struct pp_globals *ppg,
return 0;
}
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;
}
struct pp_argline pp_arch_arglines[] = {
{f_ppm_real, "sim_ppm_real", ARG_INT},
{f_ppm_servo, "sim_init_ppm_servo", ARG_INT},
......@@ -121,6 +129,7 @@ struct pp_argline pp_arch_arglines[] = {
{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},
{f_duration, "sim_duration_sec", ARG_TIME},
{}
};
......
......@@ -121,6 +121,7 @@ int main(int argc, char **argv)
sim_set_global_DS(&ppg->pp_instances[SIM_MASTER]);
pp_config_string(ppg, strdup("port SIM_MASTER; iface MASTER;"
"proto udp; role master;"
"sim_duration_sec 3600;" // one hour
"sim_init_master_time 10.0;"));
/* parse commandline for configuration options */
......
......@@ -39,6 +39,7 @@ int sim_fast_forward_ns(struct pp_globals *ppg, int64_t ff_ns)
}
}
data->duration_ns -= ff_ns;
return 0;
}
......
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