Delay API

Module: Utils API

More…

Functions

Name

void

Utils_Delay_Ms(uint32_t ms)
Delay for the specified number of milliseconds.

void

Utils_Delay_Us(uint32_t us)
Delay for the specified number of microseconds.

void

Utils_Delay_Cycles(uint32_t cycles)
Delay for the specified number of CPU cycles.

Detailed Description

This module provides millisecond, microsecond, and CPU-cycle delay functions that work in both FreeRTOS and bare-metal environments.

Notes,

  • Zero delay returns immediately without blocking.

Functions Documentation

function Utils_Delay_Ms

void Utils_Delay_Ms(
    uint32_t ms
)

Delay for the specified number of milliseconds.

Parameters:

  • ms Number of milliseconds to delay

FreeRTOS,

  • Uses vTaskDelay() to yield to the scheduler for the delay period.

  • In case of freertos, the delay resolution is +/- 1 tick period (typically 1 ms). For example, a 100 ms delay can actually be anywhere between 99 ms and 101 ms.

Bare-Metal,

  • Uses a busy-wait loop with CPU cycle counter.

  • On baremetal systems, CPU cycle counters are typically 32-bit, which limits the maximum achievable delay duration. The exact limit depends on the CPU clock frequency. For example, a 600 MHz CPU can support delays up to approximately 7 seconds.

function Utils_Delay_Us

void Utils_Delay_Us(
    uint32_t us
)

Delay for the specified number of microseconds.

Parameters:

  • us Number of microseconds to delay

Uses a busy-wait loop with CPU cycle counter for microsecond precision.

Since this API uses a busy-wait loop even in case of FreeRTOS, use this only for very short delays (< 1 ms). Use Utils_Delay_Ms() for longer delays.

function Utils_Delay_Cycles

void Utils_Delay_Cycles(
    uint32_t cycles
)

Delay for the specified number of CPU cycles.

Parameters:

  • cycles Number of CPU cycles to delay

Uses a busy-wait loop with the CPU cycle counter.