SuperTinyKernel™ RTOS 1.08.x
Lightweight, high-performance, deterministic, bare-metal C++ RTOS for resource-constrained embedded systems. MIT Open Source License.
Loading...
Searching...
No Matches
stk_arch_x86-win32.h
Go to the documentation of this file.
1/*
2 * SuperTinyKernel(TM) RTOS: Lightweight High-Performance Deterministic C++ RTOS for Embedded Systems.
3 *
4 * Source: https://github.com/SuperTinyKernel-RTOS
5 *
6 * Copyright (c) 2022-2026 Neutron Code Limited <stk@neutroncode.com>. All Rights Reserved.
7 * License: MIT License, see LICENSE for a full text.
8 */
9
10#ifndef STK_ARCH_X86_WIN32_H_
11#define STK_ARCH_X86_WIN32_H_
12
13#include "stk_common.h"
14
18
19namespace stk {
20
26{
27public:
33
34 void Initialize(IEventHandler *event_handler, IKernelService *service, uint32_t resolution_us, Stack *exit_trap) override;
35 void Start() override;
36 void Stop() override;
37 void InitStack(EStackType stack_type, Stack *stack, IStackMemory *stack_memory, ITask *user_task) override;
38 uint32_t GetTickResolution() const override;
39 Cycles GetSysTimerCount() const override;
40 uint32_t GetSysTimerFrequency() const override;
41 void SwitchToNext() override;
42 void ForceContextSwitch(TId id) override;
43 void Sleep(Timeout ticks) override;
44 bool SleepUntil(Ticks timestamp) override;
45 EWaitResult Wait(ISyncObject *sync_obj, IMutex *mutex, Timeout timeout) override;
46 void ProcessTick() override;
47 void ProcessHardFault() override;
48 void SetEventOverrider(IEventOverrider *overrider, bool non_secure) override;
49 Word GetCallerSP() const override;
50 TId GetTid() const override;
51 Timeout Suspend() override;
52 void Resume(Timeout elapsed_ticks) override;
53 void SetCpuFrequency(uint8_t core_id, uint32_t frequency) override;
54};
55
60
61} // namespace stk
62
65#if defined(_MSC_VER)
66 #include <intrin.h>
67 #if defined(_M_IX86) || defined(_M_X64)
68 // x86/x64: full hardware serializing fence
69 static __stk_forceinline void __stk_dmb() { _mm_mfence(); }
70 #elif defined(_M_ARM) || defined(_M_ARM64)
71 // ARM/ARM64: Data Memory Barrier (Inner Shareable)
72 static __stk_forceinline void __stk_dmb() { __dmb(_ARM_BARRIER_ISH); }
73 #endif
74#elif defined(__GNUC__) || defined(__clang__)
75 static __stk_forceinline void __stk_dmb() { __sync_synchronize(); }
76#else
77 #error "__stk_dmb() is not implemented for this compiler."
78#endif
79
80#endif /* STK_ARCH_X86_WIN32_H_ */
static void __stk_dmb()
Hardware memory barrier: ensures visibility across cores and bus masters.
Contains interface definitions of the library.
#define __stk_forceinline
Forces compiler to always inline the decorated function, regardless of optimisation level.
Definition stk_defs.h:277
Namespace of STK package.
uintptr_t Word
Native processor word type.
Definition stk_common.h:143
EWaitResult
Wait result (see IKernelService::Wait).
Definition stk_common.h:121
int64_t Ticks
Ticks value.
Definition stk_common.h:158
int32_t Timeout
Timeout time (ticks).
Definition stk_common.h:153
PlatformArmCortexM PlatformDefault
Default platform implementation.
EStackType
Stack type.
Definition stk_common.h:79
uint64_t Cycles
Cycles value.
Definition stk_common.h:168
Word TId
Task (thread) id.
Definition stk_common.h:148
Concrete implementation of IPlatform driver for the x86 Win32 platform.
EWaitResult Wait(ISyncObject *sync_obj, IMutex *mutex, Timeout timeout) override
Put calling process into a waiting state until synchronization object is signaled or timeout occurs.
void Sleep(Timeout ticks) override
Put calling process into a sleep state.
void Resume(Timeout elapsed_ticks) override
Resume scheduling after a prior Suspend() call.
void Stop() override
Stop scheduling.
void Initialize(IEventHandler *event_handler, IKernelService *service, uint32_t resolution_us, Stack *exit_trap) override
Initialize scheduler's context.
Word GetCallerSP() const override
Get caller's Stack Pointer (SP).
void Start() override
Start scheduling.
uint32_t GetSysTimerFrequency() const override
Get system timer frequency.
uint32_t GetTickResolution() const override
Get resolution of the system tick timer in microseconds. Resolution means a number of microseconds be...
void SetCpuFrequency(uint8_t core_id, uint32_t frequency) override
Notify the scheduler of a CPU core's operating frequency.
void InitStack(EStackType stack_type, Stack *stack, IStackMemory *stack_memory, ITask *user_task) override
Initialize stack memory of the user task.
void ProcessHardFault() override
Cause a hard fault of the system.
void ProcessTick() override
Process one tick.
Cycles GetSysTimerCount() const override
Get system timer count value.
void SetEventOverrider(IEventOverrider *overrider, bool non_secure) override
Set platform event overrider.
bool SleepUntil(Ticks timestamp) override
Put calling process into a sleep state until the specified timestamp.
void ForceContextSwitch(TId id) override
Force context switch.
TId GetTid() const override
Get thread Id.
void SwitchToNext() override
Switch to a next task.
Timeout Suspend() override
Suspend scheduling.
Stack descriptor.
Definition stk_common.h:392
Interface for a stack memory region.
Definition stk_common.h:413
Synchronization object interface.
Definition stk_common.h:564
Interface for mutex synchronization primitive.
Definition stk_common.h:697
Interface for a user task.
Definition stk_common.h:755
Interface for a platform driver.
Definition stk_common.h:978
Interface for a back-end event handler.
Definition stk_common.h:986
Interface for a platform event overrider.
Interface for the kernel services exposed to the user processes during run-time when Kernel started s...