1 | /** |
---|
2 | * @file |
---|
3 | * |
---|
4 | * @brief Inlined Routines in the Priority Handler Bit Map Implementation |
---|
5 | * |
---|
6 | * This file contains the static inline implementation of all inlined |
---|
7 | * routines in the Priority Handler bit map implementation |
---|
8 | */ |
---|
9 | |
---|
10 | /* |
---|
11 | * COPYRIGHT (c) 1989-2010. |
---|
12 | * On-Line Applications Research Corporation (OAR). |
---|
13 | * |
---|
14 | * The license and distribution terms for this file may be |
---|
15 | * found in the file LICENSE in this distribution or at |
---|
16 | * http://www.rtems.org/license/LICENSE. |
---|
17 | */ |
---|
18 | |
---|
19 | #ifndef _RTEMS_SCORE_PRIORITYBITMAPIMPL_H |
---|
20 | #define _RTEMS_SCORE_PRIORITYBITMAPIMPL_H |
---|
21 | |
---|
22 | #include <rtems/score/prioritybitmap.h> |
---|
23 | #include <rtems/score/priority.h> |
---|
24 | |
---|
25 | #include <string.h> |
---|
26 | |
---|
27 | #ifdef __cplusplus |
---|
28 | extern "C" { |
---|
29 | #endif |
---|
30 | |
---|
31 | /** |
---|
32 | * @addtogroup ScorePriority |
---|
33 | */ |
---|
34 | /**@{**/ |
---|
35 | |
---|
36 | #if ( CPU_USE_GENERIC_BITFIELD_DATA == TRUE ) |
---|
37 | |
---|
38 | /** |
---|
39 | * This table is used by the generic bitfield routines to perform |
---|
40 | * a highly optimized bit scan without the use of special CPU |
---|
41 | * instructions. |
---|
42 | */ |
---|
43 | extern const unsigned char __log2table[256]; |
---|
44 | |
---|
45 | #endif |
---|
46 | |
---|
47 | /** |
---|
48 | * @brief Gets the @a _bit_number of the first bit set in the specified value. |
---|
49 | * |
---|
50 | * This routine returns the @a _bit_number of the first bit set |
---|
51 | * in the specified value. The correspondence between @a _bit_number |
---|
52 | * and actual bit position is processor dependent. The search for |
---|
53 | * the first bit set may run from most to least significant bit |
---|
54 | * or vice-versa. |
---|
55 | * |
---|
56 | * @param[in] _value is the value to bit scan. |
---|
57 | * @param[in] _bit_number is the position of the first bit set. |
---|
58 | * |
---|
59 | * @note This routine is used when the executing thread is removed |
---|
60 | * from the ready state and, as a result, its performance has a |
---|
61 | * significant impact on the performance of the executive as a whole. |
---|
62 | * |
---|
63 | * @note This routine must be a macro because if a CPU specific version |
---|
64 | * is used it will most likely use inline assembly. |
---|
65 | */ |
---|
66 | #if ( CPU_USE_GENERIC_BITFIELD_CODE == FALSE ) |
---|
67 | #define _Bitfield_Find_first_bit( _value, _bit_number ) \ |
---|
68 | _CPU_Bitfield_Find_first_bit( _value, _bit_number ) |
---|
69 | #else |
---|
70 | #define _Bitfield_Find_first_bit( _value, _bit_number ) \ |
---|
71 | { \ |
---|
72 | register uint32_t __value = (uint32_t) (_value); \ |
---|
73 | register const unsigned char *__p = __log2table; \ |
---|
74 | \ |
---|
75 | if ( __value < 0x100 ) \ |
---|
76 | (_bit_number) = (Priority_bit_map_Word)( __p[ __value ] + 8 ); \ |
---|
77 | else \ |
---|
78 | (_bit_number) = (Priority_bit_map_Word)( __p[ __value >> 8 ] ); \ |
---|
79 | } |
---|
80 | #endif |
---|
81 | |
---|
82 | #if ( CPU_USE_GENERIC_BITFIELD_CODE == FALSE ) |
---|
83 | /** |
---|
84 | * This method returns the priority bit mask for the specified major |
---|
85 | * or minor bit number. |
---|
86 | * |
---|
87 | * @param[in] _bit_number is the bit number for which we need a mask |
---|
88 | * |
---|
89 | * @retval the priority bit mask |
---|
90 | * |
---|
91 | * @note This may simply be a pass through to a CPU dependent implementation. |
---|
92 | */ |
---|
93 | #define _Priority_Mask( _bit_number ) \ |
---|
94 | _CPU_Priority_Mask( _bit_number ) |
---|
95 | #endif |
---|
96 | |
---|
97 | #if ( CPU_USE_GENERIC_BITFIELD_CODE == FALSE ) |
---|
98 | /** |
---|
99 | * This method returns the bit index position for the specified priority. |
---|
100 | * |
---|
101 | * @param[in] _priority is the priority for which we need the index. |
---|
102 | * |
---|
103 | * @retval This method returns the array index into the priority bit map. |
---|
104 | * |
---|
105 | * @note This may simply be a pass through to a CPU dependent implementation. |
---|
106 | */ |
---|
107 | #define _Priority_Bits_index( _priority ) \ |
---|
108 | _CPU_Priority_bits_index( _priority ) |
---|
109 | #endif |
---|
110 | |
---|
111 | /** |
---|
112 | * This function returns the major portion of the_priority. |
---|
113 | */ |
---|
114 | |
---|
115 | RTEMS_INLINE_ROUTINE Priority_bit_map_Word _Priority_Major ( |
---|
116 | Priority_Control the_priority |
---|
117 | ) |
---|
118 | { |
---|
119 | return (Priority_bit_map_Word)( the_priority / 16 ); |
---|
120 | } |
---|
121 | |
---|
122 | /** |
---|
123 | * This function returns the minor portion of the_priority. |
---|
124 | */ |
---|
125 | |
---|
126 | RTEMS_INLINE_ROUTINE Priority_bit_map_Word _Priority_Minor ( |
---|
127 | Priority_Control the_priority |
---|
128 | ) |
---|
129 | { |
---|
130 | return (Priority_bit_map_Word)( the_priority % 16 ); |
---|
131 | } |
---|
132 | |
---|
133 | #if ( CPU_USE_GENERIC_BITFIELD_CODE == TRUE ) |
---|
134 | |
---|
135 | /** |
---|
136 | * This function returns the mask associated with the major or minor |
---|
137 | * number passed to it. |
---|
138 | */ |
---|
139 | |
---|
140 | RTEMS_INLINE_ROUTINE Priority_bit_map_Word _Priority_Mask ( |
---|
141 | uint32_t bit_number |
---|
142 | ) |
---|
143 | { |
---|
144 | return (Priority_bit_map_Word)(0x8000u >> bit_number); |
---|
145 | } |
---|
146 | |
---|
147 | /** |
---|
148 | * This function returns the mask bit inverted. |
---|
149 | */ |
---|
150 | |
---|
151 | RTEMS_INLINE_ROUTINE Priority_bit_map_Word _Priority_Mask_invert ( |
---|
152 | uint32_t mask |
---|
153 | ) |
---|
154 | { |
---|
155 | return (Priority_bit_map_Word)(~mask); |
---|
156 | } |
---|
157 | |
---|
158 | /** |
---|
159 | * This function translates the bit numbers returned by the bit scan |
---|
160 | * of a priority bit field into something suitable for use as |
---|
161 | * a major or minor component of a priority. |
---|
162 | */ |
---|
163 | |
---|
164 | RTEMS_INLINE_ROUTINE uint32_t _Priority_Bits_index ( |
---|
165 | uint32_t bit_number |
---|
166 | ) |
---|
167 | { |
---|
168 | return bit_number; |
---|
169 | } |
---|
170 | |
---|
171 | #endif |
---|
172 | |
---|
173 | RTEMS_INLINE_ROUTINE void _Priority_bit_map_Initialize( |
---|
174 | Priority_bit_map_Control *bit_map |
---|
175 | ) |
---|
176 | { |
---|
177 | memset( bit_map, 0, sizeof( *bit_map ) ); |
---|
178 | } |
---|
179 | |
---|
180 | /** |
---|
181 | * Priority Queue implemented by bit map |
---|
182 | */ |
---|
183 | |
---|
184 | RTEMS_INLINE_ROUTINE void _Priority_bit_map_Add ( |
---|
185 | Priority_bit_map_Control *bit_map, |
---|
186 | Priority_bit_map_Information *bit_map_info |
---|
187 | ) |
---|
188 | { |
---|
189 | *bit_map_info->minor |= bit_map_info->ready_minor; |
---|
190 | bit_map->major_bit_map |= bit_map_info->ready_major; |
---|
191 | } |
---|
192 | |
---|
193 | RTEMS_INLINE_ROUTINE void _Priority_bit_map_Remove ( |
---|
194 | Priority_bit_map_Control *bit_map, |
---|
195 | Priority_bit_map_Information *bit_map_info |
---|
196 | ) |
---|
197 | { |
---|
198 | *bit_map_info->minor &= bit_map_info->block_minor; |
---|
199 | if ( *bit_map_info->minor == 0 ) |
---|
200 | bit_map->major_bit_map &= bit_map_info->block_major; |
---|
201 | } |
---|
202 | |
---|
203 | RTEMS_INLINE_ROUTINE Priority_Control _Priority_bit_map_Get_highest( |
---|
204 | const Priority_bit_map_Control *bit_map |
---|
205 | ) |
---|
206 | { |
---|
207 | Priority_bit_map_Word minor; |
---|
208 | Priority_bit_map_Word major; |
---|
209 | |
---|
210 | /* Avoid problems with some inline ASM statements */ |
---|
211 | Priority_bit_map_Word tmp; |
---|
212 | |
---|
213 | tmp = bit_map->major_bit_map; |
---|
214 | _Bitfield_Find_first_bit( tmp, major ); |
---|
215 | |
---|
216 | tmp = bit_map->bit_map[ major ]; |
---|
217 | _Bitfield_Find_first_bit( tmp, minor ); |
---|
218 | |
---|
219 | return (_Priority_Bits_index( major ) << 4) + |
---|
220 | _Priority_Bits_index( minor ); |
---|
221 | } |
---|
222 | |
---|
223 | RTEMS_INLINE_ROUTINE bool _Priority_bit_map_Is_empty( |
---|
224 | const Priority_bit_map_Control *bit_map |
---|
225 | ) |
---|
226 | { |
---|
227 | return bit_map->major_bit_map == 0; |
---|
228 | } |
---|
229 | |
---|
230 | RTEMS_INLINE_ROUTINE void _Priority_bit_map_Initialize_information( |
---|
231 | Priority_bit_map_Control *bit_map, |
---|
232 | Priority_bit_map_Information *bit_map_info, |
---|
233 | Priority_Control new_priority |
---|
234 | ) |
---|
235 | { |
---|
236 | Priority_bit_map_Word major; |
---|
237 | Priority_bit_map_Word minor; |
---|
238 | Priority_bit_map_Word mask; |
---|
239 | |
---|
240 | major = _Priority_Major( new_priority ); |
---|
241 | minor = _Priority_Minor( new_priority ); |
---|
242 | |
---|
243 | bit_map_info->minor = &bit_map->bit_map[ _Priority_Bits_index( major ) ]; |
---|
244 | |
---|
245 | mask = _Priority_Mask( major ); |
---|
246 | bit_map_info->ready_major = mask; |
---|
247 | /* Add _Priority_Mask_invert to non-generic bitfield then change this code. */ |
---|
248 | bit_map_info->block_major = (Priority_bit_map_Word)(~((uint32_t)mask)); |
---|
249 | |
---|
250 | mask = _Priority_Mask( minor ); |
---|
251 | bit_map_info->ready_minor = mask; |
---|
252 | /* Add _Priority_Mask_invert to non-generic bitfield then change this code. */ |
---|
253 | bit_map_info->block_minor = (Priority_bit_map_Word)(~((uint32_t)mask)); |
---|
254 | } |
---|
255 | |
---|
256 | /** @} */ |
---|
257 | |
---|
258 | #ifdef __cplusplus |
---|
259 | } |
---|
260 | #endif |
---|
261 | |
---|
262 | #endif |
---|
263 | /* end of include file */ |
---|