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

4.104.115
Last change on this file since 6083017 was 6083017, checked in by Joel Sherrill <joel.sherrill@…>, on Nov 23, 2009 at 8:11:57 PM

2009-11-23 Joel Sherrill <joel.sherrill@…>

  • clockdrv_shell.h: Clean up.
  • Property mode set to 100644
File size: 3.5 KB
Line 
1/*
2 *  Clock Tick Device Driver Shell
3 *
4 *  COPYRIGHT (c) 1989-2009.
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
41void Clock_exit( void );
42
43/*
44 *  Clock_isr
45 *
46 *  This is the clock tick interrupt handler.
47 *
48 *  Input parameters:
49 *    vector - vector number
50 *
51 *  Output parameters:  NONE
52 *
53 *  Return values:      NONE
54 */
55rtems_isr Clock_isr(
56  rtems_vector_number vector
57)
58{
59  /*
60   *  Accurate count of ISRs
61   */
62  Clock_driver_ticks += 1;
63
64  #ifdef CLOCK_DRIVER_USE_FAST_IDLE
65    do {
66      rtems_clock_tick();
67    } while ( _Thread_Executing == _Thread_Idle &&
68            _Thread_Heir == _Thread_Executing);
69
70    Clock_driver_support_at_tick();
71    return;
72  #else
73    /*
74     *  Do the hardware specific per-tick action.
75     *
76     *  The counter/timer may or may not be set to automatically reload.
77     */
78    Clock_driver_support_at_tick();
79
80    #ifdef CLOCK_DRIVER_ISRS_PER_TICK
81      /*
82       *  The driver is multiple ISRs per clock tick.
83       */
84      if ( !Clock_driver_isrs ) {
85        rtems_clock_tick();
86
87        Clock_driver_isrs = CLOCK_DRIVER_ISRS_PER_TICK;
88      }
89      Clock_driver_isrs--;
90    #else
91      /*
92       *  The driver is one ISR per clock tick.
93       */
94      rtems_clock_tick();
95    #endif
96  #endif
97}
98
99/*
100 *  Clock_exit
101 *
102 *  This routine allows the clock driver to exit by masking the interrupt and
103 *  disabling the clock's counter.
104 *
105 *  Input parameters:   NONE
106 *
107 *  Output parameters:  NONE
108 *
109 *  Return values:      NONE
110 *
111 */
112
113void Clock_exit( void )
114{
115  Clock_driver_support_shutdown_hardware();
116
117  /* do not restore old vector */
118}
119
120/*
121 *  Clock_initialize
122 *
123 *  This routine initializes the clock driver.
124 *
125 *  Input parameters:
126 *    major - clock device major number
127 *    minor - clock device minor number
128 *    parg  - pointer to optional device driver arguments
129 *
130 *  Output parameters:  NONE
131 *
132 *  Return values:
133 *    rtems_device_driver status code
134 */
135
136rtems_device_driver Clock_initialize(
137  rtems_device_major_number major,
138  rtems_device_minor_number minor,
139  void *pargp
140)
141{
142  rtems_isr_entry  Old_ticker;
143
144  Clock_driver_ticks = 0;
145
146  /*
147   *  Find timer -- some BSPs search buses for hardware timer
148   */
149  Clock_driver_support_find_timer();
150
151  /*
152   *  Install vector
153   */
154  Clock_driver_support_install_isr( Clock_isr, Old_ticker );
155
156  #if defined(Clock_driver_nanoseconds_since_last_tick)
157    rtems_clock_set_nanoseconds_extension(
158      Clock_driver_nanoseconds_since_last_tick
159    );
160  #endif
161
162  /*
163   *  Now initialize the hardware that is the source of the tick ISR.
164   */
165  Clock_driver_support_initialize_hardware();
166
167  atexit( Clock_exit );
168
169  /*
170   *  If we are counting ISRs per tick, then initialize the counter.
171   */
172  #ifdef CLOCK_DRIVER_ISRS_PER_TICK
173    Clock_driver_isrs = CLOCK_DRIVER_ISRS_PER_TICK;
174  #endif
175
176  return RTEMS_SUCCESSFUL;
177}
Note: See TracBrowser for help on using the repository browser.