source: rtems/cpukit/libcsupport/include/rtems/assoc.h @ 0c43130

5
Last change on this file since 0c43130 was 0c43130, checked in by Sebastian Huber <sebastian.huber@…>, on 01/11/17 at 10:03:24

Add rtems_assoc_32_to_string()

  • Property mode set to 100644
File size: 3.7 KB
Line 
1/**
2 * @file rtems/assoc.h
3 *
4 * @brief RTEMS Associativity Routines
5 *
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)
8 */
9
10
11#ifndef _RTEMS_RTEMS_ASSOC_H
12#define _RTEMS_RTEMS_ASSOC_H
13
14/**
15 *  @defgroup Associativity Associativity Routines
16 */
17/**@{*/
18
19#include <stddef.h>
20#include <stdint.h>
21
22#ifdef __cplusplus
23extern "C" {
24#endif
25
26typedef struct {
27    const char  *name;
28    uint32_t     local_value;
29    uint32_t     remote_value;
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
38/**
39 *  @brief RTEMS Associate Pointer by Name
40 */
41const rtems_assoc_t *rtems_assoc_ptr_by_name(
42  const rtems_assoc_t *,
43  const char *
44);
45
46/**
47 *  @brief RTEMS Associate Pointer by Remote
48 */
49const rtems_assoc_t *rtems_assoc_ptr_by_remote(
50  const rtems_assoc_t *,
51  uint32_t
52);
53
54uint32_t rtems_assoc_remote_by_local(
55  const rtems_assoc_t *,
56  uint32_t
57);
58
59/**
60 *  @brief RTEMS Associate Local by Remote
61 */
62uint32_t rtems_assoc_local_by_remote(
63  const rtems_assoc_t *,
64  uint32_t
65);
66
67/**
68 *  @brief RTEMS Associate Remote by Name
69 */
70uint32_t rtems_assoc_remote_by_name(
71  const rtems_assoc_t *,
72  const char *
73);
74
75/**
76 *  @brief RTEMS Associate Local by Name
77 */
78uint32_t rtems_assoc_local_by_name(
79  const rtems_assoc_t *,
80  const char *
81);
82
83/**
84 *  @brief RTEMS Associate Name by Local
85 */
86const char *rtems_assoc_name_by_local(
87  const rtems_assoc_t *,
88  uint32_t
89);
90
91/**
92 *  @brief RTEMS Associate Name by Remote
93 */
94const char *rtems_assoc_name_by_remote(
95  const rtems_assoc_t *,
96  uint32_t
97);
98
99/**
100 *  @brief RTEMS Assoc Routines
101 */
102uint32_t rtems_assoc_remote_by_local_bitfield(
103  const rtems_assoc_t *,
104  uint32_t
105);
106
107/**
108 *  @brief RTEMS Associate Name by Local Bitfield
109 */
110char *rtems_assoc_name_by_local_bitfield(
111  const rtems_assoc_t *,
112  uint32_t  ,
113  char *
114);
115
116/**
117 *  @brief RTEMS Associate Name by Remote Bitfield
118 */
119char *rtems_assoc_name_by_remote_bitfield(
120  const rtems_assoc_t *,
121  uint32_t  ,
122  char *
123);
124
125uint32_t     rtems_assoc_local_by_remote_bitfield(
126  const rtems_assoc_t *,
127  uint32_t
128);
129
130/**
131 *  @brief RTEMS Associate Pointer by Local
132 */
133const rtems_assoc_t *rtems_assoc_ptr_by_local(
134  const rtems_assoc_t *ap,
135  uint32_t             local_value
136);
137
138#if defined(INSIDE_ASSOC)
139
140#define rtems_assoc_is_default(_ap) \
141  ((_ap)->name && !strcmp((_ap)->name, RTEMS_ASSOC_DEFAULT_NAME))
142
143/**
144 *  @brief RTEMS Associate Bad Name
145 *
146 *  what to return if a value is not found
147 *  this is not reentrant, but it really shouldn't be invoked anyway
148 */
149const char *rtems_assoc_name_bad(
150  uint32_t   bad_value
151);
152#endif
153
154typedef 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 */
174size_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
184#ifdef __cplusplus
185}
186#endif
187/**@}*/
188#endif /* ! _RTEMS_RTEMS_ASSOC_H */
Note: See TracBrowser for help on using the repository browser.