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 be scheduled immediately.
27 Possible \ref osStatus_t return values:
28 - \em osOK: the time delay is executed.
29 - \em osErrorParameter: the time cannot be handled (zero value).
30 - \em osErrorISR: \ref osDelay cannot be called from \ref CMSIS_RTOS_ISR_Calls "Interrupt Service Routines".
31 - \em osError: \ref osDelay cannot be executed (kernel not running or no \ref ThreadStates "READY" thread exists).
33 \note This function \b cannot be called from \ref CMSIS_RTOS_ISR_Calls "Interrupt Service Routines".
37 #include "cmsis_os2.h"
39 void Thread_1 (void *arg) { // Thread function
40 osStatus_t status; // capture the return status
41 uint32_t delayTime; // delay time in milliseconds
43 delayTime = 1000U; // delay 1 second
44 status = osDelay(delayTime); // suspend thread execution
49 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
51 \fn osStatus_t osDelayUntil (uint32_t ticks)
53 The function \b osDelayUntil waits until an absolute time (specified in kernel \a ticks) is reached.
55 The corner case when the kernel tick counter overflows is handled by \b osDelayUntil. Thus it is absolutely legal
56 to provide a value which is lower than the current tick value, i.e. returned by \ref osKernelGetTickCount. Typically
57 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
58 maximum delay is limited to (2<sup>31</sup>)-1 ticks.
60 The delayed thread is put into the \ref ThreadStates "BLOCKED" state and a context switch occurs immediately. The thread
61 is automatically put back to the \ref ThreadStates "READY" state when the given time is reached. If the thread will
62 have the highest priority in \ref ThreadStates "READY" state it will be scheduled immediately.
64 Possible \ref osStatus_t return values:
65 - \em osOK: the time delay is executed.
66 - \em osErrorParameter: the time cannot be handled (out of bounds).
67 - \em osErrorISR: \ref osDelayUntil cannot be called from \ref CMSIS_RTOS_ISR_Calls "Interrupt Service Routines".
68 - \em osError: \ref osDelayUntil cannot be executed (kernel not running or no \ref ThreadStates "READY" thread exists).
70 \note This function \b cannot be called from \ref CMSIS_RTOS_ISR_Calls "Interrupt Service Routines".
74 #include "cmsis_os2.h"
76 void Thread_1 (void *arg) { // Thread function
79 tick = osKernelGetTickCount(); // retrieve the number of system ticks
81 tick += 1000U; // delay 1000 ticks periodically