flexPTP 1.0
An IEEE 1588 PTP implementation designed for microcontrollers
Loading...
Searching...
No Matches
format_utils.c
Go to the documentation of this file.
1/* (C) AndrĂ¡s Wiesner, 2020-2022 */
2
3#include "format_utils.h"
4#include <stdint.h>
5
6#define LOG_INTERVAL_LOOKUP_OFFSET (6)
7
11static uint16_t sLogIntervalMs[] = { 15, 31, 62, 125, 250, 500, 1000, 2000, 4000, 8000, 0 }; // terminating zero as last element
12
13// log interval to milliseconds
14uint16_t ptp_logi2ms(int8_t logi) {
16}
17
18// milliseconds to log interval
19int8_t ptp_ms2logi(uint16_t ms) {
20 uint16_t * pIter = sLogIntervalMs;
21 while (*pIter != 0) {
22 if (*pIter == ms) {
23 break;
24 }
25 }
26 return (int8_t)(pIter - sLogIntervalMs) + LOG_INTERVAL_LOOKUP_OFFSET;
27}
28
29// Network->Host byte order conversion for 64-bit values
30uint64_t FLEXPTP_ntohll(uint64_t in) {
31 unsigned char out[8] = { in >> 56, in >> 48, in >> 40, in >> 32, in >> 24, in >> 16, in >> 8, in };
32 return *(uint64_t*) out;
33}
34
35uint64_t FLEXPTP_htonll(uint64_t in) {
36 return FLEXPTP_ntohll(in);
37}
#define LOG_INTERVAL_LOOKUP_OFFSET
Index associated with the 1s logarithmic interval.
Definition: format_utils.c:6
static uint16_t sLogIntervalMs[]
Definition: format_utils.c:11
uint64_t FLEXPTP_htonll(uint64_t in)
Definition: format_utils.c:35
int8_t ptp_ms2logi(uint16_t ms)
Definition: format_utils.c:19
uint64_t FLEXPTP_ntohll(uint64_t in)
Definition: format_utils.c:30
uint16_t ptp_logi2ms(int8_t logi)
Definition: format_utils.c:14
This module defines format conversion functions between network and host byte order and conversion fu...