29 template <HostFn Handler>
36 return (static_cast<WasmSequencer*>(userdata)->*Handler)(caller, params, n_params, out_result);
46 &hostFunctionTrampoline<&WasmSequencer::wasmExit>,
this);
50 &hostFunctionTrampoline<&WasmSequencer::wasmPanic>,
this);
54 &hostFunctionTrampoline<&WasmSequencer::wasmArgs>,
this);
58 &hostFunctionTrampoline<&WasmSequencer::wasmTime>,
this);
62 &hostFunctionTrampoline<&WasmSequencer::wasmReadTelemetry>,
this);
66 &hostFunctionTrampoline<&WasmSequencer::wasmReadParameter>,
this);
70 &hostFunctionTrampoline<&WasmSequencer::wasmCommand>,
this);
74 &hostFunctionTrampoline<&WasmSequencer::wasmEvent>,
this);
78 &hostFunctionTrampoline<&WasmSequencer::wasmRsleep>,
this);
82 &hostFunctionTrampoline<&WasmSequencer::wasmAsleep>,
this);
86 &hostFunctionTrampoline<&WasmSequencer::wasmSerialOut>,
this);
90 &hostFunctionTrampoline<&WasmSequencer::wasmSerialRecv>,
this);
98 FW_ASSERT(!this->m_pendingHostFunction.isPending());
100 FW_ASSERT(n_params == 1, static_cast<FwAssertArgType>(n_params));
105 this->m_exit.code = params[0].
u.
i32_;
114 FW_ASSERT(!this->m_pendingHostFunction.isPending());
116 FW_ASSERT(n_params == 1, static_cast<FwAssertArgType>(n_params));
121 this->m_exit.code = params[0].
u.
i32_;
130 FW_ASSERT(!this->m_pendingHostFunction.isPending());
132 FW_ASSERT(n_params == 2, static_cast<FwAssertArgType>(n_params));
137 const U32 ptr =
static_cast<U32
>(params[0].
u.
i32_);
138 const U32 size =
static_cast<U32
>(params[1].
u.
i32_);
141 this->m_pendingHostFunction.caller = caller;
142 this->m_pendingHostFunction.u.args.ptr = ptr;
143 this->m_pendingHostFunction.u.args.len = size;
152 FW_ASSERT(!this->m_pendingHostFunction.isPending());
154 FW_ASSERT(n_params == 2, static_cast<FwAssertArgType>(n_params));
158 const U32 time_ptr =
static_cast<U32
>(params[0].
u.
i32_);
159 const U32 time_size =
static_cast<U32
>(params[1].
u.
i32_);
172 this->m_pendingHostFunction.caller = caller;
173 this->m_pendingHostFunction.u.time.ptr = time_ptr;
174 this->m_pendingHostFunction.u.time.len = time_size;
180 return return_status;
187 FW_ASSERT(!this->m_pendingHostFunction.isPending());
190 FW_ASSERT(n_params == 5, static_cast<FwAssertArgType>(n_params));
199 I64
id = params[0].
u.
i64_;
200 const U32 time_ptr =
static_cast<U32
>(params[1].
u.
i32_);
201 const U32 time_size =
static_cast<U32
>(params[2].
u.
i32_);
202 const U32 value_ptr =
static_cast<U32
>(params[3].
u.
i32_);
203 const U32 value_size =
static_cast<U32
>(params[4].
u.
i32_);
223 }
else if (
id < 0 || static_cast<U64>(
id) > static_cast<U64>(std::numeric_limits<FwChanIdType>::max())) {
230 this->m_pendingHostFunction.caller = caller;
231 this->m_pendingHostFunction.u.telemetry.chanId =
static_cast<FwChanIdType>(id);
232 this->m_pendingHostFunction.u.telemetry.timePtr = time_ptr;
233 this->m_pendingHostFunction.u.telemetry.timeLen = time_size;
234 this->m_pendingHostFunction.u.telemetry.valuePtr = value_ptr;
235 this->m_pendingHostFunction.u.telemetry.valueLen = value_size;
241 return return_status;
248 FW_ASSERT(!this->m_pendingHostFunction.isPending());
251 FW_ASSERT(n_params == 3, static_cast<FwAssertArgType>(n_params));
258 I64
id = params[0].
u.
i64_;
259 const U32 ptr =
static_cast<U32
>(params[1].
u.
i32_);
260 const U32 len =
static_cast<U32
>(params[2].
u.
i32_);
269 if (
id < 0 || static_cast<U64>(
id) > static_cast<U64>(std::numeric_limits<FwPrmIdType>::max())) {
278 this->m_pendingHostFunction.caller = caller;
279 this->m_pendingHostFunction.u.parameter.prmId =
static_cast<FwPrmIdType>(id);
280 this->m_pendingHostFunction.u.parameter.ptr = ptr;
281 this->m_pendingHostFunction.u.parameter.len = len;
291 FW_ASSERT(!this->m_pendingHostFunction.isPending());
294 FW_ASSERT(n_params == 2, static_cast<FwAssertArgType>(n_params));
298 const U32 ptr =
static_cast<U32
>(params[0].
u.
i32_);
299 const U32 len =
static_cast<U32
>(params[1].
u.
i32_);
310 if (len > maxPayload) {
315 this->m_pendingHostFunction.caller = caller;
316 this->m_pendingHostFunction.u.command.ptr = ptr;
317 this->m_pendingHostFunction.u.command.len = len;
323 return return_status;
330 FW_ASSERT(!this->m_pendingHostFunction.isPending());
333 FW_ASSERT(n_params == 3, static_cast<FwAssertArgType>(n_params));
342 U32 ptr =
static_cast<U32
>(params[1].
u.
i32_);
343 U32 len =
static_cast<U32
>(params[2].
u.
i32_);
350 this->m_pendingHostFunction.caller = caller;
351 this->m_pendingHostFunction.u.event.rawSeverity =
static_cast<U32
>(params[0].
u.
i32_);
352 this->m_pendingHostFunction.u.event.msgPtr = ptr;
353 this->m_pendingHostFunction.u.event.msgLen = len;
362 FW_ASSERT(!this->m_pendingHostFunction.isPending());
364 FW_ASSERT(n_params == 1, static_cast<FwAssertArgType>(n_params));
367 const U64 us =
static_cast<U64
>(params[0].
u.
i64_);
371 if ((us / 1000000
u) >
static_cast<U64
>(std::numeric_limits<U32>::max())) {
377 this->m_pendingHostFunction.caller = caller;
378 this->m_pendingHostFunction.u.rsleep.us = us;
387 FW_ASSERT(!this->m_pendingHostFunction.isPending());
389 FW_ASSERT(n_params == 1, static_cast<FwAssertArgType>(n_params));
392 const U64 us =
static_cast<U64
>(params[0].
u.
i64_);
396 if ((us / 1000000
u) >
static_cast<U64
>(std::numeric_limits<U32>::max())) {
402 this->m_pendingHostFunction.caller = caller;
403 this->m_pendingHostFunction.u.asleep.us = us;
412 FW_ASSERT(!this->m_pendingHostFunction.isPending());
415 FW_ASSERT(n_params == 3, static_cast<FwAssertArgType>(n_params));
420 const I32 index = params[0].
u.
i32_;
421 const U32 ptr =
static_cast<U32
>(params[1].
u.
i32_);
422 const U32 len =
static_cast<U32
>(params[2].
u.
i32_);
429 static_cast<U32>(this->m_serialOutBuffer.
getCapacity()));
441 this->m_pendingHostFunction.caller = caller;
442 this->m_pendingHostFunction.u.serialOut.index =
static_cast<U32
>(index);
443 this->m_pendingHostFunction.u.serialOut.ptr = ptr;
444 this->m_pendingHostFunction.u.serialOut.len = len;
454 FW_ASSERT(!this->m_pendingHostFunction.isPending());
457 FW_ASSERT(n_params == 5, static_cast<FwAssertArgType>(n_params));
464 const I32 index = params[0].
u.
i32_;
465 const U32 data_ptr =
static_cast<U32
>(params[1].
u.
i32_);
466 const U32 data_len =
static_cast<U32
>(params[2].
u.
i32_);
467 const U32 actual_size_ptr =
static_cast<U32
>(params[3].
u.
i32_);
468 const I32 block_type = params[4].
u.
i32_;
476 if (block_type < 0 || block_type > static_cast<I32>(std::numeric_limits<Svc::BlockState::SerialType>::max()) ||
483 this->m_pendingHostFunction.caller = caller;
484 this->m_pendingHostFunction.u.serialRecv.index =
static_cast<U32
>(index);
485 this->m_pendingHostFunction.u.serialRecv.dataPtr = data_ptr;
486 this->m_pendingHostFunction.u.serialRecv.dataSize = data_len;
487 this->m_pendingHostFunction.u.serialRecv.actualSizePtr = actual_size_ptr;
488 this->m_pendingHostFunction.u.serialRecv.blockingType =
static_cast<Svc::BlockState::T>(block_type);
union spacewasm_value_payload_t u
U16 FwPacketDescriptorType
The width of packet descriptors when they are serialized by the framework.
void log_WARNING_HI_HostFunctionInvalidId(const Svc::WasmSequencer_HostFunction &host_function, I64 id) const
The interpreter exited via HOST_TRAP and we indicated HOST_PANIC in the host function.
void log_WARNING_HI_InvalidBlockingTypeValue(I32 invalidValue) const
Log event InvalidBlockingTypeValue.
FwIdType FwPrmIdType
The type of a parameter identifier.
bool isConnected_getTlmChan_OutputPort(FwIndexType portNum) const
struct spacewasm_caller_t spacewasm_caller_t
spacewasm_status_t spacewasm_add_host_function(struct spacewasm_host_t *host, uint32_t module_idx, const char *name, const char *params_sig, const char *returns_sig, spacewasm_host_fn_t f, void *userdata)
bool isConnected_getParam_OutputPort(FwIndexType portNum) const
Serializable::SizeType getCapacity() const override
Get buffer capacity.
static spacewasm_hostcall_result_t hostFunctionTrampoline(struct spacewasm_caller_t *caller, void *userdata, const struct spacewasm_value_t *params, size_t n_params, struct spacewasm_value_t *out_result)
Named trampoline adapting spacewasm's C host-function ABI to a member handler.
void log_WARNING_HI_HostFunctionInvalidPort(const Svc::WasmSequencer_HostFunction &host_function, I32 index, U32 numPorts) const
U8 * getBuffAddr()
Get buffer address for data filling (non-const version)
bool isConnected_serialOut_OutputPort(FwIndexType portNum) const
FwIdType FwChanIdType
The type of a telemetry channel identifier.
spacewasm_status_t spacewasm_add_host_module(struct spacewasm_host_t *host, const char *name, size_t max_functions, size_t max_globals, uint32_t *out_idx)
The interpreter exited via HOST_TRAP but a host function indicated it was a standard exit() ...
spacewasm_hostcall_result_t
void log_WARNING_HI_BufferTooLarge(const Svc::WasmSequencer_HostFunction &host_function, U32 size, U32 maxSize) const
static constexpr FwIndexType getNum_serialOut_OutputPorts()
RateGroupDivider component implementation.
spacewasm_hostcall_result_t(WasmSequencer::*)(struct spacewasm_caller_t *, const struct spacewasm_value_t *, size_t, struct spacewasm_value_t *) HostFn
Member-function signature of a spacewasm host-function handler.
void log_WARNING_HI_SleepDurationTooLarge(const Svc::WasmSequencer_HostFunction &host_function, U64 micros) const
bool isConnected_cmdOut_OutputPort(FwIndexType portNum) const
bool isValid() const
Check raw enum value for validity.
void log_WARNING_HI_BufferTooSmall(const Svc::WasmSequencer_HostFunction &host_function, U32 size, U32 valueSize) const