source: rtems/cpukit/include/rtems/score/address.h @ 5803f37

5
Last change on this file since 5803f37 was 93dcd2b, checked in by Andreas Dachsberger <andreas.dachsberger@…>, on 04/04/19 at 07:01:43

doxygen: score: adjust doc in address.h to doxygen guidelines

Update #3706.

  • Property mode set to 100644
File size: 5.2 KB
Line 
1/**
2 * @file
3 *
4 * @ingroup RTEMSScoreAddress
5 *
6 * @brief Information Required to Manipulate Physical Addresses
7 *
8 * This include file contains the information required to manipulate
9 * physical addresses.
10 */
11
12/*
13 *  COPYRIGHT (c) 1989-2006.
14 *  On-Line Applications Research Corporation (OAR).
15 *
16 *  The license and distribution terms for this file may be
17 *  found in the file LICENSE in this distribution or at
18 *  http://www.rtems.org/license/LICENSE.
19 */
20
21#ifndef _RTEMS_SCORE_ADDRESS_H
22#define _RTEMS_SCORE_ADDRESS_H
23
24#include <rtems/score/cpu.h>
25
26#ifdef __cplusplus
27extern "C" {
28#endif
29
30/**
31 * @defgroup RTEMSScoreAddress Address Handler
32 *
33 * @ingroup RTEMSScore
34 *
35 * @brief Support for Address Manipulation
36 *
37 * This handler encapsulates functionality which abstracts address
38 * manipulation in a portable manner.
39 *
40 * @{
41 */
42
43/**
44 * @brief Adds offset to an address.
45 *
46 * This function is used to add an @a offset to a @a base address.
47 * It returns the resulting address.  This address is typically
48 * converted to an access type before being used further.
49 *
50 * @param base The base address to add the offset to.
51 * @param offset The offset to add to @a base.
52 *
53 * @return This method returns the resulting address.
54 */
55RTEMS_INLINE_ROUTINE void *_Addresses_Add_offset (
56  const void *base,
57  uintptr_t   offset
58)
59{
60  return (void *)((uintptr_t)base + offset);
61}
62
63/**
64 * @brief Subtracts offset from an address.
65 *
66 * This function is used to subtract an @a offset from a @a base
67 * address.  It returns the resulting address.  This address is
68 * typically converted to an access type before being used further.
69 *
70 * @param base The base address to subtract the offset from.
71 * @param offset The offset to subtract from @a base.
72 *
73 * @return This method returns the resulting address.
74 */
75
76RTEMS_INLINE_ROUTINE void *_Addresses_Subtract_offset (
77  const void *base,
78  uintptr_t   offset
79)
80{
81  return (void *)((uintptr_t)base - offset);
82}
83
84/**
85 * @brief Subtracts two addresses.
86 *
87 * This function is used to subtract two addresses.  It returns the
88 * resulting offset.
89 *
90 * @param left The address on the left hand side of the subtraction.
91 * @param right The address on the right hand side of the subtraction.
92 *
93 * @return This method returns the resulting address.
94 */
95RTEMS_INLINE_ROUTINE intptr_t _Addresses_Subtract(
96  const void *left,
97  const void *right
98)
99{
100  return (intptr_t) ( (const char *) left - (const char *) right );
101}
102
103/**
104 * @brief Checks if address is aligned.
105 *
106 * This function returns true if the given address is correctly
107 * aligned for this processor and false otherwise.  Proper alignment
108 * is based on correctness and efficiency.
109 *
110 * @param address The address being checked for alignment.
111 *
112 * @retval true The @a address is aligned.
113 * @retval false The @a address is not aligned.
114 */
115RTEMS_INLINE_ROUTINE bool _Addresses_Is_aligned(
116  const void *address
117)
118{
119  return ( (uintptr_t) address % CPU_ALIGNMENT ) == 0;
120}
121
122/**
123 * @brief Checks if address is in range.
124 *
125 * This function returns true if the given address is within the
126 * memory range specified and false otherwise.  @a base is the address
127 * of the first byte in the memory range and @a limit is the address
128 * of the last byte in the memory range.  The base address is
129 * assumed to be lower than the limit address.
130 *
131 * @param address The address to check if it is in the given range.
132 * @param base The lowest address of the range to check against.
133 * @param limit The highest address of the range to check against.
134 *
135 * @retval true The @a address is within the memory range specified
136 * @retval false The @a address is not within the memory range specified.
137 */
138RTEMS_INLINE_ROUTINE bool _Addresses_Is_in_range (
139  const void *address,
140  const void *base,
141  const void *limit
142)
143{
144  return (address >= base && address <= limit);
145}
146
147/**
148 * @brief Aligns address to nearest multiple of alignment, rounding up.
149 *
150 * This function returns the given address aligned to the given alignment.
151 * If the address already is aligned, or if alignment is 0, the address is
152 * returned as is. The returned address is greater than or equal to the
153 * given address.
154 *
155 * @param address The address to align to the given alignment.
156 * @param alignment The desired alignment for the address. It must be a power of two.
157 *
158 * @return Returns the aligned address.
159 */
160RTEMS_INLINE_ROUTINE void *_Addresses_Align_up(
161  void *address,
162  size_t alignment
163)
164{
165  uintptr_t mask = alignment - (uintptr_t)1;
166  return (void*)(((uintptr_t)address + mask) & ~mask);
167}
168
169/**
170 * @brief Aligns address to nearest multiple of alignment, truncating.
171 *
172 * This function returns the given address aligned to the given alignment.
173 * If the address already is aligned, or if alignment is 0, the address is
174 * returned as is. The returned address is less than or equal to the
175 * given address.
176 *
177 * @param address The address to align to the given alignment.
178 * @param alignment The desired alignment for the address. It must be a power of two.
179 *
180 * @return Returns the aligned address.
181 */
182RTEMS_INLINE_ROUTINE void *_Addresses_Align_down(
183  void *address,
184  size_t alignment
185)
186{
187  uintptr_t mask = alignment - (uintptr_t)1;
188  return (void*)((uintptr_t)address & ~mask);
189}
190
191/** @} */
192
193#ifdef __cplusplus
194}
195#endif
196
197#endif
198/* end of include file */
Note: See TracBrowser for help on using the repository browser.