From c5da7c7b33ac469f8e054dc02d660bd127991d94 Mon Sep 17 00:00:00 2001
From: ch3 <ch3@mailbox.org>
Date: Thu, 13 Jun 2019 22:41:07 +0200
Subject: [PATCH] Add first API definition

---
 hw-tests/api-demo/api/api_caller.c     | 10 ++++++++++
 hw-tests/api-demo/api/api_caller.h     |  3 +++
 hw-tests/api-demo/api/api_common.h     | 10 ++++++++++
 hw-tests/api-demo/api/api_dispatcher.c | 11 +++++++++++
 hw-tests/api-demo/api/api_dispatcher.h |  5 +++++
 hw-tests/api-demo/test-payload.c       |  3 +++
 6 files changed, 42 insertions(+)
 create mode 100644 hw-tests/api-demo/api/api_caller.c
 create mode 100644 hw-tests/api-demo/api/api_caller.h
 create mode 100644 hw-tests/api-demo/api/api_common.h
 create mode 100644 hw-tests/api-demo/api/api_dispatcher.c
 create mode 100644 hw-tests/api-demo/api/api_dispatcher.h

diff --git a/hw-tests/api-demo/api/api_caller.c b/hw-tests/api-demo/api/api_caller.c
new file mode 100644
index 00000000..ffac1a30
--- /dev/null
+++ b/hw-tests/api-demo/api/api_caller.c
@@ -0,0 +1,10 @@
+void* api_call_start (uint32_t id, void* args, size_t size)
+{
+	// aquire semaphore
+	ret = SEMA_GetSema (API_CALL_SEMA);
+
+	ApiCallSpace->id = id;
+	ApiCallSpace->returning = 0;
+	return ApiCallSpace;
+}
+
diff --git a/hw-tests/api-demo/api/api_caller.h b/hw-tests/api-demo/api/api_caller.h
new file mode 100644
index 00000000..6bb89948
--- /dev/null
+++ b/hw-tests/api-demo/api/api_caller.h
@@ -0,0 +1,3 @@
+#include "api_common.h"
+
+int api_call (uint32_t id, void *args);
diff --git a/hw-tests/api-demo/api/api_common.h b/hw-tests/api-demo/api/api_common.h
new file mode 100644
index 00000000..dbf7f0c4
--- /dev/null
+++ b/hw-tests/api-demo/api/api_common.h
@@ -0,0 +1,10 @@
+#define API_CALL_SEMA 0
+
+struct api_call
+{
+	uint32_t id;
+	uint8_t returning;
+	unsigned char *buf;
+};
+
+static struct api_call **ApiCallSpace = (void*)0x20080001;
diff --git a/hw-tests/api-demo/api/api_dispatcher.c b/hw-tests/api-demo/api/api_dispatcher.c
new file mode 100644
index 00000000..41d3a874
--- /dev/null
+++ b/hw-tests/api-demo/api/api_dispatcher.c
@@ -0,0 +1,11 @@
+#include "api_common.h"
+
+int
+api_init (sys_cfg_sema_t *sys_cfg)
+{
+	int ret;
+
+	ret = SEMA_Init (sys_cfg);
+	ApiCallSpace->returning = 1;
+}
+
diff --git a/hw-tests/api-demo/api/api_dispatcher.h b/hw-tests/api-demo/api/api_dispatcher.h
new file mode 100644
index 00000000..69526574
--- /dev/null
+++ b/hw-tests/api-demo/api/api_dispatcher.h
@@ -0,0 +1,5 @@
+#include "api_common.h"
+
+int
+api_init (sys_cfg_sema_t *sys_cfg);
+
diff --git a/hw-tests/api-demo/test-payload.c b/hw-tests/api-demo/test-payload.c
index f0aa0fe0..2b4516d4 100644
--- a/hw-tests/api-demo/test-payload.c
+++ b/hw-tests/api-demo/test-payload.c
@@ -3,6 +3,8 @@
 #include "mxc_delay.h"
 #include "api.h"
 
+#include "api/api_dispatcher.h"
+
 static const gpio_cfg_t motor_pin = {PORT_0, PIN_8, GPIO_FUNC_OUT, GPIO_PAD_NONE};
 
 void api_set_buzzer(uint8_t state)
@@ -24,6 +26,7 @@ void api_set_led(uint8_t led, led_color_t color)
 
 int main(void)
 {
+	api_init(NULL);
 	// Enable rxev on core1
 	MXC_GCR->evten |= 0x20;
 	for (int i = 0; 1; i++) {
-- 
GitLab