L4Re – L4 Runtime Environment
examples/sys/isr/main.c

Example of an interrupt service routine.

/*
* (c) 2008-2009 Adam Lackorzynski <adam@os.inf.tu-dresden.de>,
* Alexander Warg <warg@os.inf.tu-dresden.de>,
* Björn Döbel <doebel@os.inf.tu-dresden.de>
* economic rights: Technische Universität Dresden (Germany)
*
* This file is part of TUD:OS and distributed under the terms of the
* GNU General Public License 2.
* Please see the COPYING-GPL-2 file for details.
*/
/*
* This example shall show how to connect to an interrupt, receive interrupt
* events and detach again. As the interrupt source we'll use the virtual
* key interrupt. The interrupt number of the virtual key interrupt can be
* found in the kernel info page.
*/
#include <l4/sys/utcb.h>
#include <l4/sys/irq.h>
#include <l4/sys/factory.h>
#include <l4/sys/icu.h>
#include <stdio.h>
int main(void)
{
int irqno = 1;
l4_cap_idx_t irqcap, icucap;
int err;
icucap = l4re_env_get_cap("icu");
/* Get a free capability slot for the ICU capability */
if (l4_is_invalid_cap(icucap))
{
printf("Did not find an ICU\n");
return 1;
}
/* Get another free capaiblity slot for the corresponding IRQ object*/
return 1;
/* Create IRQ object */
if (l4_error(tag = l4_factory_create_irq(l4re_global_env->factory, irqcap)))
{
printf("Could not create IRQ object: %lx\n", l4_error(tag));
return 1;
}
/*
* Bind the recently allocated IRQ object to the IRQ number irqno
* as provided by the ICU.
*/
if (l4_error(l4_icu_bind(icucap, irqno, irqcap)))
{
printf("Binding IRQ%d to the ICU failed\n", irqno);
return 1;
}
/* Bind ourselves to the IRQ */
tag = l4_rcv_ep_bind_thread(irqcap, l4re_env()->main_thread, 0xDEAD);
if ((err = l4_error(tag)))
{
printf("Error binding to IRQ %d: %d\n", irqno, err);
return 1;
}
printf("Attached to key IRQ %d\nPress keys now, Shift-Q to exit\n", irqno);
/* IRQ receive loop */
while (1)
{
unsigned long label = 0;
/* Wait for the interrupt to happen */
tag = l4_irq_receive(irqcap, L4_IPC_NEVER);
if ((err = l4_ipc_error(tag, l4_utcb())))
printf("Error on IRQ receive: %d\n", err);
else
{
/* Process the interrupt -- may do a 'break' */
printf("Got IRQ with label 0x%lX\n", label);
}
}
/* We're done, detach from the interrupt. */
tag = l4_irq_detach(irqcap);
if ((err = l4_error(tag)))
printf("Error detach from IRQ: %d\n", err);
return 0;
}
Capability allocator C interface.
Common factory related definitions.
l4_cap_idx_t l4re_util_cap_alloc(void) L4_NOTHROW
Get free capability index at capability allocator.
l4_cap_idx_t l4re_env_get_cap(char const *name) L4_NOTHROW
Get the capability selector for the object named name.
Definition: env.h:227
l4re_env_t * l4re_env(void) L4_NOTHROW
Get L4Re initial environment.
Definition: env.h:185
unsigned long l4_cap_idx_t
L4 Capability selector Type.
Definition: types.h:342
unsigned l4_is_invalid_cap(l4_cap_idx_t c) L4_NOTHROW
Test if a capability selector is the invalid capability.
Definition: types.h:392
l4_msgtag_t l4_factory_create_irq(l4_cap_idx_t factory, l4_cap_idx_t target_cap) L4_NOTHROW
Create a new IRQ sender.
Definition: factory.h:389
l4_msgtag_t l4_icu_bind(l4_cap_idx_t icu, unsigned irqnum, l4_cap_idx_t irq) L4_NOTHROW
Bind an interrupt line of an interrupt controller to an interrupt object.
Definition: icu.h:473
long l4_error(l4_msgtag_t tag) L4_NOTHROW
Return error code of a system call return message tag or the tag label.
Definition: ipc.h:535
l4_umword_t l4_ipc_error(l4_msgtag_t tag, l4_utcb_t *utcb) L4_NOTHROW
Get the error code for an object invocation.
Definition: ipc.h:518
l4_msgtag_t l4_irq_detach(l4_cap_idx_t irq) L4_NOTHROW
Detach from an interrupt source.
Definition: irq.h:287
l4_msgtag_t l4_irq_receive(l4_cap_idx_t irq, l4_timeout_t to) L4_NOTHROW
Unmask and wait for specified IRQ.
Definition: irq.h:299
l4_msgtag_t l4_rcv_ep_bind_thread(l4_cap_idx_t ep, l4_cap_idx_t thread, l4_umword_t label)
Bind the IPC gate to a thread.
Definition: rcv_endpoint.h:80
l4_utcb_t * l4_utcb(void) L4_NOTHROW L4_PURE
Get the UTCB address.
Definition: utcb.h:340
Interrupt controller.
C Irq interface.
Namespace functions, C interface.
Message tag data structure.
Definition: types.h:160
l4_cap_idx_t factory
Object-capability of the factory available to the task.
Definition: env.h:116