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 | |
---|
36 | static 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 | |
---|
53 | CPU_Counter_ticks _CPU_Counter_read(void) |
---|
54 | { |
---|
55 | return arm_cp15_get_performance_monitors_cycle_count(); |
---|
56 | } |
---|
57 | |
---|
58 | RTEMS_SYSINIT_ITEM( |
---|
59 | tms570_cpu_counter_initialize, |
---|
60 | RTEMS_SYSINIT_BSP_START, |
---|
61 | RTEMS_SYSINIT_ORDER_FIRST |
---|
62 | ); |
---|