static void _TickTimer (void *payload, void *arg) { nOS_Timer *timer = (nOS_Timer *)payload; bool call = false; NOS_UNUSED(arg); nOS_EnterCritical(); if ((timer->state & (NOS_TIMER_RUNNING | NOS_TIMER_PAUSED)) == NOS_TIMER_RUNNING) { if (timer->count > 0) { timer->count--; } if (timer->count == 0) { if (((nOS_TimerMode)timer->state & NOS_TIMER_MODE) == NOS_TIMER_FREE_RUNNING) { timer->count = timer->reload; /* One-shot timer */ } else { timer->state = (nOS_TimerState)(timer->state &~ NOS_TIMER_RUNNING); } /* Call callback function outside of critical section */ call = true; } } nOS_LeaveCritical(); if (call) { if (timer->callback != NULL) { timer->callback(timer, timer->arg); } } }
static void _Thread (void *arg) #endif { nOS_StatusReg sr; NOS_UNUSED(arg); while (true) { nOS_AlarmProcess(); nOS_EnterCritical(sr); if (nOS_GetHeadOfList(&_triggeredList) == NULL) { nOS_WaitForEvent(NULL, NOS_THREAD_ON_HOLD #if (NOS_CONFIG_WAITING_TIMEOUT_ENABLE > 0) || (NOS_CONFIG_SLEEP_ENABLE > 0) || (NOS_CONFIG_SLEEP_UNTIL_ENABLE > 0) ,NOS_WAIT_INFINITE #endif ); } nOS_LeaveCritical(sr); #if (NOS_CONFIG_THREAD_JOIN_ENABLE > 0) if (false) break; /* Remove "statement is unreachable" warning */ } return 0; #else }
static void _ThreadSignal (void *arg) { NOS_UNUSED(arg); while (1) { nOS_SignalProcess(); } }
void ThreadA (void *arg) { NOS_UNUSED(arg); while (1) { nOS_SemTake(&semA, NOS_WAIT_INFINITE); } }
static void _ThreadTimer (void *arg) { NOS_UNUSED(arg); while (true) { nOS_TimerProcess(); } }
void ThreadC (void *arg) { NOS_UNUSED(arg); while (1) { nOS_SemTake(&semC, NOS_WAIT_INFINITE); nOS_SemGive(&semB); } }
static void _TickTime(void *payload, void *arg) { nOS_Thread *thread = (nOS_Thread*)payload; nOS_Time time = *(nOS_Time*)thread->ext; /* Avoid warning */ NOS_UNUSED(arg); if (_timeCounter == time) { nOS_SignalThread(thread, NOS_OK); } }
static void _SuspendThread (void *payload, void *arg) { nOS_Thread *thread = (nOS_Thread*)payload; /* Avoid warning */ NOS_UNUSED(arg); /* If thread not already suspended */ if ( !(thread->state & NOS_THREAD_SUSPENDED) ) { if (thread->state == NOS_THREAD_READY) { nOS_RemoveThreadFromReadyList(thread); } thread->state = (nOS_ThreadState)(thread->state | NOS_THREAD_SUSPENDED); } }
void nOS_TickThread (void *payload, void *arg) { nOS_Thread *thread = (nOS_Thread*)payload; nOS_ThreadState state = (thread->state & NOS_THREAD_WAITING_MASK); nOS_Error err = NOS_E_TIMEOUT; /* Avoid warning */ NOS_UNUSED(arg); if (thread->timeout == nOS_tickCounter) { #if (NOS_CONFIG_SLEEP_ENABLE > 0) if (state == NOS_THREAD_SLEEPING) { err = NOS_OK; } #endif #if (NOS_CONFIG_SLEEP_UNTIL_ENABLE > 0) if (state == NOS_THREAD_SLEEPING_UNTIL) { err = NOS_OK; } #endif nOS_WakeUpThread(thread, err); } }
static void _ResumeThread (void *payload, void *arg) { nOS_Thread *thread = (nOS_Thread*)payload; #if (NOS_CONFIG_HIGHEST_THREAD_PRIO > 0) && (NOS_CONFIG_SCHED_PREEMPTIVE_ENABLE > 0) bool *sched = (bool*)arg; #else NOS_UNUSED(arg); #endif if (thread->state & NOS_THREAD_SUSPENDED) { thread->state = (nOS_ThreadState)(thread->state &~ NOS_THREAD_SUSPENDED); if (thread->state == NOS_THREAD_READY) { nOS_AppendThreadToReadyList(thread); #if (NOS_CONFIG_SCHED_PREEMPTIVE_ENABLE > 0) if (thread->prio > nOS_runningThread->prio) { if (sched != NULL) { *sched = true; } } #endif } } }