From fa9b36aff3676a897503a359314d08db8fc5a09d Mon Sep 17 00:00:00 2001 From: gdisirio Date: Sat, 14 Feb 2009 18:20:33 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@766 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- src/chdebug.c | 67 +++++++++++++++++++++++++------------------------- src/chheap.c | 2 +- src/chschd.c | 6 ++--- src/chsys.c | 4 ++- src/chthreads.c | 6 ++--- src/include/ch.h | 4 +-- src/include/debug.h | 32 +++++++++--------------- src/include/threads.h | 6 ++--- src/templates/chconf.h | 25 +++++++++++++------ 9 files changed, 75 insertions(+), 77 deletions(-) (limited to 'src') diff --git a/src/chdebug.c b/src/chdebug.c index 4a16e2d2a..63d5090ee 100644 --- a/src/chdebug.c +++ b/src/chdebug.c @@ -26,58 +26,57 @@ #include -#if CH_USE_DEBUG - -char *panicmsg; +#if CH_DBG_ENABLE_TRACE +/** + * @brief Public trace buffer. + */ +TraceBuffer trace_buffer; /** - * @brief Debug subsystem initialization. + * @brief Trace circular buffer subsystem initialization. */ -void debug_init(void) { +void trace_init(void) { -#if CH_USE_TRACE - dbgtb.tb_size = TRACE_BUFFER_SIZE; - dbgtb.tb_ptr = &dbgtb.tb_buffer[0]; -#endif + trace_buffer.tb_size = TRACE_BUFFER_SIZE; + trace_buffer.tb_ptr = &trace_buffer.tb_buffer[0]; } - /** - * @brief Prints a panic message on the console/debugger and then halts the - * system. + * @brief Inserts in the circular debug trace buffer a context switch record. * - * @param msg the pointer to the message string + * @param otp the thread being switched out + * @param ntp the thread to be resumed */ -void chDbgPanic(char *msg) { +void chDbgTrace(Thread *otp, Thread *ntp) { - panicmsg = msg; - chSysPuts("PANIC: "); - chSysPuts(msg); - chSysHalt(); + trace_buffer.tb_ptr->cse_wtobjp = otp->p_wtobjp; + trace_buffer.tb_ptr->cse_time = chSysGetTime(); + trace_buffer.tb_ptr->cse_state = otp->p_state; + trace_buffer.tb_ptr->cse_tid = (unsigned)ntp >> 4; + if (++trace_buffer.tb_ptr >= &trace_buffer.tb_buffer[TRACE_BUFFER_SIZE]) + trace_buffer.tb_ptr = &trace_buffer.tb_buffer[0]; } +#endif /* CH_DBG_ENABLE_TRACE */ -#if CH_USE_TRACE +#if CH_DBG_ENABLE_ASSERTS /** - * @brief Public trace buffer. + * @brief Pointer to the panic message. + * @details This pointer is meant to be accessed through the debugger, it is + * written once and then the system is halted. */ -TraceBuffer dbgtb; +char *panic_msg; /** - * @brief Inserts in the circular debug trace buffer a context switch record. + * @brief Prints a panic message on the console and then halts the system. * - * @param otp the thread being switched out - * @param ntp the thread to be resumed + * @param msg the pointer to the panic message string */ -void chDbgTrace(Thread *otp, Thread *ntp) { +void chDbgPanic(char *msg) { - dbgtb.tb_ptr->cse_wtobjp = otp->p_wtobjp; - dbgtb.tb_ptr->cse_time = chSysGetTime(); - dbgtb.tb_ptr->cse_state = otp->p_state; - dbgtb.tb_ptr->cse_tid = (unsigned)ntp >> 4; - if (++dbgtb.tb_ptr >= &dbgtb.tb_buffer[TRACE_BUFFER_SIZE]) - dbgtb.tb_ptr = &dbgtb.tb_buffer[0]; + panic_msg = msg; + chSysPuts("PANIC: "); + chSysPuts(msg); + chSysHalt(); } -#endif /* CH_USE_TRACE */ - -#endif /* CH_USE_DEBUG */ +#endif /* CH_DBG_ENABLE_ASSERTS */ /** @} */ diff --git a/src/chheap.c b/src/chheap.c index 5193f19b8..f2bcc2b9e 100644 --- a/src/chheap.c +++ b/src/chheap.c @@ -162,7 +162,7 @@ void chHeapFree(void *p) { while (TRUE) { - chDbgAssert((hp < qp) && (hp >= LIMIT(qp)), "chheap.c, chHeapFree() #2"); + chDbgAssert((hp < qp) || (hp >= LIMIT(qp)), "chheap.c, chHeapFree() #2"); if (((qp == &heap.free) || (hp > qp)) && ((qp->h_next == NULL) || (hp < qp->h_next))) { diff --git a/src/chschd.c b/src/chschd.c index a07db5737..e3f4d9e0d 100644 --- a/src/chschd.c +++ b/src/chschd.c @@ -88,7 +88,7 @@ void chSchGoSleepS(tstate_t newstate) { #if CH_USE_ROUNDROBIN rlist.r_preempt = CH_TIME_QUANTUM; #endif -#if CH_USE_TRACE +#if CH_DBG_ENABLE_TRACE chDbgTrace(otp, currp); #endif chSysSwitchI(otp, currp); @@ -171,7 +171,7 @@ void chSchWakeupS(Thread *ntp, msg_t msg) { #if CH_USE_ROUNDROBIN rlist.r_preempt = CH_TIME_QUANTUM; #endif -#if CH_USE_TRACE +#if CH_DBG_ENABLE_TRACE /* trace the context switch */ chDbgTrace(otp, ntp); #endif @@ -194,7 +194,7 @@ void chSchDoRescheduleI(void) { #if CH_USE_ROUNDROBIN rlist.r_preempt = CH_TIME_QUANTUM; #endif -#if CH_USE_TRACE +#if CH_DBG_ENABLE_TRACE chDbgTrace(otp, currp); #endif chSysSwitchI(otp, currp); diff --git a/src/chsys.c b/src/chsys.c index 2b48278af..db1e7f955 100644 --- a/src/chsys.c +++ b/src/chsys.c @@ -61,11 +61,13 @@ void chSysInit(void) { port_init(); scheduler_init(); - debug_init(); vt_init(); #if CH_USE_HEAP heap_init(); #endif +#if CH_DBG_ENABLE_TRACE + trace_init(); +#endif /* * Now this instructions flow becomes the main thread. diff --git a/src/chthreads.c b/src/chthreads.c index 58f2b46d5..e91c4c18f 100644 --- a/src/chthreads.c +++ b/src/chthreads.c @@ -55,7 +55,7 @@ Thread *init_thread(Thread *tp, tprio_t prio) { return tp; } -#if CH_USE_DEBUG +#if CH_DBG_FILL_THREADS static void memfill(uint8_t *p, uint32_t n, uint8_t v) { while (n) @@ -91,7 +91,7 @@ Thread *chThdInit(void *workspace, size_t wsize, chDbgAssert((wsize >= THD_WA_SIZE(0)) && (prio <= HIGHPRIO) && (workspace != NULL) && (pf != NULL), "chthreads.c, chThdInit()"); -#if CH_USE_DEBUG +#if CH_DBG_FILL_THREADS memfill(workspace, wsize, MEM_FILL_PATTERN); #endif SETUP_CONTEXT(workspace, wsize, pf, arg); @@ -327,7 +327,7 @@ msg_t chThdWait(Thread *tp) { msg_t msg; chSysLock(); - chDbgAssert((tp != NULL) && (tp != currp) && (tp->p_waiting != NULL), + chDbgAssert((tp != NULL) && (tp != currp) && (tp->p_waiting == NULL), "chthreads.c, chThdWait()"); if (tp->p_state != PREXIT) { tp->p_waiting = currp; diff --git a/src/include/ch.h b/src/include/ch.h index 8303d90f6..ec53b4197 100644 --- a/src/include/ch.h +++ b/src/include/ch.h @@ -35,7 +35,7 @@ /** * Kernel version string. */ -#define CH_KERNEL_VERSION "1.1.0unstable" +#define CH_KERNEL_VERSION "1.1.1unstable" /** * Kernel version major number. @@ -50,7 +50,7 @@ /** * Kernel version patch number. */ -#define CH_KERNEL_PATCH 0 +#define CH_KERNEL_PATCH 1 /* * Common values. diff --git a/src/include/debug.h b/src/include/debug.h index 37400d967..ac9034a8b 100644 --- a/src/include/debug.h +++ b/src/include/debug.h @@ -27,8 +27,6 @@ #ifndef _DEBUG_H_ #define _DEBUG_H_ -#if CH_USE_DEBUG - /** * @brief Trace buffer entries. */ @@ -62,25 +60,13 @@ typedef struct { CtxSwcEvent tb_buffer[TRACE_BUFFER_SIZE]; /**< Ring buffer.*/ } TraceBuffer; -extern CtxSwcEvent *dbgnext; -extern TraceBuffer dbgtb; -extern char *dbglastmsg; - -#ifdef __cplusplus -extern "C" { -#endif - void debug_init(void); - void chDbgPanic(char *msg); -#ifdef __cplusplus -} -#endif - +#if CH_DBG_ENABLE_ASSERTS /** * Condition assertion, if the condition check fails then the kernel panics * with the specified message. * @param c the condition to be verified to be true * @param m the text message - * @note The condition is tested only if the @p CH_USE_DEBUG switch is + * @note The condition is tested only if the @p CH_DBG_ENABLE_ASSERTS switch is * specified in @p chconf.h else the macro does nothing. */ #define chDbgAssert(c, m) { \ @@ -88,23 +74,27 @@ extern "C" { chDbgPanic(m); \ } -#else /* !CH_USE_DEBUG */ +#else /* !CH_DBG_ENABLE_ASSERTS */ -#define debug_init() #define chDbgPanic(msg) {} #define chDbgAssert(c, m) {(void)(c);} -#endif /* CH_USE_DEBUG */ +#endif /* !CH_DBG_ENABLE_ASSERTS */ -#if CH_USE_TRACE #ifdef __cplusplus extern "C" { #endif +#if CH_DBG_ENABLE_TRACE + extern TraceBuffer trace_buffer; void chDbgTrace(Thread *otp, Thread *ntp); +#endif +#if CH_DBG_ENABLE_ASSERTS + extern char *panic_msg; + void chDbgPanic(char *msg); +#endif #ifdef __cplusplus } #endif -#endif /* CH_USE_TRACE */ #endif /* _DEBUG_H_ */ diff --git a/src/include/threads.h b/src/include/threads.h index 29ed7f21f..be48fcbb3 100644 --- a/src/include/threads.h +++ b/src/include/threads.h @@ -59,6 +59,8 @@ struct Thread { msg_t p_rdymsg; /**< Thread wakeup code.*/ msg_t p_exitcode; /**< The thread exit code (@p PREXIT state).*/ + void *p_wtobjp; /**< Generic kernel object pointer used + for opaque access.*/ #if CH_USE_SEMAPHORES Semaphore *p_wtsemp; /**< Semaphore where the thread is waiting on (@p PRWTSEM state).*/ @@ -78,10 +80,6 @@ struct Thread { #if CH_USE_EVENTS eventmask_t p_ewmask; /**< Enabled events mask (@p PRWTOREVT or @p PRWTANDEVT states).*/ -#endif -#if CH_USE_TRACE - void *p_wtobjp; /**< Generic kernel object pointer used - for opaque access.*/ #endif }; /* diff --git a/src/templates/chconf.h b/src/templates/chconf.h index f05f8b0b5..3338d5b3f 100644 --- a/src/templates/chconf.h +++ b/src/templates/chconf.h @@ -310,21 +310,30 @@ #endif /** - * Debug option, if enableed includes basic debug support to the kernel. - * @note The debug support is port-dependent, it may be not present on some - * targets. In that case stub functions will be included. + * Debug option, if enabled all the assertions in the kernel code are + * activated. This includes function parameters checks and consistency + * checks inside the kernel. * @note The default is @p FALSE. */ -#ifndef CH_USE_DEBUG -#define CH_USE_DEBUG FALSE +#ifndef CH_DBG_ENABLE_ASSERTS +#define CH_DBG_ENABLE_ASSERTS FALSE #endif /** - * Debug option, includes the threads context switch tracing feature. + * Debug option, if enabled the context switch circular trace buffer is + * activated. * @note The default is @p FALSE. */ -#ifndef CH_USE_TRACE -#define CH_USE_TRACE FALSE +#ifndef CH_DBG_ENABLE_TRACE +#define CH_DBG_ENABLE_TRACE FALSE +#endif + +/** + * Debug option, if enabled the threads working area is filled with a byte + * pattern when a thread is created. + */ +#ifndef CH_DBG_FILL_THREADS +#define CH_DBG_FILL_THREADS FALSE #endif /** -- cgit v1.2.3