2 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
3 // ==== Generic Wait Functions ====
5 \addtogroup CMSIS_RTOS_Wait Generic Wait Functions
7 \brief Wait for a certain period of time.
9 The generic wait functions provide means for a time delay.
11 \note Generic wait functions cannot be called from \ref CMSIS_RTOS_ISR_Calls "Interrupt Service Routines".
15 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
17 \fn osStatus_t osDelay (uint32_t ticks)
19 The function \b osDelay waits for a time period specified in kernel \a ticks. For a value of \token{1} the system waits
20 until the next timer tick occurs. The actual time delay may be up to one timer tick less than specified, i.e. calling
21 \c osDelay(1) right before the next system tick occurs the thread is rescheduled immediately.
23 The delayed thread is put into the \ref ThreadStates "BLOCKED" state and a context switch occurs immediately. The thread
24 is automatically put back to the \ref ThreadStates "READY" state after the given amount of ticks has elapsed. If the thread
25 will have the highest priority in \ref ThreadStates "READY" state it will being scheduled immediately.
27 Possible \ref osStatus_t return values:
28 - \em osOK: the time delay is executed.
29 - \em osErrorISR: \ref osDelay cannot be called from \ref CMSIS_RTOS_ISR_Calls "Interrupt Service Routines".
31 \note This function \b cannot be called from \ref CMSIS_RTOS_ISR_Calls "Interrupt Service Routines".
35 #include "cmsis_os2.h"
37 void Thread_1 (void *arg) { // Thread function
38 osStatus_t status; // capture the return status
39 uint32_t delayTime; // delay time in milliseconds
41 delayTime = 1000U; // delay 1 second
42 status = osDelay(delayTime); // suspend thread execution
47 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
49 \fn osStatus_t osDelayUntil (uint32_t ticks)
51 The function \b osDelayUntil waits until an absolute time (specified in kernel \a ticks) is reached.
53 The corner case when the kernel tick counter overflows is handled by \b osDelayUntil. Thus it is absolutely legal
54 to provide a value which is lower than the current tick value, i.e. returned by \ref osKernelGetTickCount. Typically
55 as a user you do not have to take care about the overflow. The only limitation you have to have in mind is that the
56 maximum delay is limited to (2<sup>31</sup>)-1 ticks.
58 The delayed thread is put into the \ref ThreadStates "BLOCKED" state and a context switch occurs immediately. The thread
59 is automatically put back to the \ref ThreadStates "READY" state when the given time is reached. If the thread will
60 have the highest priority in \ref ThreadStates "READY" state it will being scheduled immediately.
62 Possible \ref osStatus_t return values:
63 - \em osOK: the time delay is executed.
64 - \em osParameter: the time cannot be handled (out of bounds).
65 - \em osErrorISR: \ref osDelayUntil cannot be called from \ref CMSIS_RTOS_ISR_Calls "Interrupt Service Routines".
67 \note This function \b cannot be called from \ref CMSIS_RTOS_ISR_Calls "Interrupt Service Routines".
71 #include "cmsis_os2.h"
73 void Thread_1 (void *arg) { // Thread function
76 tick = osKernelGetTickCount(); // retrieve the number of system ticks
78 tick += 1000U; // delay 1000 ticks periodically