Calling non-normal class functions from normal state

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

Moderators: RoccoMarco, lbednarz, tfAteba

Post Reply
cgudrian
Posts: 5
Joined: Sun Mar 10, 2013 8:33 am

Calling non-normal class functions from normal state

Post 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
cgudrian
Posts: 5
Joined: Sun Mar 10, 2013 8:33 am

Re: Calling non-normal class functions from normal state

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

Re: Calling non-normal class functions from normal state

Post 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
cgudrian
Posts: 5
Joined: Sun Mar 10, 2013 8:33 am

Re: Calling non-normal class functions from normal state

Post 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
Post Reply