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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [rtems/] [c/] [src/] [lib/] [libbsp/] [m68k/] [mvme136/] [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 the Z80386 1 on the MVME136 board.
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:13 chris Exp $
18
 */
19
 
20
#include <stdlib.h>
21
 
22
#include <bsp.h>
23
#include <rtems/libio.h>
24
#include <zilog/z8036.h>
25
 
26
#define MICRVAL     0xe2            /* disable lower chain, no vec */
27
                                    /*  set right justified addr */
28
                                    /*  and master int enable */
29
#define MCCRVAL     0xc4            /* enable T1 and port B */
30
                                    /*   timers independent */
31
#define MS_COUNT    0x07d0          /* T1's countdown constant (1 ms) */
32
#define T1MSRVAL    0x80            /* T1 cont. cycle/pulse output */
33
#define T1CSRVAL    0xc6            /* enable interrupt, allow and */
34
                                    /*   and trigger countdown */
35
 
36
#define TIMER        0xfffb0000
37
#define RELOAD       0x24            /* clr IP & IUS,allow countdown */
38
 
39
#define CLOCK_VECTOR 66
40
 
41
rtems_unsigned32 Clock_isrs;        /* ISRs until next tick */
42
 
43
volatile rtems_unsigned32 Clock_driver_ticks; /* ticks since initialization */
44
 
45
rtems_isr_entry  Old_ticker;
46
 
47
void Clock_exit( void );
48
 
49
/*
50
 * These are set by clock driver during its init
51
 */
52
 
53
rtems_device_major_number rtems_clock_major = ~0;
54
rtems_device_minor_number rtems_clock_minor;
55
 
56
/*
57
 *  ISR Handler
58
 */
59
 
60
rtems_isr Clock_isr(
61
  rtems_vector_number vector
62
)
63
{
64
  Clock_driver_ticks += 1;
65
  ((volatile struct z8036_map *) TIMER)->CT1_CMD_STATUS = RELOAD;
66
 
67
  if ( Clock_isrs == 1 ) {
68
    rtems_clock_tick();
69
    Clock_isrs = BSP_Configuration.microseconds_per_tick / 1000;
70
  }
71
  else
72
    Clock_isrs -= 1;
73
}
74
 
75
void Install_clock(
76
  rtems_isr_entry clock_isr
77
)
78
{
79
  volatile struct z8036_map *timer;
80
 
81
  Clock_driver_ticks = 0;
82
  Clock_isrs = BSP_Configuration.microseconds_per_tick / 1000;
83
 
84
  Old_ticker = (rtems_isr_entry) set_vector( clock_isr, CLOCK_VECTOR, 1 );
85
  timer = (struct z8036_map *) 0xfffb0000;
86
  timer->MASTER_INTR        = MICRVAL;
87
  timer->CT1_MODE_SPEC      = T1MSRVAL;
88
 
89
  *((rtems_unsigned16 *)0xfffb0016) = MS_COUNT;  /* write countdown value */
90
 
91
  /*
92
   *  timer->CT1_TIME_CONST_MSB = (MS_COUNT >> 8);
93
   *  timer->CT1_TIME_CONST_LSB = (MS_COUNT &  0xff);
94
   */
95
 
96
  timer->MASTER_CFG         = MCCRVAL;
97
  timer->CT1_CMD_STATUS     = T1CSRVAL;
98
 
99
  /*
100
   * Enable interrupt via VME interrupt mask register
101
   */
102
  (*(rtems_unsigned8 *)0xfffb0038) &= 0xfd;
103
 
104
  atexit( Clock_exit );
105
}
106
 
107
void Clock_exit( void )
108
{
109
  volatile struct z8036_map *timer;
110
 
111
  timer = (struct z8036_map *) 0xfffb0000;
112
  timer->MASTER_INTR        = 0x62;
113
  timer->CT1_MODE_SPEC      = 0x00;
114
  timer->MASTER_CFG         = 0xf4;
115
  timer->CT1_CMD_STATUS     = 0x00;
116
  /* do not restore old vector */
117
}
118
 
119
rtems_device_driver Clock_initialize(
120
  rtems_device_major_number major,
121
  rtems_device_minor_number minor,
122
  void *pargp
123
)
124
{
125
  Install_clock( Clock_isr );
126
 
127
  /*
128
   * make major/minor avail to others such as shared memory driver
129
   */
130
 
131
  rtems_clock_major = major;
132
  rtems_clock_minor = minor;
133
 
134
  return RTEMS_SUCCESSFUL;
135
}
136
 
137
rtems_device_driver Clock_control(
138
  rtems_device_major_number major,
139
  rtems_device_minor_number minor,
140
  void *pargp
141
)
142
{
143
    rtems_unsigned32 isrlevel;
144
    rtems_libio_ioctl_args_t *args = pargp;
145
 
146
    if (args == 0)
147
        goto done;
148
 
149
    /*
150
     * This is hokey, but until we get a defined interface
151
     * to do this, it will just be this simple...
152
     */
153
 
154
    if (args->command == rtems_build_name('I', 'S', 'R', ' '))
155
    {
156
        Clock_isr(CLOCK_VECTOR);
157
    }
158
    else if (args->command == rtems_build_name('N', 'E', 'W', ' '))
159
    {
160
      rtems_interrupt_disable( isrlevel );
161
       (void) set_vector( args->buffer, CLOCK_VECTOR, 1 );
162
      rtems_interrupt_enable( isrlevel );
163
    }
164
 
165
done:
166
    return RTEMS_SUCCESSFUL;
167
}

powered by: WebSVN 2.1.0

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