source: rtems/bsps/sparc/erc32/clock/ckinit.c @ c05d7a9d

5
Last change on this file since c05d7a9d was 0a1f5df9, checked in by Sebastian Huber <sebastian.huber@…>, on 05/03/18 at 11:03:27

Simplify _CPU_Counter_difference()

In order to simplify the use of CPU counter values it is beneficial to
have monotonic increasing values within the range of the CPU counter
ticks data type, e.g. 32-bit unsigned integer. This eases the use of
CPU counter timestamps in external tools which do not know the details
of the CPU counter hardware. The CPU counter is the fastest way to get
a time on an RTEMS system.

Such a CPU counter may be also used as the timecounter. Use it on SPARC
for this purpose to simplify the clock drivers.

Update #3456.

  • Property mode set to 100644
File size: 3.4 KB
Line 
1/*
2 *  This routine initializes the Real Time Clock Counter Timer which is
3 *  part of the MEC on the ERC32 CPU.
4 *
5 *  The tick frequency is directly programmed to the configured number of
6 *  microseconds per tick.
7 */
8
9/*
10 *  COPYRIGHT (c) 1989-2008.
11 *  On-Line Applications Research Corporation (OAR).
12 *
13 *  The license and distribution terms for this file may be
14 *  found in the file LICENSE in this distribution or at
15 *  http://www.rtems.org/license/LICENSE.
16 *
17 *  Ported to ERC32 implementation of the SPARC by On-Line Applications
18 *  Research Corporation (OAR) under contract to the European Space
19 *  Agency (ESA).
20 *
21 *  ERC32 modifications of respective RTEMS file: COPYRIGHT (c) 1995.
22 *  European Space Agency.
23 */
24
25#include <bsp.h>
26#include <bspopts.h>
27#include <rtems/sysinit.h>
28#include <rtems/timecounter.h>
29#include <rtems/score/sparcimpl.h>
30
31extern int CLOCK_SPEED;
32
33#define ERC32_REAL_TIME_CLOCK_FREQUENCY 1000000
34
35static struct timecounter erc32_tc;
36
37static void erc32_clock_init( void )
38{
39  struct timecounter *tc;
40
41  tc = &erc32_tc;
42  tc->tc_get_timecount = _SPARC_Get_timecount_clock;
43  tc->tc_counter_mask = 0xffffffff;
44  tc->tc_frequency = ERC32_REAL_TIME_CLOCK_FREQUENCY;
45  tc->tc_quality = RTEMS_TIMECOUNTER_QUALITY_CLOCK_DRIVER;
46  rtems_timecounter_install(tc);
47}
48
49uint32_t _CPU_Counter_frequency(void)
50{
51  return ERC32_REAL_TIME_CLOCK_FREQUENCY;
52}
53
54static void erc32_clock_at_tick( void )
55{
56  SPARC_Counter *counter;
57  rtems_interrupt_level level;
58
59  counter = &_SPARC_Counter_mutable;
60  rtems_interrupt_local_disable(level);
61
62  ERC32_Clear_interrupt( ERC32_INTERRUPT_REAL_TIME_CLOCK );
63  counter->accumulated += counter->interval;
64
65  rtems_interrupt_local_enable(level);
66}
67
68static void erc32_clock_initialize_early( void )
69{
70  SPARC_Counter *counter;
71
72  /* approximately 1 us per countdown */
73  ERC32_MEC.Real_Time_Clock_Scalar = CLOCK_SPEED - 1;
74  ERC32_MEC.Real_Time_Clock_Counter =
75    rtems_configuration_get_microseconds_per_tick();
76  ERC32_MEC_Set_Real_Time_Clock_Timer_Control(
77      ERC32_MEC_TIMER_COUNTER_ENABLE_COUNTING |
78      ERC32_MEC_TIMER_COUNTER_LOAD_SCALER |
79      ERC32_MEC_TIMER_COUNTER_LOAD_COUNTER
80  );
81  ERC32_MEC_Set_Real_Time_Clock_Timer_Control(
82    ERC32_MEC_TIMER_COUNTER_ENABLE_COUNTING |
83    ERC32_MEC_TIMER_COUNTER_RELOAD_AT_ZERO
84  );
85
86  counter = &_SPARC_Counter_mutable;
87  counter->read_isr_disabled = _SPARC_Counter_read_clock_isr_disabled;
88  counter->read = _SPARC_Counter_read_clock;
89  counter->counter_register = &ERC32_MEC.Real_Time_Clock_Counter,
90  counter->pending_register = &ERC32_MEC.Interrupt_Pending;
91  counter->pending_mask = UINT32_C(1) << ERC32_INTERRUPT_REAL_TIME_CLOCK;
92  counter->accumulated = rtems_configuration_get_microseconds_per_tick();
93  counter->interval = rtems_configuration_get_microseconds_per_tick();
94}
95
96RTEMS_SYSINIT_ITEM(
97  erc32_clock_initialize_early,
98  RTEMS_SYSINIT_CPU_COUNTER,
99  RTEMS_SYSINIT_ORDER_FIRST
100);
101
102/*
103 *  The Real Time Clock Counter Timer uses this trap type.
104 */
105#define CLOCK_VECTOR ERC32_TRAP_TYPE( ERC32_INTERRUPT_REAL_TIME_CLOCK )
106
107#define Clock_driver_support_install_isr( _new ) \
108  set_vector( _new, CLOCK_VECTOR, 1 )
109
110#define Clock_driver_support_set_interrupt_affinity( _online_processors ) \
111  do { \
112    (void) _online_processors; \
113  } while (0)
114
115#define Clock_driver_support_at_tick() erc32_clock_at_tick()
116
117#define Clock_driver_support_initialize_hardware() erc32_clock_init()
118
119#include "../../../shared/dev/clock/clockimpl.h"
120
121SPARC_COUNTER_DEFINITION;
Note: See TracBrowser for help on using the repository browser.