2626#include " platform/mbed_error.h"
2727#include " platform/mbed_assert.h"
2828
29+ using std::milli;
30+ using std::chrono::duration;
31+
2932namespace rtos {
3033
3134EventFlags::EventFlags ()
@@ -81,12 +84,32 @@ uint32_t EventFlags::get() const
8184
8285uint32_t EventFlags::wait_all (uint32_t flags, uint32_t millisec, bool clear)
8386{
84- return wait (flags, osFlagsWaitAll, millisec, clear);
87+ return wait_all_for (flags, duration<uint32_t , milli>(millisec), clear);
88+ }
89+
90+ uint32_t EventFlags::wait_all_for (uint32_t flags, Kernel::Clock::duration_u32 rel_time, bool clear)
91+ {
92+ return wait_for (flags, osFlagsWaitAll, rel_time, clear);
93+ }
94+
95+ uint32_t EventFlags::wait_all_until (uint32_t flags, Kernel::Clock::time_point abs_time, bool clear)
96+ {
97+ return wait_until (flags, osFlagsWaitAll, abs_time, clear);
8598}
8699
87100uint32_t EventFlags::wait_any (uint32_t flags, uint32_t millisec, bool clear)
88101{
89- return wait (flags, osFlagsWaitAny, millisec, clear);
102+ return wait_any_for (flags, duration<uint32_t , milli>(millisec), clear);
103+ }
104+
105+ uint32_t EventFlags::wait_any_for (uint32_t flags, Kernel::Clock::duration_u32 rel_time, bool clear)
106+ {
107+ return wait_for (flags, osFlagsWaitAny, rel_time, clear);
108+ }
109+
110+ uint32_t EventFlags::wait_any_until (uint32_t flags, Kernel::Clock::time_point abs_time, bool clear)
111+ {
112+ return wait_until (flags, osFlagsWaitAny, abs_time, clear);
90113}
91114
92115EventFlags::~EventFlags ()
@@ -96,30 +119,47 @@ EventFlags::~EventFlags()
96119#endif
97120}
98121
99- uint32_t EventFlags::wait (uint32_t flags, uint32_t opt, uint32_t millisec , bool clear)
122+ uint32_t EventFlags::wait_for (uint32_t flags, uint32_t opt, Kernel::Clock::duration_u32 rel_time , bool clear)
100123{
101124 if (clear == false ) {
102125 opt |= osFlagsNoClear;
103126 }
104127
105128#if MBED_CONF_RTOS_PRESENT
106- return osEventFlagsWait (_id, flags, opt, millisec );
129+ return osEventFlagsWait (_id, flags, opt, rel_time. count () );
107130#else
108131 rtos::internal::flags_check_capture check;
109132 check.flags = &_flags;
110133 check.options = opt;
111134 check.flags_wanted = flags;
112135 check.result = 0 ;
113136 check.match = false ;
114- mbed::internal::do_timed_sleep_relative_or_forever (millisec , rtos::internal::non_rtos_check_flags, &check);
137+ mbed::internal::do_timed_sleep_relative_or_forever (rel_time , rtos::internal::non_rtos_check_flags, &check);
115138 if (check.match ) {
116139 return check.result ;
117- } else if (millisec == 0 ) {
140+ } else if (rel_time == rel_time. zero () ) {
118141 return osErrorResource;
119142 } else {
120143 return osErrorTimeout;
121144 }
122145#endif
123146}
124147
148+ uint32_t EventFlags::wait_until (uint32_t flags, uint32_t opt, Kernel::Clock::time_point abs_time, bool clear)
149+ {
150+ Kernel::Clock::time_point now = Kernel::Clock::now ();
151+
152+ Kernel::Clock::duration_u32 rel_time;
153+ if (now >= abs_time) {
154+ rel_time = rel_time.zero ();
155+ } else if (abs_time - now > Kernel::wait_for_u32_max) {
156+ // Documentation permits early return for big offsets
157+ rel_time = Kernel::wait_for_u32_max;
158+ } else {
159+ rel_time = abs_time - now;
160+ }
161+ return wait_for (flags, opt, rel_time, clear);
162+ }
163+
164+
125165}
0 commit comments