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

4.115
Last change on this file since 64a04ac was c499856, checked in by Chris Johns <chrisj@…>, on 03/20/14 at 21:10:47

Change all references of rtems.com to rtems.org.

  • Property mode set to 100644
File size: 3.8 KB
Line 
1/**
2 * @file
3 *
4 * @ingroup bsp_clock
5 *
6 * @brief Clock Tick Device Driver Shell
7 */
8
9/*
10 *  COPYRIGHT (c) 1989-2012.
11 *  On-Line Applications Research Corporation (OAR).
12 *
13 *  The license and distribution terms for this file may be
14 *  found in the file LICENSE in this distribution or at
15 *  http://www.rtems.org/license/LICENSE.
16 */
17
18#include <stdlib.h>
19
20#include <bsp.h>
21
22/**
23 * @defgroup bsp_clock Clock Support
24 *
25 * @ingroup bsp_shared
26 *
27 * @brief Clock support
28 *
29 */
30#if CLOCK_DRIVER_USE_FAST_IDLE && CLOCK_DRIVER_ISRS_PER_TICK
31#error "clockdrv_shell.h: Fast Idle PLUS n ISRs per tick is not supported"
32#endif
33
34/**
35 * @brief This method is rarely used so default it.
36 */
37#ifndef Clock_driver_support_find_timer
38  #define Clock_driver_support_find_timer()
39#endif
40
41/**
42 * @brief ISRs until next clock tick
43 */
44#if CLOCK_DRIVER_ISRS_PER_TICK
45  volatile uint32_t  Clock_driver_isrs;
46#endif
47
48/**
49 * @brief Clock ticks since initialization
50 */
51volatile uint32_t    Clock_driver_ticks;
52
53void Clock_exit( void );
54
55/**
56 *  @brief Clock_isr
57 *
58 *  This is the clock tick interrupt handler.
59 *
60 *  @param vector Vector number.
61 *
62 *  Output parameters:  NONE
63 *
64 *  Return values:      NONE
65 */
66#if defined(BSP_FEATURE_IRQ_EXTENSION) || \
67    (CPU_SIMPLE_VECTORED_INTERRUPTS != TRUE)
68void Clock_isr(void *arg)
69{
70#else
71rtems_isr Clock_isr(rtems_vector_number vector);
72rtems_isr Clock_isr(
73  rtems_vector_number vector
74)
75{
76#endif
77  /*
78   *  Accurate count of ISRs
79   */
80  Clock_driver_ticks += 1;
81
82  #if CLOCK_DRIVER_USE_FAST_IDLE
83    do {
84      rtems_clock_tick();
85    } while (
86      _Thread_Heir == _Thread_Executing
87        && _Thread_Executing->Start.entry_point
88          == rtems_configuration_get_idle_task()
89    );
90
91    Clock_driver_support_at_tick();
92    return;
93  #else
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    Clock_driver_support_at_tick();
100
101    #if CLOCK_DRIVER_ISRS_PER_TICK
102      /*
103       *  The driver is multiple ISRs per clock tick.
104       */
105      if ( !Clock_driver_isrs ) {
106        rtems_clock_tick();
107
108        Clock_driver_isrs = CLOCK_DRIVER_ISRS_PER_TICK;
109      }
110      Clock_driver_isrs--;
111    #else
112      /*
113       *  The driver is one ISR per clock tick.
114       */
115      rtems_clock_tick();
116    #endif
117  #endif
118}
119
120/**
121 *  @brief Clock_exit
122 *
123 *  This routine allows the clock driver to exit by masking the interrupt and
124 *  disabling the clock's counter.
125 *
126 *  Input parameters:   NONE
127 *
128 *  Output parameters:  NONE
129 *
130 *  Return values:      NONE
131 *
132 */
133
134void Clock_exit( void )
135{
136  Clock_driver_support_shutdown_hardware();
137
138  /* do not restore old vector */
139}
140
141/**
142 * @brief Clock_initialize
143 *
144 * This routine initializes the clock driver.
145 *
146 * @param[in] major Clock device major number.
147 * @param[in] minor Clock device minor number.
148 * @param[in] parg  Pointer to optional device driver arguments
149 *
150 * @retval rtems_device_driver status code
151 */
152
153rtems_device_driver Clock_initialize(
154  rtems_device_major_number major,
155  rtems_device_minor_number minor,
156  void *pargp
157)
158{
159  rtems_isr_entry  Old_ticker;
160
161  Clock_driver_ticks = 0;
162
163  /*
164   *  Find timer -- some BSPs search buses for hardware timer
165   */
166  Clock_driver_support_find_timer();
167
168  /*
169   *  Install vector
170   */
171  (void) Old_ticker;
172  Clock_driver_support_install_isr( Clock_isr, Old_ticker );
173
174  #if defined(Clock_driver_nanoseconds_since_last_tick)
175    rtems_clock_set_nanoseconds_extension(
176      Clock_driver_nanoseconds_since_last_tick
177    );
178  #endif
179
180  /*
181   *  Now initialize the hardware that is the source of the tick ISR.
182   */
183  Clock_driver_support_initialize_hardware();
184
185  atexit( Clock_exit );
186
187  /*
188   *  If we are counting ISRs per tick, then initialize the counter.
189   */
190  #if CLOCK_DRIVER_ISRS_PER_TICK
191    Clock_driver_isrs = CLOCK_DRIVER_ISRS_PER_TICK_VALUE;
192  #endif
193
194  return RTEMS_SUCCESSFUL;
195}
Note: See TracBrowser for help on using the repository browser.