31 U8* WasmSequencer ::globalAllocCallback(
void* userdata,
size_t size,
size_t align) {
32 if (userdata ==
nullptr) {
35 return static_cast<WasmSequencer*
>(userdata)->globalAlloc(static_cast<U32>(size),
static_cast<U32
>(align));
38 void WasmSequencer ::globalDeallocCallback(
void* userdata,
U8* ptr,
size_t size,
size_t align) {
41 if (userdata !=
nullptr) {
54 m_heapPoisoned(false),
58 m_hasExecutingContext(false),
60 m_hasPendingTimer(false),
61 m_hostFunctionStart(),
62 m_hasHostFunctionStart(false),
63 m_dequeueSucceeded(false),
65 m_pendingPause(false),
66 m_cancelRequested(false),
67 m_sequencesStarted(0) {}
73 getGlobalAllocatorLock()->
lock();
75 getGlobalAllocatorLock()->
unlock();
91 this->m_heapPages =
reinterpret_cast<U8**
>(ptr);
99 this->m_heapPages[i] =
reinterpret_cast<U8*
>(ptr);
101 this->m_heapPagesUsed = 0;
109 this->m_guestPoolOffset = 0;
110 this->m_guestPool =
reinterpret_cast<U8*
>(ptr);
117 this->m_serialOutBuffer.
setExtBuffer(reinterpret_cast<U8*>(ptr), actualSize);
128 this->m_serialInQueue[i].
setup(reinterpret_cast<U8*>(ptr), actualSize);
139 if (this->m_wasm !=
nullptr) {
140 this->destroyStore();
143 if (this->m_allocator !=
nullptr) {
146 this->m_allocator->
deallocate(static_cast<FwIndexType>(i) + 1, this->m_heapPages[i]);
147 this->m_heapPages[i] =
nullptr;
151 this->m_allocator->
deallocate(0, this->m_heapPages);
154 if (this->m_guestPool !=
nullptr) {
155 this->m_allocator->
deallocate(static_cast<FwIndexType>(this->m_config.
heapPages) + 1, this->m_guestPool);
159 if (this->m_serialOutBuffer.
getBuffAddr() !=
nullptr) {
161 this->m_serialOutBuffer.getBuffAddr());
166 if (this->m_serialInQueue[i].get_capacity() > 0) {
168 this->m_serialInQueue[i].get_buffer());
175 getGlobalAllocatorLock()->
lock();
177 getGlobalAllocatorLock()->
unlock();
180 this->m_allocator =
nullptr;
181 this->m_wasm =
nullptr;
190 void WasmSequencer ::checkTimers_handler(
FwIndexType portNum, U32 context) {
195 void WasmSequencer ::cmdResponseIn_handler(
FwIndexType portNum,
203 const U32 cmdUid = cmdSeq;
204 const U16 sequenceIndex =
static_cast<U16
>((cmdUid & 0xFFFF0000) >> 16);
205 const U16 cmdIndex =
static_cast<U16
>(cmdUid & 0xFFFF);
206 const U16 currentSequenceIndex =
static_cast<U16
>(this->m_sequencesStarted & 0xFFFF);
207 const U16 currentCmdIndex =
static_cast<U16
>(this->m_tlm.commandsDispatched & 0xFFFF);
212 if (sequenceIndex != currentSequenceIndex) {
228 if (cmdIndex != currentCmdIndex) {
234 this->m_pendingHostFunction.clear();
238 this->m_tlm.commandsFailed++;
244 void WasmSequencer ::writeTelemetry_handler(
FwIndexType portNum, U32 context) {
266 filename, runModuleName, args,
273 void WasmSequencer ::seqCancelIn_handler(
FwIndexType portNum) {
285 auto& queue = this->m_serialInQueue[portNum];
291 const FwSizeType capacity = queue.get_capacity();
295 if (headerSize + payloadSize > capacity) {
298 const FwSizeType maxPayload = (capacity > headerSize) ? (capacity - headerSize) : 0;
300 static_cast<U32>(maxPayload));
305 const FwSizeType frameSize = headerSize + payloadSize;
308 if (frameSize > queue.get_free_size()) {
310 switch (fullFullBehavior) {
313 while (frameSize > queue.get_free_size()) {
315 auto status = queue.peek(nextMsgSize);
318 const FwSizeType allocated = queue.get_allocated_size();
319 FW_ASSERT(allocated >= headerSize, portNum, static_cast<FwAssertArgType>(allocated));
320 FW_ASSERT(static_cast<FwSizeType>(nextMsgSize) <= allocated - headerSize, portNum,
321 static_cast<FwAssertArgType>(nextMsgSize), static_cast<FwAssertArgType>(allocated));
323 status = queue.rotate(headerSize + nextMsgSize);
335 FW_ASSERT(
false, portNum, static_cast<FwAssertArgType>(frameSize),
336 static_cast<FwAssertArgType>(queue.get_free_size()), static_cast<FwAssertArgType>(capacity));
344 auto status = sizeSer.
serializeFrom(static_cast<U32>(payloadSize));
347 status = queue.serialize(sizeSer.
getBuffAddr(), headerSize);
350 status = queue.serialize(buffer.
getBuffAddr(), payloadSize);
361 void WasmSequencer ::RUN_cmdHandler(
FwOpcodeType opCode,
365 const SeqArgs& seqArgs) {
370 fileName, runModuleName, seqArgs,
372 WasmSequencer_CommandRequest(opCode, cmdSeq), block,
377 void WasmSequencer ::WAIT_cmdHandler(
FwOpcodeType opCode, U32 cmdSeq) {
387 const auto status = this->m_waiting.
enqueue(WaitingCmd(opCode, cmdSeq));
396 void WasmSequencer ::LOAD_cmdHandler(
FwOpcodeType opCode,
410 void WasmSequencer ::INVOKE_cmdHandler(
FwOpcodeType opCode,
420 WasmSequencer_CommandRequest(opCode, cmdSeq), block,
425 void WasmSequencer ::CANCEL_cmdHandler(
FwOpcodeType opCode, U32 cmdSeq) {
430 void WasmSequencer ::PAUSE_cmdHandler(
FwOpcodeType opCode, U32 cmdSeq) {
437 this->m_pendingPause =
true;
441 void WasmSequencer ::CONTINUE_cmdHandler(
FwOpcodeType opCode, U32 cmdSeq) {
464 void WasmSequencer ::GLOBAL_SET_I32_cmdHandler(
FwOpcodeType opCode,
473 s_value.
u.
i32_ = value;
475 auto status = this->setGlobal(moduleName, name, s_value);
484 void WasmSequencer ::GLOBAL_SET_I64_cmdHandler(
FwOpcodeType opCode,
493 s_value.
u.
i64_ = value;
495 auto status = this->setGlobal(moduleName, name, s_value);
504 void WasmSequencer ::GLOBAL_SET_F32_cmdHandler(
FwOpcodeType opCode,
513 s_value.
u.
f32_ = value;
515 auto status = this->setGlobal(moduleName, name, s_value);
524 void WasmSequencer ::GLOBAL_SET_F64_cmdHandler(
FwOpcodeType opCode,
533 g_value.
u.
f64_ = value;
535 auto status = this->setGlobal(moduleName, name, g_value);
544 void WasmSequencer ::GLOBAL_GET_cmdHandler(
FwOpcodeType opCode,
551 auto status = this->getGlobal(moduleName, name, g_value);
553 switch (g_value.
tag) {
union spacewasm_value_payload_t u
Serialization/Deserialization operation was successful.
void interpreter_sendSignal_hostResumeI32(I32 value)
Send signal hostResumeI32 to state machine interpreter.
void tlmWrite_SequencesSucceeded(U64 arg, Fw::Time _tlmTime=Fw::Time())
FwIdType FwOpcodeType
The type of a command opcode.
void log_WARNING_HI_TooManyBlockingCommands() const
void log_WARNING_LO_CmdResponseFromOldSequence(FwOpcodeType opcode, const Fw::CmdResponse &response, U16 oldSequenceIdx, U16 currentSequenceIdx) const
PlatformSizeType FwSizeType
Auto-generated base for WasmSequencer component.
void log_ACTIVITY_LO_GlobalValueF32(const Fw::StringBase &module_name, const Fw::StringBase &globalName, F32 value) const
Log event GlobalValueF32.
constexpr FwSizeType SPACEWASM_PAGE_SIZE
void tlmWrite_InterpreterState(const Svc::WasmSequencer_InterpreterStateMachine_State &arg, Fw::Time _tlmTime=Fw::Time())
Serializable::SizeType getSize() const override
Get current buffer size.
Interpreter has modules loaded into the store and is ready to execute.
WasmSequencer(const char *const compName)
Construct WasmSequencer object.
enum T e
The raw enum value.
void interpreter_sendSignal_serialInMessage(const FwIndexType &value)
Send signal serialInMessage to state machine interpreter.
void cmdResponse_out(FwOpcodeType opCode, U32 cmdSeq, Fw::CmdResponse response)
Emit command response.
Enum representing a command response.
void deinit() override
Tear down the allocations made by configure()
SerializeStatus serializeFrom(U8 val, Endianness mode=Endianness::BIG) override
Serialize an 8-bit unsigned integer value.
static constexpr FwSizeType SPACEWASM_MEMORY_ALIGNMENT
SpaceWasm has a hard-coded memory alignment requirement.
FwSizeType guestMemorySize
void controller_sendSignal_cancel()
Send signal cancel to state machine controller.
float F32
32-bit floating point
void unlock()
alias for unLock to meet BasicLockable requirements
void log_ACTIVITY_LO_GlobalValueI32(const Fw::StringBase &module_name, const Fw::StringBase &globalName, I32 value) const
Log event GlobalValueI32.
void interpreter_sendSignal_cmd_CONTINUE()
Send signal cmd_CONTINUE to state machine interpreter.
sequencer is spinning the interpreter loop
Svc_WasmSequencer_ControllerStateMachine::State controller_getState() const
Get the state of state machine instance controller.
Models the special case sleeping host function which has a time of it's own.
void log_WARNING_LO_SequenceNotRunning() const
void controller_sendSignal_load(const Svc::WasmSequencer_LoadRequest &value)
Send signal load to state machine controller.
SerialInQueueFullBehavior fullBehavior
Overflow policy applied when a new frame does not fit.
U8 * getBuffAddr()
Get buffer address for data filling (non-const version)
SerialInQueueConfig serialIn[NUM_SERIALIN_INPUT_PORTS]
void interpreter_sendSignal_hostResponseUnexpected(const Svc::WasmSequencer_HostFunction &value)
Send signal hostResponseUnexpected to state machine interpreter.
void tlmWrite_LastTrapReason(const Svc::WasmSequencer_TrapReason &arg, Fw::Time _tlmTime=Fw::Time())
void configure(const Config &cfg, Fw::MemAllocator &mallocator)
void * checkedAllocate(const FwEnumStoreType identifier, FwSizeType &size, bool &recoverable, FwSizeType alignment=alignof(std::max_align_t))
void deinit() override
Allows de-initialization on teardown.
Sequencer blocking state.
void log_ACTIVITY_LO_GlobalValueF64(const Fw::StringBase &module_name, const Fw::StringBase &globalName, F64 value) const
Log event GlobalValueF64.
void log_WARNING_LO_GlobalSetFailed(const Fw::StringBase &module_name, const Fw::StringBase &globalName, const Svc::WasmSequencer_Status &reason) const
Log event GlobalSetFailed.
void log_WARNING_HI_SerialInFrameTooLarge(U32 portIndex, U32 size, U32 maxSize) const
void tlmWrite_SequencesFailed(U64 arg, Fw::Time _tlmTime=Fw::Time())
Command successfully executed.
void tlmWrite_ControllerState(const Svc::WasmSequencer_ControllerStateMachine_State &arg, Fw::Time _tlmTime=Fw::Time())
void log_ACTIVITY_LO_GlobalValueI64(const Fw::StringBase &module_name, const Fw::StringBase &globalName, I64 value) const
Log event GlobalValueI64.
uint8_t U8
8-bit unsigned integer
Svc_WasmSequencer_InterpreterStateMachine::State interpreter_getState() const
Get the state of state machine instance interpreter.
Trigger an assertion if the queue fills and cannot process another message.
Drop the latest message if it cannot fit in the remaining queue space.
void interpreter_sendSignal_checkTimers()
Send signal checkTimers to state machine interpreter.
Command had execution error.
void controller_sendSignal_run(const Svc::WasmSequencer_LoadRequest &value)
Send signal run to state machine controller.
void tlmWrite_SeqName(const Fw::StringBase &arg, Fw::Time _tlmTime=Fw::Time())
void setExtBuffer(U8 *buffPtr, Serializable::SizeType size)
Set the external buffer.
Memory Allocation base class.
void tlmWrite_CommandsFailed(U64 arg, Fw::Time _tlmTime=Fw::Time())
Interpreter does not have any modules loaded or a store initialized.
spacewasm_status_t spacewasm_fprime_deregister_global_allocator(void *userdata)
void log_WARNING_HI_WrongCmdResponseIndex(FwOpcodeType opcode, const Fw::CmdResponse &response, U16 actualCmdIdx, U16 expectedCmdIdx) const
PlatformIndexType FwIndexType
locks a mutex within the current scope
void log_WARNING_LO_GlobalGetFailed(const Fw::StringBase &module_name, const Fw::StringBase &globalName, const Svc::WasmSequencer_Status &reason) const
Log event GlobalGetFailed.
void tlmWrite_SequencesCancelled(U64 arg, Fw::Time _tlmTime=Fw::Time())
spacewasm_status_t spacewasm_fprime_register_global_allocator(spacewasm_global_alloc_fn_t alloc, spacewasm_global_dealloc_fn_t dealloc, void *userdata)
void setup(U8 *const buffer, const FwSizeType size)
double F64
64-bit floating point (double). Required for compiler-supplied double promotion.
Fw::MallocAllocator mallocator
RateGroupDivider component implementation.
virtual void deallocate(const FwEnumStoreType identifier, void *ptr)=0
Success enqueue(const T &e) override
void interpreter_sendSignal_cancel()
Send signal cancel to state machine interpreter.
void interpreter_sendSignal_cmdCancel(const Svc::WasmSequencer_CommandRequest &value)
Send signal cmdCancel to state machine interpreter.
constexpr FwSizeType SPACEWASM_MAX_PAGES
FwSizeType size
Queue size in bytes. A port left at size 0 gets no queue (all inbound frames on that index are droppe...
void controller_sendSignal_invoke(const Svc::WasmSequencer_InvokeRequest &value)
Send signal invoke to state machine controller.
The idle state means there is no function running in the engine.
void lock()
lock the mutex and assert success
void tlmWrite_CommandsDispatched(U64 arg, Fw::Time _tlmTime=Fw::Time())