Page 1 of 1
Calling non-normal class functions from normal state
Posted: Sat Dec 28, 2013 10:07 am
by cgudrian
Hi!
While calling normal class functions is only allowed from normal state, what about non-normal class functions? Do they have to be called exclusively from their non-normal state or may they be called from normal state as well?
Christian
Re: Calling non-normal class functions from normal state
Posted: Sat Dec 28, 2013 10:44 am
by cgudrian
Hi!
I've just found out the answer myself:
Use of S-class or I-class APIs outside a proper lock state.
(from "Common Mistakes")
Re: Calling non-normal class functions from normal state
Posted: Sat Dec 28, 2013 12:20 pm
by Giovanni
Hi,
Correct, look at the states diagram into the "Kernel Concepts" chapter in the documentation. You can go from Normal state to a Lock state using specific functions: chSysLock(), chSysUnlock(), chSysLockFromIsr(), chSysUnlockFromIsr().
Note that all I-Class functions never reschedule internally so you may have to force a reschedule before exiting a lock zone, for example:
Code: Select all
chSysLock();
chSemSignalI(....); /* Does not reschedule by itself but could wakeup an higher priority thread.*/
chSchRescheduleS(); /* Checks if a reschedule is required, if so reschedules.*/
chSysUnlock();
The above mechanism is also used to create combined atomic primitives, for example signaling a semaphore and generating an event atomically.
Giovanni
Re: Calling non-normal class functions from normal state
Posted: Sat Dec 28, 2013 2:52 pm
by cgudrian
Hi, Giovanni!
Thanks for the reply. I've read the kernel concepts chapter before posting. Having read it yet again I must confess that I must have skipped over the relevant part right at the top of the page. Mea culpa!
Christian