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

4.115
Last change on this file since 7579e25 was 7579e25, checked in by Sebastian Huber <sebastian.huber@…>, on Nov 25, 2013 at 7:46:19 AM

bsp/leon3: New BSP variant leon3_qemu

  • Property mode set to 100644
File size: 3.9 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.com/license/LICENSE.
19 */
20
21#include <bsp.h>
22#include <bspopts.h>
23#include <ambapp.h>
24
25#if SIMSPARC_FAST_IDLE==1
26#define CLOCK_DRIVER_USE_FAST_IDLE 1
27#endif
28
29/*
30 *  The Real Time Clock Counter Timer uses this trap type.
31 */
32
33#if defined(RTEMS_MULTIPROCESSING)
34  #define LEON3_CLOCK_INDEX \
35    (rtems_configuration_get_user_multiprocessing_table() ? LEON3_Cpu_Index : 0)
36#else
37  #define LEON3_CLOCK_INDEX 0
38#endif
39
40volatile struct gptimer_regs *LEON3_Timer_Regs = 0;
41static int clkirq;
42
43#define CLOCK_VECTOR LEON_TRAP_TYPE( clkirq )
44
45#define Clock_driver_support_at_tick()
46
47#if defined(RTEMS_MULTIPROCESSING)
48  #define Adjust_clkirq_for_node() \
49    do { \
50      if (rtems_configuration_get_user_multiprocessing_table() != NULL) { \
51        clkirq += LEON3_Cpu_Index; \
52      } \
53    } while(0)
54#else
55  #define Adjust_clkirq_for_node() do { clkirq += LEON3_CLOCK_INDEX; } while(0)
56#endif
57
58#ifndef LEON3_QEMU
59#define Clock_driver_support_find_timer() \
60  do { \
61    struct ambapp_dev *adev; \
62    \
63    /* Find first LEON3 GP Timer */ \
64    adev = (void *)ambapp_for_each(&ambapp_plb, (OPTIONS_ALL|OPTIONS_APB_SLVS),\
65              VENDOR_GAISLER, GAISLER_GPTIMER, ambapp_find_by_idx, NULL); \
66    if (adev) { \
67      /* Found APB GPTIMER Timer */ \
68      LEON3_Timer_Regs = (volatile struct gptimer_regs *) \
69                         DEV_TO_APB(adev)->start; \
70      clkirq = (LEON3_Timer_Regs->cfg & 0xf8) >> 3; \
71      \
72      Adjust_clkirq_for_node(); \
73    } \
74  } while (0)
75#else /* LEON3_QEMU */
76#define Clock_driver_support_find_timer() \
77  do { \
78    LEON3_Timer_Regs = (volatile struct gptimer_regs *) \
79                       0x80000300; \
80    clkirq = 6; \
81  } while (0)
82#endif /* LEON3_QEMU */
83
84#define Clock_driver_support_install_isr( _new, _old ) \
85  do { \
86    _old = set_vector( _new, CLOCK_VECTOR, 1 ); \
87  } while(0)
88
89#ifndef LEON3_QEMU
90#define Clock_driver_support_initialize_hardware() \
91  do { \
92    LEON3_Timer_Regs->timer[LEON3_CLOCK_INDEX].reload = \
93      rtems_configuration_get_microseconds_per_tick() - 1; \
94    \
95    LEON3_Timer_Regs->timer[LEON3_CLOCK_INDEX].ctrl = \
96      LEON3_GPTIMER_EN | LEON3_GPTIMER_RL | \
97        LEON3_GPTIMER_LD | LEON3_GPTIMER_IRQEN; \
98  } while (0)
99#else
100#define Clock_driver_support_initialize_hardware() \
101  do { \
102    LEON3_Timer_Regs->timer[LEON3_CLOCK_INDEX].reload = \
103      40 * (rtems_configuration_get_microseconds_per_tick() - 1); \
104    \
105    LEON3_Timer_Regs->timer[LEON3_CLOCK_INDEX].ctrl = \
106      LEON3_GPTIMER_EN | LEON3_GPTIMER_RL | \
107        LEON3_GPTIMER_LD | LEON3_GPTIMER_IRQEN; \
108  } while (0)
109#endif
110
111#define Clock_driver_support_shutdown_hardware() \
112  do { \
113    LEON_Mask_interrupt(LEON_TRAP_TYPE(clkirq)); \
114    LEON3_Timer_Regs->timer[LEON3_CLOCK_INDEX].ctrl = 0; \
115  } while (0)
116
117static uint32_t bsp_clock_nanoseconds_since_last_tick(void)
118{
119  uint32_t clicks;
120  uint32_t usecs;
121
122  if ( !LEON3_Timer_Regs )
123    return 0;
124
125#ifndef LEON3_QEMU
126  clicks = LEON3_Timer_Regs->timer[LEON3_CLOCK_INDEX].value;
127#else
128  clicks = LEON3_Timer_Regs->timer[LEON3_CLOCK_INDEX].value / 40;
129#endif
130
131  if ( LEON_Is_interrupt_pending( clkirq ) ) {
132    clicks = LEON3_Timer_Regs->timer[LEON3_CLOCK_INDEX].value;
133    usecs = (2*rtems_configuration_get_microseconds_per_tick() - clicks);
134  } else {
135    usecs = (rtems_configuration_get_microseconds_per_tick() - clicks);
136  }
137  return usecs * 1000;
138}
139
140#define Clock_driver_nanoseconds_since_last_tick \
141        bsp_clock_nanoseconds_since_last_tick
142
143#include "../../../shared/clockdrv_shell.h"
Note: See TracBrowser for help on using the repository browser.