summaryrefslogtreecommitdiff
path: root/common/shared_mem.c
diff options
context:
space:
mode:
authorRandall Spangler <rspangler@chromium.org>2011-12-07 18:51:09 +0000
committerVincent Palatin <vpalatin@chromium.org>2011-12-07 19:10:02 +0000
commitbdf7da5b082f6d18dd27f1e5d8cca0b12154a28c (patch)
tree6f14312a6cc70d056efc2bede8728c0868266719 /common/shared_mem.c
parentabe5786058f4b60dc6d30e7d7c964aae850caa1f (diff)
downloadchrome-ec-bdf7da5b082f6d18dd27f1e5d8cca0b12154a28c.tar.gz
Initial sources import 1/3
source files mainly done by Randall. Signed-off-by: Randall Spangler <rspangler@chromium.org> Change-Id: Iaff83a842b17f3350fb6f2a3f1597ad4c29bd12a
Diffstat (limited to 'common/shared_mem.c')
-rw-r--r--common/shared_mem.c54
1 files changed, 54 insertions, 0 deletions
diff --git a/common/shared_mem.c b/common/shared_mem.c
new file mode 100644
index 0000000000..bff3ec6da3
--- /dev/null
+++ b/common/shared_mem.c
@@ -0,0 +1,54 @@
+/* Copyright (c) 2011 The Chromium OS Authors. All rights reserved.
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+/* Shared memory module for Chrome EC */
+
+#include "shared_mem.h"
+#include "uart.h"
+
+/* Size of shared memory buffer */
+#define SHARED_MEM_SIZE 4096
+
+static char shared_buf[SHARED_MEM_SIZE];
+static int buf_in_use = 0;
+
+
+int shared_mem_init(void)
+{
+ return EC_SUCCESS;
+}
+
+
+int shared_mem_size(void)
+{
+ return SHARED_MEM_SIZE;
+}
+
+
+int shared_mem_acquire(int size, int wait, char **dest_ptr)
+{
+ if (size > SHARED_MEM_SIZE || size <= 0)
+ return EC_ERROR_INVAL;
+
+ /* TODO: if task_start() hasn't been called, fail immediately
+ * if not available. */
+
+ /* TODO: wait if requested; for now, we fail immediately if
+ * not available. */
+ if (buf_in_use)
+ return EC_ERROR_BUSY;
+
+ /* TODO: atomically acquire buf_in_use. */
+ buf_in_use = 1;
+ *dest_ptr = shared_buf;
+ return EC_SUCCESS;
+}
+
+
+void shared_mem_release(void *ptr)
+{
+ /* TODO: use event to wake up a previously-blocking acquire */
+ buf_in_use = 0;
+}