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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [rtems/] [c/] [src/] [lib/] [libbsp/] [i960/] [rxgen960/] [clock/] [ckinit.c] - Blame information for rev 562

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 30 unneback
/*  Clock_init()
2
 *
3
 *  This routine initializes the i960RP onboard timer
4
 *  The tick frequency is 1 millisecond; assuming 33MHz core
5
 *
6
 *  Input parameters:  NONE
7
 *
8
 *  Output parameters:  NONE
9
 *
10
 *  COPYRIGHT (c) 1989-1997.
11
 *  RAMiX Inc 1999
12
 *  On-Line Applications Research Corporation (OAR).
13
 *  Copyright assigned to U.S. Government, 1994.
14
 *
15
 *  The license and distribution terms for this file may in
16
 *  the file LICENSE in this distribution or at
17
 *  http://www.OARcorp.com/rtems/license.html.
18
 *
19
 *  $Id: ckinit.c,v 1.2 2001-09-27 11:59:58 chris Exp $
20
 */
21
 
22
#include <stdlib.h>
23
 
24
#include <bsp.h>
25
#include <i960RP.h>
26
#include <rtems/libio.h>
27
 
28
#define CLOCK_VECTOR 0x92
29
 
30
rtems_unsigned32 Clock_isrs;              /* ISRs until next tick */
31
rtems_unsigned32 Reload_Clock_isrs;
32
 
33
i960_isr_entry   Old_ticker;
34
rtems_unsigned32 Clock_driver_ticks;
35
                                          /* ticks since initialization */
36
unsigned int clock_isr_global[16];  /* place to store global regs */
37
 
38
void Clock_exit( void );
39
 
40
/*
41
 * These are set by clock driver during its init
42
 */
43
 
44
rtems_device_major_number rtems_clock_major = ~0;
45
rtems_device_minor_number rtems_clock_minor;
46
 
47
/* this is later in the file to avoid it being inlined */
48
rtems_isr Clock_isr( rtems_vector_number vector );
49
 
50
void Install_clock(
51
  rtems_isr_entry clock_isr
52
)
53
{
54
  volatile unsigned int *tmr0 = (unsigned int *) TMR0_ADDR;
55
  volatile unsigned int *trr0 = (unsigned int *) TRR0_ADDR;
56
  volatile unsigned int *tcr0 = (unsigned int *) TCR0_ADDR;
57
  volatile unsigned int *icon = (unsigned int *) ICON_ADDR;
58
  volatile unsigned int *imap2 = (unsigned int *) IMAP2_ADDR;
59
  volatile unsigned int *ipnd = (unsigned int *) IPND_ADDR;
60
  volatile unsigned int *imsk = (unsigned int *) IMSK_ADDR;
61
  void clockHandler();
62
 
63
 
64
  Clock_driver_ticks = 0;
65
  Reload_Clock_isrs = BSP_Configuration.microseconds_per_tick / 1000;
66
  Clock_isrs = Reload_Clock_isrs;
67
 
68
    #define BUS_CLOCK_1 0
69
    #define TMR_WRITE_CNTL 8
70
    #define TMR_AUTO_RELOAD 4
71
    #define TMR_ENABLE 2
72
    #define TMR_TERM_CNT_STAT 1
73
 
74
    Old_ticker = set_vector( (((unsigned int) clock_isr) | 0x2), CLOCK_VECTOR, 1 );
75
 
76
    /* initialize the i960RP timer 0 here */
77
 
78
    /* set the timer countdown (Assume 33MHz operation) */
79
    *trr0 = 30 * BSP_Configuration.microseconds_per_tick ;
80
    *tcr0 = 30 * BSP_Configuration.microseconds_per_tick ;
81
/*
82
kkprintf("Load the timers with %x\n", 30 * BSP_Configuration.microseconds_per_tick / Reload_Clock_isrs);
83
*/
84
 
85
    *tmr0 = BUS_CLOCK_1 | TMR_AUTO_RELOAD | TMR_ENABLE;
86
/* Unmask the interrupts */
87
        *ipnd &= ~(1 << 12);
88
        *imsk |= 1 << 12;
89
 
90
}
91
 
92
void Clock_exit()
93
{
94
  volatile unsigned int *tmr0 = (unsigned int *) TMR0_ADDR;
95
 
96
  /* shut down the timer */
97
  *tmr0 = *tmr0 & ~TMR_ENABLE;
98
 
99
  i960_mask_intr( 12 );
100
  /* do not restore old vector */
101
}
102
 
103
rtems_device_driver Clock_initialize(
104
  rtems_device_major_number major,
105
  rtems_device_minor_number minor,
106
  void *pargp
107
)
108
{
109
  Install_clock( Clock_isr );
110
 
111
  atexit( Clock_exit );
112
 
113
  /*
114
   * make major/minor avail to others such as shared memory driver
115
   */
116
 
117
  rtems_clock_major = major;
118
  rtems_clock_minor = minor;
119
 
120
  return RTEMS_SUCCESSFUL;
121
}
122
 
123
rtems_device_driver Clock_control(
124
  rtems_device_major_number major,
125
  rtems_device_minor_number minor,
126
  void *pargp
127
)
128
{
129
    rtems_unsigned32 isrlevel;
130
    rtems_libio_ioctl_args_t *args = pargp;
131
 
132
    if (args == 0)
133
        goto done;
134
 
135
    /*
136
     * This is hokey, but until we get a defined interface
137
     * to do this, it will just be this simple...
138
     */
139
 
140
    if (args->command == rtems_build_name('I', 'S', 'R', ' '))
141
    {
142
        Clock_isr(CLOCK_VECTOR);
143
    }
144
    else if (args->command == rtems_build_name('N', 'E', 'W', ' '))
145
    {
146
      rtems_interrupt_disable( isrlevel );
147
       (void) set_tmr_vector( args->buffer, CLOCK_VECTOR, 0 );
148
      rtems_interrupt_enable( isrlevel );
149
    }
150
 
151
done:
152
    return RTEMS_SUCCESSFUL;
153
}
154
 
155
rtems_isr Clock_isr(
156
  rtems_vector_number vector
157
)
158
{
159
  /* enable_tracing(); */
160
#ifdef NOTMB
161
  if ( Clock_isrs == 1 ) {
162
    rtems_clock_tick();
163
    Clock_isrs = Reload_Clock_isrs;
164
  }
165
  else
166
  {
167
    Clock_isrs -= 1;
168
  }
169
#else
170
*(int *)(0xfed00000) += 1;
171
    rtems_clock_tick();
172
#endif
173
 
174
  i960_clear_intr( 12 );
175
}
176
 

powered by: WebSVN 2.1.0

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