1 | /* Clock_init() |
---|
2 | * |
---|
3 | * |
---|
4 | * This is modified by Doug McBride to get it to work for the MC68EC040 |
---|
5 | * IDP board. The below comments are kept to show that some prior work |
---|
6 | * was done in the area and the modifications performed was application |
---|
7 | * specific for the IDP board to port it to. |
---|
8 | * |
---|
9 | * This routine initializes the mc68230 on the MC68EC040 board. |
---|
10 | * The tick frequency is 40 milliseconds. |
---|
11 | * |
---|
12 | * Input parameters: NONE |
---|
13 | * |
---|
14 | * Output parameters: NONE |
---|
15 | * |
---|
16 | * COPYRIGHT (c) 1989, 1990, 1991, 1992, 1993, 1994. |
---|
17 | * On-Line Applications Research Corporation (OAR). |
---|
18 | * All rights assigned to U.S. Government, 1994. |
---|
19 | * |
---|
20 | * This material may be reproduced by or for the U.S. Government pursuant |
---|
21 | * to the copyright license under the clause at DFARS 252.227-7013. This |
---|
22 | * notice must appear in all copies of this file and its derivatives. |
---|
23 | * |
---|
24 | * $Id$ |
---|
25 | */ |
---|
26 | |
---|
27 | #include <stdlib.h> |
---|
28 | |
---|
29 | #include "rtems.h" |
---|
30 | #include "clockdrv.h" |
---|
31 | #include "bsp.h" |
---|
32 | #include "cpu.h" |
---|
33 | |
---|
34 | rtems_unsigned32 Clock_isrs; /* ISRs until next tick */ |
---|
35 | volatile rtems_unsigned32 Clock_driver_ticks; |
---|
36 | /* ticks since initialization */ |
---|
37 | rtems_isr_entry Old_ticker; |
---|
38 | |
---|
39 | extern rtems_configuration_table Configuration; |
---|
40 | extern void led_putnum(); |
---|
41 | void Disable_clock(); |
---|
42 | |
---|
43 | #define TIMER_VECTOR 0x4D |
---|
44 | |
---|
45 | rtems_device_driver Clock_initialize( |
---|
46 | rtems_device_major_number major, |
---|
47 | rtems_device_minor_number minor, |
---|
48 | void *pargp, |
---|
49 | rtems_id tid, |
---|
50 | rtems_unsigned32 *rval |
---|
51 | ) |
---|
52 | { |
---|
53 | Install_clock( Clock_isr ); |
---|
54 | } |
---|
55 | |
---|
56 | void ReInstall_clock( clock_isr ) |
---|
57 | rtems_isr_entry clock_isr; |
---|
58 | { |
---|
59 | rtems_unsigned32 isrlevel = 0 ; |
---|
60 | |
---|
61 | rtems_interrupt_disable( isrlevel ); |
---|
62 | (void) set_vector( clock_isr, TIMER_VECTOR, 1 ); |
---|
63 | rtems_interrupt_enable( isrlevel ); |
---|
64 | } |
---|
65 | |
---|
66 | /* The following was added for debugging purposes */ |
---|
67 | void Disable_clock() |
---|
68 | { |
---|
69 | /* Disable timer */ |
---|
70 | MC68230_WRITE (TCR, 0x00); |
---|
71 | } |
---|
72 | |
---|
73 | void Install_clock( clock_isr ) |
---|
74 | rtems_isr_entry clock_isr; |
---|
75 | { |
---|
76 | Clock_driver_ticks = 0; |
---|
77 | Clock_isrs = (int)(Configuration.microseconds_per_tick / 1000); |
---|
78 | |
---|
79 | if ( Configuration.ticks_per_timeslice ) { |
---|
80 | /* led_putnum('c'); * for debugging purposes */ |
---|
81 | Old_ticker = (rtems_isr_entry) set_vector( clock_isr, TIMER_VECTOR, 1 ); |
---|
82 | |
---|
83 | /* Disable timer for initialization */ |
---|
84 | MC68230_WRITE (TCR, 0x00); |
---|
85 | |
---|
86 | /* some PI/T initialization stuff here -- see comment in the ckisr.c |
---|
87 | file in this directory to understand why I use the values that I do */ |
---|
88 | /* Set up the interrupt vector on the MC68230 chip: |
---|
89 | TIVR = TIMER_VECTOR; */ |
---|
90 | MC68230_WRITE (TIVR, TIMER_VECTOR); |
---|
91 | |
---|
92 | /* Set CPRH through CPRL to 193 (not 203) decimal for countdown--see ckisr.c |
---|
93 | CPRH = 0x00; |
---|
94 | CPRM = 0x00; |
---|
95 | CPRL = 0xC1; */ |
---|
96 | MC68230_WRITE (CPRH, 0x00); |
---|
97 | MC68230_WRITE (CPRM, 0x00); |
---|
98 | MC68230_WRITE (CPRL, 0xC1); |
---|
99 | |
---|
100 | /* Enable timer and use it as an external periodic interrupt generator |
---|
101 | TCR = 0xA1; */ |
---|
102 | /* led_putnum('a'); * for debugging purposes */ |
---|
103 | MC68230_WRITE (TCR, 0xA1); |
---|
104 | |
---|
105 | /* |
---|
106 | * Schedule the clock cleanup routine to execute if the application exits. |
---|
107 | */ |
---|
108 | atexit( Clock_exit ); |
---|
109 | } |
---|
110 | } |
---|
111 | |
---|
112 | void Clock_exit( void ) |
---|
113 | { |
---|
114 | rtems_unsigned8 data; |
---|
115 | |
---|
116 | if ( Configuration.ticks_per_timeslice ) { |
---|
117 | |
---|
118 | /* disable timer |
---|
119 | data = TCR; |
---|
120 | TCR = (data & 0xFE); */ |
---|
121 | MC68230_READ (TCR, data); |
---|
122 | MC68230_WRITE (TCR, (data & 0xFE)); |
---|
123 | |
---|
124 | /* do not restore old vector */ |
---|
125 | } |
---|
126 | } |
---|