irq_handler.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2019 Gunar Schorcht
3  *
4  * This file is subject to the terms and conditions of the GNU Lesser
5  * General Public License v2.1. See the file LICENSE in the top level
6  * directory for more details.
7  */
8 
152 #ifndef IRQ_HANDLER_H
153 #define IRQ_HANDLER_H
154 
155 #include <stdbool.h>
156 
157 #include "assert.h"
158 #include "event.h"
159 
160 #ifdef __cplusplus
161 extern "C" {
162 #endif
163 
170 #ifndef IRQ_HANDLER_PRIO
171 #define IRQ_HANDLER_PRIO 0
172 #endif
173 
180 typedef void (*irq_isr_t)(void *ctx);
181 
193 typedef struct {
195  bool pending;
198  void *ctx;
199 } irq_event_t;
200 
204 #define IRQ_EVENT_INIT { \
205  .event.handler = NULL, \
206  .event.list_node.next = NULL, \
207  .pending = false, \
208  .isr = NULL, \
209  .ctx = NULL, \
210  }
211 
224 static inline void irq_event_init(irq_event_t *irq)
225 {
226  assert(irq != NULL);
228  *irq = tmp;
229 }
230 
246 int irq_event_add(irq_event_t *irq);
247 
248 #ifdef __cplusplus
249 }
250 #endif
251 
252 #endif /* IRQ_HANDLER_H */
253 
bool pending
Indicates whether the same interrupt request event is already pending.
Definition: irq_handler.h:195
event structure
Definition: event.h:139
void(* irq_isr_t)(void *ctx)
Interrupt handling function prototype.
Definition: irq_handler.h:180
event_t event
Event structure.
Definition: irq_handler.h:194
POSIX.1-2008 compliant version of the assert macro.
int irq_event_add(irq_event_t *irq)
Add an interrupt event to the pending interrupt queue.
#define IRQ_EVENT_INIT
Static initializer for irq_event_t.
Definition: irq_handler.h:204
#define assert(cond)
abort the program if assertion is false
Definition: assert.h:104
void * ctx
Context used by the function.
Definition: irq_handler.h:198
irq_isr_t isr
Function to be called to handle the interrupt.
Definition: irq_handler.h:197
static void irq_event_init(irq_event_t *irq)
Initialize an interrupt event.
Definition: irq_handler.h:224
Event API.
Interrupt event structure.
Definition: irq_handler.h:193