#include "target.h"
#include "xcp.h"
#include "LocatedVars.h"
#include "osek.h"
/**
* This task is activated every 10ms.
*/
long OSTICKDURATION;
TASK( Task10ms )
{
void XCP_FN_TYPE Xcp_CmdProcessor( void );
uint32 startTime = GetQueryPerformanceCounter();
/* Trigger DAQ for the 10ms XCP raster. */
if( XCPEVENT_DAQ_OVERLOAD & Xcp_DoDaqForEvent_10msRstr() )
{
++numDaqOverload10ms;
}
/* Update those variables which are modified every 10ms. */
counter16 += slope16;
/* Trigger STIM for the 10ms XCP raster. */
if( enableBypass10ms )
{
if( XCPEVENT_MISSING_DTO & Xcp_DoStimForEvent_10msRstr() )
{
++numMissingDto10ms;
}
}
duration10ms = (uint32)( ( GetQueryPerformanceCounter() - startTime ) / STOPWATCH_TICKS_PER_US );
}
从 C++ 同步到某个精确时钟以在特定时间间隔调用函数(在正常情况下几乎没有抖动)的最简单(和/或最好)方法是什么?我现在在WINDOWS操作系统上工作。
上面的代码适用于 RTAS OSEK,但我想在 Windows 操作系统的特定时间间隔调用函数。任何人都可以用 C++ 语言帮助我吗?
新的应用程序应该使用CreateTimerQueueTimer!
此队列中的计时器(称为计时器队列计时器)是轻量级对象,使您能够指定在指定的到期时间到达时要调用的回调函数。等待操作由线程池中的线程执行。
创建TimerQueue定时器函数 http://msdn.microsoft.com/en-us/library/windows/desktop/ms682485%28v=vs.85%29.aspx。例子:使用定时器队列 http://msdn.microsoft.com/en-us/library/windows/desktop/ms687003%28v=vs.85%29.aspx (C++).
然而,粒度约为 1ms,设置 10ms 可能会导致 9/11ms 出现周期性卡顿。
为了获得更高的分辨率,您可能必须使用设置计时器轮Clock::now()
如上所述here https://stackoverflow.com/a/5524138/1504523.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)