Tutorial 9 : delay_blocking library - sudeshmoreyos/Morey_os-demo-1.0 GitHub Wiki
As discussed in the previous tutorial, it is not recommended to use DELAY_SEC() macros for delays shorter than 50 milliseconds. So what should we do if we need delays shorter than 50 milliseconds?
For such cases, we can use the delay_blocking utility library. The term blocking means that the CPU is blocked for the specified delay duration and cannot execute any other tasks during that time. Therefore, it is recommended to use blocking delays only for short durations, typically not exceeding 50 milliseconds. To use the delay_blocking utility library, include the following header file in your code:
#include "util/delay_blocking.h"
You can find header file for delay_blocking utility library here delay_blocking utility Library. The source file is platform-dependent and can be found in the corresponding arch directory. This library provides the following two functions:
1. delay_ms_blocking
This function provides a delay in milliseconds. It takes a single input parameter, which must be a positive integer constant. Please note that only constant values can be passed to this function. A typical example for a 10 millisecond delay is shown below:
delay_ms_blocking(10);
2. delay_us_blocking
This function provides a delay in microseconds. It takes a single input parameter, which must be a positive integer constant. Please note that only constant values can be passed to this function. A typical example for a 10 microsecond delay is shown below:
delay_us_blocking(10);