123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348 |
- #ifndef ZEPHYR_INCLUDE_NET_GPTP_H_
- #define ZEPHYR_INCLUDE_NET_GPTP_H_
- #include <net/net_core.h>
- #include <net/ptp_time.h>
- #include <stdbool.h>
- #ifdef __cplusplus
- extern "C" {
- #endif
- #define GPTP_OFFSET_SCALED_LOG_VAR_UNKNOWN 0x436A
- #define GPTP_PRIORITY1_NON_GM_CAPABLE 255
- #define GPTP_PRIORITY1_GM_CAPABLE 248
- #if defined(CONFIG_NET_GPTP_BMCA_PRIORITY2)
- #define GPTP_PRIORITY2_DEFAULT CONFIG_NET_GPTP_BMCA_PRIORITY2
- #else
- #define GPTP_PRIORITY2_DEFAULT 248
- #endif
- struct gptp_scaled_ns {
-
- int32_t high;
-
- int64_t low;
- } __packed;
- struct gptp_uscaled_ns {
-
- uint32_t high;
-
- uint64_t low;
- } __packed;
- #if defined(CONFIG_NEWLIB_LIBC)
- #include <math.h>
- #define GPTP_POW2(exp) pow(2, exp)
- #else
- static inline double gptp_pow2(int exp)
- {
- double res;
- if (exp >= 0) {
- res = 1 << exp;
- } else {
- res = 1.0;
- while (exp++) {
- res /= 2;
- }
- }
- return res;
- }
- #define GPTP_POW2(exp) gptp_pow2(exp)
- #endif
- #define GPTP_POW2_16 65536.0
- #define GPTP_POW2_41 2199023255552.0
- #define GPTP_SYNC_MESSAGE 0x00
- #define GPTP_DELAY_REQ_MESSAGE 0x01
- #define GPTP_PATH_DELAY_REQ_MESSAGE 0x02
- #define GPTP_PATH_DELAY_RESP_MESSAGE 0x03
- #define GPTP_FOLLOWUP_MESSAGE 0x08
- #define GPTP_DELAY_RESP_MESSAGE 0x09
- #define GPTP_PATH_DELAY_FOLLOWUP_MESSAGE 0x0a
- #define GPTP_ANNOUNCE_MESSAGE 0x0b
- #define GPTP_SIGNALING_MESSAGE 0x0c
- #define GPTP_MANAGEMENT_MESSAGE 0x0d
- #define GPTP_IS_EVENT_MSG(msg_type) (!((msg_type) & BIT(3)))
- #define GPTP_CLOCK_ID_LEN 8
- struct gptp_port_identity {
-
- uint8_t clk_id[GPTP_CLOCK_ID_LEN];
-
- uint16_t port_number;
- } __packed;
- struct gptp_flags {
- union {
-
- uint8_t octets[2];
-
- uint16_t all;
- };
- } __packed;
- struct gptp_hdr {
-
- uint8_t message_type:4;
-
- uint8_t transport_specific:4;
-
- uint8_t ptp_version:4;
-
- uint8_t reserved0:4;
-
- uint16_t message_length;
-
- uint8_t domain_number;
-
- uint8_t reserved1;
-
- struct gptp_flags flags;
-
- int64_t correction_field;
-
- uint32_t reserved2;
-
- struct gptp_port_identity port_id;
-
- uint16_t sequence_id;
-
- uint8_t control;
-
- int8_t log_msg_interval;
- } __packed;
- #define GPTP_GET_CURRENT_TIME_USCALED_NS(port, uscaled_ns_ptr) \
- do { \
- (uscaled_ns_ptr)->low = \
- gptp_get_current_time_nanosecond(port) << 16; \
- (uscaled_ns_ptr)->high = 0; \
- } while (false)
- typedef void (*gptp_phase_dis_callback_t)(
- uint8_t *gm_identity,
- uint16_t *time_base,
- struct gptp_scaled_ns *last_gm_ph_change,
- double *last_gm_freq_change);
- struct gptp_phase_dis_cb {
-
- sys_snode_t node;
-
- gptp_phase_dis_callback_t cb;
- };
- struct gptp_clk_src_time_invoke_params {
-
- double last_gm_freq_change;
-
- struct net_ptp_extended_time src_time;
-
- struct gptp_scaled_ns last_gm_phase_change;
-
- uint16_t time_base_indicator;
- };
- void gptp_register_phase_dis_cb(struct gptp_phase_dis_cb *phase_dis,
- gptp_phase_dis_callback_t cb);
- void gptp_unregister_phase_dis_cb(struct gptp_phase_dis_cb *phase_dis);
- void gptp_call_phase_dis_cb(void);
- int gptp_event_capture(struct net_ptp_time *slave_time, bool *gm_present);
- char *gptp_sprint_clock_id(const uint8_t *clk_id, char *output,
- size_t output_len);
- typedef void (*gptp_port_cb_t)(int port, struct net_if *iface,
- void *user_data);
- void gptp_foreach_port(gptp_port_cb_t cb, void *user_data);
- struct gptp_domain *gptp_get_domain(void);
- void gptp_clk_src_time_invoke(struct gptp_clk_src_time_invoke_params *arg);
- struct gptp_hdr *gptp_get_hdr(struct net_pkt *pkt);
- #ifdef __cplusplus
- }
- #endif
- #endif
|