source: rtems/bsps/m68k/gen68360/clock/clock.c @ 753873e5

Last change on this file since 753873e5 was 753873e5, checked in by Joel Sherrill <joel@…>, on 03/22/22 at 20:03:30

Update Eric Norum contact info and start to normalize file headers

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