From b9933c2089f5f0cd93738ae9081c45fcf3df54b7 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Thu, 11 Aug 2011 17:51:37 +0000 Subject: Implemented system state checker debug option, remove the option CH_USE_NESTED_LOCKS. Documentation improvements and fixes. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@3221 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/kernel/include/chdebug.h | 101 +++++++++++++++++++++++++++++++++--------- os/kernel/include/chsys.h | 74 ++++++++++++++++--------------- os/kernel/include/chthreads.h | 6 --- 3 files changed, 119 insertions(+), 62 deletions(-) (limited to 'os/kernel/include') diff --git a/os/kernel/include/chdebug.h b/os/kernel/include/chdebug.h index b2edf176e..3bfadb750 100644 --- a/os/kernel/include/chdebug.h +++ b/os/kernel/include/chdebug.h @@ -29,15 +29,31 @@ #ifndef _CHDEBUG_H_ #define _CHDEBUG_H_ +#if CH_DBG_ENABLE_ASSERTS || CH_DBG_ENABLE_CHECKS || \ + CH_DBG_ENABLE_STACK_CHECK || CH_DBG_SYSTEM_STATE_CHECK +#define CH_DBG_ENABLED TRUE +#else +#define CH_DBG_ENABLED FALSE +#endif + +#define __QUOTE_THIS(p) #p + +/*===========================================================================*/ /** - * @brief Trace buffer entries. + * @name Debug related settings + * @{ + */ +/*===========================================================================*/ + +/** + * @brief Trace buffer entries. */ #ifndef CH_TRACE_BUFFER_SIZE #define CH_TRACE_BUFFER_SIZE 64 #endif /** - * @brief Fill value for thread stack area in debug mode. + * @brief Fill value for thread stack area in debug mode. */ #ifndef CH_STACK_FILL_VALUE #define CH_STACK_FILL_VALUE 0x55 @@ -54,11 +70,31 @@ #define CH_THREAD_FILL_VALUE 0xFF #endif -#define __QUOTE_THIS(p) #p +/** @} */ + +/*===========================================================================*/ +/* System state checker related code and variables. */ +/*===========================================================================*/ + +#if !CH_DBG_SYSTEM_STATE_CHECK +#define dbg_check_disable() +#define dbg_check_suspend() +#define dbg_check_enable() +#define dbg_check_lock() +#define dbg_check_unlock() +#define dbg_check_lock_from_isr() +#define dbg_check_unlock_from_isr() +#define dbg_check_enter_isr() +#define dbg_check_leave_isr() +#endif + +/*===========================================================================*/ +/* Trace related structures and macros. */ +/*===========================================================================*/ #if CH_DBG_ENABLE_TRACE || defined(__DOXYGEN__) /** - * @brief Trace buffer record. + * @brief Trace buffer record. */ typedef struct { systime_t se_time; /**< @brief Time of the switch event. */ @@ -68,7 +104,7 @@ typedef struct { } ch_swc_event_t; /** - * @brief Trace buffer header. + * @brief Trace buffer header. */ typedef struct { unsigned tb_size; /**< @brief Trace buffer size (entries).*/ @@ -76,9 +112,25 @@ typedef struct { /** @brief Ring buffer.*/ ch_swc_event_t tb_buffer[CH_TRACE_BUFFER_SIZE]; } ch_trace_buffer_t; + +#if !defined(__DOXYGEN__) +extern ch_trace_buffer_t dbg_trace_buffer; +#endif + #endif /* CH_DBG_ENABLE_TRACE */ +#if !CH_DBG_ENABLE_TRACE +/* When the trace feature is disabled this function is replaced by an empty + macro.*/ +#define dbg_trace(otp) +#endif + +/*===========================================================================*/ +/* Parameters checking related macros. */ +/*===========================================================================*/ + #if CH_DBG_ENABLE_CHECKS || defined(__DOXYGEN__) + /** * @brief Function parameter check. * @details If the condition check fails then the kernel panics and halts. @@ -102,6 +154,10 @@ typedef struct { } #endif /* !CH_DBG_ENABLE_CHECKS */ +/*===========================================================================*/ +/* Assertions related macros. */ +/*===========================================================================*/ + #if CH_DBG_ENABLE_ASSERTS || defined(__DOXYGEN__) /** * @brief Condition assertion. @@ -130,37 +186,42 @@ typedef struct { #define chDbgAssert(c, m, r) {(void)(c);} #endif /* !CH_DBG_ENABLE_ASSERTS */ -#if !(CH_DBG_ENABLE_ASSERTS || \ - CH_DBG_ENABLE_CHECKS || \ - CH_DBG_ENABLE_STACK_CHECK) +extern char *dbg_panic_msg; + +/*===========================================================================*/ +/* Panic related macros. */ +/*===========================================================================*/ + +#if !CH_DBG_ENABLED /* When the debug features are disabled this function is replaced by an empty macro.*/ #define chDbgPanic(msg) {} #endif -#if !CH_DBG_ENABLE_TRACE -/* When the trace feature is disabled this function is replaced by an empty - macro.*/ -#define chDbgTrace(otp) {} -#endif - -#if !defined(__DOXYGEN__) #ifdef __cplusplus extern "C" { #endif +#if CH_DBG_SYSTEM_STATE_CHECK + void dbg_check_disable(void); + void dbg_check_suspend(void); + void dbg_check_enable(void); + void dbg_check_lock(void); + void dbg_check_unlock(void); + void dbg_check_lock_from_isr(void); + void dbg_check_unlock_from_isr(void); + void dbg_check_enter_isr(void); + void dbg_check_leave_isr(void); +#endif #if CH_DBG_ENABLE_TRACE || defined(__DOXYGEN__) - extern ch_trace_buffer_t dbg_trace_buffer; void _trace_init(void); - void chDbgTrace(Thread *otp); + void dbg_trace(Thread *otp); #endif -#if CH_DBG_ENABLE_ASSERTS || CH_DBG_ENABLE_CHECKS || CH_DBG_ENABLE_STACK_CHECK - extern char *dbg_panic_msg; +#if CH_DBG_ENABLED void chDbgPanic(char *msg); #endif #ifdef __cplusplus } #endif -#endif /* !defined(__DOXYGEN__) */ #endif /* _CHDEBUG_H_ */ diff --git a/os/kernel/include/chsys.h b/os/kernel/include/chsys.h index 37d4cd7ce..994b1301f 100644 --- a/os/kernel/include/chsys.h +++ b/os/kernel/include/chsys.h @@ -73,7 +73,10 @@ * * @special */ -#define chSysSwitchI(ntp, otp) port_switch(ntp, otp) +#define chSysSwitchI(ntp, otp) { \ + dbg_trace(otp); \ + port_switch(ntp, otp); \ +} /** * @brief Raises the system interrupt priority mask to the maximum level. @@ -83,7 +86,10 @@ * * @special */ -#define chSysDisable() port_disable() +#define chSysDisable() { \ + port_disable(); \ + dbg_check_disable(); \ +} /** * @brief Raises the system interrupt priority mask to system level. @@ -96,7 +102,10 @@ * * @special */ -#define chSysSuspend() port_suspend() +#define chSysSuspend() { \ + port_suspend(); \ + dbg_check_suspend(); \ +} /** * @brief Lowers the system interrupt priority mask to user level. @@ -107,45 +116,30 @@ * * @special */ -#define chSysEnable() port_enable() +#define chSysEnable() { \ + dbg_check_enable(); \ + port_enable(); \ +} /** * @brief Enters the kernel lock mode. - * @note The use of kernel lock mode is not recommended in the user code, - * it is a better idea to use the semaphores or mutexes instead. - * @see CH_USE_NESTED_LOCKS * * @special */ -#if CH_USE_NESTED_LOCKS || defined(__DOXYGEN__) -#if CH_OPTIMIZE_SPEED || defined(__DOXYGEN__) -#define chSysLock() { \ - if (currp->p_locks++ == 0) \ - port_lock(); \ +#define chSysLock() { \ + port_lock(); \ + dbg_check_lock(); \ } -#endif /* CH_OPTIMIZE_SPEED */ -#else /* !CH_USE_NESTED_LOCKS */ -#define chSysLock() port_lock() -#endif /* !CH_USE_NESTED_LOCKS */ /** * @brief Leaves the kernel lock mode. - * @note The use of kernel lock mode is not recommended in the user code, - * it is a better idea to use the semaphores or mutexes instead. - * @see CH_USE_NESTED_LOCKS * * @special */ -#if CH_USE_NESTED_LOCKS || defined(__DOXYGEN__) -#if CH_OPTIMIZE_SPEED || defined(__DOXYGEN__) -#define chSysUnlock() { \ - if (--currp->p_locks == 0) \ - port_unlock(); \ +#define chSysUnlock() { \ + dbg_check_unlock(); \ + port_unlock(); \ } -#endif /* CH_OPTIMIZE_SPEED */ -#else /* !CH_USE_NESTED_LOCKS */ -#define chSysUnlock() port_unlock() -#endif /* !CH_USE_NESTED_LOCKS */ /** * @brief Enters the kernel lock mode from within an interrupt handler. @@ -159,7 +153,10 @@ * * @special */ -#define chSysLockFromIsr() port_lock_from_isr() +#define chSysLockFromIsr() { \ + port_lock_from_isr(); \ + dbg_check_lock_from_isr(); \ +} /** * @brief Leaves the kernel lock mode from within an interrupt handler. @@ -174,14 +171,20 @@ * * @special */ -#define chSysUnlockFromIsr() port_unlock_from_isr() +#define chSysUnlockFromIsr() { \ + dbg_check_unlock_from_isr(); \ + port_unlock_from_isr(); \ +} /** * @brief IRQ handler enter code. * @note Usually IRQ handlers functions are also declared naked. * @note On some architectures this macro can be empty. */ -#define CH_IRQ_PROLOGUE() PORT_IRQ_PROLOGUE() +#define CH_IRQ_PROLOGUE() { \ + PORT_IRQ_PROLOGUE(); \ + dbg_check_enter_isr(); \ +} /** * @brief IRQ handler exit code. @@ -189,7 +192,10 @@ * @note This macro usually performs the final reschedule by using * @p chSchRescRequiredI() and @p chSchDoRescheduleI(). */ -#define CH_IRQ_EPILOGUE() PORT_IRQ_EPILOGUE() +#define CH_IRQ_EPILOGUE() { \ + dbg_check_leave_isr(); \ + PORT_IRQ_EPILOGUE(); \ +} /** * @brief Standard normal IRQ handler declaration. @@ -211,10 +217,6 @@ extern "C" { #endif void chSysInit(void); void chSysTimerHandlerI(void); -#if CH_USE_NESTED_LOCKS && !CH_OPTIMIZE_SPEED - void chSysLock(void); - void chSysUnlock(void); -#endif /* CH_USE_NESTED_LOCKS && !CH_OPTIMIZE_SPEED */ #ifdef __cplusplus } #endif diff --git a/os/kernel/include/chthreads.h b/os/kernel/include/chthreads.h index b02960bd4..a0a668df4 100644 --- a/os/kernel/include/chthreads.h +++ b/os/kernel/include/chthreads.h @@ -75,12 +75,6 @@ struct Thread { */ trefs_t p_refs; #endif -#if CH_USE_NESTED_LOCKS || defined(__DOXYGEN__) - /** - * @brief Number of nested locks. - */ - cnt_t p_locks; -#endif #if CH_DBG_THREADS_PROFILING || defined(__DOXYGEN__) /** * @brief Thread consumed time in ticks. -- cgit v1.2.3