diff --git a/hw-tests/api-demo/api/api_caller.c b/hw-tests/api-demo/api/api_caller.c
index 3b8d42fa80078f5a950e2f925bf3b182e526f070..311dcc5561187cafd5b685988317ab5d8ee9a58b 100644
--- a/hw-tests/api-demo/api/api_caller.c
+++ b/hw-tests/api-demo/api/api_caller.c
@@ -1,6 +1,7 @@
#include <stdlib.h>
#include "api/api_caller.h"
+#include "tmr_utils.h"
void* api_call_start (uint32_t id, void* args, uint32_t size)
{
@@ -9,13 +10,24 @@ void* api_call_start (uint32_t id, void* args, uint32_t size)
ApiCallSpace->id = id;
ApiCallSpace->returning = 0;
- return ApiCallSpace;
+ return ApiCallSpace->buf;
}
void* api_call_bother_dispatcher (void* buf)
{
SEMA_FreeSema (API_CALL_SEMA);
- // set event
+ // TODO: set event
+
+ while(1) {
+ // aquire semaphore
+ while (E_BUSY == SEMA_GetSema (API_CALL_SEMA)) ;
+ if (ApiCallSpace->returning == 1) {
+ break;
+ }
+ SEMA_FreeSema(API_CALL_SEMA);
+ TMR_Delay(MXC_TMR2, MSEC(100), 0);
+ }
+ SEMA_FreeSema(API_CALL_SEMA);
return NULL;
}
diff --git a/hw-tests/api-demo/api/api_dispatcher.c b/hw-tests/api-demo/api/api_dispatcher.c
index 1b02552e875eb3277412f52ce483820036666543..be5db0967aa78dc0f74f13b9ffb73fd951579662 100644
--- a/hw-tests/api-demo/api/api_dispatcher.c
+++ b/hw-tests/api-demo/api/api_dispatcher.c
@@ -1,7 +1,6 @@
#include "api_dispatcher.h"
-int
-api_init (sys_cfg_sema_t *sys_cfg)
+int api_init (sys_cfg_sema_t *sys_cfg)
{
int ret;
@@ -13,3 +12,23 @@ api_init (sys_cfg_sema_t *sys_cfg)
return ret;
}
+void api_dispatcher()
+{
+ while (SEMA_GetSema(API_CALL_SEMA) == E_BUSY) {}
+
+ if (ApiCallSpace->returning == 1) {
+ SEMA_FreeSema(API_CALL_SEMA);
+ return;
+ }
+
+ printf("core1: Catched API CALL!\n");
+ printf("%d: ",ApiCallSpace->id);
+ for (int i = 0; i < 16; i++) {
+ printf("0x%02x ", ((char*)ApiCallSpace->buf)[i]);
+ }
+ printf("\n");
+
+ ApiCallSpace->returning = 1;
+
+ SEMA_FreeSema(API_CALL_SEMA);
+}
diff --git a/hw-tests/api-demo/api/api_dispatcher.h b/hw-tests/api-demo/api/api_dispatcher.h
index 001e167930e71f6a1ef1a8ca5899c183a023b120..622c347961f3ed686696e7f714e54721b14475cc 100644
--- a/hw-tests/api-demo/api/api_dispatcher.h
+++ b/hw-tests/api-demo/api/api_dispatcher.h
@@ -1,6 +1,6 @@
#include "api_common.h"
#include "mxc_sys.h"
-int
-api_init (sys_cfg_sema_t *sys_cfg);
+int api_init (sys_cfg_sema_t *sys_cfg);
+void api_dispatcher();
diff --git a/hw-tests/api-demo/test-payload.c b/hw-tests/api-demo/core1-dispatcher.c
similarity index 85%
rename from hw-tests/api-demo/test-payload.c
rename to hw-tests/api-demo/core1-dispatcher.c
index 2b4516d484593a28e05dfbdeacd1b95a9541322f..cf1659abf6b552ef0d3ba287a68e2a636b5e9fc2 100644
--- a/hw-tests/api-demo/test-payload.c
+++ b/hw-tests/api-demo/core1-dispatcher.c
@@ -2,6 +2,7 @@
#include "gpio.h"
#include "mxc_delay.h"
#include "api.h"
+#include "tmr_utils.h"
#include "api/api_dispatcher.h"
@@ -27,10 +28,18 @@ void api_set_led(uint8_t led, led_color_t color)
int main(void)
{
api_init(NULL);
+
+ while (1) {
+ api_dispatcher();
+ TMR_Delay(MXC_TMR1, MSEC(100), 0);
+ }
+
+#if 0
// Enable rxev on core1
MXC_GCR->evten |= 0x20;
for (int i = 0; 1; i++) {
__asm volatile("wfe");
printf("core1: Hello! %d\n", i);
}
+#endif
}
diff --git a/hw-tests/api-demo/genapi.py b/hw-tests/api-demo/genapi.py
index 3aacbdc02aa37bb7801d21c73ba45278bb1f36b7..56782979ab07abba68cd84aec162577f41c3e94b 100644
--- a/hw-tests/api-demo/genapi.py
+++ b/hw-tests/api-demo/genapi.py
@@ -80,7 +80,10 @@ def main():
/* Autogenerated stub for {id} */
{cdecl}({cargs}) {{
const int size = {total_size};
- unsigned char buffer[size];
+ void*buffer;
+
+ buffer = api_call_start({id}, size);
+ /* TODO: Check if buffer is no NULL */
""".format(
id=api_id,
cdecl=api_decl,
@@ -102,11 +105,13 @@ def main():
print(
"""
- printf("{id}: ");
+ printf("Sending call {id}\\nBUF: ");
for (int i = 0; i < size; i++) {{
- printf("0x%02x ", buffer[i]);
+ printf("0x%02x ", ((char*)buffer)[i]);
}}
printf("\\n");
+
+ api_call_bother_dispatcher(buffer);
}}
""".format(
id=api_id
diff --git a/hw-tests/api-demo/main.c b/hw-tests/api-demo/main.c
index d3e4fe6b314ceabef6d9938f4f9850b890592f64..bb49d153b2cab798ec6e76472b72f7de79439f72 100644
--- a/hw-tests/api-demo/main.c
+++ b/hw-tests/api-demo/main.c
@@ -24,6 +24,13 @@ int main(void)
card10_diag();
printf("API Test.\n");
+ printf("core0: Starting dispatcher on core1\n");
+ Core1_Start();
+ TMR_Delay(MXC_TMR0, MSEC(100), 0);
+
+ api_set_buzzer(1);
+ TMR_Delay(MXC_TMR0, MSEC(300), 0);
+ api_set_buzzer(0);
while(1) {
printf("count = %d\n", count++);
diff --git a/hw-tests/api-demo/meson.build b/hw-tests/api-demo/meson.build
index 9216e59d04df4d64a3cd2742114c568cadd47921..d80efafa1514d4cfcdc6e37f4b30cb3c7fd8b193 100644
--- a/hw-tests/api-demo/meson.build
+++ b/hw-tests/api-demo/meson.build
@@ -30,7 +30,7 @@ name = 'api-demo-core1'
executable(
name + '.elf',
- 'test-payload.c',
+ 'core1-dispatcher.c',
'./api/api_dispatcher.c',
api_stubs[1],
dependencies: [libcard10, max32665_startup_core1],