RTEMS
6.3
Toggle main menu visibility
Loading...
Searching...
No Matches
bsps
include
bsp
utility.h
Go to the documentation of this file.
1
/* SPDX-License-Identifier: BSD-2-Clause */
2
10
11
/*
12
* Copyright (C) 2008, 2011 embedded brains GmbH & Co. KG
13
*
14
* Redistribution and use in source and binary forms, with or without
15
* modification, are permitted provided that the following conditions
16
* are met:
17
* 1. Redistributions of source code must retain the above copyright
18
* notice, this list of conditions and the following disclaimer.
19
* 2. Redistributions in binary form must reproduce the above copyright
20
* notice, this list of conditions and the following disclaimer in the
21
* documentation and/or other materials provided with the distribution.
22
*
23
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
24
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
27
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
28
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
29
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
30
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
31
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
32
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33
* POSSIBILITY OF SUCH DAMAGE.
34
*/
35
36
#ifndef LIBCPU_SHARED_UTILITY_H
37
#define LIBCPU_SHARED_UTILITY_H
38
39
#include <stdint.h>
40
41
#define BSP_BIT8(bit) \
42
((uint8_t) (((unsigned int) 1) << (bit)))
43
44
#define BSP_MSK8(first_bit, last_bit) \
45
((uint8_t) ((BSP_BIT8((last_bit) - (first_bit) + 1) - 1) << (first_bit)))
46
47
#define BSP_FLD8(val, first_bit, last_bit) \
48
((uint8_t) \
49
((((unsigned int) (val)) << (first_bit)) & BSP_MSK8(first_bit, last_bit)))
50
51
#define BSP_FLD8GET(reg, first_bit, last_bit) \
52
((uint8_t) (((reg) & BSP_MSK8(first_bit, last_bit)) >> (first_bit)))
53
54
#define BSP_FLD8SET(reg, val, first_bit, last_bit) \
55
((uint8_t) (((reg) & ~BSP_MSK8(first_bit, last_bit)) \
56
| BSP_FLD8(val, first_bit, last_bit)))
57
58
#define BSP_BIT16(bit) \
59
((uint16_t) (((unsigned int) 1) << (bit)))
60
61
#define BSP_MSK16(first_bit, last_bit) \
62
((uint16_t) ((BSP_BIT16((last_bit) - (first_bit) + 1) - 1) << (first_bit)))
63
64
#define BSP_FLD16(val, first_bit, last_bit) \
65
((uint16_t) \
66
((((unsigned int) (val)) << (first_bit)) & BSP_MSK16(first_bit, last_bit)))
67
68
#define BSP_FLD16GET(reg, first_bit, last_bit) \
69
((uint16_t) (((reg) & BSP_MSK16(first_bit, last_bit)) >> (first_bit)))
70
71
#define BSP_FLD16SET(reg, val, first_bit, last_bit) \
72
((uint16_t) (((reg) & ~BSP_MSK16(first_bit, last_bit)) \
73
| BSP_FLD16(val, first_bit, last_bit)))
74
75
#define BSP_BIT32(bit) \
76
((uint32_t) (((uint32_t) 1) << (bit)))
77
78
#define BSP_MSK32(first_bit, last_bit) \
79
((uint32_t) ((BSP_BIT32((last_bit) - (first_bit) + 1) - 1) << (first_bit)))
80
81
#define BSP_FLD32(val, first_bit, last_bit) \
82
((uint32_t) \
83
((((uint32_t) (val)) << (first_bit)) & BSP_MSK32(first_bit, last_bit)))
84
85
#define BSP_FLD32GET(reg, first_bit, last_bit) \
86
((uint32_t) (((reg) & BSP_MSK32(first_bit, last_bit)) >> (first_bit)))
87
88
#define BSP_FLD32SET(reg, val, first_bit, last_bit) \
89
((uint32_t) (((reg) & ~BSP_MSK32(first_bit, last_bit)) \
90
| BSP_FLD32(val, first_bit, last_bit)))
91
92
#define BSP_BIT64(bit) \
93
((uint64_t) (((uint64_t) 1) << (bit)))
94
95
#define BSP_MSK64(first_bit, last_bit) \
96
((uint64_t) ((BSP_BIT64((last_bit) - (first_bit) + 1) - 1) << (first_bit)))
97
98
#define BSP_FLD64(val, first_bit, last_bit) \
99
((uint64_t) \
100
((((uint64_t) (val)) << (first_bit)) & BSP_MSK64(first_bit, last_bit)))
101
102
#define BSP_FLD64GET(reg, first_bit, last_bit) \
103
((uint64_t) (((reg) & BSP_MSK64(first_bit, last_bit)) >> (first_bit)))
104
105
#define BSP_FLD64SET(reg, val, first_bit, last_bit) \
106
((uint64_t) (((reg) & ~BSP_MSK64(first_bit, last_bit)) \
107
| BSP_FLD64(val, first_bit, last_bit)))
108
109
#define BSP_BBIT8(bit) \
110
BSP_BIT8(7 - (bit))
111
112
#define BSP_BMSK8(first_bit, last_bit) \
113
BSP_MSK8(7 - (last_bit), 7 - (first_bit))
114
115
#define BSP_BFLD8(val, first_bit, last_bit) \
116
BSP_FLD8(val, 7 - (last_bit), 7 - (first_bit))
117
118
#define BSP_BFLD8GET(reg, first_bit, last_bit) \
119
BSP_FLD8GET(reg, 7 - (last_bit), 7 - (first_bit))
120
121
#define BSP_BFLD8SET(reg, val, first_bit, last_bit) \
122
BSP_FLD8SET(reg, val, 7 - (last_bit), 7 - (first_bit))
123
124
#define BSP_BBIT16(bit) \
125
BSP_BIT16(15 - (bit))
126
127
#define BSP_BMSK16(first_bit, last_bit) \
128
BSP_MSK16(15 - (last_bit), 15 - (first_bit))
129
130
#define BSP_BFLD16(val, first_bit, last_bit) \
131
BSP_FLD16(val, 15 - (last_bit), 15 - (first_bit))
132
133
#define BSP_BFLD16GET(reg, first_bit, last_bit) \
134
BSP_FLD16GET(reg, 15 - (last_bit), 15 - (first_bit))
135
136
#define BSP_BFLD16SET(reg, val, first_bit, last_bit) \
137
BSP_FLD16SET(reg, val, 15 - (last_bit), 15 - (first_bit))
138
139
#define BSP_BBIT32(bit) \
140
BSP_BIT32(31 - (bit))
141
142
#define BSP_BMSK32(first_bit, last_bit) \
143
BSP_MSK32(31 - (last_bit), 31 - (first_bit))
144
145
#define BSP_BFLD32(val, first_bit, last_bit) \
146
BSP_FLD32(val, 31 - (last_bit), 31 - (first_bit))
147
148
#define BSP_BFLD32GET(reg, first_bit, last_bit) \
149
BSP_FLD32GET(reg, 31 - (last_bit), 31 - (first_bit))
150
151
#define BSP_BFLD32SET(reg, val, first_bit, last_bit) \
152
BSP_FLD32SET(reg, val, 31 - (last_bit), 31 - (first_bit))
153
154
#define BSP_BBIT64(bit) \
155
BSP_BIT64(63 - (bit))
156
157
#define BSP_BMSK64(first_bit, last_bit) \
158
BSP_MSK64(63 - (last_bit), 63 - (first_bit))
159
160
#define BSP_BFLD64(val, first_bit, last_bit) \
161
BSP_FLD64(val, 63 - (last_bit), 63 - (first_bit))
162
163
#define BSP_BFLD64GET(reg, first_bit, last_bit) \
164
BSP_FLD64GET(reg, 63 - (last_bit), 63 - (first_bit))
165
166
#define BSP_BFLD64SET(reg, val, first_bit, last_bit) \
167
BSP_FLD64SET(reg, val, 63 - (last_bit), 63 - (first_bit))
168
169
#endif
/* LIBCPU_SHARED_UTILITY_H */
Generated by
1.18.0