Interrupt handling in S state

Discussions and support about ChibiOS/RT, the free embedded RTOS.
Post Reply
Prathibha Prakash
Posts: 10
Joined: Sat Jun 22, 2019 6:15 pm

Interrupt handling in S state

Post by Prathibha Prakash »

Hi,in the demos ChibiOS/demos/various/RT-ARMCM4-USELIB it started the main thread then it sleep for some finite seconds.So when I looked at the sequence of actions taken,I can see a context switch occured..
chThdSleep --> chSysLock() --> chThdSleepS --> chSchGoSleepTimeoutS --> chSchGoSleepS --> chSysSwitch-->port switch..
So currently the stack pointer is at thread1 so it can't call unlock since the lock was taken by main thread and the system state is S.But in S state the regular interrupts are disabled,so how it will handle the interrupts without leaving the S state?
User avatar
Giovanni
Site Admin
Posts: 14891
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: Interrupt handling in S state

Post by Giovanni »

Hi,

Common question :)

Inside that sequence there is a context switch, the thread switched-in leaves the S-lock state on its side. The system never -stays- in S-lock state.

The sequence is always lock->switch->unlock, no delays inside.

Giovanni
Prathibha Prakash
Posts: 10
Joined: Sat Jun 22, 2019 6:15 pm

Re: Interrupt handling in S state

Post by Prathibha Prakash »

But after context switch from main thread the pointer is at thread1 and it will start running it.Lock is taken from main so it should unlock it from main,so how to leave S-state??
main thread --> chSysLock --> Context switch(pointer at thread1 in S state) How to unlock from thread1?To unlock we need to return to main thread??
User avatar
Giovanni
Site Admin
Posts: 14891
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: Interrupt handling in S state

Post by Giovanni »

Hi,

I suggest you step by step through a context switch, this should make it clear.

Giovanni
Post Reply