When use chSysLock?

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

Moderators: RoccoMarco, lbednarz, tfAteba

Post Reply
User avatar
kreyl
Posts: 59
Joined: Sun Jan 13, 2013 11:46 pm
Been thanked: 4 times

When use chSysLock?

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

Re: When use chSysLock?

Post 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
User avatar
kreyl
Posts: 59
Joined: Sun Jan 13, 2013 11:46 pm
Been thanked: 4 times

Re: When use chSysLock?

Post 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.
User avatar
alex31
Posts: 445
Joined: Fri May 25, 2012 10:23 am
Has thanked: 57 times
Been thanked: 88 times

Re: When use chSysLock?

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

Re: When use chSysLock?

Post 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
User avatar
alex31
Posts: 445
Joined: Fri May 25, 2012 10:23 am
Has thanked: 57 times
Been thanked: 88 times

Re: When use chSysLock?

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

Re: When use chSysLock?

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