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.
External Interrupt Handler
Moderators: RoccoMarco, lbednarz, tfAteba
- 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
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
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
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?
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?
- 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
No because the EXT driver declares that handler internally, so you use the EXT driver OR write the handler yourself.
Giovanni
Giovanni