27
27
#include " platform/mbed_error.h"
28
28
#include " platform/mbed_assert.h"
29
29
30
+ using std::milli;
31
+ using std::chrono::duration;
32
+
30
33
namespace rtos {
31
34
32
35
EventFlags::EventFlags ()
@@ -82,12 +85,32 @@ uint32_t EventFlags::get() const
82
85
83
86
uint32_t EventFlags::wait_all (uint32_t flags, uint32_t millisec, bool clear)
84
87
{
85
- return wait (flags, osFlagsWaitAll, millisec, clear);
88
+ return wait_all_for (flags, duration<uint32_t , milli>(millisec), clear);
89
+ }
90
+
91
+ uint32_t EventFlags::wait_all_for (uint32_t flags, Kernel::Clock::duration_u32 rel_time, bool clear)
92
+ {
93
+ return wait_for (flags, osFlagsWaitAll, rel_time, clear);
94
+ }
95
+
96
+ uint32_t EventFlags::wait_all_until (uint32_t flags, Kernel::Clock::time_point abs_time, bool clear)
97
+ {
98
+ return wait_until (flags, osFlagsWaitAll, abs_time, clear);
86
99
}
87
100
88
101
uint32_t EventFlags::wait_any (uint32_t flags, uint32_t millisec, bool clear)
89
102
{
90
- return wait (flags, osFlagsWaitAny, millisec, clear);
103
+ return wait_any_for (flags, duration<uint32_t , milli>(millisec), clear);
104
+ }
105
+
106
+ uint32_t EventFlags::wait_any_for (uint32_t flags, Kernel::Clock::duration_u32 rel_time, bool clear)
107
+ {
108
+ return wait_for (flags, osFlagsWaitAny, rel_time, clear);
109
+ }
110
+
111
+ uint32_t EventFlags::wait_any_until (uint32_t flags, Kernel::Clock::time_point abs_time, bool clear)
112
+ {
113
+ return wait_until (flags, osFlagsWaitAny, abs_time, clear);
91
114
}
92
115
93
116
EventFlags::~EventFlags ()
@@ -97,30 +120,47 @@ EventFlags::~EventFlags()
97
120
#endif
98
121
}
99
122
100
- uint32_t EventFlags::wait (uint32_t flags, uint32_t opt, uint32_t millisec , bool clear)
123
+ uint32_t EventFlags::wait_for (uint32_t flags, uint32_t opt, Kernel::Clock::duration_u32 rel_time , bool clear)
101
124
{
102
125
if (clear == false ) {
103
126
opt |= osFlagsNoClear;
104
127
}
105
128
106
129
#if MBED_CONF_RTOS_PRESENT
107
- return osEventFlagsWait (_id, flags, opt, millisec );
130
+ return osEventFlagsWait (_id, flags, opt, rel_time. count () );
108
131
#else
109
132
rtos::internal::flags_check_capture check;
110
133
check.flags = &_flags;
111
134
check.options = opt;
112
135
check.flags_wanted = flags;
113
136
check.result = 0 ;
114
137
check.match = false ;
115
- mbed::internal::do_timed_sleep_relative_or_forever (millisec , rtos::internal::non_rtos_check_flags, &check);
138
+ mbed::internal::do_timed_sleep_relative_or_forever (rel_time , rtos::internal::non_rtos_check_flags, &check);
116
139
if (check.match ) {
117
140
return check.result ;
118
- } else if (millisec == 0 ) {
141
+ } else if (rel_time == rel_time. zero () ) {
119
142
return osErrorResource;
120
143
} else {
121
144
return osErrorTimeout;
122
145
}
123
146
#endif
124
147
}
125
148
149
+ uint32_t EventFlags::wait_until (uint32_t flags, uint32_t opt, Kernel::Clock::time_point abs_time, bool clear)
150
+ {
151
+ Kernel::Clock::time_point now = Kernel::Clock::now ();
152
+
153
+ Kernel::Clock::duration_u32 rel_time;
154
+ if (now >= abs_time) {
155
+ rel_time = rel_time.zero ();
156
+ } else if (abs_time - now > Kernel::wait_for_u32_max) {
157
+ // Documentation permits early return for big offsets
158
+ rel_time = Kernel::wait_for_u32_max;
159
+ } else {
160
+ rel_time = abs_time - now;
161
+ }
162
+ return wait_for (flags, opt, rel_time, clear);
163
+ }
164
+
165
+
126
166
}
0 commit comments