资源简介
基于IEEE 1588协议的精确时钟同步实现代码
代码片段和文件信息
/*-
* Copyright (c) 2009-2011 George V. Neville-Neil Steven Kreuzer
* Martin Burnicki Gael Mace Alexandre Van Kempen
* Copyright (c) 2005-2008 Kendall Correll Aidan Williams
*
* All Rights Reserved
*
* Redistribution and use in source and binary forms with or without
* modification are permitted provided that the following conditions are
* met:
* 1. Redistributions of source code must retain the above copyright notice
* this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHORS ‘‘AS IS‘‘ AND ANY EXPRESS OR
* IMPLIED WARRANTIES INCLUDING BUT NOT LIMITED TO THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT INDIRECT INCIDENTAL SPECIAL EXEMPLARY OR
* CONSEQUENTIAL DAMAGES (INCLUDING BUT NOT LIMITED TO PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE DATA OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY
* WHETHER IN CONTRACT STRICT LIABILITY OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/**
* @file arith.c
* @date Tue Jul 20 16:12:51 2010
*
* @brief Time format conversion routines and additional math functions.
*
*
*/
#include “ptpd.h“
void
integer64_to_internalTime(Integer64 bigint TimeInternal * internal)
{
int sign;
int64_t scaledNanoseconds;
scaledNanoseconds = bigint.msb;
scaledNanoseconds <<=32;
scaledNanoseconds += bigint.lsb;
/*determine sign of result big integer number*/
if (scaledNanoseconds < 0)
{
scaledNanoseconds = -scaledNanoseconds;
sign = -1;
}
else
{
sign = 1;
}
/*fractional nanoseconds are excluded (see 5.3.2)*/
scaledNanoseconds >>= 16;
internal->seconds = sign * (scaledNanoseconds / 1000000000);
internal->nanoseconds = sign * (scaledNanoseconds % 1000000000);
}
void
fromInternalTime(TimeInternal * internal Timestamp * external)
{
/*
* fromInternalTime is only used to convert time given by the system
* to a timestamp As a consequence no negative value can normally
* be found in (internal)
*
* Note that offsets are also represented with TimeInternal structure
* and can be negative but offset are never convert into Timestamp
* so there is no problem here.
*/
if ((internal->seconds & ~INT_MAX) ||
(internal->nanoseconds & ~INT_MAX)) {
DBG(“Negative value canno‘t be converted into timestamp \n“);
return;
} else {
external->secondsField.lsb = internal->seconds;
external->nanosecondsField = internal->nanoseconds;
external->secondsField.msb = 0;
- 上一篇:卫星通信导论 习题解答
- 下一篇:libv4l-0.6.2-test.tar.gz
评论
共有 条评论