Implement nova64 API with native yield function and registration

This commit is contained in:
Lukas Höppner
2026-08-10 12:43:13 +02:00
parent 1cfcd5a169
commit 27c3aaf88f
7 changed files with 79 additions and 4 deletions
+24
View File
@@ -0,0 +1,24 @@
#include "FreeRTOS.h"
#include "task.h"
#include "wasm_export.h"
#include "projdefs.h"
static void native_yield(wasm_exec_env_t exec_env, uint32_t timeout_ms) {
if (timeout_ms == 0) {
// Gibt die Rest-Quantenzeit ab, blockiert aber nicht künstlich
taskYIELD();
} else {
// Blockiert den Task für x Millisekunden
vTaskDelay(pdMS_TO_TICKS(timeout_ms));
}
}
static NativeSymbol native_symbols[] = {
{"yield", (void *)native_yield, "(i)", NULL},
// { "flush_framebuffer", (void*)native_flush_framebuffer, "()", NULL }
};
void register_nova64_imports(void) {
wasm_runtime_register_natives("nova64", native_symbols,
sizeof(native_symbols) / sizeof(NativeSymbol));
}
+30 -2
View File
@@ -1,6 +1,7 @@
#include "wasm_runner.h"
#include "nova64_fs.h"
#include "nova64_internal.h"
#include "nova64_api.h"
#include "wasm_export.h"
#include <stdlib.h>
@@ -17,6 +18,7 @@ uint32_t stack_size = 8092, heap_size = 8092;
bool wasm_runner_initialize(void) {
wasm_runtime_init();
register_nova64_imports();
nova64_log("WASM runtime initialized successfully.\n");
const char *module_file = "SYS:/init.wasm";
@@ -44,7 +46,33 @@ bool wasm_runner_initialize(void) {
wasm_module_inst_t module_inst = wasm_runtime_instantiate(
module, stack_size, heap_size, error_buf, sizeof(error_buf));
wasm_exec_env_t exec_env = wasm_runtime_create_exec_env(module_inst, stack_size);
wasm_function_inst_t start_func =
wasm_runtime_lookup_function(module_inst, "_start");
if (start_func == NULL) {
nova64_log("Failed to find '_start' function in WASM module: %s\n",
wasm_runtime_get_exception(module_inst));
free(buffer);
return false;
}
wasm_exec_env_t exec_env =
wasm_runtime_create_exec_env(module_inst, stack_size);
uint32_t argv[2] = {5, 3}; // Example arguments for the "add" function
if (wasm_runtime_call_wasm(exec_env, start_func, 2, argv)) {
nova64_log("WASM module executed successfully. Sum: %d\n", argv[0]);
} else {
nova64_log("Failed to execute WASM module: %s\n",
wasm_runtime_get_exception(module_inst));
}
wasm_runtime_destroy_exec_env(exec_env);
wasm_runtime_deinstantiate(module_inst);
wasm_runtime_unload(module);
free(buffer);
wasm_runtime_destroy();
return true;
}