From f8c5454b6e4c4252f711ad4665c8cfd5e108b36c Mon Sep 17 00:00:00 2001 From: Rahix <rahix@rahix.de> Date: Thu, 13 Jun 2019 23:55:31 +0200 Subject: [PATCH] feat(api-demo): Make demo work Signed-off-by: Rahix <rahix@rahix.de> --- hw-tests/api-demo/api/api_caller.c | 16 +++++++++++-- hw-tests/api-demo/api/api_dispatcher.c | 23 +++++++++++++++++-- hw-tests/api-demo/api/api_dispatcher.h | 4 ++-- .../{test-payload.c => core1-dispatcher.c} | 9 ++++++++ hw-tests/api-demo/genapi.py | 11 ++++++--- hw-tests/api-demo/main.c | 7 ++++++ hw-tests/api-demo/meson.build | 2 +- 7 files changed, 62 insertions(+), 10 deletions(-) rename hw-tests/api-demo/{test-payload.c => core1-dispatcher.c} (85%) diff --git a/hw-tests/api-demo/api/api_caller.c b/hw-tests/api-demo/api/api_caller.c index 3b8d42fa8..311dcc556 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 1b02552e8..be5db0967 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 001e16793..622c34796 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 2b4516d48..cf1659abf 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 3aacbdc02..56782979a 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 d3e4fe6b3..bb49d153b 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 9216e59d0..d80efafa1 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], -- GitLab