-
Notifications
You must be signed in to change notification settings - Fork 5.1k
/
Copy pathrttypes.h
258 lines (219 loc) · 9.35 KB
/
rttypes.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
/*
* Copyright (c) 2006-2024, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2024-01-18 Shell Separate the basic types from rtdef.h
*/
#ifndef __RT_TYPES_H__
#define __RT_TYPES_H__
#include <rtconfig.h>
#include <stdint.h>
#include <stddef.h>
#include <stdarg.h>
#ifndef RT_USING_NANO
#include <sys/types.h>
#include <sys/errno.h>
#if defined(RT_USING_SIGNALS) || defined(RT_USING_SMART)
#include <sys/signal.h>
#endif /* defined(RT_USING_SIGNALS) || defined(RT_USING_SMART) */
#endif /* RT_USING_NANO */
#ifdef __cplusplus
extern "C" {
#endif
/**
* RT-Thread basic data types definition
*/
#if defined(_WIN64) || defined(__x86_64__)
#ifndef ARCH_CPU_64BIT
#define ARCH_CPU_64BIT
#endif // ARCH_CPU_64BIT
#endif // defined(_WIN64) || defined(__x86_64__)
typedef int rt_bool_t; /**< boolean type */
#ifndef RT_USING_ARCH_DATA_TYPE
#ifdef RT_USING_LIBC
typedef int8_t rt_int8_t; /**< 8bit integer type */
typedef int16_t rt_int16_t; /**< 16bit integer type */
typedef int32_t rt_int32_t; /**< 32bit integer type */
typedef uint8_t rt_uint8_t; /**< 8bit unsigned integer type */
typedef uint16_t rt_uint16_t; /**< 16bit unsigned integer type */
typedef uint32_t rt_uint32_t; /**< 32bit unsigned integer type */
typedef int64_t rt_int64_t; /**< 64bit integer type */
typedef uint64_t rt_uint64_t; /**< 64bit unsigned integer type */
#else
typedef signed char rt_int8_t; /**< 8bit integer type */
typedef signed short rt_int16_t; /**< 16bit integer type */
typedef signed int rt_int32_t; /**< 32bit integer type */
typedef unsigned char rt_uint8_t; /**< 8bit unsigned integer type */
typedef unsigned short rt_uint16_t; /**< 16bit unsigned integer type */
typedef unsigned int rt_uint32_t; /**< 32bit unsigned integer type */
#ifdef ARCH_CPU_64BIT
typedef signed long rt_int64_t; /**< 64bit integer type */
typedef unsigned long rt_uint64_t; /**< 64bit unsigned integer type */
#else
typedef signed long long rt_int64_t; /**< 64bit integer type */
typedef unsigned long long rt_uint64_t; /**< 64bit unsigned integer type */
#endif /* ARCH_CPU_64BIT */
#endif /* RT_USING_LIBC */
#endif /* RT_USING_ARCH_DATA_TYPE */
#ifdef ARCH_CPU_64BIT
typedef rt_int64_t rt_base_t; /**< Nbit CPU related data type */
typedef rt_uint64_t rt_ubase_t; /**< Nbit unsigned CPU related data type */
#else
typedef rt_int32_t rt_base_t; /**< Nbit CPU related data type */
typedef rt_uint32_t rt_ubase_t; /**< Nbit unsigned CPU related data type */
#endif
#if defined(RT_USING_LIBC) && !defined(RT_USING_NANO)
typedef size_t rt_size_t; /**< Type for size number */
typedef ssize_t rt_ssize_t; /**< Used for a count of bytes or an error indication */
typedef intptr_t rt_intptr_t; /**< Type for signed pointer length integer */
typedef uintptr_t rt_uintptr_t; /**< Type for unsigned pointer length integer */
#else
typedef rt_ubase_t rt_size_t; /**< Type for size number */
typedef rt_base_t rt_ssize_t; /**< Used for a count of bytes or an error indication */
typedef rt_base_t rt_intptr_t; /**< Type for signed pointer length integer */
typedef rt_ubase_t rt_uintptr_t; /**< Type for unsigned pointer length integer */
#endif /* defined(RT_USING_LIBC) && !defined(RT_USING_NANO) */
typedef rt_base_t rt_err_t; /**< Type for error number */
typedef rt_uint32_t rt_time_t; /**< Type for time stamp */
typedef rt_uint32_t rt_tick_t; /**< Type for tick count */
typedef rt_base_t rt_flag_t; /**< Type for flags */
typedef rt_ubase_t rt_dev_t; /**< Type for device */
typedef rt_base_t rt_off_t; /**< Type for offset */
#if defined(RT_USING_STDC_ATOMIC) && __STDC_VERSION__ < 201112L
#undef RT_USING_STDC_ATOMIC
#warning Not using C11 or beyond! Maybe you should change the -std option on your compiler
#endif
#ifdef __cplusplus
typedef rt_base_t rt_atomic_t;
#else
#if defined(RT_USING_STDC_ATOMIC)
#include <stdatomic.h>
typedef _Atomic(rt_base_t) rt_atomic_t;
#elif defined(RT_USING_HW_ATOMIC)
typedef rt_base_t rt_atomic_t;
#else
typedef rt_base_t rt_atomic_t;
#endif /* RT_USING_STDC_ATOMIC */
#endif /* __cplusplus */
/* boolean type definitions */
#define RT_TRUE 1 /**< boolean true */
#define RT_FALSE 0 /**< boolean fails */
/* null pointer definition */
#define RT_NULL 0
/**
* Double List structure
*/
struct rt_list_node
{
struct rt_list_node *next; /**< point to next node. */
struct rt_list_node *prev; /**< point to prev node. */
};
typedef struct rt_list_node rt_list_t; /**< Type for lists. */
/**
* Single List structure
*/
struct rt_slist_node
{
struct rt_slist_node *next; /**< point to next node. */
};
typedef struct rt_slist_node rt_slist_t; /**< Type for single list. */
/**
* Lock-less Single List structure
*/
struct rt_lockless_slist_node
{
rt_atomic_t next; /**< point to next node. */
};
typedef struct rt_lockless_slist_node rt_ll_slist_t; /**< Type for lock-les single list. */
/**
* Spinlock
*/
#ifdef RT_USING_SMP
#include <cpuport.h> /* for spinlock from arch */
struct rt_spinlock
{
rt_hw_spinlock_t lock;
#ifdef RT_USING_DEBUG
rt_uint32_t critical_level;
#endif /* RT_USING_DEBUG */
#if defined(RT_DEBUGING_SPINLOCK)
void *owner;
void *pc;
#endif /* RT_DEBUGING_SPINLOCK */
};
#ifndef RT_SPINLOCK_INIT
#define RT_SPINLOCK_INIT {{0}} /* can be overridden by cpuport.h */
#endif /* RT_SPINLOCK_INIT */
#else /* !RT_USING_SMP */
struct rt_spinlock
{
#ifdef RT_USING_DEBUG
rt_uint32_t critical_level;
#endif /* RT_USING_DEBUG */
rt_ubase_t lock;
};
#define RT_SPINLOCK_INIT {0}
#endif /* RT_USING_SMP */
#if defined(RT_DEBUGING_SPINLOCK) && defined(RT_USING_SMP)
#define __OWNER_MAGIC ((void *)0xdeadbeaf)
#if defined(__GNUC__)
#define __GET_RETURN_ADDRESS __builtin_return_address(0)
#else /* !__GNUC__ */
#define __GET_RETURN_ADDRESS RT_NULL
#endif /* __GNUC__ */
#define _SPIN_LOCK_DEBUG_OWNER(lock) \
do \
{ \
struct rt_thread *_curthr = rt_thread_self(); \
if (_curthr != RT_NULL) \
{ \
(lock)->owner = _curthr; \
(lock)->pc = __GET_RETURN_ADDRESS; \
} \
} while (0)
#define _SPIN_UNLOCK_DEBUG_OWNER(lock) \
do \
{ \
(lock)->owner = __OWNER_MAGIC; \
(lock)->pc = RT_NULL; \
} while (0)
#else /* !RT_DEBUGING_SPINLOCK */
#define _SPIN_LOCK_DEBUG_OWNER(lock) RT_UNUSED(lock)
#define _SPIN_UNLOCK_DEBUG_OWNER(lock) RT_UNUSED(lock)
#endif /* RT_DEBUGING_SPINLOCK */
#ifdef RT_DEBUGING_CRITICAL
#define _SPIN_LOCK_DEBUG_CRITICAL(lock) \
do \
{ \
(lock)->critical_level = rt_critical_level(); \
} while (0)
#define _SPIN_UNLOCK_DEBUG_CRITICAL(lock, critical) \
do \
{ \
(critical) = (lock)->critical_level; \
} while (0)
#else /* !RT_DEBUGING_CRITICAL */
#define _SPIN_LOCK_DEBUG_CRITICAL(lock) RT_UNUSED(lock)
#define _SPIN_UNLOCK_DEBUG_CRITICAL(lock, critical) do {critical = 0; RT_UNUSED(lock);} while (0)
#endif /* RT_DEBUGING_CRITICAL */
#define RT_SPIN_LOCK_DEBUG(lock) \
do \
{ \
_SPIN_LOCK_DEBUG_OWNER(lock); \
_SPIN_LOCK_DEBUG_CRITICAL(lock); \
} while (0)
#define RT_SPIN_UNLOCK_DEBUG(lock, critical) \
do \
{ \
_SPIN_UNLOCK_DEBUG_OWNER(lock); \
_SPIN_UNLOCK_DEBUG_CRITICAL(lock, critical); \
} while (0)
typedef struct rt_spinlock rt_spinlock_t;
#define RT_DEFINE_SPINLOCK(x) struct rt_spinlock x = RT_SPINLOCK_INIT
#ifdef __cplusplus
}
#endif
#endif /* __RT_TYPES_H__ */