1 | /* |
---|
2 | * This routine initializes the Tick Timer 2 on the MVME147 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 | * MVME147 port for TNI - Telecom Bretagne |
---|
15 | * by Dominique LE CAMPION (Dominique.LECAMPION@enst-bretagne.fr) |
---|
16 | * May 1996 |
---|
17 | */ |
---|
18 | |
---|
19 | #include <stdlib.h> |
---|
20 | |
---|
21 | #include <bsp.h> |
---|
22 | #include <rtems/clockdrv.h> |
---|
23 | |
---|
24 | #define MS_COUNT 65376 /* 1ms */ |
---|
25 | /* MS_COUNT = 0x10000 - 1e-3/6.25e-6 */ |
---|
26 | #define CLOCK_INT_LEVEL 6 /* T2's interrupt level */ |
---|
27 | |
---|
28 | uint32_t Clock_isrs; /* ISRs until next tick */ |
---|
29 | volatile uint32_t Clock_driver_ticks; /* ticks since initialization */ |
---|
30 | rtems_isr_entry Old_ticker; |
---|
31 | |
---|
32 | void Clock_exit( void ); |
---|
33 | |
---|
34 | /* |
---|
35 | * ISR Handler |
---|
36 | */ |
---|
37 | static rtems_isr Clock_isr(rtems_vector_number vector) |
---|
38 | { |
---|
39 | Clock_driver_ticks += 1; |
---|
40 | pcc->timer2_int_control |= 0x80; /* Acknowledge interr. */ |
---|
41 | |
---|
42 | if (Clock_isrs == 1) { |
---|
43 | rtems_clock_tick(); |
---|
44 | Clock_isrs = rtems_configuration_get_microseconds_per_tick() / 1000; |
---|
45 | } |
---|
46 | else |
---|
47 | Clock_isrs -= 1; |
---|
48 | } |
---|
49 | |
---|
50 | static void Install_clock(rtems_isr_entry clock_isr ) |
---|
51 | { |
---|
52 | |
---|
53 | Clock_driver_ticks = 0; |
---|
54 | Clock_isrs = rtems_configuration_get_microseconds_per_tick() / 1000; |
---|
55 | |
---|
56 | Old_ticker = (rtems_isr_entry) set_vector( clock_isr, TIMER_2_VECTOR, 1 ); |
---|
57 | |
---|
58 | pcc->timer2_int_control = 0x00; /* Disable T2 Interr. */ |
---|
59 | pcc->timer2_preload = MS_COUNT; |
---|
60 | /* write preload value */ |
---|
61 | pcc->timer2_control = 0x07; /* clear T2 overflow counter, enable counter */ |
---|
62 | pcc->timer2_int_control = CLOCK_INT_LEVEL|0x08; |
---|
63 | /* Enable Timer 2 and set its int. level */ |
---|
64 | |
---|
65 | atexit( Clock_exit ); |
---|
66 | } |
---|
67 | |
---|
68 | void Clock_exit( void ) |
---|
69 | { |
---|
70 | pcc->timer2_int_control = 0x00; /* Disable T2 Interr. */ |
---|
71 | } |
---|
72 | |
---|
73 | rtems_device_driver Clock_initialize( |
---|
74 | rtems_device_major_number major, |
---|
75 | rtems_device_minor_number minor, |
---|
76 | void *pargp |
---|
77 | ) |
---|
78 | { |
---|
79 | Install_clock( Clock_isr ); |
---|
80 | |
---|
81 | return RTEMS_SUCCESSFUL; |
---|
82 | } |
---|