#pragma once #include #include #include #ifdef __cplusplus extern "C" { #endif struct rt_notify; // Notify without changing the notification value. void rt_notify_post(struct rt_notify *note); // Notify and |= the notification value. void rt_notify_or(struct rt_notify *note, uint32_t value); // Notify and += the notification value. void rt_notify_add(struct rt_notify *note, uint32_t value); // Notify set the notification value unconditionally. void rt_notify_set(struct rt_notify *note, uint32_t value); /* Block until notified, and return the notification value. Only one task may * call rt_notify_*wait* for each struct rt_notify. */ uint32_t rt_notify_wait(struct rt_notify *note); /* Block the current task until notified, and &= ~clear the notification value. * The returned value is before clearing. */ uint32_t rt_notify_wait_clear(struct rt_notify *note, uint32_t clear); /* Get the notification value if one is pending. Returns false if there is no * notification pending. */ bool rt_notify_trywait(struct rt_notify *note, uint32_t *value); // rt_notify_trywait and &= ~clear the notification value after fetching it. bool rt_notify_trywait_clear(struct rt_notify *note, uint32_t *value, uint32_t clear); /* Wait for a pending notification until a timeout expires and get the value if * a notification occurs. Returns false if there is no notification before the * timeout expires. */ bool rt_notify_timedwait(struct rt_notify *note, uint32_t *value, unsigned long ticks); // rt_notify_timedwait and &= ~clear the notification value after fetching it. bool rt_notify_timedwait_clear(struct rt_notify *note, uint32_t *value, uint32_t clear, unsigned long ticks); struct rt_notify { rt_atomic_uint32_t value; struct rt_sem sem; }; #define RT_NOTIFY_INIT(name, value_) \ { \ .value = (value_), \ .sem = RT_SEM_INIT_BINARY(name.sem), \ } #define RT_NOTIFY(name, value_) \ struct rt_notify name = RT_NOTIFY_INIT(name, value_) #ifdef __cplusplus } #endif