Commit 912d4db3 authored by Alessandro Rubini's avatar Alessandro Rubini

arch-wrpc: add wrpc-time.c, with the time operations

I forgot to fix arch-wrpc when making the time_ops.
Code mainly by Tomasz (wrpc-sw/shell/cmd_time.c)
Signed-off-by: Alessandro Rubini's avatarAlessandro Rubini <rubini@gnudd.com>
parent 2512bece
......@@ -30,6 +30,7 @@ LIBS += -L$A -larch
OBJ-libarch := $A/wrpc-socket.o \
$A/wrpc-io.o \
$A/wrpc-time.o \
$A/wrpc-spll.o \
$A/wrpc-calibration.o \
$A/wrc_ptp_ppsi.o \
......
......@@ -2,40 +2,10 @@
* Alessandro Rubini for CERN, 2011 -- public domain
*/
#include <ppsi/ppsi.h>
#include <uart.h>
#include <pps_gen.h>
#include "wrpc.h"
#include "uart.h" /* wrpc-sw */
void pp_puts(const char *s)
{
uart_write_string(s);
}
void pp_get_tstamp(TimeInternal *t)
{
uint64_t sec;
uint32_t nsec;
shw_pps_gen_get_time(&sec, &nsec);
t->seconds = (int32_t)sec;
t->nanoseconds = (int32_t)nsec;
}
int32_t wrpc_set_tstamp(TimeInternal *t)
{
shw_pps_gen_set_time(t->seconds, t->nanoseconds);
return 0; /* SPEC uses a sort of monotonic tstamp for timers */
}
int wrpc_adj_freq(Integer32 adj)
{
/* FIXME: this adjusts nanoseconds, not frequency */
shw_pps_gen_adjust(PPSG_ADJUST_NSEC, adj);
return -1; /* failure? */
}
int pp_adj_freq(Integer32 adj)
__attribute__((alias("wrpc_adj_freq")));
int32_t pp_set_tstamp(TimeInternal *t)
__attribute__((alias("wrpc_set_tstamp")));
/*
* Alessandro Rubini for CERN, 2013 -- LGPL 2.1 or later
* (Mostly code by Tomasz Wlostowski in wrpc-sw)
*/
#include <ppsi/ppsi.h>
#include "wrpc.h"
#include "pps_gen.h" /* in wrpc-sw */
#include "syscon.h" /* in wrpc-sw */
static int wrpc_time_get(struct pp_instance *ppi, TimeInternal *t)
{
uint64_t sec;
uint32_t nsec;
shw_pps_gen_get_time(&sec, &nsec);
t->seconds = sec;
t->nanoseconds = nsec;
if (!(pp_global_flags & PP_FLAG_NOTIMELOG))
pp_diag(ppi, time, 2, "%s: %9lu.%09li\n", __func__,
(long)sec, (long)nsec);
return 0;
}
static int wrpc_time_set(struct pp_instance *ppi, TimeInternal *t)
{
uint64_t sec;
unsigned long nsec;
sec = t->seconds;
nsec = t->nanoseconds;
shw_pps_gen_set_time(sec, nsec);
pp_diag(ppi, time, 1, "%s: %9lu.%09li\n", __func__,
(long)sec, (long)nsec);
return 0;
}
static int wrpc_time_adjust(struct pp_instance *ppi, long offset_ns,
long freq_ppm)
{
pp_diag(ppi, time, 1, "%s: %li %li\n",
__func__, offset_ns, freq_ppm);
if (offset_ns)
shw_pps_gen_adjust(PPSG_ADJUST_NSEC, offset_ns);
return 0;
}
static unsigned long wrpc_calc_timeout(struct pp_instance *ppi, int millisec)
{
unsigned long now_ms = timer_get_tics();
now_ms += millisec;
return now_ms ? now_ms : 1; /* cannot return 0 */
}
struct pp_time_operations wrpc_time_ops = {
.get = wrpc_time_get,
.set = wrpc_time_set,
.adjust = wrpc_time_adjust,
.calc_timeout = wrpc_calc_timeout,
};
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