summaryrefslogtreecommitdiff
path: root/c/src/lib/libbsp/arm/xm-tms570/startup/cpucounterread.c
blob: 9cefff34ecb85a459633b5723a6c513a1d1440c9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
/*
 * @file cpucounterread.c
 *
 * @author Miguel Masmano <mmasmano@fentiss.com>
 *
 * @copyright
 * Copyright 2016 Fent Innovative Software Solutions (FENTISS). 
 * All rights reserved.
 *
 * Copyright 2017 embedded brains GmbH.
 *
 * The license and distribution terms for this file may be
 * found in the file LICENSE in this distribution or at
 * http://www.rtems.org/license/LICENSE.
 */

#include <rtems/counter.h>
#include <rtems/sysinit.h>

#include <libcpu/arm-cp15.h>

#include <bsp.h>
#include <xm.h>

CPU_Counter_ticks _CPU_Counter_read(void)
{
#ifdef XM_TMS570_USE_PMU_FOR_CPU_COUNTER
  return arm_cp15_get_performance_monitors_cycle_count();
#else
  xmTime_t cTime;
  XM_get_time(XM_HW_CLOCK, &cTime);

  return (CPU_Counter_ticks)cTime;
#endif
}

static void xm_tms570_cpu_counter_initialize(void)
{
#ifdef XM_TMS570_USE_PMU_FOR_CPU_COUNTER
  rtems_counter_initialize_converter(XM_TMS570_GCLK);
#else
  rtems_counter_initialize_converter(1000000);
#endif
}

RTEMS_SYSINIT_ITEM(
  xm_tms570_cpu_counter_initialize,
  RTEMS_SYSINIT_BSP_START,
  RTEMS_SYSINIT_ORDER_FIRST
);