Mark3 Realtime Kernel
kernel.h
Go to the documentation of this file.
1 /*===========================================================================
2  _____ _____ _____ _____
3  ___| _|__ __|_ |__ __|__ |__ __| __ |__ ______
4 | \ / | || \ || | || |/ / ||___ |
5 | \/ | || \ || \ || \ ||___ |
6 |__/\__/|__|_||__|\__\ __||__|\__\ __||__|\__\ __||______|
7  |_____| |_____| |_____| |_____|
8 
9 --[Mark3 Realtime Platform]--------------------------------------------------
10 
11 Copyright (c) 2012 - 2019 m0slevin, all rights reserved.
12 See license.txt for more information
13 ===========================================================================*/
32 #pragma once
33 
34 #include "mark3cfg.h"
35 #include "kerneltypes.h"
36 #include "paniccodes.h"
37 #include "thread.h"
38 
39 using DebugPrintFunction = void (*)(const char* szString_);
40 
41 namespace Mark3
42 {
43 //---------------------------------------------------------------------------
48 class Kernel
49 {
50 public:
58  static void Init();
59 
71  static void Start();
72 
78  static void CompleteStart();
79 
86  static bool IsStarted() { return m_bIsStarted; }
94  static void SetPanic(PanicFunc pfPanic_) { m_pfPanic = pfPanic_; }
99  static bool IsPanic() { return m_bIsPanic; }
104  static void Panic(uint16_t u16Cause_);
105 
106 #if KERNEL_THREAD_CREATE_CALLOUT
107 
117 #endif // #if KERNEL_THREAD_CREATE_HOOK
118 
119 #if KERNEL_THREAD_EXIT_CALLOUT
120 
131 #endif // #if KERNEL_THREAD_EXIT_CALLOUT
132 
133 #if KERNEL_CONTEXT_SWITCH_CALLOUT
134 
144  {
145  m_pfThreadContextCallout = pfContext_;
146  }
147 #endif // KERNEL_CONTEXT_SWITCH_CALLOUT
148 
155  static void SetDebugPrintFunction(DebugPrintFunction pfPrintFunction_)
156  {
157  m_pfDebugPrintFunction = pfPrintFunction_;
158  }
159 
168  static void DebugPrint(const char* szString_);
169 
170 #if KERNEL_THREAD_CREATE_CALLOUT
171 
179 #endif // #if KERNEL_THREAD_CREATE_HOOK
180 #if KERNEL_THREAD_EXIT_CALLOUT
181 
189 #endif // #if KERNEL_THREAD_EXIT_HOOK
190 #if KERNEL_CONTEXT_SWITCH_CALLOUT
191 
199 #endif // #if KERNEL_CONTEXT_SWITCH_CALLOUT
200 #if KERNEL_STACK_CHECK
201  static void SetStackGuardThreshold(uint16_t u16Threshold_) { m_u16GuardThreshold = u16Threshold_; }
202  static uint16_t GetStackGuardThreshold() { return m_u16GuardThreshold; }
203 #endif // #if KERNEL_STACK_CHECK
204 
205  static void Tick() { m_u32Ticks++; }
206  static uint32_t GetTicks();
207 
208 private:
209  static bool m_bIsStarted;
210  static bool m_bIsPanic;
212 
213 #if KERNEL_THREAD_CREATE_CALLOUT
215 #endif // #if KERNEL_THREAD_CREATE_HOOK
216 #if KERNEL_THREAD_EXIT_CALLOUT
218 #endif // #if KERNEL_THREAD_EXIT_HOOK
219 #if KERNEL_CONTEXT_SWITCH_CALLOUT
221 #endif // #if KERNEL_CONTEXT_SWITCH_CALLOUT
223 #if KERNEL_STACK_CHECK
224  static uint16_t m_u16GuardThreshold;
225 #endif // #if KERNEL_STACK_CHECK
226  static uint32_t m_u32Ticks;
227 };
228 
229 } // namespace Mark3
Basic data type primatives used throughout the OS.
Defines the reason codes thrown when a kernel panic occurs.
void(*)(Thread *pclThread_) ThreadExitCallout
Definition: thread.h:53
static void SetThreadContextSwitchCallout(ThreadContextCallout pfContext_)
SetThreadContextSwitchCallout Set a function to be called on each context switch. ...
Definition: kernel.h:143
void(*)(const char *szString_) DebugPrintFunction
Definition: kernel.h:39
void(*)(Thread *pclThread_) ThreadCreateCallout
Definition: thread.h:52
static ThreadExitCallout m_pfThreadExitCallout
Function to call on thread exit.
Definition: kernel.h:217
The Kernel Class encapsulates all of the kernel startup, configuration and management functions...
Definition: kernel.h:48
static void DebugPrint(const char *szString_)
DebugPrint Print a string to the configured output interface. Has no effect if Kernel::SetDebugPrintF...
Definition: kernel.cpp:81
static bool IsPanic()
IsPanic Returns whether or not the kernel is in a panic state.
Definition: kernel.h:99
static ThreadCreateCallout GetThreadCreateCallout()
GetThreadCreateCallout Return the current function called on every Thread::Init();.
Definition: kernel.h:178
Definition: atomic.cpp:23
static void Tick()
Definition: kernel.h:205
Mark3 Kernel Configuration This file is used to configure the kernel for your specific application in...
Platform independent thread class declarations Threads are an atomic unit of execution, and each instance of the thread class represents an instance of a program running of the processor. The Thread is the fundmanetal user-facing object in the kernel - it is what makes multiprocessing possible from application code.
static void SetThreadCreateCallout(ThreadCreateCallout pfCreate_)
SetThreadCreateCallout Set a function to be called on creation of a new thread. This callout is execu...
Definition: kernel.h:116
static PanicFunc m_pfPanic
set panic function
Definition: kernel.h:211
static ThreadContextCallout GetThreadContextSwitchCallout()
GetThreadContextSwitchCallout Return the current function called on every Thread::ContextSwitchSWI() ...
Definition: kernel.h:198
static uint32_t GetTicks()
Definition: kernel.cpp:90
static void CompleteStart()
CompleteStart Call this from the thread initialization code at the point that the scheduler is to be ...
Definition: kernel.cpp:64
static void Start()
Start the operating system kernel - the current execution context is cancelled, all kernel services a...
Definition: kernel.cpp:58
static bool m_bIsStarted
true if kernel is running, false otherwise
Definition: kernel.h:209
static void SetDebugPrintFunction(DebugPrintFunction pfPrintFunction_)
SetDebugPrintFunction Set the function to be used when printing kernel debug information.
Definition: kernel.h:155
static void SetPanic(PanicFunc pfPanic_)
SetPanic Set a function to be called when a kernel panic occurs, giving the user to determine the beh...
Definition: kernel.h:94
static bool IsStarted()
IsStarted.
Definition: kernel.h:86
static void SetThreadExitCallout(ThreadExitCallout pfExit_)
SetThreadExitCallout Set a function to be called on thread exit. This callout is executed from the be...
Definition: kernel.h:130
static ThreadCreateCallout m_pfThreadCreateCallout
Function to call on thread creation.
Definition: kernel.h:214
void(*)(Thread *pclThread_) ThreadContextCallout
Definition: thread.h:54
static DebugPrintFunction m_pfDebugPrintFunction
Function to call to print debug info.
Definition: kernel.h:222
static uint16_t m_u16GuardThreshold
Definition: kernel.h:224
static bool m_bIsPanic
true if kernel is in panic state, false otherwise
Definition: kernel.h:210
static void SetStackGuardThreshold(uint16_t u16Threshold_)
Definition: kernel.h:201
static uint16_t GetStackGuardThreshold()
Definition: kernel.h:202
static ThreadExitCallout GetThreadExitCallout()
GetThreadExitCallout Return the current function called on every Thread::Exit();. ...
Definition: kernel.h:188
static uint32_t m_u32Ticks
Definition: kernel.h:226
void(*)(uint16_t u16PanicCode_) PanicFunc
Definition: kerneltypes.h:30
static ThreadContextCallout m_pfThreadContextCallout
Function to call on context switch.
Definition: kernel.h:220
static void Init()
Kernel Initialization Function, call before any other OS function.
Definition: kernel.cpp:44
static void Panic(uint16_t u16Cause_)
Panic Cause the kernel to enter its panic state.
Definition: kernel.cpp:70