source: rtems/c/src/lib/libbsp/m68k/dmv152/clock/ckinit.c @ 08311cc3

4.104.114.84.95
Last change on this file since 08311cc3 was 08311cc3, checked in by Joel Sherrill <joel.sherrill@…>, on 11/17/99 at 17:51:34

Updated copyright notice.

  • Property mode set to 100644
File size: 3.6 KB
Line 
1/*  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$
18 */
19
20#include <stdlib.h>
21 
22#include <bsp.h>
23#include <rtems/libio.h>
24
25rtems_unsigned32 Clock_isrs;        /* ISRs until next tick */
26volatile rtems_unsigned32 Clock_driver_ticks;
27                                    /* ticks since initialization */
28rtems_isr_entry  Old_ticker;
29
30void Clock_exit( void );
31
32#define CLOCK_VECTOR  TIMER_VECTOR
33 
34/*
35 * These are set by clock driver during its init
36 */
37 
38rtems_device_major_number rtems_clock_major = ~0;
39rtems_device_minor_number rtems_clock_minor;
40
41/*
42 *  ISR Handler
43 */
44
45rtems_isr Clock_isr(
46  rtems_vector_number vector
47)
48{
49  Clock_driver_ticks += 1;
50
51  Z8x36_WRITE( TIMER, CT1_CMD_STATUS, 0xE2 );
52  Z8x36_WRITE( TIMER, CT1_CMD_STATUS, 0x22 );
53  Z8x36_WRITE( TIMER, CT1_CMD_STATUS, 0xC6 );
54
55  if ( Clock_isrs == 1 ) {
56    rtems_clock_tick();
57    Clock_isrs = BSP_Configuration.microseconds_per_tick / 1000;
58  }
59  else
60    Clock_isrs -= 1;
61}
62
63void Install_clock(
64  rtems_isr_entry clock_isr
65)
66{
67  rtems_unsigned8 data;
68
69  Clock_driver_ticks = 0;
70  Clock_isrs = BSP_Configuration.microseconds_per_tick / 1000;
71
72  if ( BSP_Configuration.ticks_per_timeslice ) {
73    Old_ticker = (rtems_isr_entry) set_vector( clock_isr, CLOCK_VECTOR, 1 );
74
75    Z8x36_WRITE( TIMER, MASTER_CFG, 0xd4 );
76    Z8x36_READ ( TIMER, MASTER_INTR, data );
77    Z8x36_WRITE( TIMER, MASTER_INTR, (data & 0x7E) );
78    Z8x36_WRITE( TIMER, CT1_TIME_CONST_MSB, 0x04 );
79    Z8x36_WRITE( TIMER, CT1_TIME_CONST_LSB, 0xCE );
80    Z8x36_WRITE( TIMER, CT1_MODE_SPEC, 0x83 );
81    Z8x36_WRITE( TIMER, CNT_TMR_VECTOR, CLOCK_VECTOR );
82    Z8x36_WRITE( TIMER, CT1_CMD_STATUS, 0x20 );
83    Z8x36_READ ( TIMER, MASTER_INTR, data );
84    Z8x36_WRITE( TIMER, MASTER_INTR, (data & 0xDA) | 0x80 );
85
86    /*
87     * ACC_IC54 - interrupt 5 will be vectored and mapped to level 6
88     */
89
90    data = (*(rtems_unsigned8 *)0x0D00000B);
91    (*(rtems_unsigned8 *)0x0D00000B) = (data & 0x7F) | 0x60;
92
93    Z8x36_WRITE( TIMER, CT1_CMD_STATUS, 0xC6 );
94
95    atexit( Clock_exit );
96  }
97}
98
99void Clock_exit( void )
100{
101  rtems_unsigned8 data;
102
103  if ( BSP_Configuration.ticks_per_timeslice ) {
104
105    Z8x36_READ ( TIMER, MASTER_INTR, data );
106    Z8x36_WRITE( TIMER, MASTER_INTR, (data & 0x01) );
107    /* do not restore old vector */
108
109  }
110}
111
112rtems_device_driver Clock_initialize(
113  rtems_device_major_number major,
114  rtems_device_minor_number minor,
115  void *pargp
116)
117{
118  Install_clock( Clock_isr );
119 
120  /*
121   * make major/minor avail to others such as shared memory driver
122   */
123 
124  rtems_clock_major = major;
125  rtems_clock_minor = minor;
126 
127  return RTEMS_SUCCESSFUL;
128}
129 
130rtems_device_driver Clock_control(
131  rtems_device_major_number major,
132  rtems_device_minor_number minor,
133  void *pargp
134)
135{
136    rtems_unsigned32 isrlevel;
137    rtems_libio_ioctl_args_t *args = pargp;
138 
139    if (args == 0)
140        goto done;
141 
142    /*
143     * This is hokey, but until we get a defined interface
144     * to do this, it will just be this simple...
145     */
146 
147    if (args->command == rtems_build_name('I', 'S', 'R', ' '))
148    {
149        Clock_isr(CLOCK_VECTOR);
150    }
151    else if (args->command == rtems_build_name('N', 'E', 'W', ' '))
152    {
153      rtems_interrupt_disable( isrlevel );
154       (void) set_vector( args->buffer, CLOCK_VECTOR, 1 );
155      rtems_interrupt_enable( isrlevel );
156    }
157 
158done:
159    return RTEMS_SUCCESSFUL;
160}
161
Note: See TracBrowser for help on using the repository browser.