Commit feb613eb authored by Aurelio Colosimo's avatar Aurelio Colosimo

ppsi: fix "calibration force" command

tests/measure_t24p.c used a mix of ptp-noposix and ppsi net functions, and
ppsi case did not work properly.
Now they have been distinguished and ppsi its own system.
Signed-off-by: Aurelio Colosimo's avatarAurelio Colosimo <aurelio@aureliocolosimo.it>
parent 394cc5e4
ppsi @ f27f7319
Subproject commit 8f2add6b1142041e52f2d771c2731b6e2c6df3e8
Subproject commit f27f7319a87893c5672be10f311adaff529bb79f
......@@ -26,12 +26,8 @@
#include <ptpd_netif.h>
#ifdef CONFIG_PPSI
#include <ppsi/ppsi.h>
#define UNPACK_HEADER msg_unpack_header
#define UNPACK_FOLLOWUP msg_unpack_follow_up
#else
#include "ptpd.h"
#define UNPACK_HEADER msgUnpackHeader
#define UNPACK_FOLLOWUP msgUnpackFollowUp
#endif
#if 0 /* not used, currently */
......@@ -57,6 +53,69 @@ static void purge_socket(wr_socket_t * sock)
update_rx_queues();
}
#ifdef CONFIG_PPSI
extern struct pp_instance ppi_static;
static struct pp_instance *ppi = &ppi_static;
static int meas_phase_range(wr_socket_t * sock, int phase_min, int phase_max,
int phase_step, struct meas_entry *results)
{
char buf[128];
TimeInternal ts_rx, ts_sync = {0,};
MsgHeader *mhdr;
int setpoint = phase_min, i = 0, phase;
mhdr = &ppi->msg_tmp_header;
spll_set_phase_shift(SPLL_ALL_CHANNELS, phase_min);
while (spll_shifter_busy(0)) ;
purge_socket(sock);
i = 0;
while (setpoint <= phase_max) {
ptpd_netif_get_dmtd_phase(sock, &phase);
update_rx_queues();
int n = pp_recv_packet(ppi, buf, 128, &ts_rx);
if (n > 0) {
msg_unpack_header(ppi, buf);
if (mhdr->messageType == 0)
assign_TimeInternal(&ts_sync, &ts_rx);
else if (mhdr->messageType == 8 && ts_sync.correct) {
MsgFollowUp fup;
msg_unpack_follow_up(buf, &fup);
mprintf("Shift: %d/%dps [step %dps] \r",
setpoint, phase_max, phase_step);
results[i].phase = phase;
results[i].phase_sync = ts_sync.phase;
results[i].ahead = ts_sync.raw_ahead;
results[i].delta_ns =
fup.preciseOriginTimestamp.
nanosecondsField - ts_sync.nanoseconds;
results[i].delta_ns +=
(fup.preciseOriginTimestamp.secondsField.
lsb - ts_sync.seconds) * 1000000000;
setpoint += phase_step;
spll_set_phase_shift(0, setpoint);
while (spll_shifter_busy(0)) ;
purge_socket(sock);
ts_sync.correct = 0;
i++;
}
}
}
mprintf("\n");
return i;
}
#else
static int meas_phase_range(wr_socket_t * sock, int phase_min, int phase_max,
int phase_step, struct meas_entry *results)
......@@ -80,12 +139,12 @@ static int meas_phase_range(wr_socket_t * sock, int phase_min, int phase_max,
int n = ptpd_netif_recvfrom(sock, &from, buf, 128, &ts_rx);
if (n > 0) {
UNPACK_HEADER(buf, &mhdr);
msgUnpackHeader(buf, &mhdr);
if (mhdr.messageType == 0)
ts_sync = ts_rx;
else if (mhdr.messageType == 8 && ts_sync.correct) {
MsgFollowUp fup;
UNPACK_FOLLOWUP(buf, &fup);
msgUnpackFollowUp(buf, &fup);
mprintf("Shift: %d/%dps [step %dps] \r",
setpoint, phase_max, phase_step);
......@@ -113,6 +172,8 @@ static int meas_phase_range(wr_socket_t * sock, int phase_min, int phase_max,
return i;
}
#endif /* CONFIG_PPSI else CONFIG_PTPNOPOSIX*/
static int find_transition(struct meas_entry *results, int n, int positive)
{
int i;
......@@ -133,6 +194,13 @@ int measure_t24p(int *value)
int i, nr;
struct meas_entry results[128];
#ifdef CONFIG_PPSI
if (!NP(ppi)->inited) {
if (pp_net_init(ppi) < 0)
return -1;
NP(ppi)->inited = 1;
}
#endif
spll_enable_ptracker(0, 1);
sock_addr.family = PTPD_SOCK_RAW_ETHERNET; // socket type
......@@ -189,6 +257,11 @@ int measure_t24p(int *value)
mprintf("Verification... \n");
nr = meas_phase_range(sock, 0, 16000, 500, results);
#ifdef CONFIG_PPSI
pp_net_shutdown(ppi);
NP(ppi)->inited = 0;
#endif
for (i = 0; i < nr; i++)
mprintf("phase_dmtd: %d delta_ns: %d, phase_sync: %d\n",
results[i].phase, results[i].delta_ns,
......
......@@ -22,7 +22,8 @@
#include "uart.h"
static int ptp_enabled = 0, ptp_mode = WRC_MODE_UNKNOWN;
static struct pp_instance ppi_static;
struct pp_instance ppi_static; /* FIXME: no more static, because used in
tests/measure_t24p.c */
int pp_diag_verbosity = CONFIG_PPSI_VERBOSITY;
/*ppi fields*/
......
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