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 | #include <rtems/score/sparcimpl.h> |
---|
30 | |
---|
31 | /* |
---|
32 | * The Real Time Clock Counter Timer uses this trap type. |
---|
33 | */ |
---|
34 | #define CLOCK_VECTOR ERC32_TRAP_TYPE( ERC32_INTERRUPT_REAL_TIME_CLOCK ) |
---|
35 | |
---|
36 | #define Clock_driver_support_install_isr( _new ) \ |
---|
37 | set_vector( _new, CLOCK_VECTOR, 1 ) |
---|
38 | |
---|
39 | #define Clock_driver_support_set_interrupt_affinity( _online_processors ) \ |
---|
40 | do { \ |
---|
41 | (void) _online_processors; \ |
---|
42 | } while (0) |
---|
43 | |
---|
44 | extern int CLOCK_SPEED; |
---|
45 | |
---|
46 | static rtems_timecounter_simple erc32_tc; |
---|
47 | |
---|
48 | static uint32_t erc32_tc_get( rtems_timecounter_simple *tc ) |
---|
49 | { |
---|
50 | return ERC32_MEC.Real_Time_Clock_Counter; |
---|
51 | } |
---|
52 | |
---|
53 | static bool erc32_tc_is_pending( rtems_timecounter_simple *tc ) |
---|
54 | { |
---|
55 | return ERC32_Is_interrupt_pending( ERC32_INTERRUPT_REAL_TIME_CLOCK ); |
---|
56 | } |
---|
57 | |
---|
58 | static 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 | |
---|
67 | static void erc32_tc_at_tick( rtems_timecounter_simple *tc ) |
---|
68 | { |
---|
69 | /* Nothing to do */ |
---|
70 | } |
---|
71 | |
---|
72 | static 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 | |
---|
81 | static void erc32_counter_initialize( uint32_t frequency ) |
---|
82 | { |
---|
83 | _SPARC_Counter_initialize( |
---|
84 | _SPARC_Counter_read_address, |
---|
85 | _SPARC_Counter_difference_clock_period, |
---|
86 | &ERC32_MEC.Real_Time_Clock_Counter |
---|
87 | ); |
---|
88 | rtems_counter_initialize_converter( frequency ); |
---|
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 | erc32_counter_initialize( 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/dev/clock/clockimpl.h" |
---|
130 | |
---|
131 | SPARC_COUNTER_DEFINITION; |
---|