1 | /* Clock_init() |
---|
2 | * |
---|
3 | * This routine initializes the Tick Timer 2 on the MVME147 board. |
---|
4 | * The tick frequency is 1 millisecond. |
---|
5 | * |
---|
6 | * Input parameters: NONE |
---|
7 | * |
---|
8 | * Output parameters: NONE |
---|
9 | * |
---|
10 | * COPYRIGHT (c) 1989-1999. |
---|
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.com/license/LICENSE. |
---|
16 | * |
---|
17 | * MVME147 port for TNI - Telecom Bretagne |
---|
18 | * by Dominique LE CAMPION (Dominique.LECAMPION@enst-bretagne.fr) |
---|
19 | * May 1996 |
---|
20 | * |
---|
21 | * $Id$ |
---|
22 | */ |
---|
23 | |
---|
24 | #include <stdlib.h> |
---|
25 | |
---|
26 | #include <bsp.h> |
---|
27 | #include <rtems/libio.h> |
---|
28 | |
---|
29 | #define MS_COUNT 65376 /* 1ms */ |
---|
30 | /* MS_COUNT = 0x10000 - 1e-3/6.25e-6 */ |
---|
31 | #define CLOCK_INT_LEVEL 6 /* T2's interrupt level */ |
---|
32 | |
---|
33 | uint32_t Clock_isrs; /* ISRs until next tick */ |
---|
34 | volatile uint32_t Clock_driver_ticks; /* ticks since initialization */ |
---|
35 | rtems_isr_entry Old_ticker; |
---|
36 | |
---|
37 | void Clock_exit( void ); |
---|
38 | |
---|
39 | /* |
---|
40 | * These are set by clock driver during its init |
---|
41 | */ |
---|
42 | |
---|
43 | rtems_device_major_number rtems_clock_major = ~0; |
---|
44 | rtems_device_minor_number rtems_clock_minor; |
---|
45 | |
---|
46 | /* |
---|
47 | * ISR Handler |
---|
48 | */ |
---|
49 | |
---|
50 | rtems_isr Clock_isr(rtems_vector_number vector) |
---|
51 | { |
---|
52 | Clock_driver_ticks += 1; |
---|
53 | pcc->timer2_int_control |= 0x80; /* Acknowledge interr. */ |
---|
54 | |
---|
55 | if (Clock_isrs == 1) { |
---|
56 | rtems_clock_tick(); |
---|
57 | Clock_isrs = rtems_configuration_get_microseconds_per_tick() / 1000; |
---|
58 | } |
---|
59 | else |
---|
60 | Clock_isrs -= 1; |
---|
61 | } |
---|
62 | |
---|
63 | void Install_clock(rtems_isr_entry clock_isr ) |
---|
64 | { |
---|
65 | |
---|
66 | Clock_driver_ticks = 0; |
---|
67 | Clock_isrs = rtems_configuration_get_microseconds_per_tick() / 1000; |
---|
68 | |
---|
69 | Old_ticker = (rtems_isr_entry) set_vector( clock_isr, TIMER_2_VECTOR, 1 ); |
---|
70 | |
---|
71 | pcc->timer2_int_control = 0x00; /* Disable T2 Interr. */ |
---|
72 | pcc->timer2_preload = MS_COUNT; |
---|
73 | /* write preload value */ |
---|
74 | pcc->timer2_control = 0x07; /* clear T2 overflow counter, enable counter */ |
---|
75 | pcc->timer2_int_control = CLOCK_INT_LEVEL|0x08; |
---|
76 | /* Enable Timer 2 and set its int. level */ |
---|
77 | |
---|
78 | atexit( Clock_exit ); |
---|
79 | } |
---|
80 | |
---|
81 | void Clock_exit( void ) |
---|
82 | { |
---|
83 | pcc->timer2_int_control = 0x00; /* Disable T2 Interr. */ |
---|
84 | } |
---|
85 | |
---|
86 | rtems_device_driver Clock_initialize( |
---|
87 | rtems_device_major_number major, |
---|
88 | rtems_device_minor_number minor, |
---|
89 | void *pargp |
---|
90 | ) |
---|
91 | { |
---|
92 | Install_clock( Clock_isr ); |
---|
93 | |
---|
94 | /* |
---|
95 | * make major/minor avail to others such as shared memory driver |
---|
96 | */ |
---|
97 | |
---|
98 | rtems_clock_major = major; |
---|
99 | rtems_clock_minor = minor; |
---|
100 | |
---|
101 | return RTEMS_SUCCESSFUL; |
---|
102 | } |
---|