Commit 8d4eba82 authored by Alessandro Rubini's avatar Alessandro Rubini

time: fix simulator

Signed-off-by: Alessandro Rubini's avatarAlessandro Rubini <rubini@gnudd.com>
parent d395932e
...@@ -73,7 +73,7 @@ static int pending_received(struct sim_ppg_arch_data *data) ...@@ -73,7 +73,7 @@ static int pending_received(struct sim_ppg_arch_data *data)
} }
static int sim_recv_msg(struct pp_instance *ppi, int fd, void *pkt, int len, static int sim_recv_msg(struct pp_instance *ppi, int fd, void *pkt, int len,
TimeInternal *t) struct pp_time *t)
{ {
ssize_t ret; ssize_t ret;
struct msghdr msg; struct msghdr msg;
...@@ -119,7 +119,7 @@ static int sim_recv_msg(struct pp_instance *ppi, int fd, void *pkt, int len, ...@@ -119,7 +119,7 @@ static int sim_recv_msg(struct pp_instance *ppi, int fd, void *pkt, int len,
ppi->t_ops->get(ppi, t); ppi->t_ops->get(ppi, t);
/* This is not really hw... */ /* This is not really hw... */
pp_diag(ppi, time, 2, "recv stamp: %i.%09i (%s)\n", pp_diag(ppi, time, 2, "recv stamp: %i.%09i (%s)\n",
(int)t->seconds, (int)t->nanoseconds, "user"); (int)t->secs, (int)(t->scaled_nsecs >> 16), "user");
/* If we got a DelayResponse print out the offset from master */ /* If we got a DelayResponse print out the offset from master */
if (((*(Enumeration4 *) (pkt + 0)) & 0x0F) == PPM_DELAY_RESP) { if (((*(Enumeration4 *) (pkt + 0)) & 0x0F) == PPM_DELAY_RESP) {
master_ns = SIM_PPI_ARCH(INST(ppg, SIM_MASTER))->time.current_ns; master_ns = SIM_PPI_ARCH(INST(ppg, SIM_MASTER))->time.current_ns;
...@@ -132,7 +132,7 @@ static int sim_recv_msg(struct pp_instance *ppi, int fd, void *pkt, int len, ...@@ -132,7 +132,7 @@ static int sim_recv_msg(struct pp_instance *ppi, int fd, void *pkt, int len,
} }
static int sim_net_recv(struct pp_instance *ppi, void *pkt, int len, static int sim_net_recv(struct pp_instance *ppi, void *pkt, int len,
TimeInternal *t) struct pp_time *t)
{ {
struct sim_ppg_arch_data *data = SIM_PPG_ARCH(ppi->glbs); struct sim_ppg_arch_data *data = SIM_PPG_ARCH(ppi->glbs);
struct pp_channel *ch; struct pp_channel *ch;
...@@ -165,7 +165,7 @@ static int sim_net_send(struct pp_instance *ppi, void *pkt, int len, ...@@ -165,7 +165,7 @@ static int sim_net_send(struct pp_instance *ppi, void *pkt, int len,
int msgtype) int msgtype)
{ {
int chtype = pp_msgtype_info[msgtype].chtype; int chtype = pp_msgtype_info[msgtype].chtype;
TimeInternal *t = &ppi->last_snt_time; struct pp_time *t = &ppi->last_snt_time;
struct sim_ppi_arch_data *data = SIM_PPI_ARCH(ppi); struct sim_ppi_arch_data *data = SIM_PPI_ARCH(ppi);
struct sockaddr_in addr; struct sockaddr_in addr;
struct sim_pending_pkt pending; struct sim_pending_pkt pending;
......
...@@ -46,32 +46,31 @@ int sim_fast_forward_ns(struct pp_globals *ppg, int64_t ff_ns) ...@@ -46,32 +46,31 @@ int sim_fast_forward_ns(struct pp_globals *ppg, int64_t ff_ns)
return 0; return 0;
} }
static int sim_time_get(struct pp_instance *ppi, TimeInternal *t) static int sim_time_get(struct pp_instance *ppi, struct pp_time *t)
{ {
t->nanoseconds = SIM_PPI_ARCH(ppi)->time.current_ns % t->scaled_nsecs = (SIM_PPI_ARCH(ppi)->time.current_ns %
(long long)PP_NSEC_PER_SEC; (long long)PP_NSEC_PER_SEC) << 16;
t->seconds = (SIM_PPI_ARCH(ppi)->time.current_ns - t->nanoseconds) / t->secs = SIM_PPI_ARCH(ppi)->time.current_ns /
(long long)PP_NSEC_PER_SEC; (long long)PP_NSEC_PER_SEC;
t->correct = 1;
if (!(pp_global_d_flags & PP_FLAG_NOTIMELOG)) if (!(pp_global_d_flags & PP_FLAG_NOTIMELOG))
pp_diag(ppi, time, 2, "%s: %9li.%09li\n", __func__, pp_diag(ppi, time, 2, "%s: %9li.%09li\n", __func__,
(long)t->seconds, (long)t->nanoseconds); (long)t->secs, (long)(t->scaled_nsecs >> 16));
return 0; return 0;
} }
static int sim_time_set(struct pp_instance *ppi, TimeInternal *t) static int sim_time_set(struct pp_instance *ppi, const struct pp_time *t)
{ {
if (!t) { if (!t) {
/* Change the network notion of utc/tai offset */ /* Change the network notion of utc/tai offset */
return 0; return 0;
} }
SIM_PPI_ARCH(ppi)->time.current_ns = t->nanoseconds SIM_PPI_ARCH(ppi)->time.current_ns = (t->scaled_nsecs >> 16)
+ t->seconds * (long long)PP_NSEC_PER_SEC; + t->secs * (long long)PP_NSEC_PER_SEC;
pp_diag(ppi, time, 1, "%s: %9i.%09i\n", __func__, pp_diag(ppi, time, 1, "%s: %9i.%09i\n", __func__,
t->seconds, t->nanoseconds); (int)t->secs, (int)(t->scaled_nsecs >> 16));
return 0; 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