[4d3017a] | 1 | /** |
---|
| 2 | * @file rtems/assoc.h |
---|
[21242c2] | 3 | * |
---|
[c5782a2] | 4 | * @brief RTEMS Associativity Routines |
---|
| 5 | * |
---|
[21242c2] | 6 | * RTEMS associativity routines. Mainly used to convert a value from |
---|
| 7 | * one space to another (eg: our errno's to host errno's and vice-versa) |
---|
[4d3017a] | 8 | */ |
---|
| 9 | |
---|
[b06e68ef] | 10 | |
---|
[7945944] | 11 | #ifndef _RTEMS_RTEMS_ASSOC_H |
---|
| 12 | #define _RTEMS_RTEMS_ASSOC_H |
---|
[b06e68ef] | 13 | |
---|
[ceaa999] | 14 | /** |
---|
[b8fc260f] | 15 | * @defgroup Associativity Associativity Routines |
---|
[ceaa999] | 16 | */ |
---|
| 17 | /**@{*/ |
---|
| 18 | |
---|
[0c43130] | 19 | #include <stddef.h> |
---|
| 20 | #include <stdint.h> |
---|
[b0ddb61] | 21 | |
---|
| 22 | #ifdef __cplusplus |
---|
| 23 | extern "C" { |
---|
| 24 | #endif |
---|
| 25 | |
---|
[b06e68ef] | 26 | typedef struct { |
---|
[cd225515] | 27 | const char *name; |
---|
[83c5fc1] | 28 | uint32_t local_value; |
---|
| 29 | uint32_t remote_value; |
---|
[b06e68ef] | 30 | } rtems_assoc_t; |
---|
| 31 | |
---|
| 32 | /* |
---|
| 33 | * Flag/marker for optional default value in each table |
---|
| 34 | */ |
---|
| 35 | |
---|
| 36 | #define RTEMS_ASSOC_DEFAULT_NAME "(default)" |
---|
| 37 | |
---|
[bcd0ea64] | 38 | /** |
---|
| 39 | * @brief RTEMS Associate Pointer by Name |
---|
| 40 | */ |
---|
[9d52e69] | 41 | const rtems_assoc_t *rtems_assoc_ptr_by_name( |
---|
| 42 | const rtems_assoc_t *, |
---|
| 43 | const char * |
---|
| 44 | ); |
---|
[b06e68ef] | 45 | |
---|
[3750995] | 46 | /** |
---|
| 47 | * @brief RTEMS Associate Pointer by Remote |
---|
| 48 | */ |
---|
[9d52e69] | 49 | const rtems_assoc_t *rtems_assoc_ptr_by_remote( |
---|
| 50 | const rtems_assoc_t *, |
---|
| 51 | uint32_t |
---|
| 52 | ); |
---|
| 53 | |
---|
| 54 | uint32_t rtems_assoc_remote_by_local( |
---|
| 55 | const rtems_assoc_t *, |
---|
| 56 | uint32_t |
---|
| 57 | ); |
---|
| 58 | |
---|
[3750995] | 59 | /** |
---|
| 60 | * @brief RTEMS Associate Local by Remote |
---|
| 61 | */ |
---|
[9d52e69] | 62 | uint32_t rtems_assoc_local_by_remote( |
---|
| 63 | const rtems_assoc_t *, |
---|
| 64 | uint32_t |
---|
| 65 | ); |
---|
| 66 | |
---|
[bcd0ea64] | 67 | /** |
---|
| 68 | * @brief RTEMS Associate Remote by Name |
---|
| 69 | */ |
---|
[9d52e69] | 70 | uint32_t rtems_assoc_remote_by_name( |
---|
| 71 | const rtems_assoc_t *, |
---|
[cd225515] | 72 | const char * |
---|
| 73 | ); |
---|
[ceaa999] | 74 | |
---|
| 75 | /** |
---|
| 76 | * @brief RTEMS Associate Local by Name |
---|
| 77 | */ |
---|
[9d52e69] | 78 | uint32_t rtems_assoc_local_by_name( |
---|
| 79 | const rtems_assoc_t *, |
---|
[cd225515] | 80 | const char * |
---|
| 81 | ); |
---|
[9d52e69] | 82 | |
---|
[cc390b62] | 83 | /** |
---|
| 84 | * @brief RTEMS Associate Name by Local |
---|
| 85 | */ |
---|
[9d52e69] | 86 | const char *rtems_assoc_name_by_local( |
---|
| 87 | const rtems_assoc_t *, |
---|
| 88 | uint32_t |
---|
| 89 | ); |
---|
| 90 | |
---|
[cefc9aea] | 91 | /** |
---|
| 92 | * @brief RTEMS Associate Name by Remote |
---|
| 93 | */ |
---|
[9d52e69] | 94 | const char *rtems_assoc_name_by_remote( |
---|
| 95 | const rtems_assoc_t *, |
---|
| 96 | uint32_t |
---|
| 97 | ); |
---|
| 98 | |
---|
[ceaa999] | 99 | /** |
---|
| 100 | * @brief RTEMS Assoc Routines |
---|
| 101 | */ |
---|
[9d52e69] | 102 | uint32_t rtems_assoc_remote_by_local_bitfield( |
---|
| 103 | const rtems_assoc_t *, |
---|
| 104 | uint32_t |
---|
| 105 | ); |
---|
| 106 | |
---|
[cc390b62] | 107 | /** |
---|
| 108 | * @brief RTEMS Associate Name by Local Bitfield |
---|
| 109 | */ |
---|
[9d52e69] | 110 | char *rtems_assoc_name_by_local_bitfield( |
---|
| 111 | const rtems_assoc_t *, |
---|
| 112 | uint32_t , |
---|
| 113 | char * |
---|
| 114 | ); |
---|
| 115 | |
---|
[c9bb60a] | 116 | /** |
---|
| 117 | * @brief RTEMS Associate Name by Remote Bitfield |
---|
| 118 | */ |
---|
[9d52e69] | 119 | char *rtems_assoc_name_by_remote_bitfield( |
---|
| 120 | const rtems_assoc_t *, |
---|
| 121 | uint32_t , |
---|
| 122 | char * |
---|
| 123 | ); |
---|
| 124 | |
---|
| 125 | uint32_t rtems_assoc_local_by_remote_bitfield( |
---|
| 126 | const rtems_assoc_t *, |
---|
| 127 | uint32_t |
---|
| 128 | ); |
---|
| 129 | |
---|
[17c6ad6a] | 130 | /** |
---|
| 131 | * @brief RTEMS Associate Pointer by Local |
---|
| 132 | */ |
---|
[2f44708] | 133 | const rtems_assoc_t *rtems_assoc_ptr_by_local( |
---|
| 134 | const rtems_assoc_t *ap, |
---|
| 135 | uint32_t local_value |
---|
| 136 | ); |
---|
| 137 | |
---|
[9d52e69] | 138 | #if defined(INSIDE_ASSOC) |
---|
| 139 | |
---|
| 140 | #define rtems_assoc_is_default(_ap) \ |
---|
| 141 | ((_ap)->name && !strcmp((_ap)->name, RTEMS_ASSOC_DEFAULT_NAME)) |
---|
| 142 | |
---|
[cc390b62] | 143 | /** |
---|
| 144 | * @brief RTEMS Associate Bad Name |
---|
[c5782a2] | 145 | * |
---|
[cc390b62] | 146 | * what to return if a value is not found |
---|
| 147 | * this is not reentrant, but it really shouldn't be invoked anyway |
---|
[9d52e69] | 148 | */ |
---|
| 149 | const char *rtems_assoc_name_bad( |
---|
| 150 | uint32_t bad_value |
---|
| 151 | ); |
---|
| 152 | #endif |
---|
[b06e68ef] | 153 | |
---|
[0c43130] | 154 | typedef struct { |
---|
| 155 | uint32_t bits; |
---|
| 156 | const char *name; |
---|
| 157 | } rtems_assoc_32_pair; |
---|
| 158 | |
---|
| 159 | /** |
---|
| 160 | * @brief Converts the specified value into a text representation. |
---|
| 161 | * |
---|
| 162 | * @param[in] value The value to convert. |
---|
| 163 | * @param[in] buffer The buffer for the text representation. |
---|
| 164 | * @param[in] buffer_size The buffer size in characters. |
---|
| 165 | * @param[in] pairs Names for particular bits. |
---|
| 166 | * @param[in] pair_count Count of pairs. |
---|
| 167 | * @param[in] separator Separator between individual names. |
---|
| 168 | * @param[in] fallback Fallback value in case no bits contained in the pairs |
---|
| 169 | * are set in the value. |
---|
| 170 | * |
---|
| 171 | * @retval The length of the text representation. May be greater than the |
---|
| 172 | * buffer size if truncation occurred. |
---|
| 173 | */ |
---|
| 174 | size_t rtems_assoc_32_to_string( |
---|
| 175 | uint32_t value, |
---|
| 176 | char *buffer, |
---|
| 177 | size_t buffer_size, |
---|
| 178 | const rtems_assoc_32_pair *pairs, |
---|
| 179 | size_t pair_count, |
---|
| 180 | const char *separator, |
---|
| 181 | const char *fallback |
---|
| 182 | ); |
---|
| 183 | |
---|
[a3730b38] | 184 | /** |
---|
| 185 | * @brief Converts the specified thread states into a text representation. |
---|
| 186 | * |
---|
| 187 | * @param[in] states The thread states to convert. |
---|
| 188 | * @param[in] buffer The buffer for the text representation. |
---|
| 189 | * @param[in] buffer_size The buffer size in characters. |
---|
| 190 | * |
---|
| 191 | * @retval The length of the text representation. May be greater than the |
---|
| 192 | * buffer size if truncation occurred. |
---|
| 193 | */ |
---|
| 194 | size_t rtems_assoc_thread_states_to_string( |
---|
| 195 | uint32_t states, |
---|
| 196 | char *buffer, |
---|
| 197 | size_t buffer_size |
---|
| 198 | ); |
---|
| 199 | |
---|
[b0ddb61] | 200 | #ifdef __cplusplus |
---|
| 201 | } |
---|
| 202 | #endif |
---|
[ceaa999] | 203 | /**@}*/ |
---|
[b0ddb61] | 204 | #endif /* ! _RTEMS_RTEMS_ASSOC_H */ |
---|