Page 1 of 1

When use chSysLock?

Posted: Mon Apr 22, 2013 8:03 pm
by kreyl
Hi again!
ChibiOs v.2.5.1, stm32f205VE, Discovery as debugger.
I use debugger and those perfect Eclipse plugin. I found that time after time interrupt occures when system is inside chSysLock() - chSysUnlock(), i.e. in lock state; and then I have chDebugPanic with SV#8 and SV#9 messages.
I have the messages when DMA rises TransmissionCompleted Interrupt. I use built-in DMA drivers, providing just a callback function at setup. I have no chSysLock
It seems that chDebugPanic will occur every time when interrupt tiggers inside Lock state. But, since noone knows when interrupt will trigger, I cannot understand when I should use chSysLock and when not.
Is it really bad when interrupt occurs within Lock state? Is this situation avoided somehow in system functions?

Sorry if the question is silly, but when should I use SysLock in my code, or when should avoid it? (There are system functions with 'S' postfix, it is all clear with them).
Thanks in advance!

Re: When use chSysLock?

Posted: Mon Apr 22, 2013 8:42 pm
by Giovanni
Hi,

The only way an interrupt can happen between a lock and an unlock is if you have an IRQ priority higher than the maximum allowed for calls to the system.

Priority levels 0 and 1 are reserved for "fast interrupts", fast interrupts can preempt a lock but you cannot call kernel functions from fast ISRs. Note that you also have to use a different declaration for fast interrupts, using the normal declaration can cause those #8 and #9.

See here: http://chibios.sourceforge.net/html/con ... pt_classes
and here: http://www.chibios.org/dokuwiki/doku.ph ... interrupts

Giovanni

Re: When use chSysLock?

Posted: Mon Apr 22, 2013 10:29 pm
by kreyl
Thank you so much, Giovanni, the problem was that I used too high IRQ priorities: mainly 1, which is nearly top one.
By the way, I believe that it would be good to append mentioned documentation with example interrupts priorities. It took about an hour to squeeze through several samples and macroses alot to figure out exact numbers.
Thank you again.

Re: When use chSysLock?

Posted: Fri May 03, 2013 12:29 pm
by alex31
Priority levels 0 and 1 are reserved for "fast interrupts", fast interrupts can preempt a lock but you cannot call kernel functions from fast ISRs. Note that you also have to use a different declaration for fast interrupts, using the normal declaration can cause those #8 and #9.

See here: http://chibios.sourceforge.net/html/con ... pt_classes
and here: http://www.chibios.org/dokuwiki/doku.ph ... interrupts



I am writing adsb frame decoder (2Mhz manchester code) , and need to use Fast Interrupt to detect the first edge, at the end of frame decoding, i need to pend a lower priority regular interrupt
which will post decode result on a mailbox.

I have seen on the documentation how to write a fast interrupt handler, but how to pend a lower priority regular interrupt ?, is there reserved
software triggerable interrupt for this use on the stm32 ?, is there somewhere example of this use case ?

Thanks
Alexandre

Re: When use chSysLock?

Posted: Fri May 03, 2013 12:35 pm
by Giovanni
Hi,

You have to look at he Cortex-Mx programming manual and search for the PendSV vector, it is a software triggerable interrupt.

You can use:

SCB_ICSR = ICSR_PENDSVSET;

in order to trigger it.

Giovanni

Re: When use chSysLock?

Posted: Sun May 05, 2013 10:14 pm
by alex31
Hi,

Thanks for the advice.
it works quite nicely, i can decode adsb signal @ 2 mhz and output it via usb cdc.

So i use a fast interrupt for capture compare stuff, and when i have acquire a complete frame, i trigg
a PendSV interrupt which post the start idx and end idx of a circular buffer via mailbox, and,
a normal prio thread do the decoding and send it over usb.

EDIT : i had a bug when using priority 0 or 1 for my fast interrupt, but that was stupid error in my code,
now it works.

For fast capture, is it possible to bind a dma buffer on an icu peripheral (i know that's not in the chibios hal), but
is it possible dealing directly with registers and without breaking chibios which already use dma buffers ?

if it's possible, should be a better way than having an interrupt on each edge of a 2 mhz signal.

Alexandre

Re: When use chSysLock?

Posted: Mon May 06, 2013 8:39 am
by Giovanni
Hi,

If you manipulate only the registers of a single reserved channel then you should not break anything. You should also be able to use the functions provided by the DMA helper driver.

Giovanni