Page 1 of 1

chibios_rt::Timer

Posted: Mon Feb 16, 2015 11:35 am
by Thargon
Hi guys,

I'm trying to implement some state machine like behaviour and would like to use a timer to trigger an upcoming state.
I just want to wait for some time and then trigger an event for one specific thread (no broadcast).

Since evereything else is done in C++, I would prefer to use the provided C++ class chibios_rt::Timer.
Unfortunately, all member function of that class are I-Class API functions and I can't get them to work.
If I don't use chSysLock() and chSysUnlock() I get the SV#10 error (misplaced I-class function) as expected.
But when I try to lock the system via chSysLock() I get the SV#4 error (misplaced chSysLock()).

Since I can't find any example on the net how to use the Timer class, maybe someone of you can provide some help :)

Thanks in advance!

Thargon

Re: chibios_rt::Timer

Posted: Mon Feb 16, 2015 11:45 am
by Giovanni
Hi,

SV#4 means that you call chSysLock() twice, use the debugger stack trace and see where this happens.

Giovanni

Re: chibios_rt::Timer

Posted: Mon Feb 16, 2015 12:35 pm
by Thargon
Hi,

thanks for your quick reply.

If that was the case, why do I get SV#10 without chSysLock()?

Maybe I don't understand the locking system yet, but I can't find a good explanation in the documentation.
The documentation just states
Function Class:
Special function, this function has special requirements see the notes.

So far I was unable to find these notes.

Thargon

Re: chibios_rt::Timer

Posted: Mon Feb 16, 2015 12:37 pm
by Giovanni
Hi,

Read the "Kernel Concepts" section into the general documentation, classes are described there.

http://chibios.sourceforge.net/html/concepts.html

Giovanni

Re: chibios_rt::Timer

Posted: Mon Feb 16, 2015 2:29 pm
by Thargon
Hi again,

thanks for the link, though it didn't help me in this particular case :(

I don't have a dev board at hand right now, so I cant use the debugger stack trace.

What I just did, was to read the dbg_lock_cnt and isr_lock_cnt variables (which seem to be relevant for the SV#4 error) just before I call chSysLock(). Both are 0, though I can't guarantee that nothing happens between the two calls.

Any further Ideas or examples?

Thank you for your help!

Thargon

Re: chibios_rt::Timer

Posted: Mon Feb 16, 2015 3:43 pm
by Giovanni
If both variables are set to zero then you should not get that SV#4, it is hard for me to imagine what could be wrong there if you don't inspect with a debugger.

You need to single step through it and see which check fails.

Giovanni