flexPTP 1.0
An IEEE 1588 PTP implementation designed for microcontrollers
Loading...
Searching...
No Matches
format_utils.c File Reference
#include "format_utils.h"
#include <stdint.h>

Go to the source code of this file.

Macros

#define LOG_INTERVAL_LOOKUP_OFFSET   (6)
 Index associated with the 1s logarithmic interval.
 

Functions

uint16_t ptp_logi2ms (int8_t logi)
 
int8_t ptp_ms2logi (uint16_t ms)
 
uint64_t FLEXPTP_ntohll (uint64_t in)
 
uint64_t FLEXPTP_htonll (uint64_t in)
 

Variables

static uint16_t sLogIntervalMs [] = { 15, 31, 62, 125, 250, 500, 1000, 2000, 4000, 8000, 0 }
 

Macro Definition Documentation

◆ LOG_INTERVAL_LOOKUP_OFFSET

#define LOG_INTERVAL_LOOKUP_OFFSET   (6)

Index associated with the 1s logarithmic interval.

Definition at line 6 of file format_utils.c.

Function Documentation

◆ FLEXPTP_htonll()

uint64_t FLEXPTP_htonll ( uint64_t  in)

Function to swap byte order, convert LE representation to BE. The naming complies with other flexPTP host->network conversion function namings.

Parameters
invalue in BE representation
Returns
value in LE representation

Definition at line 35 of file format_utils.c.

◆ FLEXPTP_ntohll()

uint64_t FLEXPTP_ntohll ( uint64_t  in)

Function to swap byte order, convert BE representation to LE. The naming complies with other flexPTP network->host conversion function namings.

Parameters
invalue in BE representation
Returns
value in LE representation

Definition at line 30 of file format_utils.c.

◆ ptp_logi2ms()

uint16_t ptp_logi2ms ( int8_t  logi)

Convert logarithmic interval designator code to a milliseconds value. Input must be in the inclusive range of [-6, 3].

The function emulates the execution of the following computation: 2^(n) * 1000

Parameters
logiPTP-defined logarithmic interval code
Returns
closest defined period in milliseconds

Definition at line 14 of file format_utils.c.

◆ ptp_ms2logi()

int8_t ptp_ms2logi ( uint16_t  ms)

Convert millisecond period value to PTP-defined logarithmic interval designator code. Input must be a value from the following set: (15, 31, 62, 125, 250, 500, 1000, 2000, 4000, 8000).

This function mimics the following computation: round(log2(T/1000))

Parameters
msperiod in milliseconds. Values of above valid input set must be respected.
Returns
PTP-defined logarithmic interval code

Definition at line 19 of file format_utils.c.

Variable Documentation

◆ sLogIntervalMs

uint16_t sLogIntervalMs[] = { 15, 31, 62, 125, 250, 500, 1000, 2000, 4000, 8000, 0 }
static

Lookup table for log msg. period to ms conversion (ms values are floor-rounded).

Definition at line 11 of file format_utils.c.