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 | |
---|
28 | #if SIMSPARC_FAST_IDLE==1 |
---|
29 | #define CLOCK_DRIVER_USE_FAST_IDLE 1 |
---|
30 | #endif |
---|
31 | |
---|
32 | /* |
---|
33 | * The Real Time Clock Counter Timer uses this trap type. |
---|
34 | */ |
---|
35 | |
---|
36 | #define CLOCK_VECTOR LEON_TRAP_TYPE( LEON_INTERRUPT_TIMER1 ) |
---|
37 | |
---|
38 | #define Clock_driver_support_at_tick() |
---|
39 | |
---|
40 | #define Clock_driver_support_install_isr( _new, _old ) \ |
---|
41 | do { \ |
---|
42 | _old = set_vector( _new, CLOCK_VECTOR, 1 ); \ |
---|
43 | } while(0) |
---|
44 | |
---|
45 | extern int CLOCK_SPEED; |
---|
46 | |
---|
47 | #define Clock_driver_support_initialize_hardware() \ |
---|
48 | do { \ |
---|
49 | LEON_REG.Timer_Reload_1 = \ |
---|
50 | rtems_configuration_get_microseconds_per_tick() - 1; \ |
---|
51 | \ |
---|
52 | LEON_REG.Timer_Control_1 = ( \ |
---|
53 | LEON_REG_TIMER_COUNTER_ENABLE_COUNTING | \ |
---|
54 | LEON_REG_TIMER_COUNTER_RELOAD_AT_ZERO | \ |
---|
55 | LEON_REG_TIMER_COUNTER_LOAD_COUNTER \ |
---|
56 | ); \ |
---|
57 | } while (0) |
---|
58 | |
---|
59 | #define Clock_driver_support_shutdown_hardware() \ |
---|
60 | do { \ |
---|
61 | LEON_Mask_interrupt( LEON_INTERRUPT_TIMER1 ); \ |
---|
62 | LEON_REG.Timer_Control_1 = 0; \ |
---|
63 | } while (0) |
---|
64 | |
---|
65 | static uint32_t bsp_clock_nanoseconds_since_last_tick(void) |
---|
66 | { |
---|
67 | uint32_t clicks; |
---|
68 | uint32_t usecs; |
---|
69 | |
---|
70 | clicks = LEON_REG.Timer_Counter_1; |
---|
71 | |
---|
72 | if ( LEON_Is_interrupt_pending( LEON_INTERRUPT_TIMER1 ) ) { |
---|
73 | clicks = LEON_REG.Timer_Counter_1; |
---|
74 | usecs = (2*rtems_configuration_get_microseconds_per_tick() - clicks); |
---|
75 | } else { |
---|
76 | usecs = (rtems_configuration_get_microseconds_per_tick() - clicks); |
---|
77 | } |
---|
78 | return usecs * 1000; |
---|
79 | } |
---|
80 | |
---|
81 | #define Clock_driver_nanoseconds_since_last_tick \ |
---|
82 | bsp_clock_nanoseconds_since_last_tick |
---|
83 | |
---|
84 | #include "../../../shared/clockdrv_shell.h" |
---|