RT-Thread RTOS 1.2.0
An open source embedded real-time operating system
载入中...
搜索中...
未找到
rttypes.h
浏览该文件的文档.
1/*
2 * Copyright (c) 2006-2024, RT-Thread Development Team
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 *
6 * Change Logs:
7 * Date Author Notes
8 * 2024-01-18 Shell Separate the basic types from rtdef.h
9 */
10
11#ifndef __RT_TYPES_H__
12#define __RT_TYPES_H__
13
14#include <rtconfig.h>
15
16#include <stdint.h>
17#include <stddef.h>
18#include <stdarg.h>
19#ifndef RT_USING_NANO
20#include <sys/types.h>
21#include <sys/errno.h>
22#if defined(RT_USING_SIGNALS) || defined(RT_USING_SMART)
23#include <sys/signal.h>
24#endif /* defined(RT_USING_SIGNALS) || defined(RT_USING_SMART) */
25#endif /* RT_USING_NANO */
26
27#ifdef __cplusplus
28extern "C" {
29#endif
30
34
35typedef int rt_bool_t;
36
37#ifndef RT_USING_ARCH_DATA_TYPE
38#ifdef RT_USING_LIBC
39typedef int8_t rt_int8_t;
40typedef int16_t rt_int16_t;
41typedef int32_t rt_int32_t;
42typedef uint8_t rt_uint8_t;
43typedef uint16_t rt_uint16_t;
44typedef uint32_t rt_uint32_t;
45typedef int64_t rt_int64_t;
46typedef uint64_t rt_uint64_t;
47#else
48typedef signed char rt_int8_t;
49typedef signed short rt_int16_t;
50typedef signed int rt_int32_t;
51typedef unsigned char rt_uint8_t;
52typedef unsigned short rt_uint16_t;
53typedef unsigned int rt_uint32_t;
54#ifdef ARCH_CPU_64BIT
55typedef signed long rt_int64_t;
56typedef unsigned long rt_uint64_t;
57#else
58typedef signed long long rt_int64_t;
59typedef unsigned long long rt_uint64_t;
60#endif /* ARCH_CPU_64BIT */
61#endif /* RT_USING_LIBC */
62#endif /* RT_USING_ARCH_DATA_TYPE */
63
64#ifdef ARCH_CPU_64BIT
65typedef rt_int64_t rt_base_t;
66typedef rt_uint64_t rt_ubase_t;
67#else
70#endif
71
72#if defined(RT_USING_LIBC) && !defined(RT_USING_NANO)
73typedef size_t rt_size_t;
74typedef ssize_t rt_ssize_t;
75typedef intptr_t rt_intptr_t;
76typedef uintptr_t rt_uintptr_t;
77#else
82#endif /* defined(RT_USING_LIBC) && !defined(RT_USING_NANO) */
83
90
91#if defined(RT_USING_STDC_ATOMIC) && __STDC_VERSION__ < 201112L
92#undef RT_USING_STDC_ATOMIC
93#warning Not using C11 or beyond! Maybe you should change the -std option on your compiler
94#endif
95
96#ifdef __cplusplus
97 typedef rt_base_t rt_atomic_t;
98#else
99 #if defined(RT_USING_STDC_ATOMIC)
100 #include <stdatomic.h>
101 typedef _Atomic(rt_base_t) rt_atomic_t;
102 #elif defined(RT_USING_HW_ATOMIC)
103 typedef rt_base_t rt_atomic_t;
104 #else
106 #endif /* RT_USING_STDC_ATOMIC */
107#endif /* __cplusplus */
108
109/* boolean type definitions */
110#define RT_TRUE 1
111#define RT_FALSE 0
112
113/* null pointer definition */
114#define RT_NULL 0
115
120{
123};
124typedef struct rt_list_node rt_list_t;
125
130{
132};
133typedef struct rt_slist_node rt_slist_t;
134
143
147#ifdef RT_USING_SMP
148#include <cpuport.h> /* for spinlock from arch */
149
150struct rt_spinlock
151{
152 rt_hw_spinlock_t lock;
153#ifdef RT_USING_DEBUG
154 rt_uint32_t critical_level;
155#endif /* RT_USING_DEBUG */
156#if defined(RT_DEBUGING_SPINLOCK)
157 void *owner;
158 void *pc;
159#endif /* RT_DEBUGING_SPINLOCK */
160};
161
162#ifndef RT_SPINLOCK_INIT
163#define RT_SPINLOCK_INIT {{0}} /* can be overridden by cpuport.h */
164#endif /* RT_SPINLOCK_INIT */
165
166#else /* !RT_USING_SMP */
167
169{
170#ifdef RT_USING_DEBUG
171 rt_uint32_t critical_level;
172#endif /* RT_USING_DEBUG */
174};
175#define RT_SPINLOCK_INIT {0}
176#endif /* RT_USING_SMP */
177#if defined(RT_DEBUGING_SPINLOCK) && defined(RT_USING_SMP)
178
179 #define __OWNER_MAGIC ((void *)0xdeadbeaf)
180
181 #if defined(__GNUC__)
182 #define __GET_RETURN_ADDRESS __builtin_return_address(0)
183 #else /* !__GNUC__ */
184 #define __GET_RETURN_ADDRESS RT_NULL
185 #endif /* __GNUC__ */
186
187 #define _SPIN_LOCK_DEBUG_OWNER(lock) \
188 do \
189 { \
190 struct rt_thread *_curthr = rt_thread_self(); \
191 if (_curthr != RT_NULL) \
192 { \
193 (lock)->owner = _curthr; \
194 (lock)->pc = __GET_RETURN_ADDRESS; \
195 } \
196 } while (0)
197
198 #define _SPIN_UNLOCK_DEBUG_OWNER(lock) \
199 do \
200 { \
201 (lock)->owner = __OWNER_MAGIC; \
202 (lock)->pc = RT_NULL; \
203 } while (0)
204
205#else /* !RT_DEBUGING_SPINLOCK */
206
207 #define _SPIN_LOCK_DEBUG_OWNER(lock) RT_UNUSED(lock)
208 #define _SPIN_UNLOCK_DEBUG_OWNER(lock) RT_UNUSED(lock)
209#endif /* RT_DEBUGING_SPINLOCK */
210
211#ifdef RT_DEBUGING_CRITICAL
212 #define _SPIN_LOCK_DEBUG_CRITICAL(lock) \
213 do \
214 { \
215 (lock)->critical_level = rt_critical_level(); \
216 } while (0)
217
218 #define _SPIN_UNLOCK_DEBUG_CRITICAL(lock, critical) \
219 do \
220 { \
221 (critical) = (lock)->critical_level; \
222 } while (0)
223
224#else /* !RT_DEBUGING_CRITICAL */
225 #define _SPIN_LOCK_DEBUG_CRITICAL(lock) RT_UNUSED(lock)
226 #define _SPIN_UNLOCK_DEBUG_CRITICAL(lock, critical) do {critical = 0; RT_UNUSED(lock);} while (0)
227
228#endif /* RT_DEBUGING_CRITICAL */
229
230#define RT_SPIN_LOCK_DEBUG(lock) \
231 do \
232 { \
233 _SPIN_LOCK_DEBUG_OWNER(lock); \
234 _SPIN_LOCK_DEBUG_CRITICAL(lock); \
235 } while (0)
236
237#define RT_SPIN_UNLOCK_DEBUG(lock, critical) \
238 do \
239 { \
240 _SPIN_UNLOCK_DEBUG_OWNER(lock); \
241 _SPIN_UNLOCK_DEBUG_CRITICAL(lock, critical); \
242 } while (0)
243
245
246#define RT_DEFINE_SPINLOCK(x) struct rt_spinlock x = RT_SPINLOCK_INIT
247
248#ifdef __cplusplus
249}
250#endif
251
252#endif /* __RT_TYPES_H__ */
signed char rt_int8_t
rt_base_t rt_ssize_t
rt_int32_t rt_base_t
rt_base_t rt_off_t
rt_uint32_t rt_time_t
struct rt_lockless_slist_node rt_ll_slist_t
rt_base_t rt_uintptr_t
int rt_bool_t
rt_base_t rt_err_t
signed long long rt_int64_t
unsigned char rt_uint8_t
unsigned short rt_uint16_t
rt_uint32_t rt_tick_t
rt_ubase_t rt_dev_t
rt_ubase_t rt_size_t
rt_base_t rt_atomic_t
struct rt_list_node rt_list_t
unsigned int rt_uint32_t
rt_uint32_t rt_ubase_t
rt_base_t rt_flag_t
struct rt_spinlock rt_spinlock_t
unsigned long long rt_uint64_t
signed short rt_int16_t
rt_ubase_t rt_intptr_t
struct rt_slist_node rt_slist_t
signed int rt_int32_t
struct rt_list_node * next
struct rt_list_node * prev
struct rt_slist_node * next
rt_ubase_t lock