2009-08-16 13:07:24 +00:00
|
|
|
/*
|
2015-01-11 13:45:54 +00:00
|
|
|
ChibiOS - Copyright (C) 2006..2015 Giovanni Di Sirio.
|
2009-08-16 13:07:24 +00:00
|
|
|
|
2015-01-11 13:45:54 +00:00
|
|
|
This file is part of ChibiOS.
|
2009-08-16 13:07:24 +00:00
|
|
|
|
2015-01-11 13:45:54 +00:00
|
|
|
ChibiOS is free software; you can redistribute it and/or modify
|
2009-08-16 13:07:24 +00:00
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation; either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
2015-01-11 13:45:54 +00:00
|
|
|
ChibiOS is distributed in the hope that it will be useful,
|
2009-08-16 13:07:24 +00:00
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
2010-02-27 08:54:22 +00:00
|
|
|
* @file chdebug.h
|
2010-02-06 12:31:09 +00:00
|
|
|
* @brief Debug macros and structures.
|
|
|
|
*
|
2009-08-30 06:59:43 +00:00
|
|
|
* @addtogroup debug
|
2009-08-16 13:07:24 +00:00
|
|
|
* @{
|
|
|
|
*/
|
|
|
|
|
2010-02-27 08:54:22 +00:00
|
|
|
#ifndef _CHDEBUG_H_
|
|
|
|
#define _CHDEBUG_H_
|
2009-08-16 13:07:24 +00:00
|
|
|
|
2013-08-10 10:17:45 +00:00
|
|
|
/*===========================================================================*/
|
|
|
|
/* Module constants. */
|
|
|
|
/*===========================================================================*/
|
2011-08-11 17:51:37 +00:00
|
|
|
|
|
|
|
/*===========================================================================*/
|
2013-08-10 10:17:45 +00:00
|
|
|
/* Module pre-compile time settings. */
|
|
|
|
/*===========================================================================*/
|
|
|
|
|
2009-08-16 13:07:24 +00:00
|
|
|
/**
|
2011-08-11 17:51:37 +00:00
|
|
|
* @name Debug related settings
|
|
|
|
* @{
|
|
|
|
*/
|
|
|
|
/**
|
|
|
|
* @brief Trace buffer entries.
|
2009-08-16 13:07:24 +00:00
|
|
|
*/
|
2013-08-10 10:17:45 +00:00
|
|
|
#ifndef CH_DBG_TRACE_BUFFER_SIZE
|
|
|
|
#define CH_DBG_TRACE_BUFFER_SIZE 64
|
2009-08-16 13:07:24 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/**
|
2011-08-11 17:51:37 +00:00
|
|
|
* @brief Fill value for thread stack area in debug mode.
|
2009-08-16 13:07:24 +00:00
|
|
|
*/
|
2013-08-10 10:17:45 +00:00
|
|
|
#ifndef CH_DBG_STACK_FILL_VALUE
|
|
|
|
#define CH_DBG_STACK_FILL_VALUE 0x55
|
2009-08-16 13:07:24 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/**
|
2010-02-06 12:31:09 +00:00
|
|
|
* @brief Fill value for thread area in debug mode.
|
|
|
|
* @note The chosen default value is 0xFF in order to make evident which
|
|
|
|
* thread fields were not initialized when inspecting the memory with
|
|
|
|
* a debugger. A uninitialized field is not an error in itself but it
|
|
|
|
* better to know it.
|
2009-08-16 13:07:24 +00:00
|
|
|
*/
|
2013-08-10 10:17:45 +00:00
|
|
|
#ifndef CH_DBG_THREAD_FILL_VALUE
|
|
|
|
#define CH_DBG_THREAD_FILL_VALUE 0xFF
|
2009-08-16 13:07:24 +00:00
|
|
|
#endif
|
2011-08-11 17:51:37 +00:00
|
|
|
/** @} */
|
|
|
|
|
|
|
|
/*===========================================================================*/
|
2013-08-10 10:17:45 +00:00
|
|
|
/* Derived constants and error checks. */
|
2011-08-11 17:51:37 +00:00
|
|
|
/*===========================================================================*/
|
|
|
|
|
|
|
|
/*===========================================================================*/
|
2013-08-10 10:17:45 +00:00
|
|
|
/* Module data structures and types. */
|
2011-08-11 17:51:37 +00:00
|
|
|
/*===========================================================================*/
|
2011-07-09 09:15:49 +00:00
|
|
|
|
2015-03-05 21:28:51 +00:00
|
|
|
#if (CH_DBG_ENABLE_TRACE == TRUE) || defined(__DOXYGEN__)
|
2009-08-16 13:07:24 +00:00
|
|
|
/**
|
2011-08-11 17:51:37 +00:00
|
|
|
* @brief Trace buffer record.
|
2009-08-16 13:07:24 +00:00
|
|
|
*/
|
|
|
|
typedef struct {
|
2013-08-10 10:17:45 +00:00
|
|
|
/**
|
|
|
|
* @brief Time of the switch event.
|
|
|
|
*/
|
|
|
|
systime_t se_time;
|
|
|
|
/**
|
|
|
|
* @brief Switched in thread.
|
|
|
|
*/
|
|
|
|
thread_t *se_tp;
|
|
|
|
/**
|
|
|
|
* @brief Object where going to sleep.
|
|
|
|
*/
|
|
|
|
void *se_wtobjp;
|
|
|
|
/**
|
|
|
|
* @brief Switched out thread state.
|
|
|
|
*/
|
|
|
|
uint8_t se_state;
|
2011-07-09 09:15:49 +00:00
|
|
|
} ch_swc_event_t;
|
2009-08-16 13:07:24 +00:00
|
|
|
|
|
|
|
/**
|
2011-08-11 17:51:37 +00:00
|
|
|
* @brief Trace buffer header.
|
2009-08-16 13:07:24 +00:00
|
|
|
*/
|
|
|
|
typedef struct {
|
2013-08-10 10:17:45 +00:00
|
|
|
/**
|
|
|
|
* @brief Trace buffer size (entries).
|
|
|
|
*/
|
|
|
|
unsigned tb_size;
|
|
|
|
/**
|
|
|
|
* @brief Pointer to the buffer front.
|
|
|
|
*/
|
|
|
|
ch_swc_event_t *tb_ptr;
|
|
|
|
/**
|
|
|
|
* @brief Ring buffer.
|
|
|
|
*/
|
|
|
|
ch_swc_event_t tb_buffer[CH_DBG_TRACE_BUFFER_SIZE];
|
2011-07-09 09:15:49 +00:00
|
|
|
} ch_trace_buffer_t;
|
2013-08-10 10:17:45 +00:00
|
|
|
#endif /* CH_DBG_ENABLE_TRACE */
|
|
|
|
|
|
|
|
/*===========================================================================*/
|
|
|
|
/* Module macros. */
|
|
|
|
/*===========================================================================*/
|
2011-08-11 17:51:37 +00:00
|
|
|
|
2015-03-05 21:28:51 +00:00
|
|
|
#if CH_DBG_SYSTEM_STATE_CHECK == TRUE
|
2014-11-14 11:07:04 +00:00
|
|
|
#define _dbg_enter_lock() (ch.dbg.lock_cnt = 1)
|
|
|
|
#define _dbg_leave_lock() (ch.dbg.lock_cnt = 0)
|
2011-08-11 17:51:37 +00:00
|
|
|
#endif
|
|
|
|
|
2013-08-10 10:17:45 +00:00
|
|
|
/* When the state checker feature is disabled then the following functions
|
|
|
|
are replaced by an empty macro.*/
|
2015-03-05 21:28:51 +00:00
|
|
|
#if CH_DBG_SYSTEM_STATE_CHECK == FALSE
|
2013-08-10 10:17:45 +00:00
|
|
|
#define _dbg_enter_lock()
|
|
|
|
#define _dbg_leave_lock()
|
|
|
|
#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()
|
|
|
|
#define chDbgCheckClassI()
|
|
|
|
#define chDbgCheckClassS()
|
|
|
|
#endif
|
2009-08-16 13:07:24 +00:00
|
|
|
|
2011-08-11 17:51:37 +00:00
|
|
|
/* When the trace feature is disabled this function is replaced by an empty
|
|
|
|
macro.*/
|
2015-03-05 21:28:51 +00:00
|
|
|
#if CH_DBG_ENABLE_TRACE == FALSE
|
2013-08-10 10:17:45 +00:00
|
|
|
#define _dbg_trace(otp)
|
2011-08-11 17:51:37 +00:00
|
|
|
#endif
|
|
|
|
|
2011-08-23 10:09:08 +00:00
|
|
|
/**
|
|
|
|
* @name Macro Functions
|
|
|
|
* @{
|
|
|
|
*/
|
2009-08-16 13:07:24 +00:00
|
|
|
/**
|
2013-04-04 09:45:32 +00:00
|
|
|
* @brief Function parameters check.
|
2010-02-06 12:31:09 +00:00
|
|
|
* @details If the condition check fails then the kernel panics and halts.
|
|
|
|
* @note The condition is tested only if the @p CH_DBG_ENABLE_CHECKS switch
|
|
|
|
* is specified in @p chconf.h else the macro does nothing.
|
|
|
|
*
|
|
|
|
* @param[in] c the condition to be verified to be true
|
2010-09-21 10:22:06 +00:00
|
|
|
*
|
|
|
|
* @api
|
2009-08-16 13:07:24 +00:00
|
|
|
*/
|
2011-08-01 14:33:04 +00:00
|
|
|
#if !defined(chDbgCheck)
|
2013-09-24 13:00:46 +00:00
|
|
|
#define chDbgCheck(c) do { \
|
2015-03-08 09:17:38 +00:00
|
|
|
/*lint -save -e506 -e774 [2.1, 14.3] Can be a constant by design.*/ \
|
|
|
|
if (CH_DBG_ENABLE_CHECKS != FALSE) { \
|
|
|
|
if (!(c)) { \
|
|
|
|
/*lint -restore*/ \
|
|
|
|
chSysHalt(__func__); \
|
|
|
|
} \
|
2015-03-03 11:01:09 +00:00
|
|
|
} \
|
2015-03-05 21:28:51 +00:00
|
|
|
} while (false)
|
2011-08-01 14:33:04 +00:00
|
|
|
#endif /* !defined(chDbgCheck) */
|
2013-08-10 10:17:45 +00:00
|
|
|
|
2009-08-16 13:07:24 +00:00
|
|
|
/**
|
2010-02-06 12:31:09 +00:00
|
|
|
* @brief Condition assertion.
|
2013-08-10 14:50:32 +00:00
|
|
|
* @details If the condition check fails then the kernel panics with a
|
|
|
|
* message and halts.
|
2010-02-06 12:31:09 +00:00
|
|
|
* @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.
|
|
|
|
* @note The remark string is not currently used except for putting a
|
|
|
|
* comment in the code about the assertion.
|
|
|
|
*
|
|
|
|
* @param[in] c the condition to be verified to be true
|
|
|
|
* @param[in] r a remark string
|
2010-09-21 10:22:06 +00:00
|
|
|
*
|
|
|
|
* @api
|
2009-08-16 13:07:24 +00:00
|
|
|
*/
|
2011-08-01 14:33:04 +00:00
|
|
|
#if !defined(chDbgAssert)
|
2013-09-24 13:00:46 +00:00
|
|
|
#define chDbgAssert(c, r) do { \
|
2015-03-08 09:17:38 +00:00
|
|
|
/*lint -save -e506 -e774 [2.1, 14.3] Can be a constant by design.*/ \
|
|
|
|
if (CH_DBG_ENABLE_ASSERTS != FALSE) { \
|
|
|
|
if (!(c)) { \
|
2015-03-07 11:07:31 +00:00
|
|
|
/*lint -restore*/ \
|
2015-03-08 09:17:38 +00:00
|
|
|
chSysHalt(__func__); \
|
|
|
|
} \
|
2015-03-03 11:01:09 +00:00
|
|
|
} \
|
2015-03-05 21:28:51 +00:00
|
|
|
} while (false)
|
2011-08-01 14:33:04 +00:00
|
|
|
#endif /* !defined(chDbgAssert) */
|
2013-08-10 10:17:45 +00:00
|
|
|
/** @} */
|
2009-08-16 13:07:24 +00:00
|
|
|
|
2011-08-11 17:51:37 +00:00
|
|
|
/*===========================================================================*/
|
2013-08-10 10:17:45 +00:00
|
|
|
/* External declarations. */
|
2011-08-11 17:51:37 +00:00
|
|
|
/*===========================================================================*/
|
|
|
|
|
2009-08-16 13:07:24 +00:00
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
2015-03-05 21:28:51 +00:00
|
|
|
#if CH_DBG_SYSTEM_STATE_CHECK == TRUE
|
2013-08-10 10:17:45 +00:00
|
|
|
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);
|
2011-08-12 11:10:19 +00:00
|
|
|
void chDbgCheckClassI(void);
|
|
|
|
void chDbgCheckClassS(void);
|
2011-08-11 17:51:37 +00:00
|
|
|
#endif
|
2015-03-05 21:28:51 +00:00
|
|
|
#if (CH_DBG_ENABLE_TRACE == TRUE) || defined(__DOXYGEN__)
|
2014-11-14 11:07:04 +00:00
|
|
|
void _dbg_trace_init(void);
|
2013-08-10 10:17:45 +00:00
|
|
|
void _dbg_trace(thread_t *otp);
|
2009-08-16 13:07:24 +00:00
|
|
|
#endif
|
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2013-08-10 10:17:45 +00:00
|
|
|
/*===========================================================================*/
|
|
|
|
/* Module inline functions. */
|
|
|
|
/*===========================================================================*/
|
|
|
|
|
2010-02-27 08:54:22 +00:00
|
|
|
#endif /* _CHDEBUG_H_ */
|
2009-08-16 13:07:24 +00:00
|
|
|
|
|
|
|
/** @} */
|