External Interruption handling Topic is solved

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

Moderators: RoccoMarco, lbednarz, tfAteba

User avatar
tfAteba
Posts: 551
Joined: Fri Oct 16, 2015 11:03 pm
Has thanked: 91 times
Been thanked: 50 times

External Interruption handling

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

Re: External Interruption handling

Post 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
utzig
Posts: 359
Joined: Sat Jan 07, 2012 6:22 pm
Has thanked: 1 time
Been thanked: 20 times

Re: External Interruption handling

Post 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
User avatar
tfAteba
Posts: 551
Joined: Fri Oct 16, 2015 11:03 pm
Has thanked: 91 times
Been thanked: 50 times

Re: External Interruption handling

Post 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.
User avatar
tfAteba
Posts: 551
Joined: Fri Oct 16, 2015 11:03 pm
Has thanked: 91 times
Been thanked: 50 times

Re: External Interruption handling

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

Re: External Interruption handling

Post by Giovanni »

Yes, both are forbidden in ISRs for different reasons.

Giovanni
User avatar
tfAteba
Posts: 551
Joined: Fri Oct 16, 2015 11:03 pm
Has thanked: 91 times
Been thanked: 50 times

Re: External Interruption handling

Post by tfAteba »

Hi,

Is there some documentation were I can find that kind of informations please?
User avatar
Giovanni
Site Admin
Posts: 14895
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: External Interruption handling

Post 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
User avatar
tfAteba
Posts: 551
Joined: Fri Oct 16, 2015 11:03 pm
Has thanked: 91 times
Been thanked: 50 times

Re: External Interruption handling

Post by tfAteba »

Thank you very much I'm going to look that carefully!
User avatar
tfAteba
Posts: 551
Joined: Fri Oct 16, 2015 11:03 pm
Has thanked: 91 times
Been thanked: 50 times

Re: External Interruption handling

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