Use chSysLock() to make sleep

ChibiOS public support forum for topics related to the STMicroelectronics STM32 family of micro-controllers.

Moderator: RoccoMarco

Post Reply
Jessica
Posts: 8
Joined: Fri Dec 13, 2013 3:17 pm

Use chSysLock() to make sleep

Post 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
User avatar
Giovanni
Site Admin
Posts: 14892
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: Use chSysLock() to make sleep

Post 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
Jessica
Posts: 8
Joined: Fri Dec 13, 2013 3:17 pm

Re: Use chSysLock() to make sleep

Post 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
User avatar
Giovanni
Site Admin
Posts: 14892
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: Use chSysLock() to make sleep

Post by Giovanni »

See halPolledDelay() or gptPolledDelay().

For mS-class delays better use chThdSleepMilliseconds().

Giovanni
Jessica
Posts: 8
Joined: Fri Dec 13, 2013 3:17 pm

Re: Use chSysLock() to make sleep

Post 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
Post Reply