Page 1 of 1

I lock state or S lock state?

Posted: Tue May 14, 2013 6:43 pm
by jacobfeng
Dears. Quite probably my question is a silly one... But could any one tell me what is the difference between these, and when I should use which? I have looked into those examples in /tests folder, but still have no clear clue. Thank you very much.

Re: I lock state or S lock state?

Posted: Tue May 14, 2013 7:21 pm
by Giovanni
Hi,

The matter is explained in the documentation section "Kernel Concepts".

In brief, both classes are meant to be invoked with interrupts disabled but with a difference, I-class functions can be used from ISRs too, S-class functions cannot be invoked from ISRs.

An S-class function is a function that reschedules internally or refers the current thread. Rescheduling is something forbidden in ISRs because the reschedule operation must happen at the end of the ISR execution (and is performed there automatically if required). Referring the current thread from an ISRs is meaningless because the ISR could have preempted a random thread.

The correct usage of the functions is checked by the "state checker" which can be enabled in chconf.h, the state checker makes sure that all functions are invoked from the appropriate context and is very useful during development.

Giovanni

Re: I lock state or S lock state?

Posted: Wed May 15, 2013 2:39 am
by jacobfeng
I see. Thank you very much, Giovanni!