summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBernard Xiong <[email protected]>2015-08-03 16:07:30 +0800
committerBernard Xiong <[email protected]>2015-08-03 16:07:30 +0800
commit266496cef3a109660dc575a38a127d5508d59208 (patch)
tree40bdcce55d498ac1ae6d918d9fdd4d4f2b7b9aa9 /src
parentabd19b8dd7fac0235c28c5c5e84bc5779d4d0991 (diff)
[Kernel] Use rt_assert_handler() function to handle assertion.
Diffstat (limited to 'src')
-rw-r--r--src/kservice.c37
1 files changed, 37 insertions, 0 deletions
diff --git a/src/kservice.c b/src/kservice.c
index e8076eb237..0e15610e51 100644
--- a/src/kservice.c
+++ b/src/kservice.c
@@ -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__)