Back to home page

LXR

 
 

    


File indexing completed on 2025-05-11 08:24:13

0001 /* SPDX-License-Identifier: BSD-2-Clause */
0002 
0003 /**
0004  * @file
0005  *
0006  * @ingroup RTEMSAPIAssociativity
0007  *
0008  * @brief RTEMS Associativity Routines
0009  */
0010 
0011 /*
0012  * Copyright (C) 1995 Tony Bennett <tbennett@divnc.com>
0013  *
0014  * Redistribution and use in source and binary forms, with or without
0015  * modification, are permitted provided that the following conditions
0016  * are met:
0017  * 1. Redistributions of source code must retain the above copyright
0018  *    notice, this list of conditions and the following disclaimer.
0019  * 2. Redistributions in binary form must reproduce the above copyright
0020  *    notice, this list of conditions and the following disclaimer in the
0021  *    documentation and/or other materials provided with the distribution.
0022  *
0023  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
0024  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
0025  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
0026  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
0027  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
0028  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
0029  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
0030  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
0031  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
0032  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
0033  * POSSIBILITY OF SUCH DAMAGE.
0034  */
0035 
0036 #ifndef _RTEMS_RTEMS_ASSOC_H
0037 #define _RTEMS_RTEMS_ASSOC_H
0038 
0039 #include <stddef.h>
0040 #include <stdint.h>
0041 
0042 #ifdef __cplusplus
0043 extern "C" {
0044 #endif
0045 
0046 /**
0047  * @defgroup RTEMSAPIAssociativity Associativity Routines
0048  *
0049  * @ingroup RTEMSAPI
0050  *
0051  * RTEMS associativity routines.  Mainly used to convert a value from
0052  * one space to another (eg: our errno's to host errno's and vice-versa)
0053  *
0054  * @{
0055  */
0056 
0057 typedef struct {
0058     const char  *name;
0059     uint32_t     local_value;
0060     uint32_t     remote_value;
0061 } rtems_assoc_t;
0062 
0063 /*
0064  * Flag/marker for optional default value in each table
0065  */
0066 
0067 #define RTEMS_ASSOC_DEFAULT_NAME "(default)"
0068 
0069 /**
0070  *  @brief RTEMS Associate Pointer by Name
0071  */
0072 const rtems_assoc_t *rtems_assoc_ptr_by_name(
0073   const rtems_assoc_t *,
0074   const char *
0075 );
0076 
0077 /**
0078  *  @brief RTEMS Associate Pointer by Remote
0079  */
0080 const rtems_assoc_t *rtems_assoc_ptr_by_remote(
0081   const rtems_assoc_t *,
0082   uint32_t
0083 );
0084 
0085 uint32_t rtems_assoc_remote_by_local(
0086   const rtems_assoc_t *,
0087   uint32_t
0088 );
0089 
0090 /**
0091  *  @brief RTEMS Associate Local by Remote
0092  */
0093 uint32_t rtems_assoc_local_by_remote(
0094   const rtems_assoc_t *,
0095   uint32_t
0096 );
0097 
0098 /**
0099  *  @brief RTEMS Associate Remote by Name
0100  */
0101 uint32_t rtems_assoc_remote_by_name(
0102   const rtems_assoc_t *,
0103   const char *
0104 );
0105 
0106 /**
0107  *  @brief RTEMS Associate Local by Name
0108  */
0109 uint32_t rtems_assoc_local_by_name(
0110   const rtems_assoc_t *,
0111   const char *
0112 );
0113 
0114 /**
0115  *  @brief RTEMS Associate Name by Local
0116  */
0117 const char *rtems_assoc_name_by_local(
0118   const rtems_assoc_t *,
0119   uint32_t
0120 );
0121 
0122 /**
0123  *  @brief RTEMS Associate Name by Remote
0124  */
0125 const char *rtems_assoc_name_by_remote(
0126   const rtems_assoc_t *,
0127   uint32_t
0128 );
0129 
0130 /**
0131  *  @brief RTEMS Assoc Routines
0132  */
0133 uint32_t rtems_assoc_remote_by_local_bitfield(
0134   const rtems_assoc_t *,
0135   uint32_t
0136 );
0137 
0138 /**
0139  *  @brief RTEMS Associate Name by Local Bitfield
0140  */
0141 char *rtems_assoc_name_by_local_bitfield(
0142   const rtems_assoc_t *,
0143   uint32_t  ,
0144   char *
0145 );
0146 
0147 /**
0148  *  @brief RTEMS Associate Name by Remote Bitfield
0149  */
0150 char *rtems_assoc_name_by_remote_bitfield(
0151   const rtems_assoc_t *,
0152   uint32_t  ,
0153   char *
0154 );
0155 
0156 uint32_t     rtems_assoc_local_by_remote_bitfield(
0157   const rtems_assoc_t *,
0158   uint32_t
0159 );
0160 
0161 /**
0162  *  @brief RTEMS Associate Pointer by Local
0163  */
0164 const rtems_assoc_t *rtems_assoc_ptr_by_local(
0165   const rtems_assoc_t *ap,
0166   uint32_t             local_value
0167 );
0168 
0169 #if defined(INSIDE_ASSOC)
0170 
0171 #define rtems_assoc_is_default(_ap) \
0172   ((_ap)->name && !strcmp((_ap)->name, RTEMS_ASSOC_DEFAULT_NAME))
0173 
0174 /**
0175  *  @brief RTEMS Associate Bad Name
0176  *
0177  *  what to return if a value is not found
0178  *  this is not reentrant, but it really shouldn't be invoked anyway
0179  */
0180 const char *rtems_assoc_name_bad(
0181   uint32_t   bad_value
0182 );
0183 #endif
0184 
0185 typedef struct {
0186   uint32_t    bits;
0187   const char *name;
0188 } rtems_assoc_32_pair;
0189 
0190 /**
0191  * @brief Converts the specified value into a text representation.
0192  *
0193  * @param[in] value The value to convert.
0194  * @param[in] buffer The buffer for the text representation.
0195  * @param[in] buffer_size The buffer size in characters.
0196  * @param[in] pairs Names for particular bits.
0197  * @param[in] pair_count Count of pairs.
0198  * @param[in] separator Separator between individual names.
0199  * @param[in] fallback Fallback value in case no bits contained in the pairs
0200  *   are set in the value.
0201  *
0202  * @retval The length of the text representation.  May be greater than or equal
0203  * to the buffer size if truncation occurred.
0204  */
0205 size_t rtems_assoc_32_to_string(
0206   uint32_t                   value,
0207   char                      *buffer,
0208   size_t                     buffer_size,
0209   const rtems_assoc_32_pair *pairs,
0210   size_t                     pair_count,
0211   const char                *separator,
0212   const char                *fallback
0213 );
0214 
0215 /**
0216  * @brief Converts the specified thread states into a text representation.
0217  *
0218  * @param[in] states The thread states to convert.
0219  * @param[in] buffer The buffer for the text representation.
0220  * @param[in] buffer_size The buffer size in characters.
0221  *
0222  * @retval The length of the text representation.  May be greater than or equal
0223  * to the buffer size if truncation occurred.
0224  */
0225 size_t rtems_assoc_thread_states_to_string(
0226   uint32_t  states,
0227   char     *buffer,
0228   size_t    buffer_size
0229 );
0230 
0231 /** @} */
0232 
0233 #ifdef __cplusplus
0234 }
0235 #endif
0236 
0237 #endif /* ! _RTEMS_RTEMS_ASSOC_H */