source: rtems/c/src/lib/libbsp/sparc/leon2/clock/ckinit.c @ a0d4e99

5
Last change on this file since a0d4e99 was 655ce0fb, checked in by Sebastian Huber <sebastian.huber@…>, on 06/22/16 at 11:45:02

sparc: Optimize CPU counter support

  • Property mode set to 100644
File size: 2.5 KB
Line 
1/**
2 * @file
3 * @ingroup sparc_leon2
4 * @brief Clock Tick Device Driver
5 *
6 *  This routine initializes LEON timer 1 which used for the clock tick.
7 *
8 *  The tick frequency is directly programmed to the configured number of
9 *  microseconds per tick.
10 */
11
12/*
13 *  COPYRIGHT (c) 1989-2008.
14 *  On-Line Applications Research Corporation (OAR).
15 *
16 *  Modified for LEON BSP
17 *  COPYRIGHT (c) 2004.
18 *  Gaisler Research.
19 *
20 *  The license and distribution terms for this file may be
21 *  found in the file LICENSE in this distribution or at
22 *  http://www.rtems.org/license/LICENSE.
23 */
24
25#include <bsp.h>
26#include <bspopts.h>
27#include <rtems/timecounter.h>
28#include <rtems/score/sparcimpl.h>
29
30#if SIMSPARC_FAST_IDLE==1
31#define CLOCK_DRIVER_USE_FAST_IDLE 1
32#endif
33
34static rtems_timecounter_simple leon2_tc;
35
36static uint32_t leon2_tc_get( rtems_timecounter_simple *tc )
37{
38  return LEON_REG.Timer_Counter_1;
39}
40
41static bool leon2_tc_is_pending( rtems_timecounter_simple *tc )
42{
43  return LEON_Is_interrupt_pending( LEON_INTERRUPT_TIMER1 );
44}
45
46static uint32_t leon2_tc_get_timecount( struct timecounter *tc )
47{
48  return rtems_timecounter_simple_downcounter_get(
49    tc,
50    leon2_tc_get,
51    leon2_tc_is_pending
52  );
53}
54
55static void leon2_tc_at_tick( rtems_timecounter_simple *tc )
56{
57  /* Nothing to do */
58}
59
60static void leon2_tc_tick( void )
61{
62  rtems_timecounter_simple_downcounter_tick(
63    &leon2_tc,
64    leon2_tc_get,
65    leon2_tc_at_tick
66  );
67}
68
69/*
70 *  The Real Time Clock Counter Timer uses this trap type.
71 */
72
73#define CLOCK_VECTOR LEON_TRAP_TYPE( LEON_INTERRUPT_TIMER1 )
74
75#define Clock_driver_support_install_isr( _new, _old ) \
76  do { \
77    _old = set_vector( _new, CLOCK_VECTOR, 1 ); \
78  } while(0)
79
80extern int CLOCK_SPEED;
81
82#define Clock_driver_support_initialize_hardware() \
83  do { \
84    LEON_REG.Timer_Reload_1 = \
85        rtems_configuration_get_microseconds_per_tick() - 1; \
86    \
87    LEON_REG.Timer_Control_1 = ( \
88      LEON_REG_TIMER_COUNTER_ENABLE_COUNTING |  \
89        LEON_REG_TIMER_COUNTER_RELOAD_AT_ZERO | \
90        LEON_REG_TIMER_COUNTER_LOAD_COUNTER  \
91    ); \
92    rtems_timecounter_simple_install( \
93      &leon2_tc, \
94      1000000, \
95      rtems_configuration_get_microseconds_per_tick(), \
96      leon2_tc_get_timecount \
97    ); \
98  } while (0)
99
100#define Clock_driver_support_shutdown_hardware() \
101  do { \
102    LEON_Mask_interrupt( LEON_INTERRUPT_TIMER1 ); \
103    LEON_REG.Timer_Control_1 = 0; \
104  } while (0)
105
106#define Clock_driver_timecounter_tick() leon2_tc_tick()
107
108#include "../../../shared/clockdrv_shell.h"
109
110SPARC_COUNTER_DEFINITION;
Note: See TracBrowser for help on using the repository browser.