SuperTinyKernel™ RTOS 1.05.3
Lightweight, high-performance, deterministic, bare-metal C++ RTOS for resource-constrained embedded systems. MIT Open Source License.
Loading...
Searching...
No Matches
stk_arch_risc-v.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_RISC_V_H_
11#define STK_ARCH_RISC_V_H_
12
13#include "stk_common.h"
14
18
19namespace stk {
20
25{
26public:
32
37 {
38 public:
42 virtual bool OnException(Word cause) = 0;
43 };
44
45 void Initialize(IEventHandler *event_handler, IKernelService *service, uint32_t resolution_us, Stack *exit_trap);
46 void Start();
47 void Stop();
48 bool InitStack(EStackType stack_type, Stack *stack, IStackMemory *stack_memory, ITask *user_task);
49 uint32_t GetTickResolution() const;
51 void Sleep(Timeout ticks);
52 void SleepUntil(Ticks timestamp);
53 IWaitObject *Wait(ISyncObject *sync_obj, IMutex *mutex, Timeout timeout);
58 TId GetTid() const;
59
61};
62
67
73{
74 Word tp;
75 __asm volatile("mv %0, tp" : "=r"(tp) : /* input: none */ : /* clobbers: none */);
76 return tp;
77}
78
84{
85 __asm volatile("mv tp, %0" : /* output: none */ : "r"(tp) : /* clobbers: none */);
86}
87
88// Notify stk_arch.h that we defined inline versions of GetTls/SetTls.
89#define _STK_INLINE_TLS_DEFINED 1
90
91} // namespace stk
92
96#define __stk_dmb() __asm volatile("fence rw, rw" ::: "memory")
97
102#ifndef STK_SUBMICORSECOND_PRECISION_TIMER
103 #define STK_SUBMICORSECOND_PRECISION_TIMER 0
104#endif
105
109#ifndef STK_SYSTEM_CORE_CLOCK_VAR
110 #define STK_SYSTEM_CORE_CLOCK_VAR SystemCoreClock
111#endif
112
116#ifndef STK_SYSTEM_CORE_CLOCK_FREQUENCY
117 #define STK_SYSTEM_CORE_CLOCK_FREQUENCY 150000000U
118#endif
119
123extern "C" volatile uint32_t STK_SYSTEM_CORE_CLOCK_VAR;
124
125#endif /* STK_ARCH_RISC_V_H_ */
#define STK_SYSTEM_CORE_CLOCK_VAR
Definition of the system core clock variable holding frequency of the CPU in Hz.
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:104
Namespace of STK package.
uintptr_t Word
Native processor word type.
Definition stk_common.h:112
int64_t Ticks
Ticks value.
Definition stk_common.h:150
int32_t Timeout
Timeout time (ticks).
Definition stk_common.h:133
void SetTls(Word tp)
Set thread-local storage (TLS).
EStackType
Stack type.
Definition stk_common.h:70
Word GetTls()
Get thread-local storage (TLS).
PlatformArmCortexM PlatformDefault
Default platform implementation.
Word TId
Definition stk_common.h:117
Concrete implementation of IPlatform driver for the Risc-V processors.
~PlatformRiscV()
Destructor.
void SetEventOverrider(IEventOverrider *overrider)
Set platform event overrider.
void Initialize(IEventHandler *event_handler, IKernelService *service, uint32_t resolution_us, Stack *exit_trap)
Initialize scheduler's context.
void SleepUntil(Ticks timestamp)
Put calling process into a sleep state until the specified timestamp.
void SetSpecificEventHandler(ISpecificEventHandler *handler)
void Stop()
Stop scheduling.
void Sleep(Timeout ticks)
Put calling process into a sleep state.
void SwitchToNext()
Switch to a next task.
void ProcessTick()
Process one tick.
uint32_t GetTickResolution() const
Get resolution of the system tick timer in microseconds. Resolution means a number of microseconds be...
bool InitStack(EStackType stack_type, Stack *stack, IStackMemory *stack_memory, ITask *user_task)
Initialize stack memory of the user task.
void ProcessHardFault()
Cause a hard fault of the system.
IWaitObject * Wait(ISyncObject *sync_obj, IMutex *mutex, Timeout timeout)
Word GetCallerSP() const
Get caller's Stack Pointer (SP).
TId GetTid() const
Get thread Id.
void Start()
Start scheduling.
virtual bool OnException(Word cause)=0
Called by ISR handler on IRQ_XXX (see encoding.h).
Stack descriptor.
Definition stk_common.h:181
Interface for a stack memory region.
Definition stk_common.h:193
Wait object.
Definition stk_common.h:212
Synchronization object.
Definition stk_common.h:297
Interface for mutex synchronization primitive.
Definition stk_common.h:381
Interface for a user task.
Definition stk_common.h:433
Interface for a platform driver.
Definition stk_common.h:575
Interface for a back-end event handler.
Definition stk_common.h:583
Interface for a platform event overrider.
Definition stk_common.h:659
Interface for the kernel services exposed to the user processes during run-time when Kernel started s...
Definition stk_common.h:929