source: rtems/cpukit/include/rtems/rtems/support.h

Last change on this file was bcef89f2, checked in by Sebastian Huber <sebastian.huber@…>, on 05/19/23 at 06:18:25

Update company name

The embedded brains GmbH & Co. KG is the legal successor of embedded
brains GmbH.

  • Property mode set to 100644
File size: 12.2 KB
Line 
1/* SPDX-License-Identifier: BSD-2-Clause */
2
3/**
4 * @file
5 *
6 * @ingroup RTEMSImplClassic
7 *
8 * @brief This header file defines support services of the API.
9 */
10
11/*
12 * Copyright (C) 2020, 2021 embedded brains GmbH & Co. KG
13 * Copyright (C) 1988, 2008 On-Line Applications Research Corporation (OAR)
14 *
15 * Redistribution and use in source and binary forms, with or without
16 * modification, are permitted provided that the following conditions
17 * are met:
18 * 1. Redistributions of source code must retain the above copyright
19 *    notice, this list of conditions and the following disclaimer.
20 * 2. Redistributions in binary form must reproduce the above copyright
21 *    notice, this list of conditions and the following disclaimer in the
22 *    documentation and/or other materials provided with the distribution.
23 *
24 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
25 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
28 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
29 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
30 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
31 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
32 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
33 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
34 * POSSIBILITY OF SUCH DAMAGE.
35 */
36
37/*
38 * This file is part of the RTEMS quality process and was automatically
39 * generated.  If you find something that needs to be fixed or
40 * worded better please post a report or patch to an RTEMS mailing list
41 * or raise a bug report:
42 *
43 * https://www.rtems.org/bugs.html
44 *
45 * For information on updating and regenerating please refer to the How-To
46 * section in the Software Requirements Engineering chapter of the
47 * RTEMS Software Engineering manual.  The manual is provided as a part of
48 * a release.  For development sources please refer to the online
49 * documentation at:
50 *
51 * https://docs.rtems.org
52 */
53
54/* Generated from spec:/rtems/support/if/header */
55
56#ifndef _RTEMS_RTEMS_SUPPORT_H
57#define _RTEMS_RTEMS_SUPPORT_H
58
59#include <stdbool.h>
60#include <stddef.h>
61#include <stdint.h>
62#include <rtems/config.h>
63#include <rtems/rtems/types.h>
64#include <rtems/score/heapinfo.h>
65
66#ifdef __cplusplus
67extern "C" {
68#endif
69
70/* Generated from spec:/rtems/support/if/group */
71
72/**
73 * @defgroup RTEMSAPIClassicSupport Support Services
74 *
75 * @ingroup RTEMSAPIClassic
76 *
77 * @brief Items of this group should move to other groups.
78 */
79
80/* Generated from spec:/rtems/support/if/is-name-valid */
81
82/**
83 * @ingroup RTEMSAPIClassicSupport
84 *
85 * @brief Checks if the object name is valid.
86 *
87 * @param name is the object name to check.
88 *
89 * @return Returns true, if the object name is valid, otherwise false.
90 *
91 * @par Constraints
92 * @parblock
93 * The following constraints apply to this directive:
94 *
95 * * The directive may be called from within any runtime context.
96 *
97 * * The directive will not cause the calling task to be preempted.
98 * @endparblock
99 */
100static inline bool rtems_is_name_valid( rtems_name name )
101{
102  return name != 0;
103}
104
105/* Generated from spec:/rtems/support/if/microseconds-to-ticks */
106
107/**
108 * @ingroup RTEMSAPIClassicSupport
109 *
110 * @brief Gets the number of clock ticks for the microseconds value.
111 *
112 * @param _us is the microseconds value to convert to clock ticks.
113 *
114 * @return Returns the number of clock ticks for the specified microseconds
115 *   value.
116 *
117 * @par Notes
118 * The number of clock ticks per second is defined by the @ref
119 * CONFIGURE_MICROSECONDS_PER_TICK application configuration option.
120 *
121 * @par Constraints
122 * @parblock
123 * The following constraints apply to this directive:
124 *
125 * * The directive may be called from within any runtime context.
126 *
127 * * The directive will not cause the calling task to be preempted.
128 * @endparblock
129 */
130#define RTEMS_MICROSECONDS_TO_TICKS( _us ) \
131  ( ( _us ) / rtems_configuration_get_microseconds_per_tick() )
132
133/* Generated from spec:/rtems/support/if/milliseconds-to-microseconds */
134
135/**
136 * @ingroup RTEMSAPIClassicSupport
137 *
138 * @brief Gets the number of microseconds for the milliseconds value.
139 *
140 * @param _ms is the milliseconds value to convert to microseconds.
141 *
142 * @return Returns the number of microseconds for the milliseconds value.
143 *
144 * @par Constraints
145 * @parblock
146 * The following constraints apply to this directive:
147 *
148 * * The directive is implemented by a macro and may be called from within
149 *   C/C++ constant expressions.  In addition, a function implementation of the
150 *   directive exists for bindings to other programming languages.
151 *
152 * * The directive will not cause the calling task to be preempted.
153 * @endparblock
154 */
155#define RTEMS_MILLISECONDS_TO_MICROSECONDS( _ms ) ( ( _ms ) * 1000UL )
156
157/* Generated from spec:/rtems/support/if/milliseconds-to-ticks */
158
159/**
160 * @ingroup RTEMSAPIClassicSupport
161 *
162 * @brief Gets the number of clock ticks for the milliseconds value.
163 *
164 * @param _ms is the milliseconds value to convert to clock ticks.
165 *
166 * @return Returns the number of clock ticks for the milliseconds value.
167 *
168 * @par Notes
169 * The number of clock ticks per second is defined by the @ref
170 * CONFIGURE_MICROSECONDS_PER_TICK application configuration option.
171 *
172 * @par Constraints
173 * @parblock
174 * The following constraints apply to this directive:
175 *
176 * * The directive may be called from within any runtime context.
177 *
178 * * The directive will not cause the calling task to be preempted.
179 * @endparblock
180 */
181#define RTEMS_MILLISECONDS_TO_TICKS( _ms ) \
182  RTEMS_MICROSECONDS_TO_TICKS( RTEMS_MILLISECONDS_TO_MICROSECONDS( _ms ) )
183
184/* Generated from spec:/rtems/support/if/name-to-characters */
185
186/**
187 * @ingroup RTEMSAPIClassicSupport
188 *
189 * @brief Breaks the object name into the four component characters.
190 *
191 * @param name is the object name to break into four component characters.
192 *
193 * @param[out] c1 is the first character of the object name.
194 *
195 * @param[out] c2 is the second character of the object name.
196 *
197 * @param[out] c3 is the third character of the object name.
198 *
199 * @param[out] c4 is the fourth character of the object name.
200 *
201 * @par Constraints
202 * @parblock
203 * The following constraints apply to this directive:
204 *
205 * * The directive may be called from within any runtime context.
206 *
207 * * The directive will not cause the calling task to be preempted.
208 * @endparblock
209 */
210static inline void rtems_name_to_characters(
211  rtems_name name,
212  char      *c1,
213  char      *c2,
214  char      *c3,
215  char      *c4
216)
217{
218  *c1 = (char) ( ( ( name ) >> 24 ) & 0xff );
219  *c2 = (char) ( ( ( name ) >> 16 ) & 0xff );
220  *c3 = (char) ( ( ( name ) >> 8 ) & 0xff );
221  *c4 = (char) ( ( name ) & 0xff );
222}
223
224/* Generated from spec:/rtems/support/if/workspace-allocate */
225
226/**
227 * @ingroup RTEMSAPIClassicSupport
228 *
229 * @brief Allocates a memory area from the RTEMS Workspace.
230 *
231 * @param bytes is the number of bytes to allocated.
232 *
233 * @param[out] pointer is the pointer to a ``void`` pointer object.  When the
234 *   directive call is successful, the begin address of the allocated memory
235 *   area will be stored in this object.
236 *
237 * @return Returns true, if the allocation was successful, otherwise false.
238 *
239 * @par Notes
240 * This directive is intended to be used by tests of the RTEMS test suites.
241 *
242 * @par Constraints
243 * @parblock
244 * The following constraints apply to this directive:
245 *
246 * * The directive may be called from within device driver initialization
247 *   context.
248 *
249 * * The directive may be called from within task context.
250 *
251 * * The directive may obtain and release the object allocator mutex.  This may
252 *   cause the calling task to be preempted.
253 * @endparblock
254 */
255bool rtems_workspace_allocate( size_t bytes, void **pointer );
256
257/* Generated from spec:/rtems/support/if/workspace-free */
258
259/**
260 * @ingroup RTEMSAPIClassicSupport
261 *
262 * @brief Frees the memory area allocated from the RTEMS Workspace.
263 *
264 * @param pointer is the begin address of the memory area to free.
265 *
266 * @return Returns true, if freeing the memory area was successful, otherwise
267 *   false.
268 *
269 * @par Constraints
270 * @parblock
271 * The following constraints apply to this directive:
272 *
273 * * The directive may be called from within device driver initialization
274 *   context.
275 *
276 * * The directive may be called from within task context.
277 *
278 * * The directive may obtain and release the object allocator mutex.  This may
279 *   cause the calling task to be preempted.
280 * @endparblock
281 */
282bool rtems_workspace_free( void *pointer );
283
284/* Generated from spec:/rtems/support/if/workspace-get-information */
285
286/**
287 * @ingroup RTEMSAPIClassicSupport
288 *
289 * @brief Gets information about the RTEMS Workspace.
290 *
291 * @param[out] the_info is the pointer to a Heap_Information_block object.
292 *   When the directive call is successful, the heap information will be stored
293 *   in this object.
294 *
295 * @return Returns true, if getting the information was successful, otherwise
296 *   false.
297 *
298 * @par Constraints
299 * @parblock
300 * The following constraints apply to this directive:
301 *
302 * * The directive may be called from within device driver initialization
303 *   context.
304 *
305 * * The directive may be called from within task context.
306 *
307 * * The directive may obtain and release the object allocator mutex.  This may
308 *   cause the calling task to be preempted.
309 * @endparblock
310 */
311bool rtems_workspace_get_information( Heap_Information_block *the_info );
312
313/* Generated from spec:/rtems/support/if/workspace-greedy-allocate */
314
315/**
316 * @ingroup RTEMSAPIClassicSupport
317 *
318 * @brief Greedy allocates that empties the RTEMS Workspace.
319 *
320 * @param block_sizes is the array of block sizes.
321 *
322 * @param block_count is the block count.
323 *
324 * Afterwards the heap has at most ``block_count`` allocatable blocks of sizes
325 * specified by ``block_sizes``.  The ``block_sizes`` must point to an array
326 * with ``block_count`` members.  All other blocks are used.
327 *
328 * @return The returned pointer value may be used to free the greedy allocation
329 *   by calling rtems_workspace_greedy_free().
330 */
331void *rtems_workspace_greedy_allocate(
332  const uintptr_t *block_sizes,
333  size_t           block_count
334);
335
336/* Generated from spec:/rtems/support/if/workspace-greedy-allocate-all-except-largest */
337
338/**
339 * @ingroup RTEMSAPIClassicSupport
340 *
341 * @brief Greedy allocates all blocks of the RTEMS Workspace except the largest
342 *   free block.
343 *
344 * @param allocatable_size is the remaining allocatable size.
345 *
346 * Afterwards the heap has at most one allocatable block.  This block is the
347 * largest free block if it exists.  The allocatable size of this block is
348 * stored in ``allocatable_size``.  All other blocks are used.
349 *
350 * @return The returned pointer value may be used to free the greedy allocation
351 *   by calling rtems_workspace_greedy_free().
352 *
353 * @par Notes
354 * This directive is intended to be used by tests of the RTEMS test suites.
355 *
356 * @par Constraints
357 * @parblock
358 * The following constraints apply to this directive:
359 *
360 * * The directive may be called from within device driver initialization
361 *   context.
362 *
363 * * The directive may be called from within task context.
364 *
365 * * The directive may obtain and release the object allocator mutex.  This may
366 *   cause the calling task to be preempted.
367 * @endparblock
368 */
369void *rtems_workspace_greedy_allocate_all_except_largest(
370  uintptr_t *allocatable_size
371);
372
373/* Generated from spec:/rtems/support/if/workspace-greedy-free */
374
375/**
376 * @ingroup RTEMSAPIClassicSupport
377 *
378 * @brief Frees space of a greedy allocation to the RTEMS Workspace.
379 *
380 * @param opaque is the pointer value returned by
381 *   rtems_workspace_greedy_allocate() or
382 *   rtems_workspace_greedy_allocate_all_except_largest().
383 *
384 * @par Notes
385 * This directive is intended to be used by tests of the RTEMS test suites.
386 *
387 * @par Constraints
388 * @parblock
389 * The following constraints apply to this directive:
390 *
391 * * The directive may be called from within device driver initialization
392 *   context.
393 *
394 * * The directive may be called from within task context.
395 *
396 * * The directive may obtain and release the object allocator mutex.  This may
397 *   cause the calling task to be preempted.
398 * @endparblock
399 */
400void rtems_workspace_greedy_free( void *opaque );
401
402#ifdef __cplusplus
403}
404#endif
405
406#endif /* _RTEMS_RTEMS_SUPPORT_H */
Note: See TracBrowser for help on using the repository browser.