1 | /* |
---|
2 | * This routine initializes the MC68360 Periodic Interval Timer |
---|
3 | * |
---|
4 | * The PIT has rather poor resolution, but it is easy to set up |
---|
5 | * and requires no housekeeping once it is going. |
---|
6 | * |
---|
7 | * W. Eric Norum |
---|
8 | * Saskatchewan Accelerator Laboratory |
---|
9 | * University of Saskatchewan |
---|
10 | * Saskatoon, Saskatchewan, CANADA |
---|
11 | * eric@skatter.usask.ca |
---|
12 | */ |
---|
13 | |
---|
14 | #include <rtems.h> |
---|
15 | #include <bsp.h> |
---|
16 | #include <rtems/m68k/m68360.h> |
---|
17 | |
---|
18 | #define CLOCK_VECTOR 120 |
---|
19 | #define CLOCK_IRQ_LEVEL 4 |
---|
20 | |
---|
21 | char M360DefaultWatchdogFeeder = 1; |
---|
22 | |
---|
23 | /* |
---|
24 | * RTEMS and hardware have different notions of clock rate. |
---|
25 | */ |
---|
26 | static unsigned long rtems_nsec_per_tick; |
---|
27 | static unsigned long pit_nsec_per_tick; |
---|
28 | static unsigned long nsec; |
---|
29 | |
---|
30 | /* |
---|
31 | * Periodic interval timer interrupt handler |
---|
32 | * See if it's really time for a `tick' |
---|
33 | * Perform a dummy read of DPRAM (work around bug in Rev. B of the 68360). |
---|
34 | * Feed the watchdog |
---|
35 | * Application code can override this by |
---|
36 | * setting M360DefaultWatchdogFeeder to zero. |
---|
37 | */ |
---|
38 | #define Clock_driver_support_at_tick() \ |
---|
39 | do { \ |
---|
40 | nsec += pit_nsec_per_tick; \ |
---|
41 | if (nsec >= rtems_nsec_per_tick) \ |
---|
42 | return; \ |
---|
43 | nsec -= rtems_nsec_per_tick; \ |
---|
44 | m360.dpram0[0]; \ |
---|
45 | if (M360DefaultWatchdogFeeder) { \ |
---|
46 | m360.swsr = 0x55; \ |
---|
47 | m360.swsr = 0xAA; \ |
---|
48 | } \ |
---|
49 | } while (0) \ |
---|
50 | |
---|
51 | /* |
---|
52 | * Attach clock interrupt handler |
---|
53 | */ |
---|
54 | #define Clock_driver_support_install_isr( _new ) \ |
---|
55 | set_vector(_new, CLOCK_VECTOR, 1) |
---|
56 | |
---|
57 | /* |
---|
58 | * Turn off the clock |
---|
59 | */ |
---|
60 | #define Clock_driver_support_shutdown_hardware() \ |
---|
61 | do { \ |
---|
62 | m360.pitr &= ~0xFF; \ |
---|
63 | } while(0) |
---|
64 | |
---|
65 | /* |
---|
66 | * Set up the clock hardware |
---|
67 | * The rate at which the periodic interval timer |
---|
68 | * can generate interrupts is almost certainly not |
---|
69 | * the same as desired by the BSP configuration. |
---|
70 | * Handle the difference by choosing the largest PIT |
---|
71 | * interval which is less than or equal to the RTEMS |
---|
72 | * interval and skipping some hardware interrupts. |
---|
73 | * To reduce the jitter in the calls to RTEMS the |
---|
74 | * hardware interrupt interval is never greater than |
---|
75 | * the maximum non-prescaled value from the PIT. |
---|
76 | * |
---|
77 | * For a 25 MHz external clock the basic clock rate is |
---|
78 | * 40 nsec * 128 * 4 = 20.48 usec/tick |
---|
79 | */ |
---|
80 | extern int m360_clock_rate; |
---|
81 | |
---|
82 | #define Clock_driver_support_initialize_hardware() \ |
---|
83 | do { \ |
---|
84 | unsigned int divisor; \ |
---|
85 | unsigned long nsec_per_chip_tick = 1000000000 / m360_clock_rate; \ |
---|
86 | unsigned long nsec_per_pit_tick = 512 * nsec_per_chip_tick; \ |
---|
87 | rtems_nsec_per_tick = rtems_configuration_get_microseconds_per_tick() * 1000; \ |
---|
88 | divisor = rtems_nsec_per_tick / nsec_per_pit_tick; \ |
---|
89 | if (divisor > 255) \ |
---|
90 | divisor = 255; \ |
---|
91 | else if (divisor == 0) \ |
---|
92 | divisor = 1; \ |
---|
93 | pit_nsec_per_tick = nsec_per_pit_tick * divisor; \ |
---|
94 | m360.pitr &= ~0x1FF; \ |
---|
95 | m360.picr = (CLOCK_IRQ_LEVEL << 8) | CLOCK_VECTOR; \ |
---|
96 | m360.pitr |= divisor; \ |
---|
97 | } while (0) |
---|
98 | |
---|
99 | #define CLOCK_DRIVER_USE_DUMMY_TIMECOUNTER |
---|
100 | |
---|
101 | #include "../../../shared/dev/clock/clockimpl.h" |
---|