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

4.115
Last change on this file since 847fc79 was 847fc79, checked in by Sebastian Huber <sebastian.huber@…>, on 02/07/14 at 08:32:31

Revert "bsp/leon3: New BSP variant leon3_qemu"

This reverts commit 7579e255127ee0cf04901bbab6c1538559053508.

Improve QEMU to support AMBA plug and play instead.

  • Property mode set to 100644
File size: 3.2 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#define Clock_driver_support_find_timer() \
59  do { \
60    struct ambapp_dev *adev; \
61    \
62    /* Find first LEON3 GP Timer */ \
63    adev = (void *)ambapp_for_each(&ambapp_plb, (OPTIONS_ALL|OPTIONS_APB_SLVS),\
64              VENDOR_GAISLER, GAISLER_GPTIMER, ambapp_find_by_idx, NULL); \
65    if (adev) { \
66      /* Found APB GPTIMER Timer */ \
67      LEON3_Timer_Regs = (volatile struct gptimer_regs *) \
68                         DEV_TO_APB(adev)->start; \
69      clkirq = (LEON3_Timer_Regs->cfg & 0xf8) >> 3; \
70      \
71      Adjust_clkirq_for_node(); \
72    } \
73  } while (0)
74
75#define Clock_driver_support_install_isr( _new, _old ) \
76  do { \
77    _old = set_vector( _new, CLOCK_VECTOR, 1 ); \
78  } while(0)
79
80#define Clock_driver_support_initialize_hardware() \
81  do { \
82    LEON3_Timer_Regs->timer[LEON3_CLOCK_INDEX].reload = \
83      rtems_configuration_get_microseconds_per_tick() - 1; \
84    \
85    LEON3_Timer_Regs->timer[LEON3_CLOCK_INDEX].ctrl = \
86      LEON3_GPTIMER_EN | LEON3_GPTIMER_RL | \
87        LEON3_GPTIMER_LD | LEON3_GPTIMER_IRQEN; \
88  } while (0)
89
90#define Clock_driver_support_shutdown_hardware() \
91  do { \
92    LEON_Mask_interrupt(LEON_TRAP_TYPE(clkirq)); \
93    LEON3_Timer_Regs->timer[LEON3_CLOCK_INDEX].ctrl = 0; \
94  } while (0)
95
96static uint32_t bsp_clock_nanoseconds_since_last_tick(void)
97{
98  uint32_t clicks;
99  uint32_t usecs;
100
101  if ( !LEON3_Timer_Regs )
102    return 0;
103
104  clicks = LEON3_Timer_Regs->timer[LEON3_CLOCK_INDEX].value;
105
106  if ( LEON_Is_interrupt_pending( clkirq ) ) {
107    clicks = LEON3_Timer_Regs->timer[LEON3_CLOCK_INDEX].value;
108    usecs = (2*rtems_configuration_get_microseconds_per_tick() - clicks);
109  } else {
110    usecs = (rtems_configuration_get_microseconds_per_tick() - clicks);
111  }
112  return usecs * 1000;
113}
114
115#define Clock_driver_nanoseconds_since_last_tick \
116        bsp_clock_nanoseconds_since_last_tick
117
118#include "../../../shared/clockdrv_shell.h"
Note: See TracBrowser for help on using the repository browser.