RTEMS
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

static uint32_t rtems_counter_frequency (void)
 Returns the current counter frequency in Hz. More...
 
static rtems_counter_ticks rtems_counter_read (void)
 Reads the current counter value. More...
 
static rtems_counter_ticks rtems_counter_difference (rtems_counter_ticks second, rtems_counter_ticks first)
 Returns the difference between the second and first CPU counter value. More...
 
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_difference()

static rtems_counter_ticks rtems_counter_difference ( rtems_counter_ticks  second,
rtems_counter_ticks  first 
)
inlinestatic

Returns the difference between the second and first CPU counter value.

This operation may be carried out as a modulo operation depending on the range of the CPU counter device.

Parameters
[in]secondThe second CPU counter value.
[in]firstThe first CPU counter value.
Returns
Returns second minus first modulo counter period.

Definition at line 96 of file counter.h.

◆ rtems_counter_frequency()

static uint32_t rtems_counter_frequency ( void  )
inlinestatic

Returns the current counter frequency in Hz.

Returns
The current counter frequency in Hz.

Definition at line 69 of file counter.h.

◆ 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_read()

static rtems_counter_ticks rtems_counter_read ( void  )
inlinestatic

Reads the current counter value.

Returns
The current counter value.

Definition at line 79 of file counter.h.

◆ 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.