chEvtWaitAny and Syslock

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

Moderators: RoccoMarco, lbednarz, tfAteba

Post Reply
FlorianS
Posts: 22
Joined: Thu Jan 26, 2012 12:29 pm

chEvtWaitAny and Syslock

Post by FlorianS »

Hi,
i'm a little confused about the chEvtWaitAny (chThdYield and chThdSleep). When i call one of those functions the System will go into chSysLock. For the in parallel running Thread the System is still locked until the Thread which performed the chEvtWaitAny/chThdYield/chThdSleep will be waked up.
So if the in parallel running Thread wants to perform a canStart() the debug Error SV#4 will occur.

Regards,
Florian
User avatar
Giovanni
Site Admin
Posts: 14891
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: chEvtWaitAny and Syslock

Post by Giovanni »

When the system goes in a context switch function (chthdSleep for example) the lock primitive is invoked before going to sleep and the unlock is immediately invoked by the next thread executed.

The sequence is always: lock - switch - unlock-

If you get an #SV4 then you have some call protocol violation somewhere.

Giovanni
FlorianS
Posts: 22
Joined: Thu Jan 26, 2012 12:29 pm

Re: chEvtWaitAny and Syslock

Post by FlorianS »

Hi,
i located the error at wrong position. After PIT Initialization an interrupt will be called by the SYSIrqHandler. There I get an SV#8.

vt_systime: 1
r_current: 00201208 "idle"
r_preempt: 20
dbg_isr_cnt: not within ISR
dbg_lock_cnt: within lock

Why do a get an interrupt while in lock?

Regards,
Florian
User avatar
Giovanni
Site Admin
Posts: 14891
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: chEvtWaitAny and Syslock

Post by Giovanni »

Are your IRQ priorities within allowed ranges? if you have some priority above the max then it can preempt even in a lock. I am assuming you are talking about a Cortex, you gave no context.

Giovanni
FlorianS
Posts: 22
Joined: Thu Jan 26, 2012 12:29 pm

Re: chEvtWaitAny and Syslock

Post by FlorianS »

Hi,
the prorities are like in board.c defined highest - 1. We are on a AT91SAM7X256 (board by olimex).

from board.c:
/*
* PIT Initialization.
*/
AIC_ConfigureIT(AT91C_ID_SYS,
AT91C_AIC_SRCTYPE_HIGH_LEVEL | (AT91C_AIC_PRIOR_HIGHEST - 1),
SYSIrqHandler);
AIC_EnableIT(AT91C_ID_SYS);
AT91C_BASE_PITC->PITC_PIMR = (MCK / 16 / CH_FREQUENCY) - 1;
AT91C_BASE_PITC->PITC_PIMR |= AT91C_PITC_PITEN | AT91C_PITC_PITIEN;

I even have that problem with an empty main loop.
User avatar
Giovanni
Site Admin
Posts: 14891
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: chEvtWaitAny and Syslock

Post by Giovanni »

Can you post a minimal project showcasing the problem?

Giovanni
FlorianS
Posts: 22
Joined: Thu Jan 26, 2012 12:29 pm

Re: chEvtWaitAny and Syslock

Post by FlorianS »

Hi,
i think i found the cause of the SV#4. After creating a thread we used chSchDoReschedule() instead of chThdYield(). But why doesn't chSchDoReschedule() work?

Regards,
Florian
User avatar
Giovanni
Site Admin
Posts: 14891
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: chEvtWaitAny and Syslock

Post by Giovanni »

Hi,

From the function description: "Not a user function, it is meant to be invoked by the scheduler itself or from within the port layer.".

Why you need to reschedule after creating a thread? this is not required usually.

Giovanni
FlorianS
Posts: 22
Joined: Thu Jan 26, 2012 12:29 pm

Re: chEvtWaitAny and Syslock

Post by FlorianS »

I have a thread which does some CAN initialisation. This is needed later on in the main thread. So i just wait until the CAN-Thread is ready. To not suck in a while, which does nothing, i want to yield execution to the CAN thread.

I had other situations where I just wanted to ensure that the thread was active at least once.

"Not a user function" - I'm a giddy Goat :roll:

Regards,
Florian
User avatar
Giovanni
Site Admin
Posts: 14891
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: chEvtWaitAny and Syslock

Post by Giovanni »

Hi,

You may just give the CAN thread an higher priority, the effect would be the same without relying on the round-robin behavior.

Giovanni
Post Reply