Page 1 of 1

chEvtWaitAny and Syslock

Posted: Thu Aug 15, 2013 5:25 pm
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

Re: chEvtWaitAny and Syslock

Posted: Thu Aug 15, 2013 5:30 pm
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

Re: chEvtWaitAny and Syslock

Posted: Fri Aug 30, 2013 3:41 pm
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

Re: chEvtWaitAny and Syslock

Posted: Fri Aug 30, 2013 4:03 pm
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

Re: chEvtWaitAny and Syslock

Posted: Mon Sep 02, 2013 5:29 pm
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.

Re: chEvtWaitAny and Syslock

Posted: Mon Sep 02, 2013 5:39 pm
by Giovanni
Can you post a minimal project showcasing the problem?

Giovanni

Re: chEvtWaitAny and Syslock

Posted: Tue Sep 10, 2013 5:44 pm
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

Re: chEvtWaitAny and Syslock

Posted: Tue Sep 10, 2013 7:00 pm
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

Re: chEvtWaitAny and Syslock

Posted: Wed Sep 11, 2013 1:04 pm
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

Re: chEvtWaitAny and Syslock

Posted: Wed Sep 11, 2013 1:21 pm
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