rtdef.h 62 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604
  1. /*
  2. * Copyright (c) 2006-2022, 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-12-18 xqyjlj add rt_always_inline
  57. * 2023-12-22 Shell Support hook list
  58. */
  59. #ifndef __RT_DEF_H__
  60. #define __RT_DEF_H__
  61. #include <rtconfig.h>
  62. #include <stdint.h>
  63. #include <stddef.h>
  64. #include <stdarg.h>
  65. #ifndef RT_USING_NANO
  66. #include <sys/types.h>
  67. #include <sys/errno.h>
  68. #if defined(RT_USING_SIGNALS) || defined(RT_USING_SMART)
  69. #include <sys/signal.h>
  70. #endif /* defined(RT_USING_SIGNALS) || defined(RT_USING_SMART) */
  71. #endif /* RT_USING_NANO */
  72. #ifdef __cplusplus
  73. extern "C" {
  74. #endif
  75. /**
  76. * @addtogroup BasicDef
  77. */
  78. /**@{*/
  79. /* RT-Thread version information */
  80. #define RT_VERSION_MAJOR 5 /**< Major version number (X.x.x) */
  81. #define RT_VERSION_MINOR 1 /**< Minor version number (x.X.x) */
  82. #define RT_VERSION_PATCH 0 /**< Patch version number (x.x.X) */
  83. /* e.g. #if (RTTHREAD_VERSION >= RT_VERSION_CHECK(4, 1, 0) */
  84. #define RT_VERSION_CHECK(major, minor, revise) ((major * 10000) + (minor * 100) + revise)
  85. /* RT-Thread version */
  86. #define RTTHREAD_VERSION RT_VERSION_CHECK(RT_VERSION_MAJOR, RT_VERSION_MINOR, RT_VERSION_PATCH)
  87. /* RT-Thread basic data type definitions */
  88. typedef int rt_bool_t; /**< boolean type */
  89. typedef signed long rt_base_t; /**< Nbit CPU related date type */
  90. typedef unsigned long rt_ubase_t; /**< Nbit unsigned CPU related data type */
  91. #ifndef RT_USING_ARCH_DATA_TYPE
  92. #ifdef RT_USING_LIBC
  93. typedef int8_t rt_int8_t; /**< 8bit integer type */
  94. typedef int16_t rt_int16_t; /**< 16bit integer type */
  95. typedef int32_t rt_int32_t; /**< 32bit integer type */
  96. typedef uint8_t rt_uint8_t; /**< 8bit unsigned integer type */
  97. typedef uint16_t rt_uint16_t; /**< 16bit unsigned integer type */
  98. typedef uint32_t rt_uint32_t; /**< 32bit unsigned integer type */
  99. typedef int64_t rt_int64_t; /**< 64bit integer type */
  100. typedef uint64_t rt_uint64_t; /**< 64bit unsigned integer type */
  101. #else
  102. typedef signed char rt_int8_t; /**< 8bit integer type */
  103. typedef signed short rt_int16_t; /**< 16bit integer type */
  104. typedef signed int rt_int32_t; /**< 32bit integer type */
  105. typedef unsigned char rt_uint8_t; /**< 8bit unsigned integer type */
  106. typedef unsigned short rt_uint16_t; /**< 16bit unsigned integer type */
  107. typedef unsigned int rt_uint32_t; /**< 32bit unsigned integer type */
  108. #ifdef ARCH_CPU_64BIT
  109. typedef signed long rt_int64_t; /**< 64bit integer type */
  110. typedef unsigned long rt_uint64_t; /**< 64bit unsigned integer type */
  111. #else
  112. typedef signed long long rt_int64_t; /**< 64bit integer type */
  113. typedef unsigned long long rt_uint64_t; /**< 64bit unsigned integer type */
  114. #endif /* ARCH_CPU_64BIT */
  115. #endif /* RT_USING_LIBC */
  116. #endif /* RT_USING_ARCH_DATA_TYPE */
  117. #if defined(RT_USING_LIBC) && !defined(RT_USING_NANO)
  118. typedef size_t rt_size_t; /**< Type for size number */
  119. typedef ssize_t rt_ssize_t; /**< Used for a count of bytes or an error indication */
  120. #else
  121. typedef rt_ubase_t rt_size_t; /**< Type for size number */
  122. typedef rt_base_t rt_ssize_t; /**< Used for a count of bytes or an error indication */
  123. #endif /* defined(RT_USING_LIBC) && !defined(RT_USING_NANO) */
  124. typedef rt_base_t rt_err_t; /**< Type for error number */
  125. typedef rt_uint32_t rt_time_t; /**< Type for time stamp */
  126. typedef rt_uint32_t rt_tick_t; /**< Type for tick count */
  127. typedef rt_base_t rt_flag_t; /**< Type for flags */
  128. typedef rt_ubase_t rt_dev_t; /**< Type for device */
  129. typedef rt_base_t rt_off_t; /**< Type for offset */
  130. #ifdef __cplusplus
  131. typedef rt_base_t rt_atomic_t;
  132. #else
  133. #if defined(RT_USING_HW_ATOMIC)
  134. typedef rt_base_t rt_atomic_t;
  135. #elif defined(RT_USING_STDC_ATOMIC)
  136. #include <stdatomic.h>
  137. typedef atomic_size_t rt_atomic_t;
  138. #else
  139. typedef rt_base_t rt_atomic_t;
  140. #endif /* RT_USING_STDC_ATOMIC */
  141. #endif /* __cplusplus */
  142. /* boolean type definitions */
  143. #define RT_TRUE 1 /**< boolean true */
  144. #define RT_FALSE 0 /**< boolean fails */
  145. /* null pointer definition */
  146. #define RT_NULL 0
  147. /**@}*/
  148. /* maximum value of base type */
  149. #ifdef RT_USING_LIBC
  150. #define RT_UINT8_MAX UINT8_MAX /**< Maximum number of UINT8 */
  151. #define RT_UINT16_MAX UINT16_MAX /**< Maximum number of UINT16 */
  152. #define RT_UINT32_MAX UINT32_MAX /**< Maximum number of UINT32 */
  153. #define RT_UINT64_MAX UINT64_MAX /**< Maximum number of UINT64 */
  154. #else
  155. #define RT_UINT8_MAX 0xff /**< Maximum number of UINT8 */
  156. #define RT_UINT16_MAX 0xffff /**< Maximum number of UINT16 */
  157. #define RT_UINT32_MAX 0xffffffff /**< Maximum number of UINT32 */
  158. #define RT_UINT64_MAX 0xffffffffffffffff
  159. #endif /* RT_USING_LIBC */
  160. #define RT_TICK_MAX RT_UINT32_MAX /**< Maximum number of tick */
  161. /* maximum value of ipc type */
  162. #define RT_SEM_VALUE_MAX RT_UINT16_MAX /**< Maximum number of semaphore .value */
  163. #define RT_MUTEX_VALUE_MAX RT_UINT16_MAX /**< Maximum number of mutex .value */
  164. #define RT_MUTEX_HOLD_MAX RT_UINT8_MAX /**< Maximum number of mutex .hold */
  165. #define RT_MB_ENTRY_MAX RT_UINT16_MAX /**< Maximum number of mailbox .entry */
  166. #define RT_MQ_ENTRY_MAX RT_UINT16_MAX /**< Maximum number of message queue .entry */
  167. /* Common Utilities */
  168. #define RT_UNUSED(x) ((void)x)
  169. /* compile time assertion */
  170. #define RT_STATIC_ASSERT(name, expn) typedef char _static_assert_##name[(expn)?1:-1]
  171. /* Compiler Related Definitions */
  172. #if defined(__ARMCC_VERSION) /* ARM Compiler */
  173. #define rt_section(x) __attribute__((section(x)))
  174. #define rt_used __attribute__((used))
  175. #define rt_align(n) __attribute__((aligned(n)))
  176. #define rt_weak __attribute__((weak))
  177. #define rt_typeof typeof
  178. #define rt_noreturn
  179. #define rt_inline static __inline
  180. #define rt_always_inline rt_inline
  181. #elif defined (__IAR_SYSTEMS_ICC__) /* for IAR Compiler */
  182. #define rt_section(x) @ x
  183. #define rt_used __root
  184. #define PRAGMA(x) _Pragma(#x)
  185. #define rt_align(n) PRAGMA(data_alignment=n)
  186. #define rt_weak __weak
  187. #define rt_typeof typeof
  188. #define rt_noreturn
  189. #define rt_inline static inline
  190. #define rt_always_inline rt_inline
  191. #elif defined (__GNUC__) /* GNU GCC Compiler */
  192. #define __RT_STRINGIFY(x...) #x
  193. #define RT_STRINGIFY(x...) __RT_STRINGIFY(x)
  194. #define rt_section(x) __attribute__((section(x)))
  195. #define rt_used __attribute__((used))
  196. #define rt_align(n) __attribute__((aligned(n)))
  197. #define rt_weak __attribute__((weak))
  198. #define rt_typeof __typeof__
  199. #define rt_noreturn __attribute__ ((noreturn))
  200. #define rt_inline static __inline
  201. #define rt_always_inline static inline __attribute__((always_inline))
  202. #elif defined (__ADSPBLACKFIN__) /* for VisualDSP++ Compiler */
  203. #define rt_section(x) __attribute__((section(x)))
  204. #define rt_used __attribute__((used))
  205. #define rt_align(n) __attribute__((aligned(n)))
  206. #define rt_weak __attribute__((weak))
  207. #define rt_typeof typeof
  208. #define rt_noreturn
  209. #define rt_inline static inline
  210. #define rt_always_inline rt_inline
  211. #elif defined (_MSC_VER)
  212. #define rt_section(x)
  213. #define rt_used
  214. #define rt_align(n) __declspec(align(n))
  215. #define rt_weak
  216. #define rt_typeof typeof
  217. #define rt_noreturn
  218. #define rt_inline static __inline
  219. #define rt_always_inline rt_inline
  220. #elif defined (__TI_COMPILER_VERSION__)
  221. /* The way that TI compiler set section is different from other(at least
  222. * GCC and MDK) compilers. See ARM Optimizing C/C++ Compiler 5.9.3 for more
  223. * details. */
  224. #define rt_section(x) __attribute__((section(x)))
  225. #ifdef __TI_EABI__
  226. #define rt_used __attribute__((retain)) __attribute__((used))
  227. #else
  228. #define rt_used __attribute__((used))
  229. #endif
  230. #define PRAGMA(x) _Pragma(#x)
  231. #define rt_align(n) __attribute__((aligned(n)))
  232. #ifdef __TI_EABI__
  233. #define rt_weak __attribute__((weak))
  234. #else
  235. #define rt_weak
  236. #endif
  237. #define rt_typeof typeof
  238. #define rt_noreturn
  239. #define rt_inline static inline
  240. #define rt_always_inline rt_inline
  241. #elif defined (__TASKING__)
  242. #define rt_section(x) __attribute__((section(x)))
  243. #define rt_used __attribute__((used, protect))
  244. #define PRAGMA(x) _Pragma(#x)
  245. #define rt_align(n) __attribute__((__align(n)))
  246. #define rt_weak __attribute__((weak))
  247. #define rt_typeof typeof
  248. #define rt_noreturn
  249. #define rt_inline static inline
  250. #define rt_always_inline rt_inline
  251. #else
  252. #error not supported tool chain
  253. #endif /* __ARMCC_VERSION */
  254. /* initialization export */
  255. #ifdef RT_USING_COMPONENTS_INIT
  256. typedef int (*init_fn_t)(void);
  257. #ifdef _MSC_VER
  258. #pragma section("rti_fn$f",read)
  259. #ifdef RT_DEBUGING_AUTO_INIT
  260. struct rt_init_desc
  261. {
  262. const char* level;
  263. const init_fn_t fn;
  264. const char* fn_name;
  265. };
  266. #define INIT_EXPORT(fn, level) \
  267. const char __rti_level_##fn[] = ".rti_fn." level; \
  268. const char __rti_##fn##_name[] = #fn; \
  269. __declspec(allocate("rti_fn$f")) \
  270. rt_used const struct rt_init_desc __rt_init_msc_##fn = \
  271. {__rti_level_##fn, fn, __rti_##fn##_name};
  272. #else
  273. struct rt_init_desc
  274. {
  275. const char* level;
  276. const init_fn_t fn;
  277. };
  278. #define INIT_EXPORT(fn, level) \
  279. const char __rti_level_##fn[] = ".rti_fn." level; \
  280. __declspec(allocate("rti_fn$f")) \
  281. rt_used const struct rt_init_desc __rt_init_msc_##fn = \
  282. {__rti_level_##fn, fn };
  283. #endif /* RT_DEBUGING_AUTO_INIT */
  284. #else
  285. #ifdef RT_DEBUGING_AUTO_INIT
  286. struct rt_init_desc
  287. {
  288. const char* fn_name;
  289. const init_fn_t fn;
  290. };
  291. #define INIT_EXPORT(fn, level) \
  292. const char __rti_##fn##_name[] = #fn; \
  293. rt_used const struct rt_init_desc __rt_init_desc_##fn rt_section(".rti_fn." level) = \
  294. { __rti_##fn##_name, fn};
  295. #else
  296. #define INIT_EXPORT(fn, level) \
  297. rt_used const init_fn_t __rt_init_##fn rt_section(".rti_fn." level) = fn
  298. #endif /* RT_DEBUGING_AUTO_INIT */
  299. #endif
  300. #else
  301. #define INIT_EXPORT(fn, level)
  302. #endif
  303. /* board init routines will be called in board_init() function */
  304. #define INIT_BOARD_EXPORT(fn) INIT_EXPORT(fn, "1")
  305. /* init cpu, memory, interrupt-controller, bus... */
  306. #define INIT_CORE_EXPORT(fn) INIT_EXPORT(fn, "1.0")
  307. /* init pci/pcie, usb platform driver... */
  308. #define INIT_FRAMEWORK_EXPORT(fn) INIT_EXPORT(fn, "1.1")
  309. /* init platform, user code... */
  310. #define INIT_PLATFORM_EXPORT(fn) INIT_EXPORT(fn, "1.2")
  311. /* init sys-timer, clk, pinctrl... */
  312. #define INIT_SUBSYS_EXPORT(fn) INIT_EXPORT(fn, "1.3")
  313. /* init early drivers */
  314. #define INIT_DRIVER_EARLY_EXPORT(fn) INIT_EXPORT(fn, "1.4")
  315. /* pre/device/component/env/app init routines will be called in init_thread */
  316. /* components pre-initialization (pure software initialization) */
  317. #define INIT_PREV_EXPORT(fn) INIT_EXPORT(fn, "2")
  318. /* device initialization */
  319. #define INIT_DEVICE_EXPORT(fn) INIT_EXPORT(fn, "3")
  320. /* components initialization (dfs, lwip, ...) */
  321. #define INIT_COMPONENT_EXPORT(fn) INIT_EXPORT(fn, "4")
  322. /* environment initialization (mount disk, ...) */
  323. #define INIT_ENV_EXPORT(fn) INIT_EXPORT(fn, "5")
  324. /* application initialization (rtgui application etc ...) */
  325. #define INIT_APP_EXPORT(fn) INIT_EXPORT(fn, "6")
  326. /* init after mount fs */
  327. #define INIT_FS_EXPORT(fn) INIT_EXPORT(fn, "6.0")
  328. /* init in secondary_cpu_c_start */
  329. #define INIT_SECONDARY_CPU_EXPORT(fn) INIT_EXPORT(fn, "7")
  330. #if !defined(RT_USING_FINSH)
  331. /* define these to empty, even if not include finsh.h file */
  332. #define FINSH_FUNCTION_EXPORT(name, desc)
  333. #define FINSH_FUNCTION_EXPORT_ALIAS(name, alias, desc)
  334. #define MSH_CMD_EXPORT(command, desc)
  335. #define MSH_CMD_EXPORT_ALIAS(command, alias, desc)
  336. #elif !defined(FINSH_USING_SYMTAB)
  337. #define FINSH_FUNCTION_EXPORT_CMD(name, cmd, desc)
  338. #endif
  339. /* event length */
  340. #define RT_EVENT_LENGTH 32
  341. /* memory management option */
  342. #define RT_MM_PAGE_SIZE 4096
  343. #define RT_MM_PAGE_MASK (RT_MM_PAGE_SIZE - 1)
  344. #define RT_MM_PAGE_BITS 12
  345. /* kernel malloc definitions */
  346. #ifndef RT_KERNEL_MALLOC
  347. #define RT_KERNEL_MALLOC(sz) rt_malloc(sz)
  348. #endif
  349. #ifndef RT_KERNEL_FREE
  350. #define RT_KERNEL_FREE(ptr) rt_free(ptr)
  351. #endif
  352. #ifndef RT_KERNEL_REALLOC
  353. #define RT_KERNEL_REALLOC(ptr, size) rt_realloc(ptr, size)
  354. #endif
  355. /**
  356. * @addtogroup Error
  357. */
  358. /**@{*/
  359. /* RT-Thread error code definitions */
  360. #if defined(RT_USING_LIBC) && !defined(RT_USING_NANO)
  361. /* POSIX error code compatible */
  362. #define RT_EOK 0 /**< There is no error */
  363. #define RT_ERROR 255 /**< A generic/unknown error happens */
  364. #define RT_ETIMEOUT ETIMEDOUT /**< Timed out */
  365. #define RT_EFULL ENOSPC /**< The resource is full */
  366. #define RT_EEMPTY ENODATA /**< The resource is empty */
  367. #define RT_ENOMEM ENOMEM /**< No memory */
  368. #define RT_ENOSYS ENOSYS /**< Function not implemented */
  369. #define RT_EBUSY EBUSY /**< Busy */
  370. #define RT_EIO EIO /**< IO error */
  371. #define RT_EINTR EINTR /**< Interrupted system call */
  372. #define RT_EINVAL EINVAL /**< Invalid argument */
  373. #define RT_ENOENT ENOENT /**< No entry */
  374. #define RT_ENOSPC ENOSPC /**< No space left */
  375. #define RT_EPERM EPERM /**< Operation not permitted */
  376. #define RT_EFAULT EFAULT /**< Bad address */
  377. #define RT_ENOBUFS ENOBUFS /**< No buffer space is available */
  378. #define RT_ETRAP 254 /**< Trap event */
  379. #else
  380. #define RT_EOK 0 /**< There is no error */
  381. #define RT_ERROR 1 /**< A generic/unknown error happens */
  382. #define RT_ETIMEOUT 2 /**< Timed out */
  383. #define RT_EFULL 3 /**< The resource is full */
  384. #define RT_EEMPTY 4 /**< The resource is empty */
  385. #define RT_ENOMEM 5 /**< No memory */
  386. #define RT_ENOSYS 6 /**< Function not implemented */
  387. #define RT_EBUSY 7 /**< Busy */
  388. #define RT_EIO 8 /**< IO error */
  389. #define RT_EINTR 9 /**< Interrupted system call */
  390. #define RT_EINVAL 10 /**< Invalid argument */
  391. #define RT_ENOENT 11 /**< No entry */
  392. #define RT_ENOSPC 12 /**< No space left */
  393. #define RT_EPERM 13 /**< Operation not permitted */
  394. #define RT_ETRAP 14 /**< Trap event */
  395. #define RT_EFAULT 15 /**< Bad address */
  396. #define RT_ENOBUFS 16 /**< No buffer space is available */
  397. #endif /* defined(RT_USING_LIBC) && !defined(RT_USING_NANO) */
  398. /**@}*/
  399. /**
  400. * @ingroup BasicDef
  401. *
  402. * @def RT_IS_ALIGN(addr, align)
  403. * Return true(1) or false(0).
  404. * RT_IS_ALIGN(128, 4) is judging whether 128 aligns with 4.
  405. * The result is 1, which means 128 aligns with 4.
  406. * @note If the address is NULL, false(0) will be returned
  407. */
  408. #define RT_IS_ALIGN(addr, align) ((!(addr & (align - 1))) && (addr != RT_NULL))
  409. /**
  410. * @ingroup BasicDef
  411. *
  412. * @def RT_ALIGN(size, align)
  413. * Return the most contiguous size aligned at specified width. RT_ALIGN(13, 4)
  414. * would return 16.
  415. */
  416. #define RT_ALIGN(size, align) (((size) + (align) - 1) & ~((align) - 1))
  417. /**
  418. * @ingroup BasicDef
  419. *
  420. * @def RT_ALIGN_DOWN(size, align)
  421. * Return the down number of aligned at specified width. RT_ALIGN_DOWN(13, 4)
  422. * would return 12.
  423. */
  424. #define RT_ALIGN_DOWN(size, align) ((size) & ~((align) - 1))
  425. /**
  426. * Double List structure
  427. */
  428. struct rt_list_node
  429. {
  430. struct rt_list_node *next; /**< point to next node. */
  431. struct rt_list_node *prev; /**< point to prev node. */
  432. };
  433. typedef struct rt_list_node rt_list_t; /**< Type for lists. */
  434. /**
  435. * Single List structure
  436. */
  437. struct rt_slist_node
  438. {
  439. struct rt_slist_node *next; /**< point to next node. */
  440. };
  441. typedef struct rt_slist_node rt_slist_t; /**< Type for single list. */
  442. #ifdef RT_USING_SMP
  443. #include <cpuport.h> /* for spinlock from arch */
  444. struct rt_spinlock
  445. {
  446. rt_hw_spinlock_t lock;
  447. #if defined(RT_DEBUGING_SPINLOCK)
  448. void *owner;
  449. void *pc;
  450. #endif /* RT_DEBUGING_SPINLOCK */
  451. };
  452. typedef struct rt_spinlock rt_spinlock_t;
  453. #ifndef RT_SPINLOCK_INIT
  454. #define RT_SPINLOCK_INIT {{0}} // default
  455. #endif /* RT_SPINLOCK_INIT */
  456. #else
  457. typedef rt_ubase_t rt_spinlock_t;
  458. struct rt_spinlock
  459. {
  460. rt_spinlock_t lock;
  461. };
  462. #define RT_SPINLOCK_INIT {0}
  463. #endif /* RT_USING_SMP */
  464. #define RT_DEFINE_SPINLOCK(x) struct rt_spinlock x = RT_SPINLOCK_INIT
  465. /**
  466. * @addtogroup KernelObject
  467. */
  468. /**@{*/
  469. /*
  470. * kernel object macros
  471. */
  472. #define RT_OBJECT_FLAG_MODULE 0x80 /**< is module object. */
  473. /**
  474. * Base structure of Kernel object
  475. */
  476. struct rt_object
  477. {
  478. #if RT_NAME_MAX > 0
  479. char name[RT_NAME_MAX]; /**< dynamic name of kernel object */
  480. #else
  481. const char *name; /**< static name of kernel object */
  482. #endif /* RT_NAME_MAX > 0 */
  483. rt_uint8_t type; /**< type of kernel object */
  484. rt_uint8_t flag; /**< flag of kernel object */
  485. #ifdef RT_USING_MODULE
  486. void * module_id; /**< id of application module */
  487. #endif /* RT_USING_MODULE */
  488. #ifdef RT_USING_SMART
  489. rt_atomic_t lwp_ref_count; /**< ref count for lwp */
  490. #endif /* RT_USING_SMART */
  491. rt_list_t list; /**< list node of kernel object */
  492. };
  493. typedef struct rt_object *rt_object_t; /**< Type for kernel objects. */
  494. /**
  495. * The object type can be one of the follows with specific
  496. * macros enabled:
  497. * - Thread
  498. * - Semaphore
  499. * - Mutex
  500. * - Event
  501. * - MailBox
  502. * - MessageQueue
  503. * - MemHeap
  504. * - MemPool
  505. * - Device
  506. * - Timer
  507. * - Module
  508. * - Unknown
  509. * - Static
  510. */
  511. enum rt_object_class_type
  512. {
  513. RT_Object_Class_Null = 0x00, /**< The object is not used. */
  514. RT_Object_Class_Thread = 0x01, /**< The object is a thread. */
  515. RT_Object_Class_Semaphore = 0x02, /**< The object is a semaphore. */
  516. RT_Object_Class_Mutex = 0x03, /**< The object is a mutex. */
  517. RT_Object_Class_Event = 0x04, /**< The object is a event. */
  518. RT_Object_Class_MailBox = 0x05, /**< The object is a mail box. */
  519. RT_Object_Class_MessageQueue = 0x06, /**< The object is a message queue. */
  520. RT_Object_Class_MemHeap = 0x07, /**< The object is a memory heap. */
  521. RT_Object_Class_MemPool = 0x08, /**< The object is a memory pool. */
  522. RT_Object_Class_Device = 0x09, /**< The object is a device. */
  523. RT_Object_Class_Timer = 0x0a, /**< The object is a timer. */
  524. RT_Object_Class_Module = 0x0b, /**< The object is a module. */
  525. RT_Object_Class_Memory = 0x0c, /**< The object is a memory. */
  526. RT_Object_Class_Channel = 0x0d, /**< The object is a channel */
  527. RT_Object_Class_Custom = 0x0e, /**< The object is a custom object */
  528. RT_Object_Class_Unknown = 0x0f, /**< The object is unknown. */
  529. RT_Object_Class_Static = 0x80 /**< The object is a static object. */
  530. };
  531. /**
  532. * The information of the kernel object
  533. */
  534. struct rt_object_information
  535. {
  536. enum rt_object_class_type type; /**< object class type */
  537. rt_list_t object_list; /**< object list */
  538. rt_size_t object_size; /**< object size */
  539. struct rt_spinlock spinlock;
  540. };
  541. /**
  542. * The hook function call macro
  543. */
  544. #ifndef RT_USING_HOOK
  545. #define RT_OBJECT_HOOK_CALL(func, argv)
  546. #else
  547. /**
  548. * @brief Add hook point in the routines
  549. * @note Usage:
  550. * void foo() {
  551. * do_something();
  552. *
  553. * RT_OBJECT_HOOK_CALL(foo);
  554. *
  555. * do_other_things();
  556. * }
  557. */
  558. #define _RT_OBJECT_HOOK_CALL(func, argv) __ON_HOOK_ARGS(func, argv)
  559. #define RT_OBJECT_HOOK_CALL(func, argv) _RT_OBJECT_HOOK_CALL(func, argv)
  560. #ifdef RT_HOOK_USING_FUNC_PTR
  561. #define __ON_HOOK_ARGS(__hook, argv) do {if ((__hook) != RT_NULL) __hook argv; } while (0)
  562. #else
  563. #define __ON_HOOK_ARGS(__hook, argv)
  564. #endif /* RT_HOOK_USING_FUNC_PTR */
  565. #endif /* RT_USING_HOOK */
  566. #ifdef RT_USING_HOOKLIST
  567. /**
  568. * @brief Add declaration for hook list types.
  569. *
  570. * @note Usage:
  571. * This is typically used in your header. In foo.h using this like:
  572. *
  573. * ```foo.h
  574. * typedef void (*bar_hook_proto_t)(arguments...);
  575. * RT_OBJECT_HOOKLIST_DECLARE(bar_hook_proto_t, bar_myhook);
  576. * ```
  577. */
  578. #define RT_OBJECT_HOOKLIST_DECLARE(handler_type, name) \
  579. typedef struct name##_hooklistnode \
  580. { \
  581. handler_type handler; \
  582. rt_list_t list_node; \
  583. } *name##_hooklistnode_t; \
  584. extern volatile rt_ubase_t name##_nested; \
  585. void name##_sethook(name##_hooklistnode_t node); \
  586. void name##_rmhook(name##_hooklistnode_t node)
  587. /**
  588. * @brief Add declaration for hook list node.
  589. *
  590. * @note Usage
  591. * You can add a hook like this.
  592. *
  593. * ```addhook.c
  594. * void myhook(arguments...) { do_something(); }
  595. * RT_OBJECT_HOOKLIST_DEFINE_NODE(bar_myhook, myhook_node, myhook);
  596. *
  597. * void addhook(void)
  598. * {
  599. * bar_myhook_sethook(myhook);
  600. * }
  601. * ```
  602. *
  603. * BTW, you can also find examples codes under
  604. * `examples/utest/testcases/kernel/hooklist_tc.c`.
  605. */
  606. #define RT_OBJECT_HOOKLIST_DEFINE_NODE(hookname, nodename, hooker_handler) \
  607. struct hookname##_hooklistnode nodename = { \
  608. .handler = hooker_handler, \
  609. .list_node = RT_LIST_OBJECT_INIT(nodename.list_node), \
  610. };
  611. /**
  612. * @note Usage
  613. * Add this macro to the source file where your hook point is inserted.
  614. */
  615. #define RT_OBJECT_HOOKLIST_DEFINE(name) \
  616. static rt_list_t name##_hooklist = RT_LIST_OBJECT_INIT(name##_hooklist); \
  617. static struct rt_spinlock name##lock = RT_SPINLOCK_INIT; \
  618. volatile rt_ubase_t name##_nested = 0; \
  619. void name##_sethook(name##_hooklistnode_t node) \
  620. { \
  621. rt_ubase_t level = rt_spin_lock_irqsave(&name##lock); \
  622. while (name##_nested) \
  623. { \
  624. rt_spin_unlock_irqrestore(&name##lock, level); \
  625. level = rt_spin_lock_irqsave(&name##lock); \
  626. } \
  627. rt_list_insert_before(&name##_hooklist, &node->list_node); \
  628. rt_spin_unlock_irqrestore(&name##lock, level); \
  629. } \
  630. void name##_rmhook(name##_hooklistnode_t node) \
  631. { \
  632. rt_ubase_t level = rt_spin_lock_irqsave(&name##lock); \
  633. while (name##_nested) \
  634. { \
  635. rt_spin_unlock_irqrestore(&name##lock, level); \
  636. level = rt_spin_lock_irqsave(&name##lock); \
  637. } \
  638. rt_list_remove(&node->list_node); \
  639. rt_spin_unlock_irqrestore(&name##lock, level); \
  640. }
  641. /**
  642. * @brief Add hook list point in the routines. Multiple hookers in the list will
  643. * be called one by one starting from head node.
  644. *
  645. * @note Usage:
  646. * void foo() {
  647. * do_something();
  648. *
  649. * RT_OBJECT_HOOKLIST_CALL(foo);
  650. *
  651. * do_other_things();
  652. * }
  653. */
  654. #define _RT_OBJECT_HOOKLIST_CALL(nodetype, nested, list, lock, argv) \
  655. do \
  656. { \
  657. nodetype iter; \
  658. rt_ubase_t level = rt_spin_lock_irqsave(&lock); \
  659. nested += 1; \
  660. rt_spin_unlock_irqrestore(&lock, level); \
  661. if (!rt_list_isempty(&list)) \
  662. { \
  663. rt_list_for_each_entry(iter, &list, list_node) \
  664. { \
  665. iter->handler argv; \
  666. } \
  667. } \
  668. level = rt_spin_lock_irqsave(&lock); \
  669. nested -= 1; \
  670. rt_spin_unlock_irqrestore(&lock, level); \
  671. } while (0)
  672. #define RT_OBJECT_HOOKLIST_CALL(name, argv) \
  673. _RT_OBJECT_HOOKLIST_CALL(name##_hooklistnode_t, name##_nested, \
  674. name##_hooklist, name##lock, argv)
  675. #else
  676. #define RT_OBJECT_HOOKLIST_DECLARE(handler_type, name)
  677. #define RT_OBJECT_HOOKLIST_DEFINE_NODE(hookname, nodename, hooker_handler)
  678. #define RT_OBJECT_HOOKLIST_DEFINE(name)
  679. #define RT_OBJECT_HOOKLIST_CALL(name, argv)
  680. #endif /* RT_USING_HOOKLIST */
  681. /**@}*/
  682. /**
  683. * @addtogroup Clock
  684. */
  685. /**@{*/
  686. /**
  687. * clock & timer macros
  688. */
  689. #define RT_TIMER_FLAG_DEACTIVATED 0x0 /**< timer is deactive */
  690. #define RT_TIMER_FLAG_ACTIVATED 0x1 /**< timer is active */
  691. #define RT_TIMER_FLAG_ONE_SHOT 0x0 /**< one shot timer */
  692. #define RT_TIMER_FLAG_PERIODIC 0x2 /**< periodic timer */
  693. #define RT_TIMER_FLAG_HARD_TIMER 0x0 /**< hard timer,the timer's callback function will be called in tick isr. */
  694. #define RT_TIMER_FLAG_SOFT_TIMER 0x4 /**< soft timer,the timer's callback function will be called in timer thread. */
  695. #define RT_TIMER_CTRL_SET_TIME 0x0 /**< set timer control command */
  696. #define RT_TIMER_CTRL_GET_TIME 0x1 /**< get timer control command */
  697. #define RT_TIMER_CTRL_SET_ONESHOT 0x2 /**< change timer to one shot */
  698. #define RT_TIMER_CTRL_SET_PERIODIC 0x3 /**< change timer to periodic */
  699. #define RT_TIMER_CTRL_GET_STATE 0x4 /**< get timer run state active or deactive*/
  700. #define RT_TIMER_CTRL_GET_REMAIN_TIME 0x5 /**< get the remaining hang time */
  701. #define RT_TIMER_CTRL_GET_FUNC 0x6 /**< get timer timeout func */
  702. #define RT_TIMER_CTRL_SET_FUNC 0x7 /**< set timer timeout func */
  703. #define RT_TIMER_CTRL_GET_PARM 0x8 /**< get timer parameter */
  704. #define RT_TIMER_CTRL_SET_PARM 0x9 /**< get timer parameter */
  705. #ifndef RT_TIMER_SKIP_LIST_LEVEL
  706. #define RT_TIMER_SKIP_LIST_LEVEL 1
  707. #endif
  708. /* 1 or 3 */
  709. #ifndef RT_TIMER_SKIP_LIST_MASK
  710. #define RT_TIMER_SKIP_LIST_MASK 0x3 /**< Timer skips the list mask */
  711. #endif
  712. /**
  713. * timer structure
  714. */
  715. struct rt_timer
  716. {
  717. struct rt_object parent; /**< inherit from rt_object */
  718. rt_list_t row[RT_TIMER_SKIP_LIST_LEVEL];
  719. void (*timeout_func)(void *parameter); /**< timeout function */
  720. void *parameter; /**< timeout function's parameter */
  721. rt_tick_t init_tick; /**< timer timeout tick */
  722. rt_tick_t timeout_tick; /**< timeout tick */
  723. };
  724. typedef struct rt_timer *rt_timer_t;
  725. /**@}*/
  726. /**
  727. * @addtogroup Signal
  728. */
  729. /**@{*/
  730. #ifdef RT_USING_SIGNALS
  731. #define RT_SIG_MAX 32
  732. typedef unsigned long rt_sigset_t;
  733. typedef siginfo_t rt_siginfo_t;
  734. typedef void (*rt_sighandler_t)(int signo);
  735. #endif /* RT_USING_SIGNALS */
  736. /**@}*/
  737. /**
  738. * @addtogroup Thread
  739. */
  740. /**@{*/
  741. /*
  742. * Thread
  743. */
  744. /*
  745. * thread state definitions
  746. */
  747. #define RT_THREAD_INIT 0x00 /**< Initialized status */
  748. #define RT_THREAD_CLOSE 0x01 /**< Closed status */
  749. #define RT_THREAD_READY 0x02 /**< Ready status */
  750. #define RT_THREAD_RUNNING 0x03 /**< Running status */
  751. /*
  752. * for rt_thread_suspend_with_flag()
  753. */
  754. enum
  755. {
  756. RT_INTERRUPTIBLE = 0,
  757. RT_KILLABLE,
  758. RT_UNINTERRUPTIBLE,
  759. };
  760. #define RT_THREAD_SUSPEND_MASK 0x04
  761. #define RT_SIGNAL_COMMON_WAKEUP_MASK 0x02
  762. #define RT_SIGNAL_KILL_WAKEUP_MASK 0x01
  763. #define RT_THREAD_SUSPEND_INTERRUPTIBLE (RT_THREAD_SUSPEND_MASK) /**< Suspend interruptable 0x4 */
  764. #define RT_THREAD_SUSPEND RT_THREAD_SUSPEND_INTERRUPTIBLE
  765. #define RT_THREAD_SUSPEND_KILLABLE (RT_THREAD_SUSPEND_MASK | RT_SIGNAL_COMMON_WAKEUP_MASK) /**< Suspend with killable 0x6 */
  766. #define RT_THREAD_SUSPEND_UNINTERRUPTIBLE (RT_THREAD_SUSPEND_MASK | RT_SIGNAL_COMMON_WAKEUP_MASK | RT_SIGNAL_KILL_WAKEUP_MASK) /**< Suspend with uninterruptable 0x7 */
  767. #define RT_THREAD_STAT_MASK 0x07
  768. #define RT_THREAD_STAT_YIELD 0x08 /**< indicate whether remaining_tick has been reloaded since last schedule */
  769. #define RT_THREAD_STAT_YIELD_MASK RT_THREAD_STAT_YIELD
  770. #define RT_THREAD_STAT_SIGNAL 0x10 /**< task hold signals */
  771. #define RT_THREAD_STAT_SIGNAL_READY (RT_THREAD_STAT_SIGNAL | RT_THREAD_READY)
  772. #define RT_THREAD_STAT_SIGNAL_WAIT 0x20 /**< task is waiting for signals */
  773. #define RT_THREAD_STAT_SIGNAL_PENDING 0x40 /**< signals is held and it has not been procressed */
  774. #define RT_THREAD_STAT_SIGNAL_MASK 0xf0
  775. /**
  776. * thread control command definitions
  777. */
  778. #define RT_THREAD_CTRL_STARTUP 0x00 /**< Startup thread. */
  779. #define RT_THREAD_CTRL_CLOSE 0x01 /**< Close thread. */
  780. #define RT_THREAD_CTRL_CHANGE_PRIORITY 0x02 /**< Change thread priority. */
  781. #define RT_THREAD_CTRL_INFO 0x03 /**< Get thread information. */
  782. #define RT_THREAD_CTRL_BIND_CPU 0x04 /**< Set thread bind cpu. */
  783. #ifdef RT_USING_SMP
  784. #define RT_CPU_DETACHED RT_CPUS_NR /**< The thread not running on cpu. */
  785. #define RT_CPU_MASK ((1 << RT_CPUS_NR) - 1) /**< All CPUs mask bit. */
  786. #ifndef RT_SCHEDULE_IPI
  787. #define RT_SCHEDULE_IPI 0
  788. #endif /* RT_SCHEDULE_IPI */
  789. #ifndef RT_STOP_IPI
  790. #define RT_STOP_IPI 1
  791. #endif /* RT_STOP_IPI */
  792. struct rt_cpu_usage_stats
  793. {
  794. rt_uint64_t user;
  795. rt_uint64_t system;
  796. rt_uint64_t irq;
  797. rt_uint64_t idle;
  798. };
  799. typedef struct rt_cpu_usage_stats *rt_cpu_usage_stats_t;
  800. /**
  801. * CPUs definitions
  802. *
  803. */
  804. struct rt_cpu
  805. {
  806. struct rt_thread *current_thread;
  807. struct rt_thread *idle_thread;
  808. rt_atomic_t irq_nest;
  809. rt_uint8_t irq_switch_flag;
  810. rt_uint8_t current_priority;
  811. rt_list_t priority_table[RT_THREAD_PRIORITY_MAX];
  812. #if RT_THREAD_PRIORITY_MAX > 32
  813. rt_uint32_t priority_group;
  814. rt_uint8_t ready_table[32];
  815. #else
  816. rt_uint32_t priority_group;
  817. #endif /* RT_THREAD_PRIORITY_MAX > 32 */
  818. rt_atomic_t tick;
  819. struct rt_spinlock spinlock;
  820. #ifdef RT_USING_SMART
  821. struct rt_cpu_usage_stats cpu_stat;
  822. #endif
  823. };
  824. typedef struct rt_cpu *rt_cpu_t;
  825. #endif /* RT_USING_SMP */
  826. struct rt_thread;
  827. #ifdef RT_USING_SMART
  828. typedef rt_err_t (*rt_wakeup_func_t)(void *object, struct rt_thread *thread);
  829. struct rt_wakeup
  830. {
  831. rt_wakeup_func_t func;
  832. void *user_data;
  833. };
  834. #define _LWP_NSIG 64
  835. #ifdef ARCH_CPU_64BIT
  836. #define _LWP_NSIG_BPW 64
  837. #else
  838. #define _LWP_NSIG_BPW 32
  839. #endif
  840. #define _LWP_NSIG_WORDS (RT_ALIGN(_LWP_NSIG, _LWP_NSIG_BPW) / _LWP_NSIG_BPW)
  841. typedef void (*lwp_sighandler_t)(int);
  842. typedef void (*lwp_sigaction_t)(int signo, siginfo_t *info, void *context);
  843. typedef struct {
  844. unsigned long sig[_LWP_NSIG_WORDS];
  845. } lwp_sigset_t;
  846. #if _LWP_NSIG <= 64
  847. #define lwp_sigmask(signo) ((lwp_sigset_t){.sig = {[0] = ((long)(1u << ((signo)-1)))}})
  848. #define lwp_sigset_init(mask) ((lwp_sigset_t){.sig = {[0] = (long)(mask)}})
  849. #endif
  850. struct lwp_sigaction {
  851. union {
  852. void (*_sa_handler)(int);
  853. void (*_sa_sigaction)(int, siginfo_t *, void *);
  854. } __sa_handler;
  855. lwp_sigset_t sa_mask;
  856. int sa_flags;
  857. void (*sa_restorer)(void);
  858. };
  859. typedef struct lwp_siginfo {
  860. rt_list_t node;
  861. struct {
  862. int signo;
  863. int code;
  864. long value;
  865. int from_tid;
  866. pid_t from_pid;
  867. } ksiginfo;
  868. } *lwp_siginfo_t;
  869. typedef struct lwp_sigqueue {
  870. rt_list_t siginfo_list;
  871. lwp_sigset_t sigset_pending;
  872. } *lwp_sigqueue_t;
  873. struct lwp_thread_signal {
  874. lwp_sigset_t sigset_mask;
  875. struct lwp_sigqueue sig_queue;
  876. };
  877. struct rt_user_context
  878. {
  879. void *sp;
  880. void *pc;
  881. void *flag;
  882. void *ctx;
  883. };
  884. #endif
  885. typedef void (*rt_thread_cleanup_t)(struct rt_thread *tid);
  886. /**
  887. * Thread structure
  888. */
  889. struct rt_thread
  890. {
  891. struct rt_object parent;
  892. rt_list_t tlist; /**< the thread list */
  893. rt_list_t tlist_schedule; /**< the thread list */
  894. /* stack point and entry */
  895. void *sp; /**< stack point */
  896. void *entry; /**< entry */
  897. void *parameter; /**< parameter */
  898. void *stack_addr; /**< stack address */
  899. rt_uint32_t stack_size; /**< stack size */
  900. /* error code */
  901. rt_err_t error; /**< error code */
  902. rt_uint8_t stat; /**< thread status */
  903. #ifdef RT_USING_SMP
  904. rt_uint8_t bind_cpu; /**< thread is bind to cpu */
  905. rt_uint8_t oncpu; /**< process on cpu */
  906. rt_atomic_t cpus_lock_nest; /**< cpus lock count */
  907. rt_atomic_t critical_lock_nest; /**< critical lock count */
  908. #endif /*RT_USING_SMP*/
  909. /* priority */
  910. rt_uint8_t current_priority; /**< current priority */
  911. rt_uint8_t init_priority; /**< initialized priority */
  912. #if RT_THREAD_PRIORITY_MAX > 32
  913. rt_uint8_t number;
  914. rt_uint8_t high_mask;
  915. #endif /* RT_THREAD_PRIORITY_MAX > 32 */
  916. rt_uint32_t number_mask; /**< priority number mask */
  917. #ifdef RT_USING_MUTEX
  918. /* object for IPC */
  919. rt_list_t taken_object_list;
  920. rt_object_t pending_object;
  921. #endif
  922. #ifdef RT_USING_EVENT
  923. /* thread event */
  924. rt_uint32_t event_set;
  925. rt_uint8_t event_info;
  926. #endif /* RT_USING_EVENT */
  927. #ifdef RT_USING_SIGNALS
  928. rt_sigset_t sig_pending; /**< the pending signals */
  929. rt_sigset_t sig_mask; /**< the mask bits of signal */
  930. #ifndef RT_USING_SMP
  931. void *sig_ret; /**< the return stack pointer from signal */
  932. #endif /* RT_USING_SMP */
  933. rt_sighandler_t *sig_vectors; /**< vectors of signal handler */
  934. void *si_list; /**< the signal infor list */
  935. #endif /* RT_USING_SIGNALS */
  936. rt_atomic_t init_tick; /**< thread's initialized tick */
  937. rt_atomic_t remaining_tick; /**< remaining tick */
  938. #ifdef RT_USING_CPU_USAGE
  939. rt_uint64_t duration_tick; /**< cpu usage tick */
  940. #endif /* RT_USING_CPU_USAGE */
  941. #ifdef RT_USING_PTHREADS
  942. void *pthread_data; /**< the handle of pthread data, adapt 32/64bit */
  943. #endif /* RT_USING_PTHREADS */
  944. struct rt_timer thread_timer; /**< built-in thread timer */
  945. rt_thread_cleanup_t cleanup; /**< cleanup function when thread exit */
  946. /* light weight process if present */
  947. #ifdef RT_USING_SMART
  948. void *msg_ret; /**< the return msg */
  949. void *lwp; /**< the lwp reference */
  950. /* for user create */
  951. void *user_entry;
  952. void *user_stack;
  953. rt_uint32_t user_stack_size;
  954. rt_uint32_t *kernel_sp; /**< kernel stack point */
  955. rt_list_t sibling; /**< next thread of same process */
  956. struct lwp_thread_signal signal; /**< lwp signal for user-space thread */
  957. struct rt_user_context user_ctx; /**< user space context */
  958. struct rt_wakeup wakeup; /**< wakeup data */
  959. int exit_request; /**< pending exit request of thread */
  960. int tid; /**< thread ID used by process */
  961. int tid_ref_count; /**< reference of tid */
  962. void *susp_recycler; /**< suspended recycler on this thread */
  963. rt_uint64_t user_time;
  964. rt_uint64_t system_time;
  965. #ifndef ARCH_MM_MMU
  966. lwp_sighandler_t signal_handler[32];
  967. #else
  968. int step_exec;
  969. int debug_attach_req;
  970. int debug_ret_user;
  971. int debug_suspend;
  972. struct rt_hw_exp_stack *regs;
  973. void *thread_idr; /** lwp thread indicator */
  974. int *clear_child_tid;
  975. #endif /* ARCH_MM_MMU */
  976. #endif /* RT_USING_SMART */
  977. #ifdef RT_USING_MEM_PROTECTION
  978. void *mem_regions;
  979. #ifdef RT_USING_HW_STACK_GUARD
  980. void *stack_buf;
  981. #endif
  982. #endif
  983. rt_atomic_t ref_count;
  984. struct rt_spinlock spinlock;
  985. rt_ubase_t user_data; /**< private user data beyond this thread */
  986. };
  987. typedef struct rt_thread *rt_thread_t;
  988. #ifdef RT_USING_SMART
  989. #define IS_USER_MODE(t) ((t)->user_ctx.ctx == RT_NULL)
  990. #endif /* RT_USING_SMART */
  991. /**@}*/
  992. #define rt_atomic_inc(v) rt_atomic_add((v), 1)
  993. #define rt_atomic_dec(v) rt_atomic_sub((v), 1)
  994. #define rt_get_thread_struct(object) do { rt_atomic_inc(&(object)->ref_count); } while(0)
  995. #define rt_put_thread_struct(object) do { rt_atomic_dec(&(object)->ref_count); } while(0)
  996. /**
  997. * @addtogroup IPC
  998. */
  999. /**@{*/
  1000. /**
  1001. * IPC flags and control command definitions
  1002. */
  1003. #define RT_IPC_FLAG_FIFO 0x00 /**< FIFOed IPC. @ref IPC. */
  1004. #define RT_IPC_FLAG_PRIO 0x01 /**< PRIOed IPC. @ref IPC. */
  1005. #define RT_IPC_CMD_UNKNOWN 0x00 /**< unknown IPC command */
  1006. #define RT_IPC_CMD_RESET 0x01 /**< reset IPC object */
  1007. #define RT_IPC_CMD_GET_STATE 0x02 /**< get the state of IPC object */
  1008. #define RT_IPC_CMD_SET_VLIMIT 0x03 /**< set max limit value of IPC value */
  1009. #define RT_WAITING_FOREVER -1 /**< Block forever until get resource. */
  1010. #define RT_WAITING_NO 0 /**< Non-block. */
  1011. /**
  1012. * Base structure of IPC object
  1013. */
  1014. struct rt_ipc_object
  1015. {
  1016. struct rt_object parent; /**< inherit from rt_object */
  1017. rt_list_t suspend_thread; /**< threads pended on this resource */
  1018. };
  1019. #ifdef RT_USING_SEMAPHORE
  1020. /**
  1021. * Semaphore structure
  1022. */
  1023. struct rt_semaphore
  1024. {
  1025. struct rt_ipc_object parent; /**< inherit from ipc_object */
  1026. rt_uint16_t value; /**< value of semaphore. */
  1027. rt_uint16_t max_value;
  1028. struct rt_spinlock spinlock;
  1029. };
  1030. typedef struct rt_semaphore *rt_sem_t;
  1031. #endif /* RT_USING_SEMAPHORE */
  1032. #ifdef RT_USING_MUTEX
  1033. /**
  1034. * Mutual exclusion (mutex) structure
  1035. */
  1036. struct rt_mutex
  1037. {
  1038. struct rt_ipc_object parent; /**< inherit from ipc_object */
  1039. rt_uint8_t ceiling_priority; /**< the priority ceiling of mutexe */
  1040. rt_uint8_t priority; /**< the maximal priority for pending thread */
  1041. rt_uint8_t hold; /**< numbers of thread hold the mutex */
  1042. rt_uint8_t reserved; /**< reserved field */
  1043. struct rt_thread *owner; /**< current owner of mutex */
  1044. rt_list_t taken_list; /**< the object list taken by thread */
  1045. struct rt_spinlock spinlock;
  1046. };
  1047. typedef struct rt_mutex *rt_mutex_t;
  1048. #endif /* RT_USING_MUTEX */
  1049. #ifdef RT_USING_EVENT
  1050. /**
  1051. * flag definitions in event
  1052. */
  1053. #define RT_EVENT_FLAG_AND 0x01 /**< logic and */
  1054. #define RT_EVENT_FLAG_OR 0x02 /**< logic or */
  1055. #define RT_EVENT_FLAG_CLEAR 0x04 /**< clear flag */
  1056. /*
  1057. * event structure
  1058. */
  1059. struct rt_event
  1060. {
  1061. struct rt_ipc_object parent; /**< inherit from ipc_object */
  1062. rt_uint32_t set; /**< event set */
  1063. struct rt_spinlock spinlock;
  1064. };
  1065. typedef struct rt_event *rt_event_t;
  1066. #endif /* RT_USING_EVENT */
  1067. #ifdef RT_USING_MAILBOX
  1068. /**
  1069. * mailbox structure
  1070. */
  1071. struct rt_mailbox
  1072. {
  1073. struct rt_ipc_object parent; /**< inherit from ipc_object */
  1074. rt_ubase_t *msg_pool; /**< start address of message buffer */
  1075. rt_uint16_t size; /**< size of message pool */
  1076. rt_uint16_t entry; /**< index of messages in msg_pool */
  1077. rt_uint16_t in_offset; /**< input offset of the message buffer */
  1078. rt_uint16_t out_offset; /**< output offset of the message buffer */
  1079. rt_list_t suspend_sender_thread; /**< sender thread suspended on this mailbox */
  1080. struct rt_spinlock spinlock;
  1081. };
  1082. typedef struct rt_mailbox *rt_mailbox_t;
  1083. #endif /* RT_USING_MAILBOX */
  1084. #ifdef RT_USING_MESSAGEQUEUE
  1085. /**
  1086. * message queue structure
  1087. */
  1088. struct rt_messagequeue
  1089. {
  1090. struct rt_ipc_object parent; /**< inherit from ipc_object */
  1091. void *msg_pool; /**< start address of message queue */
  1092. rt_uint16_t msg_size; /**< message size of each message */
  1093. rt_uint16_t max_msgs; /**< max number of messages */
  1094. rt_uint16_t entry; /**< index of messages in the queue */
  1095. void *msg_queue_head; /**< list head */
  1096. void *msg_queue_tail; /**< list tail */
  1097. void *msg_queue_free; /**< pointer indicated the free node of queue */
  1098. rt_list_t suspend_sender_thread; /**< sender thread suspended on this message queue */
  1099. struct rt_spinlock spinlock;
  1100. };
  1101. typedef struct rt_messagequeue *rt_mq_t;
  1102. #endif /* RT_USING_MESSAGEQUEUE */
  1103. /**@}*/
  1104. /**
  1105. * @addtogroup MM
  1106. */
  1107. /**@{*/
  1108. #ifdef RT_USING_HEAP
  1109. /*
  1110. * memory structure
  1111. */
  1112. struct rt_memory
  1113. {
  1114. struct rt_object parent; /**< inherit from rt_object */
  1115. const char * algorithm; /**< Memory management algorithm name */
  1116. rt_ubase_t address; /**< memory start address */
  1117. rt_size_t total; /**< memory size */
  1118. rt_size_t used; /**< size used */
  1119. rt_size_t max; /**< maximum usage */
  1120. };
  1121. typedef struct rt_memory *rt_mem_t;
  1122. #endif /* RT_USING_HEAP */
  1123. /*
  1124. * memory management
  1125. * heap & partition
  1126. */
  1127. #ifdef RT_USING_SMALL_MEM
  1128. typedef rt_mem_t rt_smem_t;
  1129. #endif /* RT_USING_SMALL_MEM */
  1130. #ifdef RT_USING_SLAB
  1131. typedef rt_mem_t rt_slab_t;
  1132. #endif /* RT_USING_SLAB */
  1133. #ifdef RT_USING_MEMHEAP
  1134. /**
  1135. * memory item on the heap
  1136. */
  1137. struct rt_memheap_item
  1138. {
  1139. rt_uint32_t magic; /**< magic number for memheap */
  1140. struct rt_memheap *pool_ptr; /**< point of pool */
  1141. struct rt_memheap_item *next; /**< next memheap item */
  1142. struct rt_memheap_item *prev; /**< prev memheap item */
  1143. struct rt_memheap_item *next_free; /**< next free memheap item */
  1144. struct rt_memheap_item *prev_free; /**< prev free memheap item */
  1145. #ifdef RT_USING_MEMTRACE
  1146. rt_uint8_t owner_thread_name[4]; /**< owner thread name */
  1147. #endif /* RT_USING_MEMTRACE */
  1148. };
  1149. /**
  1150. * Base structure of memory heap object
  1151. */
  1152. struct rt_memheap
  1153. {
  1154. struct rt_object parent; /**< inherit from rt_object */
  1155. void *start_addr; /**< pool start address and size */
  1156. rt_size_t pool_size; /**< pool size */
  1157. rt_size_t available_size; /**< available size */
  1158. rt_size_t max_used_size; /**< maximum allocated size */
  1159. struct rt_memheap_item *block_list; /**< used block list */
  1160. struct rt_memheap_item *free_list; /**< free block list */
  1161. struct rt_memheap_item free_header; /**< free block list header */
  1162. struct rt_semaphore lock; /**< semaphore lock */
  1163. rt_bool_t locked; /**< External lock mark */
  1164. };
  1165. #endif /* RT_USING_MEMHEAP */
  1166. #ifdef RT_USING_MEMPOOL
  1167. /**
  1168. * Base structure of Memory pool object
  1169. */
  1170. struct rt_mempool
  1171. {
  1172. struct rt_object parent; /**< inherit from rt_object */
  1173. void *start_address; /**< memory pool start */
  1174. rt_size_t size; /**< size of memory pool */
  1175. rt_size_t block_size; /**< size of memory blocks */
  1176. rt_uint8_t *block_list; /**< memory blocks list */
  1177. rt_size_t block_total_count; /**< numbers of memory block */
  1178. rt_size_t block_free_count; /**< numbers of free memory block */
  1179. rt_list_t suspend_thread; /**< threads pended on this resource */
  1180. struct rt_spinlock spinlock;
  1181. };
  1182. typedef struct rt_mempool *rt_mp_t;
  1183. #endif /* RT_USING_MEMPOOL */
  1184. /**@}*/
  1185. #ifdef RT_USING_DEVICE
  1186. /**
  1187. * @addtogroup Device
  1188. */
  1189. /**@{*/
  1190. /**
  1191. * device (I/O) class type
  1192. */
  1193. enum rt_device_class_type
  1194. {
  1195. RT_Device_Class_Char = 0, /**< character device */
  1196. RT_Device_Class_Block, /**< block device */
  1197. RT_Device_Class_NetIf, /**< net interface */
  1198. RT_Device_Class_MTD, /**< memory device */
  1199. RT_Device_Class_CAN, /**< CAN device */
  1200. RT_Device_Class_RTC, /**< RTC device */
  1201. RT_Device_Class_Sound, /**< Sound device */
  1202. RT_Device_Class_Graphic, /**< Graphic device */
  1203. RT_Device_Class_I2CBUS, /**< I2C bus device */
  1204. RT_Device_Class_USBDevice, /**< USB slave device */
  1205. RT_Device_Class_USBHost, /**< USB host bus */
  1206. RT_Device_Class_USBOTG, /**< USB OTG bus */
  1207. RT_Device_Class_SPIBUS, /**< SPI bus device */
  1208. RT_Device_Class_SPIDevice, /**< SPI device */
  1209. RT_Device_Class_SDIO, /**< SDIO bus device */
  1210. RT_Device_Class_PM, /**< PM pseudo device */
  1211. RT_Device_Class_Pipe, /**< Pipe device */
  1212. RT_Device_Class_Portal, /**< Portal device */
  1213. RT_Device_Class_Timer, /**< Timer device */
  1214. RT_Device_Class_Miscellaneous, /**< Miscellaneous device */
  1215. RT_Device_Class_Sensor, /**< Sensor device */
  1216. RT_Device_Class_Touch, /**< Touch device */
  1217. RT_Device_Class_PHY, /**< PHY device */
  1218. RT_Device_Class_Security, /**< Security device */
  1219. RT_Device_Class_WLAN, /**< WLAN device */
  1220. RT_Device_Class_Pin, /**< Pin device */
  1221. RT_Device_Class_ADC, /**< ADC device */
  1222. RT_Device_Class_DAC, /**< DAC device */
  1223. RT_Device_Class_WDT, /**< WDT device */
  1224. RT_Device_Class_PWM, /**< PWM device */
  1225. RT_Device_Class_Bus, /**< Bus device */
  1226. RT_Device_Class_Unknown /**< unknown device */
  1227. };
  1228. /**
  1229. * device flags definitions
  1230. */
  1231. #define RT_DEVICE_FLAG_DEACTIVATE 0x000 /**< device is not not initialized */
  1232. #define RT_DEVICE_FLAG_RDONLY 0x001 /**< read only */
  1233. #define RT_DEVICE_FLAG_WRONLY 0x002 /**< write only */
  1234. #define RT_DEVICE_FLAG_RDWR 0x003 /**< read and write */
  1235. #define RT_DEVICE_FLAG_REMOVABLE 0x004 /**< removable device */
  1236. #define RT_DEVICE_FLAG_STANDALONE 0x008 /**< standalone device */
  1237. #define RT_DEVICE_FLAG_ACTIVATED 0x010 /**< device is activated */
  1238. #define RT_DEVICE_FLAG_SUSPENDED 0x020 /**< device is suspended */
  1239. #define RT_DEVICE_FLAG_STREAM 0x040 /**< stream mode */
  1240. #define RT_DEVICE_FLAG_INT_RX 0x100 /**< INT mode on Rx */
  1241. #define RT_DEVICE_FLAG_DMA_RX 0x200 /**< DMA mode on Rx */
  1242. #define RT_DEVICE_FLAG_INT_TX 0x400 /**< INT mode on Tx */
  1243. #define RT_DEVICE_FLAG_DMA_TX 0x800 /**< DMA mode on Tx */
  1244. #define RT_DEVICE_OFLAG_CLOSE 0x000 /**< device is closed */
  1245. #define RT_DEVICE_OFLAG_RDONLY 0x001 /**< read only access */
  1246. #define RT_DEVICE_OFLAG_WRONLY 0x002 /**< write only access */
  1247. #define RT_DEVICE_OFLAG_RDWR 0x003 /**< read and write */
  1248. #define RT_DEVICE_OFLAG_OPEN 0x008 /**< device is opened */
  1249. #define RT_DEVICE_OFLAG_MASK 0xf0f /**< mask of open flag */
  1250. /**
  1251. * general device commands
  1252. * 0x01 - 0x1F general device control commands
  1253. * 0x20 - 0x3F udevice control commands
  1254. * 0x40 - special device control commands
  1255. */
  1256. #define RT_DEVICE_CTRL_RESUME 0x01 /**< resume device */
  1257. #define RT_DEVICE_CTRL_SUSPEND 0x02 /**< suspend device */
  1258. #define RT_DEVICE_CTRL_CONFIG 0x03 /**< configure device */
  1259. #define RT_DEVICE_CTRL_CLOSE 0x04 /**< close device */
  1260. #define RT_DEVICE_CTRL_NOTIFY_SET 0x05 /**< set notify func */
  1261. #define RT_DEVICE_CTRL_SET_INT 0x06 /**< set interrupt */
  1262. #define RT_DEVICE_CTRL_CLR_INT 0x07 /**< clear interrupt */
  1263. #define RT_DEVICE_CTRL_GET_INT 0x08 /**< get interrupt status */
  1264. #define RT_DEVICE_CTRL_CONSOLE_OFLAG 0x09 /**< get console open flag */
  1265. #define RT_DEVICE_CTRL_MASK 0x1f /**< mask for contrl commands */
  1266. /**
  1267. * device control
  1268. */
  1269. #define RT_DEVICE_CTRL_BASE(Type) ((RT_Device_Class_##Type + 1) * 0x100)
  1270. typedef struct rt_device *rt_device_t;
  1271. #ifdef RT_USING_DEVICE_OPS
  1272. /**
  1273. * operations set for device object
  1274. */
  1275. struct rt_device_ops
  1276. {
  1277. /* common device interface */
  1278. rt_err_t (*init) (rt_device_t dev);
  1279. rt_err_t (*open) (rt_device_t dev, rt_uint16_t oflag);
  1280. rt_err_t (*close) (rt_device_t dev);
  1281. rt_ssize_t (*read) (rt_device_t dev, rt_off_t pos, void *buffer, rt_size_t size);
  1282. rt_ssize_t (*write) (rt_device_t dev, rt_off_t pos, const void *buffer, rt_size_t size);
  1283. rt_err_t (*control)(rt_device_t dev, int cmd, void *args);
  1284. };
  1285. #endif /* RT_USING_DEVICE_OPS */
  1286. /**
  1287. * WaitQueue structure
  1288. */
  1289. struct rt_wqueue
  1290. {
  1291. rt_uint32_t flag;
  1292. rt_list_t waiting_list;
  1293. struct rt_spinlock spinlock;
  1294. };
  1295. typedef struct rt_wqueue rt_wqueue_t;
  1296. #ifdef RT_USING_DM
  1297. struct rt_driver;
  1298. struct rt_bus;
  1299. #endif
  1300. /**
  1301. * Device structure
  1302. */
  1303. struct rt_device
  1304. {
  1305. struct rt_object parent; /**< inherit from rt_object */
  1306. #ifdef RT_USING_DM
  1307. struct rt_bus *bus; /**< the bus mounting to */
  1308. rt_list_t node; /**< to mount on bus */
  1309. struct rt_driver *drv; /**< driver for powering the device */
  1310. #ifdef RT_USING_OFW
  1311. void *ofw_node; /**< ofw node get from device tree */
  1312. #endif
  1313. #endif
  1314. enum rt_device_class_type type; /**< device type */
  1315. rt_uint16_t flag; /**< device flag */
  1316. rt_uint16_t open_flag; /**< device open flag */
  1317. rt_uint8_t ref_count; /**< reference count */
  1318. rt_uint8_t device_id; /**< 0 - 255 */
  1319. /* device call back */
  1320. rt_err_t (*rx_indicate)(rt_device_t dev, rt_size_t size);
  1321. rt_err_t (*tx_complete)(rt_device_t dev, void *buffer);
  1322. #ifdef RT_USING_DEVICE_OPS
  1323. const struct rt_device_ops *ops;
  1324. #else
  1325. /* common device interface */
  1326. rt_err_t (*init) (rt_device_t dev);
  1327. rt_err_t (*open) (rt_device_t dev, rt_uint16_t oflag);
  1328. rt_err_t (*close) (rt_device_t dev);
  1329. rt_ssize_t (*read) (rt_device_t dev, rt_off_t pos, void *buffer, rt_size_t size);
  1330. rt_ssize_t (*write) (rt_device_t dev, rt_off_t pos, const void *buffer, rt_size_t size);
  1331. rt_err_t (*control)(rt_device_t dev, int cmd, void *args);
  1332. #endif /* RT_USING_DEVICE_OPS */
  1333. #ifdef RT_USING_POSIX_DEVIO
  1334. const struct dfs_file_ops *fops;
  1335. struct rt_wqueue wait_queue;
  1336. #endif /* RT_USING_POSIX_DEVIO */
  1337. void *user_data; /**< device private data */
  1338. };
  1339. /**
  1340. * Notify structure
  1341. */
  1342. struct rt_device_notify
  1343. {
  1344. void (*notify)(rt_device_t dev);
  1345. struct rt_device *dev;
  1346. };
  1347. #ifdef RT_USING_SMART
  1348. struct rt_channel
  1349. {
  1350. struct rt_ipc_object parent; /**< inherit from object */
  1351. struct rt_thread *reply; /**< the thread will be reply */
  1352. struct rt_spinlock slock; /**< spinlock of this channel */
  1353. rt_list_t wait_msg; /**< the wait queue of sender msg */
  1354. rt_list_t wait_thread; /**< the wait queue of sender thread */
  1355. rt_wqueue_t reader_queue; /**< channel poll queue */
  1356. rt_uint8_t stat; /**< the status of this channel */
  1357. rt_ubase_t ref;
  1358. };
  1359. typedef struct rt_channel *rt_channel_t;
  1360. #endif
  1361. /**@}*/
  1362. #endif /* RT_USING_DEVICE */
  1363. #ifdef __cplusplus
  1364. }
  1365. #endif
  1366. #ifdef __cplusplus
  1367. /* RT-Thread definitions for C++ */
  1368. namespace rtthread {
  1369. enum TICK_WAIT {
  1370. WAIT_NONE = 0,
  1371. WAIT_FOREVER = -1,
  1372. };
  1373. }
  1374. #endif /* __cplusplus */
  1375. #endif /* __RT_DEF_H__ */