chThdSleepMilliseconds( 1000 ) Weird ?

ChibiOS public support forum for all topics not covered by a specific support forum.

Moderators: RoccoMarco, lbednarz, tfAteba

Tabulous
Posts: 518
Joined: Fri May 03, 2013 12:02 pm
Has thanked: 7 times
Been thanked: 18 times

Re: chThdSleepMilliseconds( 1000 ) Weird ?

Post by Tabulous »

Marco wrote:The timer callback is called in interrupt context. While in that timer callback the scheduler is blocked.
You could use gptPolledDelay() from within a thread like Giovanni suggested. This way the scheduler is able to preempt the i2c operation to do other stuff, like toggling your led.


This is missing the point, gpt was use to ensure precise timing, this cannot be achieved using a thread.... there is too much jitter.

Lets take a step back.....

This is what i'm tring to achieve:-

sampling of device on i2cbus @ 100hz with very little or no jitter.
cant use chibios i2c driver as it fails and locks up, so must be bit banged.
utzig
Posts: 359
Joined: Sat Jan 07, 2012 6:22 pm
Has thanked: 1 time
Been thanked: 20 times

Re: chThdSleepMilliseconds( 1000 ) Weird ?

Post by utzig »

What MCU are you using? What I2C problems are you having?
Tabulous
Posts: 518
Joined: Fri May 03, 2013 12:02 pm
Has thanked: 7 times
Been thanked: 18 times

Re: chThdSleepMilliseconds( 1000 ) Weird ?

Post by Tabulous »

utzig wrote:What MCU are you using? What I2C problems are you having?


STM32F10x

This is a know issue, the driver can lock up but it's down to the silicon
User avatar
Giovanni
Site Admin
Posts: 14895
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: chThdSleepMilliseconds( 1000 ) Weird ?

Post by Giovanni »

Isn't F3xx pin compatible or very close to the F1xx? It includes a new I2C.

Giovanni
Tabulous
Posts: 518
Joined: Fri May 03, 2013 12:02 pm
Has thanked: 7 times
Been thanked: 18 times

Re: chThdSleepMilliseconds( 1000 ) Weird ?

Post by Tabulous »

Giovanni wrote:Isn't F3xx pin compatible or very close to the F1xx? It includes a new I2C.

Giovanni


that is not a option as this is an existing design.

So back to the the problem in hand ? :-)

This is what i'm tring to achieve:-

sampling of device on i2cbus @ 100hz with very little or no jitter.
cant use chibios i2c driver as it fails and locks up, so must be bit banged.
Last edited by Tabulous on Wed Nov 30, 2016 5:34 pm, edited 1 time in total.
User avatar
Giovanni
Site Admin
Posts: 14895
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: chThdSleepMilliseconds( 1000 ) Weird ?

Post by Giovanni »

Anyway, threading does not add much jitter in itself if priorities are assigned correctly, also consider that you could raise thread priority around transfers and make those "atomic".

It depends on the rest of the system of course, mostly what other threads do.

Giovanni
Tabulous
Posts: 518
Joined: Fri May 03, 2013 12:02 pm
Has thanked: 7 times
Been thanked: 18 times

Re: chThdSleepMilliseconds( 1000 ) Weird ?

Post by Tabulous »

Giovanni wrote:Anyway, threading does not add much jitter in itself if priorities are assigned correctly, also consider that you could raise thread priority around transfers and make those "atomic".

It depends on the rest of the system of course, mostly what other threads do.

Giovanni


We went down this route before, and thats why i went to use the gpt, trying to run a thread at 100hz with other threads running, and keeping the jitter low was not possible. Worth noting the other thread i the system of significance is the GPS receive thread. this receives around 400bytes of data per second. not alot but if you dont process it fast enough you get buffer overflows, so the interrupt on this SD driver is set lower.

Even if it was possible you would have a thread which is ticking every 10ms, but as im using bit banged i2c, the thread is blocked for the time the i2c is running, this is around 1ms. But i would assume the OS can still switch half way through if needed ?
Marco
Posts: 128
Joined: Tue Apr 16, 2013 8:22 pm
Has thanked: 4 times
Been thanked: 11 times

Re: chThdSleepMilliseconds( 1000 ) Weird ?

Post by Marco »

Instead of blocking in the gpt callback can't you just start another oneshot timer to handle the next event? It then becomes some sort of interrupt driven state machine.

If it is working we could make it a complex driver built on top of GPT and PAL. What do you think?

Marco
Tabulous
Posts: 518
Joined: Fri May 03, 2013 12:02 pm
Has thanked: 7 times
Been thanked: 18 times

Re: chThdSleepMilliseconds( 1000 ) Weird ?

Post by Tabulous »

when you say blocking i mean delays, as per delaying for i2c bus timing.


what we need is a delay routine like chThdSleepMilliseconds that can be used in iclass context, then i could use this for the i2c delays.
User avatar
Giovanni
Site Admin
Posts: 14895
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: chThdSleepMilliseconds( 1000 ) Weird ?

Post by Giovanni »

Hi,

If you use the tickless mode you can also have delays in microseconds but the F1 has 16bits timers so the maximum delays would be 65535uS, is this acceptable? (consider jitter in the range of 10-20 uS).

Alternatively you can use the GPT to wakeup a thread with whatever resolution you want.

Anyway, what are the acceptable jitter figures?

Giovanni
Post Reply