[En-Nut-Discussion] external irq, wiki
Harald Kipp
harald.kipp at egnite.de
Tue Dec 20 11:24:22 CET 2011
Hi Klaus,
On 20.12.2011 06:43, Klaus Kloos wrote:
> Im searching for an example of using an external irq using ethernut and SAM7x.
Use
NutRegisterIrqHandler(&sig_INTERRUPT0, MyHandler, ¶m);
to register the interrupt routine MyHandler() for external interrupt 0.
Some CPUs provide interrupt triggering on simple GPIO pins. This is
supported by the signals sig_GPIOA, sig_GPIOB etc.
The interrupt handler is a simple C function, where the pointer to param
is passed as an argument.
static void MyHandler(void *arg)
{
...
}
When handling sig_GPIO interrupts for several pins, the handler must
determine the interrupt source.
Use
NutIrqEnable(&sig_INTERRUPT0);
NutIrqDisable(&sig_INTERRUPT0);
to enable or disable this interrupt. In addition, the hardware may
require additional initialization like enabling clocks etc.
Use
NutIrqSetMode(&sig_INTERRUPT0, mode);
to set the interrupt mode, where mode may be
NUT_IRQMODE_LOWLEVEL
NUT_IRQMODE_HIGHLEVEL
NUT_IRQMODE_FALLINGEDGE
NUT_IRQMODE_RISINGEDGE
NUT_IRQMODE_EDGE
NUT_IRQMODE_LEVEL
depending on the capabilities of your hardware.
All these functions work on all supported platforms. Your application
will be fully portable.
The backside of the coin is, that they add a significant amount of
overhead. If you need fast interrupt responses, you better implement
them in a native way. Nut/OS allows this. You'll probably find
sufficient infos in the web, e.g.
http://gandalf.arubi.uni-kl.de/avr_projects/arm_projects/index_at91.html
Note, that you cannot call most Nut/OS API functions from within
interrupts, except
NutEventPostFromIrq(&que);
In general, avoid any lengthy code in the handler. The above call may
trigger a thread that sits at
NutEventWait(&que, NUT_WAIT_INFINITE);
and processes the interrupt when triggered.
But you can use stdio functions like putchar(), puts() and even printf()
for debugging, if stdout has been opened on the DEV_DEBUG device.
> On the page http://www.ethernut.de/nutwiki/Nut/OS_Examples there is a link to 'Digital Input Interrupt' which sounds very good, but it is red and using it gives an
> 'The action you have requested is limited to users in the group user.'.
Please see my next post.
Regards,
Harald
More information about the En-Nut-Discussion
mailing list