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

4.104.114.95
Last change on this file since 34ef6c7 was 34ef6c7, checked in by Joel Sherrill <joel.sherrill@…>, on 09/05/08 at 22:06:51

2008-09-05 Joel Sherrill <joel.sherrill@…>

  • clock/ckinit.c: The Shared Memory Driver no longer requires the special IOCTL in Clock_control. This was a hack which has existed since before the Classic API Timer Manager was implemented. All implementations of and references to Clock_control were removed.
  • Property mode set to 100644
File size: 3.4 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 (rtems_configuration_get_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 (rtems_configuration_get_ticks_per_timeslice()) {
104      rtems_isr_entry  old_isr;
105      period = bsp_clicks_per_second / rtems_configuration_get_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}
Note: See TracBrowser for help on using the repository browser.