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

4.115
Last change on this file since 9b4422a2 was 9b4422a2, checked in by Joel Sherrill <joel.sherrill@…>, on 05/03/12 at 15:09:24

Remove All CVS Id Strings Possible Using a Script

Script does what is expected and tries to do it as
smartly as possible.

+ remove occurrences of two blank comment lines

next to each other after Id string line removed.

+ remove entire comment blocks which only exited to

contain CVS Ids

+ If the processing left a blank line at the top of

a file, it was removed.

  • Property mode set to 100644
File size: 3.7 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
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
21char M360DefaultWatchdogFeeder = 1;
22
23/*
24 * RTEMS and hardware have different notions of clock rate.
25 */
26static unsigned long rtems_nsec_per_tick;
27static unsigned long pit_nsec_per_tick;
28static 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, _old ) \
55    do {                                                          \
56        _old = (rtems_isr_entry)set_vector(_new, CLOCK_VECTOR, 1);  \
57    } while(0)
58
59/*
60 * Turn off the clock
61 */
62#define Clock_driver_support_shutdown_hardware() \
63    do {                       \
64        m360.pitr &= ~0xFF;    \
65    } while(0)
66
67/*
68 * Set up the clock hardware
69 *     The rate at which the periodic interval timer
70 *     can generate interrupts is almost certainly not
71 *     the same as desired by the BSP configuration.
72 *     Handle the difference by choosing the largest PIT
73 *     interval which is less than or equal to the RTEMS
74 *     interval and skipping some hardware interrupts.
75 *     To reduce the jitter in the calls to RTEMS the
76 *     hardware interrupt interval is never greater than
77 *     the maximum non-prescaled value from the PIT.
78 *
79 *     For a 25 MHz external clock the basic clock rate is
80 *        40 nsec * 128 * 4 = 20.48 usec/tick
81 */
82extern int m360_clock_rate;
83
84#define Clock_driver_support_initialize_hardware() \
85    do {                                                                      \
86        unsigned int divisor;                                                 \
87        unsigned long nsec_per_chip_tick = 1000000000 / m360_clock_rate;      \
88        unsigned long nsec_per_pit_tick = 512 * nsec_per_chip_tick;           \
89        rtems_nsec_per_tick = rtems_configuration_get_microseconds_per_tick() * 1000; \
90        divisor = rtems_nsec_per_tick / nsec_per_pit_tick;                    \
91        if (divisor > 255)                                                    \
92            divisor = 255;                                                    \
93        else if (divisor == 0)                                                \
94            divisor = 1;                                                      \
95        pit_nsec_per_tick = nsec_per_pit_tick * divisor;                      \
96        m360.pitr &= ~0x1FF;                                                  \
97        m360.picr = (CLOCK_IRQ_LEVEL << 8) | CLOCK_VECTOR;                    \
98        m360.pitr |= divisor;                                                 \
99    } while (0)
100
101#include "../../../shared/clockdrv_shell.h"
Note: See TracBrowser for help on using the repository browser.