Skip to content
Snippets Groups Projects
Verified Commit f8c5454b authored by rahix's avatar rahix
Browse files

feat(api-demo): Make demo work


Signed-off-by: default avatarRahix <rahix@rahix.de>
parent 9da038a2
No related branches found
No related tags found
No related merge requests found
#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;
}
#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);
}
#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();
......@@ -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
}
......@@ -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
......
......@@ -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++);
......
......@@ -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],
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment