1 /*
2 * Copyright (c) 2018 Intel Corporation.
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6
7 #include <zephyr/logging/log.h>
8 LOG_MODULE_REGISTER(net_gptp_sample, LOG_LEVEL_DBG);
9
10 #include <zephyr/kernel.h>
11 #include <errno.h>
12
13 #include <zephyr/net/net_core.h>
14 #include <zephyr/net/net_l2.h>
15 #include <zephyr/net/net_if.h>
16 #include <zephyr/net/ethernet.h>
17 #include <zephyr/net/gptp.h>
18
19 extern void init_testing(void);
20
21 static struct gptp_phase_dis_cb phase_dis;
22
gptp_phase_dis_cb(uint8_t * gm_identity,uint16_t * time_base,struct gptp_scaled_ns * last_gm_ph_change,double * last_gm_freq_change)23 static void gptp_phase_dis_cb(uint8_t *gm_identity,
24 uint16_t *time_base,
25 struct gptp_scaled_ns *last_gm_ph_change,
26 double *last_gm_freq_change)
27 {
28 char output[sizeof("xx:xx:xx:xx:xx:xx:xx:xx")];
29 static uint8_t id[8];
30
31 if (memcmp(id, gm_identity, sizeof(id))) {
32 memcpy(id, gm_identity, sizeof(id));
33
34 LOG_DBG("GM %s last phase %d.%" PRId64 "",
35 gptp_sprint_clock_id(gm_identity, output, sizeof(output)),
36 last_gm_ph_change->high,
37 last_gm_ph_change->low);
38 }
39 }
40
init_app(void)41 static int init_app(void)
42 {
43 gptp_register_phase_dis_cb(&phase_dis, gptp_phase_dis_cb);
44
45 return 0;
46 }
47
main(void)48 int main(void)
49 {
50 init_app();
51
52 init_testing();
53 return 0;
54 }
55