I lock state or S lock state?

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

Moderators: RoccoMarco, lbednarz, tfAteba

Post Reply
jacobfeng
Posts: 2
Joined: Tue May 14, 2013 6:08 pm

I lock state or S lock state?

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

Re: I lock state or S lock state?

Post 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
jacobfeng
Posts: 2
Joined: Tue May 14, 2013 6:08 pm

Re: I lock state or S lock state?

Post by jacobfeng »

I see. Thank you very much, Giovanni!
Post Reply