kservice.c 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245
  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. * 2006-03-16 Bernard the first version
  9. * 2006-05-25 Bernard rewrite vsprintf
  10. * 2006-08-10 Bernard add rt_show_version
  11. * 2010-03-17 Bernard remove rt_strlcpy function
  12. * fix gcc compiling issue.
  13. * 2010-04-15 Bernard remove weak definition on ICCM16C compiler
  14. * 2012-07-18 Arda add the alignment display for signed integer
  15. * 2012-11-23 Bernard fix IAR compiler error.
  16. * 2012-12-22 Bernard fix rt_kprintf issue, which found by Grissiom.
  17. * 2013-06-24 Bernard remove rt_kprintf if RT_USING_CONSOLE is not defined.
  18. * 2013-09-24 aozima make sure the device is in STREAM mode when used by rt_kprintf.
  19. * 2015-07-06 Bernard Add rt_assert_handler routine.
  20. * 2021-02-28 Meco Man add RT_KSERVICE_USING_STDLIB
  21. * 2021-12-20 Meco Man implement rt_strcpy()
  22. * 2022-01-07 Gabriel add __on_rt_assert_hook
  23. * 2022-06-04 Meco Man remove strnlen
  24. * 2022-08-24 Yunjie make rt_memset word-independent to adapt to ti c28x (16bit word)
  25. * 2022-08-30 Yunjie make rt_vsnprintf adapt to ti c28x (16bit int)
  26. * 2023-02-02 Bernard add Smart ID for logo version show
  27. * 2023-10-16 Shell Add hook point for rt_malloc services
  28. * 2023-10-21 Shell support the common backtrace API which is arch-independent
  29. * 2023-12-10 xqyjlj perf rt_hw_interrupt_disable/enable, fix memheap lock
  30. * 2024-03-10 Meco Man move std libc related functions to rtklibc
  31. */
  32. #include <rtthread.h>
  33. /* include rt_hw_backtrace macro defined in cpuport.h */
  34. #define RT_HW_INCLUDE_CPUPORT
  35. #include <rthw.h>
  36. #define DBG_TAG "kernel.service"
  37. #ifdef RT_DEBUG_DEVICE
  38. #define DBG_LVL DBG_LOG
  39. #else
  40. #define DBG_LVL DBG_WARNING
  41. #endif /* defined (RT_DEBUG_DEVICE) */
  42. #include <rtdbg.h>
  43. #ifdef RT_USING_MODULE
  44. #include <dlmodule.h>
  45. #endif /* RT_USING_MODULE */
  46. #ifdef RT_USING_SMART
  47. #include <lwp.h>
  48. #include <lwp_user_mm.h>
  49. #endif
  50. /**
  51. * @addtogroup group_kernel_service
  52. * @{
  53. */
  54. #if defined(RT_USING_DEVICE) && defined(RT_USING_CONSOLE)
  55. static rt_device_t _console_device = RT_NULL;
  56. #endif
  57. rt_weak void rt_hw_us_delay(rt_uint32_t us)
  58. {
  59. (void) us;
  60. LOG_W("rt_hw_us_delay() doesn't support for this board."
  61. "Please consider implementing rt_hw_us_delay() in another file.");
  62. }
  63. rt_weak void rt_hw_cpu_reset(void)
  64. {
  65. LOG_W("rt_hw_cpu_reset() doesn't support for this board."
  66. "Please consider implementing rt_hw_cpu_reset() in another file.");
  67. return;
  68. }
  69. rt_weak void rt_hw_cpu_shutdown(void)
  70. {
  71. LOG_I("CPU shutdown...");
  72. LOG_W("Using default rt_hw_cpu_shutdown()."
  73. "Please consider implementing rt_hw_cpu_shutdown() in another file.");
  74. rt_hw_interrupt_disable();
  75. RT_ASSERT(0);
  76. return;
  77. }
  78. /**
  79. * @note can be overridden by cpuport.h which is defined by a specific arch
  80. */
  81. #ifndef RT_HW_BACKTRACE_FRAME_GET_SELF
  82. #ifdef __GNUC__
  83. #define RT_HW_BACKTRACE_FRAME_GET_SELF(frame) do { \
  84. (frame)->fp = (rt_uintptr_t)__builtin_frame_address(0U); \
  85. (frame)->pc = ({__label__ pc; pc: (rt_uintptr_t)&&pc;}); \
  86. } while (0)
  87. #else
  88. #define RT_HW_BACKTRACE_FRAME_GET_SELF(frame) do { \
  89. (frame)->fp = 0; \
  90. (frame)->pc = 0; \
  91. } while (0)
  92. #endif /* __GNUC__ */
  93. #endif /* RT_HW_BACKTRACE_FRAME_GET_SELF */
  94. /**
  95. * @brief Get the inner most frame of target thread
  96. *
  97. * @param thread the thread which frame belongs to
  98. * @param frame the specified frame to be unwound
  99. * @return rt_err_t 0 is succeed, otherwise a failure
  100. */
  101. rt_weak rt_err_t rt_hw_backtrace_frame_get(rt_thread_t thread, struct rt_hw_backtrace_frame *frame)
  102. {
  103. RT_UNUSED(thread);
  104. RT_UNUSED(frame);
  105. LOG_W("%s is not implemented", __func__);
  106. return -RT_ENOSYS;
  107. }
  108. /**
  109. * @brief Unwind the target frame
  110. *
  111. * @param thread the thread which frame belongs to
  112. * @param frame the specified frame to be unwound
  113. * @return rt_err_t 0 is succeed, otherwise a failure
  114. */
  115. rt_weak rt_err_t rt_hw_backtrace_frame_unwind(rt_thread_t thread, struct rt_hw_backtrace_frame *frame)
  116. {
  117. RT_UNUSED(thread);
  118. RT_UNUSED(frame);
  119. LOG_W("%s is not implemented", __func__);
  120. return -RT_ENOSYS;
  121. }
  122. rt_weak const char *rt_hw_cpu_arch(void)
  123. {
  124. return "unknown";
  125. }
  126. /**
  127. * @brief This function will show the version of rt-thread rtos
  128. */
  129. void rt_show_version(void)
  130. {
  131. rt_kprintf("\n \\ | /\n");
  132. #if defined(RT_USING_SMART)
  133. rt_kprintf("- RT - Thread Smart Operating System\n");
  134. #elif defined(RT_USING_NANO)
  135. rt_kprintf("- RT - Thread Nano Operating System\n");
  136. #else
  137. rt_kprintf("- RT - Thread Operating System\n");
  138. #endif
  139. rt_kprintf(" / | \\ %d.%d.%d build %s %s\n",
  140. (rt_int32_t)RT_VERSION_MAJOR, (rt_int32_t)RT_VERSION_MINOR, (rt_int32_t)RT_VERSION_PATCH, __DATE__, __TIME__);
  141. rt_kprintf(" 2006 - 2024 Copyright by RT-Thread team\n");
  142. }
  143. RTM_EXPORT(rt_show_version);
  144. #ifdef RT_USING_CONSOLE
  145. #ifdef RT_USING_DEVICE
  146. /**
  147. * @brief This function returns the device using in console.
  148. *
  149. * @return Returns the console device pointer or RT_NULL.
  150. */
  151. rt_device_t rt_console_get_device(void)
  152. {
  153. return _console_device;
  154. }
  155. RTM_EXPORT(rt_console_get_device);
  156. /**
  157. * @brief This function will set a device as console device.
  158. * After set a device to console, all output of rt_kprintf will be
  159. * redirected to this new device.
  160. *
  161. * @param name is the name of new console device.
  162. *
  163. * @return the old console device handler on successful, or RT_NULL on failure.
  164. */
  165. rt_device_t rt_console_set_device(const char *name)
  166. {
  167. rt_device_t old_device = _console_device;
  168. rt_device_t new_device = rt_device_find(name);
  169. if (new_device != RT_NULL && new_device != old_device)
  170. {
  171. if (old_device != RT_NULL)
  172. {
  173. /* close old console device */
  174. rt_device_close(old_device);
  175. }
  176. /* set new console device */
  177. rt_device_open(new_device, RT_DEVICE_OFLAG_RDWR | RT_DEVICE_FLAG_STREAM);
  178. _console_device = new_device;
  179. }
  180. return old_device;
  181. }
  182. RTM_EXPORT(rt_console_set_device);
  183. #endif /* RT_USING_DEVICE */
  184. #ifdef RT_USING_CONSOLE_OUTPUT_CTL
  185. static volatile rt_bool_t _console_output_enabled = RT_TRUE;
  186. /**
  187. * @brief Enable or disable console log output.
  188. *
  189. * @param enabled RT_TRUE to enable output, RT_FALSE to disable output.
  190. */
  191. void rt_console_output_set_enabled(rt_bool_t enabled)
  192. {
  193. _console_output_enabled = enabled;
  194. }
  195. RTM_EXPORT(rt_console_output_set_enabled);
  196. /**
  197. * @brief Get current console log output enable state.
  198. *
  199. * @return RT_TRUE if output is enabled, RT_FALSE otherwise.
  200. */
  201. rt_bool_t rt_console_output_get_enabled(void)
  202. {
  203. return _console_output_enabled;
  204. }
  205. RTM_EXPORT(rt_console_output_get_enabled);
  206. #endif /* RT_USING_CONSOLE_OUTPUT_CTL */
  207. rt_weak void rt_hw_console_output(const char *str)
  208. {
  209. /* empty console output */
  210. RT_UNUSED(str);
  211. }
  212. RTM_EXPORT(rt_hw_console_output);
  213. #ifdef RT_USING_THREADSAFE_PRINTF
  214. /* system console lock */
  215. static struct rt_spinlock _syscon_lock = RT_SPINLOCK_INIT;
  216. /* lock of kprintf buffer */
  217. static struct rt_spinlock _prbuf_lock = RT_SPINLOCK_INIT;
  218. /* current user of system console */
  219. static rt_thread_t _pr_curr_user;
  220. #ifdef RT_USING_DEBUG
  221. static rt_base_t _pr_critical_level;
  222. #endif /* RT_USING_DEBUG */
  223. /* nested level of current user */
  224. static volatile int _pr_curr_user_nested;
  225. rt_thread_t rt_console_current_user(void)
  226. {
  227. return _pr_curr_user;
  228. }
  229. static void _console_take(void)
  230. {
  231. rt_ubase_t level = rt_spin_lock_irqsave(&_syscon_lock);
  232. rt_thread_t self_thread = rt_thread_self();
  233. rt_base_t critical_level;
  234. RT_UNUSED(critical_level);
  235. while (_pr_curr_user != self_thread)
  236. {
  237. if (_pr_curr_user == RT_NULL)
  238. {
  239. /* no preemption is allowed to avoid dead lock */
  240. critical_level = rt_enter_critical();
  241. #ifdef RT_USING_DEBUG
  242. _pr_critical_level = _syscon_lock.critical_level;
  243. _syscon_lock.critical_level = critical_level;
  244. #endif
  245. _pr_curr_user = self_thread;
  246. break;
  247. }
  248. else
  249. {
  250. rt_spin_unlock_irqrestore(&_syscon_lock, level);
  251. rt_thread_yield();
  252. level = rt_spin_lock_irqsave(&_syscon_lock);
  253. }
  254. }
  255. _pr_curr_user_nested++;
  256. rt_spin_unlock_irqrestore(&_syscon_lock, level);
  257. }
  258. static void _console_release(void)
  259. {
  260. rt_ubase_t level = rt_spin_lock_irqsave(&_syscon_lock);
  261. rt_thread_t self_thread = rt_thread_self();
  262. RT_UNUSED(self_thread);
  263. RT_ASSERT(_pr_curr_user == self_thread);
  264. _pr_curr_user_nested--;
  265. if (!_pr_curr_user_nested)
  266. {
  267. _pr_curr_user = RT_NULL;
  268. #ifdef RT_USING_DEBUG
  269. rt_exit_critical_safe(_syscon_lock.critical_level);
  270. _syscon_lock.critical_level = _pr_critical_level;
  271. #else
  272. rt_exit_critical();
  273. #endif
  274. }
  275. rt_spin_unlock_irqrestore(&_syscon_lock, level);
  276. }
  277. #define CONSOLE_TAKE _console_take()
  278. #define CONSOLE_RELEASE _console_release()
  279. #define PRINTF_BUFFER_TAKE rt_ubase_t level = rt_spin_lock_irqsave(&_prbuf_lock)
  280. #define PRINTF_BUFFER_RELEASE rt_spin_unlock_irqrestore(&_prbuf_lock, level)
  281. #else
  282. #define CONSOLE_TAKE
  283. #define CONSOLE_RELEASE
  284. #define PRINTF_BUFFER_TAKE
  285. #define PRINTF_BUFFER_RELEASE
  286. #endif /* RT_USING_THREADSAFE_PRINTF */
  287. /**
  288. * @brief This function will put string to the console.
  289. *
  290. * @param str is the string output to the console.
  291. */
  292. static void _kputs(const char *str, long len)
  293. {
  294. #ifdef RT_USING_DEVICE
  295. rt_device_t console_device = rt_console_get_device();
  296. #endif /* RT_USING_DEVICE */
  297. CONSOLE_TAKE;
  298. #ifdef RT_USING_DEVICE
  299. if (console_device == RT_NULL)
  300. {
  301. rt_hw_console_output(str);
  302. }
  303. else
  304. {
  305. rt_device_write(console_device, 0, str, len);
  306. }
  307. #else
  308. RT_UNUSED(len);
  309. rt_hw_console_output(str);
  310. #endif /* RT_USING_DEVICE */
  311. CONSOLE_RELEASE;
  312. }
  313. /**
  314. * @brief This function will put string to the console.
  315. *
  316. * @param str is the string output to the console.
  317. */
  318. void rt_kputs(const char *str)
  319. {
  320. if (!str)
  321. {
  322. return;
  323. }
  324. if (!rt_console_output_get_enabled())
  325. {
  326. return;
  327. }
  328. _kputs(str, rt_strlen(str));
  329. }
  330. /**
  331. * @brief This function will print a formatted string on system console.
  332. *
  333. * @param fmt is the format parameters.
  334. *
  335. * @return The number of characters actually written to buffer.
  336. */
  337. rt_weak int rt_kprintf(const char *fmt, ...)
  338. {
  339. va_list args;
  340. rt_size_t length = 0;
  341. static char rt_log_buf[RT_CONSOLEBUF_SIZE];
  342. if (!rt_console_output_get_enabled())
  343. {
  344. return 0;
  345. }
  346. va_start(args, fmt);
  347. PRINTF_BUFFER_TAKE;
  348. /* the return value of vsnprintf is the number of bytes that would be
  349. * written to buffer had if the size of the buffer been sufficiently
  350. * large excluding the terminating null byte. If the output string
  351. * would be larger than the rt_log_buf, we have to adjust the output
  352. * length. */
  353. length = rt_vsnprintf(rt_log_buf, sizeof(rt_log_buf) - 1, fmt, args);
  354. if (length > RT_CONSOLEBUF_SIZE - 1)
  355. {
  356. length = RT_CONSOLEBUF_SIZE - 1;
  357. }
  358. _kputs(rt_log_buf, length);
  359. PRINTF_BUFFER_RELEASE;
  360. va_end(args);
  361. return length;
  362. }
  363. RTM_EXPORT(rt_kprintf);
  364. #endif /* RT_USING_CONSOLE */
  365. /**
  366. * @brief Print backtrace of current thread to system console device
  367. *
  368. * @return rt_err_t 0 is success, otherwise a failure
  369. */
  370. rt_weak rt_err_t rt_backtrace(void)
  371. {
  372. struct rt_hw_backtrace_frame frame;
  373. rt_thread_t thread = rt_thread_self();
  374. RT_HW_BACKTRACE_FRAME_GET_SELF(&frame);
  375. if (!frame.fp)
  376. return -RT_EINVAL;
  377. /* we don't want this frame to be printed which is nearly garbage info */
  378. rt_hw_backtrace_frame_unwind(thread, &frame);
  379. return rt_backtrace_frame(thread, &frame);
  380. }
  381. /**
  382. * @brief Print backtrace from frame to system console device
  383. *
  384. * @param thread the thread which frame belongs to
  385. * @param frame where backtrace starts from
  386. * @return rt_err_t 0 is success, otherwise a failure
  387. */
  388. rt_weak rt_err_t rt_backtrace_frame(rt_thread_t thread, struct rt_hw_backtrace_frame *frame)
  389. {
  390. long nesting = 0;
  391. rt_kprintf("please use: addr2line -e rtthread.elf -a -f\n");
  392. while (nesting < RT_BACKTRACE_LEVEL_MAX_NR)
  393. {
  394. rt_kprintf(" 0x%lx", (rt_ubase_t)frame->pc);
  395. if (rt_hw_backtrace_frame_unwind(thread, frame))
  396. {
  397. break;
  398. }
  399. nesting++;
  400. }
  401. rt_kprintf("\n");
  402. return RT_EOK;
  403. }
  404. /**
  405. * @brief Print backtrace from buffer to system console
  406. *
  407. * @param buffer where traced frames saved
  408. * @param buflen number of items in buffer
  409. * @return rt_err_t 0 is success, otherwise a failure
  410. */
  411. rt_weak rt_err_t rt_backtrace_formatted_print(rt_ubase_t *buffer, long buflen)
  412. {
  413. rt_kprintf("please use: addr2line -e rtthread.elf -a -f\n");
  414. for (rt_size_t i = 0; i < buflen && buffer[i] != 0; i++)
  415. {
  416. rt_kprintf(" 0x%lx", (rt_ubase_t)buffer[i]);
  417. }
  418. rt_kprintf("\n");
  419. return RT_EOK;
  420. }
  421. /**
  422. * @brief Print backtrace from frame to the given buffer
  423. *
  424. * @param thread the thread which frame belongs to
  425. * @param frame where backtrace starts from. NULL if it's the current one
  426. * @param skip the number of frames to discarded counted from calling function.
  427. * Noted that the inner most frame is always discarded and not counted,
  428. * which is obviously reasonable since that's this function itself.
  429. * @param buffer where traced frames saved
  430. * @param buflen max number of items can be saved in buffer. If there are no more
  431. * than buflen items to be saved, there will be a NULL after the
  432. * last saved item in the buffer.
  433. * @return rt_err_t 0 is success, otherwise a failure
  434. */
  435. rt_weak rt_err_t rt_backtrace_to_buffer(rt_thread_t thread,
  436. struct rt_hw_backtrace_frame *frame,
  437. long skip,
  438. rt_ubase_t *buffer,
  439. long buflen)
  440. {
  441. long nesting = 0;
  442. struct rt_hw_backtrace_frame cur_frame;
  443. if (!thread)
  444. return -RT_EINVAL;
  445. RT_ASSERT(rt_object_get_type(&thread->parent) == RT_Object_Class_Thread);
  446. if (!frame)
  447. {
  448. frame = &cur_frame;
  449. RT_HW_BACKTRACE_FRAME_GET_SELF(frame);
  450. if (!frame->fp)
  451. return -RT_EINVAL;
  452. }
  453. /* discard frames as required. The inner most is always threw. */
  454. do {
  455. rt_hw_backtrace_frame_unwind(thread, frame);
  456. } while (skip-- > 0);
  457. while (nesting < buflen)
  458. {
  459. *buffer++ = (rt_ubase_t)frame->pc;
  460. if (rt_hw_backtrace_frame_unwind(thread, frame))
  461. {
  462. break;
  463. }
  464. nesting++;
  465. }
  466. if (nesting < buflen)
  467. *buffer = RT_NULL;
  468. return RT_EOK;
  469. }
  470. /**
  471. * @brief Print backtrace of a thread to system console device
  472. *
  473. * @param thread which call stack is traced
  474. * @return rt_err_t 0 is success, otherwise a failure
  475. */
  476. rt_err_t rt_backtrace_thread(rt_thread_t thread)
  477. {
  478. rt_err_t rc;
  479. struct rt_hw_backtrace_frame frame;
  480. if (thread)
  481. {
  482. rc = rt_hw_backtrace_frame_get(thread, &frame);
  483. if (rc == RT_EOK)
  484. {
  485. rc = rt_backtrace_frame(thread, &frame);
  486. }
  487. }
  488. else
  489. {
  490. rc = -RT_EINVAL;
  491. }
  492. return rc;
  493. }
  494. #ifdef RT_USING_CPU_USAGE_TRACER
  495. /**
  496. * @brief Get thread usage percentage relative to total system CPU time
  497. *
  498. * This function calculates the CPU usage percentage of a specific thread
  499. * relative to the total CPU time consumed by all threads in the system.
  500. *
  501. * @param thread Pointer to the thread object. Must not be NULL.
  502. *
  503. * @return The CPU usage percentage as an integer value (0-100).
  504. * Returns 0 if total system time is 0 or if CPU usage tracing is not enabled.
  505. *
  506. * @note This function requires RT_USING_CPU_USAGE_TRACER to be enabled.
  507. * @note The percentage is calculated as: (thread_time * 100) / total_system_time
  508. * @note Due to integer arithmetic, the result is truncated and may not sum
  509. * to exactly 100% across all threads due to rounding.
  510. * @note If thread is NULL, an assertion will be triggered in debug builds.
  511. */
  512. rt_uint8_t rt_thread_get_usage(rt_thread_t thread)
  513. {
  514. rt_ubase_t thread_time;
  515. rt_ubase_t total_time = 0U;
  516. int i;
  517. rt_cpu_t pcpu;
  518. RT_ASSERT(thread != RT_NULL);
  519. thread_time = thread->user_time + thread->system_time;
  520. /* Calculate total system time by summing all CPUs' time */
  521. for (i = 0; i < RT_CPUS_NR; i++)
  522. {
  523. pcpu = rt_cpu_index(i);
  524. total_time += pcpu->cpu_stat.user + pcpu->cpu_stat.system + pcpu->cpu_stat.idle;
  525. }
  526. if (total_time > 0U)
  527. {
  528. /* Calculate thread usage percentage: (thread_time * 100) / total_time */
  529. rt_ubase_t usage = (thread_time * 100U) / total_time;
  530. return (rt_uint8_t)(usage > 100U ? 100U : usage);
  531. }
  532. return 0U;
  533. }
  534. #endif /* RT_USING_CPU_USAGE_TRACER */
  535. #if defined(RT_USING_LIBC) && defined(RT_USING_FINSH)
  536. #include <stdlib.h> /* for string service */
  537. static void cmd_backtrace(int argc, char** argv)
  538. {
  539. rt_uintptr_t pid;
  540. char *end_ptr;
  541. if (argc != 2)
  542. {
  543. if (argc == 1)
  544. {
  545. rt_kprintf("[INFO] No thread specified\n"
  546. "[HELP] You can use commands like: backtrace %p\n"
  547. "Printing backtrace of calling stack...\n",
  548. rt_thread_self());
  549. rt_backtrace();
  550. return ;
  551. }
  552. else
  553. {
  554. rt_kprintf("please use: backtrace [thread_address]\n");
  555. return;
  556. }
  557. }
  558. pid = strtoul(argv[1], &end_ptr, 0);
  559. if (end_ptr == argv[1])
  560. {
  561. rt_kprintf("Invalid input: %s\n", argv[1]);
  562. return ;
  563. }
  564. if (pid && rt_object_get_type((void *)pid) == RT_Object_Class_Thread)
  565. {
  566. rt_thread_t target = (rt_thread_t)pid;
  567. rt_kprintf("backtrace %s(0x%lx), from %s\n", target->parent.name, pid, argv[1]);
  568. rt_backtrace_thread(target);
  569. }
  570. else
  571. rt_kprintf("Invalid pid: %ld\n", pid);
  572. }
  573. MSH_CMD_EXPORT_ALIAS(cmd_backtrace, backtrace, print backtrace of a thread);
  574. #endif /* RT_USING_LIBC */
  575. #if defined(RT_USING_HEAP) && !defined(RT_USING_USERHEAP)
  576. #ifdef RT_USING_HOOK
  577. static void (*rt_malloc_hook)(void **ptr, rt_size_t size);
  578. static void (*rt_realloc_entry_hook)(void **ptr, rt_size_t size);
  579. static void (*rt_realloc_exit_hook)(void **ptr, rt_size_t size);
  580. static void (*rt_free_hook)(void **ptr);
  581. /**
  582. * @ingroup group_hook
  583. * @{
  584. */
  585. /**
  586. * @brief This function will set a hook function, which will be invoked when a memory
  587. * block is allocated from heap memory.
  588. *
  589. * @param hook the hook function.
  590. */
  591. void rt_malloc_sethook(void (*hook)(void **ptr, rt_size_t size))
  592. {
  593. rt_malloc_hook = hook;
  594. }
  595. /**
  596. * @brief This function will set a hook function, which will be invoked when a memory
  597. * block is allocated from heap memory.
  598. *
  599. * @param hook the hook function.
  600. */
  601. void rt_realloc_set_entry_hook(void (*hook)(void **ptr, rt_size_t size))
  602. {
  603. rt_realloc_entry_hook = hook;
  604. }
  605. /**
  606. * @brief This function will set a hook function, which will be invoked when a memory
  607. * block is allocated from heap memory.
  608. *
  609. * @param hook the hook function.
  610. */
  611. void rt_realloc_set_exit_hook(void (*hook)(void **ptr, rt_size_t size))
  612. {
  613. rt_realloc_exit_hook = hook;
  614. }
  615. /**
  616. * @brief This function will set a hook function, which will be invoked when a memory
  617. * block is released to heap memory.
  618. *
  619. * @param hook the hook function
  620. */
  621. void rt_free_sethook(void (*hook)(void **ptr))
  622. {
  623. rt_free_hook = hook;
  624. }
  625. /**@}*/
  626. #endif /* RT_USING_HOOK */
  627. #if defined(RT_USING_HEAP_ISR)
  628. static struct rt_spinlock _heap_spinlock;
  629. #elif defined(RT_USING_MUTEX)
  630. static struct rt_mutex _lock;
  631. #endif
  632. rt_inline void _heap_lock_init(void)
  633. {
  634. #if defined(RT_USING_HEAP_ISR)
  635. rt_spin_lock_init(&_heap_spinlock);
  636. #elif defined(RT_USING_MUTEX)
  637. rt_mutex_init(&_lock, "heap", RT_IPC_FLAG_PRIO);
  638. #endif
  639. }
  640. rt_inline rt_base_t _heap_lock(void)
  641. {
  642. #if defined(RT_USING_HEAP_ISR)
  643. return rt_spin_lock_irqsave(&_heap_spinlock);
  644. #elif defined(RT_USING_MUTEX)
  645. if (rt_thread_self())
  646. return rt_mutex_take(&_lock, RT_WAITING_FOREVER);
  647. else
  648. return RT_EOK;
  649. #else
  650. rt_enter_critical();
  651. return RT_EOK;
  652. #endif
  653. }
  654. rt_inline void _heap_unlock(rt_base_t level)
  655. {
  656. #if defined(RT_USING_HEAP_ISR)
  657. rt_spin_unlock_irqrestore(&_heap_spinlock, level);
  658. #elif defined(RT_USING_MUTEX)
  659. RT_ASSERT(level == RT_EOK);
  660. if (rt_thread_self())
  661. rt_mutex_release(&_lock);
  662. #else
  663. rt_exit_critical();
  664. #endif
  665. }
  666. #ifdef RT_USING_UTESTCASES
  667. /* export to utest to observe the inner statements */
  668. #ifdef _MSC_VER
  669. #define rt_heap_lock() _heap_lock()
  670. #define rt_heap_unlock() _heap_unlock()
  671. #else
  672. rt_base_t rt_heap_lock(void) __attribute__((alias("_heap_lock")));
  673. void rt_heap_unlock(rt_base_t level) __attribute__((alias("_heap_unlock")));
  674. #endif /* _MSC_VER */
  675. #endif
  676. #if defined(RT_USING_SMALL_MEM_AS_HEAP)
  677. static rt_smem_t system_heap;
  678. rt_inline void _smem_info(rt_size_t *total,
  679. rt_size_t *used, rt_size_t *max_used)
  680. {
  681. if (total)
  682. *total = system_heap->total;
  683. if (used)
  684. *used = system_heap->used;
  685. if (max_used)
  686. *max_used = system_heap->max;
  687. }
  688. #define _MEM_INIT(_name, _start, _size) \
  689. system_heap = rt_smem_init(_name, _start, _size)
  690. #define _MEM_MALLOC(_size) \
  691. rt_smem_alloc(system_heap, _size)
  692. #define _MEM_REALLOC(_ptr, _newsize)\
  693. rt_smem_realloc(system_heap, _ptr, _newsize)
  694. #define _MEM_FREE(_ptr) \
  695. rt_smem_free(_ptr)
  696. #define _MEM_INFO(_total, _used, _max) \
  697. _smem_info(_total, _used, _max)
  698. #elif defined(RT_USING_MEMHEAP_AS_HEAP)
  699. static struct rt_memheap system_heap;
  700. void *_memheap_alloc(struct rt_memheap *heap, rt_size_t size);
  701. void _memheap_free(void *rmem);
  702. void *_memheap_realloc(struct rt_memheap *heap, void *rmem, rt_size_t newsize);
  703. #define _MEM_INIT(_name, _start, _size) \
  704. do {\
  705. rt_memheap_init(&system_heap, _name, _start, _size); \
  706. system_heap.locked = RT_TRUE; \
  707. } while(0)
  708. #define _MEM_MALLOC(_size) \
  709. _memheap_alloc(&system_heap, _size)
  710. #define _MEM_REALLOC(_ptr, _newsize) \
  711. _memheap_realloc(&system_heap, _ptr, _newsize)
  712. #define _MEM_FREE(_ptr) \
  713. _memheap_free(_ptr)
  714. #define _MEM_INFO(_total, _used, _max) \
  715. rt_memheap_info(&system_heap, _total, _used, _max)
  716. #elif defined(RT_USING_SLAB_AS_HEAP)
  717. static rt_slab_t system_heap;
  718. rt_inline void _slab_info(rt_size_t *total,
  719. rt_size_t *used, rt_size_t *max_used)
  720. {
  721. if (total)
  722. *total = system_heap->total;
  723. if (used)
  724. *used = system_heap->used;
  725. if (max_used)
  726. *max_used = system_heap->max;
  727. }
  728. #define _MEM_INIT(_name, _start, _size) \
  729. system_heap = rt_slab_init(_name, _start, _size)
  730. #define _MEM_MALLOC(_size) \
  731. rt_slab_alloc(system_heap, _size)
  732. #define _MEM_REALLOC(_ptr, _newsize) \
  733. rt_slab_realloc(system_heap, _ptr, _newsize)
  734. #define _MEM_FREE(_ptr) \
  735. rt_slab_free(system_heap, _ptr)
  736. #define _MEM_INFO _slab_info
  737. #else
  738. #define _MEM_INIT(...)
  739. #define _MEM_MALLOC(...) RT_NULL
  740. #define _MEM_REALLOC(...) RT_NULL
  741. #define _MEM_FREE(...)
  742. #define _MEM_INFO(...)
  743. #endif
  744. /**
  745. * @brief This function will do the generic system heap initialization.
  746. *
  747. * @param begin_addr the beginning address of system page.
  748. *
  749. * @param end_addr the end address of system page.
  750. */
  751. void rt_system_heap_init_generic(void *begin_addr, void *end_addr)
  752. {
  753. rt_uintptr_t begin_align = RT_ALIGN((rt_uintptr_t)begin_addr, RT_ALIGN_SIZE);
  754. rt_uintptr_t end_align = RT_ALIGN_DOWN((rt_uintptr_t)end_addr, RT_ALIGN_SIZE);
  755. RT_ASSERT(end_align > begin_align);
  756. /* Initialize system memory heap */
  757. _MEM_INIT("heap", (void *)begin_align, end_align - begin_align);
  758. /* Initialize multi thread contention lock */
  759. _heap_lock_init();
  760. }
  761. /**
  762. * @brief This function will init system heap. User can override this API to
  763. * complete other works, like heap sanitizer initialization.
  764. *
  765. * @param begin_addr the beginning address of system page.
  766. *
  767. * @param end_addr the end address of system page.
  768. */
  769. rt_weak void rt_system_heap_init(void *begin_addr, void *end_addr)
  770. {
  771. rt_system_heap_init_generic(begin_addr, end_addr);
  772. }
  773. /**
  774. * @brief Allocate a block of memory with a minimum of 'size' bytes.
  775. *
  776. * @param size is the minimum size of the requested block in bytes.
  777. *
  778. * @return the pointer to allocated memory or NULL if no free memory was found.
  779. */
  780. rt_weak void *rt_malloc(rt_size_t size)
  781. {
  782. rt_base_t level;
  783. void *ptr;
  784. /* Enter critical zone */
  785. level = _heap_lock();
  786. /* allocate memory block from system heap */
  787. ptr = _MEM_MALLOC(size);
  788. /* Exit critical zone */
  789. _heap_unlock(level);
  790. /* call 'rt_malloc' hook */
  791. RT_OBJECT_HOOK_CALL(rt_malloc_hook, (&ptr, size));
  792. return ptr;
  793. }
  794. RTM_EXPORT(rt_malloc);
  795. /**
  796. * @brief This function will change the size of previously allocated memory block.
  797. *
  798. * @param ptr is the pointer to memory allocated by rt_malloc.
  799. *
  800. * @param newsize is the required new size.
  801. *
  802. * @return the changed memory block address.
  803. */
  804. rt_weak void *rt_realloc(void *ptr, rt_size_t newsize)
  805. {
  806. rt_base_t level;
  807. void *nptr;
  808. /* Entry hook */
  809. RT_OBJECT_HOOK_CALL(rt_realloc_entry_hook, (&ptr, newsize));
  810. /* Enter critical zone */
  811. level = _heap_lock();
  812. /* Change the size of previously allocated memory block */
  813. nptr = _MEM_REALLOC(ptr, newsize);
  814. /* Exit critical zone */
  815. _heap_unlock(level);
  816. /* Exit hook */
  817. RT_OBJECT_HOOK_CALL(rt_realloc_exit_hook, (&nptr, newsize));
  818. return nptr;
  819. }
  820. RTM_EXPORT(rt_realloc);
  821. /**
  822. * @brief This function will contiguously allocate enough space for count objects
  823. * that are size bytes of memory each and returns a pointer to the allocated
  824. * memory.
  825. *
  826. * @note The allocated memory is filled with bytes of value zero.
  827. *
  828. * @param count is the number of objects to allocate.
  829. *
  830. * @param size is the size of one object to allocate.
  831. *
  832. * @return pointer to allocated memory / NULL pointer if there is an error.
  833. */
  834. rt_weak void *rt_calloc(rt_size_t count, rt_size_t size)
  835. {
  836. void *p;
  837. /* allocate 'count' objects of size 'size' */
  838. p = rt_malloc(count * size);
  839. /* zero the memory */
  840. if (p)
  841. {
  842. rt_memset(p, 0, count * size);
  843. }
  844. return p;
  845. }
  846. RTM_EXPORT(rt_calloc);
  847. /**
  848. * @brief This function will release the previously allocated memory block by
  849. * rt_malloc. The released memory block is taken back to system heap.
  850. *
  851. * @param ptr the address of memory which will be released.
  852. */
  853. rt_weak void rt_free(void *ptr)
  854. {
  855. rt_base_t level;
  856. /* call 'rt_free' hook */
  857. RT_OBJECT_HOOK_CALL(rt_free_hook, (&ptr));
  858. /* NULL check */
  859. if (ptr == RT_NULL) return;
  860. /* Enter critical zone */
  861. level = _heap_lock();
  862. _MEM_FREE(ptr);
  863. /* Exit critical zone */
  864. _heap_unlock(level);
  865. }
  866. RTM_EXPORT(rt_free);
  867. /**
  868. * @brief This function will caculate the total memory, the used memory, and
  869. * the max used memory.
  870. *
  871. * @param total is a pointer to get the total size of the memory.
  872. *
  873. * @param used is a pointer to get the size of memory used.
  874. *
  875. * @param max_used is a pointer to get the maximum memory used.
  876. */
  877. rt_weak void rt_memory_info(rt_size_t *total,
  878. rt_size_t *used,
  879. rt_size_t *max_used)
  880. {
  881. rt_base_t level;
  882. /* Enter critical zone */
  883. level = _heap_lock();
  884. _MEM_INFO(total, used, max_used);
  885. /* Exit critical zone */
  886. _heap_unlock(level);
  887. }
  888. RTM_EXPORT(rt_memory_info);
  889. #if defined(RT_USING_SLAB) && defined(RT_USING_SLAB_AS_HEAP)
  890. void *rt_page_alloc(rt_size_t npages)
  891. {
  892. rt_base_t level;
  893. void *ptr;
  894. /* Enter critical zone */
  895. level = _heap_lock();
  896. /* alloc page */
  897. ptr = rt_slab_page_alloc(system_heap, npages);
  898. /* Exit critical zone */
  899. _heap_unlock(level);
  900. return ptr;
  901. }
  902. void rt_page_free(void *addr, rt_size_t npages)
  903. {
  904. rt_base_t level;
  905. /* Enter critical zone */
  906. level = _heap_lock();
  907. /* free page */
  908. rt_slab_page_free(system_heap, addr, npages);
  909. /* Exit critical zone */
  910. _heap_unlock(level);
  911. }
  912. #endif
  913. /**
  914. * @brief This function allocates a memory block, which address is aligned to the
  915. * specified alignment size.
  916. *
  917. * @param size is the allocated memory block size.
  918. *
  919. * @param align is the alignment size.
  920. *
  921. * @return The memory block address was returned successfully, otherwise it was
  922. * returned empty RT_NULL.
  923. */
  924. rt_weak void *rt_malloc_align(rt_size_t size, rt_size_t align)
  925. {
  926. void *ptr = RT_NULL;
  927. void *align_ptr = RT_NULL;
  928. int uintptr_size = 0;
  929. rt_size_t align_size = 0;
  930. /* sizeof pointer */
  931. uintptr_size = sizeof(void*);
  932. uintptr_size -= 1;
  933. /* align the alignment size to uintptr size byte */
  934. align = ((align + uintptr_size) & ~uintptr_size);
  935. /* get total aligned size */
  936. align_size = ((size + uintptr_size) & ~uintptr_size) + align;
  937. /* allocate memory block from heap */
  938. ptr = rt_malloc(align_size);
  939. if (ptr != RT_NULL)
  940. {
  941. /* the allocated memory block is aligned */
  942. if (((rt_uintptr_t)ptr & (align - 1)) == 0)
  943. {
  944. align_ptr = (void *)((rt_uintptr_t)ptr + align);
  945. }
  946. else
  947. {
  948. align_ptr = (void *)(((rt_uintptr_t)ptr + (align - 1)) & ~(align - 1));
  949. }
  950. /* set the pointer before alignment pointer to the real pointer */
  951. *((rt_uintptr_t *)((rt_uintptr_t)align_ptr - sizeof(void *))) = (rt_uintptr_t)ptr;
  952. ptr = align_ptr;
  953. }
  954. return ptr;
  955. }
  956. RTM_EXPORT(rt_malloc_align);
  957. /**
  958. * @brief This function release the memory block, which is allocated by
  959. * rt_malloc_align function and address is aligned.
  960. *
  961. * @param ptr is the memory block pointer.
  962. */
  963. rt_weak void rt_free_align(void *ptr)
  964. {
  965. void *real_ptr = RT_NULL;
  966. /* NULL check */
  967. if (ptr == RT_NULL) return;
  968. real_ptr = (void *) * (rt_uintptr_t *)((rt_uintptr_t)ptr - sizeof(void *));
  969. rt_free(real_ptr);
  970. }
  971. RTM_EXPORT(rt_free_align);
  972. #endif /* RT_USING_HEAP */
  973. #ifndef RT_USING_CPU_FFS
  974. #ifdef RT_USING_TINY_FFS
  975. const rt_uint8_t __lowest_bit_bitmap[] =
  976. {
  977. /* 0 - 7 */ 0, 1, 2, 27, 3, 24, 28, 32,
  978. /* 8 - 15 */ 4, 17, 25, 31, 29, 12, 32, 14,
  979. /* 16 - 23 */ 5, 8, 18, 32, 26, 23, 32, 16,
  980. /* 24 - 31 */ 30, 11, 13, 7, 32, 22, 15, 10,
  981. /* 32 - 36 */ 6, 21, 9, 20, 19
  982. };
  983. /**
  984. * @brief This function finds the first bit set (beginning with the least significant bit)
  985. * in value and return the index of that bit.
  986. *
  987. * Bits are numbered starting at 1 (the least significant bit). A return value of
  988. * zero from any of these functions means that the argument was zero.
  989. *
  990. * @param value is the value to find the first bit set in.
  991. *
  992. * @return return the index of the first bit set. If value is 0, then this function
  993. * shall return 0.
  994. */
  995. int __rt_ffs(int value)
  996. {
  997. return __lowest_bit_bitmap[(rt_uint32_t)(value & (value - 1) ^ value) % 37];
  998. }
  999. #else
  1000. const rt_uint8_t __lowest_bit_bitmap[] =
  1001. {
  1002. /* 00 */ 0, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0,
  1003. /* 10 */ 4, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0,
  1004. /* 20 */ 5, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0,
  1005. /* 30 */ 4, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0,
  1006. /* 40 */ 6, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0,
  1007. /* 50 */ 4, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0,
  1008. /* 60 */ 5, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0,
  1009. /* 70 */ 4, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0,
  1010. /* 80 */ 7, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0,
  1011. /* 90 */ 4, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0,
  1012. /* A0 */ 5, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0,
  1013. /* B0 */ 4, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0,
  1014. /* C0 */ 6, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0,
  1015. /* D0 */ 4, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0,
  1016. /* E0 */ 5, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0,
  1017. /* F0 */ 4, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0
  1018. };
  1019. /**
  1020. * @brief This function finds the first bit set (beginning with the least significant bit)
  1021. * in value and return the index of that bit.
  1022. *
  1023. * Bits are numbered starting at 1 (the least significant bit). A return value of
  1024. * zero from any of these functions means that the argument was zero.
  1025. *
  1026. * @param value is the value to find the first bit set in.
  1027. *
  1028. * @return Return the index of the first bit set. If value is 0, then this function
  1029. * shall return 0.
  1030. */
  1031. int __rt_ffs(int value)
  1032. {
  1033. if (value == 0)
  1034. {
  1035. return 0;
  1036. }
  1037. if (value & 0xff)
  1038. {
  1039. return __lowest_bit_bitmap[value & 0xff] + 1;
  1040. }
  1041. if (value & 0xff00)
  1042. {
  1043. return __lowest_bit_bitmap[(value & 0xff00) >> 8] + 9;
  1044. }
  1045. if (value & 0xff0000)
  1046. {
  1047. return __lowest_bit_bitmap[(value & 0xff0000) >> 16] + 17;
  1048. }
  1049. return __lowest_bit_bitmap[(value & 0xff000000) >> 24] + 25;
  1050. }
  1051. #endif /* RT_USING_TINY_FFS */
  1052. #endif /* RT_USING_CPU_FFS */
  1053. #ifdef RT_DEBUGING_ASSERT
  1054. /* RT_ASSERT(EX)'s hook */
  1055. void (*rt_assert_hook)(const char *ex, const char *func, rt_size_t line);
  1056. /**
  1057. * This function will set a hook function to RT_ASSERT(EX). It will run when the expression is false.
  1058. *
  1059. * @param hook is the hook function.
  1060. */
  1061. void rt_assert_set_hook(void (*hook)(const char *ex, const char *func, rt_size_t line))
  1062. {
  1063. rt_assert_hook = hook;
  1064. }
  1065. /**
  1066. * The RT_ASSERT function.
  1067. *
  1068. * @param ex_string is the assertion condition string.
  1069. *
  1070. * @param func is the function name when assertion.
  1071. *
  1072. * @param line is the file line number when assertion.
  1073. */
  1074. void rt_assert_handler(const char *ex_string, const char *func, rt_size_t line)
  1075. {
  1076. volatile char dummy = 0;
  1077. if (rt_assert_hook == RT_NULL)
  1078. {
  1079. #ifdef RT_USING_MODULE
  1080. if (dlmodule_self())
  1081. {
  1082. /* close assertion module */
  1083. dlmodule_exit(-1);
  1084. }
  1085. else
  1086. #endif /*RT_USING_MODULE*/
  1087. {
  1088. rt_kprintf("(%s) assertion failed at function:%s, line number:%d \n", ex_string, func, line);
  1089. rt_backtrace();
  1090. while (dummy == 0);
  1091. }
  1092. }
  1093. else
  1094. {
  1095. rt_assert_hook(ex_string, func, line);
  1096. }
  1097. }
  1098. RTM_EXPORT(rt_assert_handler);
  1099. #endif /* RT_DEBUGING_ASSERT */
  1100. /**@}*/