背景
新环境,新挑战,没有环境我们自己创造。车载以太网之前的开发都是基于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;
}
}