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

4.115
Last change on this file since 876af7a was 876af7a, checked in by Joel Sherrill <joel.sherrill@…>, on 09/23/13 at 13:16:55

leon3/.../ckinit.c: Change get nanoseconds handler to static

  • Property mode set to 100644
File size: 3.2 KB
RevLine 
[41c9282]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 *
[29d1fce]9 *  COPYRIGHT (c) 1989-2006.
[41c9282]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>
[29d1fce]22#include <bspopts.h>
[1f7cfbe3]23#include <ambapp.h>
[29d1fce]24
25#if SIMSPARC_FAST_IDLE==1
[d473dc0]26#define CLOCK_DRIVER_USE_FAST_IDLE 1
[29d1fce]27#endif
[41c9282]28
29/*
30 *  The Real Time Clock Counter Timer uses this trap type.
31 */
32
[7f3c6ce]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
[44b06ca]38#endif
[7f3c6ce]39
[226d48d8]40volatile struct gptimer_regs *LEON3_Timer_Regs = 0;
[41c9282]41static int clkirq;
42
[29d1fce]43#define CLOCK_VECTOR LEON_TRAP_TYPE( clkirq )
44
45#define Clock_driver_support_at_tick()
46
[7f3c6ce]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
[4fa6be9]55  #define Adjust_clkirq_for_node() do { clkirq += LEON3_CLOCK_INDEX; } while(0)
[7f3c6ce]56#endif
57
[29d1fce]58#define Clock_driver_support_find_timer() \
[921bb59]59  do { \
[1f7cfbe3]60    struct ambapp_dev *adev; \
[29d1fce]61    \
[1f7cfbe3]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) { \
[30a8915]66      /* Found APB GPTIMER Timer */ \
[226d48d8]67      LEON3_Timer_Regs = (volatile struct gptimer_regs *) \
[1f7cfbe3]68                         DEV_TO_APB(adev)->start; \
[226d48d8]69      clkirq = (LEON3_Timer_Regs->cfg & 0xf8) >> 3; \
[921bb59]70      \
[7f3c6ce]71      Adjust_clkirq_for_node(); \
[29d1fce]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 = \
[12bd47e]83      rtems_configuration_get_microseconds_per_tick() - 1; \
[29d1fce]84    \
[226d48d8]85    LEON3_Timer_Regs->timer[LEON3_CLOCK_INDEX].ctrl = \
[29d1fce]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)); \
[226d48d8]93    LEON3_Timer_Regs->timer[LEON3_CLOCK_INDEX].ctrl = 0; \
[29d1fce]94  } while (0)
95
[876af7a]96static uint32_t bsp_clock_nanoseconds_since_last_tick(void)
[0e58c4f]97{
98  uint32_t clicks;
[b3559ee9]99  uint32_t usecs;
100
[0e58c4f]101  if ( !LEON3_Timer_Regs )
102    return 0;
103
[4fa6be9]104  clicks = LEON3_Timer_Regs->timer[LEON3_CLOCK_INDEX].value;
[0e58c4f]105
[b3559ee9]106  if ( LEON_Is_interrupt_pending( clkirq ) ) {
[4fa6be9]107    clicks = LEON3_Timer_Regs->timer[LEON3_CLOCK_INDEX].value;
[b3559ee9]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;
[0e58c4f]113}
114
[b3559ee9]115#define Clock_driver_nanoseconds_since_last_tick \
116        bsp_clock_nanoseconds_since_last_tick
[0e58c4f]117
[8ce272b]118#include "../../../shared/clockdrv_shell.h"
Note: See TracBrowser for help on using the repository browser.