source: rtems/c/src/lib/libbsp/sparc/erc32/clock/ckinit.c @ 76ac1ee3

5
Last change on this file since 76ac1ee3 was 76ac1ee3, checked in by Sebastian Huber <sebastian.huber@…>, on 12/23/15 at 06:29:47

score: Fix simple timecounter support

Update #2502.

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