source: rtems/c/src/lib/libbsp/sparc/leon3/clock/ckinit.c @ ead16ae1

4.115
Last change on this file since ead16ae1 was 60b0fd5, checked in by Daniel Hellstrom <daniel@…>, on 02/19/15 at 08:20:13

leon3: clock driver rely on previous found timer

No point in scanning for the same GPTIMER twice. Rely on
amba.c AMBA PnP scanning.

  • Property mode set to 100644
File size: 4.0 KB
Line 
1/*
2 *  Clock Tick Device Driver
3 *
4 *  This routine initializes LEON timer 1 which used for the clock tick.
5 *
6 *  The tick frequency is directly programmed to the configured number of
7 *  microseconds per tick.
8 *
9 *  COPYRIGHT (c) 1989-2006.
10 *  On-Line Applications Research Corporation (OAR).
11 *
12 *  Modified for LEON3 BSP.
13 *  COPYRIGHT (c) 2004.
14 *  Gaisler Research.
15 *
16 *  The license and distribution terms for this file may be
17 *  found in the file LICENSE in this distribution or at
18 *  http://www.rtems.org/license/LICENSE.
19 */
20
21#include <bsp.h>
22#include <bspopts.h>
23#include <bsp/fatal.h>
24#include <rtems/rtems/intr.h>
25#include <ambapp.h>
26#include <rtems/score/profiling.h>
27
28#if SIMSPARC_FAST_IDLE==1
29#define CLOCK_DRIVER_USE_FAST_IDLE 1
30#endif
31
32/*
33 *  The Real Time Clock Counter Timer uses this trap type.
34 */
35
36volatile struct gptimer_regs *LEON3_Timer_Regs = 0;
37static int clkirq;
38
39static void leon3_clock_profiling_interrupt_delay(void)
40{
41#ifdef RTEMS_PROFILING
42  /*
43   * We need a small state machine to ignore the first clock interrupt, since
44   * it contains the sequential system initialization time.  Do the timestamp
45   * initialization on the fly.
46   */
47  static int state = 1;
48
49  volatile struct irqmp_timestamp_regs *irqmp_ts =
50    &LEON3_IrqCtrl_Regs->timestamp[0];
51  unsigned int s1_s2 = (1U << 25) | (1U << 26);
52
53  if (state == 0) {
54    unsigned int first = irqmp_ts->assertion;
55    unsigned int second = irqmp_ts->counter;
56
57    irqmp_ts->control |= s1_s2;
58
59    _Profiling_Update_max_interrupt_delay(_Per_CPU_Get(), second - first);
60  } else if (state == 1 && leon3_irqmp_has_timestamp(irqmp_ts)) {
61    unsigned int ks = 1U << 5;
62
63    state = 0;
64
65    irqmp_ts->control = ks | s1_s2 | (unsigned int) clkirq;
66  } else if (state == 1) {
67    state = 2;
68  }
69#endif
70}
71
72#define Clock_driver_support_at_tick() \
73  do { \
74    leon3_clock_profiling_interrupt_delay(); \
75  } while (0)
76
77#if defined(RTEMS_MULTIPROCESSING)
78  #define Adjust_clkirq_for_node() \
79    do { \
80      if (rtems_configuration_get_user_multiprocessing_table() != NULL) { \
81        clkirq += LEON3_Cpu_Index; \
82      } \
83    } while(0)
84#else
85  #define Adjust_clkirq_for_node() do { clkirq += LEON3_CLOCK_INDEX; } while(0)
86#endif
87
88#define Clock_driver_support_find_timer() \
89  do { \
90    /* Assume timer found during BSP initialization */ \
91    if (LEON3_Timer_Regs) { \
92      clkirq = (LEON3_Timer_Regs->cfg & 0xf8) >> 3; \
93      \
94      Adjust_clkirq_for_node(); \
95    } \
96  } while (0)
97
98#define Clock_driver_support_install_isr( _new, _old ) \
99  do { \
100    (_old) = NULL; \
101    bsp_clock_handler_install(_new); \
102  } while(0)
103
104static void bsp_clock_handler_install(rtems_isr *new)
105{
106  rtems_status_code sc;
107
108  sc = rtems_interrupt_handler_install(
109    clkirq,
110    "Clock",
111    RTEMS_INTERRUPT_UNIQUE,
112    new,
113    NULL
114  );
115  if (sc != RTEMS_SUCCESSFUL) {
116    rtems_fatal(RTEMS_FATAL_SOURCE_BSP, LEON3_FATAL_CLOCK_INITIALIZATION);
117  }
118}
119
120#define Clock_driver_support_initialize_hardware() \
121  do { \
122    LEON3_Timer_Regs->timer[LEON3_CLOCK_INDEX].reload = \
123      rtems_configuration_get_microseconds_per_tick() - 1; \
124    \
125    LEON3_Timer_Regs->timer[LEON3_CLOCK_INDEX].ctrl = \
126      GPTIMER_TIMER_CTRL_EN | GPTIMER_TIMER_CTRL_RS | \
127        GPTIMER_TIMER_CTRL_LD | GPTIMER_TIMER_CTRL_IE; \
128  } while (0)
129
130#define Clock_driver_support_shutdown_hardware() \
131  do { \
132    LEON_Mask_interrupt(LEON_TRAP_TYPE(clkirq)); \
133    LEON3_Timer_Regs->timer[LEON3_CLOCK_INDEX].ctrl = 0; \
134  } while (0)
135
136static uint32_t bsp_clock_nanoseconds_since_last_tick(void)
137{
138  uint32_t clicks;
139  uint32_t usecs;
140
141  if ( !LEON3_Timer_Regs )
142    return 0;
143
144  clicks = LEON3_Timer_Regs->timer[LEON3_CLOCK_INDEX].value;
145
146  if ( LEON_Is_interrupt_pending( clkirq ) ) {
147    clicks = LEON3_Timer_Regs->timer[LEON3_CLOCK_INDEX].value;
148    usecs = (2*rtems_configuration_get_microseconds_per_tick() - clicks);
149  } else {
150    usecs = (rtems_configuration_get_microseconds_per_tick() - clicks);
151  }
152  return usecs * 1000;
153}
154
155#define Clock_driver_nanoseconds_since_last_tick \
156        bsp_clock_nanoseconds_since_last_tick
157
158#include "../../../shared/clockdrv_shell.h"
Note: See TracBrowser for help on using the repository browser.