source: rtems/c/src/lib/libbsp/arm/tms570/misc/cpucounterread.c @ b2ed712

5
Last change on this file since b2ed712 was e2191d6c, checked in by Sebastian Huber <sebastian.huber@…>, on 03/27/17 at 11:21:59

bsp/tms570: Simplify CPU counter support

Only touch the cycle counter settings. Do not enable user mode access.

  • Property mode set to 100644
File size: 1.5 KB
Line 
1/**
2 * @file
3 *
4 * @ingroup tms570_clocks
5 *
6 * @brief Cortex-R performace counters
7 *
8 * The counters setup functions are these which has been suggested
9 * on StackOverflow
10 *
11 * Code is probably for use on Cortex-A without modifications as well.
12 *
13 * http://stackoverflow.com/questions/3247373/how-to-measure-program-execution-time-in-arm-cortex-a8-processor
14 */
15
16/*
17 * Copyright (c) 2014 Pavel Pisa <pisa@cmp.felk.cvut.cz>
18 *
19 * Czech Technical University in Prague
20 * Zikova 1903/4
21 * 166 36 Praha 6
22 * Czech Republic
23 *
24 * The license and distribution terms for this file may be
25 * found in the file LICENSE in this distribution or at
26 * http://www.rtems.org/license/LICENSE.
27 */
28
29#include <rtems/counter.h>
30#include <rtems/sysinit.h>
31
32#include <libcpu/arm-cp15.h>
33
34#include <bsp.h>
35
36static void tms570_cpu_counter_initialize(void)
37{
38  uint32_t cycle_counter;
39  uint32_t pmcr;
40
41  cycle_counter = ARM_CP15_PMCLRSET_CYCLE_COUNTER;
42  arm_cp15_set_performance_monitors_interrupt_enable_clear(cycle_counter);
43  arm_cp15_set_performance_monitors_count_enable_set(cycle_counter);
44
45  pmcr = arm_cp15_get_performance_monitors_control();
46  pmcr &= ~ARM_CP15_PMCR_D;
47  pmcr |= ARM_CP15_PMCR_E;
48  arm_cp15_set_performance_monitors_control(pmcr);
49
50  rtems_counter_initialize_converter(2 * BSP_PLL_OUT_CLOCK);
51}
52
53CPU_Counter_ticks _CPU_Counter_read(void)
54{
55  return arm_cp15_get_performance_monitors_cycle_count();
56}
57
58RTEMS_SYSINIT_ITEM(
59  tms570_cpu_counter_initialize,
60  RTEMS_SYSINIT_BSP_START,
61  RTEMS_SYSINIT_ORDER_FIRST
62);
Note: See TracBrowser for help on using the repository browser.