aboutsummaryrefslogtreecommitdiff
path: root/module/eventhandler
diff options
context:
space:
mode:
authorAvinash Mehta <avinash.mehta@arm.com>2019-08-15 14:21:18 +0100
committerTushar Khandelwal <tushar.khandelwal@arm.com>2019-09-04 11:09:24 +0100
commit30099ec7221f5b49b4b62da2ae1b165844a96bed (patch)
tree0b4eeba9bc0d83223e9ca2ce01ec0532645565ad /module/eventhandler
parent564633134c5def8bbd0324eb2649b71203dbb947 (diff)
moving all modules to single folder
moving contents of product/corstone-700/module to module folder Change-Id: I1b1dc32001929dcc082542ab0a1e3be613d47ffc Signed-off-by: Avinash Mehta <avinash.mehta@arm.com>
Diffstat (limited to 'module/eventhandler')
-rw-r--r--module/eventhandler/include/mod_eventhandler.h18
-rw-r--r--module/eventhandler/src/Makefile10
-rw-r--r--module/eventhandler/src/mod_eventhandler.c154
3 files changed, 182 insertions, 0 deletions
diff --git a/module/eventhandler/include/mod_eventhandler.h b/module/eventhandler/include/mod_eventhandler.h
new file mode 100644
index 0000000..9662094
--- /dev/null
+++ b/module/eventhandler/include/mod_eventhandler.h
@@ -0,0 +1,18 @@
+/*
+ * Copyright (c) 2019, Arm Limited and Contributors. All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ *
+ */
+
+#ifndef MOD_EVENTHANDLER_H
+#define MOD_EVENTHANDLER_H
+
+#include <openamp/rpmsg_internal.h>
+#include <stddef.h>
+
+struct mod_eventhandler_api {
+ int (*handleRpmsgEvent)(struct rpmsg_endpoint *ept, void *data, size_t len);
+};
+
+#endif /* MOD_eventhandler_H */
diff --git a/module/eventhandler/src/Makefile b/module/eventhandler/src/Makefile
new file mode 100644
index 0000000..1a04be1
--- /dev/null
+++ b/module/eventhandler/src/Makefile
@@ -0,0 +1,10 @@
+#
+# Copyright (c) 2019, Arm Limited and Contributors. All rights reserved.
+#
+# SPDX-License-Identifier: BSD-3-Clause
+#
+
+BS_LIB_NAME := eventhandler
+BS_LIB_SOURCES := mod_eventhandler.c
+
+include $(BS_DIR)/lib.mk
diff --git a/module/eventhandler/src/mod_eventhandler.c b/module/eventhandler/src/mod_eventhandler.c
new file mode 100644
index 0000000..3d992ba
--- /dev/null
+++ b/module/eventhandler/src/mod_eventhandler.c
@@ -0,0 +1,154 @@
+/*
+ * Copyright (c) 2019, Arm Limited and Contributors. All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ *
+ */
+
+#include <assert.h>
+#include <fwk_module_idx.h>
+#include <fwk_module.h>
+#include <mod_log.h>
+#include <mod_timer.h>
+#include <mod_eventhandler.h>
+#include <se_mhu.h>
+#include <limits.h>
+#include <openamp/rpmsg.h>
+
+const struct mod_log_api *log_api;
+const struct mod_timer_alarm_api *timer_api;
+
+/* MHU Test command syntax
+ bit 3 downto 0 : command
+ bit 31 downto 4 : value
+*/
+
+#define BITMASK(x) ((unsigned int)-1 >> ((sizeof(int) * CHAR_BIT) - x))
+#define CMD_WIDTH 4
+#define COMMAND(message) (message & BITMASK(CMD_WIDTH))
+#define VALUE(message) ((unsigned int)message >> CMD_WIDTH)
+#define ENCODE(command, value) ((command & BITMASK(CMD_WIDTH)) |\
+ ((value) << CMD_WIDTH))
+
+enum Command {
+ NONE,
+ // Increment the value and return to sender
+ INC_RETURN,
+ // Start a single shot timer
+ TIMER_ONCE,
+ NUM_COMMANDS,
+};
+
+void timerCallback(uintptr_t param)
+{
+ log_api->log(MOD_LOG_GROUP_INFO, "Timer callback executed\r\n");
+}
+
+static void timerTest(void)
+{
+ const int ms = 3000;
+ log_api->log(MOD_LOG_GROUP_INFO,
+ "Starting single-shot timer for %dms ...\r\n", ms);
+ timer_api->start(FWK_ID_SUB_ELEMENT(FWK_MODULE_IDX_TIMER, 0, 0),
+ ms, MOD_TIMER_ALARM_TYPE_ONCE, timerCallback, 0);
+ log_api->log(MOD_LOG_GROUP_INFO,
+ "Timer started\r\n", ms);
+}
+
+static int handleRpmsgEvent(struct rpmsg_endpoint *ept, void *data, size_t len)
+{
+ if (ept->dest_addr == MHU_SEND_S_BASE)
+ log_api->log(MOD_LOG_GROUP_INFO, "From Host MHU0\n");
+ else if (ept->dest_addr == MHU_SEND_NS_BASE)
+ log_api->log(MOD_LOG_GROUP_INFO, "From Host MHU1\n");
+ else if (ept->dest_addr == MHU_SE_ES_0_BASE)
+ log_api->log(MOD_LOG_GROUP_INFO, "From ES0 MHU0\n");
+ else if (ept->dest_addr == MHU_SE_ES_1_BASE)
+ log_api->log(MOD_LOG_GROUP_INFO, "From ES0 MHU1\n");
+ else
+ log_api->log(MOD_LOG_GROUP_INFO, "From unknown source\n");
+
+ int message = *(int*)data;
+ switch (COMMAND(message)) {
+ case NONE:
+ log_api->log(MOD_LOG_GROUP_INFO,
+ "CMD: Do nothing...\r\n");
+ break;
+ case INC_RETURN: {
+ log_api->log(MOD_LOG_GROUP_INFO,
+ "CMD: Increment and return to sender...\r\n");
+ const int command = ENCODE(NONE, VALUE(message) + 1);
+ int status = rpmsg_send(ept, &command, sizeof(command));
+ if (status != RPMSG_SUCCESS) {
+ log_api->log(MOD_LOG_GROUP_INFO,
+ "EventHandler: Could not send message via rpmsg_send\r\n");
+ }
+ break;
+ }
+ case TIMER_ONCE: {
+ log_api->log(MOD_LOG_GROUP_INFO,
+ "CMD: Test single shot timer\r\n", COMMAND(message));
+ timerTest();
+ break;
+ }
+ default: {
+ log_api->log(MOD_LOG_GROUP_INFO,
+ "CMD: Unknwn command: %u\r\n", COMMAND(message));
+ break;
+ }
+ }
+ return FWK_SUCCESS;
+}
+
+static struct mod_eventhandler_api module_api = {
+ .handleRpmsgEvent = handleRpmsgEvent,
+};
+
+static int eventhandler_process_bind_request(
+ fwk_id_t requester_id,
+ fwk_id_t id,
+ fwk_id_t api_id,
+ const void **api)
+{
+ *api = &module_api;
+ return FWK_SUCCESS;
+}
+
+static int eventhandler_init(fwk_id_t id, unsigned int element_count,
+ const void* data)
+{
+ return FWK_SUCCESS;
+}
+
+static int eventhandler_bind(fwk_id_t id, unsigned int round)
+{
+ int status;
+
+ if ((round == 1)) {
+ status = fwk_module_bind(FWK_ID_MODULE(FWK_MODULE_IDX_LOG),
+ FWK_ID_API(FWK_MODULE_IDX_LOG, 0),
+ &log_api);
+ if (status != FWK_SUCCESS) {
+ /* Unable to bind back to SMT channel */
+ assert(false);
+ return status;
+ }
+ status = fwk_module_bind(FWK_ID_SUB_ELEMENT(FWK_MODULE_IDX_TIMER, 0, 0),
+ FWK_ID_API(FWK_MODULE_IDX_TIMER,
+ MOD_TIMER_API_IDX_ALARM), &timer_api);
+ if (status != FWK_SUCCESS) {
+ assert(false);
+ return status;
+ }
+ }
+ return FWK_SUCCESS;
+}
+
+const struct fwk_module module_eventhandler = {
+ .name = "eventhandler",
+ .type = FWK_MODULE_TYPE_DRIVER,
+ .api_count = 1,
+ .bind = eventhandler_bind,
+ .init = eventhandler_init,
+ .process_bind_request = eventhandler_process_bind_request,
+};