RTEMS CPU Kit with SuperCore  4.10.99.0
rtems/score/object.h
Go to the documentation of this file.
00001 
00011 /*
00012  *  COPYRIGHT (c) 1989-2011.
00013  *  On-Line Applications Research Corporation (OAR).
00014  *
00015  *  The license and distribution terms for this file may be
00016  *  found in the file LICENSE in this distribution or at
00017  *  http://www.rtems.com/license/LICENSE.
00018  */
00019 
00020 #ifndef _RTEMS_SCORE_OBJECT_H
00021 #define _RTEMS_SCORE_OBJECT_H
00022 
00023 #include <rtems/score/chain.h>
00024 #include <rtems/score/isr.h>
00025 
00026 #if defined(RTEMS_POSIX_API)
00027 
00033   #define RTEMS_SCORE_OBJECT_ENABLE_STRING_NAMES
00034 #endif
00035 
00036 #ifdef __cplusplus
00037 extern "C" {
00038 #endif
00039 
00067 typedef union {
00068   #if defined(RTEMS_SCORE_OBJECT_ENABLE_STRING_NAMES)
00069 
00070     const char *name_p;
00071   #endif
00072 
00073   uint32_t    name_u32;
00074 } Objects_Name;
00075 
00079 typedef bool    (*Objects_Name_comparators)(
00080   void       * /* name_1 */,
00081   void       * /* name_2 */,
00082   uint16_t     /* length */
00083 );
00084 
00085 #if defined(RTEMS_USE_16_BIT_OBJECT)
00086 
00094 typedef uint16_t   Objects_Id;
00095 
00100 typedef uint8_t    Objects_Maximum;
00101 
00102 #define OBJECTS_INDEX_START_BIT  0U
00103 #define OBJECTS_API_START_BIT    8U
00104 #define OBJECTS_CLASS_START_BIT 11U
00105 
00106 #define OBJECTS_INDEX_MASK      (Objects_Id)0x00ffU
00107 #define OBJECTS_API_MASK        (Objects_Id)0x0700U
00108 #define OBJECTS_CLASS_MASK      (Objects_Id)0xF800U
00109 
00110 #define OBJECTS_INDEX_VALID_BITS  (Objects_Id)0x00ffU
00111 #define OBJECTS_API_VALID_BITS    (Objects_Id)0x0007U
00112 /* OBJECTS_NODE_VALID_BITS should not be used with 16 bit Ids */
00113 #define OBJECTS_CLASS_VALID_BITS  (Objects_Id)0x001fU
00114 
00115 #define OBJECTS_UNLIMITED_OBJECTS 0x8000U
00116 
00117 #define OBJECTS_ID_INITIAL_INDEX  (0)
00118 #define OBJECTS_ID_FINAL_INDEX    (0xff)
00119 
00120 #else
00121 
00130 typedef uint32_t   Objects_Id;
00131 
00136 typedef uint16_t   Objects_Maximum;
00137 
00142 #define OBJECTS_INDEX_START_BIT  0U
00143 
00147 #define OBJECTS_NODE_START_BIT  16U
00148 
00153 #define OBJECTS_API_START_BIT   24U
00154 
00159 #define OBJECTS_CLASS_START_BIT 27U
00160 
00164 #define OBJECTS_INDEX_MASK      (Objects_Id)0x0000ffffU
00165 
00169 #define OBJECTS_NODE_MASK       (Objects_Id)0x00ff0000U
00170 
00174 #define OBJECTS_API_MASK        (Objects_Id)0x07000000U
00175 
00179 #define OBJECTS_CLASS_MASK      (Objects_Id)0xf8000000U
00180 
00185 #define OBJECTS_INDEX_VALID_BITS  (Objects_Id)0x0000ffffU
00186 
00191 #define OBJECTS_NODE_VALID_BITS   (Objects_Id)0x000000ffU
00192 
00197 #define OBJECTS_API_VALID_BITS    (Objects_Id)0x00000007U
00198 
00203 #define OBJECTS_CLASS_VALID_BITS  (Objects_Id)0x0000001fU
00204 
00209 #define OBJECTS_UNLIMITED_OBJECTS 0x80000000U
00210 
00214 #define OBJECTS_ID_INITIAL_INDEX  (0)
00215 
00219 #define OBJECTS_ID_FINAL_INDEX    (0xffffU)
00220 #endif
00221 
00225 typedef enum {
00226   OBJECTS_NO_API       = 0,
00227   OBJECTS_INTERNAL_API = 1,
00228   OBJECTS_CLASSIC_API  = 2,
00229   OBJECTS_POSIX_API    = 3
00230 } Objects_APIs;
00231 
00233 #define OBJECTS_APIS_LAST OBJECTS_POSIX_API
00234 
00239 typedef enum {
00240   OBJECTS_INTERNAL_NO_CLASS =  0,
00241   OBJECTS_INTERNAL_THREADS  =  1,
00242   OBJECTS_INTERNAL_MUTEXES  =  2
00243 } Objects_Internal_API;
00244 
00246 #define OBJECTS_INTERNAL_CLASSES_LAST OBJECTS_INTERNAL_MUTEXES
00247 
00252 typedef enum {
00253   OBJECTS_CLASSIC_NO_CLASS     = 0,
00254   OBJECTS_RTEMS_TASKS          = 1,
00255   OBJECTS_RTEMS_TIMERS         = 2,
00256   OBJECTS_RTEMS_SEMAPHORES     = 3,
00257   OBJECTS_RTEMS_MESSAGE_QUEUES = 4,
00258   OBJECTS_RTEMS_PARTITIONS     = 5,
00259   OBJECTS_RTEMS_REGIONS        = 6,
00260   OBJECTS_RTEMS_PORTS          = 7,
00261   OBJECTS_RTEMS_PERIODS        = 8,
00262   OBJECTS_RTEMS_EXTENSIONS     = 9,
00263   OBJECTS_RTEMS_BARRIERS       = 10
00264 } Objects_Classic_API;
00265 
00267 #define OBJECTS_RTEMS_CLASSES_LAST OBJECTS_RTEMS_BARRIERS
00268 
00273 typedef enum {
00274   OBJECTS_POSIX_NO_CLASS            = 0,
00275   OBJECTS_POSIX_THREADS             = 1,
00276   OBJECTS_POSIX_KEYS                = 2,
00277   OBJECTS_POSIX_INTERRUPTS          = 3,
00278   OBJECTS_POSIX_MESSAGE_QUEUE_FDS   = 4,
00279   OBJECTS_POSIX_MESSAGE_QUEUES      = 5,
00280   OBJECTS_POSIX_MUTEXES             = 6,
00281   OBJECTS_POSIX_SEMAPHORES          = 7,
00282   OBJECTS_POSIX_CONDITION_VARIABLES = 8,
00283   OBJECTS_POSIX_TIMERS              = 9,
00284   OBJECTS_POSIX_BARRIERS            = 10,
00285   OBJECTS_POSIX_SPINLOCKS           = 11,
00286   OBJECTS_POSIX_RWLOCKS             = 12
00287 } Objects_POSIX_API;
00288 
00290 #define OBJECTS_POSIX_CLASSES_LAST OBJECTS_POSIX_RWLOCKS
00291 
00297 typedef enum {
00298 #if defined(RTEMS_MULTIPROCESSING)
00299   OBJECTS_REMOTE = 2,         /* object is remote */
00300 #endif
00301   OBJECTS_LOCAL  = 0,         /* object is local */
00302   OBJECTS_ERROR  = 1          /* id was invalid */
00303 } Objects_Locations;
00304 
00310 typedef void ( *Objects_Thread_queue_Extract_callout )( void * );
00311 
00316 typedef struct {
00318   Chain_Node     Node;
00320   Objects_Id     id;
00322   Objects_Name   name;
00323 } Objects_Control;
00324 
00329 typedef struct {
00331   Objects_APIs      the_api;
00333   uint16_t          the_class;
00335   Objects_Id        minimum_id;
00337   Objects_Id        maximum_id;
00339   Objects_Maximum   maximum;
00341   bool              auto_extend;
00343   Objects_Maximum   allocation_size;
00345   size_t            size;
00347   Objects_Control **local_table;
00349   Chain_Control     Inactive;
00351   Objects_Maximum   inactive;
00353   uint32_t         *inactive_per_block;
00355   void            **object_blocks;
00356   #if defined(RTEMS_SCORE_OBJECT_ENABLE_STRING_NAMES)
00357 
00358     bool              is_string;
00359   #endif
00360 
00361   uint16_t          name_length;
00363   Objects_Thread_queue_Extract_callout extract;
00364   #if defined(RTEMS_MULTIPROCESSING)
00365 
00366     Chain_Control    *global_table;
00367   #endif
00368 }   Objects_Information;
00369 
00373 #if defined(RTEMS_MULTIPROCESSING)
00374 SCORE_EXTERN uint16_t       _Objects_Local_node;
00375 #else
00376 #define _Objects_Local_node ((uint16_t)1)
00377 #endif
00378 
00382 #if defined(RTEMS_MULTIPROCESSING)
00383 SCORE_EXTERN uint16_t    _Objects_Maximum_nodes;
00384 #else
00385 #define _Objects_Maximum_nodes 1
00386 #endif
00387 
00393 SCORE_EXTERN Objects_Information
00394     **_Objects_Information_table[OBJECTS_APIS_LAST + 1];
00395 
00399 #define OBJECTS_ID_NONE 0
00400 
00405 #define OBJECTS_ID_OF_SELF ((Objects_Id) 0)
00406 
00411 #define OBJECTS_SEARCH_ALL_NODES   0
00412 
00417 #define OBJECTS_SEARCH_OTHER_NODES 0x7FFFFFFE
00418 
00423 #define OBJECTS_SEARCH_LOCAL_NODE  0x7FFFFFFF
00424 
00429 #define OBJECTS_WHO_AM_I           0
00430 
00435 #define OBJECTS_ID_INITIAL(_api, _class, _node) \
00436   _Objects_Build_id( (_api), (_class), (_node), OBJECTS_ID_INITIAL_INDEX )
00437 
00441 #define OBJECTS_ID_FINAL           ((Objects_Id)~0)
00442 
00448 void _Objects_Extend_information(
00449   Objects_Information *information
00450 );
00451 
00462 void _Objects_Shrink_information(
00463   Objects_Information *information
00464 );
00465 
00487 void _Objects_Initialize_information (
00488   Objects_Information *information,
00489   Objects_APIs         the_api,
00490   uint16_t             the_class,
00491   uint32_t             maximum,
00492   uint16_t             size,
00493   bool                 is_string,
00494   uint32_t             maximum_name_length
00495 #if defined(RTEMS_MULTIPROCESSING)
00496   ,
00497   bool                 supports_global,
00498   Objects_Thread_queue_Extract_callout extract
00499 #endif
00500 );
00501 
00512 unsigned int _Objects_API_maximum_class(
00513   uint32_t api
00514 );
00515 
00524 Objects_Control *_Objects_Allocate(
00525   Objects_Information *information
00526 );
00527 
00537 void _Objects_Free(
00538   Objects_Information *information,
00539   Objects_Control     *the_object
00540 );
00541 
00552 #define  _Objects_Build_name( _C1, _C2, _C3, _C4 ) \
00553   ( (uint32_t)(_C1) << 24 | \
00554     (uint32_t)(_C2) << 16 | \
00555     (uint32_t)(_C3) << 8 | \
00556     (uint32_t)(_C4) )
00557 
00568 typedef enum {
00569   OBJECTS_NAME_OR_ID_LOOKUP_SUCCESSFUL,
00570   OBJECTS_INVALID_NAME,
00571   OBJECTS_INVALID_ADDRESS,
00572   OBJECTS_INVALID_ID,
00573   OBJECTS_INVALID_NODE
00574 } Objects_Name_or_id_lookup_errors;
00575 
00580 #define OBJECTS_NAME_ERRORS_FIRST OBJECTS_NAME_OR_ID_LOOKUP_SUCCESSFUL
00581 
00586 #define OBJECTS_NAME_ERRORS_LAST  OBJECTS_INVALID_NODE
00587 
00604 Objects_Name_or_id_lookup_errors _Objects_Name_to_id_u32(
00605   Objects_Information *information,
00606   uint32_t             name,
00607   uint32_t             node,
00608   Objects_Id          *id
00609 );
00610 
00611 #if defined(RTEMS_SCORE_OBJECT_ENABLE_STRING_NAMES)
00612 
00627 Objects_Name_or_id_lookup_errors _Objects_Name_to_id_string(
00628   Objects_Information *information,
00629   const char          *name,
00630   Objects_Id          *id
00631 );
00632 #endif
00633 
00651 Objects_Name_or_id_lookup_errors _Objects_Id_to_name (
00652   Objects_Id      id,
00653   Objects_Name   *name
00654 );
00655 
00682 Objects_Control *_Objects_Get (
00683   Objects_Information *information,
00684   Objects_Id           id,
00685   Objects_Locations   *location
00686 );
00687 
00715 Objects_Control *_Objects_Get_isr_disable(
00716   Objects_Information *information,
00717   Objects_Id           id,
00718   Objects_Locations   *location,
00719   ISR_Level           *level
00720 );
00721 
00748 Objects_Control *_Objects_Get_no_protection(
00749   Objects_Information *information,
00750   Objects_Id           id,
00751   Objects_Locations   *location
00752 );
00753 
00765 Objects_Control *_Objects_Get_next(
00766     Objects_Information *information,
00767     Objects_Id           id,
00768     Objects_Locations   *location_p,
00769     Objects_Id          *next_id_p
00770 );
00771 
00785 Objects_Information *_Objects_Get_information(
00786   Objects_APIs   the_api,
00787   uint16_t       the_class
00788 );
00789 
00801 Objects_Information *_Objects_Get_information_id(
00802   Objects_Id  id
00803 );
00804 
00819 char *_Objects_Get_name_as_string(
00820   Objects_Id   id,
00821   size_t       length,
00822   char        *name
00823 );
00824 
00838 bool _Objects_Set_name(
00839   Objects_Information *information,
00840   Objects_Control     *the_object,
00841   const char          *name
00842 );
00843 
00852 void _Objects_Namespace_remove(
00853   Objects_Information  *information,
00854   Objects_Control      *the_object
00855 );
00856 
00866 void _Objects_Close(
00867   Objects_Information  *information,
00868   Objects_Control      *the_object
00869 );
00870 
00878 Objects_Maximum _Objects_Active_count(
00879   const Objects_Information *information
00880 );
00881 
00882 /*
00883  *  Pieces of object.inl are promoted out to the user
00884  */
00885 
00886 #include <rtems/score/object.inl>
00887 #if defined(RTEMS_MULTIPROCESSING)
00888 #include <rtems/score/objectmp.h>
00889 #endif
00890 
00891 #ifdef __cplusplus
00892 }
00893 #endif
00894 
00898 #endif
00899 /* end of include file */