Page 1 of 1
External Interrupt Handler
Posted: Tue Jun 25, 2013 11:01 am
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.
Re: External Interrupt Handler
Posted: Tue Jun 25, 2013 11:21 am
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
Re: External Interrupt Handler
Posted: Tue Jun 25, 2013 11:39 am
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?
Re: External Interrupt Handler
Posted: Tue Jun 25, 2013 12:44 pm
by Giovanni
No because the EXT driver declares that handler internally, so you use the EXT driver OR write the handler yourself.
Giovanni