source: rtems/cpukit/score/include/rtems/score/object.h @ 8237b2d

4.115
Last change on this file since 8237b2d was 8237b2d, checked in by Joel Sherrill <joel.sherrill@…>, on 10/15/14 at 14:15:07

rtems/score/object.h: Include <rtems/score/cpu.h> to honor 16-bit Ids

Selection of 16-bit object Ids is a port specific decision. Somewhere
along the way, the file providing this information was dropped from
the include file set. This resulted in the code being compiled with
a mix of 16 and 32 bit ID assumptions for those targets with 16-bit Ids.

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