source: rtems/c/src/lib/libbsp/sparc/erc32/clock/ckinit.c @ 75acd9e

4.115
Last change on this file since 75acd9e was 75acd9e, checked in by Alexander Krutwig <alexander.krutwig@…>, on 04/01/15 at 13:33:25

bsps: Convert clock drivers to use a timecounter

Update #2271.

  • 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/counter.h>
28#include <rtems/timecounter.h>
29
30#if SIMSPARC_FAST_IDLE==1
31#define CLOCK_DRIVER_USE_FAST_IDLE 1
32#endif
33
34/*
35 *  The Real Time Clock Counter Timer uses this trap type.
36 */
37#define CLOCK_VECTOR ERC32_TRAP_TYPE( ERC32_INTERRUPT_REAL_TIME_CLOCK )
38
39#define Clock_driver_support_at_tick()
40
41#define Clock_driver_support_install_isr( _new, _old ) \
42  do { \
43    _old = set_vector( _new, CLOCK_VECTOR, 1 ); \
44  } while(0)
45
46extern int CLOCK_SPEED;
47
48static rtems_timecounter_simple erc32_tc;
49
50static uint32_t erc32_tc_get( rtems_timecounter_simple *tc )
51{
52  return ERC32_MEC.Real_Time_Clock_Counter;
53}
54
55static bool erc32_tc_is_pending( rtems_timecounter_simple *tc )
56{
57  return ERC32_Is_interrupt_pending( ERC32_INTERRUPT_REAL_TIME_CLOCK );
58}
59
60static uint32_t erc32_tc_get_timecount( struct timecounter *tc )
61{
62  return rtems_timecounter_simple_downcounter_get(
63    tc,
64    erc32_tc_get,
65    erc32_tc_is_pending
66  );
67}
68
69static void erc32_tc_tick( void )
70{
71  rtems_timecounter_simple_downcounter_tick(
72    &erc32_tc,
73    erc32_tc_get
74  );
75}
76
77static CPU_Counter_ticks erc32_counter_difference(
78  CPU_Counter_ticks second,
79  CPU_Counter_ticks first
80)
81{
82  CPU_Counter_ticks period = rtems_configuration_get_microseconds_per_tick();
83
84  return (first + period - second) % period;
85}
86
87#define Clock_driver_support_initialize_hardware() \
88  do { \
89    uint32_t frequency = 1000000; \
90    /* approximately 1 us per countdown */ \
91    ERC32_MEC.Real_Time_Clock_Scalar  = CLOCK_SPEED - 1; \
92    ERC32_MEC.Real_Time_Clock_Counter = \
93      rtems_configuration_get_microseconds_per_tick(); \
94    \
95    ERC32_MEC_Set_Real_Time_Clock_Timer_Control( \
96        ERC32_MEC_TIMER_COUNTER_ENABLE_COUNTING | \
97        ERC32_MEC_TIMER_COUNTER_LOAD_SCALER | \
98        ERC32_MEC_TIMER_COUNTER_LOAD_COUNTER \
99    ); \
100    \
101    ERC32_MEC_Set_Real_Time_Clock_Timer_Control( \
102        ERC32_MEC_TIMER_COUNTER_ENABLE_COUNTING | \
103        ERC32_MEC_TIMER_COUNTER_RELOAD_AT_ZERO \
104    );  \
105    rtems_timecounter_simple_install( \
106        &erc32_tc, \
107        frequency, \
108        rtems_configuration_get_microseconds_per_tick(), \
109        erc32_tc_get_timecount \
110    ); \
111    _SPARC_Counter_initialize( \
112      &ERC32_MEC.Real_Time_Clock_Counter, \
113      erc32_counter_difference \
114    ); \
115    rtems_counter_initialize_converter( frequency ); \
116  } while (0)
117
118#define Clock_driver_timecounter_tick() erc32_tc_tick()
119
120#define Clock_driver_support_shutdown_hardware() \
121  do { \
122    ERC32_Mask_interrupt( ERC32_INTERRUPT_REAL_TIME_CLOCK ); \
123     \
124    ERC32_MEC_Set_Real_Time_Clock_Timer_Control( \
125      ERC32_MEC_TIMER_COUNTER_DISABLE_COUNTING \
126    ); \
127  } while (0)
128
129#include "../../../shared/clockdrv_shell.h"
130
Note: See TracBrowser for help on using the repository browser.