1 | /* |
---|
2 | * This routine initializes the Tick Timer 2 on the MVME162 board. |
---|
3 | * The tick frequency is 1 millisecond. |
---|
4 | */ |
---|
5 | |
---|
6 | /* |
---|
7 | * COPYRIGHT (c) 1989-1999. |
---|
8 | * On-Line Applications Research Corporation (OAR). |
---|
9 | * |
---|
10 | * The license and distribution terms for this file may be |
---|
11 | * found in the file LICENSE in this distribution or at |
---|
12 | * http://www.rtems.org/license/LICENSE. |
---|
13 | * |
---|
14 | * Modifications of respective RTEMS file: COPYRIGHT (c) 1994. |
---|
15 | * EISCAT Scientific Association. M.Savitski |
---|
16 | * |
---|
17 | * This material is a part of the MVME162 Board Support Package |
---|
18 | * for the RTEMS executive. Its licensing policies are those of the |
---|
19 | * RTEMS above. |
---|
20 | */ |
---|
21 | |
---|
22 | #include <stdlib.h> |
---|
23 | |
---|
24 | #include <bsp.h> |
---|
25 | #include <rtems/clockdrv.h> |
---|
26 | |
---|
27 | #define MS_COUNT 1000 /* T2's countdown constant (1 ms) */ |
---|
28 | #define CLOCK_INT_LEVEL 6 /* T2's interrupt level */ |
---|
29 | |
---|
30 | uint32_t Clock_isrs; /* ISRs until next tick */ |
---|
31 | volatile uint32_t Clock_driver_ticks; /* ticks since initialization */ |
---|
32 | rtems_isr_entry Old_ticker; |
---|
33 | |
---|
34 | static void Clock_exit( void ); |
---|
35 | |
---|
36 | #define CLOCK_VECTOR (VBR0 * 0x10 + 0x9) |
---|
37 | |
---|
38 | /* |
---|
39 | * ISR Handler |
---|
40 | */ |
---|
41 | static rtems_isr Clock_isr(rtems_vector_number vector) |
---|
42 | { |
---|
43 | Clock_driver_ticks += 1; |
---|
44 | lcsr->timer_cnt_2 = 0; /* clear counter */ |
---|
45 | lcsr->intr_clear |= 0x02000000; |
---|
46 | |
---|
47 | if ( Clock_isrs == 1 ) { |
---|
48 | rtems_clock_tick(); |
---|
49 | Clock_isrs = rtems_configuration_get_microseconds_per_tick() / 1000; |
---|
50 | } |
---|
51 | else |
---|
52 | Clock_isrs -= 1; |
---|
53 | } |
---|
54 | |
---|
55 | static void Install_clock(rtems_isr_entry clock_isr ) |
---|
56 | { |
---|
57 | |
---|
58 | Clock_driver_ticks = 0; |
---|
59 | Clock_isrs = rtems_configuration_get_microseconds_per_tick() / 1000; |
---|
60 | |
---|
61 | Old_ticker = (rtems_isr_entry) set_vector( clock_isr, CLOCK_VECTOR, 1 ); |
---|
62 | lcsr->vector_base |= MASK_INT; /* unmask VMEchip2 interrupts */ |
---|
63 | lcsr->to_ctl = 0xE7; /* prescaler to 1 MHz (see Appendix A1) */ |
---|
64 | lcsr->timer_cmp_2 = MS_COUNT; |
---|
65 | lcsr->timer_cnt_2 = 0; /* clear counter */ |
---|
66 | lcsr->board_ctl |= 0x700; /* increment, reset-on-compare, and */ |
---|
67 | /* clear-overflow-cnt */ |
---|
68 | |
---|
69 | lcsr->intr_level[0] |= CLOCK_INT_LEVEL * 0x10; /* set int level */ |
---|
70 | lcsr->intr_ena |= 0x02000000; /* enable tick timer 2 interrupt */ |
---|
71 | |
---|
72 | atexit( Clock_exit ); |
---|
73 | } |
---|
74 | |
---|
75 | void Clock_exit( void ) |
---|
76 | { |
---|
77 | /* Dummy for now. See other m68k BSP's for code examples */ |
---|
78 | } |
---|
79 | |
---|
80 | rtems_device_driver Clock_initialize( |
---|
81 | rtems_device_major_number major, |
---|
82 | rtems_device_minor_number minor, |
---|
83 | void *pargp |
---|
84 | ) |
---|
85 | { |
---|
86 | Install_clock( Clock_isr ); |
---|
87 | |
---|
88 | return RTEMS_SUCCESSFUL; |
---|
89 | } |
---|