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

Last change on this file since 7a9b240 was 7a9b240, checked in by Joel Sherrill <joel@…>, on 03/01/22 at 21:34:50

bsps/sparc: Scripted embedded brains header file clean up

Updates #4625.

  • Property mode set to 100644
File size: 2.3 KB
Line 
1/*
2 * Copyright (c) 2014, 2018 embedded brains GmbH.  All rights reserved.
3 *
4 * The license and distribution terms for this file may be
5 * found in the file LICENSE in this distribution or at
6 * http://www.rtems.org/license/LICENSE.
7 */
8
9#include <leon.h>
10
11#include <rtems/counter.h>
12#include <rtems/sysinit.h>
13#include <rtems/score/sparcimpl.h>
14
15static uint32_t leon3_counter_frequency = 1000000000;
16
17uint32_t _CPU_Counter_frequency(void)
18{
19  return leon3_counter_frequency;
20}
21
22static void leon3_counter_initialize(void)
23{
24  volatile struct irqmp_timestamp_regs *irqmp_ts;
25  volatile struct gptimer_regs *gpt;
26  SPARC_Counter *counter;
27
28  irqmp_ts = &LEON3_IrqCtrl_Regs->timestamp[0];
29  gpt = LEON3_Timer_Regs;
30  counter = &_SPARC_Counter_mutable;
31
32  leon3_up_counter_enable();
33
34  if (leon3_up_counter_is_available()) {
35    /* Use the LEON4 up-counter if available */
36    counter->read_isr_disabled = _SPARC_Counter_read_asr23;
37    counter->read = _SPARC_Counter_read_asr23;
38
39    leon3_counter_frequency = leon3_up_counter_frequency();
40  } else if (irqmp_has_timestamp(irqmp_ts)) {
41    /* Use the interrupt controller timestamp counter if available */
42    counter->read_isr_disabled = _SPARC_Counter_read_up;
43    counter->read = _SPARC_Counter_read_up;
44    counter->counter_register = &LEON3_IrqCtrl_Regs->timestamp[0].counter;
45
46    /* Enable interrupt timestamping for an arbitrary interrupt line */
47    irqmp_ts->control = 0x1;
48
49    leon3_counter_frequency = ambapp_freq_get(ambapp_plb(), LEON3_IrqCtrl_Adev);
50  } else if (gpt != NULL) {
51    /* Fall back to the first GPTIMER if available */
52    counter->read_isr_disabled = _SPARC_Counter_read_down;
53    counter->read = _SPARC_Counter_read_down;
54    counter->counter_register = &gpt->timer[LEON3_COUNTER_GPTIMER_INDEX].value;
55
56    /* Enable timer just in case no clock driver is configured */
57    gpt->timer[LEON3_COUNTER_GPTIMER_INDEX].reload = 0xffffffff;
58    gpt->timer[LEON3_COUNTER_GPTIMER_INDEX].ctrl |= GPTIMER_TIMER_CTRL_EN |
59                                                    GPTIMER_TIMER_CTRL_RS |
60                                                    GPTIMER_TIMER_CTRL_LD;
61
62    leon3_counter_frequency = ambapp_freq_get(ambapp_plb(), LEON3_Timer_Adev) /
63      (gpt->scaler_reload + 1);
64  }
65}
66
67RTEMS_SYSINIT_ITEM(
68  leon3_counter_initialize,
69  RTEMS_SYSINIT_CPU_COUNTER,
70  RTEMS_SYSINIT_ORDER_FIRST
71);
72
73SPARC_COUNTER_DEFINITION;
Note: See TracBrowser for help on using the repository browser.