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

4.115
Last change on this file since b3f86763 was b3f86763, checked in by Joel Sherrill <joel.sherrill@…>, on 10/12/14 at 15:06:05

ods68302/clock/ckinit.c: Fix warnings

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