source: rtems/c/src/lib/libbsp/sh/simsh4/clock/ckinit.c @ fa920f1

4.104.114.9
Last change on this file since fa920f1 was fa920f1, checked in by Joel Sherrill <joel.sherrill@…>, on Nov 26, 2007 at 11:02:17 PM

2007-11-26 Joel Sherrill <joel.sherrill@…>

  • clock/ckinit.c, startup/bspstart.c: Eliminate the clicks_per_microsecond field in the SuperH CPU Table and define another mechanism for drivers to obtain this information.
  • Property mode set to 100644
File size: 4.5 KB
Line 
1/*
2 *  Clock Driver for SH4 simulator (timer interrupt not supported now).
3 *
4 *  Copyright (C) 2001 OKTET Ltd., St.-Petersburg, Russia
5 *  Author: Victor V. Vengerov <vvv@oktet.ru>
6 *
7 *  COPYRIGHT (c) 1989-2001.
8 *  On-Line Applications Research Corporation (OAR).
9 *
10 *  The license and distribution terms for this file may be
11 *  found in the file LICENSE in this distribution or at
12 *
13 *  http://www.rtems.com/license/LICENSE.
14 *
15 *  $Id$
16 */
17
18#include <stdlib.h>
19#include <bsp.h>
20#include <rtems/libio.h>
21
22extern uint32_t bsp_clicks_per_second;
23
24/*
25 * Clock_driver_ticks is a monotonically increasing counter of the
26 * number of clock ticks since the driver was initialized.
27 */
28volatile uint32_t         Clock_driver_ticks;
29
30/*
31 * These are set by clock driver during its init
32 */
33
34rtems_device_major_number rtems_clock_major = ~0;
35rtems_device_minor_number rtems_clock_minor;
36
37rtems_isr (*rtems_clock_hook)(rtems_vector_number) = NULL;
38
39static void
40set_clock_period(uint32_t         period)
41{
42    asm volatile ("\tmov %0,r0\n"
43                  "\ttrapa\t#4\n"
44                  :
45                  : "r" (period)
46                  : "r0" );
47}
48
49/* Clock_isr --
50 *     This handles the timer interrupt by clearing the timer's interrupt
51 *     flag and announcing the clock tick to the system.
52 *
53 * PARAMETERS:
54 *     vector - timer interrupt vector number
55 *
56 * RETURNS:
57 *     none
58 */
59rtems_isr
60Clock_isr (rtems_vector_number vector)
61{
62    /* Announce the clock tick */
63    Clock_driver_ticks++;
64    rtems_clock_tick();
65}
66
67/* Clock_exit --
68 *     This shuts down the timer if it was enabled and removes it
69 *     from the interrupt mask.
70 *
71 * PARAMETERS:
72 *     none
73 *
74 * RETURNS:
75 *     none
76 */
77void
78Clock_exit(void)
79{
80    if (BSP_Configuration.ticks_per_timeslice)
81    {
82        /* disable all timer1 interrupts */
83        set_clock_period(0);
84    }
85}
86
87/* Install_clock --
88 *     This initialises timer1 with the BSP timeslice config value
89 *     as a reference and sets up the interrupt handler for clock ticks.
90 *
91 * PARAMETERS:
92 *     clock_isr - clock interrupt handler routine
93 *
94 * RETURNS:
95 *     none.
96 */
97static void
98Install_clock(rtems_isr_entry clock_isr)
99{
100  uint32_t         period;
101
102  Clock_driver_ticks = 0;
103  if (BSP_Configuration.ticks_per_timeslice) {
104      rtems_isr_entry  old_isr;
105      period = bsp_clicks_per_second / BSP_Configuration.ticks_per_timeslice;
106
107      /* Configure timer interrupts */
108      set_clock_period(period);
109
110      /* Register the interrupt handler */
111      rtems_interrupt_catch(clock_isr, CLOCK_VECTOR, &old_isr);
112
113      /* Register the driver exit procedure so we can shutdown */
114      atexit(Clock_exit);
115  }
116}
117
118/* Clock_initialize --
119 *     This is called to setup the clock driver. It calls the hardware
120 *     setup function and make the driver major/minor values available
121 *     for other.
122 *
123 * PARAMETERS:
124 *     major - clock device major number
125 *     minor - clock device minor number
126 *     pargp - device driver initialization argument (not used)
127 *
128 * RETURNS:
129 *     RTEMS status code
130 */
131rtems_device_driver
132Clock_initialize(rtems_device_major_number major,
133                 rtems_device_minor_number minor,
134                 void *pargp)
135{
136    Install_clock (Clock_isr);
137
138    /* Make major/minor avail to others such as shared memory driver */
139    rtems_clock_major = major;
140    rtems_clock_minor = minor;
141
142    return RTEMS_SUCCESSFUL;
143}
144
145/* Clock_control --
146 *     I/O control (IOCTL) function for Clock driver. At this moment this
147 *     just runs the interrupt handler or re-registers the interrupt handler
148 *     on request.
149 *
150 * PARAMETERS:
151 *     major - clock major device number
152 *     minor - clock minor device number
153 *     pargp - pointer to IOCTL arguments
154 *
155 * RETURNS:
156 *     RTEMS status code
157 */
158rtems_device_driver
159Clock_control(rtems_device_major_number major,
160              rtems_device_minor_number minor,
161              void *pargp)
162{
163    uint32_t         isrlevel;
164    rtems_libio_ioctl_args_t *args = pargp;
165
166    if (args)
167    {
168        rtems_isr_entry  old_isr;
169        /*
170         * This is hokey, but until we get a defined interface
171         * to do this, it will just be this simple...
172         */
173        if (args->command == rtems_build_name('I', 'S', 'R', ' '))
174        {
175            Clock_isr(CLOCK_VECTOR);
176        }
177        else if (args->command == rtems_build_name('N', 'E', 'W', ' '))
178        {
179            rtems_interrupt_disable( isrlevel );
180            rtems_interrupt_catch(Clock_isr, CLOCK_VECTOR, &old_isr);
181            rtems_interrupt_enable( isrlevel );
182        }
183    }
184    return RTEMS_SUCCESSFUL;
185}
Note: See TracBrowser for help on using the repository browser.