Page 1 of 2

External Interruption handling

Posted: Wed Sep 28, 2016 8:43 am
by tfAteba
Hello Giovanni,

My goal is implement External Interruption for AVR. There is no support for that part in the os/hal/ports/AVR/ directory.

I don't know is some one already did that?

To do that, I first made a test without RT kernel part to trigger an external interruption 4 generate by a switch.

Here is how I have implemented the ISR:

Code: Select all

ISR(INT4_vect)
{
    //my callback code here
}


This works well, my code is executed every time I pressed the button.

Now I whant to use the RT kernel, and register this ISR as a callback so that it can be call every time the button is pressed.

Can you please briefly explain me how to implement external interrupt on ChibiOS?

Re: External Interruption handling

Posted: Wed Sep 28, 2016 9:10 am
by Giovanni
Hi,

There are two ways:

The "old" one is the implementation of an EXT driver, the STM32 port does this.

The new way is an extension to the PAL driver, see the latest PAL code in trunk, STM32 will transition to this at some point.

I don't remember if the AVR port includes an EXT driver already, you should ask to utzig, he has been handling the AVR code of late.

Giovanni

Re: External Interruption handling

Posted: Wed Sep 28, 2016 10:40 am
by utzig
Hi,

An EXT driver for AVR was contributed last year or so by Igor Stoppa. I don't remember why I haven't merged it but most probably due to some open issue(s). But I guess he got it working and you can probably use that as a starting point. Just search for it in the AVR posts.

Cheers,
Fabio Utzig

Re: External Interruption handling

Posted: Wed Sep 28, 2016 12:25 pm
by tfAteba
Hi Utzig,

I already made a port base on STM32 style, but it don't work properly, when an interruption is triggered, the cpu is restart, and I see my booting debuging messages again.

It will be nice to compare with Igor's work.

I will then search in the AVR furum to see if there is some contribution.

thank you for your help.

Re: External Interruption handling

Posted: Sat Oct 01, 2016 12:22 am
by tfAteba
Hello,

I made more investigations to resolve my problem (reset after interruption detected).

It appears that the problem was coming from some functions called in my callback. For example chprintf and chThdSleepMilliseconds.

Giovanni is those functions are forbidden in ISR routine? because when I remove them every things work well :D .

Re: External Interruption handling

Posted: Sat Oct 01, 2016 9:32 am
by Giovanni
Yes, both are forbidden in ISRs for different reasons.

Giovanni

Re: External Interruption handling

Posted: Sat Oct 01, 2016 1:30 pm
by tfAteba
Hi,

Is there some documentation were I can find that kind of informations please?

Re: External Interruption handling

Posted: Sat Oct 01, 2016 2:16 pm
by Giovanni
The "Kernel Concepts" section in the RT Reference Manual.

In general you should consider things like "what does it means sleeping in an interrupt handler"?

Anyway, if you enable the debug options in chconf.h such things would not be allowed.

Giovanni

Re: External Interruption handling

Posted: Sat Oct 01, 2016 2:26 pm
by tfAteba
Thank you very much I'm going to look that carefully!

Re: External Interruption handling

Posted: Tue Oct 04, 2016 9:37 pm
by tfAteba
Hi Giovanni,

Now my implementation of EXT for Arduino Mega2560 is working well, I just made some test.

I can toggle a LED with a switch by triggering an external interruption. But .....

Yes there is still the usual phenomena. I then need to implement a debounce to toggle my LED just one time when I pressed the button.

What is the best way to do that?
- In the driver side by setting the debounce time in my extConfig for example?
- In the application side in the external interruption callback?