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

4.104.115
Last change on this file since f1e8903 was f1e8903, checked in by Joel Sherrill <joel.sherrill@…>, on Aug 28, 2009 at 6:24:10 PM

2009-08-28 Joel Sherrill <joel.sherrill@…>

  • bootcard.c, bsplibc.c, clockdrv_shell.h, console-polled.c: Fix formatting.
  • Property mode set to 100644
File size: 3.9 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 * This method is rarely used so default it.
24 */
25#ifndef Clock_driver_support_find_timer
26  #define Clock_driver_support_find_timer()
27#endif
28
29/*
30 *  ISRs until next clock tick
31 */
32#ifdef CLOCK_DRIVER_ISRS_PER_TICK
33  volatile uint32_t  Clock_driver_isrs;
34#endif
35
36/*
37 *  Clock ticks since initialization
38 */
39volatile uint32_t         Clock_driver_ticks;
40
41/*
42 *  ISR formerly installed.
43 */
44rtems_isr_entry  Old_ticker;
45
46void Clock_exit( void );
47
48/*
49 *  Clock_isr
50 *
51 *  This is the clock tick interrupt handler.
52 *
53 *  Input parameters:
54 *    vector - vector number
55 *
56 *  Output parameters:  NONE
57 *
58 *  Return values:      NONE
59 */
60rtems_isr Clock_isr(
61  rtems_vector_number vector
62)
63{
64  /*
65   *  Accurate count of ISRs
66   */
67  Clock_driver_ticks += 1;
68
69  #ifdef CLOCK_DRIVER_USE_FAST_IDLE
70    do {
71      rtems_clock_tick();
72    } while ( _Thread_Executing == _Thread_Idle &&
73            _Thread_Heir == _Thread_Executing);
74
75    Clock_driver_support_at_tick();
76    return;
77  #else
78    /*
79     *  Do the hardware specific per-tick action.
80     *
81     *  The counter/timer may or may not be set to automatically reload.
82     */
83    Clock_driver_support_at_tick();
84
85    #ifdef CLOCK_DRIVER_ISRS_PER_TICK
86      /*
87       *  The driver is multiple ISRs per clock tick.
88       */
89      if ( !Clock_driver_isrs ) {
90        rtems_clock_tick();
91
92        Clock_driver_isrs = CLOCK_DRIVER_ISRS_PER_TICK;
93      }
94      Clock_driver_isrs--;
95    #else
96      /*
97       *  The driver is one ISR per clock tick.
98       */
99      rtems_clock_tick();
100    #endif
101  #endif
102}
103
104/*
105 *  Install_clock
106 *
107 *  This routine actually performs the hardware initialization for the clock.
108 *
109 *  Input parameters:
110 *    clock_isr - clock interrupt service routine entry point
111 *
112 *  Output parameters:  NONE
113 *
114 *  Return values:      NONE
115 *
116 */
117
118static void Install_clock(
119  rtems_isr_entry clock_isr
120)
121{
122  Clock_driver_ticks = 0;
123
124  /*
125   *  Find timer -- some BSPs search buses for hardware timer
126   */
127  Clock_driver_support_find_timer();
128
129  /*
130   *  Install vector
131   */
132  Clock_driver_support_install_isr( clock_isr, Old_ticker );
133
134  #if defined(Clock_driver_nanoseconds_since_last_tick)
135    rtems_clock_set_nanoseconds_extension(
136      Clock_driver_nanoseconds_since_last_tick
137    );
138  #endif
139
140  /*
141   *  Now initialize the hardware that is the source of the tick ISR.
142   */
143  Clock_driver_support_initialize_hardware();
144
145  atexit( Clock_exit );
146}
147
148/*
149 *  Clock_exit
150 *
151 *  This routine allows the clock driver to exit by masking the interrupt and
152 *  disabling the clock's counter.
153 *
154 *  Input parameters:   NONE
155 *
156 *  Output parameters:  NONE
157 *
158 *  Return values:      NONE
159 *
160 */
161
162void Clock_exit( void )
163{
164  Clock_driver_support_shutdown_hardware();
165
166  /* do not restore old vector */
167}
168
169/*
170 *  Clock_initialize
171 *
172 *  This routine initializes the clock driver.
173 *
174 *  Input parameters:
175 *    major - clock device major number
176 *    minor - clock device minor number
177 *    parg  - pointer to optional device driver arguments
178 *
179 *  Output parameters:  NONE
180 *
181 *  Return values:
182 *    rtems_device_driver status code
183 */
184
185rtems_device_driver Clock_initialize(
186  rtems_device_major_number major,
187  rtems_device_minor_number minor,
188  void *pargp
189)
190{
191  Install_clock( Clock_isr );
192
193  /*
194   *  If we are counting ISRs per tick, then initialize the counter.
195   */
196  #ifdef CLOCK_DRIVER_ISRS_PER_TICK
197    Clock_driver_isrs = CLOCK_DRIVER_ISRS_PER_TICK;
198  #endif
199
200  return RTEMS_SUCCESSFUL;
201}
Note: See TracBrowser for help on using the repository browser.