summaryrefslogtreecommitdiff
path: root/core/host
diff options
context:
space:
mode:
authorAlec Berg <alecaberg@chromium.org>2015-06-04 11:45:19 -0700
committerChromeOS Commit Bot <chromeos-commit-bot@chromium.org>2015-06-11 02:57:45 +0000
commit0a7f37d720ef8e2a0c6541054e9c01161ba0afb0 (patch)
tree09136f946239518b8c0429776b29c97829741f98 /core/host
parentc75e78cd50a6e7ab2fba293199ebf97bcf66ed13 (diff)
downloadchrome-ec-0a7f37d720ef8e2a0c6541054e9c01161ba0afb0.tar.gz
core: add task_wait_event_mask() function to other cores
Add task_wait_event_mask() function to core/cortex-m0, core/host and board/zinger/runtime in order to delay a task until a specific event occurs. BUG=none BRANCH=smaug TEST=make -j buildall Change-Id: Ic89487fcae5352eec53b745179c7f0d5893ad3e0 Signed-off-by: Alec Berg <alecaberg@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/276744 Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
Diffstat (limited to 'core/host')
-rw-r--r--core/host/task.c28
1 files changed, 28 insertions, 0 deletions
diff --git a/core/host/task.c b/core/host/task.c
index 98a77b8e41..53f722e8b7 100644
--- a/core/host/task.c
+++ b/core/host/task.c
@@ -196,6 +196,34 @@ uint32_t task_wait_event(int timeout_us)
return ret;
}
+uint32_t task_wait_event_mask(uint32_t event_mask, int timeout_us)
+{
+ uint64_t deadline = get_time().val + timeout_us;
+ uint32_t events = 0;
+ int time_remaining_us = timeout_us;
+
+ /* Add the timer event to the mask so we can indicate a timeout */
+ event_mask |= TASK_EVENT_TIMER;
+
+ while (!(events & event_mask)) {
+ /* Collect events to re-post later */
+ events |= task_wait_event(time_remaining_us);
+
+ time_remaining_us = deadline - get_time().val;
+ if (timeout_us > 0 && time_remaining_us <= 0) {
+ /* Ensure we return a TIMER event if we timeout */
+ events |= TASK_EVENT_TIMER;
+ break;
+ }
+ }
+
+ /* Re-post any other events collected */
+ if (events & ~event_mask)
+ tasks[task_get_current()].event |= events & ~event_mask;
+
+ return events & event_mask;
+}
+
void mutex_lock(struct mutex *mtx)
{
int value = 0;