24 using namespace Mark3;
42 return static_cast<Semaphore_t>(AutoAlloc::NewObject<Semaphore, AutoAllocType::Semaphore>());
48 AutoAlloc::DestroyObject<Semaphore, AutoAllocType::Semaphore>(
static_cast<Semaphore*
>(handle));
54 return static_cast<Mutex_t>(AutoAlloc::NewObject<Mutex, AutoAllocType::Mutex>());
60 AutoAlloc::DestroyObject<Mutex, AutoAllocType::Mutex>(
static_cast<Mutex*
>(handle));
66 return static_cast<EventFlag_t
>(AutoAlloc::NewObject<EventFlag, AutoAllocType::EventFlag>());
72 AutoAlloc::DestroyObject<EventFlag, AutoAllocType::EventFlag>(
static_cast<EventFlag*
>(handle));
78 return static_cast<EventFlag_t
>(AutoAlloc::NewObject<Message, AutoAllocType::Message>());
84 AutoAlloc::DestroyObject<Message, AutoAllocType::Message>(
static_cast<Message*
>(handle));
90 return static_cast<MessageQueue_t>(AutoAlloc::NewObject<MessageQueue, AutoAllocType::MessageQueue>());
96 AutoAlloc::DestroyObject<MessageQueue, AutoAllocType::MessageQueue>(
static_cast<MessageQueue*
>(handle));
102 return static_cast<MessagePool_t>(AutoAlloc::NewObject<MessagePool, AutoAllocType::MessagePool>());
108 AutoAlloc::DestroyObject<MessagePool, AutoAllocType::MessagePool>(
static_cast<MessagePool*
>(handle));
114 return static_cast<Notify_t>(AutoAlloc::NewObject<Notify, AutoAllocType::Notify>());
120 AutoAlloc::DestroyObject<Notify, AutoAllocType::Notify>(
static_cast<Notify*
>(handle));
125 return static_cast<Mailbox_t>(AutoAlloc::NewObject<Mailbox, AutoAllocType::MailBox>());
130 AutoAlloc::DestroyObject<Mailbox, AutoAllocType::MailBox>(
static_cast<Mailbox*
>(handle));
136 return static_cast<ConditionVariable_t>(AutoAlloc::NewObject<ConditionVariable, AutoAllocType::ConditionVariable>());
141 AutoAlloc::DestroyObject<ConditionVariable, AutoAllocType::ConditionVariable>(
static_cast<ConditionVariable*
>(handle));
147 return static_cast<ReaderWriterLock_t>(AutoAlloc::NewObject<ReaderWriterLock, AutoAllocType::ReaderWriterLock>());
152 AutoAlloc::DestroyObject<ReaderWriterLock, AutoAllocType::ReaderWriterLock>(
static_cast<ReaderWriterLock*
>(handle));
158 return static_cast<Thread_t>(AutoAlloc::NewObject<Thread, AutoAllocType::Thread>());
163 AutoAlloc::DestroyObject<Thread, AutoAllocType::Thread>(
static_cast<Thread*
>(handle));
169 return static_cast<Timer_t>(AutoAlloc::NewObject<Timer, AutoAllocType::Timer>());
174 AutoAlloc::DestroyObject<Timer, AutoAllocType::Timer>(
static_cast<Timer*
>(handle));
180 return static_cast<Coroutine_t>(AutoAlloc::NewObject<Coroutine, AutoAllocType::Coroutine>());
185 AutoAlloc::DestroyObject<Coroutine, AutoAllocType::Coroutine>(
static_cast<Coroutine*
>(handle));
232 #if KERNEL_THREAD_CREATE_CALLOUT 234 void Kernel_SetThreadCreateCallout(thread_create_callout_t pfCreate_)
238 #endif // #if KERNEL_THREAD_CREATE_CALLOUT 240 #if KERNEL_THREAD_EXIT_CALLOUT 241 void Kernel_SetThreadExitCallout(thread_exit_callout_t pfExit_)
245 #endif //#if KERNEL_THREAD_EXIT_CALLOUT 246 #if KERNEL_CONTEXT_SWITCH_CALLOUT 248 void Kernel_SetThreadContextSwitchCallout(thread_context_callout_t pfContext_)
252 #endif // #if KERNEL_CONTEXT_SWITCH_CALLOUT 253 #if KERNEL_THREAD_CREATE_CALLOUT 255 thread_create_callout_t Kernel_GetThreadCreateCallout(
void)
259 #endif // #if KERNEL_THREAD_CREATE_CALLOUT 260 #if KERNEL_THREAD_EXIT_CALLOUT 262 thread_exit_callout_t Kernel_GetThreadExitCallout(
void)
266 #endif // #if KERNEL_THREAD_EXIT_CALLOUT 267 #if KERNEL_CONTEXT_SWITCH_CALLOUT 269 thread_context_callout_t Kernel_GetThreadContextSwitchCallout(
void)
273 #endif // #if KERNEL_CONTEXT_SWITCH_CALLOUT 323 uint16_t u16StackSize_,
328 auto* pclThread =
new ((
void*)handle)
Thread();
329 pclThread->Init(pwStack_, u16StackSize_, uXPriority_, pfEntryPoint_, pvArg_);
335 auto* pclThread =
static_cast<Thread*
>(handle);
342 auto* pclThread =
static_cast<Thread*
>(handle);
348 auto* pclThread =
static_cast<Thread*
>(handle);
354 auto* pclThread =
static_cast<Thread*
>(handle);
361 auto* pclThread =
static_cast<Thread*
>(handle);
367 auto* pclThread =
static_cast<Thread*
>(handle);
374 auto* pclThread =
static_cast<Thread*
>(handle);
380 auto* pclThread =
static_cast<Thread*
>(handle);
387 auto* pclThread =
static_cast<Thread*
>(handle);
394 auto* pclThread =
static_cast<Thread*
>(handle);
404 #if KERNEL_EXTENDED_CONTEXT 406 void* Thread_GetExtendedContext(
Thread_t handle)
408 auto* pclThread =
static_cast<Thread*
>(handle);
413 void Thread_SetExtendedContext(
Thread_t handle,
void* pvData_)
415 auto* pclThread =
static_cast<Thread*
>(handle);
418 #endif // #if KERNEL_EXTENDED_CONTEXT 433 auto* pclThread =
static_cast<Thread*
>(handle);
434 pclThread->
SetID(u8ID_);
439 auto* pclThread =
static_cast<Thread*
>(handle);
440 return pclThread->
GetID();
445 auto* pclThread =
static_cast<Thread*
>(handle);
451 auto* pclThread =
static_cast<Thread*
>(handle);
461 auto* pclTimer =
new ((
void*)handle)
Timer();
468 auto* pclTimer =
static_cast<Timer*
>(handle);
469 pclTimer->
Start(bRepeat_, u32IntervalMs_, reinterpret_cast<TimerCallback>(pfCallback_), pvData_);
475 auto* pclTimer =
static_cast<Timer*
>(handle);
482 auto* pclTimer =
static_cast<Timer*
>(handle);
491 auto* pclSemaphore =
new ((
void*)handle)
Semaphore();
492 pclSemaphore->Init(u16InitVal_, u16MaxVal_);
498 auto* pclSemaphore =
static_cast<Semaphore*
>(handle);
499 pclSemaphore->
Post();
505 auto* pclSemaphore =
static_cast<Semaphore*
>(handle);
506 pclSemaphore->
Pend();
512 auto* pclSemaphore =
static_cast<Semaphore*
>(handle);
513 return pclSemaphore->
Pend(u32WaitTimeMS_);
521 auto* pclMutex =
new ((
void*)handle)
Mutex();
528 auto* pclMutex =
static_cast<Mutex*
>(handle);
535 auto* pclMutex =
static_cast<Mutex*
>(handle);
542 auto* pclMutex =
static_cast<Mutex*
>(handle);
543 return pclMutex->
Claim(u32WaitTimeMS_);
546 #if KERNEL_EVENT_FLAGS 550 void EventFlag_Init(EventFlag_t handle)
552 auto* pclFlag =
new ((
void*)handle)
EventFlag();
557 uint16_t EventFlag_Wait(EventFlag_t handle, uint16_t u16Mask_, event_flag_operation_t eMode_)
559 auto* pclFlag =
static_cast<EventFlag*
>(handle);
560 return pclFlag->
Wait(u16Mask_, static_cast<EventFlagOperation>(eMode_));
564 uint16_t EventFlag_TimedWait(EventFlag_t handle, uint16_t u16Mask_, event_flag_operation_t eMode_, uint32_t u32TimeMS_)
566 auto* pclFlag =
static_cast<EventFlag*
>(handle);
567 return pclFlag->
Wait(u16Mask_, static_cast<EventFlagOperation>(eMode_), u32TimeMS_);
571 void EventFlag_Set(EventFlag_t handle, uint16_t u16Mask_)
573 auto* pclFlag =
static_cast<EventFlag*
>(handle);
574 pclFlag->
Set(u16Mask_);
578 void EventFlag_Clear(EventFlag_t handle, uint16_t u16Mask_)
580 auto* pclFlag =
static_cast<EventFlag*
>(handle);
581 pclFlag->
Clear(u16Mask_);
585 uint16_t EventFlag_GetMask(EventFlag_t handle)
587 auto* pclFlag =
static_cast<EventFlag*
>(handle);
590 #endif // #if #if KERNEL_EVENT_FLAGS 597 auto* pclNotify =
new ((
void*)handle)
Notify();
604 auto* pclNotify =
static_cast<Notify*
>(handle);
611 auto* pclNotify =
static_cast<Notify*
>(handle);
612 pclNotify->
Wait(pbFlag_);
618 auto* pclNotify =
static_cast<Notify*
>(handle);
619 return pclNotify->
Wait(u32WaitTimeMS_, pbFlag_);
689 auto* pclMessage =
new ((
void*)handle)
Message();
690 return pclMessage->Init();
696 auto* pclMessage =
static_cast<Message*
>(handle);
703 auto* pclMessage =
static_cast<Message*
>(handle);
710 auto* pclMessage =
static_cast<Message*
>(handle);
717 auto* pclMessage =
static_cast<Message*
>(handle);
738 auto* pclMsgPool =
new ((
void*)handle)
MessagePool();
745 auto* pclMsgPool =
static_cast<MessagePool*
>(handle);
746 pclMsgPool->
Push(reinterpret_cast<Message*>(msg));
752 auto* pclMsgPool =
static_cast<MessagePool*
>(handle);
753 return reinterpret_cast<Message_t>(pclMsgPool->Pop());
760 return reinterpret_cast<Message_t>(pclMsgQ->Receive(u32TimeWaitMS_));
767 pclMsgQ->
Send(reinterpret_cast<Message*>(hMessage_));
782 auto* pclMBox =
new ((
void*)handle)
Mailbox();
783 pclMBox->Init(pvBuffer_, u16BufferSize_, u16ElementSize_);
789 auto* pclMBox =
static_cast<Mailbox*
>(handle);
790 return pclMBox->
Send(pvData_);
796 auto* pclMBox =
static_cast<Mailbox*
>(handle);
804 return pclMBox->
Send(pvData_, u32TimeoutMS_);
810 auto* pclMBox =
static_cast<Mailbox*
>(handle);
811 return pclMBox->
SendTail(pvData_, u32TimeoutMS_);
817 auto* pclMBox =
static_cast<Mailbox*
>(handle);
824 auto* pclMBox =
static_cast<Mailbox*
>(handle);
831 auto* pclMBox =
static_cast<Mailbox*
>(handle);
832 return pclMBox->
Receive(pvData_, u32TimeoutMS_);
838 auto* pclMBox =
static_cast<Mailbox*
>(handle);
839 return pclMBox->
ReceiveTail(pvData_, u32TimeoutMS_);
845 auto* pclMBox =
static_cast<Mailbox*
>(handle);
852 auto* pclMBox =
static_cast<Mailbox*
>(handle);
859 auto* pclMBox =
static_cast<Mailbox*
>(handle);
875 auto* pclMutex =
static_cast<Mutex*
>(hMutex_);
876 pclCondvar->Wait(pclMutex);
894 auto* pclMutex =
static_cast<Mutex*
>(hMutex_);
895 return pclCondvar->Wait(pclMutex, u32WaitTimeMS_);
904 pclReaderWriter->Init();
952 auto* pclCoroutine =
static_cast<Coroutine*
>(handle);
953 return pclCoroutine->
Init(uPriority_, reinterpret_cast<CoroutineHandler>(pfHandler_), pvContext_);
959 auto* pclCoroutine =
static_cast<Coroutine*
>(handle);
966 auto* pclCoroutine =
static_cast<Coroutine*
>(handle);
973 auto* pclCoroutine =
static_cast<Coroutine*
>(handle);
980 auto* pclCoroutine =
static_cast<Coroutine*
>(handle);
void * Alloc_Memory(uint16_t u16Size_)
void SetQuantum(uint16_t u16Quantum_)
SetQuantum Set the thread's round-robin execution quantum.
void * GetExtendedContext()
GetExtendedContext Return the Thread object's extended-context data pointer. Used by code implementin...
The MessagePool Class The MessagePool class implements a simple allocator for message objects exchang...
void Thread_Yield(void)
Thread_Yield.
The ReaderWriterLock class. This class implements an object that marshalls access to a resource based...
void Free_Notify(Notify_t handle)
Message * Receive()
Receive.
bool Mailbox_TimedReceiveTail(Mailbox_t handle, void *pvData_, uint32_t u32TimeoutMS_)
Mailbox_TimedReceiveTail.
MessageQueue_t Alloc_MessageQueue(void)
Alloc_MessageQueue.
#define K_WORD
Size of a data word.
void Kernel_SetStackGuardThreshold(uint16_t u16Threshold_)
uint8_t Atomic_Sub8(uint8_t *pu8Source_, uint8_t u8Val_)
Atomic_Sub8.
bool Mailbox_Send(Mailbox_t handle, void *pvData_)
Mailbox_Send.
static bool IsEnabled()
IsEnabled Return the current state of the scheduler - whether or not scheudling is enabled or disable...
Timer_t Alloc_Timer(void)
Alloc_Timer.
bool Semaphore_TimedPend(Semaphore_t handle, uint32_t u32WaitTimeMS_)
Semaphore_TimedPend.
uint16_t GetCode()
GetCode Return the code set in the message upon receipt.
void Exit()
Exit. Remove the thread from being scheduled again. The thread is effectively destroyed when this occ...
void ReaderWriterLock_AcquireReader(ReaderWriterLock_t handle)
ReaderWriterLock_AcquireReader.
ReaderWriterLock_t Alloc_ReaderWriterLock(void)
uint32_t Atomic_Sub32(uint32_t *pu32Source_, uint32_t u32Val_)
Atomic_Sub32.
void * Message_t
Message opaque handle data type.
void Thread_Stop(Thread_t handle)
Thread_Stop.
MessagePool_t Alloc_MessagePool(void)
static void SetThreadContextSwitchCallout(ThreadContextCallout pfContext_)
SetThreadContextSwitchCallout Set a function to be called on each context switch. ...
void Kernel_Init(void)
Kernel_Init.
void * Mutex_t
Mutex opaque handle data type.
void ReaderWriterLock_ReleaseWriter(ReaderWriterLock_t handle)
ReaderWriterLock_ReleaseWriter.
void Free_Message(Message_t handle)
void ConditionVariable_Init(ConditionVariable_t handle)
ConditionVariable_Init.
void MessageQueue_Init(MessageQueue_t handle)
MessageQueue_Init.
const char * GetName()
GetName.
T Set(T *pSource_, T val_)
Set Set a variable to a given value in an uninterruptable operation.
void * Semaphore_t
Semaphore opaque handle data type.
EventFlag_t Alloc_EventFlag(void)
PORT_PRIO_TYPE Coroutine_GetPriority(Coroutine_t handle)
PORT_PRIO_TYPE Thread_GetPriority(Thread_t handle)
Thread_GetPriority.
uint16_t GetFreeSlots(void)
void Free_Memory(void *pvObject_)
Free_Memory.
void Scheduler_Enable(bool bEnable_)
Scheduler_Enable.
static void CoopYield(void)
CoopYield Cooperative yield - This forces the system to not only call the scheduler, but also move the currently executing thread to the back of the current thread list, allowing other same-priority threads the opportunity to run. This is used primarily for cooperative scheduling between threads in the same priority level.
void Free_Mutex(Mutex_t handle)
static void DestroyRawData(void *pvData_)
DestroyRawData Free a previously allocated blob of data allocated via NewRawData() ...
void Release()
Release Release the mutex. When the mutex is released, another object can enter the mutex-protected r...
void Thread_SetID(Thread_t handle, uint8_t u8ID_)
Thread_SetID.
void Start(bool bRepeat_, uint32_t u32IntervalMs_, TimerCallback pfCallback_, void *pvData_)
Start Start a timer using default ownership, using repeats as an option, and millisecond resolution...
uint16_t GetMask()
GetMask Returns the state of the 16-bit bitmask within this object.
bool Mailbox_IsEmpty(Mailbox_t handle)
Mailbox_IsEmpty.
void Thread_Init(Thread_t handle, K_WORD *pwStack_, uint16_t u16StackSize_, PORT_PRIO_TYPE uXPriority_, ThreadEntryFunc pfEntryPoint_, void *pvArg_)
Thread_Init.
bool Kernel_IsPanic(void)
Kernel_IsPanic.
bool Scheduler_IsEnabled(void)
Scheduler_IsEnabled.
void Send(Message *pclSrc_)
Send.
#define PORT_PRIO_TYPE
Type used for bitmap in the PriorityMap class.
void Thread_Start(Thread_t handle)
Thread_Start.
the Semaphore class provides Binary & Counting semaphore objects, based on BlockingObject base class...
uint16_t Kernel_GetStackGuardThreshold(void)
void Set(uint16_t u16Mask_)
Set Set additional flags in this object (logical OR). This API can potentially result in threads bloc...
void Claim()
Claim Claim the mutex. When the mutex is claimed, no other thread can claim a region protected by the...
void * Message_GetData(Message_t handle)
Message_GetData.
void Coroutine_SetPriority(Coroutine_t handle, PORT_PRIO_TYPE uPriority_)
Message_t MessageQueue_Receive(MessageQueue_t handle)
MessageQueue_Receive.
void * Mailbox_t
Mailbox opaque handle data type.
uint16_t MessageQueue_GetCount(MessageQueue_t handle)
MessageQueue_GetCount.
void Activate()
Activate Tag the co-routine as pending execution. Has no effect if the co-routine is already pending ...
void Free_ReaderWriterLock(ReaderWriterLock_t handle)
uint16_t Thread_GetStackSlack(Thread_t handle)
bool Notify_TimedWait(Notify_t handle, uint32_t u32WaitTimeMS_, bool *pbFlag_)
Notify_TimedWait.
bool Kernel_IsStarted(void)
Kernel_IsStarted.
void Kernel_Start(void)
Kernel_Start.
void Mailbox_Init(Mailbox_t handle, void *pvBuffer_, uint16_t u16BufferSize_, uint16_t u16ElementSize_)
Mailbox_Init.
void ReleaseWriter()
ReleaseWriter Release the currently held writer, allowing other readers/writers to access the object...
ConditionVariable_t Alloc_ConditionVariable(void)
static void DebugPrint(const char *szString_)
DebugPrint Print a string to the configured output interface. Has no effect if Kernel::SetDebugPrintF...
void Mutex_Init(Mutex_t handle)
Mutex_Init.
void * Notify_t
Notification object opaque handle data type.
uint32_t Atomic_Set32(uint32_t *pu32Source_, uint32_t u32Val_)
Atomic_Set32.
void Receive(void *pvData_)
Receive Read one envelope from the head of the mailbox. If the mailbox is currently empty...
void Clear(uint16_t u16Mask_)
ClearFlags - Clear a specific set of flags within this object, specific by bitmask.
void Semaphore_Init(Semaphore_t handle, uint16_t u16InitVal_, uint16_t u16MaxVal_)
Semaphore_Init.
static bool IsPanic()
IsPanic Returns whether or not the kernel is in a panic state.
Header providing C-language API bindings for the Mark3 kernel.
void Push(Message *pclMessage_)
Push.
uint16_t GetStackSlack()
GetStackSlack Performs a (somewhat lengthy) check on the thread stack to check the amount of stack ma...
static ThreadCreateCallout GetThreadCreateCallout()
GetThreadCreateCallout Return the current function called on every Thread::Init();.
thread_state_t Thread_GetState(Thread_t handle)
Thread_GetState.
void SetCode(uint16_t u16Code_)
SetCode Set the code in the message before transmission.
void Notify_Signal(Notify_t handle)
Notify_Signal.
void Stop()
Stop Stop a timer already in progress. Has no effect on timers that have already been stopped...
void Free_ConditionVariable(ConditionVariable_t handle)
bool SendTail(void *pvData_)
SendTail Send an envelope to the mailbox. This safely copies the data contents of the datastructure t...
void * Thread_t
Thread opaque handle data type.
void MessageQueue_Send(MessageQueue_t handle, Message_t hMessage_)
MessageQueue_Send.
void ReaderWriterLock_ReleaseReader(ReaderWriterLock_t handle)
ReaderWriterLock_ReleaseReader.
The Mutex Class. Class providing Mutual-exclusion locks, based on BlockingObject. ...
static void SetThreadCreateCallout(ThreadCreateCallout pfCreate_)
SetThreadCreateCallout Set a function to be called on creation of a new thread. This callout is execu...
void Mutex_Release(Mutex_t handle)
Mutex_Release.
PORT_PRIO_TYPE GetCurPriority(void)
GetCurPriority Return the priority of the current thread.
void Mailbox_ReceiveTail(Mailbox_t handle, void *pvData_)
Mailbox_ReceiveTail.
void(* coroutine_callback_t)(Coroutine_t caller, void *pvContext)
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.
void Free_MessageQueue(MessageQueue_t handle)
void Mutex_Claim(Mutex_t handle)
Mutex_Claim.
bool Mailbox_SendTail(Mailbox_t handle, void *pvData_)
Mailbox_SendTail.
Mailbox_t Alloc_Mailbox(void)
Alloc_Mailbox.
void Coroutine_Init(Coroutine_t handle, PORT_PRIO_TYPE uPriority_, coroutine_callback_t pfHandler_, void *pvContext_)
void Free_MessagePool(MessagePool_t handle)
Single include file given to users of the Mark3 Kernel API.
The Thread Class. This object providing the fundamental thread control data structures and functions ...
bool ReaderWriterLock_TimedAcquireWriter(ReaderWriterLock_t handle, uint32_t u32TimeoutMs_)
ReaderWriterLock_TimedAcquireWriter.
void Thread_CoopYield(void)
Thread_CoopYield.
bool Mutex_TimedClaim(Mutex_t handle, uint32_t u32WaitTimeMS_)
Mutex_TimedClaim.
void * ConditionVariable_t
Condition Variable opaque handle data type.
void Notify_Init(Notify_t handle)
Notify_Init.
PORT_PRIO_TYPE Thread_GetCurPriority(Thread_t handle)
Thread_GetCurPriority.
void MessagePool_Push(MessagePool_t handle, Message_t msg)
MessagePool_Push.
Notify_t Alloc_Notify(void)
Alloc_Notify.
void * Coroutine_t
Coroutine opaaque handle data type.
static ThreadContextCallout GetThreadContextSwitchCallout()
GetThreadContextSwitchCallout Return the current function called on every Thread::ContextSwitchSWI() ...
The Notify class. This class provides a blocking object type that allows one or more threads to wait ...
void Thread_SetName(Thread_t handle, const char *szName_)
static uint32_t GetTicks()
void Start()
Start Start the thread - remove it from the stopped list, add it to the scheduler's list of threads (...
Coroutine_t Alloc_Coroutine(void)
void Message_SetData(Message_t handle, void *pvData_)
Message_SetData.
void Free_Semaphore(Semaphore_t handle)
void SetPriority(PORT_PRIO_TYPE uPriority_)
SetPriority Update the scheduling priority of the co-routine. Can be called from within the co-routin...
uint16_t Wait(uint16_t u16Mask_, EventFlagOperation eMode_)
Wait Block a thread on the specific flags in this event flag group.
uint16_t Message_GetCode(Message_t handle)
Message_GetCode.
bool Atomic_TestAndSet(bool *pbLock)
Atomic_TestAndSet.
uint8_t Atomic_Set8(uint8_t *pu8Source_, uint8_t u8Val_)
Atomic_Set8.
static void Yield(void)
Yield Yield the thread - this forces the system to call the scheduler and determine what thread shoul...
void Thread_SetQuantum(Thread_t handle, uint16_t u16Quantum_)
void Timer_Restart(Timer_t handle)
Timer_Restart.
void AcquireReader()
AcquireReader Acquire the object's reader lock. Multiple concurrent readers are allowed. If the writer lock is currently held, the calling thread will wait until the writer lock is relinquished.
PORT_PRIO_TYPE GetPriority()
GetPriority Retrieve the current scheduling priority of the co-routine.
void Signal()
Signal Signal/Unblock the next thread currently blocked on this condition variable.
void Thread_Exit(Thread_t handle)
Thread_Exit.
bool Mailbox_TimedReceive(Mailbox_t handle, void *pvData_, uint32_t u32TimeoutMS_)
Mailbox_TimedReceive.
bool Mailbox_IsFull(Mailbox_t handle)
Mailbox_IsFull.
void MessagePool_Init(MessagePool_t handle)
MessagePool_Init.
void Signal(void)
Signal Signal the notification object. This will cause the highest priority thread currently blocking...
void Timer_Start(Timer_t handle, bool bRepeat_, uint32_t u32IntervalMs_, timer_callback_t pfCallback_, void *pvData_)
Timer_Start.
The Coroutine class implements a lightweight, run-to-completion task that forms the basis for co-oper...
static void Start()
Start the operating system kernel - the current execution context is cancelled, all kernel services a...
void * GetData()
GetData Get the data pointer stored in the message upon receipt.
void Coroutine_Run(Coroutine_t handle)
void Free_Coroutine(Coroutine_t handle)
void SetName(const char *szName_)
SetName Set the name of the thread - this is purely optional, but can be useful when identifying issu...
void Timer_Stop(Timer_t handle)
Timer_Stop.
uint16_t GetQuantum(void)
GetQuantum Get the thread's round-robin execution quantum.
void ConditionVariable_Broadcast(ConditionVariable_t handle)
ConditionVariable_Broadcast.
void AcquireWriter()
AcquireWriter Acquire the writer lock. Only a single writer is allowed to access the object at a time...
uint8_t Atomic_Add8(uint8_t *pu8Source_, uint8_t u8Val_)
Atomic_Add8.
uint16_t Thread_GetQuantum(Thread_t handle)
Message_t MessageQueue_TimedReceive(MessageQueue_t handle, uint32_t u32TimeWaitMS_)
MessageQueue_TimedReceive.
void SetID(uint8_t u8ID_)
SetID Set an arbitrary 8-bit ID to uniquely identify this thread.
static void SetDebugPrintFunction(DebugPrintFunction pfPrintFunction_)
SetDebugPrintFunction Set the function to be used when printing kernel debug information.
void Stop()
Stop Stop a thread that's actively scheduled without destroying its stacks. Stopped threads can be re...
the Message class. This object provides threadsafe message-based IPC services based on exchange of ob...
static void SetPanic(PanicFunc pfPanic_)
SetPanic Set a function to be called when a kernel panic occurs, giving the user to determine the beh...
void Semaphore_Pend(Semaphore_t handle)
Semaphore_Pend.
bool TestAndSet(bool *pbLock)
TestAndSet Test to see if a variable is set, and set it if is not already set. This is an uninterrupt...
void Notify_Wait(Notify_t handle, bool *pbFlag_)
Notify_Wait.
uint16_t GetCount()
GetCount.
uint16_t Atomic_Set16(uint16_t *pu16Source_, uint16_t u16Val_)
Atomic_Set16.
void Wait(bool *pbFlag_)
Wait Block the current thread, waiting for a signal on the object.
bool ConditionVariable_TimedWait(ConditionVariable_t handle, Mutex_t hMutex_, uint32_t u32WaitTimeMS_)
ConditionVariable_TimedWait.
Message_t MessagePool_Pop(MessagePool_t handle)
MessagePool_Pop.
void Run()
Run Clear the co-routine's pending execution flag, and execute the coroutine's handler function...
static bool IsStarted()
IsStarted.
static void SetThreadExitCallout(ThreadExitCallout pfExit_)
SetThreadExitCallout Set a function to be called on thread exit. This callout is executed from the be...
Thread_t Scheduler_GetCurrentThread(void)
Scheduler_GetCurrentThread.
void Kernel_DebugPrint(const char *szString_)
KernelDebug_DebugPrint.
void Pend()
Decrement the semaphore count. If the count is zero, the calling Thread will block until the semaphor...
Mutex_t Alloc_Mutex(void)
Alloc_Mutex.
void(*)(void *pvArg_) ThreadEntryFunc
void ConditionVariable_Wait(ConditionVariable_t handle, Mutex_t hMutex_)
ConditionVariable_Wait.
The ConditionVariable class This class implements a condition variable. This is a synchronization obj...
uint32_t Atomic_Add32(uint32_t *pu32Source_, uint32_t u32Val_)
Atomic_Add32.
static void Sleep(uint32_t u32TimeMs_)
Sleep Put the thread to sleep for the specified time (in milliseconds). Actual time slept may be long...
void * ReaderWriterLock_t
Reader-writer-lock opaque handle data type.
void Free_EventFlag(EventFlag_t handle)
uint16_t Atomic_Sub16(uint16_t *pu16Source_, uint16_t u16Val_)
Atomic_Sub16.
void(* panic_func_t)(uint16_t u16PanicCode_)
The Mailbox class. This class implements an IPC mechnism based on sending/receiving envelopes contain...
uint8_t GetID()
GetID Return the thread's integer ID. Note that this ID is not guaranteed to be unique when dynamic t...
Thread_t Alloc_Thread(void)
Alloc_Thread.
void Timer_Init(Timer_t handle)
Timer_Init.
The Timer Class. This class provides kernel-managed timers, used to provide high-precision delays...
static void * NewRawData(size_t sSize_)
NewRawData Attempt to allocate a blob of raw data from the heap.
void * MessagePool_t
MessagePool opaque handle data type.
void Kernel_SetDebugPrintFunction(kernel_debug_print_t pfPrintFunction_)
Kernel_SetDebugPrintFunction.
bool Post()
Increment the semaphore count. If the semaphore count is zero at the time this is called...
void Free_Timer(Timer_t handle)
void Message_SetCode(Message_t handle, uint16_t u16Code_)
Message_SetCode.
uint8_t Thread_GetID(Thread_t handle)
Thread_GetID.
void Init(PORT_PRIO_TYPE uPriority_, CoroutineHandler pfHandler_, void *pvContext_)
Init Initialize the coroutine object prior to use. Must be called before using the other methods in t...
bool ReaderWriterLock_TimedAcquireReader(ReaderWriterLock_t handle, uint32_t u32TimeoutMs_)
ReaderWriterLock_TimedAcquireReader.
void Free_Thread(Thread_t handle)
void(* timer_callback_t)(Thread_t hOwner_, void *pvData_)
Message_t Alloc_Message(void)
Alloc_Message.
static void SetStackGuardThreshold(uint16_t u16Threshold_)
void ReleaseReader()
ReleaseReader Release a previously-held reader lock.
void Thread_SetPriority(Thread_t handle, PORT_PRIO_TYPE uXPriority_)
Thread_SetPriority.
void Thread_Sleep(uint32_t u32TimeMs_)
Thread_Sleep.
static uint16_t GetStackGuardThreshold()
void Broadcast()
Broadcast Unblock all threads currently blocked on this condition variable.
void SetData(void *pvData_)
SetData Set the data pointer for the message before transmission.
void(* kernel_debug_print_t)(const char *szString_)
void * MessageQueue_t
MessageQueue opaque handle data type.
The EventFlag class. This class implements a blocking object, similar to a semaphore or mutex...
static ThreadExitCallout GetThreadExitCallout()
GetThreadExitCallout Return the current function called on every Thread::Exit();. ...
void Free_Mailbox(Mailbox_t handle)
void Kernel_Panic(uint16_t u16Cause_)
Kernel_Panic.
bool Send(void *pvData_)
Send Send an envelope to the mailbox. This safely copies the data contents of the datastructure to th...
PORT_PRIO_TYPE GetPriority(void)
GetPriority Return the priority of the current thread.
const char * Thread_GetName(Thread_t handle)
void ReaderWriterLock_AcquireWriter(ReaderWriterLock_t handle)
ReaderWriterLock_AcquireWriter.
void Kernel_SetPanic(panic_func_t pfPanic_)
Kernel_SetPanic.
void Message_Init(Message_t handle)
Message_Init.
void ConditionVariable_Signal(ConditionVariable_t handle)
ConditionVariable_Signal.
Semaphore_t Alloc_Semaphore(void)
Alloc_Semaphore.
uint16_t Mailbox_GetFreeSlots(Mailbox_t handle)
Mailbox_GetFreeSlots.
T Sub(T *pSource_, T val_)
Sub Subtract a value from a variable in an uninterruptable operation.
void * Timer_t
Timer opaque handle data type.
static Thread * GetCurrentThread()
GetCurrentThread Return the pointer to the currently-running thread.
uint16_t Atomic_Add16(uint16_t *pu16Source_, uint16_t u16Val_)
Atomic_Add16.
uint32_t Kernel_GetTicks(void)
Kernel_GetTicks.
bool Mailbox_TimedSend(Mailbox_t handle, void *pvData_, uint32_t u32TimeoutMS_)
Mailbox_TimedSend.
void Coroutine_Activate(Coroutine_t handle)
void Mailbox_Receive(Mailbox_t handle, void *pvData_)
Mailbox_Receive.
void ReaderWriterLock_Init(ReaderWriterLock_t handle)
ReaderWriterLock_Init.
bool Mailbox_TimedSendTail(Mailbox_t handle, void *pvData_, uint32_t u32TimeoutMS_)
Mailbox_TimedSendTail.
void Semaphore_Post(Semaphore_t handle)
Semaphore_Post.
T Add(T *pSource_, T val_)
Add Add a value to a variable in an uninterruptable operation.
static void Init()
Kernel Initialization Function, call before any other OS function.
void SetPriority(PORT_PRIO_TYPE uXPriority_)
SetPriority. Set the priority of the Thread (running or otherwise) to a different level...
void ReceiveTail(void *pvData_)
ReceiveTail Read one envelope from the tail of the mailbox. If the mailbox is currently empty...
void SetExtendedContext(void *pvData_)
SetExtendedContext Assign the Thread object's extended-context data pointer. Used by code implementin...
static void Panic(uint16_t u16Cause_)
Panic Cause the kernel to enter its panic state.
static bool SetScheduler(bool bEnable_)
SetScheduler Set the active state of the scheduler. When the scheduler is disabled, the next thread is never set; the currently running thread will run forever until the scheduler is enabled again. Care must be taken to ensure that we don't end up trying to block while the scheduler is disabled, otherwise the system ends up in an unusable state.