source: rtems/bsps/sparc/leon3/start/cpucounter.c @ 9964895

5
Last change on this file since 9964895 was 9964895, checked in by Sebastian Huber <sebastian.huber@…>, on 04/20/18 at 08:35:35

bsps: Move startup files to bsps

Adjust build support files to new directory layout.

This patch is a part of the BSP source reorganization.

Update #3285.

  • Property mode set to 100644
File size: 2.1 KB
Line 
1/*
2 * Copyright (c) 2014, 2016 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.org/license/LICENSE.
13 */
14
15#include <leon.h>
16
17#include <rtems/counter.h>
18#include <rtems/sysinit.h>
19#include <rtems/score/sparcimpl.h>
20
21static void leon3_counter_initialize(void)
22{
23  volatile struct irqmp_timestamp_regs *irqmp_ts;
24  volatile struct gptimer_regs *gpt;
25  unsigned int freq;
26
27  irqmp_ts = &LEON3_IrqCtrl_Regs->timestamp[0];
28  gpt = LEON3_Timer_Regs;
29
30  leon3_up_counter_enable();
31
32  if (leon3_up_counter_is_available()) {
33    /* Use the LEON4 up-counter if available */
34
35    _SPARC_Counter_initialize(
36      _SPARC_Counter_read_asr23,
37      _SPARC_Counter_difference_normal,
38      NULL
39    );
40
41    freq = leon3_up_counter_frequency();
42    rtems_counter_initialize_converter(freq);
43  } else if (leon3_irqmp_has_timestamp(irqmp_ts)) {
44    /* Use the interrupt controller timestamp counter if available */
45
46    /* Enable interrupt timestamping for an arbitrary interrupt line */
47    irqmp_ts->control = 0x1;
48
49    _SPARC_Counter_initialize(
50      _SPARC_Counter_read_address,
51      _SPARC_Counter_difference_normal,
52      (volatile const uint32_t *) &irqmp_ts->counter
53    );
54
55    freq = ambapp_freq_get(&ambapp_plb, LEON3_IrqCtrl_Adev);
56    rtems_counter_initialize_converter(freq);
57  } else if (gpt != NULL) {
58    /* Fall back to the first GPTIMER if available */
59
60    /* Enable timer just in case no clock driver is configured */
61    gpt->timer[LEON3_CLOCK_INDEX].ctrl |= GPTIMER_TIMER_CTRL_EN;
62
63    _SPARC_Counter_initialize(
64      _SPARC_Counter_read_address,
65      _SPARC_Counter_difference_clock_period,
66      (volatile const uint32_t *) &gpt->timer[LEON3_CLOCK_INDEX].value
67    );
68
69    freq = ambapp_freq_get(&ambapp_plb, LEON3_Timer_Adev);
70    rtems_counter_initialize_converter(freq / (gpt->scaler_reload - 1));
71  }
72}
73
74RTEMS_SYSINIT_ITEM(
75  leon3_counter_initialize,
76  RTEMS_SYSINIT_BSP_START,
77  RTEMS_SYSINIT_ORDER_THIRD
78);
79
80SPARC_COUNTER_DEFINITION;
Note: See TracBrowser for help on using the repository browser.