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

4.104.114.84.95
Last change on this file since f05b2ac was f05b2ac, checked in by Ralf Corsepius <ralf.corsepius@…>, on 04/21/04 at 16:01:48

Remove duplicate white lines.

  • 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
22/*
23 * Clock_driver_ticks is a monotonically increasing counter of the
24 * number of clock ticks since the driver was initialized.
25 */
26volatile uint32_t         Clock_driver_ticks;
27
28/*
29 * These are set by clock driver during its init
30 */
31
32rtems_device_major_number rtems_clock_major = ~0;
33rtems_device_minor_number rtems_clock_minor;
34
35rtems_isr (*rtems_clock_hook)(rtems_vector_number) = NULL;
36
37static void
38set_clock_period(uint32_t         period)
39{
40    asm volatile ("\tmov %0,r0\n"
41                  "\ttrapa\t#4\n"
42                  :
43                  : "r" (period)
44                  : "r0" );
45}
46
47/* Clock_isr --
48 *     This handles the timer interrupt by clearing the timer's interrupt
49 *     flag and announcing the clock tick to the system.
50 *
51 * PARAMETERS:
52 *     vector - timer interrupt vector number
53 *
54 * RETURNS:
55 *     none
56 */
57rtems_isr
58Clock_isr (rtems_vector_number vector)
59{
60    /* Announce the clock tick */
61    Clock_driver_ticks++;
62    rtems_clock_tick();
63}
64
65/* Clock_exit --
66 *     This shuts down the timer if it was enabled and removes it
67 *     from the interrupt mask.
68 *
69 * PARAMETERS:
70 *     none
71 *
72 * RETURNS:
73 *     none
74 */
75void
76Clock_exit(void)
77{
78    if (BSP_Configuration.ticks_per_timeslice)
79    {
80        /* disable all timer1 interrupts */
81        set_clock_period(0);
82    }
83}
84
85/* Install_clock --
86 *     This initialises timer1 with the BSP timeslice config value
87 *     as a reference and sets up the interrupt handler for clock ticks.
88 *
89 * PARAMETERS:
90 *     clock_isr - clock interrupt handler routine
91 *
92 * RETURNS:
93 *     none.
94 */
95static void
96Install_clock(rtems_isr_entry clock_isr)
97{
98    uint32_t         period;
99    Clock_driver_ticks = 0;
100    if (BSP_Configuration.ticks_per_timeslice)
101    {
102        rtems_isr_entry  old_isr;
103        period = Cpu_table.clicks_per_second /
104                 BSP_Configuration.ticks_per_timeslice;
105
106        /* Configure timer interrupts */
107        set_clock_period(period);
108
109        /* Register the interrupt handler */
110        rtems_interrupt_catch(clock_isr, CLOCK_VECTOR, &old_isr);
111
112        /* Register the driver exit procedure so we can shutdown */
113        atexit(Clock_exit);
114    }
115}
116
117/* Clock_initialize --
118 *     This is called to setup the clock driver. It calls the hardware
119 *     setup function and make the driver major/minor values available
120 *     for other.
121 *
122 * PARAMETERS:
123 *     major - clock device major number
124 *     minor - clock device minor number
125 *     pargp - device driver initialization argument (not used)
126 *
127 * RETURNS:
128 *     RTEMS status code
129 */
130rtems_device_driver
131Clock_initialize(rtems_device_major_number major,
132                 rtems_device_minor_number minor,
133                 void *pargp)
134{
135    Install_clock (Clock_isr);
136
137    /* Make major/minor avail to others such as shared memory driver */
138    rtems_clock_major = major;
139    rtems_clock_minor = minor;
140
141    return RTEMS_SUCCESSFUL;
142}
143
144/* Clock_control --
145 *     I/O control (IOCTL) function for Clock driver. At this moment this
146 *     just runs the interrupt handler or re-registers the interrupt handler
147 *     on request.
148 *
149 * PARAMETERS:
150 *     major - clock major device number
151 *     minor - clock minor device number
152 *     pargp - pointer to IOCTL arguments
153 *
154 * RETURNS:
155 *     RTEMS status code
156 */
157rtems_device_driver
158Clock_control(rtems_device_major_number major,
159              rtems_device_minor_number minor,
160              void *pargp)
161{
162    uint32_t         isrlevel;
163    rtems_libio_ioctl_args_t *args = pargp;
164
165    if (args)
166    {
167        rtems_isr_entry  old_isr;
168        /*
169         * This is hokey, but until we get a defined interface
170         * to do this, it will just be this simple...
171         */
172        if (args->command == rtems_build_name('I', 'S', 'R', ' '))
173        {
174            Clock_isr(CLOCK_VECTOR);
175        }
176        else if (args->command == rtems_build_name('N', 'E', 'W', ' '))
177        {
178            rtems_interrupt_disable( isrlevel );
179            rtems_interrupt_catch(Clock_isr, CLOCK_VECTOR, &old_isr);
180            rtems_interrupt_enable( isrlevel );
181        }
182    }
183    return RTEMS_SUCCESSFUL;
184}
Note: See TracBrowser for help on using the repository browser.