source: rtems/c/src/lib/libbsp/m68k/gen68302/clock/ckinit.c @ 03f2154e

4.104.114.84.95
Last change on this file since 03f2154e was 03f2154e, checked in by Joel Sherrill <joel.sherrill@…>, on Apr 22, 1997 at 5:20:27 PM

headers updated to reflect new style copyright notice as part
of switching to the modified GNU GPL.

  • Property mode set to 100644
File size: 3.7 KB
Line 
1/*  Clock_init()
2 *
3 *  This routine initializes Timer 1 for an MC68302.
4 *  The tick frequency is 1 millisecond.
5 *
6 *  Input parameters:  NONE
7 *
8 *  Output parameters:  NONE
9 *
10 *  COPYRIGHT (c) 1989-1997.
11 *  On-Line Applications Research Corporation (OAR).
12 *  Copyright assigned to U.S. Government, 1994.
13 *
14 *  The license and distribution terms for this file may in
15 *  the file LICENSE in this distribution or at
16 *  http://www.OARcorp.com/rtems/license.html.
17 *
18 *  $Id$
19 */
20
21#include <stdlib.h>                     /* for atexit() */
22
23#include <bsp.h>
24#include <rtems/libio.h>
25
26#include "m68302.h"
27
28#define CLOCK_VECTOR 137
29
30#define TMR1_VAL (  RBIT_TMR_RST        /* software reset the timer */\
31                  | RBIT_TMR_ICLK_MASTER16 /* master clock divided by 16 */\
32                  | RBIT_TMR_FRR        /* restart timer after ref reached */\
33                  | RBIT_TMR_ORI)       /* enable interrupt when ref reached */
34#define TRR1_VAL 1000                   /* 1000 ticks @ 16MHz/16
35                                         *    = 1 millisecond tick.
36                                         */
37
38/*
39 *  Clock_driver_ticks is a monotonically increasing counter of the
40 *  number of clock ticks since the driver was initialized.
41 */
42volatile rtems_unsigned32 Clock_driver_ticks;
43
44/*
45 *  Clock_isrs is the number of clock ISRs until the next invocation of
46 *  the RTEMS clock tick routine.  The clock tick device driver
47 *  gets an interrupt once a millisecond and counts down until the
48 *  length of time between the user configured microseconds per tick
49 *  has passed.
50 */
51rtems_unsigned32 Clock_isrs;
52
53void Clock_exit( void );
54 
55/*
56 * These are set by clock driver during its init
57 */
58 
59rtems_device_major_number rtems_clock_major = ~0;
60rtems_device_minor_number rtems_clock_minor;
61
62/*
63 *  ISR Handler
64 */
65
66rtems_isr Clock_isr(
67  rtems_vector_number vector
68)
69{
70  Clock_driver_ticks += 1;
71
72  m302.reg.isr  = RBIT_ISR_TIMER1;      /* clear in-service bit */
73  m302.reg.ter1 = (RBIT_TER_REF | RBIT_TER_CAP); /* clear timer intr request */
74
75  if ( Clock_isrs == 1 ) {
76    rtems_clock_tick();
77    Clock_isrs = BSP_Configuration.microseconds_per_tick / 1000;
78  }
79  else
80    Clock_isrs -= 1;
81}
82
83void Install_clock(
84  rtems_isr_entry clock_isr
85)
86{
87
88  Clock_driver_ticks = 0;
89  Clock_isrs = BSP_Configuration.microseconds_per_tick / 1000;
90
91  if ( BSP_Configuration.ticks_per_timeslice ) {
92   set_vector( clock_isr, CLOCK_VECTOR, 1 );
93
94    m302.reg.trr1 = TRR1_VAL;           /* set timer reference register */
95    m302.reg.tmr1 = TMR1_VAL;           /* set timer mode register & enable */
96    /*
97     * Enable TIMER1 interrupts only.
98     */
99    m302.reg.imr  = RBIT_IMR_TIMER1;    /* set 68302 int-mask to allow ints */
100
101    atexit( Clock_exit );
102  }
103}
104
105void Clock_exit( void )
106{
107  if ( BSP_Configuration.ticks_per_timeslice ) {
108    /* TODO: figure out what to do here */
109    /* do not restore old vector */
110  }
111}
112
113rtems_device_driver Clock_initialize(
114  rtems_device_major_number major,
115  rtems_device_minor_number minor,
116  void *pargp
117)
118{
119  Install_clock( Clock_isr );
120 
121  /*
122   * make major/minor avail to others such as shared memory driver
123   */
124 
125  rtems_clock_major = major;
126  rtems_clock_minor = minor;
127 
128  return RTEMS_SUCCESSFUL;
129}
130 
131rtems_device_driver Clock_control(
132  rtems_device_major_number major,
133  rtems_device_minor_number minor,
134  void *pargp
135)
136{
137    rtems_unsigned32 isrlevel;
138    rtems_libio_ioctl_args_t *args = pargp;
139 
140    if (args == 0)
141        goto done;
142 
143    /*
144     * This is hokey, but until we get a defined interface
145     * to do this, it will just be this simple...
146     */
147 
148    if (args->command == rtems_build_name('I', 'S', 'R', ' '))
149    {
150        Clock_isr( CLOCK_VECTOR);
151    }
152    else if (args->command == rtems_build_name('N', 'E', 'W', ' '))
153    {
154      rtems_interrupt_disable( isrlevel );
155       (void) set_vector( args->buffer, CLOCK_VECTOR, 1 );
156      rtems_interrupt_enable( isrlevel );
157    }
158 
159done:
160    return RTEMS_SUCCESSFUL;
161}
162
Note: See TracBrowser for help on using the repository browser.