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 | |
---|
21 | extern uint32_t bsp_clicks_per_second; |
---|
22 | |
---|
23 | /* |
---|
24 | * Clock_driver_ticks is a monotonically increasing counter of the |
---|
25 | * number of clock ticks since the driver was initialized. |
---|
26 | */ |
---|
27 | volatile uint32_t Clock_driver_ticks; |
---|
28 | |
---|
29 | /* |
---|
30 | * These are set by clock driver during its init |
---|
31 | */ |
---|
32 | |
---|
33 | rtems_device_major_number rtems_clock_major = ~0; |
---|
34 | rtems_device_minor_number rtems_clock_minor; |
---|
35 | |
---|
36 | rtems_isr (*rtems_clock_hook)(rtems_vector_number) = NULL; |
---|
37 | |
---|
38 | static void |
---|
39 | set_clock_period(uint32_t period) |
---|
40 | { |
---|
41 | asm volatile ("\tmov %0,r0\n" |
---|
42 | "\ttrapa\t#4\n" |
---|
43 | : |
---|
44 | : "r" (period) |
---|
45 | : "r0" ); |
---|
46 | } |
---|
47 | |
---|
48 | /* Clock_isr -- |
---|
49 | * This handles the timer interrupt by clearing the timer's interrupt |
---|
50 | * flag and announcing the clock tick to the system. |
---|
51 | * |
---|
52 | * PARAMETERS: |
---|
53 | * vector - timer interrupt vector number |
---|
54 | * |
---|
55 | * RETURNS: |
---|
56 | * none |
---|
57 | */ |
---|
58 | rtems_isr |
---|
59 | Clock_isr (rtems_vector_number vector) |
---|
60 | { |
---|
61 | /* Announce the clock tick */ |
---|
62 | Clock_driver_ticks++; |
---|
63 | rtems_clock_tick(); |
---|
64 | } |
---|
65 | |
---|
66 | /* Clock_exit -- |
---|
67 | * This shuts down the timer if it was enabled and removes it |
---|
68 | * from the interrupt mask. |
---|
69 | * |
---|
70 | * PARAMETERS: |
---|
71 | * none |
---|
72 | * |
---|
73 | * RETURNS: |
---|
74 | * none |
---|
75 | */ |
---|
76 | void |
---|
77 | Clock_exit(void) |
---|
78 | { |
---|
79 | if (rtems_configuration_get_ticks_per_timeslice()) |
---|
80 | { |
---|
81 | /* disable all timer1 interrupts */ |
---|
82 | set_clock_period(0); |
---|
83 | } |
---|
84 | } |
---|
85 | |
---|
86 | /* Install_clock -- |
---|
87 | * This initialises timer1 with the BSP timeslice config value |
---|
88 | * as a reference and sets up the interrupt handler for clock ticks. |
---|
89 | * |
---|
90 | * PARAMETERS: |
---|
91 | * clock_isr - clock interrupt handler routine |
---|
92 | * |
---|
93 | * RETURNS: |
---|
94 | * none. |
---|
95 | */ |
---|
96 | static void |
---|
97 | Install_clock(rtems_isr_entry clock_isr) |
---|
98 | { |
---|
99 | uint32_t period; |
---|
100 | |
---|
101 | Clock_driver_ticks = 0; |
---|
102 | if (rtems_configuration_get_ticks_per_timeslice()) { |
---|
103 | rtems_isr_entry old_isr; |
---|
104 | period = bsp_clicks_per_second / rtems_configuration_get_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 | */ |
---|
130 | rtems_device_driver |
---|
131 | Clock_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 | } |
---|