source: rtems/c/src/lib/libcpu/powerpc/mpc6xx/clock/c_clock.c @ d3d9ef37

4.104.114.84.95
Last change on this file since d3d9ef37 was d3d9ef37, checked in by Jennifer Averett <Jennifer.Averett@…>, on 04/15/05 at 18:30:11

2005-04-15 Jennifer Averett <jennifer.averett@…>

  • mpc6xx/clock/c_clock.c, mpc6xx/clock/c_clock.h, mpc8260/console-generic/console-generic.c: add parameter to new exception interrupt handlers in powerpc bsps
  • Property mode set to 100644
File size: 4.6 KB
RevLine 
[acc25ee]1/*
2 *  Clock Tick Device Driver
3 *
4 *  This routine utilizes the Decrementer Register common to the PPC family.
5 *
6 *  The tick frequency is directly programmed to the configured number of
7 *  microseconds per tick.
8 *
9 *  COPYRIGHT (c) 1989-1997.
10 *  On-Line Applications Research Corporation (OAR).
11 *
12 *  The license and distribution terms for this file may in
13 *  the file LICENSE in this distribution or at
[21e1c44]14 *  http://www.rtems.com/license/LICENSE.
[acc25ee]15 *
16 *  Modified to support the MPC750.
17 *  Modifications Copyright (c) 1999 Eric Valette valette@crf.canon.fr
18 *
19 *  $Id$
20 */
21
[a73a977]22#include <rtems/system.h>
[acc25ee]23#include <rtems.h>
24#include <rtems/libio.h>
25#include <stdlib.h>                     /* for atexit() */
26#include <assert.h>
27#include <libcpu/c_clock.h>
[5c76213]28#include <rtems/bspIo.h>                     /* for printk() */
[acc25ee]29
[cebb89b]30extern int BSP_connect_clock_handler (void);
31
[acc25ee]32/*
33 *  Clock ticks since initialization
34 */
35
[66c373bf]36volatile uint32_t   Clock_driver_ticks;
[acc25ee]37
38/*
39 *  This is the value programmed into the count down timer.
40 */
41
[66c373bf]42uint32_t   Clock_Decrementer_value;
[acc25ee]43
44/*
45 * These are set by clock driver during its init
46 */
47 
48rtems_device_major_number rtems_clock_major = ~0;
49rtems_device_minor_number rtems_clock_minor;
50
51void clockOff(void* unused)
52{
[0dd1d44]53  /*
54   * Nothing to do as we cannot disable all interrupts and
55   * the decrementer interrupt enable is MSR_EE
56   */
[acc25ee]57}
58void clockOn(void* unused)
59{
60  PPC_Set_decrementer( Clock_Decrementer_value );
61}
62
63/*
64 *  Clock_isr
65 *
66 *  This is the clock tick interrupt handler.
67 *
68 *  Input parameters:
69 *    vector - vector number
70 *
71 *  Output parameters:  NONE
72 *
73 *  Return values:      NONE
74 *
75 */
[c984fb3]76
[d3d9ef37]77void clockIsr(void *unused)
[acc25ee]78{
[c984fb3]79int decr;
[acc25ee]80  /*
81   *  The driver has seen another tick.
82   */
[c984fb3]83  do {
84        asm volatile ("mfdec %0; add %0, %0, %1; mtdec %0":"=r"(decr):"r"(Clock_Decrementer_value));
[acc25ee]85
[c984fb3]86        Clock_driver_ticks += 1;
[acc25ee]87
[c984fb3]88        /*
89         *  Real Time Clock counter/timer is set to automatically reload.
90         */
91        rtems_clock_tick();
92  } while ( decr < 0 );
[acc25ee]93}
94
95int clockIsOn(void* unused)
96{
[66c373bf]97  uint32_t   msr_value;
[acc25ee]98
99  _CPU_MSR_GET( msr_value );
100  if (msr_value & MSR_EE) return 1;
101  return 0;
102}
103
104
105/*
106 *  Clock_exit
107 *
108 *  This routine allows the clock driver to exit by masking the interrupt and
109 *  disabling the clock's counter.
110 *
111 *  Input parameters:   NONE
112 *
113 *  Output parameters:  NONE
114 *
115 *  Return values:      NONE
116 *
117 */
118
119void Clock_exit( void )
120{
[0dd1d44]121  (void) BSP_disconnect_clock_handler ();
[acc25ee]122}
123 
124/*
125 *  Clock_initialize
126 *
127 *  This routine initializes the clock driver.
128 *
129 *  Input parameters:
130 *    major - clock device major number
131 *    minor - clock device minor number
132 *    parg  - pointer to optional device driver arguments
133 *
134 *  Output parameters:  NONE
135 *
136 *  Return values:
137 *    rtems_device_driver status code
138 */
139
140rtems_device_driver Clock_initialize(
141  rtems_device_major_number major,
142  rtems_device_minor_number minor,
143  void *pargp
144)
145{
[95273a6]146  Clock_Decrementer_value = (BSP_bus_frequency/BSP_time_base_divisor)*
[8e13ca61]147            (rtems_configuration_get_microseconds_per_tick()/1000);
[acc25ee]148
[c984fb3]149  /* set the decrementer now, prior to installing the handler
150   * so no interrupts will happen in a while.
151   */
152  PPC_Set_decrementer( (unsigned)-1 );
153
154  /* if a decrementer exception was pending, it is cleared by
155   * executing the default (nop) handler at this point;
156   * The next exception will then be taken by our clock handler.
157   * Clock handler installation initializes the decrementer to
158   * the correct value.
159   */
160
[acc25ee]161  if (!BSP_connect_clock_handler ()) {
162    printk("Unable to initialize system clock\n");
163    rtems_fatal_error_occurred(1);
164  }
165  /* make major/minor avail to others such as shared memory driver */
166 
167  rtems_clock_major = major;
168  rtems_clock_minor = minor;
169
170  return RTEMS_SUCCESSFUL;
171} /* Clock_initialize */
172 
173/*
174 *  Clock_control
175 *
176 *  This routine is the clock device driver control entry point.
177 *
178 *  Input parameters:
179 *    major - clock device major number
180 *    minor - clock device minor number
181 *    parg  - pointer to optional device driver arguments
182 *
183 *  Output parameters:  NONE
184 *
185 *  Return values:
186 *    rtems_device_driver status code
187 */
188
189rtems_device_driver Clock_control(
190  rtems_device_major_number major,
191  rtems_device_minor_number minor,
192  void *pargp
193)
194{
195    rtems_libio_ioctl_args_t *args = pargp;
196 
197    if (args == 0)
198        goto done;
199 
[95273a6]200    Clock_Decrementer_value = (BSP_bus_frequency/BSP_time_base_divisor)*
[8e13ca61]201      (rtems_configuration_get_microseconds_per_tick()/1000);
[acc25ee]202
203    if      (args->command == rtems_build_name('I', 'S', 'R', ' '))
[d3d9ef37]204      clockIsr(NULL);
[acc25ee]205    else if (args->command == rtems_build_name('N', 'E', 'W', ' '))
206    {
[c984fb3]207                Clock_initialize(major, minor, 0);
[acc25ee]208    }
209done:
210    return RTEMS_SUCCESSFUL;
211}
Note: See TracBrowser for help on using the repository browser.