Jukka Rissanen | 580596c | 2018-01-24 15:20:21 +0200 | [diff] [blame] | 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 | |
Flavio Ceolin | 67ca176 | 2018-09-14 10:43:44 -0700 | [diff] [blame] | 13 | #ifndef ZEPHYR_INCLUDE_NET_PTP_TIME_H_ |
| 14 | #define ZEPHYR_INCLUDE_NET_PTP_TIME_H_ |
Jukka Rissanen | 580596c | 2018-01-24 15:20:21 +0200 | [diff] [blame] | 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 | |
| 25 | #ifdef __cplusplus |
| 26 | extern "C" { |
| 27 | #endif |
| 28 | |
| 29 | /** |
| 30 | * @brief Precision Time Protocol Timestamp format. |
| 31 | * |
| 32 | * This structure represents a timestamp according |
| 33 | * to the Precision Time Protocol standard. |
| 34 | * |
| 35 | * Seconds are encoded as a 48 bits unsigned integer. |
| 36 | * Nanoseconds are encoded as a 32 bits unsigned integer. |
| 37 | */ |
| 38 | struct net_ptp_time { |
| 39 | /** Seconds encoded on 48 bits. */ |
| 40 | union { |
| 41 | struct { |
| 42 | #if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ |
| 43 | u32_t low; |
| 44 | u16_t high; |
| 45 | u16_t unused; |
| 46 | #elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ |
| 47 | u16_t unused; |
| 48 | u16_t high; |
| 49 | u32_t low; |
| 50 | #else |
| 51 | #error "Unknown byte order" |
| 52 | #endif |
| 53 | } _sec; |
| 54 | u64_t second; |
| 55 | }; |
| 56 | |
| 57 | /** Nanoseconds. */ |
| 58 | u32_t nanosecond; |
| 59 | }; |
| 60 | |
| 61 | #ifdef __cplusplus |
| 62 | } |
| 63 | #endif |
| 64 | |
| 65 | /** |
Tomasz Gorochowik | 792dfd4 | 2018-08-21 13:42:53 +0200 | [diff] [blame] | 66 | * @brief Precision Time Protocol Extended Timestamp format. |
| 67 | * |
| 68 | * This structure represents an extended timestamp according |
| 69 | * to the Precision Time Protocol standard. |
| 70 | * |
| 71 | * Seconds are encoded as 48 bits unsigned integer. |
| 72 | * Fractional nanoseconds are encoded as 48 bits, their unit |
| 73 | * is 2*(-16) ns. |
| 74 | */ |
| 75 | struct net_ptp_extended_time { |
| 76 | /** Seconds encoded on 48 bits. */ |
| 77 | union { |
| 78 | struct { |
| 79 | #if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ |
| 80 | u32_t low; |
| 81 | u16_t high; |
| 82 | u16_t unused; |
| 83 | #elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ |
| 84 | u16_t unused; |
| 85 | u16_t high; |
| 86 | u32_t low; |
| 87 | #else |
| 88 | #error "Unknown byte order" |
| 89 | #endif |
| 90 | } _sec; |
| 91 | u64_t second; |
| 92 | }; |
| 93 | |
| 94 | /** Fractional nanoseconds on 48 bits. */ |
| 95 | union { |
| 96 | struct { |
| 97 | #if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ |
| 98 | u32_t low; |
| 99 | u16_t high; |
| 100 | u16_t unused; |
| 101 | #elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ |
| 102 | u16_t unused; |
| 103 | u16_t high; |
| 104 | u32_t low; |
| 105 | #else |
| 106 | #error "Unknown byte order" |
| 107 | #endif |
| 108 | } _fns; |
| 109 | u64_t fract_nsecond; |
| 110 | }; |
| 111 | } __packed; |
| 112 | |
| 113 | /** |
Jukka Rissanen | 580596c | 2018-01-24 15:20:21 +0200 | [diff] [blame] | 114 | * @} |
| 115 | */ |
| 116 | |
Flavio Ceolin | 67ca176 | 2018-09-14 10:43:44 -0700 | [diff] [blame] | 117 | #endif /* ZEPHYR_INCLUDE_NET_PTP_TIME_H_ */ |