source: rtems/c/src/lib/libbsp/shared/clockdrv_shell.h @ a47cdf9

4.104.115
Last change on this file since a47cdf9 was b94554f, checked in by Ralf Corsepius <ralf.corsepius@…>, on 09/30/08 at 04:52:57

New (Copied from clockdrv_shell.c).

  • Property mode set to 100644
File size: 4.1 KB
Line 
1/*
2 *  Clock Tick Device Driver Shell
3 *
4 *  COPYRIGHT (c) 1989-2006.
5 *  On-Line Applications Research Corporation (OAR).
6 *
7 *  The license and distribution terms for this file may be
8 *  found in the file LICENSE in this distribution or at
9 *  http://www.rtems.com/license/LICENSE.
10 *
11 *  $Id$
12 */
13
14#include <stdlib.h>
15
16#include <bsp.h>
17
18#if defined(CLOCK_DRIVER_USE_FAST_IDLE) && defined(CLOCK_DRIVER_ISRS_PER_TICK)
19#error "clockdrv_shell.c: fast idle and N ISRs per tick is not supported"
20#endif
21
22
23/*
24 * This method is rarely used so default it.
25 */
26#ifndef Clock_driver_support_find_timer
27#define Clock_driver_support_find_timer()
28#endif
29
30/*
31 *  ISRs until next clock tick
32 */
33
34#ifdef CLOCK_DRIVER_ISRS_PER_TICK
35volatile uint32_t         Clock_driver_isrs;
36#endif
37
38/*
39 *  Clock ticks since initialization
40 */
41
42volatile uint32_t         Clock_driver_ticks;
43
44/*
45 *  ISR formerly installed.
46 */
47
48rtems_isr_entry  Old_ticker;
49
50void Clock_exit( void );
51
52/*
53 *  Major and minor number.
54 */
55
56rtems_device_major_number rtems_clock_major = UINT32_MAX;
57rtems_device_minor_number rtems_clock_minor;
58
59/*
60 *  Clock_isr
61 *
62 *  This is the clock tick interrupt handler.
63 *
64 *  Input parameters:
65 *    vector - vector number
66 *
67 *  Output parameters:  NONE
68 *
69 *  Return values:      NONE
70 *
71 */
72
73rtems_isr Clock_isr(
74  rtems_vector_number vector
75)
76{
77  /*
78   *  Accurate count of ISRs
79   */
80
81  Clock_driver_ticks += 1;
82
83#ifdef CLOCK_DRIVER_USE_FAST_IDLE
84  do {
85    rtems_clock_tick();
86  } while ( _Thread_Executing == _Thread_Idle &&
87          _Thread_Heir == _Thread_Executing);
88
89  Clock_driver_support_at_tick();
90  return;
91
92#else
93
94  /*
95   *  Do the hardware specific per-tick action.
96   *
97   *  The counter/timer may or may not be set to automatically reload.
98   */
99
100  Clock_driver_support_at_tick();
101
102#ifdef CLOCK_DRIVER_ISRS_PER_TICK
103  /*
104   *  The driver is multiple ISRs per clock tick.
105   */
106
107  if ( !Clock_driver_isrs ) {
108
109    rtems_clock_tick();
110
111    Clock_driver_isrs = CLOCK_DRIVER_ISRS_PER_TICK;
112  }
113  Clock_driver_isrs--;
114#else
115
116  /*
117   *  The driver is one ISR per clock tick.
118   */
119  rtems_clock_tick();
120#endif
121#endif
122}
123
124/*
125 *  Install_clock
126 *
127 *  This routine actually performs the hardware initialization for the clock.
128 *
129 *  Input parameters:
130 *    clock_isr - clock interrupt service routine entry point
131 *
132 *  Output parameters:  NONE
133 *
134 *  Return values:      NONE
135 *
136 */
137
138static void Install_clock(
139  rtems_isr_entry clock_isr
140)
141{
142  Clock_driver_ticks = 0;
143
144  /*
145   *  Find timer -- some BSPs search buses for hardware timer
146   */
147  Clock_driver_support_find_timer();
148
149  /*
150   *  Install vector
151   */
152  Clock_driver_support_install_isr( clock_isr, Old_ticker );
153
154  #if defined(Clock_driver_nanoseconds_since_last_tick)
155    rtems_clock_set_nanoseconds_extension(
156      Clock_driver_nanoseconds_since_last_tick
157    );
158  #endif
159
160  /*
161   *  Now initialize the hardware that is the source of the tick ISR.
162   */
163  Clock_driver_support_initialize_hardware();
164
165  atexit( Clock_exit );
166}
167
168/*
169 *  Clock_exit
170 *
171 *  This routine allows the clock driver to exit by masking the interrupt and
172 *  disabling the clock's counter.
173 *
174 *  Input parameters:   NONE
175 *
176 *  Output parameters:  NONE
177 *
178 *  Return values:      NONE
179 *
180 */
181
182void Clock_exit( void )
183{
184  Clock_driver_support_shutdown_hardware();
185
186  /* do not restore old vector */
187}
188
189/*
190 *  Clock_initialize
191 *
192 *  This routine initializes the clock driver.
193 *
194 *  Input parameters:
195 *    major - clock device major number
196 *    minor - clock device minor number
197 *    parg  - pointer to optional device driver arguments
198 *
199 *  Output parameters:  NONE
200 *
201 *  Return values:
202 *    rtems_device_driver status code
203 */
204
205rtems_device_driver Clock_initialize(
206  rtems_device_major_number major,
207  rtems_device_minor_number minor,
208  void *pargp
209)
210{
211  Install_clock( Clock_isr );
212
213  /*
214   * make major/minor avail to others such as shared memory driver
215   */
216
217  rtems_clock_major = major;
218  rtems_clock_minor = minor;
219
220  /*
221   *  If we are counting ISRs per tick, then initialize the counter.
222   */
223
224#ifdef CLOCK_DRIVER_ISRS_PER_TICK
225  Clock_driver_isrs = CLOCK_DRIVER_ISRS_PER_TICK;
226#endif
227
228  return RTEMS_SUCCESSFUL;
229}
Note: See TracBrowser for help on using the repository browser.