source: rtems/cpukit/score/include/rtems/score/object.h @ 43e1573c

4.115
Last change on this file since 43e1573c was 43e1573c, checked in by Sebastian Huber <sebastian.huber@…>, on 02/28/15 at 17:06:37

score: Add ISR lock to Objects_Control

This enables per-object SMP locks on SMP configurations and is the first
step to support fine-grained locking. On uni-processor configuration
there will be no overhead. The _Objects_Acquire() is intended to
replace _Objects_Get_isr_disable().

Update #2273.

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