RT-Thread RTOS 1.2.0
An open source embedded real-time operating system
载入中...
搜索中...
未找到
rtdef.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 * 2007-01-10 Bernard the first version
9 * 2008-07-12 Bernard remove all rt_int8, rt_uint32_t etc typedef
10 * 2010-10-26 yi.qiu add module support
11 * 2010-11-10 Bernard add cleanup callback function in thread exit.
12 * 2011-05-09 Bernard use builtin va_arg in GCC 4.x
13 * 2012-11-16 Bernard change RT_NULL from ((void*)0) to 0.
14 * 2012-12-29 Bernard change the RT_USING_MEMPOOL location and add
15 * RT_USING_MEMHEAP condition.
16 * 2012-12-30 Bernard add more control command for graphic.
17 * 2013-01-09 Bernard change version number.
18 * 2015-02-01 Bernard change version number to v2.1.0
19 * 2017-08-31 Bernard change version number to v3.0.0
20 * 2017-11-30 Bernard change version number to v3.0.1
21 * 2017-12-27 Bernard change version number to v3.0.2
22 * 2018-02-24 Bernard change version number to v3.0.3
23 * 2018-04-25 Bernard change version number to v3.0.4
24 * 2018-05-31 Bernard change version number to v3.1.0
25 * 2018-09-04 Bernard change version number to v3.1.1
26 * 2018-09-14 Bernard apply Apache License v2.0 to RT-Thread Kernel
27 * 2018-10-13 Bernard change version number to v4.0.0
28 * 2018-10-02 Bernard add 64bit arch support
29 * 2018-11-22 Jesven add smp member to struct rt_thread
30 * add struct rt_cpu
31 * add smp relevant macros
32 * 2019-01-27 Bernard change version number to v4.0.1
33 * 2019-05-17 Bernard change version number to v4.0.2
34 * 2019-12-20 Bernard change version number to v4.0.3
35 * 2020-08-10 Meco Man add macro for struct rt_device_ops
36 * 2020-10-23 Meco Man define maximum value of ipc type
37 * 2021-03-19 Meco Man add security devices
38 * 2021-05-10 armink change version number to v4.0.4
39 * 2021-11-19 Meco Man change version number to v4.1.0
40 * 2021-12-21 Meco Man re-implement RT_UNUSED
41 * 2022-01-01 Gabriel improve hooking method
42 * 2022-01-07 Gabriel move some __on_rt_xxxxx_hook to dedicated c source files
43 * 2022-01-12 Meco Man remove RT_THREAD_BLOCK
44 * 2022-04-20 Meco Man change version number to v4.1.1
45 * 2022-04-21 THEWON add macro RT_VERSION_CHECK
46 * 2022-06-29 Meco Man add RT_USING_LIBC and standard libc headers
47 * 2022-08-16 Meco Man change version number to v5.0.0
48 * 2022-09-12 Meco Man define rt_ssize_t
49 * 2022-12-20 Meco Man add const name for rt_object
50 * 2023-04-01 Chushicheng change version number to v5.0.1
51 * 2023-05-20 Bernard add stdc atomic detection.
52 * 2023-09-15 xqyjlj perf rt_hw_interrupt_disable/enable
53 * 2023-10-10 Chushicheng change version number to v5.1.0
54 * 2023-10-11 zmshahaha move specific devices related and driver to components/drivers
55 * 2023-11-21 Meco Man add RT_USING_NANO macro
56 * 2023-11-17 xqyjlj add process group and session support
57 * 2023-12-01 Shell Support of dynamic device
58 * 2023-12-18 xqyjlj add rt_always_inline
59 * 2023-12-22 Shell Support hook list
60 * 2024-01-18 Shell Seperate basical types to a rttypes.h
61 * Seperate the compiler portings to rtcompiler.h
62 * 2024-03-30 Meco Man update version number to v5.2.0
63 */
64
65#ifndef __RT_DEF_H__
66#define __RT_DEF_H__
67
68#include "rtsched.h"
69#include "rttypes.h"
70
71#include "klibc/kerrno.h"
72
73#ifdef __cplusplus
74extern "C" {
75#endif
76
80
82
83/* RT-Thread version information */
84#define RT_VERSION_MAJOR 5
85#define RT_VERSION_MINOR 2
86#define RT_VERSION_PATCH 0
87
88/* e.g. #if (RTTHREAD_VERSION >= RT_VERSION_CHECK(4, 1, 0) */
89#define RT_VERSION_CHECK(major, minor, revise) ((major * 10000U) + (minor * 100U) + revise)
90
91/* RT-Thread version */
92#define RTTHREAD_VERSION RT_VERSION_CHECK(RT_VERSION_MAJOR, RT_VERSION_MINOR, RT_VERSION_PATCH)
93
95
96/* maximum value of base type */
97#ifdef RT_USING_LIBC
98#define RT_UINT8_MAX UINT8_MAX
99#define RT_UINT16_MAX UINT16_MAX
100#define RT_UINT32_MAX UINT32_MAX
101#define RT_UINT64_MAX UINT64_MAX
102#else
103#define RT_UINT8_MAX 0xFFU
104#define RT_UINT16_MAX 0xFFFFU
105#define RT_UINT32_MAX 0xFFFFFFFFUL
106#define RT_UINT64_MAX 0xFFFFFFFFFFFFFFFFULL
107#endif /* RT_USING_LIBC */
108
109#define RT_TICK_MAX RT_UINT32_MAX
110
111/* maximum value of ipc type */
112#define RT_SEM_VALUE_MAX RT_UINT16_MAX
113#define RT_MUTEX_VALUE_MAX RT_UINT16_MAX
114#define RT_MUTEX_HOLD_MAX RT_UINT8_MAX
115#define RT_MB_ENTRY_MAX RT_UINT16_MAX
116#define RT_MQ_ENTRY_MAX RT_UINT16_MAX
117
118/* Common Utilities */
119
120#define RT_UNUSED(x) ((void)(x))
121
122/* compile time assertion */
123#define RT_STATIC_ASSERT(name, expn) typedef char _static_assert_##name[(expn)?1:-1]
124
125/* Compiler Related Definitions */
126#include "rtcompiler.h"
127
128/* initialization export */
129#ifdef RT_USING_COMPONENTS_INIT
130typedef int (*init_fn_t)(void);
131#ifdef _MSC_VER
132#pragma section("rti_fn$f",read)
133 #ifdef RT_DEBUGING_AUTO_INIT
134 struct rt_init_desc
135 {
136 const char* level;
137 const init_fn_t fn;
138 const char* fn_name;
139 };
140 #define INIT_EXPORT(fn, level) \
141 const char __rti_level_##fn[] = ".rti_fn." level; \
142 const char __rti_##fn##_name[] = #fn; \
143 __declspec(allocate("rti_fn$f")) \
144 rt_used const struct rt_init_desc __rt_init_msc_##fn = \
145 {__rti_level_##fn, fn, __rti_##fn##_name};
146 #else
147 struct rt_init_desc
148 {
149 const char* level;
150 const init_fn_t fn;
151 };
152 #define INIT_EXPORT(fn, level) \
153 const char __rti_level_##fn[] = ".rti_fn." level; \
154 __declspec(allocate("rti_fn$f")) \
155 rt_used const struct rt_init_desc __rt_init_msc_##fn = \
156 {__rti_level_##fn, fn };
157 #endif /* RT_DEBUGING_AUTO_INIT */
158#else
159 #ifdef RT_DEBUGING_AUTO_INIT
160 struct rt_init_desc
161 {
162 const char* fn_name;
163 const init_fn_t fn;
164 };
165 #define INIT_EXPORT(fn, level) \
166 const char __rti_##fn##_name[] = #fn; \
167 rt_used const struct rt_init_desc __rt_init_desc_##fn rt_section(".rti_fn." level) = \
168 { __rti_##fn##_name, fn};
169 #else
170 #define INIT_EXPORT(fn, level) \
171 rt_used const init_fn_t __rt_init_##fn rt_section(".rti_fn." level) = fn
172 #endif /* RT_DEBUGING_AUTO_INIT */
173#endif /* _MSC_VER */
174#else
175#define INIT_EXPORT(fn, level)
176#endif /* RT_USING_COMPONENTS_INIT */
177
178/* board init routines will be called in board_init() function */
179#define INIT_BOARD_EXPORT(fn) INIT_EXPORT(fn, "1")
180
181/* init cpu, memory, interrupt-controller, bus... */
182#define INIT_CORE_EXPORT(fn) INIT_EXPORT(fn, "1.0")
183/* init sys-timer, clk, pinctrl... */
184#define INIT_SUBSYS_EXPORT(fn) INIT_EXPORT(fn, "1.1")
185/* init platform, user code... */
186#define INIT_PLATFORM_EXPORT(fn) INIT_EXPORT(fn, "1.2")
187
188/* pre/device/component/env/app init routines will be called in init_thread */
189/* components pre-initialization (pure software initialization) */
190#define INIT_PREV_EXPORT(fn) INIT_EXPORT(fn, "2")
191/* device initialization */
192#define INIT_DEVICE_EXPORT(fn) INIT_EXPORT(fn, "3")
193/* components initialization (dfs, lwip, ...) */
194#define INIT_COMPONENT_EXPORT(fn) INIT_EXPORT(fn, "4")
195/* environment initialization (mount disk, ...) */
196#define INIT_ENV_EXPORT(fn) INIT_EXPORT(fn, "5")
197/* application initialization (rtgui application etc ...) */
198#define INIT_APP_EXPORT(fn) INIT_EXPORT(fn, "6")
199
200/* init after mount fs */
201#define INIT_FS_EXPORT(fn) INIT_EXPORT(fn, "6.0")
202/* init in secondary_cpu_c_start */
203#define INIT_SECONDARY_CPU_EXPORT(fn) INIT_EXPORT(fn, "7")
204
205#if !defined(RT_USING_FINSH)
206/* define these to empty, even if not include finsh.h file */
207#define FINSH_FUNCTION_EXPORT(name, desc)
208#define FINSH_FUNCTION_EXPORT_ALIAS(name, alias, desc)
209
210#define MSH_CMD_EXPORT(command, desc)
211#define MSH_CMD_EXPORT_ALIAS(command, alias, desc)
212#elif !defined(FINSH_USING_SYMTAB)
213#define FINSH_FUNCTION_EXPORT_CMD(name, cmd, desc)
214#endif
215
216/* event length */
217#define RT_EVENT_LENGTH 32
218
219/* memory management option */
220#define RT_MM_PAGE_SIZE 4096
221#define RT_MM_PAGE_MASK (RT_MM_PAGE_SIZE - 1)
222#define RT_MM_PAGE_BITS 12
223
224/* kernel malloc definitions */
225#ifndef RT_KERNEL_MALLOC
226#define RT_KERNEL_MALLOC(sz) rt_malloc(sz)
227#endif /* RT_KERNEL_MALLOC */
228
229#ifndef RT_KERNEL_FREE
230#define RT_KERNEL_FREE(ptr) rt_free(ptr)
231#endif /* RT_KERNEL_FREE */
232
233#ifndef RT_KERNEL_REALLOC
234#define RT_KERNEL_REALLOC(ptr, size) rt_realloc(ptr, size)
235#endif /* RT_KERNEL_REALLOC */
236
246#define RT_IS_ALIGN(addr, align) ((!(addr & (align - 1))) && (addr != RT_NULL))
247
255#define RT_ALIGN(size, align) (((size) + (align) - 1) & ~((align) - 1))
256
264#define RT_ALIGN_DOWN(size, align) ((size) & ~((align) - 1))
265
269
271
272/*
273 * kernel object macros
274 */
275#define RT_OBJECT_FLAG_MODULE 0x80
276
281{
282#if RT_NAME_MAX > 0
283 char name[RT_NAME_MAX];
284#else
285 const char *name;
286#endif /* RT_NAME_MAX > 0 */
289
290#ifdef RT_USING_MODULE
291 void * module_id;
292#endif /* RT_USING_MODULE */
293
294#ifdef RT_USING_SMART
295 rt_atomic_t lwp_ref_count;
296#endif /* RT_USING_SMART */
297
299};
300typedef struct rt_object *rt_object_t;
301
309typedef rt_err_t (*rt_object_iter_t)(rt_object_t object, void *data);
310
350
361
365#ifndef RT_USING_HOOK
366#define RT_OBJECT_HOOK_CALL(func, argv)
367
368#else
369
381#define _RT_OBJECT_HOOK_CALL(func, argv) __ON_HOOK_ARGS(func, argv)
382#define RT_OBJECT_HOOK_CALL(func, argv) _RT_OBJECT_HOOK_CALL(func, argv)
383
384 #ifdef RT_HOOK_USING_FUNC_PTR
385 #define __ON_HOOK_ARGS(__hook, argv) do {if ((__hook) != RT_NULL) __hook argv; } while (0)
386 #else
387 #define __ON_HOOK_ARGS(__hook, argv)
388 #endif /* RT_HOOK_USING_FUNC_PTR */
389#endif /* RT_USING_HOOK */
390
391#ifdef RT_USING_HOOKLIST
392
404#define RT_OBJECT_HOOKLIST_DECLARE(handler_type, name) \
405 typedef struct name##_hooklistnode \
406 { \
407 handler_type handler; \
408 rt_list_t list_node; \
409 } *name##_hooklistnode_t; \
410 extern volatile rt_ubase_t name##_nested; \
411 void name##_sethook(name##_hooklistnode_t node); \
412 void name##_rmhook(name##_hooklistnode_t node)
413
433#define RT_OBJECT_HOOKLIST_DEFINE_NODE(hookname, nodename, hooker_handler) \
434 struct hookname##_hooklistnode nodename = { \
435 .handler = hooker_handler, \
436 .list_node = RT_LIST_OBJECT_INIT(nodename.list_node), \
437 };
438
443#define RT_OBJECT_HOOKLIST_DEFINE(name) \
444 static rt_list_t name##_hooklist = RT_LIST_OBJECT_INIT(name##_hooklist); \
445 static struct rt_spinlock name##lock = RT_SPINLOCK_INIT; \
446 volatile rt_ubase_t name##_nested = 0; \
447 void name##_sethook(name##_hooklistnode_t node) \
448 { \
449 rt_ubase_t level = rt_spin_lock_irqsave(&name##lock); \
450 while (name##_nested) \
451 { \
452 rt_spin_unlock_irqrestore(&name##lock, level); \
453 level = rt_spin_lock_irqsave(&name##lock); \
454 } \
455 rt_list_insert_before(&name##_hooklist, &node->list_node); \
456 rt_spin_unlock_irqrestore(&name##lock, level); \
457 } \
458 void name##_rmhook(name##_hooklistnode_t node) \
459 { \
460 rt_ubase_t level = rt_spin_lock_irqsave(&name##lock); \
461 while (name##_nested) \
462 { \
463 rt_spin_unlock_irqrestore(&name##lock, level); \
464 level = rt_spin_lock_irqsave(&name##lock); \
465 } \
466 rt_list_remove(&node->list_node); \
467 rt_spin_unlock_irqrestore(&name##lock, level); \
468 }
469
483#define _RT_OBJECT_HOOKLIST_CALL(nodetype, nested, list, lock, argv) \
484 do \
485 { \
486 nodetype iter, next; \
487 rt_ubase_t level = rt_spin_lock_irqsave(&lock); \
488 nested += 1; \
489 rt_spin_unlock_irqrestore(&lock, level); \
490 if (!rt_list_isempty(&list)) \
491 { \
492 rt_list_for_each_entry_safe(iter, next, &list, list_node) \
493 { \
494 iter->handler argv; \
495 } \
496 } \
497 level = rt_spin_lock_irqsave(&lock); \
498 nested -= 1; \
499 rt_spin_unlock_irqrestore(&lock, level); \
500 } while (0)
501#define RT_OBJECT_HOOKLIST_CALL(name, argv) \
502 _RT_OBJECT_HOOKLIST_CALL(name##_hooklistnode_t, name##_nested, \
503 name##_hooklist, name##lock, argv)
504
505#else
506
507#define RT_OBJECT_HOOKLIST_DECLARE(handler_type, name)
508#define RT_OBJECT_HOOKLIST_DEFINE_NODE(hookname, nodename, hooker_handler)
509#define RT_OBJECT_HOOKLIST_DEFINE(name)
510#define RT_OBJECT_HOOKLIST_CALL(name, argv)
511#endif /* RT_USING_HOOKLIST */
512
514
518
520
524#define RT_TIMER_FLAG_DEACTIVATED 0x0
525#define RT_TIMER_FLAG_ACTIVATED 0x1
526#define RT_TIMER_FLAG_ONE_SHOT 0x0
527#define RT_TIMER_FLAG_PERIODIC 0x2
528
529#define RT_TIMER_FLAG_HARD_TIMER 0x0
530#define RT_TIMER_FLAG_SOFT_TIMER 0x4
531#define RT_TIMER_FLAG_THREAD_TIMER \
532 (0x8 | RT_TIMER_FLAG_HARD_TIMER)
533
534#define RT_TIMER_CTRL_SET_TIME 0x0
535#define RT_TIMER_CTRL_GET_TIME 0x1
536#define RT_TIMER_CTRL_SET_ONESHOT 0x2
537#define RT_TIMER_CTRL_SET_PERIODIC 0x3
538#define RT_TIMER_CTRL_GET_STATE 0x4
539#define RT_TIMER_CTRL_GET_REMAIN_TIME 0x5
540#define RT_TIMER_CTRL_GET_FUNC 0x6
541#define RT_TIMER_CTRL_SET_FUNC 0x7
542#define RT_TIMER_CTRL_GET_PARM 0x8
543#define RT_TIMER_CTRL_SET_PARM 0x9
544
545#ifndef RT_TIMER_SKIP_LIST_LEVEL
546#define RT_TIMER_SKIP_LIST_LEVEL 1
547#endif
548
549/* 1 or 3 */
550#ifndef RT_TIMER_SKIP_LIST_MASK
551#define RT_TIMER_SKIP_LIST_MASK 0x3
552#endif
553
557typedef void (*rt_timer_func_t)(void *parameter);
558
574typedef struct rt_timer *rt_timer_t;
575
577
582
583#ifdef RT_USING_SIGNALS
584#define RT_SIG_MAX 32
585typedef unsigned long rt_sigset_t;
586typedef siginfo_t rt_siginfo_t;
587typedef void (*rt_sighandler_t)(int signo);
588#endif /* RT_USING_SIGNALS */
590
594
596
597/*
598 * Thread
599 */
600
601/*
602 * thread state definitions
603 */
604#define RT_THREAD_INIT 0x00
605#define RT_THREAD_CLOSE 0x01
606#define RT_THREAD_READY 0x02
607#define RT_THREAD_RUNNING 0x03
608
609/*
610 * for rt_thread_suspend_with_flag()
611 */
612enum
613{
617};
618
619#define RT_THREAD_SUSPEND_MASK 0x04
620#define RT_SIGNAL_COMMON_WAKEUP_MASK 0x02
621#define RT_SIGNAL_KILL_WAKEUP_MASK 0x01
622
623#define RT_THREAD_SUSPEND_INTERRUPTIBLE (RT_THREAD_SUSPEND_MASK)
624#define RT_THREAD_SUSPEND RT_THREAD_SUSPEND_INTERRUPTIBLE
625#define RT_THREAD_SUSPEND_KILLABLE (RT_THREAD_SUSPEND_MASK | RT_SIGNAL_COMMON_WAKEUP_MASK)
626#define RT_THREAD_SUSPEND_UNINTERRUPTIBLE (RT_THREAD_SUSPEND_MASK | RT_SIGNAL_COMMON_WAKEUP_MASK | RT_SIGNAL_KILL_WAKEUP_MASK)
627#define RT_THREAD_STAT_MASK 0x07
628
629#define RT_THREAD_STAT_YIELD 0x08
630#define RT_THREAD_STAT_YIELD_MASK RT_THREAD_STAT_YIELD
631
632#define RT_THREAD_STAT_SIGNAL 0x10
633#define RT_THREAD_STAT_SIGNAL_READY (RT_THREAD_STAT_SIGNAL | RT_THREAD_READY)
634#define RT_THREAD_STAT_SIGNAL_WAIT 0x20
635#define RT_THREAD_STAT_SIGNAL_PENDING 0x40
636#define RT_THREAD_STAT_SIGNAL_MASK 0xf0
637
641#define RT_THREAD_CTRL_STARTUP 0x00
642#define RT_THREAD_CTRL_CLOSE 0x01
643#define RT_THREAD_CTRL_CHANGE_PRIORITY 0x02
644#define RT_THREAD_CTRL_INFO 0x03
645#define RT_THREAD_CTRL_BIND_CPU 0x04
646
658
659#ifdef RT_USING_SMP
660
661#define RT_CPU_DETACHED RT_CPUS_NR
662#define RT_CPU_MASK ((1 << RT_CPUS_NR) - 1)
663
664#ifndef RT_SCHEDULE_IPI
665#define RT_SCHEDULE_IPI 0
666#endif /* RT_SCHEDULE_IPI */
667
668#ifndef RT_STOP_IPI
669#define RT_STOP_IPI 1
670#endif /* RT_STOP_IPI */
671
672#ifndef RT_SMP_CALL_IPI
673#define RT_SMP_CALL_IPI 2
674#endif
675
676#define RT_MAX_IPI 3
677
678#define _SCHEDULER_CONTEXT(fileds) fileds
679
684struct rt_cpu
685{
691 _SCHEDULER_CONTEXT(
693
694 rt_uint8_t irq_switch_flag:1;
695 rt_uint8_t sched_lock_flag:1;
696#ifndef ARCH_USING_HW_THREAD_SELF
697 rt_uint8_t critical_switch_flag:1;
698#endif /* ARCH_USING_HW_THREAD_SELF */
699
700 rt_uint8_t current_priority;
701 rt_list_t priority_table[RT_THREAD_PRIORITY_MAX];
702 #if RT_THREAD_PRIORITY_MAX > 32
703 rt_uint32_t priority_group;
704 rt_uint8_t ready_table[32];
705 #else
706 rt_uint32_t priority_group;
707 #endif /* RT_THREAD_PRIORITY_MAX > 32 */
708
709 rt_atomic_t tick;
710 );
711
712 struct rt_thread *idle_thread;
713 rt_atomic_t irq_nest;
714
715#ifdef RT_USING_SMART
716 struct rt_spinlock spinlock;
717#endif /* RT_USING_SMART */
718#ifdef RT_USING_CPU_USAGE_TRACER
719 struct rt_cpu_usage_stats cpu_stat;
720#endif /* RT_USING_CPU_USAGE_TRACER */
721#ifdef ARCH_USING_IRQ_CTX_LIST
722 rt_slist_t irq_ctx_head;
723#endif /* ARCH_USING_IRQ_CTX_LIST */
724};
725
726#else /* !RT_USING_SMP */
727struct rt_cpu
728{
731
732#ifdef RT_USING_CPU_USAGE_TRACER
733 struct rt_cpu_usage_stats cpu_stat;
734#endif /* RT_USING_CPU_USAGE_TRACER */
735#ifdef ARCH_USING_IRQ_CTX_LIST
736 rt_slist_t irq_ctx_head;
737#endif /* ARCH_USING_IRQ_CTX_LIST */
738};
739
740#endif /* RT_USING_SMP */
741
742typedef struct rt_cpu *rt_cpu_t;
743/* Noted: As API to reject writing to this variable from application codes */
744#define rt_current_thread rt_thread_self()
745
746struct rt_thread;
747
752
757
758#ifdef RT_USING_SMART
759typedef rt_err_t (*rt_wakeup_func_t)(void *object, struct rt_thread *thread);
760
761struct rt_wakeup
762{
763 rt_wakeup_func_t func;
764 void *user_data;
765};
766
767#define _LWP_NSIG 64
768
769#ifdef ARCH_CPU_64BIT
770#define _LWP_NSIG_BPW 64
771#else
772#define _LWP_NSIG_BPW 32
773#endif
774
775#define _LWP_NSIG_WORDS (RT_ALIGN(_LWP_NSIG, _LWP_NSIG_BPW) / _LWP_NSIG_BPW)
776
777typedef void (*lwp_sighandler_t)(int);
778typedef void (*lwp_sigaction_t)(int signo, siginfo_t *info, void *context);
779
780typedef struct {
781 unsigned long sig[_LWP_NSIG_WORDS];
782} lwp_sigset_t;
783
784#if _LWP_NSIG <= 64
785#define lwp_sigmask(signo) ((lwp_sigset_t){.sig = {[0] = ((long)(1u << ((signo)-1)))}})
786#define lwp_sigset_init(mask) ((lwp_sigset_t){.sig = {[0] = (long)(mask)}})
787#endif /* _LWP_NSIG <= 64 */
788
789struct lwp_sigaction {
790 union {
791 void (*_sa_handler)(int);
792 void (*_sa_sigaction)(int, siginfo_t *, void *);
793 } __sa_handler;
794 lwp_sigset_t sa_mask;
795 int sa_flags;
796 void (*sa_restorer)(void);
797};
798
799typedef struct lwp_siginfo_ext {
800 union {
801 /* for SIGCHLD */
802 struct {
803 int status;
804 clock_t utime;
805 clock_t stime;
806 } sigchld;
807 };
808} *lwp_siginfo_ext_t;
809
810typedef struct lwp_siginfo {
811 rt_list_t node;
812
813 struct {
814 int signo;
815 int code;
816
817 int from_tid;
818 pid_t from_pid;
819 } ksiginfo;
820
821 /* the signal specified extension field */
822 struct lwp_siginfo_ext *ext;
823} *lwp_siginfo_t;
824
825typedef struct lwp_sigqueue {
826 rt_list_t siginfo_list;
827 lwp_sigset_t sigset_pending;
828} *lwp_sigqueue_t;
829
830struct lwp_thread_signal {
831 lwp_sigset_t sigset_mask;
832 struct lwp_sigqueue sig_queue;
833};
834
835struct rt_user_context
836{
837 void *sp;
838 void *pc;
839 void *flag;
840
841 void *ctx;
842};
843#endif /* RT_USING_SMART */
844
845typedef void (*rt_thread_cleanup_t)(struct rt_thread *tid);
846
850
852{
854
855 /* stack point and entry */
856 void *sp;
857 void *entry;
858 void *parameter;
861
862 /* error code */
864
865#ifdef RT_USING_SMP
866 rt_atomic_t cpus_lock_nest;
867#endif
868
872
873#ifdef RT_USING_MUTEX
874 /* object for IPC */
877#endif /* RT_USING_MUTEX */
878
879#ifdef RT_USING_EVENT
880 /* thread event */
883#endif /* RT_USING_EVENT */
884
885#ifdef RT_USING_SIGNALS
886 rt_sigset_t sig_pending;
887 rt_sigset_t sig_mask;
888
889#ifndef RT_USING_SMP
890 void *sig_ret;
891#endif /* RT_USING_SMP */
892 rt_sighandler_t *sig_vectors;
893 void *si_list;
894#endif /* RT_USING_SIGNALS */
895
896#ifdef RT_USING_CPU_USAGE
897 rt_uint64_t duration_tick;
898#endif /* RT_USING_CPU_USAGE */
899
900#ifdef RT_USING_PTHREADS
901 void *pthread_data;
902#endif /* RT_USING_PTHREADS */
903
904 /* light weight process if present */
905#ifdef RT_USING_SMART
906 void *msg_ret;
907
908 void *lwp;
909 /* for user create */
910 void *user_entry;
911 void *user_stack;
912 rt_uint32_t user_stack_size;
913 rt_uint32_t *kernel_sp;
914 rt_list_t sibling;
915
916 struct lwp_thread_signal signal;
917 struct rt_user_context user_ctx;
918 struct rt_wakeup wakeup_handle;
919 rt_atomic_t exit_request;
920 int tid;
921 int tid_ref_count;
922 void *susp_recycler;
923 void *robust_list;
924
925#ifndef ARCH_MM_MMU
926 lwp_sighandler_t signal_handler[32];
927#else
928 int step_exec;
929 int debug_attach_req;
930 int debug_ret_user;
931 int debug_suspend;
932 struct rt_hw_exp_stack *regs;
933 void *thread_idr;
934 int *clear_child_tid;
935#endif /* ARCH_MM_MMU */
936#endif /* RT_USING_SMART */
937
938#ifdef RT_USING_CPU_USAGE_TRACER
939 rt_ubase_t user_time;
940 rt_ubase_t system_time;
941#endif /* RT_USING_CPU_USAGE_TRACER */
942
943#ifdef RT_USING_MEM_PROTECTION
944 void *mem_regions;
945#ifdef RT_USING_HW_STACK_GUARD
946 void *stack_buf;
947#endif /* RT_USING_HW_STACK_GUARD */
948#endif /* RT_USING_MEM_PROTECTION */
949
952};
953typedef struct rt_thread *rt_thread_t;
954
955#ifdef RT_USING_SMART
956#define LWP_IS_USER_MODE(t) ((t)->user_ctx.ctx == RT_NULL)
957#else
958#define LWP_IS_USER_MODE(t) (0)
959#endif /* RT_USING_SMART */
960
962
966
968
972#define RT_IPC_FLAG_FIFO 0x00
973#define RT_IPC_FLAG_PRIO 0x01
974
975#define RT_IPC_CMD_UNKNOWN 0x00
976#define RT_IPC_CMD_RESET 0x01
977#define RT_IPC_CMD_GET_STATE 0x02
978#define RT_IPC_CMD_SET_VLIMIT 0x03
979
980#define RT_WAITING_FOREVER -1
981#define RT_WAITING_NO 0
982
992
997
998#ifdef RT_USING_SEMAPHORE
1010typedef struct rt_semaphore *rt_sem_t;
1011#endif /* RT_USING_SEMAPHORE */
1012
1014
1019
1020#ifdef RT_USING_MUTEX
1037typedef struct rt_mutex *rt_mutex_t;
1038#endif /* RT_USING_MUTEX */
1039
1041
1046
1047#ifdef RT_USING_EVENT
1051#define RT_EVENT_FLAG_AND 0x01
1052#define RT_EVENT_FLAG_OR 0x02
1053#define RT_EVENT_FLAG_CLEAR 0x04
1054
1055/*
1056 * event structure
1057 */
1065typedef struct rt_event *rt_event_t;
1066#endif /* RT_USING_EVENT */
1067
1069
1074
1075#ifdef RT_USING_MAILBOX
1094typedef struct rt_mailbox *rt_mailbox_t;
1095#endif /* RT_USING_MAILBOX */
1096
1098
1103
1104#ifdef RT_USING_MESSAGEQUEUE
1126typedef struct rt_messagequeue *rt_mq_t;
1127#endif /* RT_USING_MESSAGEQUEUE */
1128
1130
1132
1136
1138
1139#ifdef RT_USING_HEAP
1140/*
1141 * memory structure
1142 */
1152typedef struct rt_memory *rt_mem_t;
1153#endif /* RT_USING_HEAP */
1154
1155/*
1156 * memory management
1157 * heap & partition
1158 */
1159
1160#ifdef RT_USING_SMALL_MEM
1162#endif /* RT_USING_SMALL_MEM */
1163
1164#ifdef RT_USING_SLAB
1165typedef rt_mem_t rt_slab_t;
1166#endif /* RT_USING_SLAB */
1167
1168#ifdef RT_USING_MEMHEAP
1172struct rt_memheap_item
1173{
1174 rt_uint32_t magic;
1175 struct rt_memheap *pool_ptr;
1176
1177 struct rt_memheap_item *next;
1178 struct rt_memheap_item *prev;
1179
1180 struct rt_memheap_item *next_free;
1181 struct rt_memheap_item *prev_free;
1182#ifdef RT_USING_MEMTRACE
1183 rt_uint8_t owner_thread_name[4];
1184#endif /* RT_USING_MEMTRACE */
1185};
1186
1190struct rt_memheap
1191{
1192 struct rt_object parent;
1193
1194 void *start_addr;
1195
1196 rt_size_t pool_size;
1197 rt_size_t available_size;
1198 rt_size_t max_used_size;
1199
1200 struct rt_memheap_item *block_list;
1201
1202 struct rt_memheap_item *free_list;
1203 struct rt_memheap_item free_header;
1204
1205 struct rt_semaphore lock;
1206 rt_bool_t locked;
1207};
1208#endif /* RT_USING_MEMHEAP */
1209
1210#ifdef RT_USING_MEMPOOL
1230typedef struct rt_mempool *rt_mp_t;
1231#endif /* RT_USING_MEMPOOL */
1232
1234
1235#ifdef RT_USING_DEVICE
1239
1241
1280
1284#define RT_DEVICE_FLAG_DEACTIVATE 0x000
1285
1286#define RT_DEVICE_FLAG_RDONLY 0x001
1287#define RT_DEVICE_FLAG_WRONLY 0x002
1288#define RT_DEVICE_FLAG_RDWR 0x003
1289
1290#define RT_DEVICE_FLAG_REMOVABLE 0x004
1291#define RT_DEVICE_FLAG_STANDALONE 0x008
1292#define RT_DEVICE_FLAG_ACTIVATED 0x010
1293#define RT_DEVICE_FLAG_SUSPENDED 0x020
1294#define RT_DEVICE_FLAG_STREAM 0x040
1295#define RT_DEVICE_FLAG_DYNAMIC 0x080
1296
1297#define RT_DEVICE_FLAG_INT_RX 0x100
1298#define RT_DEVICE_FLAG_DMA_RX 0x200
1299#define RT_DEVICE_FLAG_INT_TX 0x400
1300#define RT_DEVICE_FLAG_DMA_TX 0x800
1301
1302#define RT_DEVICE_OFLAG_CLOSE 0x000
1303#define RT_DEVICE_OFLAG_RDONLY 0x001
1304#define RT_DEVICE_OFLAG_WRONLY 0x002
1305#define RT_DEVICE_OFLAG_RDWR 0x003
1306#define RT_DEVICE_OFLAG_OPEN 0x008
1307#define RT_DEVICE_OFLAG_MASK 0xf0f
1308
1315#define RT_DEVICE_CTRL_RESUME 0x01
1316#define RT_DEVICE_CTRL_SUSPEND 0x02
1317#define RT_DEVICE_CTRL_CONFIG 0x03
1318#define RT_DEVICE_CTRL_CLOSE 0x04
1319#define RT_DEVICE_CTRL_NOTIFY_SET 0x05
1320#define RT_DEVICE_CTRL_SET_INT 0x06
1321#define RT_DEVICE_CTRL_CLR_INT 0x07
1322#define RT_DEVICE_CTRL_GET_INT 0x08
1323#define RT_DEVICE_CTRL_CONSOLE_OFLAG 0x09
1324#define RT_DEVICE_CTRL_MASK 0x1f
1325
1329#define RT_DEVICE_CTRL_BASE(Type) ((RT_Device_Class_##Type + 1) * 0x100)
1330
1331typedef struct rt_driver *rt_driver_t;
1332typedef struct rt_device *rt_device_t;
1333
1334#ifdef RT_USING_DEVICE_OPS
1338struct rt_device_ops
1339{
1340 /* common device interface */
1341 rt_err_t (*init) (rt_device_t dev);
1342 rt_err_t (*open) (rt_device_t dev, rt_uint16_t oflag);
1343 rt_err_t (*close) (rt_device_t dev);
1344 rt_ssize_t (*read) (rt_device_t dev, rt_off_t pos, void *buffer, rt_size_t size);
1345 rt_ssize_t (*write) (rt_device_t dev, rt_off_t pos, const void *buffer, rt_size_t size);
1346 rt_err_t (*control)(rt_device_t dev, int cmd, void *args);
1347};
1348#endif /* RT_USING_DEVICE_OPS */
1349
1359typedef struct rt_wqueue rt_wqueue_t;
1360
1361#ifdef RT_USING_DM
1362struct rt_driver;
1363struct rt_bus;
1364#endif /* RT_USING_DM */
1365
1370{
1372
1373#ifdef RT_USING_DM
1374 struct rt_bus *bus;
1375 rt_list_t node;
1376 struct rt_driver *drv;
1377#ifdef RT_USING_OFW
1378 void *ofw_node;
1379#endif /* RT_USING_OFW */
1380 void *power_domain_unit;
1381#ifdef RT_USING_DMA
1382 const void *dma_ops;
1383#endif
1384#endif /* RT_USING_DM */
1385
1389
1391#ifdef RT_USING_DM
1392 rt_uint8_t master_id;
1393#endif
1395
1396 /* device call back */
1398 rt_err_t (*tx_complete)(rt_device_t dev, void *buffer);
1399
1400#ifdef RT_USING_DEVICE_OPS
1401 const struct rt_device_ops *ops;
1402#else
1403 /* common device interface */
1407 rt_ssize_t (*read) (rt_device_t dev, rt_off_t pos, void *buffer, rt_size_t size);
1408 rt_ssize_t (*write) (rt_device_t dev, rt_off_t pos, const void *buffer, rt_size_t size);
1409 rt_err_t (*control)(rt_device_t dev, int cmd, void *args);
1410#endif /* RT_USING_DEVICE_OPS */
1411
1412#ifdef RT_USING_POSIX_DEVIO
1413 const struct dfs_file_ops *fops;
1414 struct rt_wqueue wait_queue;
1415#endif /* RT_USING_POSIX_DEVIO */
1416
1418 (rt_device_t dev, char *buf, int len);
1419
1421};
1422
1427{
1430};
1431
1432#ifdef RT_USING_SMART
1433struct rt_channel
1434{
1435 struct rt_ipc_object parent;
1436 struct rt_thread *reply;
1437 struct rt_spinlock slock;
1438 rt_list_t wait_msg;
1439 rt_list_t wait_thread;
1440 rt_wqueue_t reader_queue;
1442 rt_ubase_t ref;
1443};
1444typedef struct rt_channel *rt_channel_t;
1445#endif /* RT_USING_SMART */
1446
1448#endif /* RT_USING_DEVICE */
1449
1450#ifdef __cplusplus
1451}
1452#endif
1453
1454#ifdef __cplusplus
1455/* RT-Thread definitions for C++ */
1456namespace rtthread {
1457
1458enum TICK_WAIT {
1459 WAIT_NONE = 0,
1460 WAIT_FOREVER = -1,
1461};
1462
1463}
1464
1465#endif /* __cplusplus */
1466
1467#endif /* __RT_DEF_H__ */
void(* rt_timer_func_t)(void *parameter)
struct rt_timer * rt_timer_t
#define RT_TIMER_SKIP_LIST_LEVEL
rt_device_class_type
struct rt_device * rt_device_t
struct rt_driver * rt_driver_t
struct rt_wqueue rt_wqueue_t
@ RT_Device_Class_SPIDevice
@ RT_Device_Class_Timer
@ RT_Device_Class_Touch
@ RT_Device_Class_Miscellaneous
@ RT_Device_Class_Graphic
@ RT_Device_Class_Bus
@ RT_Device_Class_PM
@ RT_Device_Class_MTD
@ RT_Device_Class_CAN
@ RT_Device_Class_Portal
@ RT_Device_Class_DAC
@ RT_Device_Class_PWM
@ RT_Device_Class_Block
@ RT_Device_Class_ADC
@ RT_Device_Class_Pipe
@ RT_Device_Class_USBOTG
@ RT_Device_Class_Sound
@ RT_Device_Class_Pin
@ RT_Device_Class_NetIf
@ RT_Device_Class_RTC
@ RT_Device_Class_WLAN
@ RT_Device_Class_SDIO
@ RT_Device_Class_USBDevice
@ RT_Device_Class_PHY
@ RT_Device_Class_Char
@ RT_Device_Class_Security
@ RT_Device_Class_USBHost
@ RT_Device_Class_WDT
@ RT_Device_Class_Unknown
@ RT_Device_Class_I2CBUS
@ RT_Device_Class_Sensor
@ RT_Device_Class_SPIBUS
ssize_t write(int fd, const void *buf, size_t len)
ssize_t read(int fd, void *buf, size_t len)
int open(const char *file, int flags,...)
int close(int fd)
int stat(const char *file, struct stat *buf)
rt_object_class_type
struct rt_object * rt_object_t
rt_err_t(* rt_object_iter_t)(rt_object_t object, void *data)
@ RT_Object_Class_Memory
@ RT_Object_Class_Module
@ RT_Object_Class_MemHeap
@ RT_Object_Class_Timer
@ RT_Object_Class_MessageQueue
@ RT_Object_Class_ProcessGroup
@ RT_Object_Class_MemPool
@ RT_Object_Class_Thread
@ RT_Object_Class_MailBox
@ RT_Object_Class_Unknown
@ RT_Object_Class_Channel
@ RT_Object_Class_Semaphore
@ RT_Object_Class_Null
@ RT_Object_Class_Session
@ RT_Object_Class_Event
@ RT_Object_Class_Static
@ RT_Object_Class_Device
@ RT_Object_Class_Custom
@ RT_Object_Class_Mutex
rt_mem_t rt_smem_t
struct rt_mempool * rt_mp_t
struct rt_memory * rt_mem_t
struct rt_cpu_usage_stats * rt_cpu_usage_stats_t
void(* rt_thread_cleanup_t)(struct rt_thread *tid)
struct rt_cpu * rt_cpu_t
struct rt_thread * rt_thread_t
struct rt_interrupt_context * rt_interrupt_context_t
@ RT_KILLABLE
@ RT_INTERRUPTIBLE
@ RT_UNINTERRUPTIBLE
struct rt_event * rt_event_t
struct rt_mailbox * rt_mailbox_t
struct rt_messagequeue * rt_mq_t
struct rt_mutex * rt_mutex_t
struct rt_semaphore * rt_sem_t
#define RT_SCHED_THREAD_CTX
rt_base_t rt_ssize_t
rt_base_t rt_off_t
int rt_bool_t
rt_base_t rt_err_t
unsigned char rt_uint8_t
unsigned short rt_uint16_t
rt_uint32_t rt_tick_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
unsigned long long rt_uint64_t
struct rt_slist_node rt_slist_t
struct rt_thread * current_thread
struct rt_thread * idle_thread
struct rt_device * dev
void(* notify)(rt_device_t dev)
rt_uint16_t open_flag
enum rt_device_class_type type
rt_uint8_t device_id
rt_uint8_t ref_count
rt_uint16_t flag
struct rt_object parent
rt_err_t(* init)(rt_device_t dev)
rt_err_t(* open)(rt_device_t dev, rt_uint16_t oflag)
void * user_data
rt_err_t(* close)(rt_device_t dev)
rt_ssize_t(* write)(rt_device_t dev, rt_off_t pos, const void *buffer, rt_size_t size)
rt_ssize_t(* read)(rt_device_t dev, rt_off_t pos, void *buffer, rt_size_t size)
rt_err_t(* control)(rt_device_t dev, int cmd, void *args)
rt_err_t(* tx_complete)(rt_device_t dev, void *buffer)
rt_err_t(* rx_indicate)(rt_device_t dev, rt_size_t size)
rt_err_t(* readlink)(rt_device_t dev, char *buf, int len)
rt_uint32_t set
struct rt_spinlock spinlock
struct rt_ipc_object parent
struct rt_object parent
rt_list_t suspend_thread
rt_list_t suspend_sender_thread
struct rt_ipc_object parent
rt_uint16_t in_offset
struct rt_spinlock spinlock
rt_uint16_t out_offset
rt_ubase_t * msg_pool
rt_uint16_t entry
rt_uint16_t size
rt_size_t total
rt_ubase_t address
struct rt_object parent
rt_size_t max
const char * algorithm
rt_size_t used
struct rt_spinlock spinlock
rt_size_t block_total_count
rt_size_t size
rt_size_t block_size
void * start_address
rt_list_t suspend_thread
struct rt_object parent
rt_uint8_t * block_list
rt_size_t block_free_count
struct rt_ipc_object parent
rt_list_t suspend_sender_thread
rt_uint16_t msg_size
rt_uint16_t max_msgs
rt_uint16_t entry
struct rt_spinlock spinlock
struct rt_spinlock spinlock
rt_uint8_t ceiling_priority
struct rt_ipc_object parent
rt_list_t taken_list
rt_uint8_t priority
struct rt_thread * owner
rt_uint8_t reserved
rt_uint8_t hold
struct rt_spinlock spinlock
enum rt_object_class_type type
rt_list_t list
void * module_id
rt_uint8_t type
rt_uint8_t flag
const char * name
rt_uint16_t value
rt_uint16_t max_value
struct rt_spinlock spinlock
struct rt_ipc_object parent
void * parameter
struct rt_spinlock spinlock
void * stack_addr
rt_err_t error
struct rt_object parent
rt_object_t pending_object
rt_thread_cleanup_t cleanup
rt_uint8_t event_info
void * sp
rt_uint32_t event_set
void * entry
rt_uint32_t stack_size
rt_ubase_t user_data
RT_SCHED_THREAD_CTX struct rt_timer thread_timer
rt_list_t taken_object_list
struct rt_object parent
rt_timer_func_t timeout_func
void * parameter
rt_list_t row[RT_TIMER_SKIP_LIST_LEVEL]
rt_tick_t init_tick
rt_tick_t timeout_tick
rt_uint32_t flag
rt_list_t waiting_list
struct rt_spinlock spinlock