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
9#pragma once
10
23
24#include "event.h"
25#include "list.h"
26#include "irq.h"
27
28#ifdef __cplusplus
29extern "C" {
30#endif
31
35typedef struct {
38
47
51#define EVENT_SOURCE_INIT { 0 }
52
59#define EVENT_SOURCE_SUBSCRIBER_INIT(e, q) { .event = (event_t *)e, .queue = q }
60
67static inline void event_source_attach(event_source_t *source,
69{
70 unsigned state = irq_disable();
71
72 list_add(&source->list, &event->node);
73
74 irq_restore(state);
75}
76
83static inline void event_source_detach(event_source_t *source,
85{
86 unsigned state = irq_disable();
87
88 list_remove(&source->list, &event->node);
89
90 irq_restore(state);
91}
92
98static inline void event_source_trigger(event_source_t *source)
99{
100 unsigned state = irq_disable();
101
104 node);
105 while (event) {
106 event_post(event->queue, event->event);
107 event = container_of(event->node.next, event_source_subscriber_t, node);
108 }
109
110 irq_restore(state);
111}
112
113#ifdef __cplusplus
114}
115#endif
#define container_of(PTR, TYPE, MEMBER)
Returns the container of a pointer to a member.
Definition container.h:61
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.
struct PTRTAG event_queue_t
event queue structure
struct event event_t
event structure forward declaration
Definition event.h:135
IRQ driver interface.
Intrusive linked list.
struct list_node list_node_t
List node structure.
static void list_add(list_node_t *node, list_node_t *new_node)
Insert object into list.
Definition list.h:52
static list_node_t * list_remove(list_node_t *list, list_node_t *node)
Removes the node from the list.
Definition list.h:85
static void event_source_attach(event_source_t *source, event_source_subscriber_t *event)
Attach an event to an event source.
Definition source.h:67
static void event_source_trigger(event_source_t *source)
Trigger all events registered on the event source.
Definition source.h:98
static void event_source_detach(event_source_t *source, event_source_subscriber_t *event)
Remove a subscription from the event source.
Definition source.h:83
Subscriber of an event source.
Definition source.h:42
list_node_t node
event subscriber list node
Definition source.h:43
event_t * event
pointer to event that should be triggered
Definition source.h:44
event_queue_t * queue
event queue to be used for the event
Definition source.h:45
Event source struct.
Definition source.h:35
list_node_t list
event source list node
Definition source.h:36
event structure
Definition event.h:145
struct list_node * next
pointer to next list entry
Definition list.h:40