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 | static rtems_timecounter_simple leon2_tc; |
---|
31 | |
---|
32 | static uint32_t leon2_tc_get( rtems_timecounter_simple *tc ) |
---|
33 | { |
---|
34 | return LEON_REG.Timer_Counter_1; |
---|
35 | } |
---|
36 | |
---|
37 | static bool leon2_tc_is_pending( rtems_timecounter_simple *tc ) |
---|
38 | { |
---|
39 | return LEON_Is_interrupt_pending( LEON_INTERRUPT_TIMER1 ); |
---|
40 | } |
---|
41 | |
---|
42 | static uint32_t leon2_tc_get_timecount( struct timecounter *tc ) |
---|
43 | { |
---|
44 | return rtems_timecounter_simple_downcounter_get( |
---|
45 | tc, |
---|
46 | leon2_tc_get, |
---|
47 | leon2_tc_is_pending |
---|
48 | ); |
---|
49 | } |
---|
50 | |
---|
51 | static void leon2_tc_at_tick( rtems_timecounter_simple *tc ) |
---|
52 | { |
---|
53 | /* Nothing to do */ |
---|
54 | } |
---|
55 | |
---|
56 | static void leon2_tc_tick( void ) |
---|
57 | { |
---|
58 | rtems_timecounter_simple_downcounter_tick( |
---|
59 | &leon2_tc, |
---|
60 | leon2_tc_get, |
---|
61 | leon2_tc_at_tick |
---|
62 | ); |
---|
63 | } |
---|
64 | |
---|
65 | /* |
---|
66 | * The Real Time Clock Counter Timer uses this trap type. |
---|
67 | */ |
---|
68 | |
---|
69 | #define CLOCK_VECTOR LEON_TRAP_TYPE( LEON_INTERRUPT_TIMER1 ) |
---|
70 | |
---|
71 | #define Clock_driver_support_install_isr( _new ) \ |
---|
72 | set_vector( _new, CLOCK_VECTOR, 1 ) |
---|
73 | |
---|
74 | extern int CLOCK_SPEED; |
---|
75 | |
---|
76 | #define Clock_driver_support_initialize_hardware() \ |
---|
77 | do { \ |
---|
78 | LEON_REG.Timer_Reload_1 = \ |
---|
79 | rtems_configuration_get_microseconds_per_tick() - 1; \ |
---|
80 | \ |
---|
81 | LEON_REG.Timer_Control_1 = ( \ |
---|
82 | LEON_REG_TIMER_COUNTER_ENABLE_COUNTING | \ |
---|
83 | LEON_REG_TIMER_COUNTER_RELOAD_AT_ZERO | \ |
---|
84 | LEON_REG_TIMER_COUNTER_LOAD_COUNTER \ |
---|
85 | ); \ |
---|
86 | rtems_timecounter_simple_install( \ |
---|
87 | &leon2_tc, \ |
---|
88 | 1000000, \ |
---|
89 | rtems_configuration_get_microseconds_per_tick(), \ |
---|
90 | leon2_tc_get_timecount \ |
---|
91 | ); \ |
---|
92 | } while (0) |
---|
93 | |
---|
94 | #define Clock_driver_support_shutdown_hardware() \ |
---|
95 | do { \ |
---|
96 | LEON_Mask_interrupt( LEON_INTERRUPT_TIMER1 ); \ |
---|
97 | LEON_REG.Timer_Control_1 = 0; \ |
---|
98 | } while (0) |
---|
99 | |
---|
100 | #define Clock_driver_timecounter_tick() leon2_tc_tick() |
---|
101 | |
---|
102 | #include "../../../shared/clockdrv_shell.h" |
---|
103 | |
---|
104 | SPARC_COUNTER_DEFINITION; |
---|