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

4.115
Last change on this file since 1f7cfbe3 was 1f7cfbe3, checked in by Daniel Hellstrom <daniel@…>, on 04/17/12 at 14:25:39

LEON2: clock driver use new AMBAPP layer

Signed-off-by: Daniel Hellstrom <daniel@…>

  • 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
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
40
41volatile LEON3_Timer_Regs_Map *LEON3_Timer_Regs = 0;
42static int clkirq;
43
44#define CLOCK_VECTOR LEON_TRAP_TYPE( clkirq )
45
46#define Clock_driver_support_at_tick()
47
48#if defined(RTEMS_MULTIPROCESSING)
49  #define Adjust_clkirq_for_node() \
50    do { \
51      if (rtems_configuration_get_user_multiprocessing_table() != NULL) { \
52        clkirq += LEON3_Cpu_Index; \
53      } \
54    } while(0)
55#else
56  #define Adjust_clkirq_for_node() do { clkirq += LEON3_CLOCK_INDEX; } while(0)
57#endif
58
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 LEON3_Timer_Regs_Map *) \
69                         DEV_TO_APB(adev)->start; \
70      clkirq = (LEON3_Timer_Regs->status & 0xf8) >> 3; \
71      \
72      Adjust_clkirq_for_node(); \
73    } \
74  } while (0)
75
76#define Clock_driver_support_install_isr( _new, _old ) \
77  do { \
78    _old = set_vector( _new, CLOCK_VECTOR, 1 ); \
79  } while(0)
80
81#define Clock_driver_support_initialize_hardware() \
82  do { \
83    LEON3_Timer_Regs->timer[LEON3_CLOCK_INDEX].reload = \
84      rtems_configuration_get_microseconds_per_tick() - 1; \
85    \
86    LEON3_Timer_Regs->timer[LEON3_CLOCK_INDEX].conf = \
87      LEON3_GPTIMER_EN | LEON3_GPTIMER_RL | \
88        LEON3_GPTIMER_LD | LEON3_GPTIMER_IRQEN; \
89  } while (0)
90
91#define Clock_driver_support_shutdown_hardware() \
92  do { \
93    LEON_Mask_interrupt(LEON_TRAP_TYPE(clkirq)); \
94    LEON3_Timer_Regs->timer[LEON3_CLOCK_INDEX].conf = 0; \
95  } while (0)
96
97uint32_t bsp_clock_nanoseconds_since_last_tick(void)
98{
99  uint32_t clicks;
100  uint32_t usecs;
101
102  if ( !LEON3_Timer_Regs )
103    return 0;
104
105  clicks = LEON3_Timer_Regs->timer[LEON3_CLOCK_INDEX].value;
106
107  if ( LEON_Is_interrupt_pending( clkirq ) ) {
108    clicks = LEON3_Timer_Regs->timer[LEON3_CLOCK_INDEX].value;
109    usecs = (2*rtems_configuration_get_microseconds_per_tick() - clicks);
110  } else {
111    usecs = (rtems_configuration_get_microseconds_per_tick() - clicks);
112  }
113  return usecs * 1000;
114}
115
116#define Clock_driver_nanoseconds_since_last_tick \
117        bsp_clock_nanoseconds_since_last_tick
118
119#include "../../../shared/clockdrv_shell.h"
Note: See TracBrowser for help on using the repository browser.