/*! * \brief Temporarily suspends the current thread. * * Causes the current thread to wait for a specified interval or, * if the specified interval is zero, to give up the CPU for * another thread with higher or same priority. * * This function may switch to another application thread, that * got the same or a higher priority and is ready to run. * * \note Threads may sleep longer than the specified number of * milliseconds, depending on the number of threads * with higher or equal priority, which are ready to run. * * \param ms Milliseconds to sleep. If 0, the current thread will not * sleep, but may give up the CPU. The resolution is limited * to the granularity of the system timer. * * \todo Code size can be reduced by trying to create the timer before * removing the thread from the run queue. */ void NutSleep(uint32_t ms) { if (ms) { /* remove running thread from runQueue */ NutThreadRemoveQueue(runningThread, &runQueue); runningThread->td_state = TDS_SLEEP; if ((runningThread->td_timer = NutTimerStart(ms, NutThreadWake, runningThread, TM_ONESHOT)) != 0) { #ifdef NUTTRACER TRACE_ADD_ITEM(TRACE_TAG_THREAD_SLEEP,(int)runningThread); #endif NutThreadResume(); } else { /* timer creation failed, restore queues */ runningThread->td_queue = &runQueue; runningThread->td_qnxt = runQueue; runningThread->td_state = TDS_RUNNING; runQueue = runningThread; } } else NutThreadYield(); }
void NutTraceStop() { TRACE_ADD_ITEM(TRACE_TAG_STOP,0); trace_mode = TRACE_MODE_OFF; }
void NutTraceClear() { trace_head = trace_isfull = 0; TRACE_ADD_ITEM(TRACE_TAG_START,0); }