Commit 0a49d0dd authored by Alessandro Rubini's avatar Alessandro Rubini

wrpc: add faults in timestamps

Signed-off-by: Alessandro Rubini's avatarAlessandro Rubini <rubini@gnudd.com>
parent 9ce04d1b
......@@ -12,6 +12,7 @@
extern struct pp_instance ppi_static;
extern int frame_rx_delay_us;
extern struct pp_time faulty_stamps[6];
static int cmd_fault(const char *args[])
{
......@@ -33,8 +34,27 @@ static int cmd_fault(const char *args[])
pp_printf("delaying %i us on rx frame\n", frame_rx_delay_us);
return 0;
}
if (args[0] && !strcmp(args[0], "stamp")) {
int i, v;
struct pp_time *t;
/* input is hex, output is decimal (ps) */
pp_printf("timestamp offset:");
for (i = 0; i < 6; i++) {
t = faulty_stamps + i;
if (args[i + 1]) {
fromhex(args[i + 1], &v);
t->scaled_nsecs = v;
}
pp_printf(" %i ps",
(int)((t->scaled_nsecs * 1000) >> 16));
}
pp_printf("\n");
}
pp_printf("Use: \"fault drop [<rxdrop> <txdrop>]\" (0..999)\n");
pp_printf(" \"fault delay [<usecs>]\"\n");
pp_printf(" \"fault stamp [<hex-offset> ...]\"\n");
return -EINVAL;
}
......
#include <ppsi/ppsi.h>
#include <ppsi/assert.h>
#include "wr-api.h"
#include <libwr/shmem.h>
......@@ -8,6 +9,23 @@
#define ARCH_IS_WRS 0
#endif
#ifdef CONFIG_WRPC_FAULTS
#define HAS_FAULTS 1
#else
#define HAS_FAULTS 0
#endif
struct pp_time faulty_stamps[6]; /* if unused, dropped at link time */
static void apply_faulty_stamp(struct wr_servo_state *s, int index)
{
if (HAS_FAULTS) {
assert(index >= 1 && index <= 6, "Wrong T index %i\n", index);
pp_time_add(&s->t1 + index - 1, faulty_stamps + index - 1);
}
}
#define WR_SERVO_OFFSET_STABILITY_THRESHOLD 60 /* psec */
#define FIX_ALPHA_FRACBITS 40
......@@ -198,8 +216,8 @@ int wr_servo_got_sync(struct pp_instance *ppi, struct pp_time *t1,
struct wr_servo_state *s =
&((struct wr_data *)ppi->ext_data)->servo_state;
s->t1 = *t1;
s->t2 = *t2;
s->t1 = *t1; apply_faulty_stamp(s, 1);
s->t2 = *t2; apply_faulty_stamp(s, 2);
got_sync = 1;
return 0;
}
......@@ -211,13 +229,12 @@ int wr_servo_got_delay(struct pp_instance *ppi)
wrs_shm_write(ppsi_head, WRS_SHM_WRITE_BEGIN);
s->t3 = ppi->t3;
/* s->t3.phase = 0; */
s->t4 = ppi->t4;
s->t3 = ppi->t3; apply_faulty_stamp(s, 3);
s->t4 = ppi->t4; apply_faulty_stamp(s, 4);
if (CONFIG_HAS_P2P && ppi->mech == PP_P2P_MECH) {
s->t5 = ppi->t5;
s->t6 = ppi->t6;
s->t5 = ppi->t5; apply_faulty_stamp(s, 5);
s->t6 = ppi->t6; apply_faulty_stamp(s, 6);
wr_p2p_delay(ppi, s);
}
......
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