source: rtems/c/src/lib/libbsp/sparc/leon3/startup/cpucounter.c @ a31845f7

4.115
Last change on this file since a31845f7 was e51eb80, checked in by Daniel Hellstrom <daniel@…>, on 02/19/15 at 08:25:09

leon3,ngmp: simplify cpucounter initialization

Remove support for using the second timer for time stamping.
Instead the user can configure the system clock timer to a higher
base clock frequency (lower the prescaler). This change does not
affect the GR712RC or LEON4-N2X. The GR712RC does not have two
GPTIMERs and the N2X uses the Interrupt Controller for time
stamping.

Bow that the AMBA initialization code exports the AMBA device,
the frequency can be obtained without an additional AMBA PnP
scanning.

  • Property mode set to 100644
File size: 2.0 KB
Line 
1/*
2 * Copyright (c) 2014 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
19static CPU_Counter_ticks timestamp_counter_difference(
20  CPU_Counter_ticks second,
21  CPU_Counter_ticks first
22)
23{
24  return second - first;
25}
26
27static CPU_Counter_ticks clock_counter_difference(
28  CPU_Counter_ticks second,
29  CPU_Counter_ticks first
30)
31{
32  CPU_Counter_ticks period = rtems_configuration_get_microseconds_per_tick();
33
34  return (first + period - second) % period;
35}
36
37static void gpt_counter_initialize(
38  volatile struct gptimer_regs *gpt,
39  size_t timer_index,
40  uint32_t frequency,
41  SPARC_Counter_difference counter_difference
42)
43{
44  _SPARC_Counter_initialize(
45    (volatile const uint32_t *) &gpt->timer[timer_index].value,
46    counter_difference
47  );
48
49  rtems_counter_initialize_converter(frequency);
50}
51
52void leon3_cpu_counter_initialize(void)
53{
54  volatile struct irqmp_timestamp_regs *irqmp_ts =
55    &LEON3_IrqCtrl_Regs->timestamp[0];
56  unsigned int freq;
57
58  if (leon3_irqmp_has_timestamp(irqmp_ts)) {
59    /* Use the interrupt controller timestamp counter if available */
60
61    /* Enable interrupt timestamping for an arbitrary interrupt line */
62    irqmp_ts->control = 0x1;
63
64    _SPARC_Counter_initialize(
65      (volatile const uint32_t *) &irqmp_ts->counter,
66      timestamp_counter_difference
67    );
68
69    /* Get and set the frequency */
70    rtems_counter_initialize_converter(ambapp_freq_get(&ambapp_plb, irqmp_dev));
71  } else if (LEON3_Timer_Regs != NULL) {
72      /* Fall back to the first GPTIMER if available */
73      freq = ambapp_freq_get(&ambapp_plb, timer_dev);
74
75      gpt_counter_initialize(
76        LEON3_Timer_Regs,
77        LEON3_CLOCK_INDEX,
78        freq / (LEON3_Timer_Regs->scaler_reload - 1),
79        clock_counter_difference
80      );
81  }
82}
Note: See TracBrowser for help on using the repository browser.