TimeSync

背景

新环境,新挑战,没有环境我们自己创造。车载以太网之前的开发都是基于Vector的开发环境,对于脚本和协议没有深入的了解,恰巧项目的需要,到处搜集资料配合Eth TSync调试。

linuxptp

linuxptp是基于linux环境下专门测试时间同步的软件,遵循协议IEEE1588,同样也支持车载以太网时间同步。

1.下载软件链接
linuxptp - Browse Files at SourceForge.net

2.点击下载最新的安装包。
在这里插入图片描述

3.解压缩安装包。
在这里插入图片描述

4.编译生成可执行文件。
在这里插入图片描述
在这里插入图片描述

5.安装可执行文件。
在这里插入图片描述
6.查看程序版本。

在这里插入图片描述

7.查看网卡是否支持硬件时间戳,从我当前虚拟机查看只支持软件时间戳,我看了网上的文章说如果没有虚拟机应该可以,但是还是要硬件网卡是否支持。

在这里插入图片描述

8.输入命令sudo ptp4l -S -m -i ens33 -f automotive-master.cfg

在这里插入图片描述
在这里插入图片描述

9.Sync报文解析。
在这里插入图片描述

10.Followup报文解析。
在这里插入图片描述

StbM

你好! 这是你第一次使用 Markdown编辑器 所展示的欢迎页。如果你想学习如何使用Markdown编辑器, 可以仔细阅读这篇文章,了解一下Markdown的基本语法知识。

GptpTimeSync_UpdateTime

FUNC(void, CtCddGptpTimeSync_CODE) GptpTimeSync_UpdateTime(void)
{
    uint32 readTicks_u32;

    /* Get the time from StbM and the tick count and put them into the shared memory
     * count the length of time in ticks it takes to do this */
    GptpTimeSync_GetPublishGlobalTime(&readTicks_u32);

    /* Check that the time and ticks were all read within a valid amount of time.
     * If they were swap banks and set the rate deviation too
     * If not do not swap banks, we will re-write the same bank next time.
     */
    if (readTicks_u32 < Gptp_ExpectedProcessingTime_u32)
    {
        GptpTimeSync_SwapGptpBanks_SetRateDeviation(&Gptp_LateTimeWriteCount_u8, &Gptp_BanksValid_u8);
    }
    else
    {
        GptpTimeSync_ProcessSlowGptpTime( &Gptp_ExpectedProcessingTime_u32, &Gptp_LateTimeWriteCount_u8, &Gptp_BanksValid_u8);
    }

    /* We now need to compute the new expected_processing_time */
    if ((readTicks_u32 * GPTP_INIT_FETCH_TIME_REDUCTION_THRES) < (Gptp_ExpectedProcessingTime_u32 * 100U))
    {
        Gptp_ExpectedProcessingTime_u32 = readTicks_u32 * GPTP_INIT_FETCH_TIME_REDUCTION_THRES / 100U;
    }

    GPTP_DEBUG_MAX_FETCH_TIME = Gptp_ExpectedProcessingTime_u32;

    /* Executing fault monitors of GPTP */
    if((GptpTimeSync_Monitor_SamplePeriod_u8 == (uint32)GPTP_TIMESYNC_MONITOR_FAULT_SAMPLE_PERIOD) || (GptpTimeSync_Monitor_SamplePeriod_u8 == (uint32)0))
    {
        GptpTimeSync_Monitor_SamplePeriod_u8 = 0;

        GptpTimeSync_MonitorRateDeviation();

        GptpTimeSync_MonitorSyncWithMaster();

        GptpTimeSync_MonitorTimeStampValidity();

        GptpTimeSync_MonitorLeapPastFuture();
    }
	/* polyspace:begin<RTE:OVFL:Not a defect:Justified> CCB NOT REQ : N/A : Condition cannot happen */
    GptpTimeSync_Monitor_SamplePeriod_u8 += GPTP_TIMESYNC_CYCLE_TIME;
}

GptpTimeSync_GetPublishGlobalTime

    /* Read the tick at the start of the process */
    preTick_u32 = (uint32) Gpt_GetTimeElapsed(GptConf_GptChannelConfiguration_GptChannelConfiguration_1);
    
    /* Read the tick at the start of the process */
    startTick_u32 = (uint32) Gpt_GetTimeElapsed(GptConf_GptChannelConfiguration_GptChannelConfiguration_1);
	
	/*获取时间戳和用户Data*/
	gptpResult = Rte_Call_RpGptpTimeSync_Service_StbmTimeBase_GetCurrentTime(&Gptp_TimeStamp_FGlob, &Gptp_UserData_FGlob);

    /* Get the tick value when current time was obtained */
    stbmClockValue = StbM_GetLastReadTimeOfLocalClockState(Gptp_TimeBaseId);

    /* Get the end tick and calculate the difference in ticks */
    endTick_u32 = (uint32) Gpt_GetTimeElapsed(GptConf_GptChannelConfiguration_GptChannelConfiguration_1);

	if (E_OK == gptpResult)
	{
        if((((Gptp_TimeStamp_FGlob.timeBaseStatus & (uint8)GLOBAL_TIME_BASE_BflMask) >> (uint8)GLOBAL_TIME_BASE_BflPn) == (uint8)GLOBAL_TIME_BASE_BflLn)
		&&((((Gptp_TimeStamp_FGlob.timeBaseStatus & (uint8)TIMEOUT_BflMask) >> (uint8)TIMEOUT_BflPn) == (uint8)TIMEOUT__FALSE)
			&&(((Gptp_TimeStamp_FGlob.timeBaseStatus & (uint8)TIMELEAP_FUTURE_BflMask) >> (uint8)TIMELEAP_FUTURE_BflPn) != (uint8)TIMELEAP_FUTURE_BflLn)
               	&&((((Gptp_TimeStamp_FGlob.timeBaseStatus & (uint8)TIMELEAP_PAST_BflMask) >> (uint8)TIMELEAP_PAST_BflPn) != (uint8)TIMELEAP_PAST_BflLn))))
		{
            SynchronizationStatus = ECU_IN_SYNCRONIZATION;
        }
        else
		{
            SynchronizationStatus = ECU_OUT_OF_SYNCRONIZATION;
        }
	}
  • 6
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值