Lines Matching refs:ptp_clk
58 __maybe_unused static struct ptp_clock ptp_clk = { 0 }; variable
149 SYS_SLIST_FOR_EACH_CONTAINER(&ptp_clk.ports_list, iter, node) { in clock_forward_management_msg()
171 ptp_clk.default_ds.priority1 = *tlv->data; in clock_management_set()
175 ptp_clk.default_ds.priority2 = *tlv->data; in clock_management_set()
187 memset(&ptp_clk.current_ds, 0, sizeof(struct ptp_current_ds)); in clock_update_grandmaster()
189 memcpy(&ptp_clk.parent_ds.port_id.clk_id, in clock_update_grandmaster()
190 &ptp_clk.default_ds.clk_id, in clock_update_grandmaster()
192 memcpy(&ptp_clk.parent_ds.gm_id, in clock_update_grandmaster()
193 &ptp_clk.default_ds.clk_id, in clock_update_grandmaster()
195 ptp_clk.parent_ds.port_id.port_number = 0; in clock_update_grandmaster()
196 ptp_clk.parent_ds.gm_clk_quality = ptp_clk.default_ds.clk_quality; in clock_update_grandmaster()
197 ptp_clk.parent_ds.gm_priority1 = ptp_clk.default_ds.priority1; in clock_update_grandmaster()
198 ptp_clk.parent_ds.gm_priority2 = ptp_clk.default_ds.priority2; in clock_update_grandmaster()
200 ptp_clk.time_prop_ds.current_utc_offset = 37; /* IEEE 1588-2019 9.4 */ in clock_update_grandmaster()
201 ptp_clk.time_prop_ds.time_src = ptp_clk.time_src; in clock_update_grandmaster()
202 ptp_clk.time_prop_ds.flags = 0; in clock_update_grandmaster()
207 struct ptp_msg *best_msg = (struct ptp_msg *)k_fifo_peek_tail(&ptp_clk.best->messages); in clock_update_time_receiver()
209 ptp_clk.current_ds.steps_rm = 1 + ptp_clk.best->dataset.steps_rm; in clock_update_time_receiver()
211 memcpy(&ptp_clk.parent_ds.gm_id, in clock_update_time_receiver()
214 memcpy(&ptp_clk.parent_ds.port_id, in clock_update_time_receiver()
215 &ptp_clk.best->dataset.sender, in clock_update_time_receiver()
216 sizeof(ptp_clk.best->dataset.sender)); in clock_update_time_receiver()
217 ptp_clk.parent_ds.gm_clk_quality = best_msg->announce.gm_clk_quality; in clock_update_time_receiver()
218 ptp_clk.parent_ds.gm_priority1 = best_msg->announce.gm_priority1; in clock_update_time_receiver()
219 ptp_clk.parent_ds.gm_priority2 = best_msg->announce.gm_priority2; in clock_update_time_receiver()
221 ptp_clk.time_prop_ds.current_utc_offset = best_msg->announce.current_utc_offset; in clock_update_time_receiver()
222 ptp_clk.time_prop_ds.flags = best_msg->header.flags[1]; in clock_update_time_receiver()
228 struct zsock_pollfd *fd = &ptp_clk.pollfd[1]; in clock_check_pollfd()
230 if (ptp_clk.pollfd_valid) { in clock_check_pollfd()
234 SYS_SLIST_FOR_EACH_CONTAINER(&ptp_clk.ports_list, port, node) { in clock_check_pollfd()
242 ptp_clk.pollfd_valid = true; in clock_check_pollfd()
247 struct ptp_default_ds *dds = &ptp_clk.default_ds; in ptp_clock_init()
248 struct ptp_parent_ds *pds = &ptp_clk.parent_ds; in ptp_clock_init()
251 ptp_clk.time_src = (enum ptp_time_src)PTP_TIME_SRC_INTERNAL_OSC; in ptp_clock_init()
282 ptp_clk.phc = net_eth_get_ptp_clock(iface); in ptp_clock_init()
283 if (!ptp_clk.phc) { in ptp_clock_init()
288 ptp_clk.pollfd[0].fd = eventfd(0, EFD_NONBLOCK); in ptp_clock_init()
289 ptp_clk.pollfd[0].events = ZSOCK_POLLIN; in ptp_clock_init()
291 sys_slist_init(&ptp_clk.ports_list); in ptp_clock_init()
293 return &ptp_clk; in ptp_clock_init()
301 ret = zsock_poll(ptp_clk.pollfd, PTP_SOCKET_CNT * ptp_clk.default_ds.n_ports + 1, -1); in ptp_clock_poll_sockets()
302 if (ret > 0 && ptp_clk.pollfd[0].revents) { in ptp_clock_poll_sockets()
305 eventfd_read(ptp_clk.pollfd[0].fd, &value); in ptp_clock_poll_sockets()
308 return &ptp_clk.pollfd[1]; in ptp_clock_poll_sockets()
317 if (!ptp_clk.state_decision_event) { in ptp_clock_handle_state_decision_evt()
321 SYS_SLIST_FOR_EACH_CONTAINER(&ptp_clk.ports_list, port, node) { in ptp_clock_handle_state_decision_evt()
331 ptp_clk.best = best; in ptp_clock_handle_state_decision_evt()
333 SYS_SLIST_FOR_EACH_CONTAINER(&ptp_clk.ports_list, port, node) { in ptp_clock_handle_state_decision_evt()
365 ptp_clk.state_decision_event = false; in ptp_clock_handle_state_decision_evt()
497 SYS_SLIST_FOR_EACH_CONTAINER(&ptp_clk.ports_list, iter, node) { in ptp_clock_management_msg_process()
512 uint64_t delay = ptp_clk.current_ds.mean_delay >> 16; in ptp_clock_synchronize()
514 ptp_clk.timestamp.t1 = egress; in ptp_clock_synchronize()
515 ptp_clk.timestamp.t2 = ingress; in ptp_clock_synchronize()
517 if (!ptp_clk.current_ds.mean_delay) { in ptp_clock_synchronize()
521 offset = ptp_clk.timestamp.t2 - ptp_clk.timestamp.t1 - delay; in ptp_clock_synchronize()
530 ptp_clock_get(ptp_clk.phc, ¤t); in ptp_clock_synchronize()
545 ptp_clock_set(ptp_clk.phc, ¤t); in ptp_clock_synchronize()
550 ptp_clk.current_ds.offset_from_tt = clock_ns_to_timeinterval(offset); in ptp_clock_synchronize()
552 ptp_clock_adjust(ptp_clk.phc, -offset); in ptp_clock_synchronize()
559 ptp_clk.timestamp.t3 = egress; in ptp_clock_delay()
560 ptp_clk.timestamp.t4 = ingress; in ptp_clock_delay()
562 delay = ((ptp_clk.timestamp.t2 - ptp_clk.timestamp.t3) + in ptp_clock_delay()
563 (ptp_clk.timestamp.t4 - ptp_clk.timestamp.t1)) / 2; in ptp_clock_delay()
566 ptp_clk.current_ds.mean_delay = clock_ns_to_timeinterval(delay); in ptp_clock_delay()
571 return &ptp_clk.ports_list; in ptp_clock_ports_list()
576 return (enum ptp_clock_type)ptp_clk.default_ds.type; in ptp_clock_type()
581 return &ptp_clk.default_ds; in ptp_clock_default_ds()
586 return &ptp_clk.parent_ds; in ptp_clock_parent_ds()
591 return &ptp_clk.current_ds; in ptp_clock_current_ds()
596 return &ptp_clk.time_prop_ds; in ptp_clock_time_prop_ds()
601 struct ptp_dataset *ds = &ptp_clk.dataset; in ptp_clock_ds()
603 ds->priority1 = ptp_clk.default_ds.priority1; in ptp_clock_ds()
604 ds->clk_quality = ptp_clk.default_ds.clk_quality; in ptp_clock_ds()
605 ds->priority2 = ptp_clk.default_ds.priority2; in ptp_clock_ds()
609 memcpy(&ds->clk_id, &ptp_clk.default_ds.clk_id, sizeof(ptp_clk_id)); in ptp_clock_ds()
610 memcpy(&ds->sender.clk_id, &ptp_clk.default_ds.clk_id, sizeof(ptp_clk_id)); in ptp_clock_ds()
611 memcpy(&ds->receiver.clk_id, &ptp_clk.default_ds.clk_id, sizeof(ptp_clk_id)); in ptp_clock_ds()
617 return ptp_clk.best ? &ptp_clk.best->dataset : NULL; in ptp_clock_best_foreign_ds()
624 SYS_SLIST_FOR_EACH_CONTAINER(&ptp_clk.ports_list, port, node) { in ptp_clock_port_from_iface()
635 ptp_clk.pollfd_valid = false; in ptp_clock_pollfd_invalidate()
640 eventfd_write(ptp_clk.pollfd[0].fd, 1); in ptp_clock_signal_timeout()
645 ptp_clk.state_decision_event = true; in ptp_clock_state_decision_req()
650 ptp_clk.default_ds.n_ports++; in ptp_clock_port_add()
651 sys_slist_append(&ptp_clk.ports_list, &port->node); in ptp_clock_port_add()
656 return ptp_clk.best; in ptp_clock_best_time_transmitter()