source: rtems/c/src/lib/libbsp/m68k/gen68302/clock/ckinit.c @ 0dd1d44

4.104.114.84.95
Last change on this file since 0dd1d44 was 0dd1d44, checked in by Joel Sherrill <joel.sherrill@…>, on 01/11/00 at 17:34:20

Removed old hack of using Configuration Table entry ticks_per_timeslice
being set to 0 to indicate that there should be no Clock Tick. This
was used by the Timing Tests to avoid clock tick overhead perturbing
execution times. Now the Timing Tests simply leave the Clock Tick
Driver out of the Device Driver Table.

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