1 | /** |
---|
2 | * @file rtems/score/object.h |
---|
3 | * |
---|
4 | * @brief Constants and Structures Associated with the Object Handler |
---|
5 | * |
---|
6 | * This include file contains all the constants and structures associated |
---|
7 | * with the Object Handler. This Handler provides mechanisms which |
---|
8 | * can be used to initialize and manipulate all objects which have ids. |
---|
9 | */ |
---|
10 | |
---|
11 | /* |
---|
12 | * COPYRIGHT (c) 1989-2011. |
---|
13 | * On-Line Applications Research Corporation (OAR). |
---|
14 | * |
---|
15 | * The license and distribution terms for this file may be |
---|
16 | * found in the file LICENSE in this distribution or at |
---|
17 | * http://www.rtems.org/license/LICENSE. |
---|
18 | */ |
---|
19 | |
---|
20 | #ifndef _RTEMS_SCORE_OBJECT_H |
---|
21 | #define _RTEMS_SCORE_OBJECT_H |
---|
22 | |
---|
23 | #include <rtems/score/basedefs.h> |
---|
24 | #include <rtems/score/cpu.h> |
---|
25 | |
---|
26 | #ifdef __cplusplus |
---|
27 | extern "C" { |
---|
28 | #endif |
---|
29 | |
---|
30 | /** |
---|
31 | * @defgroup Score SuperCore |
---|
32 | * |
---|
33 | * @brief Provides services for all APIs. |
---|
34 | */ |
---|
35 | /**@{*/ |
---|
36 | |
---|
37 | /** |
---|
38 | * @defgroup ScoreCPU CPU Architecture Support |
---|
39 | * |
---|
40 | * @ingroup Score |
---|
41 | * |
---|
42 | * @brief Provides CPU architecture dependent services. |
---|
43 | */ |
---|
44 | /**@{*/ |
---|
45 | |
---|
46 | /** |
---|
47 | * @defgroup ScoreObject Object Handler |
---|
48 | * |
---|
49 | * @ingroup Score |
---|
50 | */ |
---|
51 | /**@{*/ |
---|
52 | |
---|
53 | /** |
---|
54 | * The following type defines the control block used to manage |
---|
55 | * object names. |
---|
56 | */ |
---|
57 | typedef union { |
---|
58 | /** This is a pointer to a string name. */ |
---|
59 | const char *name_p; |
---|
60 | /** This is the actual 32-bit "raw" integer name. */ |
---|
61 | uint32_t name_u32; |
---|
62 | } Objects_Name; |
---|
63 | |
---|
64 | #if defined(RTEMS_USE_16_BIT_OBJECT) |
---|
65 | /** |
---|
66 | * The following type defines the control block used to manage |
---|
67 | * object IDs. The format is as follows (0=LSB): |
---|
68 | * |
---|
69 | * Bits 0 .. 7 = index (up to 254 objects of a type) |
---|
70 | * Bits 8 .. 10 = API (up to 7 API classes) |
---|
71 | * Bits 11 .. 15 = class (up to 31 object types per API) |
---|
72 | */ |
---|
73 | typedef uint16_t Objects_Id; |
---|
74 | |
---|
75 | /** |
---|
76 | * This type is used to store the maximum number of allowed objects |
---|
77 | * of each type. |
---|
78 | */ |
---|
79 | typedef uint8_t Objects_Maximum; |
---|
80 | |
---|
81 | #define OBJECTS_INDEX_START_BIT 0U |
---|
82 | #define OBJECTS_API_START_BIT 8U |
---|
83 | #define OBJECTS_CLASS_START_BIT 11U |
---|
84 | |
---|
85 | #define OBJECTS_INDEX_MASK (Objects_Id)0x00ffU |
---|
86 | #define OBJECTS_API_MASK (Objects_Id)0x0700U |
---|
87 | #define OBJECTS_CLASS_MASK (Objects_Id)0xF800U |
---|
88 | |
---|
89 | #define OBJECTS_INDEX_VALID_BITS (Objects_Id)0x00ffU |
---|
90 | #define OBJECTS_API_VALID_BITS (Objects_Id)0x0007U |
---|
91 | /* OBJECTS_NODE_VALID_BITS should not be used with 16 bit Ids */ |
---|
92 | #define OBJECTS_CLASS_VALID_BITS (Objects_Id)0x001fU |
---|
93 | |
---|
94 | #define OBJECTS_UNLIMITED_OBJECTS 0x8000U |
---|
95 | |
---|
96 | #define OBJECTS_ID_INITIAL_INDEX (0) |
---|
97 | #define OBJECTS_ID_FINAL_INDEX (0xff) |
---|
98 | |
---|
99 | #else |
---|
100 | /** |
---|
101 | * The following type defines the control block used to manage |
---|
102 | * object IDs. The format is as follows (0=LSB): |
---|
103 | * |
---|
104 | * Bits 0 .. 15 = index (up to 65535 objects of a type) |
---|
105 | * Bits 16 .. 23 = node (up to 255 nodes) |
---|
106 | * Bits 24 .. 26 = API (up to 7 API classes) |
---|
107 | * Bits 27 .. 31 = class (up to 31 object types per API) |
---|
108 | */ |
---|
109 | typedef uint32_t Objects_Id; |
---|
110 | |
---|
111 | /** |
---|
112 | * This type is used to store the maximum number of allowed objects |
---|
113 | * of each type. |
---|
114 | */ |
---|
115 | typedef uint16_t Objects_Maximum; |
---|
116 | |
---|
117 | /** |
---|
118 | * This is the bit position of the starting bit of the index portion of |
---|
119 | * the object Id. |
---|
120 | */ |
---|
121 | #define OBJECTS_INDEX_START_BIT 0U |
---|
122 | /** |
---|
123 | * This is the bit position of the starting bit of the node portion of |
---|
124 | * the object Id. |
---|
125 | */ |
---|
126 | #define OBJECTS_NODE_START_BIT 16U |
---|
127 | |
---|
128 | /** |
---|
129 | * This is the bit position of the starting bit of the API portion of |
---|
130 | * the object Id. |
---|
131 | */ |
---|
132 | #define OBJECTS_API_START_BIT 24U |
---|
133 | |
---|
134 | /** |
---|
135 | * This is the bit position of the starting bit of the class portion of |
---|
136 | * the object Id. |
---|
137 | */ |
---|
138 | #define OBJECTS_CLASS_START_BIT 27U |
---|
139 | |
---|
140 | /** |
---|
141 | * This mask is used to extract the index portion of an object Id. |
---|
142 | */ |
---|
143 | #define OBJECTS_INDEX_MASK (Objects_Id)0x0000ffffU |
---|
144 | |
---|
145 | /** |
---|
146 | * This mask is used to extract the node portion of an object Id. |
---|
147 | */ |
---|
148 | #define OBJECTS_NODE_MASK (Objects_Id)0x00ff0000U |
---|
149 | |
---|
150 | /** |
---|
151 | * This mask is used to extract the API portion of an object Id. |
---|
152 | */ |
---|
153 | #define OBJECTS_API_MASK (Objects_Id)0x07000000U |
---|
154 | |
---|
155 | /** |
---|
156 | * This mask is used to extract the class portion of an object Id. |
---|
157 | */ |
---|
158 | #define OBJECTS_CLASS_MASK (Objects_Id)0xf8000000U |
---|
159 | |
---|
160 | /** |
---|
161 | * This mask represents the bits that is used to ensure no extra bits |
---|
162 | * are set after shifting to extract the index portion of an object Id. |
---|
163 | */ |
---|
164 | #define OBJECTS_INDEX_VALID_BITS (Objects_Id)0x0000ffffU |
---|
165 | |
---|
166 | /** |
---|
167 | * This mask represents the bits that is used to ensure no extra bits |
---|
168 | * are set after shifting to extract the node portion of an object Id. |
---|
169 | */ |
---|
170 | #define OBJECTS_NODE_VALID_BITS (Objects_Id)0x000000ffU |
---|
171 | |
---|
172 | /** |
---|
173 | * This mask represents the bits that is used to ensure no extra bits |
---|
174 | * are set after shifting to extract the API portion of an object Id. |
---|
175 | */ |
---|
176 | #define OBJECTS_API_VALID_BITS (Objects_Id)0x00000007U |
---|
177 | |
---|
178 | /** |
---|
179 | * This mask represents the bits that is used to ensure no extra bits |
---|
180 | * are set after shifting to extract the class portion of an object Id. |
---|
181 | */ |
---|
182 | #define OBJECTS_CLASS_VALID_BITS (Objects_Id)0x0000001fU |
---|
183 | |
---|
184 | /** |
---|
185 | * Mask to enable unlimited objects. This is used in the configuration |
---|
186 | * table when specifying the number of configured objects. |
---|
187 | */ |
---|
188 | #define OBJECTS_UNLIMITED_OBJECTS 0x80000000U |
---|
189 | |
---|
190 | /** |
---|
191 | * This is the lowest value for the index portion of an object Id. |
---|
192 | */ |
---|
193 | #define OBJECTS_ID_INITIAL_INDEX (0) |
---|
194 | |
---|
195 | /** |
---|
196 | * This is the highest value for the index portion of an object Id. |
---|
197 | */ |
---|
198 | #define OBJECTS_ID_FINAL_INDEX (0xffffU) |
---|
199 | #endif |
---|
200 | |
---|
201 | /** |
---|
202 | * This enumerated type is used in the class field of the object ID. |
---|
203 | */ |
---|
204 | typedef enum { |
---|
205 | OBJECTS_NO_API = 0, |
---|
206 | OBJECTS_INTERNAL_API = 1, |
---|
207 | OBJECTS_CLASSIC_API = 2, |
---|
208 | OBJECTS_POSIX_API = 3, |
---|
209 | OBJECTS_FAKE_OBJECTS_API = 7 |
---|
210 | } Objects_APIs; |
---|
211 | |
---|
212 | /** This macro is used to generically specify the last API index. */ |
---|
213 | #define OBJECTS_APIS_LAST OBJECTS_POSIX_API |
---|
214 | |
---|
215 | /** |
---|
216 | * No object can have this ID. |
---|
217 | */ |
---|
218 | #define OBJECTS_ID_NONE 0 |
---|
219 | |
---|
220 | /** |
---|
221 | * The following defines the constant which may be used |
---|
222 | * to manipulate the calling task. |
---|
223 | */ |
---|
224 | #define OBJECTS_ID_OF_SELF ((Objects_Id) 0) |
---|
225 | |
---|
226 | /** |
---|
227 | * The following constant is used to specify that a name to ID search |
---|
228 | * should search through all nodes. |
---|
229 | */ |
---|
230 | #define OBJECTS_SEARCH_ALL_NODES 0 |
---|
231 | |
---|
232 | /** |
---|
233 | * The following constant is used to specify that a name to ID search |
---|
234 | * should search through all nodes except the current node. |
---|
235 | */ |
---|
236 | #define OBJECTS_SEARCH_OTHER_NODES 0x7FFFFFFE |
---|
237 | |
---|
238 | /** |
---|
239 | * The following constant is used to specify that a name to ID search |
---|
240 | * should search only on this node. |
---|
241 | */ |
---|
242 | #define OBJECTS_SEARCH_LOCAL_NODE 0x7FFFFFFF |
---|
243 | |
---|
244 | /** |
---|
245 | * The following constant is used to specify that a name to ID search |
---|
246 | * is being asked for the ID of the currently executing task. |
---|
247 | */ |
---|
248 | #define OBJECTS_WHO_AM_I 0 |
---|
249 | |
---|
250 | /** |
---|
251 | * This macros calculates the lowest ID for the specified api, class, |
---|
252 | * and node. |
---|
253 | */ |
---|
254 | #define OBJECTS_ID_INITIAL(_api, _class, _node) \ |
---|
255 | _Objects_Build_id( (_api), (_class), (_node), OBJECTS_ID_INITIAL_INDEX ) |
---|
256 | |
---|
257 | /** |
---|
258 | * This macro specifies the highest object ID value |
---|
259 | */ |
---|
260 | #define OBJECTS_ID_FINAL ((Objects_Id)~0) |
---|
261 | |
---|
262 | /** |
---|
263 | * This macro is used to build a thirty-two bit style name from |
---|
264 | * four characters. The most significant byte will be the |
---|
265 | * character @a _C1. |
---|
266 | * |
---|
267 | * @param[in] _C1 is the first character of the name |
---|
268 | * @param[in] _C2 is the second character of the name |
---|
269 | * @param[in] _C3 is the third character of the name |
---|
270 | * @param[in] _C4 is the fourth character of the name |
---|
271 | */ |
---|
272 | #define _Objects_Build_name( _C1, _C2, _C3, _C4 ) \ |
---|
273 | ( (uint32_t)(_C1) << 24 | \ |
---|
274 | (uint32_t)(_C2) << 16 | \ |
---|
275 | (uint32_t)(_C3) << 8 | \ |
---|
276 | (uint32_t)(_C4) ) |
---|
277 | |
---|
278 | /** |
---|
279 | * This function returns the API portion of the ID. |
---|
280 | * |
---|
281 | * @param[in] id is the object Id to be processed. |
---|
282 | * |
---|
283 | * @return This method returns an object Id constructed from the arguments. |
---|
284 | */ |
---|
285 | RTEMS_INLINE_ROUTINE Objects_APIs _Objects_Get_API( |
---|
286 | Objects_Id id |
---|
287 | ) |
---|
288 | { |
---|
289 | return (Objects_APIs) ((id >> OBJECTS_API_START_BIT) & OBJECTS_API_VALID_BITS); |
---|
290 | } |
---|
291 | |
---|
292 | /** |
---|
293 | * This function returns the class portion of the ID. |
---|
294 | * |
---|
295 | * @param[in] id is the object Id to be processed |
---|
296 | */ |
---|
297 | RTEMS_INLINE_ROUTINE uint32_t _Objects_Get_class( |
---|
298 | Objects_Id id |
---|
299 | ) |
---|
300 | { |
---|
301 | return (uint32_t) |
---|
302 | ((id >> OBJECTS_CLASS_START_BIT) & OBJECTS_CLASS_VALID_BITS); |
---|
303 | } |
---|
304 | |
---|
305 | /** |
---|
306 | * This function returns the node portion of the ID. |
---|
307 | * |
---|
308 | * @param[in] id is the object Id to be processed |
---|
309 | * |
---|
310 | * @return This method returns the node portion of an object ID. |
---|
311 | */ |
---|
312 | RTEMS_INLINE_ROUTINE uint32_t _Objects_Get_node( |
---|
313 | Objects_Id id |
---|
314 | ) |
---|
315 | { |
---|
316 | /* |
---|
317 | * If using 16-bit Ids, then there is no node field and it MUST |
---|
318 | * be a single processor system. |
---|
319 | */ |
---|
320 | #if defined(RTEMS_USE_16_BIT_OBJECT) |
---|
321 | return 1; |
---|
322 | #else |
---|
323 | return (id >> OBJECTS_NODE_START_BIT) & OBJECTS_NODE_VALID_BITS; |
---|
324 | #endif |
---|
325 | } |
---|
326 | |
---|
327 | /** |
---|
328 | * This function returns the index portion of the ID. |
---|
329 | * |
---|
330 | * @param[in] id is the Id to be processed |
---|
331 | * |
---|
332 | * @return This method returns the class portion of the specified object ID. |
---|
333 | */ |
---|
334 | RTEMS_INLINE_ROUTINE Objects_Maximum _Objects_Get_index( |
---|
335 | Objects_Id id |
---|
336 | ) |
---|
337 | { |
---|
338 | return |
---|
339 | (Objects_Maximum)((id >> OBJECTS_INDEX_START_BIT) & |
---|
340 | OBJECTS_INDEX_VALID_BITS); |
---|
341 | } |
---|
342 | |
---|
343 | /** |
---|
344 | * This function builds an object's id from the processor node and index |
---|
345 | * values specified. |
---|
346 | * |
---|
347 | * @param[in] the_api indicates the API associated with this Id. |
---|
348 | * @param[in] the_class indicates the class of object. |
---|
349 | * It is specific to @a the_api. |
---|
350 | * @param[in] node is the node where this object resides. |
---|
351 | * @param[in] index is the instance number of this object. |
---|
352 | * |
---|
353 | * @return This method returns an object Id constructed from the arguments. |
---|
354 | */ |
---|
355 | RTEMS_INLINE_ROUTINE Objects_Id _Objects_Build_id( |
---|
356 | Objects_APIs the_api, |
---|
357 | uint16_t the_class, |
---|
358 | uint8_t node, |
---|
359 | uint16_t index |
---|
360 | ) |
---|
361 | { |
---|
362 | return (( (Objects_Id) the_api ) << OBJECTS_API_START_BIT) | |
---|
363 | (( (Objects_Id) the_class ) << OBJECTS_CLASS_START_BIT) | |
---|
364 | #if !defined(RTEMS_USE_16_BIT_OBJECT) |
---|
365 | (( (Objects_Id) node ) << OBJECTS_NODE_START_BIT) | |
---|
366 | #endif |
---|
367 | (( (Objects_Id) index ) << OBJECTS_INDEX_START_BIT); |
---|
368 | } |
---|
369 | |
---|
370 | /** |
---|
371 | * Returns if the object maximum specifies unlimited objects. |
---|
372 | * |
---|
373 | * @param[in] maximum The object maximum specification. |
---|
374 | * |
---|
375 | * @retval true Unlimited objects are available. |
---|
376 | * @retval false The object count is fixed. |
---|
377 | */ |
---|
378 | RTEMS_INLINE_ROUTINE bool _Objects_Is_unlimited( uint32_t maximum ) |
---|
379 | { |
---|
380 | return (maximum & OBJECTS_UNLIMITED_OBJECTS) != 0; |
---|
381 | } |
---|
382 | |
---|
383 | /* |
---|
384 | * We cannot use an inline function for this since it may be evaluated at |
---|
385 | * compile time. |
---|
386 | */ |
---|
387 | #define _Objects_Maximum_per_allocation( maximum ) \ |
---|
388 | ((Objects_Maximum) ((maximum) & ~OBJECTS_UNLIMITED_OBJECTS)) |
---|
389 | |
---|
390 | /**@}*/ |
---|
391 | /**@}*/ |
---|
392 | /**@}*/ |
---|
393 | |
---|
394 | #ifdef __cplusplus |
---|
395 | } |
---|
396 | #endif |
---|
397 | |
---|
398 | #endif |
---|
399 | /* end of include file */ |
---|