29 #if defined(__cplusplus) 36 #if KERNEL_EVENT_FLAGS 37 typedef void* EventFlag_t;
38 #endif // #if KERNEL_EVENT_FLAGS 54 #if KERNEL_THREAD_CREATE_CALLOUT 55 typedef void (*thread_create_callout_t)(Thread_t hThread_);
56 #endif // #if KERNEL_THREAD_CREATE_CALLOUT 57 #if KERNEL_THREAD_EXIT_CALLOUT 58 typedef void (*thread_exit_callout_t)(Thread_t hThread_);
59 #endif // #if KERNEL_THREAD_EXIT_CALLOUT 60 #if KERNEL_CONTEXT_SWITCH_CALLOUT 61 typedef void (*thread_context_callout_t)(Thread_t hThread_);
62 #endif // #if KERNEL_CONTEXT_SWITCH_CALLOUT 69 #define THREAD_SIZE (sizeof(Fake_Thread)) 70 #define TIMER_SIZE (sizeof(Fake_Timer)) 71 #define SEMAPHORE_SIZE (sizeof(Fake_Semaphore)) 72 #define MUTEX_SIZE (sizeof(Fake_Mutex)) 73 #define MESSAGE_SIZE (sizeof(Fake_Message)) 74 #define MESSAGEQUEUE_SIZE (sizeof(Fake_MessageQueue)) 75 #define MAILBOX_SIZE (sizeof(Fake_Mailbox)) 76 #define NOTIFY_SIZE (sizeof(Fake_Notify)) 77 #if KERNEL_EVENT_FLAGS 78 #define EVENTFLAG_SIZE (sizeof(Fake_EventFlag)) 79 #endif // #if KERNEL_EVENT_FLAGS 80 #define MESSAGEPOOL_SIZE (sizeof(Fake_MessagePool)) 81 #define CONDITIONVARIABLE_SIZE (sizeof(Fake_ConditionVariable)) 82 #define READERWRITERLOCK_SIZE (sizeof(Fake_ReaderWriterLock)) 83 #define COROUTINE_SIZE (sizeof(Fake_Coroutine)) 84 #if KERNEL_EVENT_FLAGS 95 EVENT_FLAG_PENDING_UNBLOCK
96 } event_flag_operation_t;
97 #endif // #if KERNEL_EVENT_FLAGS 114 #define TOKEN_1(x, y) x##y 115 #define TOKEN_2(x, y) TOKEN_1(x, y) 119 #define WORD_ROUND(x) (((x) + (sizeof(K_WORD) - 1)) / sizeof(K_WORD)) 121 #define DECLARE_THREAD(name) \ 122 K_WORD TOKEN_2(__thread_, name)[WORD_ROUND(THREAD_SIZE)]; \ 123 Thread_t name = (Thread_t)TOKEN_2(__thread_, name); 125 #define DECLARE_TIMER(name) \ 126 K_WORD TOKEN_2(__timer_, name)[WORD_ROUND(TIMER_SIZE)]; \ 127 Timer_t name = (Timer_t)TOKEN_2(__timer_, name); 129 #define DECLARE_SEMAPHORE(name) \ 130 K_WORD TOKEN_2(__semaphore_, name)[WORD_ROUND(SEMAPHORE_SIZE)]; \ 131 Semaphore_t name = (Semaphore_t)TOKEN_2(__semaphore_, name); 133 #define DECLARE_MUTEX(name) \ 134 K_WORD TOKEN_2(__mutex_, name)[WORD_ROUND(MUTEX_SIZE)]; \ 135 Mutex_t name = (Mutex_t)TOKEN_2(__mutex_, name); 137 #define DECLARE_MESSAGE(name) \ 138 K_WORD TOKEN_2(__message_, name)[WORD_ROUND(MESSAGE_SIZE)]; \ 139 Message_t name = (Message_t)TOKEN_2(__message_, name); 141 #define DECLARE_MESSAGEPOOL(name) \ 142 K_WORD TOKEN_2(__messagepool_, name)[WORD_ROUND(MESSAGEPOOL_SIZE)]; \ 143 MessagePool_t name = (MessagePool_t)TOKEN_2(__messagepool_, name); 145 #define DECLARE_MESSAGEQUEUE(name) \ 146 K_WORD TOKEN_2(__messagequeue_, name)[WORD_ROUND(MESSAGEQUEUE_SIZE)]; \ 147 MessageQueue_t name = (MessageQueue_t)TOKEN_2(__messagequeue_, name); 149 #define DECLARE_MAILBOX(name) \ 150 K_WORD TOKEN_2(__mailbox_, name)[WORD_ROUND(MAILBOX_SIZE)]; \ 151 Mailbox_t name = (Mailbox_t)TOKEN_2(__mailbox_, name); 153 #define DECLARE_NOTIFY(name) \ 154 K_WORD TOKEN_2(__notify_, name)[WORD_ROUND(NOTIFY_SIZE)]; \ 155 Notify_t name = (Notify_t)TOKEN_2(__notify_, name); 157 #if KERNEL_EVENT_FLAGS 158 #define DECLARE_EVENTFLAG(name) \ 159 K_WORD TOKEN_2(__eventflag_, name)[WORD_ROUND(EVENTFLAG_SIZE)]; \ 160 EventFlag_t name = (EventFlag_t)TOKEN_2(__eventflag_, name); 161 #endif // #if KERNEL_EVENT_FLAGS 163 #define DECLARE_CONDITIONVARIABLE(name) \ 164 K_WORD TOKEN_2(__condvar_, name)[WORD_ROUND(EVENTFLAG_SIZE)]; \ 165 ConditionVariable_t name = (ConditionVariable_t)TOKEN_2(__condvar_, name); 167 #define DECLARE_READERWRITERLOCK(name) \ 168 K_WORD TOKEN_2(__readerwriterlock_, name)[WORD_ROUND(EVENTFLAG_SIZE)]; \ 169 ReaderWriterLock_t name = (ReaderWriterLock_t)TOKEN_2(__readerwriterlock_, name); 171 #define DECLARE_COROUTINE(name) \ 172 K_WORD TOKEN_2(__coroutine_, name)[WORD_ROUND(COROUTINE_SIZE)]; \ 173 Coroutine_t name = (Coroutine_t)TOKEN_2(__coroutine_, name); 207 #if KERNEL_EVENT_FLAGS 215 #endif // #if KERNEL_EVENT_FLAGS 308 #if KERNEL_THREAD_CREATE_CALLOUT 314 void Kernel_SetThreadCreateCallout(thread_create_callout_t pfCreate_);
315 #endif // #if KERNEL_THREAD_CREATE_CALLOUT 317 #if KERNEL_THREAD_EXIT_CALLOUT 323 void Kernel_SetThreadExitCallout(thread_exit_callout_t pfExit_);
324 #endif // #if KERNEL_THREAD_EXIT_CALLOUT 326 #if KERNEL_CONTEXT_SWITCH_CALLOUT 332 void Kernel_SetThreadContextSwitchCallout(thread_context_callout_t pfContext_);
333 #endif // #if KERNEL_CONTEXT_SWITCH_CALLOUT 335 #if KERNEL_THREAD_CREATE_CALLOUT 341 thread_create_callout_t Kernel_GetThreadCreateCallout(
void);
342 #endif // #if KERNEL_THREAD_CREATE_CALLOUT 344 #if KERNEL_THREAD_EXIT_CALLOUT 350 thread_exit_callout_t Kernel_GetThreadExitCallout(
void);
351 #endif // #if KERNEL_THREAD_EXIT_CALLOUT 353 #if KERNEL_CONTEXT_SWITCH_CALLOUT 359 thread_context_callout_t Kernel_GetThreadContextSwitchCallout(
void);
360 #endif // #if KERNEL_CONTEXT_SWITCH_CALLOUT 362 #if KERNEL_STACK_CHECK 377 #endif // #if KERNEL_STACK_CHECK 425 uint16_t u16StackSize_,
442 #if KERNEL_NAMED_THREADS 457 #endif // #if KERNEL_NAMED_THREADS 474 #if KERNEL_ROUND_ROBIN 489 #endif // #if KERNEL_ROUND_ROBIN 511 #if KERNEL_EXTENDED_CONTEXT 518 void* Thread_GetExtendedContext(Thread_t handle);
526 void Thread_SetExtendedContext(Thread_t handle,
void* pvData_);
527 #endif // #if KERNEL_EXTENDED_CONTEXT 556 #if KERNEL_STACK_CHECK 564 #endif // #if KERNEL_STACK_CHECK 618 void Semaphore_Init(Semaphore_t handle, uint16_t u16InitVal_, uint16_t u16MaxVal_);
669 #if KERNEL_EVENT_FLAGS 677 void EventFlag_Init(EventFlag_t handle);
686 uint16_t EventFlag_Wait(EventFlag_t handle, uint16_t u16Mask_, event_flag_operation_t eMode_);
696 uint16_t EventFlag_TimedWait(EventFlag_t handle, uint16_t u16Mask_, event_flag_operation_t eMode_, uint32_t u32TimeMS_);
703 void EventFlag_Set(EventFlag_t handle, uint16_t u16Mask_);
710 void EventFlag_Clear(EventFlag_t handle, uint16_t u16Mask_);
717 uint16_t EventFlag_GetMask(EventFlag_t handle);
718 #endif // #if KERNEL_EVENT_FLAGS 749 bool Notify_TimedWait(Notify_t handle, uint32_t u32WaitTimeMS_,
bool* pbFlag_);
760 uint8_t
Atomic_Set8(uint8_t* pu8Source_, uint8_t u8Val_);
768 uint16_t
Atomic_Set16(uint16_t* pu16Source_, uint16_t u16Val_);
776 uint32_t
Atomic_Set32(uint32_t* pu32Source_, uint32_t u32Val_);
784 uint8_t
Atomic_Add8(uint8_t* pu8Source_, uint8_t u8Val_);
792 uint16_t
Atomic_Add16(uint16_t* pu16Source_, uint16_t u16Val_);
800 uint32_t
Atomic_Add32(uint32_t* pu32Source_, uint32_t u32Val_);
808 uint8_t
Atomic_Sub8(uint8_t* pu8Source_, uint8_t u8Val_);
816 uint16_t
Atomic_Sub16(uint16_t* pu16Source_, uint16_t u16Val_);
824 uint32_t
Atomic_Sub32(uint32_t* pu32Source_, uint32_t u32Val_);
945 void Mailbox_Init(Mailbox_t handle,
void* pvBuffer_, uint16_t u16BufferSize_, uint16_t u16ElementSize_);
1159 #if defined(__cplusplus) bool ReaderWriterLock_TimedAcquireWriter(ReaderWriterLock_t handle, uint32_t u32TimeoutMs_)
ReaderWriterLock_TimedAcquireWriter.
void * Message_GetData(Message_t handle)
Message_GetData.
void Kernel_Panic(uint16_t u16Cause_)
Kernel_Panic.
void(* thread_entry_func_t)(void *pvArg_)
MessagePool_t Alloc_MessagePool(void)
void ReaderWriterLock_ReleaseWriter(ReaderWriterLock_t handle)
ReaderWriterLock_ReleaseWriter.
void ReaderWriterLock_AcquireWriter(ReaderWriterLock_t handle)
ReaderWriterLock_AcquireWriter.
#define K_WORD
Size of a data word.
void Semaphore_Pend(Semaphore_t handle)
Semaphore_Pend.
bool Mailbox_TimedSend(Mailbox_t handle, void *pvData_, uint32_t u32TimeoutMS_)
Mailbox_TimedSend.
void Kernel_SetStackGuardThreshold(uint16_t u16Threshold_)
void Scheduler_Enable(bool bEnable_)
Scheduler_Enable.
void MessagePool_Init(MessagePool_t handle)
MessagePool_Init.
thread_state_t Thread_GetState(Thread_t handle)
Thread_GetState.
void Kernel_Start(void)
Kernel_Start.
Timer_t Alloc_Timer(void)
Alloc_Timer.
void ConditionVariable_Wait(ConditionVariable_t handle, Mutex_t hMutex_)
ConditionVariable_Wait.
Mailbox_t Alloc_Mailbox(void)
Alloc_Mailbox.
!< Thread is blocked on a blocking call
void * Message_t
Message opaque handle data type.
void Free_MessageQueue(MessageQueue_t handle)
void Timer_Stop(Timer_t handle)
Timer_Stop.
void Timer_Init(Timer_t handle)
Timer_Init.
void * Mutex_t
Mutex opaque handle data type.
void Thread_Start(Thread_t handle)
Thread_Start.
void Kernel_SetPanic(panic_func_t pfPanic_)
Kernel_SetPanic.
void Free_MessagePool(MessagePool_t handle)
void * Semaphore_t
Semaphore opaque handle data type.
EventFlag_t Alloc_EventFlag(void)
void Kernel_SetDebugPrintFunction(kernel_debug_print_t pfPrintFunction_)
Kernel_SetDebugPrintFunction.
void Free_Thread(Thread_t handle)
uint16_t MessageQueue_GetCount(MessageQueue_t handle)
MessageQueue_GetCount.
uint8_t Thread_GetID(Thread_t handle)
Thread_GetID.
void Free_Semaphore(Semaphore_t handle)
uint8_t Atomic_Set8(uint8_t *pu8Source_, uint8_t u8Val_)
Atomic_Set8.
uint32_t Atomic_Sub32(uint32_t *pu32Source_, uint32_t u32Val_)
Atomic_Sub32.
#define PORT_PRIO_TYPE
Type used for bitmap in the PriorityMap class.
void ReaderWriterLock_AcquireReader(ReaderWriterLock_t handle)
ReaderWriterLock_AcquireReader.
uint16_t Kernel_GetStackGuardThreshold(void)
void Thread_Stop(Thread_t handle)
Thread_Stop.
void Message_SetData(Message_t handle, void *pvData_)
Message_SetData.
void Mutex_Release(Mutex_t handle)
Mutex_Release.
void * Mailbox_t
Mailbox opaque handle data type.
Thread_t Scheduler_GetCurrentThread(void)
Scheduler_GetCurrentThread.
Message_t MessagePool_Pop(MessagePool_t handle)
MessagePool_Pop.
uint16_t Thread_GetStackSlack(Thread_t handle)
Semaphore_t Alloc_Semaphore(void)
Alloc_Semaphore.
void Free_Timer(Timer_t handle)
Mutex_t Alloc_Mutex(void)
Alloc_Mutex.
void Free_Notify(Notify_t handle)
void * Notify_t
Notification object opaque handle data type.
void ConditionVariable_Signal(ConditionVariable_t handle)
ConditionVariable_Signal.
Thread_t Alloc_Thread(void)
Alloc_Thread.
void Mailbox_ReceiveTail(Mailbox_t handle, void *pvData_)
Mailbox_ReceiveTail.
Mark3 Kernel Configuration This file is used to configure the kernel for your specific application in...
void Thread_Exit(Thread_t handle)
Thread_Exit.
void * Thread_t
Thread opaque handle data type.
void Free_Message(Message_t handle)
bool ConditionVariable_TimedWait(ConditionVariable_t handle, Mutex_t hMutex_, uint32_t u32WaitTimeMS_)
ConditionVariable_TimedWait.
!< Thread has been manually stopped
uint8_t Atomic_Add8(uint8_t *pu8Source_, uint8_t u8Val_)
Atomic_Add8.
void Notify_Signal(Notify_t handle)
Notify_Signal.
void MessageQueue_Send(MessageQueue_t handle, Message_t hMessage_)
MessageQueue_Send.
void(* coroutine_callback_t)(Coroutine_t caller, void *pvContext)
void Mutex_Init(Mutex_t handle)
Mutex_Init.
void Free_Mailbox(Mailbox_t handle)
Message_t MessageQueue_TimedReceive(MessageQueue_t handle, uint32_t u32TimeWaitMS_)
MessageQueue_TimedReceive.
void Notify_Wait(Notify_t handle, bool *pbFlag_)
Notify_Wait.
uint32_t Kernel_GetTicks(void)
Kernel_GetTicks.
uint16_t Message_GetCode(Message_t handle)
Message_GetCode.
PORT_PRIO_TYPE Thread_GetPriority(Thread_t handle)
Thread_GetPriority.
C-struct definitions that mirror.
void * ConditionVariable_t
Condition Variable opaque handle data type.
void Message_SetCode(Message_t handle, uint16_t u16Code_)
Message_SetCode.
bool Atomic_TestAndSet(bool *pbLock)
Atomic_TestAndSet.
void Kernel_DebugPrint(const char *szString_)
KernelDebug_DebugPrint.
void * Coroutine_t
Coroutine opaaque handle data type.
void Notify_Init(Notify_t handle)
Notify_Init.
uint32_t Atomic_Set32(uint32_t *pu32Source_, uint32_t u32Val_)
Atomic_Set32.
void Thread_SetName(Thread_t handle, const char *szName_)
void Semaphore_Post(Semaphore_t handle)
Semaphore_Post.
bool Mailbox_TimedSendTail(Mailbox_t handle, void *pvData_, uint32_t u32TimeoutMS_)
Mailbox_TimedSendTail.
uint16_t Atomic_Add16(uint16_t *pu16Source_, uint16_t u16Val_)
Atomic_Add16.
bool Mailbox_IsEmpty(Mailbox_t handle)
Mailbox_IsEmpty.
void Thread_SetQuantum(Thread_t handle, uint16_t u16Quantum_)
void * Alloc_Memory(size_t eSize_)
Alloc_Memory.
void Free_Memory(void *pvObject_)
Free_Memory.
Message_t MessageQueue_Receive(MessageQueue_t handle)
MessageQueue_Receive.
void ReaderWriterLock_ReleaseReader(ReaderWriterLock_t handle)
ReaderWriterLock_ReleaseReader.
bool Kernel_IsStarted(void)
Kernel_IsStarted.
uint16_t Thread_GetQuantum(Thread_t handle)
bool Mailbox_TimedReceive(Mailbox_t handle, void *pvData_, uint32_t u32TimeoutMS_)
Mailbox_TimedReceive.
void ConditionVariable_Init(ConditionVariable_t handle)
ConditionVariable_Init.
void ConditionVariable_Broadcast(ConditionVariable_t handle)
ConditionVariable_Broadcast.
MessageQueue_t Alloc_MessageQueue(void)
Alloc_MessageQueue.
Message_t Alloc_Message(void)
Alloc_Message.
bool Mailbox_SendTail(Mailbox_t handle, void *pvData_)
Mailbox_SendTail.
bool Kernel_IsPanic(void)
Kernel_IsPanic.
void Message_Init(Message_t handle)
Message_Init.
PORT_PRIO_TYPE Thread_GetCurPriority(Thread_t handle)
Thread_GetCurPriority.
uint32_t Atomic_Add32(uint32_t *pu32Source_, uint32_t u32Val_)
Atomic_Add32.
void Mailbox_Receive(Mailbox_t handle, void *pvData_)
Mailbox_Receive.
void Thread_Sleep(uint32_t u32TimeMs_)
Thread_Sleep.
void Kernel_Init(void)
Kernel_Init.
void * ReaderWriterLock_t
Reader-writer-lock opaque handle data type.
void Free_EventFlag(EventFlag_t handle)
bool Mailbox_TimedReceiveTail(Mailbox_t handle, void *pvData_, uint32_t u32TimeoutMS_)
Mailbox_TimedReceiveTail.
bool Mutex_TimedClaim(Mutex_t handle, uint32_t u32WaitTimeMS_)
Mutex_TimedClaim.
void(* panic_func_t)(uint16_t u16PanicCode_)
void MessageQueue_Init(MessageQueue_t handle)
MessageQueue_Init.
!< Thread has terminated via exit path
void * MessagePool_t
MessagePool opaque handle data type.
void Mutex_Claim(Mutex_t handle)
Mutex_Claim.
void ReaderWriterLock_Init(ReaderWriterLock_t handle)
ReaderWriterLock_Init.
!< Thread is ready to run
void(* timer_callback_t)(Thread_t hOwner_, void *pvData_)
void Free_Mutex(Mutex_t handle)
bool Notify_TimedWait(Notify_t handle, uint32_t u32WaitTimeMS_, bool *pbFlag_)
Notify_TimedWait.
void Thread_Yield(void)
Thread_Yield.
bool ReaderWriterLock_TimedAcquireReader(ReaderWriterLock_t handle, uint32_t u32TimeoutMs_)
ReaderWriterLock_TimedAcquireReader.
void Semaphore_Init(Semaphore_t handle, uint16_t u16InitVal_, uint16_t u16MaxVal_)
Semaphore_Init.
bool Scheduler_IsEnabled(void)
Scheduler_IsEnabled.
void Thread_CoopYield(void)
Thread_CoopYield.
void(* kernel_debug_print_t)(const char *szString_)
void * MessageQueue_t
MessageQueue opaque handle data type.
void Timer_Restart(Timer_t handle)
Timer_Restart.
uint16_t Mailbox_GetFreeSlots(Mailbox_t handle)
Mailbox_GetFreeSlots.
void Thread_SetPriority(Thread_t handle, PORT_PRIO_TYPE uXPriority_)
Thread_SetPriority.
const char * Thread_GetName(Thread_t handle)
void Timer_Start(Timer_t handle, bool bRepeat_, uint32_t u32IntervalMs_, timer_callback_t pfCallback_, void *pvData_)
Timer_Start.
uint8_t Atomic_Sub8(uint8_t *pu8Source_, uint8_t u8Val_)
Atomic_Sub8.
void * Timer_t
Timer opaque handle data type.
uint16_t Atomic_Sub16(uint16_t *pu16Source_, uint16_t u16Val_)
Atomic_Sub16.
void Mailbox_Init(Mailbox_t handle, void *pvBuffer_, uint16_t u16BufferSize_, uint16_t u16ElementSize_)
Mailbox_Init.
bool Mailbox_Send(Mailbox_t handle, void *pvData_)
Mailbox_Send.
void Thread_SetID(Thread_t handle, uint8_t u8ID_)
Thread_SetID.
void MessagePool_Push(MessagePool_t handle, Message_t msg)
MessagePool_Push.
void Thread_Init(Thread_t handle, K_WORD *pwStack_, uint16_t u16StackSize_, PORT_PRIO_TYPE uXPriority_, thread_entry_func_t pfEntryPoint_, void *pvArg_)
Thread_Init.
bool Mailbox_IsFull(Mailbox_t handle)
Mailbox_IsFull.
Notify_t Alloc_Notify(void)
Alloc_Notify.
bool Semaphore_TimedPend(Semaphore_t handle, uint32_t u32WaitTimeMS_)
Semaphore_TimedPend.
uint16_t Atomic_Set16(uint16_t *pu16Source_, uint16_t u16Val_)
Atomic_Set16.