提交 266496ce 编写于 作者: B Bernard Xiong

[Kernel] Use rt_assert_handler() function to handle assertion.

上级 abd19b8d
......@@ -83,14 +83,7 @@ while (0)
#define RT_ASSERT(EX) \
if (!(EX)) \
{ \
volatile char dummy = 0; \
if (rt_assert_hook == RT_NULL) \
{ \
rt_kprintf("(%s) assert failed at %s:%d \n", #EX, __FUNCTION__, __LINE__);\
while (dummy == 0); \
} else { \
rt_assert_hook(#EX, __FUNCTION__, __LINE__); \
} \
rt_assert_handler(#EX, __FUNCTION__, __LINE__); \
}
/* Macro to check current context */
......
......@@ -518,6 +518,8 @@ void rt_show_version(void);
#ifdef RT_DEBUG
extern void (*rt_assert_hook)(const char* ex, const char* func, rt_size_t line);
void rt_assert_set_hook(void (*hook)(const char* ex, const char* func, rt_size_t line));
void rt_assert_handler(const char* ex, const char* func, rt_size_t line);
#endif /* RT_DEBUG */
/*@}*/
......
......@@ -30,6 +30,7 @@
* 2012-12-22 Bernard fix rt_kprintf issue, which found by Grissiom.
* 2013-06-24 Bernard remove rt_kprintf if RT_USING_CONSOLE is not defined.
* 2013-09-24 aozima make sure the device is in STREAM mode when used by rt_kprintf.
* 2015-07-06 Bernard Add rt_assert_handler routine.
*/
#include <rtthread.h>
......@@ -1248,6 +1249,42 @@ void (*rt_assert_hook)(const char* ex, const char* func, rt_size_t line);
void rt_assert_set_hook(void (*hook)(const char* ex, const char* func, rt_size_t line)) {
rt_assert_hook = hook;
}
/**
* The RT_ASSERT function.
*
* @param ex the assertion condition string
* @param func the function name when assertion.
* @param line the file line number when assertion.
*/
void rt_assert_handler(const char* ex_string, const char* func, rt_size_t line)
{
volatile char dummy = 0;
if (rt_assert_hook == RT_NULL)
{
#ifdef RT_USING_MODULE
if (rt_module_self() != RT_NULL)
{
/* unload assertion module */
rt_module_unload(rt_module_self());
/* re-schedule */
rt_schedule();
}
else
#endif
{
rt_kprintf("(%s) assertion failed at function:%s, line number:%d \n", ex_string, func, line);
while (dummy == 0);
}
}
else
{
rt_assert_hook(ex_string, func, line);
}
}
RTM_EXPORT(rt_assert_handler);
#endif /* RT_DEBUG */
#if !defined (RT_USING_NEWLIB) && defined (RT_USING_MINILIBC) && defined (__GNUC__)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册