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

4.11
Last change on this file since 159ee990 was 159ee990, checked in by Daniel Hellstrom <daniel@…>, on Apr 7, 2015 at 2:05:04 PM

leon3,ngmp: cpucounter initialization use proper names

To be merged with "leon3,ngmp: simplify cpucounter initialization"

.. as an affect of previous patch, the next must be updated too.

  • 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(
71      ambapp_freq_get(&ambapp_plb, LEON3_IrqCtrl_Adev));
72  } else if (LEON3_Timer_Regs != NULL) {
73      /* Fall back to the first GPTIMER if available */
74      freq = ambapp_freq_get(&ambapp_plb, LEON3_Timer_Adev);
75
76      gpt_counter_initialize(
77        LEON3_Timer_Regs,
78        LEON3_CLOCK_INDEX,
79        freq / (LEON3_Timer_Regs->scaler_reload - 1),
80        clock_counter_difference
81      );
82  }
83}
Note: See TracBrowser for help on using the repository browser.