Page 2 of 3
Re: chThdSleepMilliseconds( 1000 ) Weird ?
Posted: Wed Nov 30, 2016 5:17 pm
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.
Re: chThdSleepMilliseconds( 1000 ) Weird ?
Posted: Wed Nov 30, 2016 5:24 pm
by utzig
What MCU are you using? What I2C problems are you having?
Re: chThdSleepMilliseconds( 1000 ) Weird ?
Posted: Wed Nov 30, 2016 5:28 pm
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
Re: chThdSleepMilliseconds( 1000 ) Weird ?
Posted: Wed Nov 30, 2016 5:31 pm
by Giovanni
Isn't F3xx pin compatible or very close to the F1xx? It includes a new I2C.
Giovanni
Re: chThdSleepMilliseconds( 1000 ) Weird ?
Posted: Wed Nov 30, 2016 5:34 pm
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.
Re: chThdSleepMilliseconds( 1000 ) Weird ?
Posted: Wed Nov 30, 2016 5:34 pm
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
Re: chThdSleepMilliseconds( 1000 ) Weird ?
Posted: Wed Nov 30, 2016 5:40 pm
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 ?
Re: chThdSleepMilliseconds( 1000 ) Weird ?
Posted: Wed Nov 30, 2016 5:59 pm
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
Re: chThdSleepMilliseconds( 1000 ) Weird ?
Posted: Wed Nov 30, 2016 6:07 pm
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.
Re: chThdSleepMilliseconds( 1000 ) Weird ?
Posted: Wed Nov 30, 2016 7:49 pm
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