Loading...
Searching...
No Matches
source.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 2022 ML!PA Consulting GmbH
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
22#ifndef EVENT_SOURCE_H
23#define EVENT_SOURCE_H
24
25#include "event.h"
26#include "list.h"
27#include "irq.h"
28
29#ifdef __cplusplus
30extern "C" {
31#endif
32
36typedef struct {
39
48
52#define EVENT_SOURCE_INIT { 0 }
53
60#define EVENT_SOURCE_SUBSCRIBER_INIT(e, q) { .event = (event_t *)e, .queue = q }
61
68static inline void event_source_attach(event_source_t *source,
70{
71 unsigned state = irq_disable();
72
73 list_add(&source->list, &event->node);
74
75 irq_restore(state);
76}
77
84static inline void event_source_detach(event_source_t *source,
86{
87 unsigned state = irq_disable();
88
89 list_remove(&source->list, &event->node);
90
91 irq_restore(state);
92}
93
99static inline void event_source_trigger(event_source_t *source)
100{
101 unsigned state = irq_disable();
102
105 node);
106 while (event) {
107 event_post(event->queue, event->event);
108 event = container_of(event->node.next, event_source_subscriber_t, node);
109 }
110
111 irq_restore(state);
112}
113
114#ifdef __cplusplus
115}
116#endif
117#endif /* EVENT_SOURCE_H */
#define container_of(PTR, TYPE, MEMBER)
Returns the container of a pointer to a member.
Definition container.h:62
MAYBE_INLINE void irq_restore(unsigned state)
This function restores the IRQ disable bit in the status register to the value contained within passe...
MAYBE_INLINE unsigned irq_disable(void)
This function sets the IRQ disable bit in the status register.
void event_post(event_queue_t *queue, event_t *event)
Queue an event.
IRQ driver interface.
Intrusive linked list.
static void list_add(list_node_t *node, list_node_t *new_node)
Insert object into list.
Definition list.h:53
static list_node_t * list_remove(list_node_t *list, list_node_t *node)
Removes the node from the list.
Definition list.h:86
static void event_source_attach(event_source_t *source, event_source_subscriber_t *event)
Attach an event to an event source.
Definition source.h:68
static void event_source_trigger(event_source_t *source)
Trigger all events registered on the event source.
Definition source.h:99
static void event_source_detach(event_source_t *source, event_source_subscriber_t *event)
Remove a subscription from the event source.
Definition source.h:84
event queue structure
Definition event.h:156
Subscriber of an event source.
Definition source.h:43
list_node_t node
event subscriber list node
Definition source.h:44
event_t * event
pointer to event that should be triggered
Definition source.h:45
event_queue_t * queue
event queue to be used for the event
Definition source.h:46
Event source struct.
Definition source.h:36
list_node_t list
event source list node
Definition source.h:37
event structure
Definition event.h:148
List node structure.
Definition list.h:40
struct list_node * next
pointer to next list entry
Definition list.h:41