From 6de51563d642027774e73d4720af5ccc15285fbf Mon Sep 17 00:00:00 2001 From: Yuval Peress Date: Thu, 29 Oct 2020 12:11:43 -0600 Subject: Zephyr: add support for shimming the mutex struct This changes creates a common mutex_t which can be used in both platform/ec and zephyr code. It also adds an empty #define for k_mutex_init(mutex) such that the zephyr function can be used without affecting platform/ec. BRANCH=none BUG=b:171896666 TEST=Built platform/ec for boards: volteer & eve Signed-off-by: Yuval Peress Change-Id: I6a711252732697ab120515d916bf388fdcd9544f Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2508414 Reviewed-by: Simon Glass Reviewed-by: Paul Fagerburg Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3700694 Reviewed-by: Tim Wawrzynczak Commit-Queue: Shelley Chen Tested-by: Shelley Chen --- include/task.h | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/include/task.h b/include/task.h index 897ba79f34..eb2105805a 100644 --- a/include/task.h +++ b/include/task.h @@ -315,11 +315,19 @@ int task_reset(task_id_t id, int wait); */ void task_clear_pending_irq(int irq); +#ifdef CONFIG_ZEPHYR +typedef struct k_mutex mutex_t; + +#define mutex_lock(mtx) (k_mutex_lock(mtx, K_FOREVER)) +#define mutex_unlock(mtx) (k_mutex_unlock(mtx)) +#else struct mutex { uint32_t lock; uint32_t waiters; }; +typedef struct mutex mutex_t; + /** * Lock a mutex. * @@ -328,12 +336,16 @@ struct mutex { * * Must not be used in interrupt context! */ -void mutex_lock(struct mutex *mtx); +void mutex_lock(mutex_t *mtx); /** * Release a mutex previously locked by the same task. */ -void mutex_unlock(struct mutex *mtx); +void mutex_unlock(mutex_t *mtx); + +/** Zephyr will try to init the mutex using `k_mutex_init()`. */ +#define k_mutex_init(mutex) 0 +#endif /* CONFIG_ZEPHYR */ struct irq_priority { uint8_t irq; -- cgit v1.2.1