00001 /** ============================================================================ 00002 * @file dbc.h 00003 * 00004 * @path $(DSPLINK)/dsp/inc/ 00005 * 00006 * @brief DSP-side Design By Contract support. 00007 * 00008 * @ver 1.65.00.03 00009 * ============================================================================ 00010 * @copyright Copyright (C) 2002-2009, Texas Instruments Incorporated - 00011 * http://www.ti.com/ 00012 * 00013 * Redistribution and use in source and binary forms, with or without 00014 * modification, are permitted provided that the following conditions 00015 * are met: 00016 * 00017 * * Redistributions of source code must retain the above copyright 00018 * notice, this list of conditions and the following disclaimer. 00019 * 00020 * * Redistributions in binary form must reproduce the above copyright 00021 * notice, this list of conditions and the following disclaimer in the 00022 * documentation and/or other materials provided with the distribution. 00023 * 00024 * * Neither the name of Texas Instruments Incorporated nor the names of 00025 * its contributors may be used to endorse or promote products derived 00026 * from this software without specific prior written permission. 00027 * 00028 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 00029 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 00030 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 00031 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 00032 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 00033 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 00034 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 00035 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 00036 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 00037 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 00038 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00039 * ============================================================================ 00040 */ 00041 00042 00043 #if !defined (DBC_H) 00044 #define DBC_H 00045 00046 00047 #if defined (__cplusplus) 00048 extern "C" { 00049 #endif /* defined (__cplusplus) */ 00050 00051 00052 #if defined (_DEBUG) 00053 00054 00055 /* ----------------------------------- DSP/BIOS Headers */ 00056 #include <sys.h> 00057 #include <failure.h> 00058 00059 00060 /* If DSPLINK_FAILURE_STOP is defined, stop the execution at the point of 00061 * failure. 00062 */ 00063 #if defined (DSPLINK_FAILURE_STOP) 00064 #if (defined(USE_CCS_BREAKPOINT) && defined( _55_ )) 00065 /** ============================================================================ 00066 * @macro DBC_assert 00067 * 00068 * @brief Asserts a condition. 00069 * If USE_CCS_BREAKPOINT is defined the breakpoint instruction 00070 * specific to CCS is used. 00071 * ============================================================================ 00072 */ 00073 #define DBC_assert(expr) for (; !( expr ); ) \ 00074 CCS_BREAKPOINT ; 00075 00076 #else /* (defined(USE_CCS_BREAKPOINT) && defined( _55_ )) */ 00077 00078 /* Halt the processing at point of failed assertion. */ 00079 #define DBC_assert(c) \ 00080 if (!(c)) { \ 00081 SYS_abort ("Assertion Failed: file=%s, line=%d.\n", \ 00082 __FILE__, \ 00083 __LINE__); } 00084 #endif /* (defined(USE_CCS_BREAKPOINT) && defined( _55_ )) */ 00085 00086 #else /* if defined (DSPLINK_FAILURE_STOP) */ 00087 00088 /* Simply log an error. */ 00089 #define DBC_assert(c) \ 00090 if (!(c)) { \ 00091 SYS_error ("Assertion Failed: file=%s, line=%d.\n", \ 00092 SYS_EINVAL, \ 00093 __FILE__, \ 00094 __LINE__); } 00095 00096 #endif /* if defined (DSPLINK_FAILURE_STOP) */ 00097 00098 00099 /** ============================================================================ 00100 * @macro DBC_require 00101 * 00102 * @brief Requirement assertion. 00103 * ============================================================================ 00104 */ 00105 #define DBC_require DBC_assert 00106 00107 /** ============================================================================ 00108 * @macro DBC_ensure 00109 * 00110 * @brief Ensure assertion. 00111 * ============================================================================ 00112 */ 00113 #define DBC_ensure DBC_assert 00114 00115 #else /* if defined (_DEBUG) */ 00116 00117 /** ============================================================================ 00118 * @macro DBC_xxx 00119 * 00120 * @brief Compiled out in case of DBC_ASSERTS is not set. 00121 * ============================================================================ 00122 */ 00123 #define DBC_assert(c) 00124 #define DBC_require(c) 00125 #define DBC_ensure(c) 00126 00127 00128 #endif /* if defined (_DEBUG) */ 00129 00130 00131 #if defined (__cplusplus) 00132 } 00133 #endif /* defined (__cplusplus) */ 00134 00135 00136 #endif /* if !defined (DBC_H) */