OpenCores
URL https://opencores.org/ocsvn/openrisc_me/openrisc_me/trunk

Subversion Repositories openrisc_me

[/] [openrisc/] [trunk/] [rtos/] [rtems/] [c/] [src/] [lib/] [libbsp/] [m68k/] [ods68302/] [clock/] [ckinit.c] - Blame information for rev 173

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 30 unneback
/*  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.OARcorp.com/rtems/license.html.
16
 *
17
 *  $Id: ckinit.c,v 1.2 2001-09-27 12:00:20 chris Exp $
18
 */
19
 
20
#include <stdlib.h>                     /* for atexit() */
21
 
22
#include <bsp.h>
23
#include <rtems/libio.h>
24
 
25
#include "m68302.h"
26
 
27
#define CLOCK_VECTOR 137
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
 */
41
volatile 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
 */
50
rtems_unsigned32 Clock_isrs;
51
 
52
void Clock_exit( void );
53
 
54
/*
55
 * These are set by clock driver during its init
56
 */
57
 
58
rtems_device_major_number rtems_clock_major = ~0;
59
rtems_device_minor_number rtems_clock_minor;
60
 
61
/*
62
 *  ISR Handler
63
 */
64
 
65
rtems_isr Clock_isr(
66
  rtems_vector_number vector
67
)
68
{
69
  Clock_driver_ticks += 1;
70
 
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
}
81
 
82
void Install_clock(
83
  rtems_isr_entry clock_isr
84
)
85
{
86
 
87
  Clock_driver_ticks = 0;
88
  Clock_isrs = BSP_Configuration.microseconds_per_tick / 1000;
89
 
90
  set_vector( clock_isr, CLOCK_VECTOR, 1 );
91
 
92
  m302.reg.trr1 = TRR1_VAL;             /* set timer reference register */
93
  m302.reg.tmr1 = TMR1_VAL;             /* set timer mode register & enable */
94
  /*
95
   * Enable TIMER1 interrupts only.
96
   */
97
  m302.reg.imr  = RBIT_IMR_TIMER1;      /* set 68302 int-mask to allow ints */
98
 
99
  atexit( Clock_exit );
100
}
101
 
102
void Clock_exit( void )
103
{
104
  /* TODO: figure out what to do here */
105
  /* do not restore old vector */
106
}
107
 
108
rtems_device_driver Clock_initialize(
109
  rtems_device_major_number major,
110
  rtems_device_minor_number minor,
111
  void *pargp
112
)
113
{
114
  Install_clock( Clock_isr );
115
 
116
  /*
117
   * make major/minor avail to others such as shared memory driver
118
   */
119
 
120
  rtems_clock_major = major;
121
  rtems_clock_minor = minor;
122
 
123
  return RTEMS_SUCCESSFUL;
124
}
125
 
126
rtems_device_driver Clock_control(
127
  rtems_device_major_number major,
128
  rtems_device_minor_number minor,
129
  void *pargp
130
)
131
{
132
    rtems_unsigned32 isrlevel;
133
    rtems_libio_ioctl_args_t *args = pargp;
134
 
135
    if (args == 0)
136
        goto done;
137
 
138
    /*
139
     * This is hokey, but until we get a defined interface
140
     * to do this, it will just be this simple...
141
     */
142
 
143
    if (args->command == rtems_build_name('I', 'S', 'R', ' '))
144
    {
145
        Clock_isr( CLOCK_VECTOR);
146
    }
147
    else if (args->command == rtems_build_name('N', 'E', 'W', ' '))
148
    {
149
      rtems_interrupt_disable( isrlevel );
150
       (void) set_vector( args->buffer, CLOCK_VECTOR, 1 );
151
      rtems_interrupt_enable( isrlevel );
152
    }
153
 
154
done:
155
    return RTEMS_SUCCESSFUL;
156
}
157
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.