Mark3 Realtime Kernel
mark3c.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 "mark3c.h"
22 #include "mark3.h"
23 
24 using namespace Mark3;
25 
26 //---------------------------------------------------------------------------
27 // Kernel Memory managment APIs
28 //---------------------------------------------------------------------------
29 void* Alloc_Memory(uint16_t u16Size_)
30 {
31  return AutoAlloc::NewRawData(u16Size_);
32 }
33 //---------------------------------------------------------------------------
34 void Free_Memory(void* pvObject_)
35 {
36  AutoAlloc::DestroyRawData(pvObject_);
37 }
38 
39 //---------------------------------------------------------------------------
41 {
42  return static_cast<Semaphore_t>(AutoAlloc::NewObject<Semaphore, AutoAllocType::Semaphore>());
43 }
44 
45 //---------------------------------------------------------------------------
47 {
48  AutoAlloc::DestroyObject<Semaphore, AutoAllocType::Semaphore>(static_cast<Semaphore*>(handle));
49 }
50 
51 //---------------------------------------------------------------------------
53 {
54  return static_cast<Mutex_t>(AutoAlloc::NewObject<Mutex, AutoAllocType::Mutex>());
55 }
56 
57 //---------------------------------------------------------------------------
58 void Free_Mutex(Mutex_t handle)
59 {
60  AutoAlloc::DestroyObject<Mutex, AutoAllocType::Mutex>(static_cast<Mutex*>(handle));
61 }
62 
63 //---------------------------------------------------------------------------
64 EventFlag_t Alloc_EventFlag(void)
65 {
66  return static_cast<EventFlag_t>(AutoAlloc::NewObject<EventFlag, AutoAllocType::EventFlag>());
67 }
68 
69 //---------------------------------------------------------------------------
70 void Free_EventFlag(EventFlag_t handle)
71 {
72  AutoAlloc::DestroyObject<EventFlag, AutoAllocType::EventFlag>(static_cast<EventFlag*>(handle));
73 }
74 
75 //---------------------------------------------------------------------------
77 {
78  return static_cast<EventFlag_t>(AutoAlloc::NewObject<Message, AutoAllocType::Message>());
79 }
80 
81 //---------------------------------------------------------------------------
82 void Free_Message(Message_t handle)
83 {
84  AutoAlloc::DestroyObject<Message, AutoAllocType::Message>(static_cast<Message*>(handle));
85 }
86 
87 //---------------------------------------------------------------------------
89 {
90  return static_cast<MessageQueue_t>(AutoAlloc::NewObject<MessageQueue, AutoAllocType::MessageQueue>());
91 }
92 
93 //---------------------------------------------------------------------------
95 {
96  AutoAlloc::DestroyObject<MessageQueue, AutoAllocType::MessageQueue>(static_cast<MessageQueue*>(handle));
97 }
98 
99 //---------------------------------------------------------------------------
101 {
102  return static_cast<MessagePool_t>(AutoAlloc::NewObject<MessagePool, AutoAllocType::MessagePool>());
103 }
104 
105 //---------------------------------------------------------------------------
107 {
108  AutoAlloc::DestroyObject<MessagePool, AutoAllocType::MessagePool>(static_cast<MessagePool*>(handle));
109 }
110 
111 //---------------------------------------------------------------------------
113 {
114  return static_cast<Notify_t>(AutoAlloc::NewObject<Notify, AutoAllocType::Notify>());
115 }
116 
117 //---------------------------------------------------------------------------
118 void Free_Notify(Notify_t handle)
119 {
120  AutoAlloc::DestroyObject<Notify, AutoAllocType::Notify>(static_cast<Notify*>(handle));
121 }
122 //---------------------------------------------------------------------------
124 {
125  return static_cast<Mailbox_t>(AutoAlloc::NewObject<Mailbox, AutoAllocType::MailBox>());
126 }
127 //---------------------------------------------------------------------------
129 {
130  AutoAlloc::DestroyObject<Mailbox, AutoAllocType::MailBox>(static_cast<Mailbox*>(handle));
131 }
132 
133 //---------------------------------------------------------------------------
135 {
136  return static_cast<ConditionVariable_t>(AutoAlloc::NewObject<ConditionVariable, AutoAllocType::ConditionVariable>());
137 }
138 //---------------------------------------------------------------------------
140 {
141  AutoAlloc::DestroyObject<ConditionVariable, AutoAllocType::ConditionVariable>(static_cast<ConditionVariable*>(handle));
142 }
143 
144 //---------------------------------------------------------------------------
146 {
147  return static_cast<ReaderWriterLock_t>(AutoAlloc::NewObject<ReaderWriterLock, AutoAllocType::ReaderWriterLock>());
148 }
149 //---------------------------------------------------------------------------
151 {
152  AutoAlloc::DestroyObject<ReaderWriterLock, AutoAllocType::ReaderWriterLock>(static_cast<ReaderWriterLock*>(handle));
153 }
154 
155 //---------------------------------------------------------------------------
157 {
158  return static_cast<Thread_t>(AutoAlloc::NewObject<Thread, AutoAllocType::Thread>());
159 }
160 //---------------------------------------------------------------------------
161 void Free_Thread(Thread_t handle)
162 {
163  AutoAlloc::DestroyObject<Thread, AutoAllocType::Thread>(static_cast<Thread*>(handle));
164 }
165 
166 //---------------------------------------------------------------------------
168 {
169  return static_cast<Timer_t>(AutoAlloc::NewObject<Timer, AutoAllocType::Timer>());
170 }
171 //---------------------------------------------------------------------------
172 void Free_Timer(Timer_t handle)
173 {
174  AutoAlloc::DestroyObject<Timer, AutoAllocType::Timer>(static_cast<Timer*>(handle));
175 }
176 
177 //---------------------------------------------------------------------------
179 {
180  return static_cast<Coroutine_t>(AutoAlloc::NewObject<Coroutine, AutoAllocType::Coroutine>());
181 }
182 //---------------------------------------------------------------------------
184 {
185  AutoAlloc::DestroyObject<Coroutine, AutoAllocType::Coroutine>(static_cast<Coroutine*>(handle));
186 }
187 
188 //---------------------------------------------------------------------------
189 // Kernel APIs
190 //---------------------------------------------------------------------------
191 void Kernel_Init(void)
192 {
193  Kernel::Init();
194 }
195 
196 //---------------------------------------------------------------------------
197 void Kernel_Start(void)
198 {
199  Kernel::Start();
200 }
201 
202 //---------------------------------------------------------------------------
204 {
205  return Kernel::IsStarted();
206 }
207 
208 //---------------------------------------------------------------------------
210 {
211  Kernel::SetPanic(static_cast<PanicFunc>(pfPanic_));
212 }
213 
214 //---------------------------------------------------------------------------
215 bool Kernel_IsPanic(void)
216 {
217  return Kernel::IsPanic();
218 }
219 
220 //---------------------------------------------------------------------------
221 void Kernel_Panic(uint16_t u16Cause_)
222 {
223  Kernel::Panic(u16Cause_);
224 }
225 
226 //---------------------------------------------------------------------------
227 uint32_t Kernel_GetTicks(void)
228 {
229  return Kernel::GetTicks();
230 }
231 
232 #if KERNEL_THREAD_CREATE_CALLOUT
233 //---------------------------------------------------------------------------
234 void Kernel_SetThreadCreateCallout(thread_create_callout_t pfCreate_)
235 {
236  Kernel::SetThreadCreateCallout(reinterpret_cast<ThreadCreateCallout>(pfCreate_));
237 }
238 #endif // #if KERNEL_THREAD_CREATE_CALLOUT
239 //---------------------------------------------------------------------------
240 #if KERNEL_THREAD_EXIT_CALLOUT
241 void Kernel_SetThreadExitCallout(thread_exit_callout_t pfExit_)
242 {
243  Kernel::SetThreadExitCallout(reinterpret_cast<ThreadExitCallout>(pfExit_));
244 }
245 #endif //#if KERNEL_THREAD_EXIT_CALLOUT
246 #if KERNEL_CONTEXT_SWITCH_CALLOUT
247 //---------------------------------------------------------------------------
248 void Kernel_SetThreadContextSwitchCallout(thread_context_callout_t pfContext_)
249 {
250  Kernel::SetThreadContextSwitchCallout(reinterpret_cast<ThreadContextCallout>(pfContext_));
251 }
252 #endif // #if KERNEL_CONTEXT_SWITCH_CALLOUT
253 #if KERNEL_THREAD_CREATE_CALLOUT
254 //---------------------------------------------------------------------------
255 thread_create_callout_t Kernel_GetThreadCreateCallout(void)
256 {
257  return reinterpret_cast<thread_create_callout_t>(Kernel::GetThreadCreateCallout());
258 }
259 #endif // #if KERNEL_THREAD_CREATE_CALLOUT
260 #if KERNEL_THREAD_EXIT_CALLOUT
261 //---------------------------------------------------------------------------
262 thread_exit_callout_t Kernel_GetThreadExitCallout(void)
263 {
264  return reinterpret_cast<thread_exit_callout_t>(Kernel::GetThreadExitCallout());
265 }
266 #endif // #if KERNEL_THREAD_EXIT_CALLOUT
267 #if KERNEL_CONTEXT_SWITCH_CALLOUT
268 //---------------------------------------------------------------------------
269 thread_context_callout_t Kernel_GetThreadContextSwitchCallout(void)
270 {
271  return reinterpret_cast<thread_context_callout_t>(Kernel::GetThreadContextSwitchCallout());
272 }
273 #endif // #if KERNEL_CONTEXT_SWITCH_CALLOUT
274 //---------------------------------------------------------------------------
275 void Kernel_SetStackGuardThreshold(uint16_t u16Threshold_)
276 {
277  Kernel::SetStackGuardThreshold(u16Threshold_);
278 }
279 
280 //---------------------------------------------------------------------------
282 {
284 }
285 
286 //---------------------------------------------------------------------------
288 {
289  Kernel::SetDebugPrintFunction(pfPrintFunction_);
290 }
291 
292 //---------------------------------------------------------------------------
293 void Kernel_DebugPrint(const char* szString_)
294 {
295  Kernel::DebugPrint(szString_);
296 }
297 
298 //---------------------------------------------------------------------------
299 // Scheduler APIs
300 void Scheduler_Enable(bool bEnable_)
301 {
302  Scheduler::SetScheduler(bEnable_);
303 }
304 
305 //---------------------------------------------------------------------------
307 {
308  return Scheduler::IsEnabled();
309 }
310 
311 //---------------------------------------------------------------------------
313 {
314  return static_cast<Thread_t>(Scheduler::GetCurrentThread());
315 }
316 
317 //---------------------------------------------------------------------------
318 // Thread APIs
319 //---------------------------------------------------------------------------
320 
321 void Thread_Init(Thread_t handle,
322  K_WORD* pwStack_,
323  uint16_t u16StackSize_,
324  PORT_PRIO_TYPE uXPriority_,
325  ThreadEntryFunc pfEntryPoint_,
326  void* pvArg_)
327 {
328  auto* pclThread = new ((void*)handle) Thread();
329  pclThread->Init(pwStack_, u16StackSize_, uXPriority_, pfEntryPoint_, pvArg_);
330 }
331 
332 //---------------------------------------------------------------------------
333 void Thread_Start(Thread_t handle)
334 {
335  auto* pclThread = static_cast<Thread*>(handle);
336  pclThread->Start();
337 }
338 
339 //---------------------------------------------------------------------------
340 void Thread_Stop(Thread_t handle)
341 {
342  auto* pclThread = static_cast<Thread*>(handle);
343  pclThread->Stop();
344 }
345 //---------------------------------------------------------------------------
346 void Thread_SetName(Thread_t handle, const char* szName_)
347 {
348  auto* pclThread = static_cast<Thread*>(handle);
349  pclThread->SetName(szName_);
350 }
351 //---------------------------------------------------------------------------
352 const char* Thread_GetName(Thread_t handle)
353 {
354  auto* pclThread = static_cast<Thread*>(handle);
355  return pclThread->GetName();
356 }
357 
358 //---------------------------------------------------------------------------
360 {
361  auto* pclThread = static_cast<Thread*>(handle);
362  return pclThread->GetPriority();
363 }
364 //---------------------------------------------------------------------------
366 {
367  auto* pclThread = static_cast<Thread*>(handle);
368  return pclThread->GetCurPriority();
369 }
370 
371 //---------------------------------------------------------------------------
372 void Thread_SetQuantum(Thread_t handle, uint16_t u16Quantum_)
373 {
374  auto* pclThread = static_cast<Thread*>(handle);
375  pclThread->SetQuantum(u16Quantum_);
376 }
377 //---------------------------------------------------------------------------
378 uint16_t Thread_GetQuantum(Thread_t handle)
379 {
380  auto* pclThread = static_cast<Thread*>(handle);
381  return pclThread->GetQuantum();
382 }
383 
384 //---------------------------------------------------------------------------
385 void Thread_SetPriority(Thread_t handle, PORT_PRIO_TYPE uXPriority_)
386 {
387  auto* pclThread = static_cast<Thread*>(handle);
388  pclThread->SetPriority(uXPriority_);
389 }
390 
391 //---------------------------------------------------------------------------
392 void Thread_Exit(Thread_t handle)
393 {
394  auto* pclThread = static_cast<Thread*>(handle);
395  pclThread->Exit();
396 }
397 
398 //---------------------------------------------------------------------------
399 void Thread_Sleep(uint32_t u32TimeMs_)
400 {
401  Thread::Sleep(u32TimeMs_);
402 }
403 
404 #if KERNEL_EXTENDED_CONTEXT
405 //---------------------------------------------------------------------------
406 void* Thread_GetExtendedContext(Thread_t handle)
407 {
408  auto* pclThread = static_cast<Thread*>(handle);
409  return pclThread->GetExtendedContext();
410 }
411 
412 //---------------------------------------------------------------------------
413 void Thread_SetExtendedContext(Thread_t handle, void* pvData_)
414 {
415  auto* pclThread = static_cast<Thread*>(handle);
416  pclThread->SetExtendedContext(pvData_);
417 }
418 #endif // #if KERNEL_EXTENDED_CONTEXT
419 
420 //---------------------------------------------------------------------------
421 void Thread_Yield(void)
422 {
423  Thread::Yield();
424 }
425 //---------------------------------------------------------------------------
427 {
429 }
430 //---------------------------------------------------------------------------
431 void Thread_SetID(Thread_t handle, uint8_t u8ID_)
432 {
433  auto* pclThread = static_cast<Thread*>(handle);
434  pclThread->SetID(u8ID_);
435 }
436 //---------------------------------------------------------------------------
437 uint8_t Thread_GetID(Thread_t handle)
438 {
439  auto* pclThread = static_cast<Thread*>(handle);
440  return pclThread->GetID();
441 }
442 //---------------------------------------------------------------------------
444 {
445  auto* pclThread = static_cast<Thread*>(handle);
446  return pclThread->GetStackSlack();
447 }
448 //---------------------------------------------------------------------------
450 {
451  auto* pclThread = static_cast<Thread*>(handle);
452  return static_cast<thread_state_t>(pclThread->GetState());
453 }
454 //---------------------------------------------------------------------------
455 // Timer APIs
456 //---------------------------------------------------------------------------
457 
458 //---------------------------------------------------------------------------
459 void Timer_Init(Timer_t handle)
460 {
461  auto* pclTimer = new ((void*)handle) Timer();
462  pclTimer->Init();
463 }
464 
465 //---------------------------------------------------------------------------
466 void Timer_Start(Timer_t handle, bool bRepeat_, uint32_t u32IntervalMs_, timer_callback_t pfCallback_, void* pvData_)
467 {
468  auto* pclTimer = static_cast<Timer*>(handle);
469  pclTimer->Start(bRepeat_, u32IntervalMs_, reinterpret_cast<TimerCallback>(pfCallback_), pvData_);
470 }
471 
472 //---------------------------------------------------------------------------
473 void Timer_Stop(Timer_t handle)
474 {
475  auto* pclTimer = static_cast<Timer*>(handle);
476  pclTimer->Stop();
477 }
478 
479 //---------------------------------------------------------------------------
480 void Timer_Restart(Timer_t handle)
481 {
482  auto* pclTimer = static_cast<Timer*>(handle);
483  pclTimer->Start();
484 }
485 
486 //---------------------------------------------------------------------------
487 // Semaphore APIs
488 //---------------------------------------------------------------------------
489 void Semaphore_Init(Semaphore_t handle, uint16_t u16InitVal_, uint16_t u16MaxVal_)
490 {
491  auto* pclSemaphore = new ((void*)handle) Semaphore();
492  pclSemaphore->Init(u16InitVal_, u16MaxVal_);
493 }
494 
495 //---------------------------------------------------------------------------
497 {
498  auto* pclSemaphore = static_cast<Semaphore*>(handle);
499  pclSemaphore->Post();
500 }
501 
502 //---------------------------------------------------------------------------
504 {
505  auto* pclSemaphore = static_cast<Semaphore*>(handle);
506  pclSemaphore->Pend();
507 }
508 
509 //---------------------------------------------------------------------------
510 bool Semaphore_TimedPend(Semaphore_t handle, uint32_t u32WaitTimeMS_)
511 {
512  auto* pclSemaphore = static_cast<Semaphore*>(handle);
513  return pclSemaphore->Pend(u32WaitTimeMS_);
514 }
515 
516 //---------------------------------------------------------------------------
517 // Mutex APIs
518 //---------------------------------------------------------------------------
519 void Mutex_Init(Mutex_t handle)
520 {
521  auto* pclMutex = new ((void*)handle) Mutex();
522  pclMutex->Init();
523 }
524 
525 //---------------------------------------------------------------------------
526 void Mutex_Claim(Mutex_t handle)
527 {
528  auto* pclMutex = static_cast<Mutex*>(handle);
529  pclMutex->Claim();
530 }
531 
532 //---------------------------------------------------------------------------
533 void Mutex_Release(Mutex_t handle)
534 {
535  auto* pclMutex = static_cast<Mutex*>(handle);
536  pclMutex->Release();
537 }
538 
539 //---------------------------------------------------------------------------
540 bool Mutex_TimedClaim(Mutex_t handle, uint32_t u32WaitTimeMS_)
541 {
542  auto* pclMutex = static_cast<Mutex*>(handle);
543  return pclMutex->Claim(u32WaitTimeMS_);
544 }
545 
546 #if KERNEL_EVENT_FLAGS
547 //---------------------------------------------------------------------------
548 // EventFlag APIs
549 //---------------------------------------------------------------------------
550 void EventFlag_Init(EventFlag_t handle)
551 {
552  auto* pclFlag = new ((void*)handle) EventFlag();
553  pclFlag->Init();
554 }
555 
556 //---------------------------------------------------------------------------
557 uint16_t EventFlag_Wait(EventFlag_t handle, uint16_t u16Mask_, event_flag_operation_t eMode_)
558 {
559  auto* pclFlag = static_cast<EventFlag*>(handle);
560  return pclFlag->Wait(u16Mask_, static_cast<EventFlagOperation>(eMode_));
561 }
562 
563 //---------------------------------------------------------------------------
564 uint16_t EventFlag_TimedWait(EventFlag_t handle, uint16_t u16Mask_, event_flag_operation_t eMode_, uint32_t u32TimeMS_)
565 {
566  auto* pclFlag = static_cast<EventFlag*>(handle);
567  return pclFlag->Wait(u16Mask_, static_cast<EventFlagOperation>(eMode_), u32TimeMS_);
568 }
569 
570 //---------------------------------------------------------------------------
571 void EventFlag_Set(EventFlag_t handle, uint16_t u16Mask_)
572 {
573  auto* pclFlag = static_cast<EventFlag*>(handle);
574  pclFlag->Set(u16Mask_);
575 }
576 
577 //---------------------------------------------------------------------------
578 void EventFlag_Clear(EventFlag_t handle, uint16_t u16Mask_)
579 {
580  auto* pclFlag = static_cast<EventFlag*>(handle);
581  pclFlag->Clear(u16Mask_);
582 }
583 
584 //---------------------------------------------------------------------------
585 uint16_t EventFlag_GetMask(EventFlag_t handle)
586 {
587  auto* pclFlag = static_cast<EventFlag*>(handle);
588  return pclFlag->GetMask();
589 }
590 #endif // #if #if KERNEL_EVENT_FLAGS
591 
592 //---------------------------------------------------------------------------
593 // Notification APIs
594 //---------------------------------------------------------------------------
595 void Notify_Init(Notify_t handle)
596 {
597  auto* pclNotify = new ((void*)handle) Notify();
598  pclNotify->Init();
599 }
600 
601 //---------------------------------------------------------------------------
603 {
604  auto* pclNotify = static_cast<Notify*>(handle);
605  pclNotify->Signal();
606 }
607 
608 //---------------------------------------------------------------------------
609 void Notify_Wait(Notify_t handle, bool* pbFlag_)
610 {
611  auto* pclNotify = static_cast<Notify*>(handle);
612  pclNotify->Wait(pbFlag_);
613 }
614 
615 //---------------------------------------------------------------------------
616 bool Notify_TimedWait(Notify_t handle, uint32_t u32WaitTimeMS_, bool* pbFlag_)
617 {
618  auto* pclNotify = static_cast<Notify*>(handle);
619  return pclNotify->Wait(u32WaitTimeMS_, pbFlag_);
620 }
621 
622 //---------------------------------------------------------------------------
623 // Atomic Functions
624 //---------------------------------------------------------------------------
625 uint8_t Atomic_Set8(uint8_t* pu8Source_, uint8_t u8Val_)
626 {
627  return Atomic::Set(pu8Source_, u8Val_);
628 }
629 
630 //---------------------------------------------------------------------------
631 uint16_t Atomic_Set16(uint16_t* pu16Source_, uint16_t u16Val_)
632 {
633  return Atomic::Set(pu16Source_, u16Val_);
634 }
635 
636 //---------------------------------------------------------------------------
637 uint32_t Atomic_Set32(uint32_t* pu32Source_, uint32_t u32Val_)
638 {
639  return Atomic::Set(pu32Source_, u32Val_);
640 }
641 
642 //---------------------------------------------------------------------------
643 uint8_t Atomic_Add8(uint8_t* pu8Source_, uint8_t u8Val_)
644 {
645  return Atomic::Add(pu8Source_, u8Val_);
646 }
647 
648 //---------------------------------------------------------------------------
649 uint16_t Atomic_Add16(uint16_t* pu16Source_, uint16_t u16Val_)
650 {
651  return Atomic::Add(pu16Source_, u16Val_);
652 }
653 
654 //---------------------------------------------------------------------------
655 uint32_t Atomic_Add32(uint32_t* pu32Source_, uint32_t u32Val_)
656 {
657  return Atomic::Add(pu32Source_, u32Val_);
658 }
659 
660 //---------------------------------------------------------------------------
661 uint8_t Atomic_Sub8(uint8_t* pu8Source_, uint8_t u8Val_)
662 {
663  return Atomic::Sub(pu8Source_, u8Val_);
664 }
665 
666 //---------------------------------------------------------------------------
667 uint16_t Atomic_Sub16(uint16_t* pu16Source_, uint16_t u16Val_)
668 {
669  return Atomic::Sub(pu16Source_, u16Val_);
670 }
671 
672 //---------------------------------------------------------------------------
673 uint32_t Atomic_Sub32(uint32_t* pu32Source_, uint32_t u32Val_)
674 {
675  return Atomic::Sub(pu32Source_, u32Val_);
676 }
677 
678 //---------------------------------------------------------------------------
679 bool Atomic_TestAndSet(bool* pbLock)
680 {
681  return Atomic::TestAndSet(pbLock);
682 }
683 
684 //---------------------------------------------------------------------------
685 // Message/Message Queue APIs
686 //---------------------------------------------------------------------------
688 {
689  auto* pclMessage = new ((void*)handle) Message();
690  return pclMessage->Init();
691 }
692 
693 //---------------------------------------------------------------------------
694 void Message_SetData(Message_t handle, void* pvData_)
695 {
696  auto* pclMessage = static_cast<Message*>(handle);
697  pclMessage->SetData(pvData_);
698 }
699 
700 //---------------------------------------------------------------------------
702 {
703  auto* pclMessage = static_cast<Message*>(handle);
704  return pclMessage->GetData();
705 }
706 
707 //---------------------------------------------------------------------------
708 void Message_SetCode(Message_t handle, uint16_t u16Code_)
709 {
710  auto* pclMessage = static_cast<Message*>(handle);
711  pclMessage->SetCode(u16Code_);
712 }
713 
714 //---------------------------------------------------------------------------
715 uint16_t Message_GetCode(Message_t handle)
716 {
717  auto* pclMessage = static_cast<Message*>(handle);
718  return pclMessage->GetCode();
719 }
720 
721 //---------------------------------------------------------------------------
723 {
724  auto* pclMsgQ = new ((void*)handle) MessageQueue();
725  pclMsgQ->Init();
726 }
727 
728 //---------------------------------------------------------------------------
730 {
731  auto* pclMsgQ = static_cast<MessageQueue*>(handle);
732  return pclMsgQ->Receive();
733 }
734 
735 //---------------------------------------------------------------------------
737 {
738  auto* pclMsgPool = new ((void*)handle) MessagePool();
739  pclMsgPool->Init();
740 }
741 
742 //---------------------------------------------------------------------------
744 {
745  auto* pclMsgPool = static_cast<MessagePool*>(handle);
746  pclMsgPool->Push(reinterpret_cast<Message*>(msg));
747 }
748 
749 //---------------------------------------------------------------------------
751 {
752  auto* pclMsgPool = static_cast<MessagePool*>(handle);
753  return reinterpret_cast<Message_t>(pclMsgPool->Pop());
754 }
755 
756 //---------------------------------------------------------------------------
757 Message_t MessageQueue_TimedReceive(MessageQueue_t handle, uint32_t u32TimeWaitMS_)
758 {
759  auto* pclMsgQ = static_cast<MessageQueue*>(handle);
760  return reinterpret_cast<Message_t>(pclMsgQ->Receive(u32TimeWaitMS_));
761 }
762 
763 //---------------------------------------------------------------------------
765 {
766  auto* pclMsgQ = static_cast<MessageQueue*>(handle);
767  pclMsgQ->Send(reinterpret_cast<Message*>(hMessage_));
768 }
769 
770 //---------------------------------------------------------------------------
772 {
773  auto* pclMsgQ = static_cast<MessageQueue*>(handle);
774  return pclMsgQ->GetCount();
775 }
776 
777 //---------------------------------------------------------------------------
778 // Mailbox APIs
779 //---------------------------------------------------------------------------
780 void Mailbox_Init(Mailbox_t handle, void* pvBuffer_, uint16_t u16BufferSize_, uint16_t u16ElementSize_)
781 {
782  auto* pclMBox = new ((void*)handle) Mailbox();
783  pclMBox->Init(pvBuffer_, u16BufferSize_, u16ElementSize_);
784 }
785 
786 //---------------------------------------------------------------------------
787 bool Mailbox_Send(Mailbox_t handle, void* pvData_)
788 {
789  auto* pclMBox = static_cast<Mailbox*>(handle);
790  return pclMBox->Send(pvData_);
791 }
792 
793 //---------------------------------------------------------------------------
794 bool Mailbox_SendTail(Mailbox_t handle, void* pvData_)
795 {
796  auto* pclMBox = static_cast<Mailbox*>(handle);
797  return pclMBox->SendTail(pvData_);
798 }
799 
800 //---------------------------------------------------------------------------
801 bool Mailbox_TimedSend(Mailbox_t handle, void* pvData_, uint32_t u32TimeoutMS_)
802 {
803  Mailbox* pclMBox = (Mailbox*)handle;
804  return pclMBox->Send(pvData_, u32TimeoutMS_);
805 }
806 
807 //---------------------------------------------------------------------------
808 bool Mailbox_TimedSendTail(Mailbox_t handle, void* pvData_, uint32_t u32TimeoutMS_)
809 {
810  auto* pclMBox = static_cast<Mailbox*>(handle);
811  return pclMBox->SendTail(pvData_, u32TimeoutMS_);
812 }
813 
814 //---------------------------------------------------------------------------
815 void Mailbox_Receive(Mailbox_t handle, void* pvData_)
816 {
817  auto* pclMBox = static_cast<Mailbox*>(handle);
818  pclMBox->Receive(pvData_);
819 }
820 
821 //---------------------------------------------------------------------------
822 void Mailbox_ReceiveTail(Mailbox_t handle, void* pvData_)
823 {
824  auto* pclMBox = static_cast<Mailbox*>(handle);
825  pclMBox->ReceiveTail(pvData_);
826 }
827 
828 //---------------------------------------------------------------------------
829 bool Mailbox_TimedReceive(Mailbox_t handle, void* pvData_, uint32_t u32TimeoutMS_)
830 {
831  auto* pclMBox = static_cast<Mailbox*>(handle);
832  return pclMBox->Receive(pvData_, u32TimeoutMS_);
833 }
834 
835 //---------------------------------------------------------------------------
836 bool Mailbox_TimedReceiveTail(Mailbox_t handle, void* pvData_, uint32_t u32TimeoutMS_)
837 {
838  auto* pclMBox = static_cast<Mailbox*>(handle);
839  return pclMBox->ReceiveTail(pvData_, u32TimeoutMS_);
840 }
841 
842 //---------------------------------------------------------------------------
844 {
845  auto* pclMBox = static_cast<Mailbox*>(handle);
846  return pclMBox->GetFreeSlots();
847 }
848 
849 //---------------------------------------------------------------------------
851 {
852  auto* pclMBox = static_cast<Mailbox*>(handle);
853  return pclMBox->IsFull();
854 }
855 
856 //---------------------------------------------------------------------------
858 {
859  auto* pclMBox = static_cast<Mailbox*>(handle);
860  return pclMBox->IsEmpty();
861 }
862 
863 //---------------------------------------------------------------------------
864 // Condition Variables
865 //---------------------------------------------------------------------------
867 {
868  auto* pclCondvar = new ((void*)handle) ConditionVariable();
869  pclCondvar->Init();
870 }
871 //---------------------------------------------------------------------------
873 {
874  auto* pclCondvar = static_cast<ConditionVariable*>(handle);
875  auto* pclMutex = static_cast<Mutex*>(hMutex_);
876  pclCondvar->Wait(pclMutex);
877 }
878 //---------------------------------------------------------------------------
880 {
881  auto* pclCondvar = static_cast<ConditionVariable*>(handle);
882  pclCondvar->Signal();
883 }
884 //---------------------------------------------------------------------------
886 {
887  auto* pclCondvar = static_cast<ConditionVariable*>(handle);
888  pclCondvar->Broadcast();
889 }
890 //---------------------------------------------------------------------------
891 bool ConditionVariable_TimedWait(ConditionVariable_t handle, Mutex_t hMutex_, uint32_t u32WaitTimeMS_)
892 {
893  auto* pclCondvar = static_cast<ConditionVariable*>(handle);
894  auto* pclMutex = static_cast<Mutex*>(hMutex_);
895  return pclCondvar->Wait(pclMutex, u32WaitTimeMS_);
896 }
897 
898 //---------------------------------------------------------------------------
899 // Reader-writer locks
900 //---------------------------------------------------------------------------
902 {
903  auto* pclReaderWriter = new ((void*)handle) ReaderWriterLock();
904  pclReaderWriter->Init();
905 }
906 
907 //---------------------------------------------------------------------------
909 {
910  auto* pclReaderWriter = static_cast<ReaderWriterLock*>(handle);
911  pclReaderWriter->AcquireReader();
912 }
913 
914 //---------------------------------------------------------------------------
916 {
917  auto* pclReaderWriter = static_cast<ReaderWriterLock*>(handle);
918  pclReaderWriter->ReleaseReader();
919 }
920 
921 //---------------------------------------------------------------------------
923 {
924  auto* pclReaderWriter = static_cast<ReaderWriterLock*>(handle);
925  pclReaderWriter->AcquireWriter();
926 }
927 
928 //---------------------------------------------------------------------------
930 {
931  auto* pclReaderWriter = static_cast<ReaderWriterLock*>(handle);
932  pclReaderWriter->ReleaseWriter();
933 }
934 
935 //---------------------------------------------------------------------------
936 bool ReaderWriterLock_TimedAcquireWriter(ReaderWriterLock_t handle, uint32_t u32TimeoutMs_)
937 {
938  auto* pclReaderWriter = static_cast<ReaderWriterLock*>(handle);
939  return pclReaderWriter->AcquireWriter(u32TimeoutMs_);
940 }
941 
942 //---------------------------------------------------------------------------
943 bool ReaderWriterLock_TimedAcquireReader(ReaderWriterLock_t handle, uint32_t u32TimeoutMs_)
944 {
945  auto* pclReaderWriter = static_cast<ReaderWriterLock*>(handle);
946  return pclReaderWriter->AcquireReader(u32TimeoutMs_);
947 }
948 
949 //---------------------------------------------------------------------------
950 void Coroutine_Init(Coroutine_t handle, PORT_PRIO_TYPE uPriority_, coroutine_callback_t pfHandler_, void* pvContext_)
951 {
952  auto* pclCoroutine = static_cast<Coroutine*>(handle);
953  return pclCoroutine->Init(uPriority_, reinterpret_cast<CoroutineHandler>(pfHandler_), pvContext_);
954 }
955 
956 //---------------------------------------------------------------------------
958 {
959  auto* pclCoroutine = static_cast<Coroutine*>(handle);
960  pclCoroutine->Run();
961 }
962 
963 //---------------------------------------------------------------------------
965 {
966  auto* pclCoroutine = static_cast<Coroutine*>(handle);
967  pclCoroutine->Activate();
968 }
969 
970 //---------------------------------------------------------------------------
972 {
973  auto* pclCoroutine = static_cast<Coroutine*>(handle);
974  pclCoroutine->SetPriority(uPriority_);
975 }
976 
977 //---------------------------------------------------------------------------
979 {
980  auto* pclCoroutine = static_cast<Coroutine*>(handle);
981  return pclCoroutine->GetPriority();
982 }
void * Alloc_Memory(uint16_t u16Size_)
Definition: mark3c.cpp:29
void SetQuantum(uint16_t u16Quantum_)
SetQuantum Set the thread&#39;s round-robin execution quantum.
Definition: thread.h:190
void * GetExtendedContext()
GetExtendedContext Return the Thread object&#39;s extended-context data pointer. Used by code implementin...
Definition: thread.h:368
The MessagePool Class The MessagePool class implements a simple allocator for message objects exchang...
Definition: message.h:157
void Thread_Yield(void)
Thread_Yield.
Definition: mark3c.cpp:421
The ReaderWriterLock class. This class implements an object that marshalls access to a resource based...
Definition: readerwriter.h:40
void Free_Notify(Notify_t handle)
Definition: mark3c.cpp:118
Message * Receive()
Receive.
Definition: message.cpp:64
bool Mailbox_TimedReceiveTail(Mailbox_t handle, void *pvData_, uint32_t u32TimeoutMS_)
Mailbox_TimedReceiveTail.
Definition: mark3c.cpp:836
MessageQueue_t Alloc_MessageQueue(void)
Alloc_MessageQueue.
Definition: mark3c.cpp:88
#define K_WORD
Size of a data word.
Definition: portcfg.h:62
bool IsEmpty(void)
Definition: mailbox.h:177
void Kernel_SetStackGuardThreshold(uint16_t u16Threshold_)
Definition: mark3c.cpp:275
uint8_t Atomic_Sub8(uint8_t *pu8Source_, uint8_t u8Val_)
Atomic_Sub8.
Definition: mark3c.cpp:661
bool Mailbox_Send(Mailbox_t handle, void *pvData_)
Mailbox_Send.
Definition: mark3c.cpp:787
static bool IsEnabled()
IsEnabled Return the current state of the scheduler - whether or not scheudling is enabled or disable...
Definition: scheduler.h:150
Timer_t Alloc_Timer(void)
Alloc_Timer.
Definition: mark3c.cpp:167
bool Semaphore_TimedPend(Semaphore_t handle, uint32_t u32WaitTimeMS_)
Semaphore_TimedPend.
Definition: mark3c.cpp:510
uint16_t GetCode()
GetCode Return the code set in the message upon receipt.
Definition: message.h:139
void Exit()
Exit. Remove the thread from being scheduled again. The thread is effectively destroyed when this occ...
Definition: thread.cpp:187
void ReaderWriterLock_AcquireReader(ReaderWriterLock_t handle)
ReaderWriterLock_AcquireReader.
Definition: mark3c.cpp:908
ReaderWriterLock_t Alloc_ReaderWriterLock(void)
Definition: mark3c.cpp:145
uint32_t Atomic_Sub32(uint32_t *pu32Source_, uint32_t u32Val_)
Atomic_Sub32.
Definition: mark3c.cpp:673
void * Message_t
Message opaque handle data type.
Definition: mark3c.h:40
void Thread_Stop(Thread_t handle)
Thread_Stop.
Definition: mark3c.cpp:340
MessagePool_t Alloc_MessagePool(void)
Definition: mark3c.cpp:100
static void SetThreadContextSwitchCallout(ThreadContextCallout pfContext_)
SetThreadContextSwitchCallout Set a function to be called on each context switch. ...
Definition: kernel.h:143
void Kernel_Init(void)
Kernel_Init.
Definition: mark3c.cpp:191
void * Mutex_t
Mutex opaque handle data type.
Definition: mark3c.h:43
void ReaderWriterLock_ReleaseWriter(ReaderWriterLock_t handle)
ReaderWriterLock_ReleaseWriter.
Definition: mark3c.cpp:929
void Free_Message(Message_t handle)
Definition: mark3c.cpp:82
void ConditionVariable_Init(ConditionVariable_t handle)
ConditionVariable_Init.
Definition: mark3c.cpp:866
void MessageQueue_Init(MessageQueue_t handle)
MessageQueue_Init.
Definition: mark3c.cpp:722
const char * GetName()
GetName.
Definition: thread.h:149
T Set(T *pSource_, T val_)
Set Set a variable to a given value in an uninterruptable operation.
Definition: atomic.h:47
void * Semaphore_t
Semaphore opaque handle data type.
Definition: mark3c.h:45
EventFlag_t Alloc_EventFlag(void)
Definition: mark3c.cpp:64
PORT_PRIO_TYPE Coroutine_GetPriority(Coroutine_t handle)
Definition: mark3c.cpp:978
PORT_PRIO_TYPE Thread_GetPriority(Thread_t handle)
Thread_GetPriority.
Definition: mark3c.cpp:359
uint16_t GetFreeSlots(void)
Definition: mailbox.h:170
void Free_Memory(void *pvObject_)
Free_Memory.
Definition: mark3c.cpp:34
void Scheduler_Enable(bool bEnable_)
Scheduler_Enable.
Definition: mark3c.cpp:300
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.
Definition: thread.cpp:324
void Free_Mutex(Mutex_t handle)
Definition: mark3c.cpp:58
static void DestroyRawData(void *pvData_)
DestroyRawData Free a previously allocated blob of data allocated via NewRawData() ...
Definition: autoalloc.cpp:105
void Release()
Release Release the mutex. When the mutex is released, another object can enter the mutex-protected r...
Definition: mutex.cpp:197
void Thread_SetID(Thread_t handle, uint8_t u8ID_)
Thread_SetID.
Definition: mark3c.cpp:431
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...
Definition: timer.cpp:51
uint16_t GetMask()
GetMask Returns the state of the 16-bit bitmask within this object.
bool Mailbox_IsEmpty(Mailbox_t handle)
Mailbox_IsEmpty.
Definition: mark3c.cpp:857
void Thread_Init(Thread_t handle, K_WORD *pwStack_, uint16_t u16StackSize_, PORT_PRIO_TYPE uXPriority_, ThreadEntryFunc pfEntryPoint_, void *pvArg_)
Thread_Init.
Definition: mark3c.cpp:321
bool Kernel_IsPanic(void)
Kernel_IsPanic.
Definition: mark3c.cpp:215
bool Scheduler_IsEnabled(void)
Scheduler_IsEnabled.
Definition: mark3c.cpp:306
void Send(Message *pclSrc_)
Send.
Definition: message.cpp:92
#define PORT_PRIO_TYPE
Type used for bitmap in the PriorityMap class.
Definition: portcfg.h:73
void Thread_Start(Thread_t handle)
Thread_Start.
Definition: mark3c.cpp:333
the Semaphore class provides Binary & Counting semaphore objects, based on BlockingObject base class...
Definition: ksemaphore.h:36
uint16_t Kernel_GetStackGuardThreshold(void)
Definition: mark3c.cpp:281
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...
Definition: mutex.cpp:185
void * Message_GetData(Message_t handle)
Message_GetData.
Definition: mark3c.cpp:701
void Coroutine_SetPriority(Coroutine_t handle, PORT_PRIO_TYPE uPriority_)
Definition: mark3c.cpp:971
Message_t MessageQueue_Receive(MessageQueue_t handle)
MessageQueue_Receive.
Definition: mark3c.cpp:729
void * Mailbox_t
Mailbox opaque handle data type.
Definition: mark3c.h:39
uint16_t MessageQueue_GetCount(MessageQueue_t handle)
MessageQueue_GetCount.
Definition: mark3c.cpp:771
void Activate()
Activate Tag the co-routine as pending execution. Has no effect if the co-routine is already pending ...
Definition: coroutine.cpp:67
void Free_ReaderWriterLock(ReaderWriterLock_t handle)
Definition: mark3c.cpp:150
uint16_t Thread_GetStackSlack(Thread_t handle)
Definition: mark3c.cpp:443
bool Notify_TimedWait(Notify_t handle, uint32_t u32WaitTimeMS_, bool *pbFlag_)
Notify_TimedWait.
Definition: mark3c.cpp:616
bool Kernel_IsStarted(void)
Kernel_IsStarted.
Definition: mark3c.cpp:203
void Kernel_Start(void)
Kernel_Start.
Definition: mark3c.cpp:197
void Mailbox_Init(Mailbox_t handle, void *pvBuffer_, uint16_t u16BufferSize_, uint16_t u16ElementSize_)
Mailbox_Init.
Definition: mark3c.cpp:780
void ReleaseWriter()
ReleaseWriter Release the currently held writer, allowing other readers/writers to access the object...
ConditionVariable_t Alloc_ConditionVariable(void)
Definition: mark3c.cpp:134
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
void Mutex_Init(Mutex_t handle)
Mutex_Init.
Definition: mark3c.cpp:519
void * Notify_t
Notification object opaque handle data type.
Definition: mark3c.h:44
uint32_t Atomic_Set32(uint32_t *pu32Source_, uint32_t u32Val_)
Atomic_Set32.
Definition: mark3c.cpp:637
void Receive(void *pvData_)
Receive Read one envelope from the head of the mailbox. If the mailbox is currently empty...
Definition: mailbox.cpp:83
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.
Definition: mark3c.cpp:489
static bool IsPanic()
IsPanic Returns whether or not the kernel is in a panic state.
Definition: kernel.h:99
Header providing C-language API bindings for the Mark3 kernel.
void Push(Message *pclMessage_)
Push.
Definition: message.cpp:32
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();.
Definition: kernel.h:178
thread_state_t Thread_GetState(Thread_t handle)
Thread_GetState.
Definition: mark3c.cpp:449
Definition: atomic.cpp:23
void SetCode(uint16_t u16Code_)
SetCode Set the code in the message before transmission.
Definition: message.h:132
void Notify_Signal(Notify_t handle)
Notify_Signal.
Definition: mark3c.cpp:602
void Stop()
Stop Stop a timer already in progress. Has no effect on timers that have already been stopped...
Definition: timer.cpp:86
void Free_ConditionVariable(ConditionVariable_t handle)
Definition: mark3c.cpp:139
bool SendTail(void *pvData_)
SendTail Send an envelope to the mailbox. This safely copies the data contents of the datastructure t...
Definition: mailbox.cpp:118
void * Thread_t
Thread opaque handle data type.
Definition: mark3c.h:46
void MessageQueue_Send(MessageQueue_t handle, Message_t hMessage_)
MessageQueue_Send.
Definition: mark3c.cpp:764
void ReaderWriterLock_ReleaseReader(ReaderWriterLock_t handle)
ReaderWriterLock_ReleaseReader.
Definition: mark3c.cpp:915
The Mutex Class. Class providing Mutual-exclusion locks, based on BlockingObject. ...
Definition: mutex.h:63
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
void Mutex_Release(Mutex_t handle)
Mutex_Release.
Definition: mark3c.cpp:533
PORT_PRIO_TYPE GetCurPriority(void)
GetCurPriority Return the priority of the current thread.
Definition: thread.h:181
void Mailbox_ReceiveTail(Mailbox_t handle, void *pvData_)
Mailbox_ReceiveTail.
Definition: mark3c.cpp:822
void(* coroutine_callback_t)(Coroutine_t caller, void *pvContext)
Definition: mark3c.h:64
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.
Definition: message.h:210
void Free_MessageQueue(MessageQueue_t handle)
Definition: mark3c.cpp:94
void Mutex_Claim(Mutex_t handle)
Mutex_Claim.
Definition: mark3c.cpp:526
bool Mailbox_SendTail(Mailbox_t handle, void *pvData_)
Mailbox_SendTail.
Definition: mark3c.cpp:794
Mailbox_t Alloc_Mailbox(void)
Alloc_Mailbox.
Definition: mark3c.cpp:123
void Coroutine_Init(Coroutine_t handle, PORT_PRIO_TYPE uPriority_, coroutine_callback_t pfHandler_, void *pvContext_)
Definition: mark3c.cpp:950
void Free_MessagePool(MessagePool_t handle)
Definition: mark3c.cpp:106
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 ...
Definition: thread.h:64
bool ReaderWriterLock_TimedAcquireWriter(ReaderWriterLock_t handle, uint32_t u32TimeoutMs_)
ReaderWriterLock_TimedAcquireWriter.
Definition: mark3c.cpp:936
void Thread_CoopYield(void)
Thread_CoopYield.
Definition: mark3c.cpp:426
bool Mutex_TimedClaim(Mutex_t handle, uint32_t u32WaitTimeMS_)
Mutex_TimedClaim.
Definition: mark3c.cpp:540
void * ConditionVariable_t
Condition Variable opaque handle data type.
Definition: mark3c.h:48
void Notify_Init(Notify_t handle)
Notify_Init.
Definition: mark3c.cpp:595
PORT_PRIO_TYPE Thread_GetCurPriority(Thread_t handle)
Thread_GetCurPriority.
Definition: mark3c.cpp:365
void MessagePool_Push(MessagePool_t handle, Message_t msg)
MessagePool_Push.
Definition: mark3c.cpp:743
Notify_t Alloc_Notify(void)
Alloc_Notify.
Definition: mark3c.cpp:112
void * Coroutine_t
Coroutine opaaque handle data type.
Definition: mark3c.h:50
static ThreadContextCallout GetThreadContextSwitchCallout()
GetThreadContextSwitchCallout Return the current function called on every Thread::ContextSwitchSWI() ...
Definition: kernel.h:198
The Notify class. This class provides a blocking object type that allows one or more threads to wait ...
Definition: notify.h:33
void Thread_SetName(Thread_t handle, const char *szName_)
Definition: mark3c.cpp:346
static uint32_t GetTicks()
Definition: kernel.cpp:90
void Start()
Start Start the thread - remove it from the stopped list, add it to the scheduler&#39;s list of threads (...
Definition: thread.cpp:110
Coroutine_t Alloc_Coroutine(void)
Definition: mark3c.cpp:178
void Message_SetData(Message_t handle, void *pvData_)
Message_SetData.
Definition: mark3c.cpp:694
void Free_Semaphore(Semaphore_t handle)
Definition: mark3c.cpp:46
void SetPriority(PORT_PRIO_TYPE uPriority_)
SetPriority Update the scheduling priority of the co-routine. Can be called from within the co-routin...
Definition: coroutine.cpp:82
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.
Definition: mark3c.cpp:715
bool Atomic_TestAndSet(bool *pbLock)
Atomic_TestAndSet.
Definition: mark3c.cpp:679
uint8_t Atomic_Set8(uint8_t *pu8Source_, uint8_t u8Val_)
Atomic_Set8.
Definition: mark3c.cpp:625
static void Yield(void)
Yield Yield the thread - this forces the system to call the scheduler and determine what thread shoul...
Definition: thread.cpp:304
void Thread_SetQuantum(Thread_t handle, uint16_t u16Quantum_)
Definition: mark3c.cpp:372
void Timer_Restart(Timer_t handle)
Timer_Restart.
Definition: mark3c.cpp:480
void AcquireReader()
AcquireReader Acquire the object&#39;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.
Definition: coroutine.cpp:97
void Signal()
Signal Signal/Unblock the next thread currently blocked on this condition variable.
Definition: condvar.cpp:66
void Thread_Exit(Thread_t handle)
Thread_Exit.
Definition: mark3c.cpp:392
bool Mailbox_TimedReceive(Mailbox_t handle, void *pvData_, uint32_t u32TimeoutMS_)
Mailbox_TimedReceive.
Definition: mark3c.cpp:829
bool Mailbox_IsFull(Mailbox_t handle)
Mailbox_IsFull.
Definition: mark3c.cpp:850
void MessagePool_Init(MessagePool_t handle)
MessagePool_Init.
Definition: mark3c.cpp:736
void Signal(void)
Signal Signal the notification object. This will cause the highest priority thread currently blocking...
Definition: notify.cpp:66
void Timer_Start(Timer_t handle, bool bRepeat_, uint32_t u32IntervalMs_, timer_callback_t pfCallback_, void *pvData_)
Timer_Start.
Definition: mark3c.cpp:466
The Coroutine class implements a lightweight, run-to-completion task that forms the basis for co-oper...
Definition: coroutine.h:53
static void Start()
Start the operating system kernel - the current execution context is cancelled, all kernel services a...
Definition: kernel.cpp:58
void * GetData()
GetData Get the data pointer stored in the message upon receipt.
Definition: message.h:125
void Coroutine_Run(Coroutine_t handle)
Definition: mark3c.cpp:957
void Free_Coroutine(Coroutine_t handle)
Definition: mark3c.cpp:183
void SetName(const char *szName_)
SetName Set the name of the thread - this is purely optional, but can be useful when identifying issu...
Definition: thread.h:143
void Timer_Stop(Timer_t handle)
Timer_Stop.
Definition: mark3c.cpp:473
uint16_t GetQuantum(void)
GetQuantum Get the thread&#39;s round-robin execution quantum.
Definition: thread.h:197
void ConditionVariable_Broadcast(ConditionVariable_t handle)
ConditionVariable_Broadcast.
Definition: mark3c.cpp:885
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.
Definition: mark3c.cpp:643
uint16_t Thread_GetQuantum(Thread_t handle)
Definition: mark3c.cpp:378
Message_t MessageQueue_TimedReceive(MessageQueue_t handle, uint32_t u32TimeWaitMS_)
MessageQueue_TimedReceive.
Definition: mark3c.cpp:757
void SetID(uint8_t u8ID_)
SetID Set an arbitrary 8-bit ID to uniquely identify this thread.
Definition: thread.h:282
static void SetDebugPrintFunction(DebugPrintFunction pfPrintFunction_)
SetDebugPrintFunction Set the function to be used when printing kernel debug information.
Definition: kernel.h:155
void Stop()
Stop Stop a thread that&#39;s actively scheduled without destroying its stacks. Stopped threads can be re...
Definition: thread.cpp:141
the Message class. This object provides threadsafe message-based IPC services based on exchange of ob...
Definition: message.h:97
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
void Semaphore_Pend(Semaphore_t handle)
Semaphore_Pend.
Definition: mark3c.cpp:503
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...
Definition: atomic.cpp:26
void Notify_Wait(Notify_t handle, bool *pbFlag_)
Notify_Wait.
Definition: mark3c.cpp:609
uint16_t GetCount()
GetCount.
Definition: message.cpp:106
uint16_t Atomic_Set16(uint16_t *pu16Source_, uint16_t u16Val_)
Atomic_Set16.
Definition: mark3c.cpp:631
void Wait(bool *pbFlag_)
Wait Block the current thread, waiting for a signal on the object.
Definition: notify.cpp:95
bool ConditionVariable_TimedWait(ConditionVariable_t handle, Mutex_t hMutex_, uint32_t u32WaitTimeMS_)
ConditionVariable_TimedWait.
Definition: mark3c.cpp:891
Message_t MessagePool_Pop(MessagePool_t handle)
MessagePool_Pop.
Definition: mark3c.cpp:750
void Run()
Run Clear the co-routine&#39;s pending execution flag, and execute the coroutine&#39;s handler function...
Definition: coroutine.cpp:53
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
Thread_t Scheduler_GetCurrentThread(void)
Scheduler_GetCurrentThread.
Definition: mark3c.cpp:312
void Kernel_DebugPrint(const char *szString_)
KernelDebug_DebugPrint.
Definition: mark3c.cpp:293
void Pend()
Decrement the semaphore count. If the count is zero, the calling Thread will block until the semaphor...
Definition: ksemaphore.cpp:194
Mutex_t Alloc_Mutex(void)
Alloc_Mutex.
Definition: mark3c.cpp:52
bool IsFull(void)
Definition: mailbox.h:176
void(*)(void *pvArg_) ThreadEntryFunc
Definition: kerneltypes.h:43
void ConditionVariable_Wait(ConditionVariable_t handle, Mutex_t hMutex_)
ConditionVariable_Wait.
Definition: mark3c.cpp:872
The ConditionVariable class This class implements a condition variable. This is a synchronization obj...
Definition: condvar.h:39
uint32_t Atomic_Add32(uint32_t *pu32Source_, uint32_t u32Val_)
Atomic_Add32.
Definition: mark3c.cpp:655
static void Sleep(uint32_t u32TimeMs_)
Sleep Put the thread to sleep for the specified time (in milliseconds). Actual time slept may be long...
Definition: thread.cpp:249
void * ReaderWriterLock_t
Reader-writer-lock opaque handle data type.
Definition: mark3c.h:49
void Free_EventFlag(EventFlag_t handle)
Definition: mark3c.cpp:70
uint16_t Atomic_Sub16(uint16_t *pu16Source_, uint16_t u16Val_)
Atomic_Sub16.
Definition: mark3c.cpp:667
void(* panic_func_t)(uint16_t u16PanicCode_)
Definition: mark3c.h:288
The Mailbox class. This class implements an IPC mechnism based on sending/receiving envelopes contain...
Definition: mailbox.h:35
uint8_t GetID()
GetID Return the thread&#39;s integer ID. Note that this ID is not guaranteed to be unique when dynamic t...
Definition: thread.h:292
Thread_t Alloc_Thread(void)
Alloc_Thread.
Definition: mark3c.cpp:156
void Timer_Init(Timer_t handle)
Timer_Init.
Definition: mark3c.cpp:459
The Timer Class. This class provides kernel-managed timers, used to provide high-precision delays...
Definition: timer.h:68
static void * NewRawData(size_t sSize_)
NewRawData Attempt to allocate a blob of raw data from the heap.
Definition: autoalloc.cpp:100
void * MessagePool_t
MessagePool opaque handle data type.
Definition: mark3c.h:41
void Kernel_SetDebugPrintFunction(kernel_debug_print_t pfPrintFunction_)
Kernel_SetDebugPrintFunction.
Definition: mark3c.cpp:287
bool Post()
Increment the semaphore count. If the semaphore count is zero at the time this is called...
Definition: ksemaphore.cpp:108
void Free_Timer(Timer_t handle)
Definition: mark3c.cpp:172
void Message_SetCode(Message_t handle, uint16_t u16Code_)
Message_SetCode.
Definition: mark3c.cpp:708
uint8_t Thread_GetID(Thread_t handle)
Thread_GetID.
Definition: mark3c.cpp:437
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...
Definition: coroutine.cpp:39
bool ReaderWriterLock_TimedAcquireReader(ReaderWriterLock_t handle, uint32_t u32TimeoutMs_)
ReaderWriterLock_TimedAcquireReader.
Definition: mark3c.cpp:943
void Free_Thread(Thread_t handle)
Definition: mark3c.cpp:161
void(* timer_callback_t)(Thread_t hOwner_, void *pvData_)
Definition: mark3c.h:576
Message_t Alloc_Message(void)
Alloc_Message.
Definition: mark3c.cpp:76
static void SetStackGuardThreshold(uint16_t u16Threshold_)
Definition: kernel.h:201
void ReleaseReader()
ReleaseReader Release a previously-held reader lock.
void Thread_SetPriority(Thread_t handle, PORT_PRIO_TYPE uXPriority_)
Thread_SetPriority.
Definition: mark3c.cpp:385
void Thread_Sleep(uint32_t u32TimeMs_)
Thread_Sleep.
Definition: mark3c.cpp:399
static uint16_t GetStackGuardThreshold()
Definition: kernel.h:202
void Broadcast()
Broadcast Unblock all threads currently blocked on this condition variable.
Definition: condvar.cpp:77
void SetData(void *pvData_)
SetData Set the data pointer for the message before transmission.
Definition: message.h:118
void(* kernel_debug_print_t)(const char *szString_)
Definition: mark3c.h:63
void * MessageQueue_t
MessageQueue opaque handle data type.
Definition: mark3c.h:42
The EventFlag class. This class implements a blocking object, similar to a semaphore or mutex...
Definition: eventflag.h:45
static ThreadExitCallout GetThreadExitCallout()
GetThreadExitCallout Return the current function called on every Thread::Exit();. ...
Definition: kernel.h:188
void Free_Mailbox(Mailbox_t handle)
Definition: mark3c.cpp:128
void Kernel_Panic(uint16_t u16Cause_)
Kernel_Panic.
Definition: mark3c.cpp:221
bool Send(void *pvData_)
Send Send an envelope to the mailbox. This safely copies the data contents of the datastructure to th...
Definition: mailbox.cpp:111
PORT_PRIO_TYPE GetPriority(void)
GetPriority Return the priority of the current thread.
Definition: thread.h:174
const char * Thread_GetName(Thread_t handle)
Definition: mark3c.cpp:352
void ReaderWriterLock_AcquireWriter(ReaderWriterLock_t handle)
ReaderWriterLock_AcquireWriter.
Definition: mark3c.cpp:922
void Kernel_SetPanic(panic_func_t pfPanic_)
Kernel_SetPanic.
Definition: mark3c.cpp:209
void Message_Init(Message_t handle)
Message_Init.
Definition: mark3c.cpp:687
void ConditionVariable_Signal(ConditionVariable_t handle)
ConditionVariable_Signal.
Definition: mark3c.cpp:879
thread_state_t
Definition: mark3c.h:103
Semaphore_t Alloc_Semaphore(void)
Alloc_Semaphore.
Definition: mark3c.cpp:40
uint16_t Mailbox_GetFreeSlots(Mailbox_t handle)
Mailbox_GetFreeSlots.
Definition: mark3c.cpp:843
T Sub(T *pSource_, T val_)
Sub Subtract a value from a variable in an uninterruptable operation.
Definition: atomic.h:81
void * Timer_t
Timer opaque handle data type.
Definition: mark3c.h:47
static Thread * GetCurrentThread()
GetCurrentThread Return the pointer to the currently-running thread.
Definition: scheduler.h:116
uint16_t Atomic_Add16(uint16_t *pu16Source_, uint16_t u16Val_)
Atomic_Add16.
Definition: mark3c.cpp:649
uint32_t Kernel_GetTicks(void)
Kernel_GetTicks.
Definition: mark3c.cpp:227
bool Mailbox_TimedSend(Mailbox_t handle, void *pvData_, uint32_t u32TimeoutMS_)
Mailbox_TimedSend.
Definition: mark3c.cpp:801
void Coroutine_Activate(Coroutine_t handle)
Definition: mark3c.cpp:964
void Mailbox_Receive(Mailbox_t handle, void *pvData_)
Mailbox_Receive.
Definition: mark3c.cpp:815
void ReaderWriterLock_Init(ReaderWriterLock_t handle)
ReaderWriterLock_Init.
Definition: mark3c.cpp:901
bool Mailbox_TimedSendTail(Mailbox_t handle, void *pvData_, uint32_t u32TimeoutMS_)
Mailbox_TimedSendTail.
Definition: mark3c.cpp:808
void Semaphore_Post(Semaphore_t handle)
Semaphore_Post.
Definition: mark3c.cpp:496
T Add(T *pSource_, T val_)
Add Add a value to a variable in an uninterruptable operation.
Definition: atomic.h:64
static void Init()
Kernel Initialization Function, call before any other OS function.
Definition: kernel.cpp:44
void SetPriority(PORT_PRIO_TYPE uXPriority_)
SetPriority. Set the priority of the Thread (running or otherwise) to a different level...
Definition: thread.cpp:341
void ReceiveTail(void *pvData_)
ReceiveTail Read one envelope from the tail of the mailbox. If the mailbox is currently empty...
Definition: mailbox.cpp:97
void SetExtendedContext(void *pvData_)
SetExtendedContext Assign the Thread object&#39;s extended-context data pointer. Used by code implementin...
Definition: thread.h:380
static void Panic(uint16_t u16Cause_)
Panic Cause the kernel to enter its panic state.
Definition: kernel.cpp:70
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&#39;t end up trying to block while the scheduler is disabled, otherwise the system ends up in an unusable state.
Definition: scheduler.cpp:75