RTEMS  5.0.0
Files | Typedefs | Functions
Free-Running Counter and Busy Wait Delay

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. More...
 
rtems_counter_ticks rtems_counter_nanoseconds_to_ticks (uint32_t nanoseconds)
 Converts nanoseconds into counter ticks. More...
 
int64_t rtems_counter_ticks_to_sbintime (rtems_counter_ticks ticks)
 Converts counter ticks into signed binary time (sbintime_t). More...
 
rtems_counter_ticks rtems_counter_sbintime_to_ticks (int64_t sbt)
 Converts signed binary time (sbintime_t) into counter ticks. More...
 
void rtems_counter_initialize_converter (uint32_t frequency)
 Initializes the counter ticks to/from nanoseconds converter functions. More...
 
void rtems_counter_delay_ticks (rtems_counter_ticks ticks)
 Busy wait for some counter ticks. More...
 
void rtems_counter_delay_nanoseconds (uint32_t nanoseconds)
 Busy wait for some nanoseconds. More...
 

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]nanosecondsThe 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]ticksThe 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]frequencyThe 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]nanosecondsThe 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]sbtThe 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]ticksThe 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]ticksThe counter ticks value to convert.
Returns
The signed binary time value corresponding to the counter ticks value. The value is rounded up.