1 | /* |
---|
2 | * Clock Tick Device Driver |
---|
3 | * |
---|
4 | * This routine initializes LEON timer 1 which used for the clock tick. |
---|
5 | * |
---|
6 | * The tick frequency is directly programmed to the configured number of |
---|
7 | * microseconds per tick. |
---|
8 | * |
---|
9 | * COPYRIGHT (c) 1989-2008. |
---|
10 | * On-Line Applications Research Corporation (OAR). |
---|
11 | * |
---|
12 | * Modified for LEON BSP |
---|
13 | * COPYRIGHT (c) 2004. |
---|
14 | * Gaisler Research. |
---|
15 | * |
---|
16 | * The license and distribution terms for this file may be |
---|
17 | * found in the file LICENSE in this distribution or at |
---|
18 | * http://www.rtems.com/license/LICENSE. |
---|
19 | */ |
---|
20 | |
---|
21 | #include <bsp.h> |
---|
22 | #include <bspopts.h> |
---|
23 | |
---|
24 | #if SIMSPARC_FAST_IDLE==1 |
---|
25 | #define CLOCK_DRIVER_USE_FAST_IDLE 1 |
---|
26 | #endif |
---|
27 | |
---|
28 | /* |
---|
29 | * The Real Time Clock Counter Timer uses this trap type. |
---|
30 | */ |
---|
31 | |
---|
32 | #define CLOCK_VECTOR LEON_TRAP_TYPE( LEON_INTERRUPT_TIMER1 ) |
---|
33 | |
---|
34 | #define Clock_driver_support_at_tick() |
---|
35 | |
---|
36 | #define Clock_driver_support_install_isr( _new, _old ) \ |
---|
37 | do { \ |
---|
38 | _old = set_vector( _new, CLOCK_VECTOR, 1 ); \ |
---|
39 | } while(0) |
---|
40 | |
---|
41 | extern int CLOCK_SPEED; |
---|
42 | |
---|
43 | #define Clock_driver_support_initialize_hardware() \ |
---|
44 | do { \ |
---|
45 | LEON_REG.Timer_Reload_1 = rtems_configuration_get_microseconds_per_tick() - 1; \ |
---|
46 | \ |
---|
47 | LEON_REG.Timer_Control_1 = ( \ |
---|
48 | LEON_REG_TIMER_COUNTER_ENABLE_COUNTING | \ |
---|
49 | LEON_REG_TIMER_COUNTER_RELOAD_AT_ZERO | \ |
---|
50 | LEON_REG_TIMER_COUNTER_LOAD_COUNTER \ |
---|
51 | ); \ |
---|
52 | } while (0) |
---|
53 | |
---|
54 | #define Clock_driver_support_shutdown_hardware() \ |
---|
55 | do { \ |
---|
56 | LEON_Mask_interrupt( LEON_INTERRUPT_TIMER1 ); \ |
---|
57 | LEON_REG.Timer_Control_1 = 0; \ |
---|
58 | } while (0) |
---|
59 | |
---|
60 | uint32_t bsp_clock_nanoseconds_since_last_tick(void) |
---|
61 | { |
---|
62 | uint32_t clicks; |
---|
63 | uint32_t usecs; |
---|
64 | |
---|
65 | clicks = LEON_REG.Timer_Counter_1; |
---|
66 | |
---|
67 | if ( LEON_Is_interrupt_pending( LEON_INTERRUPT_TIMER1 ) ) { |
---|
68 | clicks = LEON_REG.Timer_Counter_1; |
---|
69 | usecs = (2*rtems_configuration_get_microseconds_per_tick() - clicks); |
---|
70 | } else { |
---|
71 | usecs = (rtems_configuration_get_microseconds_per_tick() - clicks); |
---|
72 | } |
---|
73 | return usecs * 1000; |
---|
74 | } |
---|
75 | |
---|
76 | #define Clock_driver_nanoseconds_since_last_tick bsp_clock_nanoseconds_since_last_tick |
---|
77 | |
---|
78 | #include "../../../shared/clockdrv_shell.h" |
---|