source: rtems/c/src/lib/libbsp/m68k/gen68360/clock/clock.c @ b04a2b3

4.104.114.84.95
Last change on this file since b04a2b3 was c2a4084f, checked in by Joel Sherrill <joel.sherrill@…>, on 01/12/01 at 15:00:54

2001-01-12 Eric Norum <eric.norum@…>

  • README, clock/Makefile.am, clock/ckinit.c, clock/clock.c: Clock driver updated to use shell driver mechanism.
  • clock/ckinit.c: Removed.
  • clock/clock.c: New file.
  • Property mode set to 100644
File size: 3.8 KB
Line 
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 *  $Id$
14 */
15
16#include <rtems.h>
17#include <bsp.h>
18#include "m68360.h"
19
20#define CLOCK_VECTOR     120
21#define CLOCK_IRQ_LEVEL    4
22
23char M360DefaultWatchdogFeeder = 1;
24
25/*
26 * RTEMS and hardware have different notions of clock rate.
27 */
28static unsigned long rtems_nsec_per_tick;
29static unsigned long pit_nsec_per_tick;
30static unsigned long nsec;
31
32/*
33 * Periodic interval timer interrupt handler
34 *    See if it's really time for a `tick'
35 *    Perform a dummy read of DPRAM (work around bug in Rev. B of the 68360).
36 *    Feed the watchdog
37 *        Application code can override this by
38 *        setting M360DefaultWatchdogFeeder to zero.
39 */
40#define Clock_driver_support_at_tick()  \
41    do {                                   \
42        nsec += pit_nsec_per_tick;         \
43        if (nsec >= rtems_nsec_per_tick)   \
44            return;                        \
45        nsec -= rtems_nsec_per_tick;       \
46        m360.dpram0[0];                    \
47        if (M360DefaultWatchdogFeeder) {   \
48            m360.swsr = 0x55;              \
49            m360.swsr = 0xAA;              \
50        }                                  \
51    } while (0)                            \
52
53/*
54 * Attach clock interrupt handler
55 */
56#define Clock_driver_support_install_isr( _new, _old ) \
57    do {                                                          \
58        _old = (rtems_isr_entry)set_vector(_new, CLOCK_VECTOR, 1);  \
59    } while(0)
60
61/*
62 * Turn off the clock
63 */
64#define Clock_driver_support_shutdown_hardware() \
65    do {                       \
66        m360.pitr &= ~0xFF;    \
67    } while(0)
68
69/*
70 * Set up the clock hardware
71 *     The rate at which the periodic interval timer
72 *     can generate interrupts is almost certainly not
73 *     the same as desired by the BSP configuration.
74 *     Handle the difference by choosing the largest PIT
75 *     interval which is less than or equal to the RTEMS
76 *     interval and skipping some hardware interrupts.
77 *     To reduce the jitter in the calls to RTEMS the
78 *     hardware interrupt interval is never greater than
79 *     the maximum non-prescaled value from the PIT.
80 *
81 *     For a 25 MHz external clock the basic clock rate is
82 *        40 nsec * 128 * 4 = 20.48 usec/tick
83 */
84#define Clock_driver_support_initialize_hardware() \
85    do {                                                                      \
86        unsigned int divisor;                                                 \
87        extern int m360_clock_rate;                                           \
88        unsigned long nsec_per_chip_tick = 1000000000 / m360_clock_rate;      \
89        unsigned long nsec_per_pit_tick = 512 * nsec_per_chip_tick;           \
90        rtems_nsec_per_tick = BSP_Configuration.microseconds_per_tick * 1000; \
91        divisor = rtems_nsec_per_tick / nsec_per_pit_tick;                    \
92        if (divisor > 255)                                                    \
93            divisor = 255;                                                    \
94        else if (divisor == 0)                                                \
95            divisor = 1;                                                      \
96        pit_nsec_per_tick = nsec_per_pit_tick * divisor;                      \
97        m360.pitr &= ~0x1FF;                                                  \
98        m360.picr = (CLOCK_IRQ_LEVEL << 8) | CLOCK_VECTOR;                    \
99        m360.pitr |= divisor;                                                 \
100    } while (0)
101
102#include "../../../shared/clockdrv_shell.c"
Note: See TracBrowser for help on using the repository browser.