External Interrupt Handler

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

Moderators: RoccoMarco, lbednarz, tfAteba

Post Reply
donmichael
Posts: 6
Joined: Sun May 26, 2013 10:04 am

External Interrupt Handler

Post by donmichael »

Hi

Which is the best way to write interrupt handlers? [External Interrupt]....It seems we can specify a call back function in driver configuration or we can use CH_IRQ_HANDLER with required vector name. What is the difference between these two? and It seems CH_IRQ_HANDLER is disabled in main.c file... What could be the reason? I'm using STM32VL discovery with default board files..

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: External Interrupt Handler

Post by Giovanni »

hi,

If you need to handle external interrupts you can use the EXT driver and not have to write any interrupt handler.

If you want to write an interrupt handler then CH_IRQ_HANDLER is the way to go, I don't understand what you mean with "disabled in main.c", if you include ch.h then the macro is available.

Giovanni
donmichael
Posts: 6
Joined: Sun May 26, 2013 10:04 am

Re: External Interrupt Handler

Post by donmichael »

Dear Giovanni,

The code that I tested is some thing like this.

static void button_handler(void)
{
///doing the handling.
}

// Channel configuration.
static const EXTConfig extcfg = {
{
{EXT_CH_MODE_RISING_EDGE | EXT_CH_MODE_AUTOSTART | EXT_MODE_GPIOA, button_handler}, /* 0 */
{EXT_CH_MODE_DISABLED, NULL}, /* 1 */..................

And then in main I call

// Activate first EXT driver.
extStart(&EXTD1, &extcfg);


This works just fine..

But when I try to write it with

#include "ch.h"

CH_IRQ_HANDLER(EXTI0_IRQHandler)
{
................
}

static const EXTConfig extcfg = {
{
{EXT_CH_MODE_RISING_EDGE | EXT_CH_MODE_AUTOSTART | EXT_MODE_GPIOA, CH_IRQ_HANDLER}, /* 0 */
{EXT_CH_MODE_DISABLED, NULL}, /* 1 */..................

the compiler gives error:
'CH_IRQ_HANDLER' undeclared here ( not in a function).

Chibi documentation recommends to use CH_IRQ_HANDLER any way.
Is it okay to use handler like this?
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 Interrupt Handler

Post by Giovanni »

No because the EXT driver declares that handler internally, so you use the EXT driver OR write the handler yourself.

Giovanni
Post Reply