Mark3 Realtime Kernel
kernel.cpp
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 ===========================================================================*/
21 #include "mark3.h"
22 namespace Mark3
23 {
25 bool Kernel::m_bIsPanic;
27 
28 #if KERNEL_THREAD_CREATE_CALLOUT
30 #endif // #if KERNEL_THREAD_CREATE_CALLOUT
31 #if KERNEL_THREAD_EXIT_CALLOUT
33 #endif // #if KERNEL_THREAD_EXIT_CALLOUT
34 #if KERNEL_CONTEXT_SWITCH_CALLOUT
36 #endif // #if KERNEL_CONTEXT_SWITCH_CALLOUT
38 #if KERNEL_STACK_CHECK
40 #endif // #if KERNEL_STACK_CHECK
41 uint32_t Kernel::m_u32Ticks;
42 
43 //---------------------------------------------------------------------------
45 {
46  // Call port-specific early init function
49  // Initialize the global kernel data - thread-scheduler, and timer-scheduler.
52 #if KERNEL_STACK_CHECK
54 #endif // #if KERNEL_STACK_CHECK
55 }
56 
57 //---------------------------------------------------------------------------
59 {
61 }
62 
63 //---------------------------------------------------------------------------
65 {
66  m_bIsStarted = true;
67 }
68 
69 //---------------------------------------------------------------------------
70 void Kernel::Panic(uint16_t u16Cause_)
71 {
72  m_bIsPanic = true;
73  if (nullptr != m_pfPanic) {
74  m_pfPanic(u16Cause_);
75  } else {
76  while (true) {}
77  }
78 }
79 
80 //---------------------------------------------------------------------------
81 void Kernel::DebugPrint(const char* szString_)
82 {
83  KERNEL_ASSERT(nullptr != szString_);
84  if (nullptr != m_pfDebugPrintFunction) {
85  m_pfDebugPrintFunction(szString_);
86  }
87 }
88 
89 //---------------------------------------------------------------------------
90 uint32_t Kernel::GetTicks()
91 {
92  auto cs = CriticalGuard{};
93  return m_u32Ticks;
94 }
95 
96 } // namespace Mark3
static void StartThreads()
StartThreads Function to start the scheduler, initial threads, etc.
Definition: threadport.cpp:100
void(*)(Thread *pclThread_) ThreadExitCallout
Definition: thread.h:53
void(*)(const char *szString_) DebugPrintFunction
Definition: kernel.h:39
void(*)(Thread *pclThread_) ThreadCreateCallout
Definition: thread.h:52
static void Init()
Init Function to perform early init of the target environment prior to using OS primatives.
Definition: ithreadport.h:43
#define KERNEL_STACK_GUARD_DEFAULT
Definition: portcfg.h:41
static void Init()
Init Initialize the timer scheduler. Must be called before any timer, or timer-derived functions are ...
#define KERNEL_ASSERT(x)
Definition: kerneldebug.h:36
static ThreadExitCallout m_pfThreadExitCallout
Function to call on thread exit.
Definition: kernel.h:217
static void Init(void)
Init Initialize the AutoAllocator before use. Called by Kernel::Init().
Definition: autoalloc.cpp:83
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
Definition: atomic.cpp:23
Single include file given to users of the Mark3 Kernel API.
static PanicFunc m_pfPanic
set panic function
Definition: kernel.h:211
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
The CriticalGuard class. This class provides an implemention of RAII for critical sections...
Definition: criticalguard.h:38
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 Init()
Init Intiailize the scheduler, must be called before use.
Definition: scheduler.cpp:36
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