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