RTEMS: Free-Running Counter and Busy Wait Delay

| RTEMS 5.4-rc2

Loading...
Searching...
No Matches
Files | Typedefs | Functions
Free-Running Counter and Busy Wait Delay
API » Classic

Free-running counter and busy wait delay functions. More...

## Files
file | counter.h
| Free-Running Counter and Busy Wait Delay API.

## Typedefs
typedef CPU_Counter_ticks | rtems_counter_ticks
| Unsigned integer type for counter values.

## Functions
uint64_t | rtems_counter_ticks_to_nanoseconds (rtems_counter_ticks ticks)
| Converts counter ticks into nanoseconds.
rtems_counter_ticks | rtems_counter_nanoseconds_to_ticks (uint32_t nanoseconds)
| Converts nanoseconds into counter ticks.
int64_t | rtems_counter_ticks_to_sbintime (rtems_counter_ticks ticks)
| Converts counter ticks into signed binary time (sbintime_t).
rtems_counter_ticks | rtems_counter_sbintime_to_ticks (int64_t sbt)
| Converts signed binary time (sbintime_t) into counter ticks.
void | rtems_counter_initialize_converter (uint32_t frequency)
| Initializes the counter ticks to/from nanoseconds converter functions.
void | rtems_counter_delay_ticks (rtems_counter_ticks ticks)
| Busy wait for some counter ticks.
void | rtems_counter_delay_nanoseconds (uint32_t nanoseconds)
| Busy wait for some nanoseconds.

## Detailed Description

Free-running counter and busy wait delay functions.

The RTEMS counter is some free-running counter. It ticks usually with a frequency close to the CPU or system bus clock.

The counter can be used in case the overhead of the rtems_clock_get_uptime_nanoseconds() is too high. The step from counter ticks to/from nanoseconds is explicit in this API unlike to rtems_clock_get_uptime_nanoseconds() which performs the conversion on each invocation.

This counter works without a clock driver and during system initialization.

The counter can be used to profile low-level operations like SMP locks or interrupt disabled critical sections. The counter can act also as an entropy source for a random number generator.

The period of the counter depends on the actual hardware.

## Function Documentation

## ◆ rtems_counter_delay_nanoseconds()

void rtems_counter_delay_nanoseconds | ( | uint32_t | nanoseconds | ) |

Busy wait for some nanoseconds.

This function does not disable interrupts. Thus task switches and interrupts can interfere with this busy wait may prolong the delay. This function busy waits at least the specified time. Due to some overhead the actual delay may be longer.

Parameters

  [in] | nanoseconds | The minimum busy wait time in nanoseconds.

## ◆ rtems_counter_delay_ticks()

void rtems_counter_delay_ticks | ( | rtems_counter_ticks | ticks | ) |

Busy wait for some counter ticks.

This function does not disable interrupts. Thus task switches and interrupts can interfere with this busy wait may prolong the delay. This function busy waits at least the specified time. Due to some overhead the actual delay may be longer.

Parameters

  [in] | ticks | The minimum busy wait time in counter ticks.

## ◆ rtems_counter_initialize_converter()

void rtems_counter_initialize_converter | ( | uint32_t | frequency | ) |

Initializes the counter ticks to/from nanoseconds converter functions.

This function must be used to initialize the rtems_counter_ticks_to_nanoseconds() and rtems_counter_nanoseconds_to_ticks() functions. It should be called during system initialization by the board support package.

Parameters

  [in] | frequency | The current counter frequency in Hz.

## ◆ rtems_counter_nanoseconds_to_ticks()

rtems_counter_ticks rtems_counter_nanoseconds_to_ticks | ( | uint32_t | nanoseconds | ) |

Converts nanoseconds into counter ticks.

Parameters

  [in] | nanoseconds | The nanoseconds value to convert.

Returns
  The counter ticks value corresponding to the nanoseconds value. The value is rounded up.

## ◆ rtems_counter_sbintime_to_ticks()

rtems_counter_ticks rtems_counter_sbintime_to_ticks | ( | int64_t | sbt | ) |

Converts signed binary time (sbintime_t) into counter ticks.

Parameters

  [in] | sbt | The signed binary time value to convert.

Returns
  The counter ticks value corresponding to the nanoseconds value. The value is rounded up.

## ◆ rtems_counter_ticks_to_nanoseconds()

uint64_t rtems_counter_ticks_to_nanoseconds | ( | rtems_counter_ticks | ticks | ) |

Converts counter ticks into nanoseconds.

Parameters

  [in] | ticks | The counter ticks value to convert.

Returns
  The nanoseconds value corresponding to the counter ticks. The value is rounded up.

## ◆ rtems_counter_ticks_to_sbintime()

int64_t rtems_counter_ticks_to_sbintime | ( | rtems_counter_ticks | ticks | ) |

Converts counter ticks into signed binary time (sbintime_t).

Parameters

  [in] | ticks | The counter ticks value to convert.

Returns
  The signed binary time value corresponding to the counter ticks value. The value is rounded up.