source: rtems/c/src/lib/libbsp/m68k/ods68302/clock/ckinit.c @ c499856

4.115
Last change on this file since c499856 was c499856, checked in by Chris Johns <chrisj@…>, on 03/20/14 at 21:10:47

Change all references of rtems.com to rtems.org.

  • Property mode set to 100644
File size: 2.8 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-1999.
11 *  On-Line Applications Research Corporation (OAR).
12 *
13 *  The license and distribution terms for this file may be
14 *  found in the file LICENSE in this distribution or at
15 *  http://www.rtems.org/license/LICENSE.
16 */
17
18#include <stdlib.h>                     /* for atexit() */
19
20#include <bsp.h>
21#include <rtems/m68k/m68302.h>
22
23#define CLOCK_VECTOR 137
24
25#define TMR1_VAL (  RBIT_TMR_RST        /* software reset the timer */\
26                  | RBIT_TMR_ICLK_MASTER16 /* master clock divided by 16 */\
27                  | RBIT_TMR_FRR        /* restart timer after ref reached */\
28                  | RBIT_TMR_ORI)       /* enable interrupt when ref reached */
29#define TRR1_VAL 1000                   /* 1000 ticks @ 16MHz/16
30                                         *    = 1 millisecond tick.
31                                         */
32
33/*
34 *  Clock_driver_ticks is a monotonically increasing counter of the
35 *  number of clock ticks since the driver was initialized.
36 */
37volatile uint32_t         Clock_driver_ticks;
38
39/*
40 *  Clock_isrs is the number of clock ISRs until the next invocation of
41 *  the RTEMS clock tick routine.  The clock tick device driver
42 *  gets an interrupt once a millisecond and counts down until the
43 *  length of time between the user configured microseconds per tick
44 *  has passed.
45 */
46uint32_t         Clock_isrs;
47
48void Clock_exit( void );
49
50/*
51 * These are set by clock driver during its init
52 */
53
54rtems_device_major_number rtems_clock_major = ~0;
55rtems_device_minor_number rtems_clock_minor;
56
57/*
58 *  ISR Handler
59 */
60
61rtems_isr Clock_isr(
62  rtems_vector_number vector
63)
64{
65  Clock_driver_ticks += 1;
66
67  m302.reg.isr  = RBIT_ISR_TIMER1;      /* clear in-service bit */
68  m302.reg.ter1 = (RBIT_TER_REF | RBIT_TER_CAP); /* clear timer intr request */
69
70  if ( Clock_isrs == 1 ) {
71    rtems_clock_tick();
72    Clock_isrs = rtems_configuration_get_microseconds_per_tick() / 1000;
73  }
74  else
75    Clock_isrs -= 1;
76}
77
78void Install_clock(
79  rtems_isr_entry clock_isr
80)
81{
82
83  Clock_driver_ticks = 0;
84  Clock_isrs = rtems_configuration_get_microseconds_per_tick() / 1000;
85
86  set_vector( clock_isr, CLOCK_VECTOR, 1 );
87
88  m302.reg.trr1 = TRR1_VAL;             /* set timer reference register */
89  m302.reg.tmr1 = TMR1_VAL;             /* set timer mode register & enable */
90  /*
91   * Enable TIMER1 interrupts only.
92   */
93  m302.reg.imr |= RBIT_IMR_TIMER1;      /* set 68302 int-mask to allow ints */
94
95  atexit( Clock_exit );
96}
97
98void Clock_exit( void )
99{
100  /* TODO: figure out what to do here */
101  /* do not restore old vector */
102}
103
104rtems_device_driver Clock_initialize(
105  rtems_device_major_number major,
106  rtems_device_minor_number minor,
107  void *pargp
108)
109{
110  Install_clock( Clock_isr );
111
112  /*
113   * make major/minor avail to others such as shared memory driver
114   */
115
116  rtems_clock_major = major;
117  rtems_clock_minor = minor;
118
119  return RTEMS_SUCCESSFUL;
120}
Note: See TracBrowser for help on using the repository browser.