source: rtems/cpukit/score/inline/rtems/score/object.inl @ 27b7e81

4.104.115
Last change on this file since 27b7e81 was 27b7e81, checked in by Joel Sherrill <joel.sherrill@…>, on 12/21/08 at 21:28:05

2008-12-21 Joel Sherrill <joel.sherrill@…>

  • score/inline/rtems/score/object.inl, score/src/objectgetbyindex.c: Fix issues when using 16-bit object Ids.
  • Property mode set to 100644
File size: 9.0 KB
Line 
1/**
2 * @file rtems/score/object.inl
3 */
4
5/*
6 *
7 *  This include file contains the static inline implementation of all
8 *  of the inlined routines in the Object Handler.
9 *
10 *  COPYRIGHT (c) 1989-2008.
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.com/license/LICENSE.
16 *
17 *  $Id$
18 */
19
20#ifndef _RTEMS_SCORE_OBJECT_H
21# error "Never use <rtems/score/object.inl> directly; include <rtems/score/object.h> instead."
22#endif
23
24#ifndef _RTEMS_SCORE_OBJECT_INL
25#define _RTEMS_SCORE_OBJECT_INL
26
27/**
28 *  This function builds an object's id from the processor node and index
29 *  values specified.
30 *
31 *  @param[in] the_api indicates the API associated with this Id.
32 *  @param[in] the_class indicates the class of object.
33 *             It is specific to @a the_api.
34 *  @param[in] node is the node where this object resides.
35 *  @param[in] index is the instance number of this object.
36 *
37 *  @return This method returns an object Id constructed from the arguments.
38 */
39RTEMS_INLINE_ROUTINE Objects_Id _Objects_Build_id(
40  Objects_APIs     the_api,
41  uint32_t         the_class,
42  uint32_t         node,
43  uint32_t         index
44)
45{
46  return (( (Objects_Id) the_api )   << OBJECTS_API_START_BIT)   |
47         (( (Objects_Id) the_class ) << OBJECTS_CLASS_START_BIT) |
48         #if !defined(RTEMS_USE_16_BIT_OBJECT)
49           (( (Objects_Id) node )    << OBJECTS_NODE_START_BIT)  |
50         #endif
51         (( (Objects_Id) index )     << OBJECTS_INDEX_START_BIT);
52}
53
54/**
55 *  This function returns the API portion of the ID.
56 *
57 *  @param[in] id is the object Id to be processed.
58 *
59 *  @return This method returns an object Id constructed from the arguments.
60 */
61RTEMS_INLINE_ROUTINE Objects_APIs _Objects_Get_API(
62  Objects_Id id
63)
64{
65  return (Objects_APIs) ((id >> OBJECTS_API_START_BIT) & OBJECTS_API_VALID_BITS);
66}
67
68/**
69 *  This function returns the class portion of the ID.
70 *
71 *  @param[in] id is the object Id to be processed
72 */
73RTEMS_INLINE_ROUTINE uint32_t _Objects_Get_class(
74  Objects_Id id
75)
76{
77  return (uint32_t)
78    ((id >> OBJECTS_CLASS_START_BIT) & OBJECTS_CLASS_VALID_BITS);
79}
80 
81/**
82 *  This function returns the node portion of the ID.
83 *
84 *  @param[in] id is the object Id to be processed
85 *
86 *  @return This method returns the node portion of an object ID.
87 */
88RTEMS_INLINE_ROUTINE uint32_t _Objects_Get_node(
89  Objects_Id id
90)
91{
92  /*
93   * If using 16-bit Ids, then there is no node field and it MUST
94   * be a single processor system.
95   */
96  #if defined(RTEMS_USE_16_BIT_OBJECT)
97    return 1;
98  #else
99    return (id >> OBJECTS_NODE_START_BIT) & OBJECTS_NODE_VALID_BITS;
100  #endif
101}
102
103/**
104 *  This function returns the index portion of the ID.
105 *
106 *  @param[in] id is the Id to be processed
107 *
108 *  @return This method returns the class portion of the specified object ID.
109 */
110RTEMS_INLINE_ROUTINE uint32_t _Objects_Get_index(
111  Objects_Id id
112)
113{
114  return (id >> OBJECTS_INDEX_START_BIT) & OBJECTS_INDEX_VALID_BITS;
115}
116
117/**
118 *  This function returns TRUE if the api is valid.
119 *
120 *  @param[in] the_api is the api portion of an object ID.
121 *
122 *  @return This method returns TRUE if the specified api value is valid
123 *          and FALSE otherwise.
124 */
125RTEMS_INLINE_ROUTINE bool _Objects_Is_api_valid(
126  uint32_t   the_api
127)
128{
129  if ( !the_api || the_api > OBJECTS_APIS_LAST )
130   return FALSE;
131  return TRUE;
132}
133   
134/**
135 *  This function returns TRUE if the node is of the local object, and
136 *  FALSE otherwise.
137 *
138 *  @param[in] node is the node number and corresponds to the node number
139 *         portion of an object ID.
140 *
141 *  @return This method returns TRUE if the specified node is the local node
142 *          and FALSE otherwise.
143 */
144RTEMS_INLINE_ROUTINE bool _Objects_Is_local_node(
145  uint32_t   node
146)
147{
148  return ( node == _Objects_Local_node );
149}
150
151/**
152 *  This function returns TRUE if the id is of a local object, and
153 *  FALSE otherwise.
154 *
155 *  @param[in] id is an object ID
156 *
157 *  @return This method returns TRUE if the specified object Id is local
158 *          and FALSE otherwise.
159 *
160 *  @note On a single processor configuration, this always returns TRUE.
161 */
162RTEMS_INLINE_ROUTINE bool _Objects_Is_local_id(
163  Objects_Id id
164)
165{
166#if defined(RTEMS_MULTIPROCESSING)
167  return _Objects_Is_local_node( _Objects_Get_node(id) );
168#else
169  return TRUE;
170#endif
171}
172
173/**
174 *  This function returns TRUE if left and right are equal,
175 *  and FALSE otherwise.
176 *
177 *  @param[in] left is the Id on the left hand side of the comparison
178 *  @param[in] right is the Id on the right hand side of the comparison
179 *
180 *  @return This method returns TRUE if the specified object IDs are equal
181 *          and FALSE otherwise.
182 */
183RTEMS_INLINE_ROUTINE bool _Objects_Are_ids_equal(
184  Objects_Id left,
185  Objects_Id right
186)
187{
188  return ( left == right );
189}
190
191/**
192 *  This function returns a pointer to the local_table object
193 *  referenced by the index.
194 *
195 *  @param[in] information points to an Object Information Table
196 *  @param[in] index is the index of the object the caller wants to access
197 *
198 *  @return This method returns a pointer to a local object or NULL if the
199 *          index is invalid.
200 */
201RTEMS_INLINE_ROUTINE Objects_Control *_Objects_Get_local_object(
202  Objects_Information *information,
203  uint16_t             index
204)
205{
206  if ( index > information->maximum )
207    return NULL;
208  return information->local_table[ index ];
209}
210
211/**
212 *  This function sets the pointer to the local_table object
213 *  referenced by the index.
214 *
215 *  @param[in] information points to an Object Information Table
216 *  @param[in] index is the index of the object the caller wants to access
217 *  @param[in] the_object is the local object pointer
218 *
219 *  @note This routine is ONLY to be called in places where the
220 *        index portion of the Id is known to be good.  This is
221 *        OK since it is normally called from object create/init
222 *        or delete/destroy operations.
223 */
224
225RTEMS_INLINE_ROUTINE void _Objects_Set_local_object(
226  Objects_Information *information,
227  uint16_t             index,
228  Objects_Control     *the_object
229)
230{
231  /*
232   *  This routine is ONLY to be called from places in the code
233   *  where the Id is known to be good.  Therefore, this should NOT
234   *  occur in normal situations.
235   */
236  #if defined(RTEMS_DEBUG)
237    if ( index > information->maximum )
238      return;
239  #endif
240
241  information->local_table[ index ] = the_object;
242}
243
244/**
245 *  This function sets the pointer to the local_table object
246 *  referenced by the index to a NULL so the object Id is invalid
247 *  after this call.
248 *
249 *  @param[in] information points to an Object Information Table
250 *  @param[in] the_object is the local object pointer
251 *
252 *  @note This routine is ONLY to be called in places where the
253 *        index portion of the Id is known to be good.  This is
254 *        OK since it is normally called from object create/init
255 *        or delete/destroy operations.
256 */
257
258RTEMS_INLINE_ROUTINE void _Objects_Invalidate_Id(
259  Objects_Information  *information,
260  Objects_Control      *the_object
261)
262{
263  _Objects_Set_local_object(
264    information,
265    _Objects_Get_index( the_object->id ),
266    NULL
267  );
268}
269
270/**
271 *  This function places the_object control pointer and object name
272 *  in the Local Pointer and Local Name Tables, respectively.
273 *
274 *  @param[in] information points to an Object Information Table
275 *  @param[in] the_object is a pointer to an object
276 *  @param[in] name is the name of the object to make accessible
277 */
278RTEMS_INLINE_ROUTINE void _Objects_Open(
279  Objects_Information *information,
280  Objects_Control     *the_object,
281  Objects_Name         name
282)
283{
284  _Objects_Set_local_object(
285    information,
286    _Objects_Get_index( the_object->id ),
287    the_object
288  );
289
290  the_object->name = name;
291}
292
293/**
294 *  This function places the_object control pointer and object name
295 *  in the Local Pointer and Local Name Tables, respectively.
296 *
297 *  @param[in] information points to an Object Information Table
298 *  @param[in] the_object is a pointer to an object
299 *  @param[in] name is the name of the object to make accessible
300 */
301RTEMS_INLINE_ROUTINE void _Objects_Open_u32(
302  Objects_Information *information,
303  Objects_Control     *the_object,
304  uint32_t             name
305)
306{
307  _Objects_Set_local_object(
308    information,
309    _Objects_Get_index( the_object->id ),
310    the_object
311  );
312
313  /* ASSERT: information->is_string == FALSE */
314  the_object->name.name_u32 = name;
315}
316
317/**
318 *  This function places the_object control pointer and object name
319 *  in the Local Pointer and Local Name Tables, respectively.
320 *
321 *  @param[in] information points to an Object Information Table
322 *  @param[in] the_object is a pointer to an object
323 *  @param[in] name is the name of the object to make accessible
324 */
325RTEMS_INLINE_ROUTINE void _Objects_Open_string(
326  Objects_Information *information,
327  Objects_Control     *the_object,
328  const char          *name
329)
330{
331  _Objects_Set_local_object(
332    information,
333    _Objects_Get_index( the_object->id ),
334    the_object
335  );
336
337  /* ASSERT: information->is_string */
338  the_object->name.name_p = name;
339}
340
341#endif
342/* end of include file */
Note: See TracBrowser for help on using the repository browser.