Mark3 Realtime Kernel
Mark3 Namespace Reference

Namespaces

 Atomic
 The Atomic namespace This utility module provides primatives for atomic operations - that is, operations that are guaranteed to execute uninterrupted. Basic atomic primatives provided here include Set/Add/Subtract, as well as an atomic test-and-set.
 

Classes

class  AutoAlloc
 The AutoAlloc class. This class provides an object-allocation interface for both kernel objects and user-defined types. This class supplies callouts for alloc/free that use object-type metadata to determine how objects may be allocated, allowing a user to create custom dynamic memory implementations for specific object types and sizes. As a result, the user-defined allocators can avoid the kinds of memory fragmentation and exhaustion issues that occur in typical embedded systems in which a single heap is used to satisfy all allocations in the application. More...
 
class  BlockingObject
 The BlockingObject class. Class implementing thread-blocking primatives. used for implementing things like semaphores, mutexes, message queues, or anything else that could cause a thread to suspend execution on some external stimulus. More...
 
class  CircularLinkList
 The CircularLinkList class Circular-linked-list data type, inherited from the base LinkList type. More...
 
class  CoList
 The CoList class The CoList class implements a circular-linked-listed structure for coroutine objects. The intent of this object is to maintain a list of active coroutine objects with a specific priority or state, to ensure that a freshly-schedulable co-routine always exists at the head of the list. More...
 
class  ConditionVariable
 The ConditionVariable class This class implements a condition variable. This is a synchronization object that allows multiple threads to block, each waiting for specific signals unique to them. Access to the specified condition is guarded by a mutex that is supplied by the caller. This object can permit multiple waiters that can be unblocked one-at-a-time via signalling, or unblocked all at once via broadcasting. This object is built upon lower-level primatives, and is somewhat more heavyweight than the primative types supplied by the kernel. More...
 
class  Coroutine
 The Coroutine class implements a lightweight, run-to-completion task that forms the basis for co-operative task scheduling in Mark3. Coroutines are designed to be run from a singular context, and scheduled as a result of events occurring from threads, timers, interrupt sources, or other co-routines. More...
 
class  CoScheduler
 The CoScheduler class. This class implements the coroutine scheduler. Similar to the Mark3 thread scheduler, the highest-priority active object is scheduled / returned for execution. If no active co-routines are available to be scheduled, then the scheduler returns nullptr. More...
 
class  CriticalGuard
 The CriticalGuard class. This class provides an implemention of RAII for critical sections. Object creation results in a critical section being invoked. The subsequent destructor call results in the critical section being released. More...
 
class  CriticalSection
 The CriticalSection class. This class implements a portable CriticalSection interface based on macros/inline functions that are implemented as part of each port. More...
 
class  DoubleLinkList
 The DoubleLinkList Class Doubly-linked-list data type, inherited from the base LinkList type. More...
 
class  EventFlag
 The EventFlag class. This class implements a blocking object, similar to a semaphore or mutex, commonly used for synchronizing thread execution based on events occurring within the system. Each EventFlag object contains a 16-bit bitmask, which is used to trigger events on associated threads. Threads wishing to block, waiting for a specific event to occur can wait on any pattern within this 16-bit bitmask to be set. Here, we provide the ability for a thread to block, waiting for ANY bits in a specified mask to be set, or for ALL bits within a specific mask to be set. Depending on how the object is configured, the bits that triggered the wakeup can be automatically cleared once a match has occurred. More...
 
class  Kernel
 The Kernel Class encapsulates all of the kernel startup, configuration and management functions. More...
 
class  KernelSWI
 The KernelSWI Class provides the software-interrupt used to implement the context-switching interrupt used by the kernel. This interface must be implemented by target-specific code in the porting layer. More...
 
class  KernelTimer
 The KernelTimer class provides a timer interface used by all time-based scheduling/timer subsystems in the kernel. This interface must be implemented by target-specific code in the porting layer. More...
 
class  LinkList
 The LinkList Class Abstract-data-type from which all other linked-lists are derived. More...
 
class  LinkListNode
 The LinkListNode Class Basic linked-list node data structure. This data is managed by the linked-list class types, and can be used transparently between them. More...
 
class  LockGuard
 The LockGuard class. This class provides RAII locks based on Mark3's kernel Mutex object. Note that Mark3 does not support exceptions, so care must be taken to ensure that this object is only used where that constraint can be met. More...
 
class  Mailbox
 The Mailbox class. This class implements an IPC mechnism based on sending/receiving envelopes containing data of a fixed size, configured at initialization) that reside within a buffer of memory provided by the user. More...
 
class  MemUtil
 String and Memory manipu32ation class. More...
 
class  Message
 the Message class. This object provides threadsafe message-based IPC services based on exchange of objects containing a data pointer and minimal application-defined metadata. Messages are to be allocated/produced by the sender, and deallocated/consumed by the receiver. More...
 
class  MessagePool
 The MessagePool Class The MessagePool class implements a simple allocator for message objects exchanged between threads. The sender allocates (pop's) messages, then sends them to the receiver. Upon receipt, it is the receiver's responsibility to deallocate (push) the message back to the pool. More...
 
class  MessageQueue
 The MessageQueue class. Implements a mechanism used to send/receive data between threads. Allows threads to block, waiting for messages to be sent from other contexts. More...
 
class  Mutex
 The Mutex Class. Class providing Mutual-exclusion locks, based on BlockingObject. More...
 
class  Notify
 The Notify class. This class provides a blocking object type that allows one or more threads to wait for an event to occur before resuming operation. More...
 
class  PriorityMapL1
 The PriorityMapL1 class This class implements a priority bitmap data structure. Each bit in the objects internal storage represents a priority. When a bit is set, it indicates that something is scheduled at the bit's corresponding priority, when a bit is clear it indicates that no entities are scheduled at that priority. This object provides the fundamental logic required to implement efficient priority-based scheduling for the thread + coroutine schedulers in the kernel. More...
 
class  PriorityMapL2
 The PriorityMapL2 class This class implements a priority bitmap data structure. Each bit in the objects internal storage represents a priority. When a bit is set, it indicates that something is scheduled at the bit's corresponding priority, when a bit is clear it indicates that no entities are scheduled at that priority. This object provides the fundamental logic required to implement efficient priority-based scheduling for the thread + coroutine schedulers in the kernel. More...
 
class  ProfileTimer
 Profiling timer. This class is used to perform high-performance profiling of code to see how int32_t certain operations take. useful in instrumenting the performance of key algorithms and time-critical operations to ensure real-timer behavior. More...
 
class  Quantum
 The Quantum Class. Static-class used to implement Thread quantum functionality, which is fundamental to round-robin thread scheduling. More...
 
class  ReaderWriterLock
 The ReaderWriterLock class. This class implements an object that marshalls access to a resource based on the intended usage of the resource. A reader-writer lock permits multiple concurrent read access, or single-writer access to a resource. If the object holds a write lock, other writers, and all readers will block until the writer is finished. If the object holds reader locks, all writers will block until all readers are finished before the first writer can take ownership of the resource. This is based upon lower-level synchronization primatives, and is somewhat more heavyweight than primative synchronization types. More...
 
class  Scheduler
 The Scheduler Class. This class provides priority-based round-robin Thread scheduling for all active threads managed by the kernel. More...
 
class  SchedulerGuard
 The SchedulerGuard class This class implements RAII-based control of the scheduler's global state. Upon object construction, the scheduler's state is cached locally and the scheduler is disabled (if not already disabled). Upon object destruction, the scheduler's previous state is restored. This object is interrupt-safe, although it has no effect when called from an interrupt given that interrupts are inherently higher-priority than threads. More...
 
class  Semaphore
 the Semaphore class provides Binary & Counting semaphore objects, based on BlockingObject base class. More...
 
class  Streamer
 The Streamer class. This class implements a circular byte-buffer with thread and interrupt safe methods for writing-to and reading-from the buffer. Objects of this class type are designed to be shared between threads, or between threads and interrupts. More...
 
class  Thread
 The Thread Class. This object providing the fundamental thread control data structures and functions that define a single thread of execution in the Mark3 operating system. It is the fundamental data type used to provide multitasking support in the kernel. More...
 
class  ThreadList
 The ThreadList Class. This class is used for building thread-management facilities, such as schedulers, and blocking objects. More...
 
class  ThreadListList
 The ThreadListList class Class used to track all threadlists active in the OS kernel. At any point in time, the list can be traversed to get a complete view of all running, blocked, or stopped threads in the system. More...
 
class  ThreadPort
 The ThreadPort Class defines the target-specific functions required by the kernel for threading. More...
 
class  Timer
 The Timer Class. This class provides kernel-managed timers, used to provide high-precision delays. Functionality is useful to both user-code, and is used extensively within the kernel and its blocking objects to implement round-robin scheduling, thread sleep, and timeouts. Provides one-shot and periodic timers for use by application code. This object relies on a target-defined hardware timer implementation, which is multiplexed by the kernel's timer scheduler. More...
 
class  TimerList
 the TimerList class. This class implements a doubly-linked-list of timer objects. More...
 
class  TimerScheduler
 The TimerScheduler Class. This implements a "Static" class used to manage a global list of timers used throughout the system. More...
 
struct  Token_t
 Token descriptor struct format. More...
 
class  TypedCircularLinkList
 The TypedCircularLinkList Class Circular-linked-list data type, inherited from the base LinkList type, and templated for use with linked-list-node derived data-types. More...
 
class  TypedDoubleLinkList
 The TypedDoubleLinkList Class Doubly-linked-list data type, inherited from the base LinkList type, and templated for use with linked-list-node derived data-types. More...
 
class  TypedLinkListNode
 The TypedLinkListNode class The TypedLinkListNode class provides a linked-list node type for a specified object type. This can be used with typed link-list data structures to manage lists of objects without having to static-cast between the base type and the derived class. More...
 

Typedefs

using AutoAllocAllocator_t = void *(*)(AutoAllocType eType_, size_t sSize_)
 
using AutoAllocFree_t = void(*)(AutoAllocType eType_, void *pvObj_)
 
using CoPrioMap = PriorityMapL1< PORT_PRIO_TYPE, PORT_COROUTINE_PRIORITIES >
 
using CoroutineHandler = void(*)(Coroutine *pclCaller_, void *pvContext_)
 
using PanicFunc = void(*)(uint16_t u16PanicCode_)
 
using IdleFunc = void(*)()
 
using ThreadEntryFunc = void(*)(void *pvArg_)
 
using PriorityMap = PriorityMapL1< PORT_PRIO_TYPE, KERNEL_NUM_PRIORITIES >
 
using ThreadCreateCallout = void(*)(Thread *pclThread_)
 
using ThreadExitCallout = void(*)(Thread *pclThread_)
 
using ThreadContextCallout = void(*)(Thread *pclThread_)
 
using TimerCallback = void(*)(Thread *pclOwner_, void *pvData_)
 

Enumerations

enum  AutoAllocType : uint8_t {
  AutoAllocType::EventFlag, AutoAllocType::MailBox, AutoAllocType::Message, AutoAllocType::MessagePool,
  AutoAllocType::MessageQueue, AutoAllocType::Mutex, AutoAllocType::Notify, AutoAllocType::Semaphore,
  AutoAllocType::Thread, AutoAllocType::Timer, AutoAllocType::ConditionVariable, AutoAllocType::ReaderWriterLock,
  AutoAllocType::Coroutine, AutoAllocType::User, AutoAllocType::Raw = 0xFF
}
 
enum  EventFlagOperation : uint8_t {
  EventFlagOperation::All_Set = 0, EventFlagOperation::Any_Set, EventFlagOperation::All_Clear, EventFlagOperation::Any_Clear,
  EventFlagOperation::Pending_Unblock
}
 
enum  ThreadState : uint8_t {
  ThreadState::Exit = 0, ThreadState::Ready, ThreadState::Blocked, ThreadState::Stop,
  ThreadState::Invalid
}
 

Functions

static void KernelTimer_Task (void *unused)
 
static void Thread_Switch (void)
 
 ISR (INT2_vect) __attribute__((signal
 ISR(INT2 _vect) SWI using INT2 - used to trigger a context switch. More...
 
uint8_t PORT_CLZ (uint8_t in_)
 
void PORT_IRQ_ENABLE ()
 
void PORT_IRQ_DISABLE ()
 
void PORT_CS_ENTER ()
 
void PORT_CS_EXIT ()
 
K_WORD PORT_CS_NESTING ()
 

Variables

static constexpr auto uMaxTimerTicks = uint32_t { 0x7FFFFFFF }
 Maximum value to set. More...
 
static constexpr auto uTimerTicksInvalid = uint32_t { 0 }
 
static constexpr auto uTimerFlagOneShot = uint8_t { 0x01 }
 Timer is one-shot. More...
 
static constexpr auto uTimerFlagActive = uint8_t { 0x02 }
 Timer is currently active. More...
 
static constexpr auto uTimerFlagCallback = uint8_t { 0x04 }
 Timer is pending a callback. More...
 
static constexpr auto uTimerFlagExpired = uint8_t { 0x08 }
 Timer is actually expired. More...
 
 naked
 
static constexpr auto SR_ = uint8_t{0x3F}
 
K_WORD g_kwSFR
 
K_WORD g_kwCriticalCount
 

Typedef Documentation

◆ AutoAllocAllocator_t

using Mark3::AutoAllocAllocator_t = typedef void* (*)(AutoAllocType eType_, size_t sSize_)

Definition at line 54 of file autoalloc.h.

◆ AutoAllocFree_t

using Mark3::AutoAllocFree_t = typedef void (*)(AutoAllocType eType_, void* pvObj_)

Definition at line 55 of file autoalloc.h.

◆ CoPrioMap

◆ CoroutineHandler

using Mark3::CoroutineHandler = typedef void (*)(Coroutine* pclCaller_, void* pvContext_)

Definition at line 40 of file coroutine.h.

◆ IdleFunc

using Mark3::IdleFunc = typedef void (*)()

Function pointer type used to implement the idle function, where support for an idle function (as opposed to an idle thread) exists.

Definition at line 37 of file kerneltypes.h.

◆ PanicFunc

using Mark3::PanicFunc = typedef void (*)(uint16_t u16PanicCode_)

Function pointer type used to implement kernel-panic handlers.

Definition at line 30 of file kerneltypes.h.

◆ PriorityMap

Definition at line 29 of file priomap.h.

◆ ThreadContextCallout

using Mark3::ThreadContextCallout = typedef void (*)(Thread* pclThread_)

Definition at line 54 of file thread.h.

◆ ThreadCreateCallout

using Mark3::ThreadCreateCallout = typedef void (*)(Thread* pclThread_)

Definition at line 52 of file thread.h.

◆ ThreadEntryFunc

using Mark3::ThreadEntryFunc = typedef void (*)(void* pvArg_)

Function pointer type used for thread entrypoint functions

Definition at line 43 of file kerneltypes.h.

◆ ThreadExitCallout

using Mark3::ThreadExitCallout = typedef void (*)(Thread* pclThread_)

Definition at line 53 of file thread.h.

◆ TimerCallback

using Mark3::TimerCallback = typedef void (*)(Thread* pclOwner_, void* pvData_)

This type defines the callback function type for timer events. Since these are called from an interrupt context, they do not operate from within a thread or object context directly – as a result, the context must be manually passed into the calls.

pclOwner_ is a pointer to the thread that owns the timer pvData_ is a pointer to some data or object that needs to know about the timer's expiry from within the timer interrupt context.

Definition at line 50 of file timer.h.

Enumeration Type Documentation

◆ AutoAllocType

enum Mark3::AutoAllocType : uint8_t
strong
Enumerator
EventFlag 
MailBox 
Message 
MessagePool 
MessageQueue 
Mutex 
Notify 
Semaphore 
Thread 
Timer 
ConditionVariable 
ReaderWriterLock 
Coroutine 
User 
Raw 

Definition at line 32 of file autoalloc.h.

◆ EventFlagOperation

enum Mark3::EventFlagOperation : uint8_t
strong

This enumeration describes the different operations supported by the event flag blocking object.

Enumerator
All_Set 

Block until all bits in the specified bitmask are set.

Any_Set 

Block until any bits in the specified bitmask are set.

All_Clear 

Block until all bits in the specified bitmask are cleared.

Any_Clear 

Block until any bits in the specified bitmask are cleared.

Pending_Unblock 

Special code.

Not used by user

Definition at line 50 of file kerneltypes.h.

◆ ThreadState

enum Mark3::ThreadState : uint8_t
strong

Enumeration representing the different states a thread can exist in

Enumerator
Exit 
Ready 
Blocked 
Stop 
Invalid 

Definition at line 62 of file kerneltypes.h.

Function Documentation

◆ ISR()

Mark3::ISR ( INT2_vect  )

ISR(INT2 _vect) SWI using INT2 - used to trigger a context switch.

Definition at line 137 of file threadport.cpp.

◆ KernelTimer_Task()

static void Mark3::KernelTimer_Task ( void *  unused)
static

Definition at line 44 of file kerneltimer.cpp.

◆ PORT_CLZ()

uint8_t Mark3::PORT_CLZ ( uint8_t  in_)
inline

Definition at line 144 of file threadport.h.

◆ PORT_CS_ENTER()

void Mark3::PORT_CS_ENTER ( )
inline

Definition at line 167 of file threadport.h.

◆ PORT_CS_EXIT()

void Mark3::PORT_CS_EXIT ( )
inline

Definition at line 178 of file threadport.h.

◆ PORT_CS_NESTING()

K_WORD Mark3::PORT_CS_NESTING ( )
inline

Definition at line 187 of file threadport.h.

◆ PORT_IRQ_DISABLE()

void Mark3::PORT_IRQ_DISABLE ( )
inline

Definition at line 161 of file threadport.h.

◆ PORT_IRQ_ENABLE()

void Mark3::PORT_IRQ_ENABLE ( )
inline

Definition at line 155 of file threadport.h.

◆ Thread_Switch()

static void Mark3::Thread_Switch ( void  )
static

Definition at line 94 of file threadport.cpp.

Variable Documentation

◆ g_kwCriticalCount

K_WORD Mark3::g_kwCriticalCount

Definition at line 36 of file threadport.cpp.

◆ g_kwSFR

K_WORD Mark3::g_kwSFR

Definition at line 35 of file threadport.cpp.

◆ naked

Mark3::naked

Definition at line 136 of file threadport.cpp.

◆ SR_

constexpr auto Mark3::SR_ = uint8_t{0x3F}
static

Definition at line 137 of file threadport.h.

◆ uMaxTimerTicks

constexpr auto Mark3::uMaxTimerTicks = uint32_t { 0x7FFFFFFF }
static

Maximum value to set.

Definition at line 32 of file timer.h.

◆ uTimerFlagActive

constexpr auto Mark3::uTimerFlagActive = uint8_t { 0x02 }
static

Timer is currently active.

Definition at line 35 of file timer.h.

◆ uTimerFlagCallback

constexpr auto Mark3::uTimerFlagCallback = uint8_t { 0x04 }
static

Timer is pending a callback.

Definition at line 36 of file timer.h.

◆ uTimerFlagExpired

constexpr auto Mark3::uTimerFlagExpired = uint8_t { 0x08 }
static

Timer is actually expired.

Definition at line 37 of file timer.h.

◆ uTimerFlagOneShot

constexpr auto Mark3::uTimerFlagOneShot = uint8_t { 0x01 }
static

Timer is one-shot.

Definition at line 34 of file timer.h.

◆ uTimerTicksInvalid

constexpr auto Mark3::uTimerTicksInvalid = uint32_t { 0 }
static

Definition at line 33 of file timer.h.