此方法用于初始化 RiCOSTimer 对象。
RiCBoolean RiCOSTimer_init (RiCOSTimer *const me,
timeUnit ptime, void (*cbkfunc)(void *),
void *params);
me
这是要初始化的 RiCOSTimer 对象
pTime
这是计时器的各个节拍之间的间隔时间。在大多数适配器中,时间单位都为毫秒;但是,这取决于特定的适配器实现。
cbkfunc
这是节拍计时器回调函数,用于通知计时器客户机已发出节拍。
params
这是回调函数的参数。
如果成功,那么此方法返回 RiCTRUE。
RiCBoolean RiCOSTimer_init(RiCOSTimer * const me,
timeUnit ptime, void (*cbkfunc)(void *), void *params)
{
if (me == NULL) return RiCFALSE;
me->cbkfunc = cbkfunc;
me->param = params;
if (((RiCTimerManager*)params)->realTimeModel) {
/**** VxWorks TickTimer(Real Time) ****/
me->m_Time = ptime;
/* Create a thread that runs the bridge, passing
this as an argument. */
me->ticks = cvrtTmInMStoTicks(me->m_Time);
me->hThread = taskSpawn("timer", PRIORITY_HIGH, 0,
SMALL_STACK, (int (*)())bridge,
(int)(void *)me /*p1*/, 0,0,0,0,0,0,0,0,0 );
return me->hThread != ERROR;
}
else {
/**** IdleTimer (Simulated Time) ****/
me->m_Time = 0; /* Just create context-switch
until the system enters idle mode. */
me->hThread = taskSpawn("timer", PRIORITY_LOW, 0,
SMALL_STACK, (int (*)())bridge, (int)(void*)me,
0,0,0,0,0,0,0,0,0);
return RiCTRUE;
}
}