source: rtems/c/src/lib/libbsp/m68k/idp/clock/ckinit.c @ 34ef6c7

4.104.114.95
Last change on this file since 34ef6c7 was 34ef6c7, checked in by Joel Sherrill <joel.sherrill@…>, on Sep 5, 2008 at 10:06:51 PM

2008-09-05 Joel Sherrill <joel.sherrill@…>

  • clock/ckinit.c: The Shared Memory Driver no longer requires the special IOCTL in Clock_control. This was a hack which has existed since before the Classic API Timer Manager was implemented. All implementations of and references to Clock_control were removed.
  • Property mode set to 100644
File size: 4.1 KB
Line 
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-1999.
17 *  On-Line Applications Research Corporation (OAR).
18 *
19 *  The license and distribution terms for this file may be
20 *  found in the file LICENSE in this distribution or at
21 *  http://www.rtems.com/license/LICENSE.
22 *
23 *  $Id$
24 */
25
26#include <stdlib.h>
27
28#include <bsp.h>
29#include <rtems/libio.h>
30
31uint32_t         Clock_isrs;        /* ISRs until next tick */
32volatile uint32_t         Clock_driver_ticks;
33                                    /* ticks since initialization */
34rtems_isr_entry  Old_ticker;
35
36extern rtems_configuration_table Configuration;
37extern void led_putnum(void);
38void Disable_clock(void);
39
40#define CLOCK_VECTOR 0x4D
41
42void Clock_exit( void );
43
44/*
45 * These are set by clock driver during its init
46 */
47
48rtems_device_major_number rtems_clock_major = ~0;
49rtems_device_minor_number rtems_clock_minor;
50
51/*
52 *  ISR Handler
53 *
54 *
55 * ((1ms * 6.5 MHz) / 2^5) = 203.125) where 6.5 MHz is the clock rate of the
56 * MC68230, 2^5 is the prescaler factor, and 1ms is the common interrupt
57 * interval for the Clock_isr routine.
58 * Therefore, 203 (decimal) is the number to program into the CPRH-L registers
59 * of the MC68230 for countdown.  However, I have found that 193 instead of
60 * 203 provides greater accuracy -- why?  The crystal should be more accurate
61 * than that
62 */
63
64rtems_isr Clock_isr(
65  rtems_vector_number vector
66)
67{
68  Clock_driver_ticks += 1;
69  /* acknowledge interrupt
70        MC68230_TSR = 1; */
71  MC68230_WRITE (MC68230_TSR, 1);
72
73  if ( Clock_isrs == 1 ) {
74    rtems_clock_tick();
75        /* Cast to an integer so that 68EC040 IDP which doesn't have an FPU doesn't
76           have a heart attack -- if you use newlib1.6 or greater and get
77           libgcc.a for gcc with software floating point support, this is not
78           a problem */
79    Clock_isrs =
80      (int)(rtems_configuration_get_microseconds_per_tick() / 1000);
81  }
82  else
83    Clock_isrs -= 1;
84}
85
86void Disable_clock(void)
87{
88        /* Disable timer */
89        MC68230_WRITE (MC68230_TCR, 0x00);
90}
91
92void Install_clock(
93  rtems_isr_entry clock_isr )
94{
95  Clock_driver_ticks = 0;
96  Clock_isrs = (int)(Configuration.microseconds_per_tick / 1000);
97
98/*    led_putnum('c'); * for debugging purposes */
99    Old_ticker = (rtems_isr_entry) set_vector( clock_isr, CLOCK_VECTOR, 1 );
100
101  /* Disable timer for initialization */
102  MC68230_WRITE (MC68230_TCR, 0x00);
103
104  /* some PI/T initialization stuff here -- see comment in the ckisr.c
105     file in this directory to understand why I use the values that I do */
106  /* Set up the interrupt vector on the MC68230 chip:
107  MC68230_TIVR = CLOCK_VECTOR; */
108  MC68230_WRITE (MC68230_TIVR, CLOCK_VECTOR);
109
110  /* Set CPRH through CPRL to 193 (not 203) decimal for countdown--see ckisr.c
111        CPRH = 0x00;
112        CPRM = 0x00;
113        CPRL = 0xC1; */
114  MC68230_WRITE (MC68230_CPRH, 0x00);
115  MC68230_WRITE (MC68230_CPRM, 0x00);
116  MC68230_WRITE (MC68230_CPRL, 0xC1);
117
118  /* Enable timer and use it as an external periodic interrupt generator
119        MC68230_TCR = 0xA1; */
120/*    led_putnum('a'); * for debugging purposes */
121  MC68230_WRITE (MC68230_TCR, 0xA1);
122
123  /*
124   *  Schedule the clock cleanup routine to execute if the application exits.
125   */
126  atexit( Clock_exit );
127}
128
129/* The following was added for debugging purposes */
130void Clock_exit( void )
131{
132  uint8_t         data;
133
134  /* disable timer
135        data = TCR;
136        TCR = (data & 0xFE); */
137  MC68230_READ (MC68230_TCR, data);
138  MC68230_WRITE (MC68230_TCR, (data & 0xFE));
139
140  /* do not restore old vector */
141}
142
143rtems_device_driver Clock_initialize(
144  rtems_device_major_number major,
145  rtems_device_minor_number minor,
146  void *pargp
147)
148{
149  Install_clock( Clock_isr );
150
151  /*
152   * make major/minor avail to others such as shared memory driver
153   */
154
155  rtems_clock_major = major;
156  rtems_clock_minor = minor;
157
158  return RTEMS_SUCCESSFUL;
159}
Note: See TracBrowser for help on using the repository browser.