1 | /* Clock_init() |
---|
2 | * |
---|
3 | * This routine initailizes the periodic interrupt timer on |
---|
4 | * the Motorola 68332. |
---|
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.org/license/LICENSE. |
---|
16 | */ |
---|
17 | |
---|
18 | #include <stdlib.h> |
---|
19 | #include <bsp.h> |
---|
20 | #include <mrm332.h> |
---|
21 | |
---|
22 | #define CLOCK_VECTOR MRM_PIV |
---|
23 | |
---|
24 | uint32_t Clock_isrs; /* ISRs until next tick */ |
---|
25 | volatile uint32_t Clock_driver_ticks; |
---|
26 | /* ticks since initialization */ |
---|
27 | rtems_isr_entry Old_ticker; |
---|
28 | |
---|
29 | void Clock_exit( void ); |
---|
30 | |
---|
31 | /* |
---|
32 | * These are set by clock driver during its init |
---|
33 | */ |
---|
34 | |
---|
35 | rtems_device_major_number rtems_clock_major = ~0; |
---|
36 | rtems_device_minor_number rtems_clock_minor; |
---|
37 | |
---|
38 | rtems_isr Clock_isr(rtems_vector_number vector) |
---|
39 | { |
---|
40 | Clock_driver_ticks += 1; |
---|
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 | void Install_clock( |
---|
51 | rtems_isr_entry clock_isr |
---|
52 | ) |
---|
53 | { |
---|
54 | Clock_driver_ticks = 0; |
---|
55 | Clock_isrs = rtems_configuration_get_microseconds_per_tick() / 1000; |
---|
56 | |
---|
57 | Old_ticker = (rtems_isr_entry) set_vector( clock_isr, CLOCK_VECTOR, 1 ); |
---|
58 | |
---|
59 | /* enable 1mS interrupts */ |
---|
60 | *PITR = (unsigned short int)( SAM(0x09,0,PITM) );/* load counter */ |
---|
61 | *PICR = (unsigned short int) /* enable interrupt */ |
---|
62 | ( SAM(ISRL_PIT,8,PIRQL) | SAM(CLOCK_VECTOR,0,PIV) ); |
---|
63 | |
---|
64 | atexit( Clock_exit ); |
---|
65 | } |
---|
66 | |
---|
67 | void Clock_exit( void ) |
---|
68 | { |
---|
69 | /* shutdown the periodic interrupt */ |
---|
70 | *PICR = (unsigned short int) |
---|
71 | ( SAM(0,8,PIRQL) | SAM(CLOCK_VECTOR,0,PIV) ); |
---|
72 | /* ^^ zero disables interrupt */ |
---|
73 | |
---|
74 | /* do not restore old vector */ |
---|
75 | } |
---|
76 | |
---|
77 | rtems_device_driver Clock_initialize( |
---|
78 | rtems_device_major_number major, |
---|
79 | rtems_device_minor_number minor, |
---|
80 | void *pargp |
---|
81 | ) |
---|
82 | { |
---|
83 | Install_clock( Clock_isr ); |
---|
84 | |
---|
85 | /* |
---|
86 | * make major/minor avail to others such as shared memory driver |
---|
87 | */ |
---|
88 | |
---|
89 | rtems_clock_major = major; |
---|
90 | rtems_clock_minor = minor; |
---|
91 | |
---|
92 | return RTEMS_SUCCESSFUL; |
---|
93 | } |
---|