[Cbe-oss-dev] [PATCH 16/22]MARS/task: add callback system

Yuji Mano yuji.mano at am.sony.com
Fri Mar 20 07:54:38 EST 2009


This patch adds the host callback API to the task library.

Signed-off-by: Yuji Mano <yuji.mano at am.sony.com>
---
 task/include/common/mars/task_types.h |    9 +++++++++
 task/include/host/mars/task.h         |    1 +
 task/include/mpu/mars/task.h          |   15 +++++++++++++++
 task/src/mpu/lib/task.c               |   16 ++++++++++++++++
 task/src/mpu/module/task_module.c     |   17 +++++++++++++++++
 task/src/mpu/module/task_module.h     |   13 +++++++++++++
 6 files changed, 71 insertions(+)

--- a/task/include/common/mars/task_types.h
+++ b/task/include/common/mars/task_types.h
@@ -103,4 +103,13 @@ struct mars_task_args {
 	} type;
 };
 
+/**
+ * \ingroup group_mars_task
+ * \brief MARS task host callback function
+ *
+ * This is the type definition of the host callback function.
+ */
+typedef int (*mars_task_host_callback)(struct mars_task_args *in,
+				       struct mars_task_args *out);
+
 #endif
--- a/task/include/host/mars/task.h
+++ b/task/include/host/mars/task.h
@@ -47,6 +47,7 @@
 #include <stdint.h>
 
 #include <mars/base.h>
+#include <mars/callback_types.h>
 #include <mars/context.h>
 #include <mars/error.h>
 #include <mars/task_barrier.h>
--- a/task/include/mpu/mars/task.h
+++ b/task/include/mpu/mars/task.h
@@ -46,6 +46,7 @@
 
 #include <stdint.h>
 
+#include <mars/callback_types.h>
 #include <mars/error.h>
 #include <mars/task_barrier.h>
 #include <mars/task_event_flag.h>
@@ -231,6 +232,20 @@ int mars_task_try_wait(struct mars_task_
 
 /**
  * \ingroup group_mars_task
+ * \brief <b>[MPU]</b> Calls the specified host callback.
+ *
+ * \param[in] callback_ea	- ea of host callback
+ * \param[in] in		- pointer to args to pass to host callback
+ * \param[out] out		- pointer to args returned by host callback
+ * \return
+ *	MARS_SUCCESS		- host callback successful
+ * \n	MARS_ERROR_FORMAT	- no context save area specified
+ */
+int mars_task_call_host(uint64_t callback_ea, struct mars_callback_args *in,
+			struct mars_callback_args *out);
+
+/**
+ * \ingroup group_mars_task
  * \brief <b>[host/MPU]</b> Gets tick counter value.
  *
  * \note Counter's frequency depends on runtime environment.
--- a/task/src/mpu/lib/task.c
+++ b/task/src/mpu/lib/task.c
@@ -160,6 +160,22 @@ int mars_task_try_wait(struct mars_task_
 	return MARS_SUCCESS;
 }
 
+int mars_task_call_host(uint64_t callback_ea, struct mars_callback_args *in,
+			struct mars_callback_args *out)
+{
+	struct mars_task_context *task;
+
+	/* get task context */
+	task = mars_task_module_get_task();
+
+	/* make sure task context has a context save area */
+	if (!task->context_save_area_ea)
+		return MARS_ERROR_FORMAT;
+
+	return mars_task_module_call_host(callback_ea, in, out,
+					  mars_task_module_get_heap());
+}
+
 uint32_t mars_task_get_ticks(void)
 {
 	return mars_task_module_get_ticks();
--- a/task/src/mpu/module/task_module.c
+++ b/task/src/mpu/module/task_module.c
@@ -232,6 +232,22 @@ static int task_signal_try_wait(void)
 	return mars_module_workload_signal_reset();
 }
 
+static int task_call_host(uint64_t callback_ea, struct mars_callback_args *in,
+			  struct mars_callback_args *out, void *task_heap)
+{
+	int ret;
+
+	ret = mars_module_host_callback_set(callback_ea, in);
+	if (ret != MARS_SUCCESS)
+		return ret;
+
+	task_save(task_heap, 1);
+
+	mars_module_workload_signal_reset();
+
+	return mars_module_host_callback_reset(out);
+}
+
 static struct mars_task_module_syscalls task_module_syscalls =
 {
 	get_ticks,
@@ -248,6 +264,7 @@ static struct mars_task_module_syscalls 
 	task_signal_send,
 	task_signal_wait,
 	task_signal_try_wait,
+	task_call_host,
 
 	mars_module_mutex_lock_get,
 	mars_module_mutex_unlock_put,
--- a/task/src/mpu/module/task_module.h
+++ b/task/src/mpu/module/task_module.h
@@ -41,6 +41,7 @@
 #include <stdint.h>
 #include <unistd.h>
 
+#include "mars/callback_types.h"
 #include "mars/mutex_types.h"
 #include "mars/task_types.h"
 
@@ -67,6 +68,9 @@ struct mars_task_module_syscalls {
 	int	(*signal_send)(uint16_t workload_id);
 	int	(*signal_wait)(void *heap);
 	int	(*signal_try_wait)(void);
+	int	(*call_host)(uint64_t callback_ea,
+			     struct mars_callback_args *in,
+			     struct mars_callback_args *out, void *heap);
 
 	int	(*mutex_lock_get)(uint64_t mutex_ea,
 				  struct mars_mutex *mutex);
@@ -159,6 +163,15 @@ static inline int mars_task_module_signa
 	return (*mars_task_module_syscalls->signal_try_wait)();
 }
 
+static inline int mars_task_module_call_host(uint64_t callback_ea,
+					     struct mars_callback_args *in,
+					     struct mars_callback_args *out,
+					     void *task_heap)
+{
+	return (*mars_task_module_syscalls->call_host)(callback_ea, in, out,
+						       task_heap);
+}
+
 static inline int mars_mutex_lock_get(uint64_t mutex_ea,
 				      struct mars_mutex *mutex)
 {






More information about the cbe-oss-dev mailing list