Page 1 of 1
Use chSysLock() to make sleep
Posted: Mon Dec 30, 2013 8:28 pm
by Jessica
What is locked after using chSysLock(); ?
Is it possible to make a user defined sleep using chSysLock() and a timer ? (Suppose the timer is already initialized)
void UDSleep (unsigned int sleepDelay){
TIM_SetCounter(TIM2, 0);
TIM_Cmd(TIM2, ENABLE);
chSysLock();
while (TIM_GetCounter(TIM2) < sleepDelay ){
}
chSysUnlock();
}
Thanks,
Jessi
Re: Use chSysLock() to make sleep
Posted: Mon Dec 30, 2013 9:05 pm
by Giovanni
Hi,
It is possible but the delay would degrade the realtime performance of the system because no preemption could occur during the lock.
BTW, something similar is already present in the GPT driver, see gptPolledDelay().
Giovanni
Re: Use chSysLock() to make sleep
Posted: Mon Dec 30, 2013 9:16 pm
by Jessica
Giovanni wrote:Hi,
It is possible but the delay would degrade the realtime performance of the system because no preemption could occur during the lock.
BTW, something similar is already present in the GPT driver, see gptPolledDelay().
Giovanni
Hi,
Thanks for your reply,
Is there anyway to implement a high performance delay?
Jessi
Re: Use chSysLock() to make sleep
Posted: Mon Dec 30, 2013 9:23 pm
by Giovanni
See halPolledDelay() or gptPolledDelay().
For mS-class delays better use chThdSleepMilliseconds().
Giovanni
Re: Use chSysLock() to make sleep
Posted: Tue Dec 31, 2013 1:47 pm
by Jessica
Giovanni wrote:See halPolledDelay() or gptPolledDelay().
For mS-class delays better use chThdSleepMilliseconds().
Giovanni
Thanks.
I need higher resolution than mS so I think halPolledDelay() works for me.
Jessi