source: rtems/cpukit/sapi/src/cpucounterconverter.c @ 4d3e9334

4.115
Last change on this file since 4d3e9334 was 24bf11e, checked in by Sebastian Huber <sebastian.huber@…>, on 02/12/14 at 09:31:38

score: Add CPU counter support

Add a CPU counter interface to allow access to a free-running counter.
It is useful to measure short time intervals. This can be used for
example to enable profiling of critical low-level functions.

Add two busy wait functions rtems_counter_delay_ticks() and
rtems_counter_delay_nanoseconds() implemented via the CPU counter.

  • Property mode set to 100644
File size: 1.1 KB
Line 
1/*
2 * Copyright (c) 2014 embedded brains GmbH.  All rights reserved.
3 *
4 *  embedded brains GmbH
5 *  Dornierstr. 4
6 *  82178 Puchheim
7 *  Germany
8 *  <rtems@embedded-brains.de>
9 *
10 * The license and distribution terms for this file may be
11 * found in the file LICENSE in this distribution or at
12 * http://www.rtems.com/license/LICENSE.
13 */
14
15#include <rtems/counter.h>
16
17RTEMS_STATIC_ASSERT(sizeof(rtems_counter_ticks) <= sizeof(uint32_t), type);
18
19static uint64_t to_ns_scaler = UINT64_C(1) << 32;
20
21static uint64_t from_ns_scaler = UINT64_C(1) << 32;
22
23uint64_t rtems_counter_ticks_to_nanoseconds( rtems_counter_ticks counter )
24{
25  return (uint32_t) ((counter * to_ns_scaler) >> 32);
26}
27
28rtems_counter_ticks rtems_counter_nanoseconds_to_ticks( uint32_t nanoseconds )
29{
30  return (rtems_counter_ticks) ((nanoseconds * from_ns_scaler) >> 32);
31}
32
33void rtems_counter_initialize_converter( uint32_t frequency )
34{
35  uint64_t ns_per_s = UINT64_C(1000000000);
36
37  to_ns_scaler = ((ns_per_s << 32) + frequency - 1) / frequency;
38  from_ns_scaler = ((UINT64_C(1) << 32) * frequency + ns_per_s - 1) / ns_per_s;
39}
Note: See TracBrowser for help on using the repository browser.