1 /* 2 * Copyright (c) 2018 Intel Corporation. 3 * 4 * SPDX-License-Identifier: Apache-2.0 5 */ 6 7 /** 8 * @file 9 * @brief Public functions for the Precision Time Protocol time specification. 10 * 11 */ 12 13 #ifndef ZEPHYR_INCLUDE_NET_PTP_TIME_H_ 14 #define ZEPHYR_INCLUDE_NET_PTP_TIME_H_ 15 16 /** 17 * @brief Precision Time Protocol time specification 18 * @defgroup ptp_time PTP time 19 * @ingroup networking 20 * @{ 21 */ 22 23 #include <net/net_core.h> 24 #include <toolchain.h> 25 26 #ifdef __cplusplus 27 extern "C" { 28 #endif 29 30 /** 31 * @brief Precision Time Protocol Timestamp format. 32 * 33 * This structure represents a timestamp according 34 * to the Precision Time Protocol standard. 35 * 36 * Seconds are encoded as a 48 bits unsigned integer. 37 * Nanoseconds are encoded as a 32 bits unsigned integer. 38 */ 39 struct net_ptp_time { 40 /** Seconds encoded on 48 bits. */ 41 union { 42 struct { 43 #if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ 44 uint32_t low; 45 uint16_t high; 46 uint16_t unused; 47 #elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ 48 uint16_t unused; 49 uint16_t high; 50 uint32_t low; 51 #else 52 #error "Unknown byte order" 53 #endif 54 } _sec; 55 uint64_t second; 56 }; 57 58 /** Nanoseconds. */ 59 uint32_t nanosecond; 60 }; 61 62 #ifdef __cplusplus 63 } 64 #endif 65 66 /** 67 * @brief Precision Time Protocol Extended Timestamp format. 68 * 69 * This structure represents an extended timestamp according 70 * to the Precision Time Protocol standard. 71 * 72 * Seconds are encoded as 48 bits unsigned integer. 73 * Fractional nanoseconds are encoded as 48 bits, their unit 74 * is 2*(-16) ns. 75 */ 76 struct net_ptp_extended_time { 77 /** Seconds encoded on 48 bits. */ 78 union { 79 struct { 80 #if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ 81 uint32_t low; 82 uint16_t high; 83 uint16_t unused; 84 #elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ 85 uint16_t unused; 86 uint16_t high; 87 uint32_t low; 88 #else 89 #error "Unknown byte order" 90 #endif 91 } _sec; 92 uint64_t second; 93 }; 94 95 /** Fractional nanoseconds on 48 bits. */ 96 union { 97 struct { 98 #if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ 99 uint32_t low; 100 uint16_t high; 101 uint16_t unused; 102 #elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ 103 uint16_t unused; 104 uint16_t high; 105 uint32_t low; 106 #else 107 #error "Unknown byte order" 108 #endif 109 } _fns; 110 uint64_t fract_nsecond; 111 }; 112 } __packed; 113 114 /** 115 * @} 116 */ 117 118 #endif /* ZEPHYR_INCLUDE_NET_PTP_TIME_H_ */ 119