From 2da019234ebec2cfadc3772e0e216b92da0990a9 Mon Sep 17 00:00:00 2001 From: Shicheng Chu <1468559561@qq.com> Date: Sat, 1 Jul 2023 20:41:02 +0800 Subject: [PATCH] [include][dbg]update: delete rtdebug.h (#7759) --- .../Libraries/ch56x_drivers/ch56x_gpio.c | 1 - .../Libraries/ch56x_drivers/ch56x_pfic.c | 1 - .../Libraries/ch56x_drivers/ch56x_pwm.c | 1 - .../Libraries/ch56x_drivers/ch56x_spi.c | 1 - .../Libraries/ch56x_drivers/ch56x_sys.c | 1 - .../Libraries/ch56x_drivers/ch56x_timer.c | 1 - .../Libraries/ch56x_drivers/ch56x_uart.c | 1 - .../Libraries/ch56x_drivers/ch56x_usbd.c | 1 - .../Libraries/ch56x_drivers/ch56x_wdt.c | 1 - bsp/wch/risc-v/ch569w-evt/applications/test.c | 1 - include/rtdebug.h | 112 ------------------ include/rtthread.h | 95 ++++++++++++++- 12 files changed, 93 insertions(+), 124 deletions(-) delete mode 100644 include/rtdebug.h diff --git a/bsp/wch/risc-v/Libraries/ch56x_drivers/ch56x_gpio.c b/bsp/wch/risc-v/Libraries/ch56x_drivers/ch56x_gpio.c index dd6142aa48..08a855f63f 100644 --- a/bsp/wch/risc-v/Libraries/ch56x_drivers/ch56x_gpio.c +++ b/bsp/wch/risc-v/Libraries/ch56x_drivers/ch56x_gpio.c @@ -8,7 +8,6 @@ * 2022-07-15 Emuzit first version */ #include -#include #include #include "ch56x_gpio.h" #include "isr_sp.h" diff --git a/bsp/wch/risc-v/Libraries/ch56x_drivers/ch56x_pfic.c b/bsp/wch/risc-v/Libraries/ch56x_drivers/ch56x_pfic.c index 1ecd1fa44b..b6d1f5fbb1 100644 --- a/bsp/wch/risc-v/Libraries/ch56x_drivers/ch56x_pfic.c +++ b/bsp/wch/risc-v/Libraries/ch56x_drivers/ch56x_pfic.c @@ -8,7 +8,6 @@ * 2022-07-15 Emuzit first version */ #include -#include #include "ch56x_pfic.h" #include "ch56x_sys.h" #include "isr_sp.h" diff --git a/bsp/wch/risc-v/Libraries/ch56x_drivers/ch56x_pwm.c b/bsp/wch/risc-v/Libraries/ch56x_drivers/ch56x_pwm.c index 854fd0d336..d1ce6aad83 100644 --- a/bsp/wch/risc-v/Libraries/ch56x_drivers/ch56x_pwm.c +++ b/bsp/wch/risc-v/Libraries/ch56x_drivers/ch56x_pwm.c @@ -8,7 +8,6 @@ * 2022-08-04 Emuzit first version */ #include -#include #include #include #include "ch56x_pwm.h" diff --git a/bsp/wch/risc-v/Libraries/ch56x_drivers/ch56x_spi.c b/bsp/wch/risc-v/Libraries/ch56x_drivers/ch56x_spi.c index 9fb8a30d3d..68b10f0eae 100644 --- a/bsp/wch/risc-v/Libraries/ch56x_drivers/ch56x_spi.c +++ b/bsp/wch/risc-v/Libraries/ch56x_drivers/ch56x_spi.c @@ -8,7 +8,6 @@ * 2022-07-30 Emuzit first version */ #include -#include #include #include #include "ch56x_spi.h" diff --git a/bsp/wch/risc-v/Libraries/ch56x_drivers/ch56x_sys.c b/bsp/wch/risc-v/Libraries/ch56x_drivers/ch56x_sys.c index eefb2ad643..989959c6e5 100644 --- a/bsp/wch/risc-v/Libraries/ch56x_drivers/ch56x_sys.c +++ b/bsp/wch/risc-v/Libraries/ch56x_drivers/ch56x_sys.c @@ -8,7 +8,6 @@ * 2022-07-15 Emuzit first version */ #include -#include #include "ch56x_sys.h" static uint32_t hclk_freq; diff --git a/bsp/wch/risc-v/Libraries/ch56x_drivers/ch56x_timer.c b/bsp/wch/risc-v/Libraries/ch56x_drivers/ch56x_timer.c index b466a10ed0..2c8411d6fd 100644 --- a/bsp/wch/risc-v/Libraries/ch56x_drivers/ch56x_timer.c +++ b/bsp/wch/risc-v/Libraries/ch56x_drivers/ch56x_timer.c @@ -8,7 +8,6 @@ * 2022-07-15 Emuzit first version */ #include -#include #include #include "ch56x_sys.h" #include "ch56x_timer.h" diff --git a/bsp/wch/risc-v/Libraries/ch56x_drivers/ch56x_uart.c b/bsp/wch/risc-v/Libraries/ch56x_drivers/ch56x_uart.c index 496c72f534..ae0c79d29f 100644 --- a/bsp/wch/risc-v/Libraries/ch56x_drivers/ch56x_uart.c +++ b/bsp/wch/risc-v/Libraries/ch56x_drivers/ch56x_uart.c @@ -8,7 +8,6 @@ * 2022-07-15 Emuzit first version */ #include -#include #include #include #ifdef RT_USING_SERIAL_V2 diff --git a/bsp/wch/risc-v/Libraries/ch56x_drivers/ch56x_usbd.c b/bsp/wch/risc-v/Libraries/ch56x_drivers/ch56x_usbd.c index ecd7f3fb68..ecbd0c0b0c 100644 --- a/bsp/wch/risc-v/Libraries/ch56x_drivers/ch56x_usbd.c +++ b/bsp/wch/risc-v/Libraries/ch56x_drivers/ch56x_usbd.c @@ -8,7 +8,6 @@ * 2022-08-22 Emuzit first version */ #include -#include #include #include #include "ch56x_usbhs.h" diff --git a/bsp/wch/risc-v/Libraries/ch56x_drivers/ch56x_wdt.c b/bsp/wch/risc-v/Libraries/ch56x_drivers/ch56x_wdt.c index 86e419b613..f04ab23fc9 100644 --- a/bsp/wch/risc-v/Libraries/ch56x_drivers/ch56x_wdt.c +++ b/bsp/wch/risc-v/Libraries/ch56x_drivers/ch56x_wdt.c @@ -8,7 +8,6 @@ * 2022-07-20 Emuzit first version */ #include -#include #include #include "ch56x_sys.h" diff --git a/bsp/wch/risc-v/ch569w-evt/applications/test.c b/bsp/wch/risc-v/ch569w-evt/applications/test.c index d77f121724..a1396af879 100644 --- a/bsp/wch/risc-v/ch569w-evt/applications/test.c +++ b/bsp/wch/risc-v/ch569w-evt/applications/test.c @@ -12,7 +12,6 @@ * 2022-08-04 Emuzit add pwm test */ #include -#include #include #include #include diff --git a/include/rtdebug.h b/include/rtdebug.h deleted file mode 100644 index 0246ad0fa5..0000000000 --- a/include/rtdebug.h +++ /dev/null @@ -1,112 +0,0 @@ -/* - * Copyright (c) 2006-2021, RT-Thread Development Team - * - * SPDX-License-Identifier: Apache-2.0 - * - * Change Logs: - * Date Author Notes - */ - -#ifndef __RTDEBUG_H__ -#define __RTDEBUG_H__ - -#include - -/* Using this macro to control all kernel debug features. */ -#ifdef RT_DEBUG - -/* Turn on this to enable context check */ -#ifndef RT_DEBUG_CONTEXT_CHECK -#define RT_DEBUG_CONTEXT_CHECK 1 -#endif - -#define RT_ASSERT(EX) \ -if (!(EX)) \ -{ \ - rt_assert_handler(#EX, __FUNCTION__, __LINE__); \ -} - -/* Macro to check current context */ -#if RT_DEBUG_CONTEXT_CHECK -#define RT_DEBUG_NOT_IN_INTERRUPT \ -do \ -{ \ - rt_base_t level; \ - level = rt_hw_interrupt_disable(); \ - if (rt_interrupt_get_nest() != 0) \ - { \ - rt_kprintf("Function[%s] shall not be used in ISR\n", __FUNCTION__); \ - RT_ASSERT(0) \ - } \ - rt_hw_interrupt_enable(level); \ -} \ -while (0) - -/* "In thread context" means: - * 1) the scheduler has been started - * 2) not in interrupt context. - */ -#define RT_DEBUG_IN_THREAD_CONTEXT \ -do \ -{ \ - rt_base_t level; \ - level = rt_hw_interrupt_disable(); \ - if (rt_thread_self() == RT_NULL) \ - { \ - rt_kprintf("Function[%s] shall not be used before scheduler start\n", \ - __FUNCTION__); \ - RT_ASSERT(0) \ - } \ - RT_DEBUG_NOT_IN_INTERRUPT; \ - rt_hw_interrupt_enable(level); \ -} \ -while (0) - -/* "scheduler available" means: - * 1) the scheduler has been started. - * 2) not in interrupt context. - * 3) scheduler is not locked. - * 4) interrupt is not disabled. - */ -#define RT_DEBUG_SCHEDULER_AVAILABLE(need_check) \ -do \ -{ \ - if (need_check) \ - { \ - rt_bool_t interrupt_disabled; \ - rt_base_t level; \ - interrupt_disabled = rt_hw_interrupt_is_disabled(); \ - level = rt_hw_interrupt_disable(); \ - if (rt_critical_level() != 0) \ - { \ - rt_kprintf("Function[%s]: scheduler is not available\n", \ - __FUNCTION__); \ - RT_ASSERT(0) \ - } \ - if (interrupt_disabled == RT_TRUE) \ - { \ - rt_kprintf("Function[%s]: interrupt is disabled\n", \ - __FUNCTION__); \ - RT_ASSERT(0) \ - } \ - RT_DEBUG_IN_THREAD_CONTEXT; \ - rt_hw_interrupt_enable(level); \ - } \ -} \ -while (0) -#else -#define RT_DEBUG_NOT_IN_INTERRUPT -#define RT_DEBUG_IN_THREAD_CONTEXT -#define RT_DEBUG_SCHEDULER_AVAILABLE(need_check) -#endif - -#else /* RT_DEBUG */ - -#define RT_ASSERT(EX) -#define RT_DEBUG_NOT_IN_INTERRUPT -#define RT_DEBUG_IN_THREAD_CONTEXT -#define RT_DEBUG_SCHEDULER_AVAILABLE(need_check) - -#endif /* RT_DEBUG */ - -#endif /* __RTDEBUG_H__ */ diff --git a/include/rtthread.h b/include/rtthread.h index ea3ee6f81a..fdb67a4d06 100644 --- a/include/rtthread.h +++ b/include/rtthread.h @@ -18,13 +18,13 @@ * 2021-11-14 Meco Man add rtlegacy.h for compatibility * 2022-06-04 Meco Man remove strnlen * 2023-05-20 Bernard add rtatomic.h header file to included files. + * 2023-06-30 ChuShicheng Move RT_DEBUG_CONTEXT_CHECK from the rtdebug.h */ #ifndef __RT_THREAD_H__ #define __RT_THREAD_H__ #include -#include #include #include #include @@ -728,8 +728,99 @@ 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); + +/* Turn on this to enable context check */ +#ifndef RT_DEBUG_CONTEXT_CHECK +#define RT_DEBUG_CONTEXT_CHECK 1 +#endif + +#define RT_ASSERT(EX) \ +if (!(EX)) \ +{ \ + rt_assert_handler(#EX, __FUNCTION__, __LINE__); \ +} + +/* Macro to check current context */ +#if RT_DEBUG_CONTEXT_CHECK +#define RT_DEBUG_NOT_IN_INTERRUPT \ +do \ +{ \ + rt_base_t level; \ + level = rt_hw_interrupt_disable(); \ + if (rt_interrupt_get_nest() != 0) \ + { \ + rt_kprintf("Function[%s] shall not be used in ISR\n", __FUNCTION__); \ + RT_ASSERT(0) \ + } \ + rt_hw_interrupt_enable(level); \ +} \ +while (0) + +/* "In thread context" means: + * 1) the scheduler has been started + * 2) not in interrupt context. + */ +#define RT_DEBUG_IN_THREAD_CONTEXT \ +do \ +{ \ + rt_base_t level; \ + level = rt_hw_interrupt_disable(); \ + if (rt_thread_self() == RT_NULL) \ + { \ + rt_kprintf("Function[%s] shall not be used before scheduler start\n", \ + __FUNCTION__); \ + RT_ASSERT(0) \ + } \ + RT_DEBUG_NOT_IN_INTERRUPT; \ + rt_hw_interrupt_enable(level); \ +} \ +while (0) + +/* "scheduler available" means: + * 1) the scheduler has been started. + * 2) not in interrupt context. + * 3) scheduler is not locked. + * 4) interrupt is not disabled. + */ +#define RT_DEBUG_SCHEDULER_AVAILABLE(need_check) \ +do \ +{ \ + if (need_check) \ + { \ + rt_bool_t interrupt_disabled; \ + rt_base_t level; \ + interrupt_disabled = rt_hw_interrupt_is_disabled(); \ + level = rt_hw_interrupt_disable(); \ + if (rt_critical_level() != 0) \ + { \ + rt_kprintf("Function[%s]: scheduler is not available\n", \ + __FUNCTION__); \ + RT_ASSERT(0) \ + } \ + if (interrupt_disabled == RT_TRUE) \ + { \ + rt_kprintf("Function[%s]: interrupt is disabled\n", \ + __FUNCTION__); \ + RT_ASSERT(0) \ + } \ + RT_DEBUG_IN_THREAD_CONTEXT; \ + rt_hw_interrupt_enable(level); \ + } \ +} \ +while (0) +#else +#define RT_DEBUG_NOT_IN_INTERRUPT +#define RT_DEBUG_IN_THREAD_CONTEXT +#define RT_DEBUG_SCHEDULER_AVAILABLE(need_check) +#endif + +#else /* RT_DEBUG */ + +#define RT_ASSERT(EX) +#define RT_DEBUG_NOT_IN_INTERRUPT +#define RT_DEBUG_IN_THREAD_CONTEXT +#define RT_DEBUG_SCHEDULER_AVAILABLE(need_check) #endif /* RT_DEBUG */ #ifdef RT_USING_FINSH